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
struct UserInfo
Structure of user deposited amounts and their pending reward debt.
Type | Name | Description |
---|---|---|
|
| Amount of tokens added by the user. |
|
| Accounting mechanism. Prevents double-redeeming rewards in the same block. |
struct PoolInfo
struct PoolInfo
Structure holding information about each pool's LP token and allocation information.
Type | Name | Description |
---|---|---|
|
| LP token contract. In the case of single-asset staking this is an ERC20. |
|
| Allocation points to determine how many SFI will be distributed per block to this pool. |
|
| The last block that accumulated rewards were calculated for this pool. |
|
| 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
Type | Visibility | Name | Description |
---|---|---|---|
|
|
| The amount of SFI to be rewarded per block to all pools. |
|
|
| SFI rewards are cut off after a specified block. Can be updated by governance to extend/reduce reward time. |
|
|
| SFIRewarder contract holding the SFI tokens to be rewarded to users. |
|
|
| List of pool info structs by pool id. |
|
|
| Mapping to store list of added LP tokens to prevent accidentally adding duplicate pools. |
|
|
| Mapping of mapping to store user informaton indexed by pool id and the user's address. |
|
|
| Total allocation points. Must be the sum of all allocation points in all pools. |
Constructor
Type | Name | Description |
---|---|---|
|
| |
|
| |
|
|
Governance Functions
setRewarder()
setRewarder()
Update the SFIRewarder. Only callable by the contract owner.
Parameters:
Type | Name | Description |
---|---|---|
|
| The new SFIRewarder account. |
setRewardPerBlock()
setRewardPerBlock()
Update the SFIRewarder. Only callable by the contract owner.
Parameters:
Type | Name | Description |
---|---|---|
|
| The new SFI per block amount to be distributed. |
setRewardCutoff()
setRewardCutoff()
Update the reward end block. Only callable by the contract owner.
Parameters:
Type | Name | Description |
---|---|---|
|
| The new cut-off block to end SFI reward distribution. |
setRewardPerBlockAndRewardCutoff()
setRewardPerBlockAndRewardCutoff()
Update the reward end block and sfiPerBlock atomically. Only callable by the contract owner.
Parameters:
Type | Name | Description |
---|---|---|
|
| The new SFI per block amount to be distributed. |
|
| The new cut-off block to end SFI reward distribution. |
add()
add()
Add a new pool specifying its lp token and allocation points.
Parameters:
Type | Name | Description |
---|---|---|
|
| The allocationPoints for the pool. Determines SFI per block. |
|
| Token address for the LP token in this pool. |
set()
set()
Set the allocPoint of the specific pool with id _pid.
Parameters:
Type | Name | Description |
---|---|---|
|
| The pool id that is to be set. |
|
| The new allocPoint for the pool. |
Public and External Functions
pendingSFI()
pendingSFI()
Return the pending SFI rewards of a user for a specific pool id.
Parameters:
Type | Name | Description |
---|---|---|
|
| Pool id to get SFI rewards report from. |
|
| User account to report SFI rewards from. |
Return Values:
Type | Name | Description |
---|---|---|
| Pending SFI amount for the user indexed by pool id. |
massUpdatePools()
massUpdatePools()
Update reward variables for all pools. Be careful of gas spending! More than 100 pools is not recommended.
updatePool()
updatePool()
Update accumulated SFI shares of the specified pool.
Parameters:
Type | Name | Description |
---|---|---|
|
| The id of the pool to be updated. |
Return Values:
Type | Name | Description |
---|---|---|
| Return this pools updated info |
deposit()
deposit()
Deposit the user's lp token into the the specified pool.
Parameters:
Type | Name | Description |
---|---|---|
|
| Pool id where the user's asset is being deposited. |
|
| Amount to deposit into the pool. |
withdraw()
withdraw()
Withdraw the user's lp token from the specified pool.
Parameters:
Type | Name | Description |
---|---|---|
|
| Pool id from which the user's asset is being withdrawn. |
|
| Amount to withdraw from the pool. |
emergencyWithdraw()
emergencyWithdraw()
Emergency function to withdraw a user's asset in a specified pool.
Parameters:
Type | Name | Description |
---|---|---|
|
| Pool id from which the user's asset is being withdrawn. |
Internal Functions
safeSFITransfer()
safeSFITransfer()
Transfer SFI from the SFIRewarder contract to the user's account.
Parameters:
Type | Name | Description |
---|---|---|
|
| Account to transfer SFI to from the SFIRewarder contract. |
|
| Amount of SFI to transfer from the SFIRewarder to the user's account. |
View Functions
poolLength()
poolLength()
Return the number of pools in the poolInfo
list
Return Values:
Type | Name | Description |
---|---|---|
| Length of |
pendingSFI()
pendingSFI()
Return the pending SFI rewards of a user for a specific pool id.
Parameters:
Type | Name | Description |
---|---|---|
|
| Pool id to get SFI rewards report from. |
|
| User account to report SFI rewards from. |
Return Values:
Type | Name | Description |
---|---|---|
| Pending SFI amount for the user indexed by pool id. |
Logs
TokensDeposited()
TokensDeposited()
Emitted when amount
tokens are deposited by user
into pool id pid
.
TokensWithdrawn()
TokensWithdrawn()
Emitted when amount
tokens are withdrawn by user
from pool id pid
.
TokensEmergencyWithdrawn()
TokensEmergencyWithdrawn()
Emitted when amount
tokens are emergency withdrawn by user
from pool id pid
.
Last updated