Saffron Staking V2

Introduction

Contract for rewarding users with SFI for the Saffron liquidity mining program.

Code based off Sushiswap's Masterchef contract with the addition of SFIRewarder.

NOTE: Do not add pools with LP tokens that are deflationary or have reflection.

Contract State Variables

struct UserInfo

Structure of user deposited amounts and their pending reward debt.

struct UserInfo {
        uint256 amount;
        uint256 rewardDebt;
}
TypeNameDescription

uint256

amount

Amount of tokens added by the user.

uint256

rewardDebt

Accounting mechanism. Prevents double-redeeming rewards in the same block.

struct PoolInfo

Structure holding information about each pool's LP token and allocation information.

struct PoolInfo {
        IERC20 lpToken;
        uint256 allocPoint;
        uint256 lastRewardBlock; 
        uint256 accSFIPerShare; 
}
TypeNameDescription

IREC20

lpToken

LP token contract. In the case of single-asset staking this is an ERC20.

uint256

allocPoint

Allocation points to determine how many SFI will be distributed per block to this pool.

uint256

lastRewardBlock

The last block that accumulated rewards were calculated for this pool.

uint256

accSFIPerShare

Accumulator storing the accumulated SFI earned per share of this pool. Shares are user lpToken deposit amounts. This value is scaled up by 1e18.

Miscellaneous State Variables

TypeVisibilityNameDescription

uint256

public

sfiPerBlock

The amount of SFI to be rewarded per block to all pools.

uint256

public

rewardCutoff

SFI rewards are cut off after a specified block. Can be updated by governance to extend/reduce reward time.

ISFIRewarder

public

rewarder

SFIRewarder contract holding the SFI tokens to be rewarded to users.

PoolInfo[]

public

poolInfo

List of pool info structs by pool id.

mapping(address => bool)

private

lpTokenAdded

Mapping to store list of added LP tokens to prevent accidentally adding duplicate pools.

mapping(uint256 => mapping(address => UserInfo))

public

userInfo

Mapping of mapping to store user informaton indexed by pool id and the user's address.

uint256

public

totalAllocPoint

Total allocation points. Must be the sum of all allocation points in all pools.

Constructor

constructor(address _rewarder, uint256 _sfiPerBlock, uint256 _rewardCutoff)
TypeNameDescription

address

_rewarder

uint256

_sfiPerBlock

uint256

_rewardCutoff

Governance Functions

setRewarder()

Update the SFIRewarder. Only callable by the contract owner.

function setRewarder(address _rewarder) external onlyOwner

Parameters:

TypeNameDescription

address

rewarder

The new SFIRewarder account.

setRewardPerBlock()

Update the SFIRewarder. Only callable by the contract owner.

function setRewardPerBlock(uint256 _sfiPerBlock) external onlyOwner

Parameters:

TypeNameDescription

uint256

_sfiPerBlock

The new SFI per block amount to be distributed.

setRewardCutoff()

Update the reward end block. Only callable by the contract owner.

function setRewardCutoff(uint256 _rewardCutoff) external onlyOwner

Parameters:

TypeNameDescription

uint256

_rewardCutoff

The new cut-off block to end SFI reward distribution.

setRewardPerBlockAndRewardCutoff()

Update the reward end block and sfiPerBlock atomically. Only callable by the contract owner.

function setRewardPerBlockAndRewardCutoff(uint256 _sfiPerBlock, uint256 _rewardCutoff) external onlyOwner

Parameters:

TypeNameDescription

uint256

_sfiPerBlock

The new SFI per block amount to be distributed.

uint256

_rewardCutoff

The new cut-off block to end SFI reward distribution.

add()

Add a new pool specifying its lp token and allocation points.

function add(uint256 _allocPoint, address _lpToken) public onlyOwner

Parameters:

TypeNameDescription

uint256

_allocPoint

The allocationPoints for the pool. Determines SFI per block.

address

_lpToken

Token address for the LP token in this pool.

set()

Set the allocPoint of the specific pool with id _pid.

function set(uint256 _pid, uint256 _allocPoint) public onlyOwner

Parameters:

TypeNameDescription

uint256

_pid

The pool id that is to be set.

uint256

_allocPoint

The new allocPoint for the pool.

Public and External Functions

pendingSFI()

Return the pending SFI rewards of a user for a specific pool id.

function set(uint256 _pid, uint256 _allocPoint) public onlyOwner

Parameters:

TypeNameDescription

uint256

_pid

Pool id to get SFI rewards report from.

address

_user

User account to report SFI rewards from.

Return Values:

TypeNameDescription

uint256

Pending SFI amount for the user indexed by pool id.

massUpdatePools()

Update reward variables for all pools. Be careful of gas spending! More than 100 pools is not recommended.

function massUpdatePools() public

updatePool()

Update accumulated SFI shares of the specified pool.

function updatePool(uint256 _pid) public returns (PoolInfo memory)

Parameters:

TypeNameDescription

uint256

_pid

The id of the pool to be updated.

Return Values:

TypeNameDescription

PoolInfo memory

Return this pools updated info

deposit()

Deposit the user's lp token into the the specified pool.

function deposit(uint256 _pid, uint256 _amount) public

Parameters:

TypeNameDescription

uint256

_pid

Pool id where the user's asset is being deposited.

uint256

_amount

Amount to deposit into the pool.

withdraw()

Withdraw the user's lp token from the specified pool.

function withdraw(uint256 _pid, uint256 _amount) public

Parameters:

TypeNameDescription

uint256

_pid

Pool id from which the user's asset is being withdrawn.

uint256

_amount

Amount to withdraw from the pool.

emergencyWithdraw()

Emergency function to withdraw a user's asset in a specified pool.

function emergencyWithdraw(uint256 _pid) public

Parameters:

TypeNameDescription

uint256

_pid

Pool id from which the user's asset is being withdrawn.

Internal Functions

safeSFITransfer()

Transfer SFI from the SFIRewarder contract to the user's account.

function safeSFITransfer(address to, uint256 amount) internal

Parameters:

TypeNameDescription

address

to

Account to transfer SFI to from the SFIRewarder contract.

uint256

amount

Amount of SFI to transfer from the SFIRewarder to the user's account.

View Functions

poolLength()

Return the number of pools in the poolInfo list

function poolLength() external view returns (uint256)

Return Values:

TypeNameDescription

uint256

Length of poolInfo Array.

pendingSFI()

Return the pending SFI rewards of a user for a specific pool id.

function pendingSFI(uint256 _pid, address _user) external view returns (uint256)

Parameters:

TypeNameDescription

uint256

_pid

Pool id to get SFI rewards report from.

address

_user

User account to report SFI rewards from.

Return Values:

TypeNameDescription

uint256

Pending SFI amount for the user indexed by pool id.

Logs

TokensDeposited()

Emitted when amount tokens are deposited by user into pool id pid.

event TokensDeposited(address indexed user, uint256 indexed pid, uint256 amount);

TokensWithdrawn()

Emitted when amount tokens are withdrawn by user from pool id pid.

event TokensWithdrawn(address indexed user, uint256 indexed pid, uint256 amount);

TokensEmergencyWithdrawn()

Emitted when amount tokens are emergency withdrawn by user from pool id pid.

event TokensEmergencyWithdrawn(address indexed user, uint256 indexed pid, uint256 amount);

Last updated