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.
{
"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_infosis the list of assets in the pair (The pair can be token<->native, token-token or native-native).token_code_idis the source code id ofhalo-tokencontract.asset_decimalsis the list of decimals of assets in the pair.requirementsis the whitelist wallet address list and requirements for providing liquidity for the first time.commission_rateis the commission rate of the pair.lp_token_infois 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" {
"assets": [
{
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
},
{
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
],
"slippage_tolerance": 5,
"receiver": "aura...",
}
}
Where:
assetsis the list of assets that the sender wants to provide to the contract.contract_addris used if the asset is atoken.denomis used if the asset isnative_token.
slippage_toleranceis 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.receiveris 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.
// define the hook cw20 message
const hookMsg = {
"withdraw_liquidity": { }
}
So, the message to send LP Tokens to the paircontract should look like this:
// 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": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
},
"belief_price": None,
"max_spread": None,
"to": "aura...",
},
}
Where:
offer_assetis the asset that the sender wants to swap.belief_priceis the belief price of the swap.max_spreadis 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": {}
}
The response is a PairInfo struct shown below.
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_infoscan be a Token or NativeToken.
pub enum AssetInfo {
Token { contract_addr: String },
NativeToken { denom: String },
}
contract_addris the address of the pair contract itself.liquidity_tokenis the address of the LP token of the pair.asset_decimalsis the decimal number for the two assets.requirementsis the address of the user or users who can provide liquidity for the first time and the minimum amount when usingprovide_liquidity.
Pool
The pool QueryMsg provides the current information about the pools stats. It returns a PoolResponse response type.
{
"pool": {}
}
The PoolResponse struct is shown below:
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": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
}
}
}
The SimulationResponse struct is shown below:
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": {
"ask_asset": {
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
}
}
The ReverseSimulationResponse struct is shown below:
pub struct ReverseSimulationResponse {
pub offer_amount: Uint128,
pub spread_amount: Uint128,
pub commission_amount: Uint128,
}