Saffron Staking V2
Last updated
Was this helpful?
Last updated
Was this helpful?
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.
struct UserInfo
Structure of user deposited amounts and their pending reward debt.
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.
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.
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.
address
_rewarder
uint256
_sfiPerBlock
uint256
_rewardCutoff
setRewarder()
Update the SFIRewarder. Only callable by the contract owner.
Parameters:
address
rewarder
The new SFIRewarder account.
setRewardPerBlock()
Update the SFIRewarder. Only callable by the contract owner.
Parameters:
uint256
_sfiPerBlock
The new SFI per block amount to be distributed.
setRewardCutoff()
Update the reward end block. Only callable by the contract owner.
Parameters:
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.
Parameters:
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.
Parameters:
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.
Parameters:
uint256
_pid
The pool id that is to be set.
uint256
_allocPoint
The new allocPoint for the pool.
pendingSFI()
Return the pending SFI rewards of a user for a specific pool id.
Parameters:
uint256
_pid
Pool id to get SFI rewards report from.
address
_user
User account to report SFI rewards from.
Return Values:
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.
updatePool()
Update accumulated SFI shares of the specified pool.
Parameters:
uint256
_pid
The id of the pool to be updated.
Return Values:
PoolInfo memory
Return this pools updated info
deposit()
Deposit the user's lp token into the the specified pool.
Parameters:
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.
Parameters:
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.
Parameters:
uint256
_pid
Pool id from which the user's asset is being withdrawn.
safeSFITransfer()
Transfer SFI from the SFIRewarder contract to the user's account.
Parameters:
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.
poolLength()
Return the number of pools in the poolInfo
list
Return Values:
uint256
Length of poolInfo
Array.
pendingSFI()
Return the pending SFI rewards of a user for a specific pool id.
Parameters:
uint256
_pid
Pool id to get SFI rewards report from.
address
_user
User account to report SFI rewards from.
Return Values:
uint256
Pending SFI amount for the user indexed by pool id.
TokensDeposited()
Emitted when amount
tokens are deposited by user
into pool id pid
.
TokensWithdrawn()
Emitted when amount
tokens are withdrawn by user
from pool id pid
.
TokensEmergencyWithdrawn()
Emitted when amount
tokens are emergency withdrawn by user
from pool id pid
.