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 and Y 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/trade X and Y tokens * mint/burn Z tokens

  • Bootstrap state transition from [BeforeStart] -> [Finished] happens automatically thanks to substrate framework hooks. Only transition from Finished -> 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

  1. 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

  1. When blockchain reaches block that is scheduled as start od the bootstrap participation is automatically enabled:

  2. 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.

  1. 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:

  2. 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 tokens Pallet::claim_liquidity_tokens_for_account can be used to do that in behalf of these accounts. When Pallet::finalize results with Event::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

[
          block_nr: T::BlockNumber,
          first_token_id: u32,
          second_token_id: u32,
          [
                  ratio_numerator:u128,
                  ratio_denominator:u128
          ]
]

Extrinsics

for more details see click

Re-exports

Modules

  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
  • Autogenerated weights for pallet_bootstrap

Macros

Enums