Iβm creating some diagrams and graph while reading this article
Understanding SushiSwap's MasterChef staking rewards
π§±: A β B | β³ | BlockRewards | Staked πͺ | Total πͺ | StakerShare | Rewards | Accumulated Reward | Harvest | Harvest Total | |
---|---|---|---|---|---|---|---|---|---|---|
A | 0 to 10 | 10 | 10 | 100 | 100 | 100/100 = 1.0 | 10 | 10 | ||
A | 10 to 15 | 5 | 5 | 100 | 500 | 100/500 = 0.2 | 1 | 11 β 0 | βοΈπΎπΎπΎβοΈ | 11 |
B | π | π | π | 400 | π | 400/500 = 0.8 | 4 | 4 | ||
A | 15 to 25 | 10 | 10 | 100 | 500 | 100/500 = 0.2 | 2 | 2 | ||
B | π | π | π | 400 | π | 400/500 = 0.8 | 8 | 12 β 0 | βοΈπΎπΎπΎβοΈ | 12 |
A | 25 to 30 | 5 | 5 | 100 | 500 | 100/500 = 0.2 | 1 | 3 β 0 | βοΈπΎπΎπΎβοΈ | 14 |
B | π | π | π | 400 | π | 400/500 = 0.8 | 4 | 4 β 0 | βοΈπΎπΎπΎβοΈ | 16 |
ARewards =100*{(10/100)+(5/500)+(10/500)+(5/500)}
BRewards = 400*{(5/500)+(10/500)+(5/500)}
In the codeπ
// View function to see pending SUSHIs on frontend.
function pendingSushi(uint256 _pid, address _user)
external
view
returns (uint256)
{
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSushiPerShare = pool.accSushiPerShare;
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpSupply != 0) {
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sushiReward = multiplier
.mul(sushiPerBlock)
.mul(pool.allocPoint)
.div(totalAllocPoint);
accSushiPerShare = accSushiPerShare.add(
sushiReward.mul(1e12).div(lpSupply)
);
}
return user.amount.mul(accSushiPerShare).div(1e12).sub(user.rewardDebt);
}