Expand description
§FRAME Staking Rewards Pallet
Allows accounts to be rewarded for holding fungible
asset/s, for example LP tokens.
§Overview
Initiate an incentive program for a fungible asset by creating a new pool.
During pool creation, a ‘staking asset’, ‘reward asset’, ‘reward rate per block’, ‘expiry block’, and ‘admin’ are specified.
Once created, holders of the ‘staking asset’ can ‘stake’ them in a corresponding pool, which creates a Freeze on the asset.
Once staked, rewards denominated in ‘reward asset’ begin accumulating to the staker, proportional to their share of the total staked tokens in the pool.
Reward assets pending distribution are held in an account unique to each pool.
Care should be taken by the pool operator to keep pool accounts adequately funded with the reward asset.
The pool admin may increase reward rate per block, increase expiry block, and change admin.
§Disambiguation
While this pallet shares some terminology with the staking-pool
and similar native staking
related pallets, it is distinct and is entirely unrelated to native staking.
§Permissioning
Currently, pool creation and management restricted to a configured Origin.
Future iterations of this pallet may allow permissionless creation and management of pools.
Note: The permissioned origin must return an AccountId. This can be achieved for any Origin by
wrapping it with EnsureSuccess
.
§Implementation Notes
Internal logic functions such as update_pool_and_staker_rewards
were deliberately written
without side-effects.
Storage interaction such as reads and writes are instead all performed in the top level pallet Call method, which while slightly more verbose, makes it easier to understand the code and reason about how storage reads and writes occur in the pallet.
§Rewards Algorithm
The rewards algorithm is based on the Synthetix StakingRewards.sol smart contract.
Rewards are calculated JIT (just-in-time), and all operations are O(1) making the approach scalable to many pools and stakers.
§Resources
- This video series, which walks through the math of the algorithm.
- This dev.to article, which explains the algorithm of the SushiSwap MasterChef staking. While not identical to the Synthetix approach, they are quite similar.
Re-exports§
pub use pallet::*;
Modules§
- Asset Rewards pallet benchmarking.
- The
pallet
module in each FRAME pallet hosts the most important items needed to construct this pallet.
Structs§
- The state and configuration of an incentive pool.
- The state of a staker in a pool.
Traits§
- The runtime API for the asset rewards pallet.
- Weight functions needed for
pallet_asset_rewards
.
Type Aliases§
- Unique id type for each pool.
- Convenience alias for
PoolInfo
.