Constant Product Pools
Overview
The constant product pool uses the widely known xy=k formula. More details around how the pool functions can be found here.
Links
- Contract Repo: https://github.com/astroport-fi/astroport-core/tree/main/contracts/pair
- contract.rs: https://github.com/astroport-fi/astroport-core/blob/main/contracts/pair/src/contract.rs
- pair.rs https://github.com/astroport-fi/astroport-core/blob/main/packages/astroport/src/pair.rs
- Tests: https://github.com/astroport-fi/astroport-core/blob/main/contracts/pair/tests/integration.rs
InstantiateMsg
Initializes a new x*y=k pair.
Params | Type | Description |
---|---|---|
asset_infos | Vec<AssetInfo> | Information about assets in the pool |
token_code_id | u64 | The token contract code ID used for the tokens in the pool |
factory_addr | String | The factory contract address |
init_params | Option<Binary> | Optional binary serialised parameters for custom pool types |
The contract's configuration cannot be updated for constant product pairs.
ExecuteMsg
receive
Withdraws liquidity or assets that were swapped to (ask assets in a swap operation).
Params | Type | Description |
---|---|---|
receive | Cw20ReceiveMsg | CW20 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!
Params | Type | Description |
---|---|---|
assets | Vec<Asset> | Describes a native or CW20 asset |
slippage_tolerance | Option<Decimal> | The slippage tolerance that allows liquidity provision only if the price in the pool doesn't move too much |
auto_stake | Option<bool> | Determines whether the LP tokens minted for the user is auto_staked in the Generator contract |
receiver | Option<String> | The receiver of LP tokens |
withdraw_liquidity
Burns LP tokens and withdraws liquidity from a pool.
This call must be sent to the LP token contract associated with the pool from which you want to withdraw liquidity from.
swap
Swap performs a swap in the pool.
Params | Type | Description |
---|---|---|
offer_asset | Asset | Offer asset |
ask_asset_info | Option<AssetInfo> | Information about an asset stored in a [AssetInfo ] struct |
belief_price | Option<Decimal> | Belief price |
max_spread | Option<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. |
to | Option<String> | Address receiving tokens (if different from sender) |
QueryMsg
pair
Queries information about a pair.
Returns a PairInfo
response struct.
pool
Queries information about a pool.
PoolResponse
This struct is used to return a query result with the total amount of LP tokens and assets in a specific pool.
Params | Type | Description |
---|---|---|
assets | Vec<Asset> | The assets in the pool together with asset amounts |
total_share | Uint128 | The total amount of LP tokens currently issued |
config
Queries contract configuration settings.
ConfigResponse
This struct is used to return a query result with the general contract configuration.
Params | Type | Description |
---|---|---|
block_time_last | u64 | The assets in the pool together with asset amounts |
params | Option<Binary> | The pool's parameters |
owner | Option<Addr> | The contract owner |
share
Queries information about the share of a pool.
Params | Type | Description |
---|---|---|
amount | Uint128 | Share of the pool |
Returns a vector that contains objects of type Asset
.
simulation
Queries information about a swap simulation.
Params | Type | Description |
---|---|---|
offer_asset | Asset | Offer asset |
ask_asset_info | Option<AssetInfo> | Ask asset info |
SimulationResponse
This structure holds the parameters that are returned from a swap simulation response.
Params | Type | Description |
---|---|---|
return_amount | Uint128 | The amount of ask assets returned by the swap |
spread_amount | Uint128 | The spread used in the swap operation |
commission_amount | Uint128 | The amount of fees charged by the transaction |
reverse_simulation
Queries information about a reverse swap simulation.
Params | Type | Description |
---|---|---|
offer_asset_info | Option<AssetInfo> | Offer asset info |
ask_asset | Asset | Ask asset |
ReverseSimulationResponse
This structure holds the parameters that are returned from a reverse swap simulation response.
Params | Type | Description |
---|---|---|
offer_amount | Uint128 | The amount of offer assets returned by the reverse swap |
spread_amount | Uint128 | The spread used in the swap operation |
commission_amount | Uint128 | The amount of fees charged by the transaction |
cumulative_prices
Queries information about cumulative prices in a pool.
CumulativePricesResponse
This structure is used to return a cumulative prices query response.
Params | Type | Description |
---|---|---|
assets | Vec<Asset> | The assets in the pool to query |
total_share | Uint128 | The total amount of LP tokens currently issued |
cumulative_prices | Vec<(AssetInfo, AssetInfo, Uint128)> | The vector contains cumulative prices for each pair of assets in the pool |