LiquidityPools
The Liquidity Pools pallet is a fully permissionless Substrate pallet that enables the creation and management of liquidity pools for any asset pair. It provides a flexible framework for users to stake their assets in pools and earn rewards, with automatic rollover capabilities to maintain continuous participation across successive pools.
Calls
create_pool
Creates a new liquidity pool specifying reward and staked asset IDs, interest rate, maximum token limit, and lock period (start and end blocks). Anyone can create a pool without special permissions.
Namespace
api.tx.liquidityPools.createPoolType
function create_pool(reward_asset_id: u32, staked_asset_id: u32, interest_rate: u32, max_tokens: u128, lock_start_block: u32, lock_end_block: u32)set_pool_succession
Links a predecessor pool to a successor pool, enabling automatic rollover of user stakes when the predecessor pool completes its cycle.
Namespace
api.tx.liquidityPools.setPoolSuccessionType
function set_pool_succession(predecessor_pool_id: u32, successor_pool_id: u32)set_pool_rollover
Lets users opt in or out of automatic rollover to the successor pool when the current pool matures.
Namespace
api.tx.liquidityPools.setPoolRolloverType
function set_pool_rollover(id: u32, should_rollover: bool)close_pool
Allows a pool creator to close their pool. Upon closing, only unclaimed reward tokens are returned to the creator. Staked tokens remain in the pool for users to withdraw. The pool remains in the Closed state until all user funds are withdrawn.
Namespace
api.tx.liquidityPools.closePoolType
function close_pool(id: u32)enter_pool
Enables users to join an open pool by staking their assets up to the pool's maximum capacity.
Namespace
api.tx.liquidityPools.enterPoolType
function enter_pool(pool_id: u32, amount: u128)exit_pool
Permits users to withdraw their staked assets from an Open pool before the lock period begins, and also from a Closed pool after the pool has been manually closed by the creator.
Namespace
api.tx.liquidityPools.exitPoolType
function exit_pool(id: u32)claim_reward
Allows users to claim their earned rewards after a pool matures. If the user opted out of rollover, their principle is also returned.
Namespace
api.tx.liquidityPools.claimRewardType
function claim_reward(id: u32)rollover_unsigned
An internal extrinsic executed by the offchain worker to process the automatic rollover of user stakes.
Namespace
api.tx.liquidityPools.rolloverUnsignedType
function rollover_unsigned(id: u32, current_block: u32)Storage
Pools
Stores information about each liquidity pool
Namespace
api.query.liquidityPools.poolsType
function pools(pool_id: u32) -> Option<PoolInfo>PoolUsers
Tracks user participation in pools
Namespace
api.query.liquidityPools.poolUsersType
function poolUsers(pool_id: u32, account_id: AccountId) -> Option<UserInfo>PoolRelationships
Maps predecessor pools to successor pools
Namespace
api.query.liquidityPools.poolRelationshipsType
function poolRelationships(pool_id: u32) -> Option<PoolRelationship>NextPoolId
Increment-only unique pool id
Namespace
api.query.liquidityPools.nextPoolIdType
function nextPoolId() -> u32NextRolloverUnsignedAt
Tracks when next rollover should occur
Namespace
api.query.liquidityPools.nextRolloverUnsignedAtType
function nextRolloverUnsignedAt() -> u32RolloverPivot
Tracks progress during batch rollover operations
Namespace
api.query.liquidityPools.rolloverPivotType
function rolloverPivot(pool_id: u32) -> BoundedVec<u8, MaxStringLength>ProcessedPoolPivot
Tracks the next pool id pivot used for batched processing during on_idle.
Namespace
api.query.liquidityPools.processedPoolPivotType
function processedPoolPivot() -> u32Events
PoolOpen
When a new pool is created
Namespace
api.events.liquidityPools.PoolOpenType
struct PoolOpen {
pool_id: u32,
reward_asset_id: u32,
staked_asset_id: u32,
interest_rate: u32,
max_tokens: u128,
lock_start_block: u32,
lock_end_block: u32
}PoolStarted
When a pool enters lock period
Namespace
api.events.liquidityPools.PoolStartedType
struct PoolStarted {
pool_id: u32
}PoolRenewing
When a pool starts rollover process
Namespace
api.events.liquidityPools.PoolRenewingType
struct PoolRenewing {
pool_id: u32
}PoolMatured
When a pool is ready for rewards claiming
Namespace
api.events.liquidityPools.PoolMaturedType
struct PoolMatured {
pool_id: u32
}PoolClosed
When a pool is closed
Namespace
api.events.liquidityPools.PoolClosedType
struct PoolClosed {
pool_id: u32,
reward_asset_amount: u128,
staked_asset_amount: u128,
receiver: AccountId
}Note: On close, only reward tokens are transferred to the creator; users must exit to withdraw staked tokens.
SetSuccession
When pools are linked for rollover
Namespace
api.events.liquidityPools.SetSuccessionType
struct SetSuccession {
predecessor_pool_id: u32,
successor_pool_id: u32
}UserInfoUpdated
When user rollover preference is updated
Namespace
api.events.liquidityPools.UserInfoUpdatedType
struct UserInfoUpdated {
pool_id: u32,
account_id: AccountId,
should_rollover: bool
}UserJoined
When user joins a pool
Namespace
api.events.liquidityPools.UserJoinedType
struct UserJoined {
account_id: AccountId,
pool_id: u32,
amount: u128
}UserExited
When user exits a pool
Namespace
api.events.liquidityPools.UserExitedType
struct UserExited {
account_id: AccountId,
pool_id: u32,
amount: u128
}UserRolledOver
When user is rolled over to successor pool
Namespace
api.events.liquidityPools.UserRolledOverType
struct UserRolledOver {
account_id: AccountId,
pool_id: u32,
rolled_to_pool_id: u32,
amount: u128
}RewardsClaimed
When rewards are claimed
Namespace
api.events.liquidityPools.RewardsClaimedType
struct RewardsClaimed {
account_id: AccountId,
pool_id: u32,
amount: u128
}Errors
NotPoolCreator
Caller is not the pool creator
Namespace
api.errors.liquidityPools.NotPoolCreatorInvalidBlockRange
Invalid block range for pool
Namespace
api.errors.liquidityPools.InvalidBlockRangePoolAlreadyExists
Pool already exists
Namespace
api.errors.liquidityPools.PoolAlreadyExistsPoolDoesNotExist
Pool does not exist
Namespace
api.errors.liquidityPools.PoolDoesNotExistSuccessorPoolDoesNotExist
Successor pool does not exist
Namespace
api.errors.liquidityPools.SuccessorPoolDoesNotExistPredecessorPoolDoesNotExist
Predecessor pool does not exist
Namespace
api.errors.liquidityPools.PredecessorPoolDoesNotExistSuccessorPoolSizeShouldBeGreaterThanPredecessor
Successor pool too small
Namespace
api.errors.liquidityPools.SuccessorPoolSizeShouldBeGreaterThanPredecessorSuccessorPoolSizeShouldBeLockedAfterPredecessor
Invalid successor timing
Namespace
api.errors.liquidityPools.SuccessorPoolSizeShouldBeLockedAfterPredecessorRolloverPoolsShouldBeTheSameAsset
Asset mismatch between pools
Namespace
api.errors.liquidityPools.RolloverPoolsShouldBeTheSameAssetNoTokensStaked
No tokens staked for operation
Namespace
api.errors.liquidityPools.NoTokensStakedPoolNotOpen
Pool not in open state
Namespace
api.errors.liquidityPools.PoolNotOpenNotReadyForClaimingReward
Pool not mature for claiming
Namespace
api.errors.liquidityPools.NotReadyForClaimingRewardNoAvailablePoolId
Exceeds maximum pool ID
Namespace
api.errors.liquidityPools.NoAvailablePoolIdStakingLimitExceeded
Pool capacity limit reached
Namespace
api.errors.liquidityPools.StakingLimitExceededOffchainErrNotValidator
Offchain worker not validator
Namespace
api.errors.liquidityPools.OffchainErrNotValidatorOffchainErrTooEarly
Offchain worker called too early
Namespace
api.errors.liquidityPools.OffchainErrTooEarlyOffchainErrSubmitTransaction
Offchain transaction submission error
Namespace
api.errors.liquidityPools.OffchainErrSubmitTransactionOffchainErrWrongTransactionSource
Offchain transaction source error
Namespace
api.errors.liquidityPools.OffchainErrWrongTransactionSourcePivotStringTooLong
Pivot string exceeds maximum length
Namespace
api.errors.liquidityPools.PivotStringTooLongPoolAlreadyClosed
Pool is already in the Closed state
Namespace
api.errors.liquidityPools.PoolAlreadyClosedCannotExitPool
Cannot exit the pool in the current state or conditions
Namespace
api.errors.liquidityPools.CannotExitPoolRewardCalculationOverflow
Overflow occurred during reward calculation
Namespace
api.errors.liquidityPools.RewardCalculationOverflow