Last updated
Last updated
Inherits: ILM_PC_Staking_v1, ERC20PaymentClientBase_v1, ReentrancyGuardUpgradeable
Author: Inverter Network
Provides a mechanism for users to stake tokens and earn rewards.
Extends {ERC20PaymentClientBase_v1} and integrates with the Payment Processor to enable the distribution of rewards to stakers.
address of the token that can be staked here.
total supply of the token that is staked here.
rate of how many reward tokens are distributed from the fundingmanager to the whole staking pool in seconds.
timestamp of when the reward period will end.
internal value that is needed to calculate the reward each user will receive.
timestamp of when the rewardValue was last updated.
mapping of balances of each user in the staking token address => balance.
mapping of reward Values that are needed to calculate the rewards that a user should receive.
should change everytime the user stakes or unstakes funds address => rewardValue.
mapping of how many reward tokens the user accumulated address => earned.
Storage gap for future upgrades.
See {IERC165-supportsInterface}.
modifier to check if the duration is valid.
Parameters
Initializes the staking contract.
Parameters
Returns the amount of tokens a user staked in this contract.
Parameters
Returns the amount of tokens earned up until now by the current stake of a user.
Parameters
Returns
Returns a estimation of how much rewards will be earned with the current state of the staking contract.
This calculation uses the current reward rate and the current totalSupply to calculate the rewards.
Parameters
Returns
Returns address of the token users can stake.
Returns
Returns the total supply of staked tokens of this contract.
Returns
Returns how much Tokens will be distributed per second to all users that staked in this contract.
Returns
Returns when the rewards will not be distributed anymore.
Returns
Returns the reward value.
Returns
Returns the timestamp of last state change.
Returns
Stake a specified amount of tokens to earn rewards.
Should tokens already be staked, then the sending address will collect the rewards up until this point.
Parameters
Unstake a specified amount of tokens and collect rewards.
this function will revert with a Over/Underflow error in case amount is higher than balance.
Parameters
Collects the rewards that are earned up until now.
Reaps the rewards collected up to this point for the msg.Sender().
Sets the rewards that are to be distributed.
Equally distributes the reward amount over the given time period.
Parameters
Stakes tokens.
Parameters
Updates the reward value and the timestamp of the last update.
This has to trigger on every major change of the state of the contract.
Parameters
Calculates the reward value.
This is the heart of the algorithm. The reward Value is the accumulation of all the rewards a user would get for a single token if they had staked at the beginning of the lifetime of this contract. A "single" reward value or with the lack of a better word "reward period" is the rewardRate (so the rewards per second for the whole contract) multiplied by the time period it was active and dividing that with the total multiplied by the time period it was active and dividing that with the total supply. This "single" value is essentially what a single token would have earned in that time period.
Returns
Calculates the timestamp where rewards will be distributed.
The function returns either the current timestamp or the last timestamp where rewards will be distributed, based on which one is earlier. Is necessary to calculate the exact rewardValue at the end of the reward lifespan. If not included rewards would be distributed forever.
Returns
Calculates how much a user earned for their stake up to this point.
internal function to calculate how much a user earned for their stake up to this point. Uses the difference between the current Reward Value and the reward value when the user staked their tokens in combination with their current balance to calculate their earnings.
Parameters
Returns
Distributes earned rewards via the payment processor.
direct distribution of earned rewards via the payment processor.
Parameters
Sets the rewards.
for contracts that inherit.
Parameters
Sets the staking token.
Parameters
Ensures that the duration in seconds is larger than 0.
Parameters