Crate pallet_liquidity_mining
source ·Expand description
Liquidity mining pallet
Overview
This pallet provides functionality for a liquidity mining program with a time incentive (loyalty factor) and multiple incentives scheme. Users are rewarded for each period they stay in the liq. mining program.
Reward per one period is derived from the user’s loyalty factor which grows with time (periods) the user is in the liq. mining program and the amount of LP shares the user locked into deposit. User’s loyalty factor is reset if the user exits and reenters liquidity mining. User can claim rewards without resetting loyalty factor, only withdrawing shares is penalized by loyalty factor reset. The user is rewarded from the next period after they enters.
Multiple Incentives
This feature allows users to redeposit already deposited LP shares to multiple yield farms and
receive incentives from these farms.
Deposit in yield farm is called “farm entry”.
Maximal number of redepositing same LP shares is configured by variable: MaxFarmEntriesPerDeposit
.
Set MaxFarmEntriesPerDeposit
to 1
to disable multiple incentives scheme. !!!NEVER set this
variable to 0
.
LP shares can be redeposited only to different yield farms running liquidity mining for same
pair of assets.
Notes:
- LP shares are returned ONLY if deposit is destroyed - withdrawing LP shares can be used to “free slot” for re-lock LP shares to different yield farm. Withdrawing LP shares result in resetting loyalty factor for yield farm user is withdrawing from(other farm entries in the deposit are not affected). If deposit has no more farm entries, deposit is destroyed and LP shares are returned back to user.
YieldFarm
- can be in the 3 states: [Active
,Stopped
,Terminated
]Active
- liquidity mining is running, users are able to deposit, claim and withdraw LP shares.YieldFarm
is rewarded fromGlobalFarm
in this state.Stopped
- liquidity mining is stopped. Users can claim and withdraw LP shares from the farm. Users CAN’T deposit new LP shares to stopped farm. Stopped farm is not rewarded from theGlobalFarm
. Note: stopped farm can be resumed or destroyed.Terminated
- liquidity mining is ended. User’s CAN’T deposit or claim rewards from stopped farm. Users CAN only withdraw LP shares(without rewards).YieldFarm
must be stopped before it can be terminated. Terminated farm stays in the storage until last farm’s entry is withdrawn. Last withdrawn from yield farm will remove terminated farm from the storage. Note: Terminated farm CAN’T be resumed.
GlobalFarm
- can be in the 2 states: [Active
,Terminated
]Active
- liquidity mining program is running, new yield farms can be added to the global farm.Terminated
- liquidity mining program is ended. Yield farms can’t be added to the global farm. Global farm MUST be empty(all yield farms in the global farm must be destroyed) before it can be destroyed. Destroying global farm transfer undistributed rewards to farm’s owner. Terminated global farm stay in the storage until all yield farms are removed from the storage. Last yield farm removal from storage triggers global farm removal from storage. Note: Terminated global farm CAN’T be resumed.
- Pot - account holding all rewards allocated for all
YieldFarm
s from allGlobalFarm
s. User’s rewards are transferred frompot
’s account to user’s accounts.
Re-exports
pub use pallet::*;
Modules
Structs
PriceAdjustment
trait which returns price_adjustment
value saved
in GlobalFarm
.MaxEntriesPerDeposit
).
The LP token’s lock in the deposit is called “farm entry”. Farm entry entitles deposit
owner to accumulate rewards from the yield farm.
Every deposit should have at least one farm entry and deposit without farm entries
should be removed from storage and LP shares should be unlocked.
redeposit_lp_shares()
is used to add a new farm entry into the deposit(“re-lock” LP shares“).YieldFarm
s are rewarded from
GlobalFarm
based on their stake in GlobalFarm
. YieldFarm
stake in GlobalFarm
is derived from
users stake in YieldFarm
.
Yield farm is considered live from global farm view if yield farm is active
or stopped
.