This CW20 Staking ADO allows users to stake a specified CW20 token and to receive rewards in any number of other tokens in proportion to their share. The reward token does not need to be the token they stake with but it can be. The contract allows for two types of rewards:
non-allocated rewards: These are rewards that get deposited periodically into the contract and get distributed proportionally to stakers. Rewards that are deposited are instantly granted to the stakers.
Allocated rewards: The owner deposits a number of tokens to be distributed over the course of a set time. The rewards get distributed the same way, except all of the reward tokens are already deposited in the contract.
The added rewards are distributed proportionally between the stakers that are already staked.
We assume that we instantiated the contract and there are no stakers as of yet. Then the following series of events happen:
First user stakes 100 tokens
Second user stakes 500 tokens
Third user stakes 400 tokens
100 tokens are sent to the contract as rewards
Fourth user stakes 1000 tokens
1000 tokens are sent as rewards
In this case, when the 100 coins are sent the pending rewards are as following for each user:
10 tokens for user 1
50 tokens for user 2
40 tokens for user 3
0 tokens for user 4 since he staked after the rewards were sent
After the 1000 tokens are sent to the contract as rewards, it is split as follows:
50 tokens for user 1 (60 in total)
250 tokens for user 2 (300 in total)
200 tokens for user 3 (240 in total)
500 tokens for user 4 (500 in total since did not receive rewards from first batch)
After the rewards have been sent, the stakers would not receive any extra rewards until a next batch of rewards are sent.
The additional rewards should not include the staking token.
Unstakes the specified amount of assets, or all if not specified. The user's pending rewards and indexes are updated for each additional reward token.
Optional amount to unstake. Defaults to the maximum amount.
Claims any outstanding rewards from the additional reward tokens.
Updates the global reward index for the specified assets or all of the specified ones if none is specified. Funds may be sent along with this. Usually called when new allocated rewards are deposited to update the rewards accordingly.