bifrost defi
Bifrost is a parachain that allows users to deposit their staking tokens and mint vTokens to get staking liquidity.
Theory
KnowledgeBase
Concepts
Dependency
Runtimes
// bifrost runtime modules
Assets: brml_assets::{Module, Call, Storage, Event<T>, Config<T>} = 10,
VtokenMint: brml_vtoken_mint::{Module, Call, Storage, Event, Config<T>} = 11,
Swap: brml_swap::{Module, Call, Storage, Event<T>} = 12,
StakingReward: brml_staking_reward::{Module, Storage} = 13,
Voucher: brml_voucher::{Module, Call, Storage, Event<T>, Config<T>} = 14,
Bid: brml_bid::{Module, Call, Storage, Event<T>} = 15,
Assets
create token asset
Assets::create(Origin::root(), b"BNC".to_vec(), 18, TokenType::Stable)
create token pair
Assets::create_pair(Origin::root(), b"DOT".to_vec(), 18)
issue token to account
Assets::issue(Origin::root(), dot_id, alice, 30_000)
VtokenMint
convert token to vtoken
VtokenMint::to_vtoken(Origin::signed(bob), vdot_id, bob_dot_mint, None)
convert vtoken to token
VtokenMint::to_token(Origin::signed(bob), dot_id, bob_vdot_mint)
Swap
create a new pool
Swap::create_pool(creator, swap_fee_rate, token_for_pool_vec)
Add liquidity by providing all of the tokens in proportion
Swap::add_liquidity_given_shares_in(creator, pool_id, new_pool_token)
removes liquidity of all the tokens in the pool in proportion
Swap::remove_assets_liquidity_given_shares_in(origin, pool_id: T::PoolId,#[compact] pool_amount_out: T::PoolToken)
swap one token for another kind of token
Swap::swap_exact_in(origin,pool_id: T::PoolId,
token_in_asset_id: T::AssetId,
#[compact]token_amount_in: T::Balance, // the input token amount that the user is willing to pay.
min_token_amount_out: Option<T::Balance>, // The least output token amount that the user can accept
token_out_asset_id: T::AssetId)
Bid
apis
Register a vtoken for bidding
fn register_vtoken_for_bidding(origin, vtoken: T::AssetId) -> DispatchResult
Create a bidding proposal
fn create_bidding_proposal(origin, vtoken: T::AssetId, #[compact] votes_needed: T::Balance, roi: u32, validator: T::AccountId)
storage
Bidder proposals in queue which haven’t been matched
BidderProposalInQueue get(fn bidder_proposal_in_queue): double_map
hasher(blake2_128_concat) T::AccountId,
hasher(blake2_128_concat) T::AssetId
=> Vec<T::BiddingOrderId>;
orders in service(key is id, value is BiddingOrderUnit struct)
OrdersInService get(fn orders_in_service): map hasher(blake2_128_concat) T::BiddingOrderId
=> BiddingOrderUnitOf<T>;