# Mining Contract **Published by:** [Untitled](https://paragraph.com/@0x5100a4c7ed5e75649931e14df0755f29f2f6bc2f/) **Published on:** 2022-03-23 **URL:** https://paragraph.com/@0x5100a4c7ed5e75649931e14df0755f29f2f6bc2f/mining-contract ## Content https://github.com/sushiswap/sushiswap/blob/canary/contracts/MasterChef.sol System Functions 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. Deposit 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. Withdraw The same with deposit operation, beside the User LP is decreased rather than increased. Other functions Always consider to use safeTransfer https://github.com/sushiswap/sushiswap/blob/56cedd0e06a6cf665083b3a662f9f77b80303ebe/contracts/MasterChef.sol#L283 Always consider to use a EmergencyWithdraw function Notice Some contract has a function called notifyRewards: check AC’s contract here https://github.com/MaiaDAO/hermes-protocol/commit/11bc521f4fb80dc42b6adfa3bcbbe3fe3db35897?diff=split 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 ## Publication Information - [Untitled](https://paragraph.com/@0x5100a4c7ed5e75649931e14df0755f29f2f6bc2f/): Publication homepage - [All Posts](https://paragraph.com/@0x5100a4c7ed5e75649931e14df0755f29f2f6bc2f/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@0x5100a4c7ed5e75649931e14df0755f29f2f6bc2f): Subscribe to updates