Skip to main content

Stableswap Pools

Overview

The stableswap pool uses the 4A(Rx+Ry) + D formula, resulting in a constant price ∆x / ∆y = 1. More details around how the pool functions can be found here.

InstantiateMsg

Initializes a new stableswap pair.

json
pair.rs
Copy

_17
{
_17
"asset_infos": [
_17
{
_17
"token": {
_17
"contract_addr": "..."
_17
}
_17
},
_17
{
_17
"native_token": {
_17
"denom": "..."
_17
}
_17
}
_17
],
_17
"token_code_id": 123,
_17
"factory_addr": "terra...",
_17
"init_params": "<base64_encoded_json_string; example: {'amp': 100}>"
_17
}

ParamsTypeDescription
asset_infosVec<AssetInfo>Information about assets in the pool
token_code_idu64The token contract code ID used for the tokens in the pool
factory_addrStringThe factory contract address
init_paramsOption<Binary>Optional binary serialised parameters for custom pool types

ExecuteMsg

receive

Withdraws liquidity or assets that were swapped to (ask assets in a swap operation).

json
pair.rs
Copy

_7
{
_7
"receive": {
_7
"sender": "terra...",
_7
"amount": "123",
_7
"msg": "<base64_encoded_json_string>"
_7
}
_7
}

ParamsTypeDescription
receiveCw20ReceiveMsgCW20 receive message

provide_liquidity

Provides liquidity by sending a user's native or token assets to the pool.

You should increase your token allowance for the pool before providing liquidity!

json
pair.rs
Copy

_25
{
_25
"provide_liquidity": {
_25
"assets": [
_25
{
_25
"info": {
_25
"token": {
_25
"contract_addr": "terra..."
_25
}
_25
},
_25
"amount": "1000000"
_25
},
_25
{
_25
"info": {
_25
"native_token": {
_25
"denom": "..."
_25
}
_25
},
_25
"amount": "1000000"
_25
}
_25
],
_25
"slippage_tolerance": "0.01",
_25
"auto_stake": false,
_25
"receiver": "terra..."
_25
}
_25
}

ParamsTypeDescription
assetsVec<Asset>Describes a native or CW20 asset
slippage_toleranceOption<Decimal>The slippage tolerance that allows liquidity provision only if the price in the pool doesn't move too much
auto_stakeOption<bool>Determines whether the LP tokens minted for the user is auto_staked in the Generator contract
receiverOption<String>The receiver of LP tokens

withdraw_liquidity

Burns LP tokens and withdraws liquidity from a pool.

NOTE

This call must be sent to the LP token contract associated with the pool from which you want to withdraw liquidity from.

json
pair.rs
Copy

_3
{
_3
"withdraw_liquidity": {}
_3
}

swap

Swap performs a swap in the pool.

json
pair.rs
Copy

_20
{
_20
"swap": {
_20
"offer_asset": {
_20
"info": {
_20
"token": {
_20
"contract_addr": "..."
_20
}
_20
},
_20
"amount": "10000000"
_20
},
_20
"ask_asset_info": {
_20
"native_token": {
_20
"denom": "..."
_20
}
_20
},
_20
"belief_price": "1234567",
_20
"max_spread": "10000000",
_20
"to": "...."
_20
}
_20
}

ParamsTypeDescription
offer_assetAssetOffer asset
ask_asset_infoOption<AssetInfo>Information about an asset stored in a [AssetInfo] struct
belief_priceOption<Decimal>Belief price
max_spreadOption<Decimal>The difference between the ask amount before and after the swap operation. If the swap spread exceeds the provided max limit, the swap will fail. If belief_price is provided in combination with max_spread, the pool will check the difference between the return amount (using belief_price) and the real pool price.
toOption<String>Address receiving tokens (if different from sender)

update_config

Update the pair's configuration.

json
pair.rs
Copy

_5
{
_5
"update_config": {
_5
"params": "<base64_encoded_json_string>; example: {'amp': 100}"
_5
}
_5
}

ParamsTypeDescription
paramsBinaryThe pool's parameters

QueryMsg

pair

Queries information about a pair.

json
pair.rs
Copy

_3
{
_3
"pair": {}
_3
}

Returns a PairInfo response struct.

pool

Queries information about a pool.

json
pair.rs
Copy

_3
{
_3
"pool": {}
_3
}

PoolResponse

This struct is used to return a query result with the total amount of LP tokens and assets in a specific pool.

json
pair.rs
Copy

_21
{
_21
"assets": [
_21
{
_21
"info": {
_21
"token": {
_21
"contract_addr": "..."
_21
}
_21
},
_21
"amount": "100000"
_21
},
_21
{
_21
"info": {
_21
"native_token": {
_21
"denom": "..."
_21
}
_21
},
_21
"amount": "100000"
_21
}
_21
],
_21
"total_share": "1234567"
_21
}

