💸Asset

Utils to transfer and query Terra native assets and CW20 tokens

1. Summary

The Asset file defines data structures meant to hold information about an asset and an asset amount as well as logic used to transfer native Terra assets. It also defines logic to display asset information as well as query a pair. Finally, it defines a struct used to hold data about a specific pair (LP token address, tokens in the pool etc).

2. Variables and Functions

Params

Name
Description

DECIMAL_FRACTION

Asset decimal points

Constants

Name
Description

TOKEN_SYMBOL_MAX_LENGTH

The max accepted length for a token symbol

Structs

Name
Description
Contains

Asset

This struct describes a Terra asset (native or CW20).

  • info - Information about the asset (stored in a AssetInfo struct)

  • amount - An amount of Asset

PairInfo

This struct holds information about an Astroport pair.

  • asset_infos - information about the assets in the pool (each asset being defined by an AssetInfo)

  • contract_addr - the pair contract address

  • liquidity_token - the address of the LP token associated with the pair

  • pair_type - the pair type (XYK, stableswap etc)

Struct Logic

Name
Description

fmt::Display:Asset

Logic to display asset information and an asset amount

Asset

Implementation has general logic to compute and deduct a tax for transferring a native asset. It also has logic to determine whether an asset is Terra native

PairInfo

Implementation contains logic to query asset balances from a pair

Enums

  • AssetInfo - this enum describes available token types (native and non-native Terra token)

Enum Logic

Name
Description

fmt::Display:AssetInfo

Displays the denomination for a native Terra asset or the contract address for a CW20 token

The implementation has general logic to check whether an asset is Terra native and a query to return the balance of an asset in a pool contract

Functions

Name
Params
Description

addr_validate_to_lower

(api: &dyn Api, addr: &str) -> StdResult<Addr>

Returns a lowercased, validated address upon success

format_lp_token_name

(asset_infos: [AssetInfo; 2], querier: &QuerierWrapper) -> StdResult<String>

Returns a formatted LP token name using the asset symbols (assets that are in a specific pool associated with the LP token)

native_asset

(denom: String, amount: Uint128) -> Asset

Returns an Asset struct containing information about a native Terra asset

token_asset

(contract_addr: Addr, amount: Uint128) -> Asset

Returns an Asset struct containing information about a non-native asset

native_asset_info

(denom: String) -> AssetInfo

Returns a AssetInfo::NativeToken

token_asset_info

(contract_addr: Addr) -> AssetInfo

Returns a AssetInfo::Token

Last updated

Was this helpful?