Skip to main content

Pair

Each pair contract contains a reserve pair of the two assets from the liquidity providers who deposited and they mint the corresponding Liquidity Provider (LP) tokens to the providers. It is also the main handler of any swaps within the pair of assets held, and is usually called by the router contract.

InstantiateMsg

The InstantiateMsg for the pair contract's instantiation is shown below.

instantiate
{
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"token_code_id": 123,
"asset_decimals": [ 6, 6 ],
"requirements": {
"whitelist": [
"aura...",
"aura..."
],
"first_asset_minimum": 10000,
"second_asset_minimum": 20000
},
"commission_rate": "0.003",
"lp_token_info": {
"lp_token_name": "AURA_HALO_LP",
"lp_token_symbol": "AURA_HALO_LP",
},
}

Where:

  • asset_infos is the list of assets in the pair (The pair can be token<->native, token-token or native-native).
  • token_code_id is the source code id of halo-token contract.
  • asset_decimals is the list of decimals of assets in the pair.
  • requirements is the whitelist wallet address list and requirements for providing liquidity for the first time.
  • commission_rate is the commission rate of the pair.
  • lp_token_info is the information of the LP token.

ExecuteMsg

Below are the available ExecuteMsg (write) methods for the pair contract.

ProvideLiquidity

The provide_liquidity method is used to add a pair of assets to a pair contract's pool. The method takes three argumentsL the assets pair (required), the slippage tolerance value (optional) and the LP token receiver (optional).

provide_liquidity
{
"provide_liquidity" {
"assets": [
{
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
},
{
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
],
"slippage_tolerance": 5,
"receiver": "aura...",
}
}

Where:

  • assets is the list of assets that the sender wants to provide to the contract.
    • contract_addr is used if the asset is a token.
    • denom is used if the asset is native_token.
  • slippage_tolerance is the maximum amount of slippage tolerance that the user is willing to accept. The value is in percentage. The transaction will fail if the real value exceeds the specification set.
  • receiver is the address of the receiver who will receive the LP Token. If it's not provided, the sender will receive the tokens.

WithdrawLiquidity

The withdraw_liquidity method is used to remove an amount of pair of assets from the pair contract's pool. This is used to retrieve the tokens that the user has provided to the liquidity pool as well as any rewards that may have been earned from the trading fees. When withdrawing liquidity, the LP token is burned and the user will receive their share and any earned rewards.

To withdraw liquidity, the user will send the LP Tokens to the corresponding pair using a send message of CW20 spec.

withdraw_liquidity
// define the hook cw20 message
const hookMsg = {
"withdraw_liquidity": { }
}

So, the message to send LP Tokens to the paircontract should look like this:

send
// define the hook cw20 message
const hookMsg = {
"withdraw_liquidity": { }
}

// define the exectute send for cw20
const executeSendMsg = {
"send": {
"contract": "pair_contract_address",
"amount": "100000000",
"msg": Buffer.from(JSON.stringify(hookMsg)).toString('base64')
}
}

Swap

The swap method is used execute a trade between the assets contained in the pair contract's pool.

swap
{
"swap": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
},
"belief_price": None,
"max_spread": None,
"to": "aura...",
},
}

Where:

  • offer_asset is the asset that the sender wants to swap.
  • belief_price is the belief price of the swap.
  • max_spread is the maximum spread of the swap.

QueryMsg

Below are the available QueryMsg (read) methods for the pair contract.

Pair

Each pair contract contains the information of a pool and their assets. You can query this using the pair QueryMsg method which returns a PairInfo response type.

pair
{
"pair": {}
}

The response is a PairInfo struct shown below.

PairInfo
pub struct PairInfo {
pub asset_infos: [AssetInfo; 2],
pub contract_addr: String,
pub liquidity_token: String,
pub asset_decimals: [u8; 2],
pub requirements: CreatePairRequirements,
}

Where:

  • asset_infos can be a Token or NativeToken.
AssetInfo
pub enum AssetInfo {
Token { contract_addr: String },
NativeToken { denom: String },
}
  • contract_addr is the address of the pair contract itself.
  • liquidity_token is the address of the LP token of the pair.
  • asset_decimals is the decimal number for the two assets.
  • requirements is the address of the user or users who can provide liquidity for the first time and the minimum amount when using provide_liquidity.

Pool

The pool QueryMsg provides the current information about the pools stats. It returns a PoolResponse response type.

pool:QueryMsg
{
"pool": {}
}

The PoolResponse struct is shown below:

PoolResponse
pub struct PoolResponse {
pub assets: [Asset; 2],
pub total_share: Uint128,
}

Simulation

The simulation QueryMsg allows you to simulate the execution of a trade within the pair, exactly as you would normally. This returns a SimulationResponse response type.

simulation
{
"simulation": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
}
}
}

The SimulationResponse struct is shown below:

SimulationResponse
pub struct SimulationResponse {
pub return_amount: Uint128,
pub spread_amount: Uint128,
pub commission_amount: Uint128,
}

ReverseSimulation

The simulation QueryMsg runs a reversed execution of a trade within the pair. This returns a ReverseSimulationResponse response type.

reverseSimulation
{
"reverseSimulation": {
"ask_asset": {
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
}
}

The ReverseSimulationResponse struct is shown below:

ReverseSimulationResponse
pub struct ReverseSimulationResponse {
pub offer_amount: Uint128,
pub spread_amount: Uint128,
pub commission_amount: Uint128,
}