16 stable releases (4 major)

5.0.0-rc.2-tokenfactory May 13, 2024
3.12.2 Mar 26, 2024
3.6.1 Oct 23, 2023
2.10.0-rc.1 Feb 9, 2024
0.3.1 Dec 15, 2021

#1218 in Magic Beans

Download history 1634/week @ 2024-02-10 963/week @ 2024-02-17 1337/week @ 2024-02-24 1075/week @ 2024-03-02 1147/week @ 2024-03-09 1068/week @ 2024-03-16 1126/week @ 2024-03-23 968/week @ 2024-03-30 821/week @ 2024-04-06 661/week @ 2024-04-13 808/week @ 2024-04-20 1107/week @ 2024-04-27 729/week @ 2024-05-04 818/week @ 2024-05-11 561/week @ 2024-05-18 566/week @ 2024-05-25

2,808 downloads per month
Used in 37 crates (29 directly)

Apache-2.0

215KB
4.5K SLoC

Astroport: Common Types

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

Data Types

AssetInfo

AssetInfo is a convenience wrapper to represent whether a token is the native one (from a specific chain, like LUNA for Terra) or not. It also returns the contract address of that token.

pub enum AssetInfo {
    Token { contract_addr: Addr },
    NativeToken { denom: String },
}

Asset

It contains asset info and a token amount.

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

PairInfo

It is used to represent response data coming from a Pair-Info-Querier.

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

Queriers

Native Token Balance Querier

It uses the CosmWasm standard interface to query an account's balance.

pub fn query_balance(
    querier: &QuerierWrapper,
    account_addr: impl Into<String>,
    denom: impl Into<String>,
) -> StdResult<Uint128>

Token Balance Querier

It provides a similar query interface to Native-Token-Balance-Querier for fetching CW20 token balances.

pub fn query_token_balance(
    querier: &QuerierWrapper,
    contract_addr: impl Into<String>,
    account_addr: impl Into<String>,
) -> StdResult<Uint128>

Token Supply Querier

It fetches a CW20 token's total supply.

pub fn query_supply(
    querier: &QuerierWrapper,
    contract_addr: impl Into<String>,
) -> StdResult<Uint128>

Pair Info Querier

Accepts two tokens as input and returns a pair's information.

pub fn query_pair_info(
    querier: &QuerierWrapper,
    factory_contract: impl Into<String>,
    asset_infos: &[AssetInfo; 2],
) -> StdResult<PairInfo>

Swap Pairs Simulating

Simulate

Simulates a swap and returns the output amount, the spread and commission amounts.

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

Reverse Simulate

Simulates a reverse swap and returns an input amount, the spread and commission amounts.

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

Dependencies

~11MB
~221K SLoC