Crypto Pool

This pool type will contain not-equivalent-value tokens

Contract Interface

1. Notations & Structs

1.1. PoolResultType

pub type PoolResultType<BigUint> = ManagedVec<BigUint, EsdtTokenPayment<BigUint>>;

1.2. AddLiquidityEvent

pub struct AddLiquidityEvent<M: ManagedTypeApi> {
    pub token_amounts: ManagedVec<M, BigUint<M>>,
    pub fee: BigUint<M>,
    pub lp_token_supply: BigUint<M>,
    pub lp_token_amount: BigUint<M>,

1.3. RemoveLiquidityEvent

pub struct RemoveLiquidityEvent<M: ManagedTypeApi> {
    pub token_amounts: ManagedVec<M, BigUint<M>>,
    pub lp_token_supply: BigUint<M>,
    pub lp_token_amount: BigUint<M>,

1.4. TokenExchangeEvent

pub struct TokenExchangeEvent<M: ManagedTypeApi> {
    pub sold_id: TokenIdentifier<M>,
    pub tokens_sold: BigUint<M>,
    pub bought_id: TokenIdentifier<M>,
    pub tokens_bought: BigUint<M>,

2. Write functions

2.1. Add liquidity

fn add_liquidity(&self, min_mint_amount: BigUint, opt_receiver: OptionalValue<ManagedAddress>) -> BigUint;

2.2. Remove liquidity

fn remove_liquidity(&self, min_amounts: ManagedVec<BigUint>, opt_receiver: OptionalValue<ManagedAddress>) -> ManagedVec<BigUint>

2.3. Exchange

fn exchange(&self, min_dy: BigUint) -> BigUint;

dy: the minimum amount of the output token

3. Read functions

3.1. Estimate the return of exchanging

fn get_dy(self, i: usize, j: usize, dx: BigUint) -> MultiValue2<BigUint, BigUint>

dx: input token amount

i: input token index

j: output token index

3.2. Get pool state

#[derive(TopEncode, TopDecode, PartialEq, TypeAbi, Debug)]
pub enum State { Inactive, Active, ActiveNoSwaps }

fn state(&self) -> State;

3.3. Get LP token identifier

fn get_lp_token_identifier(&self) -> TokenIdentifier

3.4. Get LP token supply

fn get_lp_token_supply(&self) -> BigUint

Get pool tokens

fn get_tokens(&self) -> ManagedVec<TokenIdentifier>

3.5. Get token balances

fn get_balances(&self) -> ManagedVec<BigUint>

4. Events

4.1. Token exchange

fn token_exchange_event(
    #[indexed] buyer: ManagedAddress<Self::Api>,
    token_exchange_event: &TokenExchangeEvent<Self::Api>,

4.2. Add liquidity

fn add_liquidity_event(
    #[indexed] provider: ManagedAddress<Self::Api>,
    add_liquidity_event: &AddLiquidityEvent<Self::Api>,

4.3. Remove liquidity

fn remove_liquidity_event(
    #[indexed] provider: ManagedAddress<Self::Api>,
    remove_liquidity_event: &RemoveLiquidityEvent<Self::Api>,

Last updated