SUSHI Liquidity Mining Code and Implementation Guide

·

In the development of autonomous smart devices, one critical challenge is enabling valuable information exchange between Internet of Things (IoT) devices. This article explores how token-based incentives can facilitate such interactions, focusing on the liquidity mining mechanism of SUSHI to address the question: How are tokens generated in a decentralized system?

By analyzing the core smart contracts behind early SUSHI (based on its pre-exchange phase), we break down the architecture that powers decentralized token distribution—offering insights applicable not only to DeFi but also to machine-to-machine economies.


Understanding Liquidity Mining with SUSHI

Liquidity mining revolutionized DeFi by rewarding users for providing liquidity to trading pools. SUSHI, inspired by YAM and built atop Uniswap’s infrastructure, introduced a governance token distributed to liquidity providers (LPs). The model combines yield farming with community ownership, creating alignment between users and protocol growth.

At a high level, SUSHI’s liquidity mining operates through five core functions:

  1. Admin creates liquidity pools
  2. Users deposit their Uniswap LP tokens
  3. Rewards are calculated based on pool weight and stake duration
  4. Users claim SUSHI tokens
  5. Migration of LP tokens to SUSHI’s own AMM (post-launch)

👉 Discover how decentralized incentive models power next-gen applications

This system relies primarily on two contracts:

We’ll dissect both to understand how they work together.


SushiToken.sol: Creating a Mineable ERC-20 Token

The SushiToken contract extends OpenZeppelin’s ERC20 standard and adds minting capabilities derived from the YAM protocol. It enables the creation of new tokens during mining rewards.

Here’s the essential line defining the token:

contract PITAYAToken is ERC20("PITAYAswap", "PITAYA"), Ownable {
Replace PITAYAswap with your project name and PITAYA with your desired symbol when cloning.

This simple inheritance pattern gives you:

No complex modifications are needed—this contract serves as a plug-and-play base for any tokenomics model involving inflationary rewards.


MasterChef.sol: The Heart of Liquidity Mining

The MasterChef contract manages all aspects of staking, reward calculation, and distribution. Below is a breakdown of its key components.

Core Data Structures

PoolInfo – Tracks Each Mining Pool

struct PoolInfo {
    IERC20 lpToken;               // LP token address (e.g., UNI-V2)
    uint256 allocPoint;           // Allocation points determining reward share
    uint256 lastRewardBlock;      // Last block rewards were distributed
    uint256 accSushiPerShare;     // Accumulated SUSHI per share (scaled)
}

UserInfo – Tracks User Stakes

struct UserInfo {
    uint256 amount;               // Amount of LP tokens deposited
    uint256 rewardDebt;           // Used to calculate pending rewards
}

These structures allow efficient per-user reward tracking without storing historical data.

Key Functions

FunctionPurpose
add()Adds a new LP pool (admin-only)
set()Updates pool allocation points
deposit() / withdraw()Stake or unstake LP tokens
pendingSushi()View pending rewards
updatePool()Update reward accruals before any action

Rewards are calculated using block-based multipliers:

function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256)

During an initial bonus period (bonusEndBlock), early stakers earn enhanced rewards (e.g., 2x), encouraging rapid liquidity bootstrapping.

Tokens are minted directly into the contract and distributed proportionally:

sushi.mint(address(this), sushiReward);

A portion (sushiReward.div(20)) is also sent to the dev address, incentivizing ongoing maintenance.


Deploying Your Own SUSHI-Inspired System

While SUSHI’s frontend wasn’t open-source at the time of writing, developers could combine:

This hybrid approach enabled rapid deployment of custom forks.

Step 1: Deploy the Token Contract

Deploy PITAYAToken.sol with your chosen name and symbol:

contract PITAYAToken is ERC20("MyProjectSwap", "MPS"), Ownable

Record the deployed address (e.g., 0x9527...6412) for later use.

Step 2: Configure MasterChef

Critical parameters to set:

ParameterDescription
BONUS_MULTIPLIERSet to 2 for early staker incentives
sushiPerBlockReward rate per block (e.g., 40 SUSHI)
startBlockWhen mining begins
bonusEndBlockEnd of bonus period (~3 months later)
devaddrAddress receiving 5% of minted tokens

Example deployment values:

sushiPerBlock = 40000000000000000000; // 40 SUSHI
bonusEndBlock = startBlock + 600000; // ~3 month window

Deployed MasterChef address: 0x6a6d...b415

Step 3: Post-Deployment Setup

After deployment, two crucial steps ensure proper operation:

  1. Transfer token ownership to the MasterChef contract so it can mint rewards.
  2. Initialize pools using the add() function:

    add(allocPoint, lpTokenAddress, true);

    Start with core pairs like NEST/ETH or USDT/ETH.

Use the set() function later to adjust weights dynamically.


Frontend Integration

To connect your UI:

Update these variables in your JavaScript configuration:

var chefAddress = "0x6a6db5fe904366023a0c0a9e2cea29ed8226b415";
var tokenAddress = "0x9527bf8828a991537558f33d291271b206376412";

const pools = [
  ["0xb23b4b10099690ff7e9ebe16d94c25124f9c4d07",
   "UNISWAP NEST/ETH",
   "https://uniswap.info/pair/...",
   2, 0, 0]
];

Launch via:

http-server

Test with small deposits first. Once confirmed, expand to additional pools.


Governance & Migration Path

True decentralization requires progressive autonomy. A mature system should include:

Phase 1: Time-Locked Control

Phase 2: Enable On-Chain Governance

Phase 3: Liquidity Migration

Once SUSHI’s own AMM is live:

Post-migration, 1/6 of trading fees are distributed to SUSHI holders, aligning long-term incentives.

👉 See how modern protocols transition from centralization to DAO governance


Frequently Asked Questions

Q: How are SUSHI rewards calculated?

Rewards depend on:

The formula uses accumulated shares (accSushiPerShare) to avoid looping through user balances.

Q: What is the role of devaddr?

The dev address receives 5% of all minted tokens (via sushiReward.div(20)), funding development and operations. This incentivizes continued protocol support.

Q: Why use a Timelock before governance?

Timelock prevents abrupt changes, giving users time to react. After integration with GovernorAlpha, all upgrades require community votes, ensuring decentralization.

Q: Can malicious migration steal funds?

Yes—if the migrator contract is misconfigured or maliciously set. Always verify the migrator address and enforce time delays before activation.

Q: How does LP token staking enable dividends?

When users provide liquidity on Uniswap, they receive LP tokens. As trades generate fees, the value of each LP token increases—effectively earning passive yield without selling.

Q: Is this model suitable for IoT device economies?

Absolutely. Devices can stake tokens to access services or earn rewards for contributing data. This creates a self-sustaining machine economy powered by programmable incentives.


Final Thoughts

This guide dissects the foundational code behind SUSHI’s liquidity mining system—offering a blueprint for building token-driven ecosystems. Whether you're launching a DeFi protocol or designing autonomous IoT networks, understanding these mechanics is key to creating sustainable incentive models.

While this analysis is based on early SUSHI code (pre-exchange), its principles remain relevant across modern yield farming platforms. Always test thoroughly on testnets, audit contracts before mainnet launch, and prioritize gradual decentralization.

👉 Start experimenting with DeFi contracts today