Contract Interface
1. Notations & Structs
1.1. PoolResultType
Copy pub type PoolResultType < BigUint > = ManagedVec < BigUint , EsdtTokenPayment < BigUint >>;
1.2. TokenAttributes
Copy pub struct TokenAttributes < M : ManagedTypeApi > {
pub reserve : BigUint < M >,
pub rate : BigUint < M >,
}
1.3. AddLiquidityAttributes
Copy pub struct AddLiquidityAttributes < M : ManagedTypeApi > {
pub token : TokenIdentifier < M >,
pub attribute : TokenAttributes < M >,
pub amount_added : BigUint < M >,
pub total_fee : BigUint < M >,
pub admin_fee : BigUint < M >,
}
1.4. AddLiquidityEvent
Copy pub struct AddLiquidityEvent < M : ManagedTypeApi > {
lp_token_amount : BigUint < M >,
lp_token_supply : BigUint < M >,
tokens : ManagedVec < M , AddLiquidityAttributes < M >>,
}
1.5. RemoveLiquidityAttributes
Copy pub struct RemoveLiquidityAttributes < M : ManagedTypeApi > {
pub token : TokenIdentifier < M >,
pub attribute : TokenAttributes < M >,
pub amount_removed : BigUint < M >,
}
1.6. RemoveLiquidityEvent
Copy pub struct RemoveLiquidityEvent < M : ManagedTypeApi > {
lp_token_amount : BigUint < M >,
lp_token_supply : BigUint < M >,
tokens : ManagedVec < M , RemoveLiquidityAttributes < M >>,
}
1.7. RemoveLiquidityOneCoinEvent
Copy pub struct RemoveLiquidityOneCoinEvent < M : ManagedTypeApi > {
lp_token_amount : BigUint < M >,
lp_token_supply : BigUint < M >,
total_fee : BigUint < M >,
admin_fee : BigUint < M >,
token_out : RemoveLiquidityAttributes < M >,
}
1.8. ExchangeAttributes
Copy pub struct ExchangeAttributes < M : ManagedTypeApi > {
pub token : TokenIdentifier < M >,
pub attribute : TokenAttributes < M >,
pub final_amount : BigUint < M >,
}
1.9. ExchangeEvent
Copy pub struct ExchangeEvent < M : ManagedTypeApi > {
total_fee : BigUint < M >,
admin_fee : BigUint < M >,
token_in : ExchangeAttributes < M >,
token_out : ExchangeAttributes < M >,
}
2. Write functions
2.1. Add liquidity
Copy #[payable( "*" )]
#[endpoint(addLiquidity)]
fn add_liquidity ( & self, mint_amount_min : BigUint , lp_token_receiver : & ManagedAddress ) -> PoolResultType <Self :: Api >
2.2. Remove liquidity
Copy #[payable( "*" )]
#[endpoint(removeLiquidity)]
fn remove_liquidity ( & self, token_amount_min : MultiValueEncoded < BigUint >) -> PoolResultType <Self :: Api >
2.3. Exchange
Copy #[payable( "*" )]
#[endpoint(exchange)]
fn exchange ( & self, token_out : TokenIdentifier , amount_out_min : BigUint ) -> PoolResultType <Self :: Api >
token_out
: The token id that you want to receive after exchanging.
amount_out_min
: The minimum amount of token_out
that you will receive. If the pool returns an amount that is smaller than amount_out_min
the transaction will be reverted.
3. Read functions
3.1. Estimate the exchange output
Copy #[derive( TopEncode , TopDecode , NestedEncode , NestedDecode , PartialEq , TypeAbi , Clone , ManagedVecItem )]
pub struct TokenAttributes < M : ManagedTypeApi > {
pub reserve : BigUint < M >,
pub rate : BigUint < M >,
}
#[derive( TopEncode , TopDecode , NestedEncode , NestedDecode , PartialEq , TypeAbi , Clone , ManagedVecItem )]
pub struct ExchangeAttributes < M : ManagedTypeApi > {
pub token : TokenIdentifier < M >,
pub attribute : TokenAttributes < M >,
pub final_amount : BigUint < M >,
}
#[derive( TopEncode , TopDecode , NestedEncode , NestedDecode , PartialEq , TypeAbi , Clone )]
pub struct ExchangeResultType < M : ManagedTypeApi > {
pub total_fee : BigUint < M >,
pub admin_fee : BigUint < M >,
pub token_in : ExchangeAttributes < M >,
pub token_out : ExchangeAttributes < M >,
}
#[view(estimateAmountOut)]
fn get_amount_out(&self, token_in: &TokenIdentifier, token_out: &TokenIdentifier, amount_in: BigUint) -> ExchangeResultType<Self::Api>
3.2. Estimate add liquidity
Copy #[derive( TopEncode , TopDecode , NestedEncode , NestedDecode , PartialEq , TypeAbi , Clone )]
pub struct AddLiquidityResultType < M : ManagedTypeApi > {
pub mint_amount : BigUint < M >,
pub tokens : ManagedVec < M , AddLiquidityAttributes < M >>,
}
#[view(estimateAddLiquidity)]
fn pool_add_liquidity ( & self, token_amount_added : & ManagedVec < BigUint >) -> AddLiquidityResultType <Self :: Api >
3.3. Estimate remove liquidity
Copy #[derive( TopEncode , TopDecode , NestedEncode , NestedDecode , PartialEq , TypeAbi , Clone )]
pub struct RemoveLiquidityResultType < M : ManagedTypeApi > {
pub burn_amount : BigUint < M >,
pub tokens : ManagedVec < M , RemoveLiquidityAttributes < M >>,
}
#[view(estimateRemoveLiquidity)]
fn pool_remove_liquidity ( & self, burn_amount : BigUint ) -> RemoveLiquidityResultType <Self :: Api >
3.4. Get AMP factor
Copy #[view(getAmpFactor)]
fn get_amp_factor ( & self) -> u64
3.5. Get pool state
Copy #[derive( TopEncode , TopDecode , PartialEq , TypeAbi , Debug )]
pub enum State { Inactive , Active , ActiveNoSwaps }
#[view(getState)]
fn state ( & self) -> State ;
3.6. Get LP token identifier
Copy #[view(getLpTokenIdentifier)]
fn get_lp_token_identifier ( & self) -> TokenIdentifier
3.7. Get LP token supply
Copy #[view(getTotalSupply)]
fn get_lp_token_supply ( & self) -> BigUint
3.8. Get pool tokens
Copy #[view(getTokens)]
fn get_tokens ( & self) -> ManagedVec < TokenIdentifier >
3.9. Get token balances
Copy #[view(getBalances)]
fn get_balances ( & self, token : & TokenIdentifier ) -> BigUint
3.10. Get swap fee
Copy #[view(getSwapFeePercent)]
fn swap_fee_percent ( & self) -> u64 ;
3.11. Get admin fee
Copy #[view(getAdminFeePercent)]
fn admin_fee_percent ( & self) -> u64 ;
4. Events
4.1. Add liquidity
Copy #[event( "add_liquidity" )]
fn add_liquidity_event (
& self,
#[indexed] timestamp : u64 ,
#[indexed] caller : & ManagedAddress ,
add_liquidity_event : & AddLiquidityEvent <Self :: Api >,
);
4.2. Remove liquidity
Copy #[event( "remove_liquidity" )]
fn remove_liquidity_event (
& self,
#[indexed] timestamp : u64 ,
#[indexed] caller : & ManagedAddress ,
remove_liquidity_event : & RemoveLiquidityEvent <Self :: Api >,
);
4.3. Remove liquidity one coin
Copy #[event( "remove_liquidity_one_coin" )]
fn remove_liquidity_one_coin_event (
& self,
#[indexed] timestamp : u64 ,
#[indexed] caller : & ManagedAddress ,
remove_liquidity_one_coin_event : & RemoveLiquidityOneCoinEvent <Self :: Api >,
);
4.4. Exchange
Copy #[event( "exchange" )]
fn exchange_event (
& self,
#[indexed] timestamp : u64 ,
#[indexed] caller : & ManagedAddress ,
exchange_event : & ExchangeEvent <Self :: Api >,
);
Last updated 11 months ago