understand_sushiswap

(WIP) Detailed explanation of the Sushiswap mechanism (MasterChef)

maximebrugel/understand_sushiswap
starsStars 1
forksForks 0
watchersWatchers 1
current-versionCurrent version
total-releasesTotal releases 0
open_issues_countOpen issues 0
dateFirst release -
dateLatest release -
updateLast update 2020-10-20

Understand Sushiswap

Introduction

The goal is to make a presentation of the Sushiswap - MasterChef code. Written by Chef Nomi, this contract is the main part of this Defi platform. Forked several times by many developers, it is important to understand how it works before forking Sushiswap.

Link to the MasterChef => https://github.com/sushiswap/sushiswap/blob/master/contracts/MasterChef.sol

If you want a first introduction to Sushiswap : https://academy.binance.com/en/articles/your-guide-to-sushiswap

Ownership

contract MasterChef is Ownable {
    (...)
}

MasterChef is using the open-zeppelin library Ownable.sol :

import "@openzeppelin/contracts/access/Ownable.sol";

It means that :

  • The msg.sender deploying the MasterChef is the owner. Functions with onlyOwner can be call only by the owner.
  • The owner can transfer his ownership of the Masterchef.
  • The owner (or the new owner in case of an ownership transfer) can renounce. But renouncing ownership will leave the contract without an owner (and onlyOwner functions can't be call anymore).

see https://docs.openzeppelin.com/contracts/3.x/api/access

Constructor

After the constructor has run, the final code of the contract is deployed to the blockchain.

constructor(
        SushiToken _sushi,
        address _devaddr,
        uint256 _sushiPerBlock,
        uint256 _startBlock,
        uint256 _bonusEndBlock
    ) public {
        sushi = _sushi;
        devaddr = _devaddr;
        sushiPerBlock = _sushiPerBlock;
        bonusEndBlock = _bonusEndBlock;
        startBlock = _startBlock;
    }

To deploy the MasterChef, we need 5 information :

  • sushi => The ERC20 Sushi Token (see the contract here)
  • devaddr => The developer address for the development fund (see Dev fund)
  • sushiPerBlock => During the bonus period, the number of SUSHIs per block as a bonus for early users (see Bonus period)
  • bonusEndBlock => The end block for the bonus period. If the block.number (current block number) is after this block we don't apply the bonus (see Bonus period).
  • startBlock => The block number when SUSHI mining starts (see Start block)

Start block

// TODO

Bonus period

// TODO

Dev fund

// TODO

Pool

// TODO

User

// TODO

Total allocation point

// TODO

Possible actions

Add a new pool

// TODO

Update a pool

// TODO

Deposit

// TODO

See pending SUSHIs

// TODO

Withdraw

// TODO

Emergency Withdraw

// TODO

Migration

// TODO