ParamsTypeDescription
assetsVec<Asset>The assets in the pool together with asset amounts
total_shareUint128The total amount of LP tokens currently issued

config

Queries contract configuration settings.

json
pair.rs
Copy

_3
{
_3
"config": {}
_3
}

ConfigResponse

This struct is used to return a query result with the general contract configuration.

json
pair.rs
Copy

_5
{
_5
"block_time_last": 1234567,
_5
"params": "<base64_encoded_json_string>",
_5
"owner": "..."
_5
}

ParamsTypeDescription
block_time_lastu64The assets in the pool together with asset amounts
paramsOption<Binary>The pool's parameters
ownerOption<Addr>The contract owner

share

Queries information about the share of a pool.

json
pair.rs
Copy

_5
{
_5
"share": {
_5
"amount": "1000000"
_5
}
_5
}

ParamsTypeDescription
amountUint128Share of the pool

Returns a vector that contains objects of type Asset.

simulation

Queries information about a swap simulation.

json
pair.rs
Copy

_17
{
_17
"simulation": {
_17
"offer_asset": {
_17
"info": {
_17
"token": {
_17
"contract_addr": "..."
_17
}
_17
},
_17
"amount": "100000"
_17
},
_17
"ask_asset_info": {
_17
"native_token": {
_17
"denom": "..."
_17
}
_17
}
_17
}
_17
}

ParamsTypeDescription
offer_assetAssetOffer asset
ask_asset_infoOption<AssetInfo>Ask asset info

SimulationResponse

This structure holds the parameters that are returned from a swap simulation response.

json
pair.rs
Copy

_5
{
_5
"return_amount": "123456",
_5
"spread_amount": "0",
_5
"commission_amount": "123"
_5
}

ParamsTypeDescription
return_amountUint128The amount of ask assets returned by the swap
spread_amountUint128The spread used in the swap operation
commission_amountUint128The amount of fees charged by the transaction

reverse_simulation

Queries information about a reverse swap simulation.

json
pair.rs
Copy

_17
{
_17
"reverse_simulation": {
_17
"offer_asset_info": {
_17
"native_token": {
_17
"denom": "..."
_17
}
_17
},
_17
"ask_asset": {
_17
"info": {
_17
"token": {
_17
"contract_addr": "..."
_17
}
_17
},
_17
"amount": "100000"
_17
}
_17
}
_17
}

ParamsTypeDescription
offer_asset_infoOption<AssetInfo>Offer asset info
ask_assetAssetAsk asset

ReverseSimulationResponse

This structure holds the parameters that are returned from a reverse swap simulation response.

json
pair.rs
Copy

_5
{
_5
"offer_amount": "12345",
_5
"spread_amount": "0",
_5
"commission_amount": "123"
_5
}

ParamsTypeDescription
offer_amountUint128The amount of offer assets returned by the reverse swap
spread_amountUint128The spread used in the swap operation
commission_amountUint128The amount of fees charged by the transaction

cumulative_prices

Queries information about cumulative prices in a pool.

json
pair.rs
Copy

_3
{
_3
"cumulative_prices": {}
_3
}

CumulativePricesResponse

This structure is used to return a cumulative prices query response.

json
pair.rs
Copy

_23
{
_23
"assets": [
_23
{
_23
"info": {
_23
"token": {
_23
"contract_addr": "..."
_23
}
_23
},
_23
"amount": "100000"
_23
},
_23
{
_23
"info": {
_23
"native_token": {
_23
"denom": "..."
_23
}
_23
},
_23
"amount": "100000"
_23
}
_23
],
_23
"total_share": "12345667",
_23
"price0_cumulative_last": "12345667",
_23
"price1_cumulative_last": "12345667"
_23
}

ParamsTypeDescription
assetsVec<Asset>The assets in the pool to query
total_shareUint128The total amount of LP tokens currently issued
cumulative_pricesVec<(AssetInfo, AssetInfo, Uint128)>The vector contains cumulative prices for each pair of assets in the pool

observe

Queries price from stored observations. If observation was not found at exact time then it is interpolated using surrounding observations.

json
pair.rs
Copy

_5
{
_5
"observe": {
_5
"seconds_ago": 3600
_5
}
_5
}

OracleObservation (Response)

This structure is used to return an observation query response.

json
observation.rs
Copy

_4
{
_4
"timestamp": 12345,
_4
"price": "1.23"
_4
}

ParamsTypeDescription
timestampu64The timestamp for returned price observations
priceDecimalThe price from stored observations