Crate pallet_bootstrap
source ·Expand description
Bootstrap Module
The Bootstrap module provides price discovery mechanism between two tokens. When bootstrap
is finished all provisioned tokens are collected and used for new liquidity token(pool) creation.
From that moment people that participated in bootstrap can claim their liquidity tokens share using
dedicated. Also since that moment its possible to exchange/trade tokens that were bootstraped using Xyk
pallet.
Features
-
Bootstrap pallet is reusable** - after bootstrap between tokens
X
andY
is finished the following one can be scheduled (with different pair of tokens). -
After bootstrap is finished new liquidity token (
Z
) is created and [pallet_xyk
] can be used to: * exchange/tradeX
andY
tokens * mint/burnZ
tokens -
Bootstrap state transition from [
BeforeStart
] -> [Finished
] happens automatically thanks to substrate framework hooks. Only transition fromFinished
->BeforeStart
needs to be triggered manually because cleaning up storage is complex operation and might not fit in a single block.(as it needs to remove a lot of keys/value pair from the runtime storage)
How to bootstrap
- Entity with sudo privileges needs to use
Pallet::schedule_bootstrap
to initiate new bootstrap
1.1 [optional] depending on fact if BootstrapPhase::Whitelist
is enabled entity
with sudo privileges can whitelist particular users using Pallet::whitelist_accounts
1.2 [optional] Pallet::update_promote_bootstrap_pool
can be used to enable or disable
automatic pool promotion of liquidity pool.
1.3 [optional] Pallet::cancel_bootstrap
can be used to cancel bootstrap event
-
When blockchain reaches block that is scheduled as start od the bootstrap participation is automatically enabled:
- in
BootstrapPhase::Whitelist
phase only whitelisted accountsPallet::whitelist_accounts
can participate - in
BootstrapPhase::Public
phase everyone can participate
- in
-
When blockchain reaches block:
current_block_nr > bootstrap_start_block + whitelist_phase_length + public_phase_length
Bootstrap is automatically finished and following participations will not be accepted. Also new
liquidity pool is created from all the tokens gathered during bootstrap (see Valuations
). TokenId
of newly created liquidity token as well as amount of minted tokens is persisted into MintedLiquidity
storage item. All the liquidity token minted as a result of pool creation are now stored in
bootstrap pallet account.
-
Accounts that participated in bootstrap can claim their liquidity pool share. Share is calculated proportionally based on provisioned amount. One can use one of below extrinsics to claim rewards:
-
When every participant of the bootstrap has claimed their liquidity tokens entity with sudo rights can
Pallet::finalize
whole bootstrap event. If there are some accounts that still hasnt claim their tokensPallet::claim_liquidity_tokens_for_account
can be used to do that in behalf of these accounts. WhenPallet::finalize
results withEvent::BootstrapFinalized
Bootstrap is finalized and another bootstrap can be scheduled (as described in 1st point).
Bootstrap has specific lifecycle as presented below:
@startuml
[*] --> BeforeStart
BeforeStart --> Whitelist
BeforeStart --> Public
Whitelist --> Public
Public --> Finished
Finished --> BeforeStart
@enduml
API
Runtime Storage Entries
-
Provisions
- stores information about who provisioned what (non vested tokens) -
VestedProvisions
- stores information about who provisioned what (vested tokens) -
WhitelistedAccount
- list of accounts allowed to participate inBootstrapPhase::Whitelist
-
Phase
- current state of bootstrap -
Valuations
- sum of all provisions in active bootstrap -
BootstrapSchedule
- parameters of active bootstrap stored as for more details checkPallet::schedule_bootstrap
[
block_nr: T::BlockNumber,
first_token_id: u32,
second_token_id: u32,
[
ratio_numerator:u128,
ratio_denominator:u128
]
]
-
ClaimedRewards
- how many liquidity tokens has user already after bootstrapBootstrapPhase::Public
period has finished. -
ProvisionAccounts
- list of participants that hasnt claim their tokens yet -
ActivePair
- bootstraped pair of tokens
Extrinsics
Pallet::schedule_bootstrap
Pallet::whitelist_accounts
Pallet::update_promote_bootstrap_pool
Pallet::cancel_bootstrap
Pallet::provision
Pallet::claim_liquidity_tokens
Pallet::claim_liquidity_tokens_for_account
Pallet::claim_and_activate_liquidity_tokens
Pallet::finalize
for more details see click
Re-exports
pub use weights::WeightInfo;
pub use pallet::*;
Modules
- The
pallet
module in each FRAME pallet hosts the most important items needed to construct this pallet. - Autogenerated weights for pallet_bootstrap