-
Notifications
You must be signed in to change notification settings - Fork 8
MultiStakingRewardsERC4626
The MultiStakingRewardsERC4626 contracts allows to stake an ERC20 token and
receieve multiple other ERC20 rewards.
https://github.com/SetProtocol/index-coop-contracts/blob/master/contracts/staking/StakingRewards.sol
Forked form SetProtocol This contracts is designed to be used via a proxy and follows the ERC4626 standard. This contracts needs at least two reward tokens to be used
bytes32 DISTRIBUTOR_ROLEGets the role that is able to distribute rewards
mapping(contract IERC20 => uint256) periodFinishGets the period finish for a reward token
| Name | Type | Description |
|---|
mapping(contract IERC20 => uint256) rewardRateReward per second given to the staking contract, split among the staked tokens
| Name | Type | Description |
|---|
uint256 rewardsDurationDuration of the reward distribution
mapping(contract IERC20 => uint256) lastUpdateTimeLast time rewardPerTokenStored was updated
| Name | Type | Description |
|---|
mapping(contract IERC20 => uint256) rewardPerTokenStoredHelps to compute the amount earned by someone. Cumulates rewards accumulated for one token since the beginning. Stored as a uint so it is actually a float times the base of the reward token
| Name | Type | Description |
|---|
mapping(contract IERC20 => mapping(address => uint256)) userRewardPerTokenPaidStores for each account the rewardPerToken: we do the difference
between the current and the old value to compute what has been earned by an account
| Name | Type | Description |
|---|
mapping(contract IERC20 => mapping(address => uint256)) rewardsStores for each account the accumulated rewards
| Name | Type | Description |
|---|
contract IERC20 rewardToken1Gets the first reward token for which the rewards are distributed
contract IERC20 rewardToken2Gets the second reward token for which the rewards are distributed
contract IOmnichainStaking stakingGets the staking contract that returns the voting power of an account
uint256 _boostedTotalSupplyBoosted total supply that is used to compute the rewards
uint256 _totalVotingPowerTotal voting power of all the depositors
mapping(address => uint256) _votingPowerVoting power of a depositor
mapping(address => uint256) _boostedBalancesBoosted balances that are used to compute the rewards
uint256 withdrawalDelaymapping(address => uint256) withdrawalTimestampmapping(address => uint256) withdrawalAmountfunction __MultiStakingRewardsERC4626_init(string name, string symbol, address _stakingToken, uint256 _withdrawalDelay, address _governance, address _rewardToken1, address _rewardToken2, uint256 _rewardsDuration, address _staking) internalInitializes the staking contract with a first set of parameters
function queueWithdrawal(uint256 shares) externalfunction cancelWithdrawal() externalfunction lastTimeRewardApplicable(contract IERC20 token) public view returns (uint256)Queries the last timestamp at which a reward was distributed
Returns the current timestamp if a reward is being distributed and the end of the staking period if staking is done
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the last time reward applicable is requested |
function rewardPerToken(contract IERC20 token) external view returns (uint256)Used to actualize the rewardPerTokenStored
It adds to the reward per token: the time elapsed since the rewardPerTokenStored was
last updated multiplied by the rewardRate divided by the number of tokens
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the reward per token is updated |
function earned(contract IERC20 token, address account) public view returns (uint256)Returns how much a given account earned rewards
It adds to the rewards the amount of reward earned since last time that is the difference in reward per token from now and last time multiplied by the number of tokens staked by the person
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the rewards are earned |
| account | address | The account for which the rewards are earned |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | How much a given account earned rewards |
function totalBoostedSupply() external view returns (uint256 boostedTotalSupply_)Gets the total supply of boosted tokens
function boostedBalance(address who) external view returns (uint256 boostedBalance_)Gets the boosted balance for an account
Code taken from https://github.com/curvefi/curve-dao-contracts/blob/master/contracts/gauges/LiquidityGaugeV5.vy#L191-L213
function totalVotingPower() external view returns (uint256 supply)Gets the total voting power of all the participants
function votingPower(address who) external view returns (uint256 balance)Gets the voting power for an account
| Name | Type | Description |
|---|---|---|
| who | address | The account for which the voting power is requested |
function approveUnderlyingWithPermit(uint256 val, uint256 deadline, uint8 v, bytes32 r, bytes32 s) externalGrants approval to the staking contract to spend the underlying token using permits
function getReward(address who, contract IERC20 token) publicTriggers a payment of the reward earned to the msg.sender
| Name | Type | Description |
|---|---|---|
| who | address | The account for which the rewards are paid |
| token | contract IERC20 | The token for which the rewards are paid |
function getRewardDual(address who) publicTriggers a payment of the rewards earned for both tokens
| Name | Type | Description |
|---|---|---|
| who | address | The account for which the rewards are paid |
function notifyRewardAmount(contract IERC20 token, uint256 reward) externalAdds rewards to be distributed
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the rewards are added |
| reward | uint256 | Amount of reward tokens to distribute |
function updateRewards(contract IERC20 token, address who) externalUpdates the rewards for an account
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the rewards are updated |
| who | address | The account for which the rewards are updated |
function _rewardPerToken(contract IERC20 _token, uint256 boostedTotalSupply_) internal view returns (uint256)function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares) internalWithdraw/redeem common workflow.
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtualDeposit/mint common workflow.
function _earned(contract IERC20 token_, address account_, uint256 boostedBalance_, uint256 boostedTotalSupply_) internal view returns (uint256)Computes the amount earned by an account
Takes into account the boosted balance and the boosted total supply
| Name | Type | Description |
|---|---|---|
| token_ | contract IERC20 | The token for which the rewards are computed |
| account_ | address | The account for which the rewards are computed |
| boostedBalance_ | uint256 | The boosted balance of the account |
| boostedTotalSupply_ | uint256 | The boosted total supply |
function _updateReward(contract IERC20 token, address account) internalCalled frequently to update the staking parameters associated to an address
| Name | Type | Description |
|---|---|---|
| token | contract IERC20 | The token for which the rewards are updated |
| account | address | The account for which the rewards are updated |
function _updateRewardDual(contract IERC20 token1, contract IERC20 token2, address account) internalCalled frequently to update the staking parameters associated to an address
| Name | Type | Description |
|---|---|---|
| token1 | contract IERC20 | The first token for which the rewards are updated |
| token2 | contract IERC20 | The second token for which the rewards are updated |
| account | address | The account for which the rewards are updated |
function _updatingVotingPower(address account) internalUpdates the voting power of an account
| Name | Type | Description |
|---|---|---|
| account | address | The account for which the voting power is updated |
function _calculateBoostedBalance(address account) internal view virtual returns (uint256 boostedBalance_, uint256 boostedTotalSupply_)Computes the boosted balance and the boosted total supply of an account
| Name | Type | Description |
|---|---|---|
| account | address | The account for which the boosted balance and the boosted total supply are computed |
| Name | Type | Description |
|---|---|---|
| boostedBalance_ | uint256 | The boosted balance of the account |
| boostedTotalSupply_ | uint256 | The boosted total supply |
function _getVotingPower(address account) internal view returns (uint256 votingBalance, uint256 votingTotal)Computes the voting power of an account
| Name | Type | Description |
|---|---|---|
| account | address | The account for which the voting power is requested |
| Name | Type | Description |
|---|---|---|
| votingBalance | uint256 | The voting power of the account |
| votingTotal | uint256 | The total voting power |