Project📒 to demonstrate staking💰 of ERC20 based tokens over a period of blocks. Inspired from sushiswap masterchef staking protocol.
-
Staking contracts rewards Fixed amount per block set at depployment of contract.
-
Reward calculation on each deposit/reward-withdrawal event.
-
Staking Reward is calculated based on share of total staked token and total block rewards tokens ; since last event.
Share of token is calculated by
share = StakedToken/TotalStakedToken
Reward token calcucated by (happens at each event)
userA accumulated rewards = ( (rewardperBlock*blocks Passed) * userShare ) + previous accumated rewards
A contract with 1 reward token per block.
Let say userA 10 tokens at block 5.
At Block 5
Status
userA staked token = 10 ,Total tokens = 10
At Block 10, userB joins the party
Status userA staked token = 10,userB staked token = 10,Total tokens = 20
Calculate rewards till the block
=> (1*5)*1 + 0
=> 5
At Block 15, userA harvest yields
Status userA staked token = 10 userB staked token = 10 Total tokens = 20
Calculate rewards till the block
=> (1*5)*0.5 + 5
=> 7.5
npm install
npm run deploy
npm test