AshSwap Docs
Search
K

Stable Pool

This pool type contain stable tokens

Contract Interface

1. Notations & Structs

1.1. PoolResultType

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

1.2. TokenAttributes

pub struct TokenAttributes<M: ManagedTypeApi> {
pub reserve: BigUint<M>,
pub rate: BigUint<M>,
}

1.3. AddLiquidityAttributes

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

pub struct AddLiquidityEvent<M: ManagedTypeApi> {
lp_token_amount: BigUint<M>,
lp_token_supply: BigUint<M>,
tokens: ManagedVec<M, AddLiquidityAttributes<M>>,
}

1.5. RemoveLiquidityAttributes

pub struct RemoveLiquidityAttributes<M: ManagedTypeApi> {
pub token: TokenIdentifier<M>,
pub attribute: TokenAttributes<M>,
pub amount_removed: BigUint<M>,
}

1.6. RemoveLiquidityEvent

pub struct RemoveLiquidityEvent<M: ManagedTypeApi> {
lp_token_amount: BigUint<M>,
lp_token_supply: BigUint<M>,
tokens: ManagedVec<M, RemoveLiquidityAttributes<M>>,
}

1.7. RemoveLiquidityOneCoinEvent

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

pub struct ExchangeAttributes<M: ManagedTypeApi> {
pub token: TokenIdentifier<M>,
pub attribute: TokenAttributes<M>,
pub final_amount: BigUint<M>,
}

1.9. ExchangeEvent

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

#[payable("*")]
#[endpoint(addLiquidity)]
fn add_liquidity(&self, mint_amount_min: BigUint, lp_token_receiver: &ManagedAddress) -> PoolResultType<Self::Api>

2.2. Remove liquidity

#[payable("*")]
#[endpoint(removeLiquidity)]
fn remove_liquidity(&self, token_amount_min: MultiValueEncoded<BigUint>) -> PoolResultType<Self::Api>

2.3. Exchange

#[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

#[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. Get AMP factor

#[view(getAmpFactor)]
fn get_amp_factor(&self) -> u64

3.3. Get pool state

#[derive(TopEncode, TopDecode, PartialEq, TypeAbi, Debug)]
pub enum State { Inactive, Active, ActiveNoSwaps }
#[view(getState)]
fn state(&self) -> State;

3.4. Get LP token identifier

#[view(getLpTokenIdentifier)]
fn get_lp_token_identifier(&self) -> TokenIdentifier

3.5. Get LP token supply

#[view(getTotalSupply)]
fn get_lp_token_supply(&self) -> BigUint

3.6. Get pool tokens

#[view(getTokens)]
fn get_tokens(&self) -> ManagedVec<TokenIdentifier>

3.7. Get token balances

#[view(getBalances)]
fn get_balances(&self, token: &TokenIdentifier) -> BigUint

3.8. Get swap fee

#[view(getSwapFeePercent)]
fn swap_fee_percent(&self) -> u64;

3.9. Get admin fee

#[view(getAdminFeePercent)]
fn admin_fee_percent(&self) -> u64;

4. Events

4.1. Add liquidity

#[event("add_liquidity")]
fn add_liquidity_event(
&self,
#[indexed] timestamp: u64,
#[indexed] caller: &ManagedAddress,
add_liquidity_event: &AddLiquidityEvent<Self::Api>,
);

4.2. Remove liquidity

#[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

#[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

#[event("exchange")]
fn exchange_event(
&self,
#[indexed] timestamp: u64,
#[indexed] caller: &ManagedAddress,
exchange_event: &ExchangeEvent<Self::Api>,
);