Skip to content

MultiStakingRewardsERC4626

senamakel edited this page Nov 25, 2024 · 8 revisions

Solidity API

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

DISTRIBUTOR_ROLE

bytes32 DISTRIBUTOR_ROLE

Gets the role that is able to distribute rewards

periodFinish

mapping(contract IERC20 => uint256) periodFinish

Gets the period finish for a reward token

Parameters

Name Type Description

rewardRate

mapping(contract IERC20 => uint256) rewardRate

Reward per second given to the staking contract, split among the staked tokens

Parameters

Name Type Description

rewardsDuration

uint256 rewardsDuration

Duration of the reward distribution

lastUpdateTime

mapping(contract IERC20 => uint256) lastUpdateTime

Last time rewardPerTokenStored was updated

Parameters

Name Type Description

rewardPerTokenStored

mapping(contract IERC20 => uint256) rewardPerTokenStored

Helps 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

Parameters

Name Type Description

userRewardPerTokenPaid

mapping(contract IERC20 => mapping(address => uint256)) userRewardPerTokenPaid

Stores 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

Parameters

Name Type Description

rewards

mapping(contract IERC20 => mapping(address => uint256)) rewards

Stores for each account the accumulated rewards

Parameters

Name Type Description

rewardToken1

contract IERC20 rewardToken1

Gets the first reward token for which the rewards are distributed

rewardToken2

contract IERC20 rewardToken2

Gets the second reward token for which the rewards are distributed

staking

contract IOmnichainStaking staking

Gets the staking contract that returns the voting power of an account

_boostedTotalSupply

uint256 _boostedTotalSupply

Boosted total supply that is used to compute the rewards

_totalVotingPower

uint256 _totalVotingPower

Total voting power of all the depositors

_votingPower

mapping(address => uint256) _votingPower

Voting power of a depositor

_boostedBalances

mapping(address => uint256) _boostedBalances

Boosted balances that are used to compute the rewards

withdrawalDelay

uint256 withdrawalDelay

withdrawalTimestamp

mapping(address => uint256) withdrawalTimestamp

withdrawalAmount

mapping(address => uint256) withdrawalAmount

__MultiStakingRewardsERC4626_init

function __MultiStakingRewardsERC4626_init(string name, string symbol, address _stakingToken, uint256 _withdrawalDelay, address _governance, address _rewardToken1, address _rewardToken2, uint256 _rewardsDuration, address _staking) internal

Initializes the staking contract with a first set of parameters

queueWithdrawal

function queueWithdrawal(uint256 shares) external

cancelWithdrawal

function cancelWithdrawal() external

lastTimeRewardApplicable

function 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

Parameters

Name Type Description
token contract IERC20 The token for which the last time reward applicable is requested

rewardPerToken

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

Parameters

Name Type Description
token contract IERC20 The token for which the reward per token is updated

earned

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

Parameters

Name Type Description
token contract IERC20 The token for which the rewards are earned
account address The account for which the rewards are earned

Return Values

Name Type Description
[0] uint256 How much a given account earned rewards

totalBoostedSupply

function totalBoostedSupply() external view returns (uint256 boostedTotalSupply_)

Gets the total supply of boosted tokens

boostedBalance

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

totalVotingPower

function totalVotingPower() external view returns (uint256 supply)

Gets the total voting power of all the participants

votingPower

function votingPower(address who) external view returns (uint256 balance)

Gets the voting power for an account

Parameters

Name Type Description
who address The account for which the voting power is requested

approveUnderlyingWithPermit

function approveUnderlyingWithPermit(uint256 val, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external

Grants approval to the staking contract to spend the underlying token using permits

getReward

function getReward(address who, contract IERC20 token) public

Triggers a payment of the reward earned to the msg.sender

Parameters

Name Type Description
who address The account for which the rewards are paid
token contract IERC20 The token for which the rewards are paid

getRewardDual

function getRewardDual(address who) public

Triggers a payment of the rewards earned for both tokens

Parameters

Name Type Description
who address The account for which the rewards are paid

notifyRewardAmount

function notifyRewardAmount(contract IERC20 token, uint256 reward) external

Adds rewards to be distributed

Parameters

Name Type Description
token contract IERC20 The token for which the rewards are added
reward uint256 Amount of reward tokens to distribute

updateRewards

function updateRewards(contract IERC20 token, address who) external

Updates the rewards for an account

Parameters

Name Type Description
token contract IERC20 The token for which the rewards are updated
who address The account for which the rewards are updated

_rewardPerToken

function _rewardPerToken(contract IERC20 _token, uint256 boostedTotalSupply_) internal view returns (uint256)

_withdraw

function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares) internal

Withdraw/redeem common workflow.

_deposit

function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual

Deposit/mint common workflow.

_earned

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

Parameters

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

_updateReward

function _updateReward(contract IERC20 token, address account) internal

Called frequently to update the staking parameters associated to an address

Parameters

Name Type Description
token contract IERC20 The token for which the rewards are updated
account address The account for which the rewards are updated

_updateRewardDual

function _updateRewardDual(contract IERC20 token1, contract IERC20 token2, address account) internal

Called frequently to update the staking parameters associated to an address

Parameters

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

_updatingVotingPower

function _updatingVotingPower(address account) internal

Updates the voting power of an account

Parameters

Name Type Description
account address The account for which the voting power is updated

_calculateBoostedBalance

function _calculateBoostedBalance(address account) internal view virtual returns (uint256 boostedBalance_, uint256 boostedTotalSupply_)

Computes the boosted balance and the boosted total supply of an account

Parameters

Name Type Description
account address The account for which the boosted balance and the boosted total supply are computed

Return Values

Name Type Description
boostedBalance_ uint256 The boosted balance of the account
boostedTotalSupply_ uint256 The boosted total supply

_getVotingPower

function _getVotingPower(address account) internal view returns (uint256 votingBalance, uint256 votingTotal)

Computes the voting power of an account

Parameters

Name Type Description
account address The account for which the voting power is requested

Return Values

Name Type Description
votingBalance uint256 The voting power of the account
votingTotal uint256 The total voting power

Clone this wiki locally