StakingRewardsallows 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.
AngleDistributorcontract and implements the
IStakingRewardsinterface. Note that
PerpetualManagercontracts also implement this interface which means that it is the logic of this contract that is used to distribute rewards to HAs.
rewardRatethat 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.
rewardRateis computed based on the reward given by the
AngleDistributorand on the
rewardsDurationparameter of the contract. The
rewardsDurationparameter has currently been set to a week for all staking contracts.
rewardToken: Token used as a reward
stakingToken: ERC20 token used for staking
rewardsDistribution: Rewards Distribution contract associated to this staking contract
stakingBase: Base of the staked token. It is mostly going to be useful in the case of sanTokens which are not in base
periodFinish: Time at which rewards distribution ends for this staking contract. It is updated each time new rewards are given to the contract
rewardRate: Reward per second given to the staking contract, split among the staked tokens
rewardsDuration: Duration of the reward distribution
lastUpdateTime: Last time
rewardPerTokenStored: Helps to compute the amount earned by someone. Cumulates rewards accumulated for one token since the beginning
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
rewards: Stores for each account the accumulated rewards
REWARD_DISTRIBUTOR_ROLEand that defining a simple modifier is easier.
msg.senderbut the staking rewards go to the
amount: Amount to stake
onBehalf: Address to stake onBehalf of
AngleDistributorcontract and the governor. Before this function is called by the current
rewardsDistributionaddress, a compatibility check is made to see if the reward token associated to the new reward distribution address is the same.