StakingRewards.sol
StakingRewards
allows to stake an ERC20 token to receive as a reward another ERC20 token. The contract used at Angle was forked from SetProtocol, some functions were added to it by Angle Core team.veANGLE
tokens.AngleDistributor
contract and implements the IStakingRewards
interface. Note that PerpetualManager
contracts also implement this interface which means that it is the logic of this contract that is used to distribute rewards to HAs.rewardRate
that is a reward per second given to the staking contract. The way the reward is distributed is that it is split among all the stakers in the contract depending on how much they staked.rewardRate
is computed based on the reward given by the AngleDistributor
and on the rewardsDuration
parameter of the contract. The rewardsDuration
parameter has currently been set to a week for all staking contracts.IStakingRewards
, ReentrancyGuard
and AccessControl
.rewardToken
: Token used as a rewardstakingToken
: ERC20 token used for stakingrewardsDistribution
: Rewards Distribution contract associated to this staking contractstakingBase
: Base of the staked token. It is mostly going to be useful in the case of sanTokens which are not in base 10^18
periodFinish
: Time at which rewards distribution ends for this staking contract. It is updated each time new rewards are given to the contractrewardRate
: Reward per second given to the staking contract, split among the staked tokensrewardsDuration
: Duration of the reward distributionlastUpdateTime
: Last time rewardPerTokenStored
was updatedrewardPerTokenStored
: Helps to compute the amount earned by someone. Cumulates rewards accumulated for one token since the beginninguserRewardPerTokenPaid
: 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 accountrewards
: Stores for each account the accumulated rewardsREWARD_DISTRIBUTOR_ROLE
and that defining a simple modifier is easier.10^18
msg.sender
but the staking rewards go to the onBehalf
addressamount
: Amount to stakeonBehalf
: Address to stake onBehalf ofAngleDistributor
contract and the governor. Before this function is called by the current rewardsDistribution
address, a compatibility check is made to see if the reward token associated to the new reward distribution address is the same.