https://github.com/sushiswap/sushiswap/blob/canary/contracts/MasterChef.sol
Add: add new LP token for Mining.
Set: set reward allocPoint, which can be used to calculate reward per block for specific pool.
massUpdatePools: Update all accSushiPerShare for all pools
updatePool: Mainly used to update single accSushiPerShare for specific pool, also mint sushi for a period.
a. updatePool
b. calculate pending reward = user current LP number * accSushiPerShare - debt
c. transfer reward to msg.sender
d. transfer LP token from msg.sender to the contract
e. change User LP, change debt
f. debt = User LP * accSushiPerShareAtCurrent
actually debt is used to record current accSushiPerShare. User pending reward = (accSushiPerShareAtClaim - accSushiPerShareAtCurrent) * User LP
User LP will not changed until next user operation.
The same with deposit operation, beside the User LP is decreased rather than increased.
Always consider to use safeTransfer
Always consider to use a EmergencyWithdraw function
Some contract has a function called notifyRewards:
check AC’s contract here
It guarantees all new reward will be fairly distributed in the next duration. Always append DURATIONS after current block.
This will also effect distribution speeds
2. Also some contract will use another set function to set distribution speeds which is also acceptable.
https://bscscan.com/address/0x3052a0f6ab15b4ae1df39962d5ddefaca86dab47#code
