4 releases

0.1.3 Feb 13, 2023
0.1.2 Feb 13, 2023
0.1.1 Feb 13, 2023
0.1.0 Feb 13, 2023

#19 in #astroport

MPL-2.0 license

74KB
2K SLoC

Astroport: Common Types

This is a collection of common types and the queriers which are commonly used in astroport contracts.

Data Types

AssetInfo

AssetInfo is a convenience wrapper to represent the native token and the contract token as a single type.

#[serde(rename_all = "snake_case")]
pub enum AssetInfo {
    Token { contract_addr: Addr },
    NativeToken { denom: String },
}

Asset

It contains asset info with the amount of token.

pub struct Asset {
    pub info: AssetInfo,
    pub amount: Uint128,
}

PairInfo

It is used to represent response data of Pair-Info-Querier

pub struct PairInfo {
    pub contract_addr: Addr,
    pub asset_infos: [AssetInfo; 2],
    pub liquidity_token: Addr,
    pub pair_type: PairType,
}

Queriers

Native Token Balance Querier

It uses CosmWasm standard interface to query the account balance to chain.

pub fn query_balance(
    deps: &Extern<S, A, Q>,
    account_addr: &Addr,
    denom: String,
) -> StdResult<Uint128>

Token Balance Querier

It provides similar query interface with Native-Token-Balance-Querier for CW20 token balance.

pub fn query_token_balance(
    deps: &Extern<S, A, Q>,
    contract_addr: &Addr,
    account_addr: &Addr,
) -> StdResult<Uint128>

Token Supply Querier

It provides token supply querier for CW20 token contract.

pub fn query_supply(
    deps: &Extern<S, A, Q>,
    contract_addr: &Addr,
) -> StdResult<Uint128>

Pair Info Querier

It also provides the query interface to query available astroport pair contract info. Any contract can query pair info to astroport factory contract.

pub fn query_pair_contract(
    deps: &Extern<S, A, Q>,
    contract_addr: &Addr,
    asset_infos: &[AssetInfo; 2],
) -> StdResult<Addr>

Liquidity Token Querier

It returns liquidity token contract address of astroport pair contract.

pub fn query_liquidity_token(
    deps: &Extern<S, A, Q>,
    contract_addr: &Addr,
) -> StdResult<Addr>

Swap Pairs Simulating

Simulate

Returns simulation swap return, spread, commission amounts.

pub fn simulate(
    querier: &QuerierWrapper,
    pair_contract: Addr,
    offer_asset: &Asset,
) -> StdResult<SimulationResponse>

Reverse Simulate

Returns simulation swap offer, spread, commission amounts.

pub fn reverse_simulate(
    querier: &QuerierWrapper,
    pair_contract: Addr,
    offer_asset: &Asset,
) -> StdResult<ReverseSimulationResponse>

Dependencies

~4–6MB
~131K SLoC