|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import "./SymbioticRewardsImports.sol"; |
| 5 | + |
| 6 | +import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; |
| 7 | +import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; |
| 8 | + |
| 9 | +import {Test} from "forge-std/Test.sol"; |
| 10 | + |
| 11 | +contract SymbioticRewardsBindings is Test { |
| 12 | + using SafeERC20 for IERC20; |
| 13 | + |
| 14 | + function _createDefaultStakerRewards_SymbioticRewards( |
| 15 | + ISymbioticDefaultStakerRewardsFactory symbioticDefaultStakerRewardsFactory, |
| 16 | + address who, |
| 17 | + address vault, |
| 18 | + uint256 adminFee, |
| 19 | + address defaultAdminRoleHolder, |
| 20 | + address adminFeeClaimRoleHolder, |
| 21 | + address adminFeeSetRoleHolder |
| 22 | + ) internal virtual returns (address defaultStakerRewards) { |
| 23 | + vm.startPrank(who); |
| 24 | + defaultStakerRewards = symbioticDefaultStakerRewardsFactory.create( |
| 25 | + ISymbioticDefaultStakerRewards.InitParams({ |
| 26 | + vault: vault, |
| 27 | + adminFee: adminFee, |
| 28 | + defaultAdminRoleHolder: defaultAdminRoleHolder, |
| 29 | + adminFeeClaimRoleHolder: adminFeeClaimRoleHolder, |
| 30 | + adminFeeSetRoleHolder: adminFeeSetRoleHolder |
| 31 | + }) |
| 32 | + ); |
| 33 | + vm.stopPrank(); |
| 34 | + } |
| 35 | + |
| 36 | + function _createDefaultOperatorRewards_SymbioticRewards( |
| 37 | + ISymbioticDefaultOperatorRewardsFactory symbioticDefaultOperatorRewardsFactory, |
| 38 | + address who |
| 39 | + ) internal virtual returns (address defaultOperatorRewards) { |
| 40 | + vm.startPrank(who); |
| 41 | + defaultOperatorRewards = symbioticDefaultOperatorRewardsFactory.create(); |
| 42 | + vm.stopPrank(); |
| 43 | + } |
| 44 | + |
| 45 | + function _distributeRewards_SymbioticRewards( |
| 46 | + address who, |
| 47 | + address defaultStakerRewards, |
| 48 | + address network, |
| 49 | + address token, |
| 50 | + uint256 amount, |
| 51 | + uint48 captureTimestamp |
| 52 | + ) internal virtual { |
| 53 | + vm.startPrank(who); |
| 54 | + IERC20(token).forceApprove(defaultStakerRewards, amount); |
| 55 | + ISymbioticDefaultStakerRewards(defaultStakerRewards).distributeRewards( |
| 56 | + network, |
| 57 | + token, |
| 58 | + amount, |
| 59 | + abi.encode( |
| 60 | + captureTimestamp, |
| 61 | + ISymbioticDefaultStakerRewards(defaultStakerRewards).ADMIN_FEE_BASE(), |
| 62 | + new bytes(0), |
| 63 | + new bytes(0) |
| 64 | + ) |
| 65 | + ); |
| 66 | + vm.stopPrank(); |
| 67 | + } |
| 68 | + |
| 69 | + function _claimRewards_SymbioticRewards( |
| 70 | + address who, |
| 71 | + address defaultStakerRewards, |
| 72 | + address recipient, |
| 73 | + address token, |
| 74 | + address network |
| 75 | + ) internal virtual { |
| 76 | + vm.startPrank(who); |
| 77 | + uint256 maxRewards = 1000; |
| 78 | + ISymbioticDefaultStakerRewards(defaultStakerRewards).claimRewards( |
| 79 | + recipient, token, abi.encode(network, maxRewards, new bytes[](0)) |
| 80 | + ); |
| 81 | + vm.stopPrank(); |
| 82 | + } |
| 83 | + |
| 84 | + function _claimRewards_SymbioticRewards( |
| 85 | + address who, |
| 86 | + address defaultStakerRewards, |
| 87 | + address token, |
| 88 | + address network |
| 89 | + ) internal virtual { |
| 90 | + _claimRewards_SymbioticRewards(who, defaultStakerRewards, who, token, network); |
| 91 | + } |
| 92 | + |
| 93 | + function _claimAdminFee_SymbioticRewards( |
| 94 | + address who, |
| 95 | + address defaultStakerRewards, |
| 96 | + address recipient, |
| 97 | + address token |
| 98 | + ) internal virtual { |
| 99 | + vm.startPrank(who); |
| 100 | + ISymbioticDefaultStakerRewards(defaultStakerRewards).claimAdminFee(recipient, token); |
| 101 | + vm.stopPrank(); |
| 102 | + } |
| 103 | + |
| 104 | + function _claimAdminFee_SymbioticRewards( |
| 105 | + address who, |
| 106 | + address defaultStakerRewards, |
| 107 | + address token |
| 108 | + ) internal virtual { |
| 109 | + _claimAdminFee_SymbioticRewards(who, defaultStakerRewards, who, token); |
| 110 | + } |
| 111 | + |
| 112 | + function _setAdminFee_SymbioticRewards( |
| 113 | + address who, |
| 114 | + address defaultStakerRewards, |
| 115 | + uint256 adminFee |
| 116 | + ) internal virtual { |
| 117 | + vm.startPrank(who); |
| 118 | + ISymbioticDefaultStakerRewards(defaultStakerRewards).setAdminFee(adminFee); |
| 119 | + vm.stopPrank(); |
| 120 | + } |
| 121 | + |
| 122 | + function _distributeRewards_SymbioticRewards( |
| 123 | + address who, |
| 124 | + address defaultOperatorRewards, |
| 125 | + address network, |
| 126 | + address token, |
| 127 | + uint256 amount, |
| 128 | + bytes32 root |
| 129 | + ) internal virtual { |
| 130 | + vm.startPrank(who); |
| 131 | + IERC20(token).forceApprove(defaultOperatorRewards, amount); |
| 132 | + ISymbioticDefaultOperatorRewards(defaultOperatorRewards).distributeRewards(network, token, amount, root); |
| 133 | + vm.stopPrank(); |
| 134 | + } |
| 135 | + |
| 136 | + function _claimRewards_SymbioticRewards( |
| 137 | + address who, |
| 138 | + address defaultOperatorRewards, |
| 139 | + address recipient, |
| 140 | + address network, |
| 141 | + address token, |
| 142 | + uint256 totalClaimable, |
| 143 | + bytes32[] memory proof |
| 144 | + ) internal virtual { |
| 145 | + vm.startPrank(who); |
| 146 | + ISymbioticDefaultOperatorRewards(defaultOperatorRewards).claimRewards( |
| 147 | + recipient, network, token, totalClaimable, proof |
| 148 | + ); |
| 149 | + vm.stopPrank(); |
| 150 | + } |
| 151 | + |
| 152 | + function _claimRewards_SymbioticRewards( |
| 153 | + address who, |
| 154 | + address defaultOperatorRewards, |
| 155 | + address network, |
| 156 | + address token, |
| 157 | + uint256 totalClaimable, |
| 158 | + bytes32[] memory proof |
| 159 | + ) internal virtual { |
| 160 | + _claimRewards_SymbioticRewards(who, defaultOperatorRewards, who, network, token, totalClaimable, proof); |
| 161 | + } |
| 162 | + |
| 163 | + function _grantRole_SymbioticRewards(address who, address where, bytes32 role, address account) internal virtual { |
| 164 | + vm.startPrank(who); |
| 165 | + AccessControl(where).grantRole(role, account); |
| 166 | + vm.stopPrank(); |
| 167 | + } |
| 168 | + |
| 169 | + function _grantRoleDefaultAdmin_SymbioticRewards(address who, address where, address account) internal virtual { |
| 170 | + _grantRole_SymbioticRewards(who, where, AccessControl(where).DEFAULT_ADMIN_ROLE(), account); |
| 171 | + } |
| 172 | + |
| 173 | + function _grantRoleAdminFeeClaim_SymbioticRewards(address who, address where, address account) internal virtual { |
| 174 | + _grantRole_SymbioticRewards(who, where, ISymbioticDefaultStakerRewards(where).ADMIN_FEE_CLAIM_ROLE(), account); |
| 175 | + } |
| 176 | + |
| 177 | + function _grantRoleAdminFeeSet_SymbioticRewards(address who, address where, address account) internal virtual { |
| 178 | + _grantRole_SymbioticRewards(who, where, ISymbioticDefaultStakerRewards(where).ADMIN_FEE_SET_ROLE(), account); |
| 179 | + } |
| 180 | +} |
0 commit comments