sidebar_position |
---|
1 |
import Admonition from '@theme/Admonition'
Astroport’s passive concentrated liquidity (PCL) pools optimize for a passive and automatic LP experience for concentrated liquidity. Instead of depositors actively managing their price ranges, liquidity becomes concentrated around an internal oracle price - this is the moving average of recent trades in a pair.
More details around how PCL pools function can be found here.
- Contract Repo: https://github.com/astroport-fi/astroport-core/tree/main/contracts/pair_concentrated
- contract.rs: https://github.com/astroport-fi/astroport-core/blob/main/contracts/pair_concentrated/src/contract.rs
- pair_concentrated.rs https://github.com/astroport-fi/astroport-core/blob/main/packages/astroport/src/pair_concentrated.rs
- Tests: https://github.com/astroport-fi/astroport-core/tree/main/contracts/pair_concentrated/tests
Initializes a new concentrated liquidity pair.
<CH.Section> <CH.Code>
```json json
{
"token_code_id": 123,
"factory_addr": "terra...",
"asset_infos": [
{
"token": {
"contract_addr": "terra..."
}
},
{
"native_token": {
"denom": "uusd"
}
}
],
"init_params": "<base64_encoded_json_string>"
}
```
</CH.Code>
</CH.Section>
where <base64_encoded_json_string>
is
<CH.Section> <CH.Code>
```json json
{
"amp": "40.0",
"gamma": "0.0001",
"mid_fee": "0.005",
"out_fee": "0.01",
"fee_gamma": "0.001",
"repeg_profit_threshold": "0.0001",
"min_price_scale_delta": "0.000001",
"initial_price_scale": "1.5",
"ma_half_time": 600,
"owner": "terra..."
}
```
</CH.Code>
</CH.Section>
Note, the aforementioned values are just examples and have no practical meaning.
Withdraws liquidity or assets that were swapped to (ask assets from a swap operation).
<CH.Section> <CH.Code>
```json json
{
"receive": {
"sender": "terra...",
"amount": "123",
"msg": "<base64_encoded_json_string>"
}
}
```
</CH.Code>
</CH.Section>
Provides liquidity by sending a user's native or token assets to the pool.
NOTE: you should increase your token allowance for the pool before providing liquidity!<CH.Section> <CH.Code>
```json json
{
"provide_liquidity": {
"assets": [
{
"info": {
"token": {
"contract_addr": "terra..."
}
},
"amount": "1000000"
},
{
"info": {
"native_token": {
"denom": "uusd"
}
},
"amount": "1000000"
}
],
"auto_stake": false,
"receiver": "terra...",
"slippage_tolerance": "0.01"
}
}
```
</CH.Code>
</CH.Section>
Burn LP tokens and withdraw liquidity from a pool. This call must be sent to a LP token contract associated with the pool from which you want to withdraw liquidity from.
<CH.Section> <CH.Code>
```json json
{
"withdraw_liquidity": {}
}
```
</CH.Code>
</CH.Section>
Perform a swap. offer_asset
is your source asset and to is the address that will receive the ask assets. All fields are optional except offer_asset
.
<CH.Section> <CH.Code>
```json json
{
"swap": {
"offer_asset": {
"info": {
"native_token": {
"denom": "uluna"
}
},
"amount": "123"
},
"belief_price": "123",
"max_spread": "123",
"to": "terra..."
}
}
```
</CH.Code>
</CH.Section>
Update the concentrated liquidity pair's configuration.
<CH.Section> <CH.Code>
```json json
{
"update_config": {
"params": "<base64_encoded_json_string>"
}
}
```
</CH.Code>
</CH.Section>
where <base64_encoded_json_string>
is one of
- Update parameters
<CH.Section> <CH.Code>
```json json
{
"update": {
"mid_fee": "0.1",
"out_fee": "0.01",
...
}
}
```
</CH.Code>
</CH.Section>
- Update Amp or Gamma
<CH.Section> <CH.Code>
```json json
{
"promote": {
"next_amp": "44",
"next_gamma": "0.001",
"future_time": 1570257049
}
}
```
</CH.Code>
</CH.Section>
- Stop Amp and Gamma change
<CH.Section> <CH.Code>
```json json
{
"stop_changing_amp_gamma": {}
}
```
</CH.Code>
</CH.Section>
Queries information about a pair.
<CH.Section> <CH.Code>
{
"pair": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code>
Returns a PairInfo
response struct.
</CH.Section>
Queries information about a pool.
<CH.Section> <CH.Code>
{
"pool": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code> </CH.Section>
This struct is used to return a query result with the total amount of LP tokens and assets in a specific pool.
<CH.Section> <CH.Code>
{
"assets": [
{
"info": {
"token": {
"contract_addr": "..."
}
},
"amount": "100000"
},
{
"info": {
"native_token": {
"denom": "..."
}
},
"amount": "100000"
}
],
"total_share": "1234567"
}
#[cw_serde]
pub struct PoolResponse {
pub assets: Vec<Asset>,
pub total_share: Uint128,
}
</CH.Code>
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 |
</CH.Section>
Queries contract configuration settings.
<CH.Section> <CH.Code>
{
"config": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code> </CH.Section>
This struct is used to return a query result with the general contract configuration.
<CH.Section> <CH.Code>
{
"block_time_last": 1234567,
"params": "<base64_encoded_json_string>",
"owner": "..."
}
#[cw_serde]
pub struct ConfigResponse {
pub block_time_last: u64,
pub params: Option<Binary>,
pub owner: Option<Addr>,
}
</CH.Code>
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 |
</CH.Section>
Queries information about the share of a pool.
<CH.Section> <CH.Code>
{
"share": {
"amount": "1000000"
}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code>
Params | Type | Description |
---|---|---|
amount |
Uint128 |
Share of the pool |
</CH.Section>
Returns a vector that contains objects of type Asset
.
Queries information about a swap simulation.
<CH.Section> <CH.Code>
{
"simulation": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "..."
}
},
"amount": "100000"
},
"ask_asset_info": {
"native_token": {
"denom": "..."
}
}
}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code>
Params | Type | Description |
---|---|---|
offer_asset |
Asset |
Offer asset |
ask_asset_info |
Option<AssetInfo> |
Ask asset info |
</CH.Section>
This structure holds the parameters that are returned from a swap simulation response.
<CH.Section> <CH.Code>
{
"return_amount": "123456",
"spread_amount": "0",
"commission_amount": "123"
}
#[cw_serde]
pub struct SimulationResponse {
pub return_amount: Uint128,
pub spread_amount: Uint128,
pub commission_amount: Uint128,
}
</CH.Code>
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 |
</CH.Section>
Queries information about a reverse swap simulation.
<CH.Section> <CH.Code>
{
"reverse_simulation": {
"offer_asset_info": {
"native_token": {
"denom": "..."
}
},
"ask_asset": {
"info": {
"token": {
"contract_addr": "..."
}
},
"amount": "100000"
}
}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code>
Params | Type | Description |
---|---|---|
offer_asset_info |
Option<AssetInfo> |
Offer asset info |
ask_asset |
Asset |
Ask asset |
</CH.Section>
This structure holds the parameters that are returned from a reverse swap simulation response.
<CH.Section> <CH.Code>
{
"offer_amount": "12345",
"spread_amount": "0",
"commission_amount": "123"
}
#[cw_serde]
pub struct ReverseSimulationResponse {
pub offer_amount: Uint128,
pub spread_amount: Uint128,
pub commission_amount: Uint128,
}
</CH.Code>
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 |
</CH.Section>
Queries information about cumulative prices in a pool.
<CH.Section> <CH.Code>
{
"cumulative_prices": {}
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(PairInfo)]
Pair {},
#[returns(PoolResponse)]
Pool {},
#[returns(ConfigResponse)]
Config {},
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
#[returns(CumulativePricesResponse)]
CumulativePrices {},
#[returns(Uint128)]
QueryComputeD {},
}
</CH.Code> </CH.Section>
This structure is used to return a cumulative prices query response.
<CH.Section> <CH.Code>
{
"assets": [
{
"info": {
"token": {
"contract_addr": "..."
}
},
"amount": "100000"
},
{
"info": {
"native_token": {
"denom": "..."
}
},
"amount": "100000"
}
],
"total_share": "12345667",
"price0_cumulative_last": "12345667",
"price1_cumulative_last": "12345667"
}
#[cw_serde]
pub struct CumulativePricesResponse {
pub assets: Vec<Asset>,
pub total_share: Uint128,
pub cumulative_prices: Vec<(AssetInfo, AssetInfo, Uint128)>,
}
</CH.Code>
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 |
</CH.Section>
Returns current D value for the pool.
<CH.Section> <CH.Code>
```json json
{
"query_compute_d": {}
}
```
```rs pair_concentrated.rs
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Returns information about a pair
#[returns(PairInfo)]
Pair {},
/// Returns information about a pool
#[returns(PoolResponse)]
Pool {},
/// Returns contract configuration
#[returns(ConfigResponse)]
Config {},
/// Returns information about the share of the pool in a vector that contains objects of type [`Asset`].
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
/// Returns information about a swap simulation
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
/// Returns information about a reverse swap simulation
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
/// Returns information about the cumulative prices
#[returns(CumulativePricesResponse)]
CumulativePrices {},
/// Returns current D invariant
#[returns(Decimal256)]
ComputeD {},
/// Query LP token virtual price
#[returns(Decimal256)]
LpPrice {},
}
```
</CH.Code>
</CH.Section>
Returns Decimal256
Query LP token virtual price.
<CH.Section> <CH.Code>
```json json
{
"lp_price": {}
}
```
```rs pair_concentrated.rs
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Returns information about a pair
#[returns(PairInfo)]
Pair {},
/// Returns information about a pool
#[returns(PoolResponse)]
Pool {},
/// Returns contract configuration
#[returns(ConfigResponse)]
Config {},
/// Returns information about the share of the pool in a vector that contains objects of type [`Asset`].
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
/// Returns information about a swap simulation
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
/// Returns information about a reverse swap simulation
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
/// Returns information about the cumulative prices
#[returns(CumulativePricesResponse)]
CumulativePrices {},
/// Returns current D invariant
#[returns(Decimal256)]
ComputeD {},
/// Query LP token virtual price
#[returns(Decimal256)]
LpPrice {},
}
```
</CH.Code>
</CH.Section>
Returns Decimal256
Query curremt Amp and Gamma parameters.
<CH.Section> <CH.Code>
```json json
{
"amp_gamma": {}
}
```
```rs pair_concentrated.rs
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Returns information about a pair
#[returns(PairInfo)]
Pair {},
/// Returns information about a pool
#[returns(PoolResponse)]
Pool {},
/// Returns contract configuration
#[returns(ConfigResponse)]
Config {},
/// Returns information about the share of the pool in a vector that contains objects of type [`Asset`].
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
/// Returns information about a swap simulation
#[returns(SimulationResponse)]
Simulation {
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
},
/// Returns information about a reverse swap simulation
#[returns(ReverseSimulationResponse)]
ReverseSimulation {
offer_asset_info: Option<AssetInfo>,
ask_asset: Asset,
},
/// Returns information about the cumulative prices
#[returns(CumulativePricesResponse)]
CumulativePrices {},
/// Returns current D invariant
#[returns(Decimal256)]
ComputeD {},
/// Query LP token virtual price
#[returns(Decimal256)]
LpPrice {},
}
```
</CH.Code>
</CH.Section>
Queries the balance of the specified asset that was in the pool just preceeding the moment of the specified block height creation. The query will return None (null) if the balance was not tracked up to the specified block height.
<CH.Section> <CH.Code>
```json json
{
"asset_balance_at": {
"asset_info": {
"native_token": {
"denom": "stake"
}
},
"block_height": "12345678"
}
}
```
```rs pair_concentrated.rs focus=1:11,14
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
// other queries
#[returns(Option<Uint128>)]
AssetBalanceAt {
asset_info: AssetInfo,
block_height: Uint64,
},
#[returns(OracleObservation)]
Observe { seconds_ago: u64 },
}
```
</CH.Code>
</CH.Section>
Queries price from stored observations. If observation was not found at exact time then it is interpolated using surrounding observations.
<CH.Section> <CH.Code>
```json json
{
"observe": {
"seconds_ago": 3600
}
}
```
```rs pair_concentrated.rs
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
// other queries
#[returns(OracleObservation)]
Observe { seconds_ago: u64 },
}
```
</CH.Code>
</CH.Section>
This structure is used to return an observation query response.
<CH.Section> <CH.Code>
```json json
{
"timestamp": 12345,
"price": "1.23"
}
```
```rust observation.rs
#[cw_serde]
pub struct OracleObservation {
pub timestamp: u64,
pub price: Decimal,
}
```
</CH.Code>
Params | Type | Description |
---|---|---|
timestamp |
u64 |
The timestamp for returned price observations |
price |
Decimal |
The price from stored observations |
</CH.Section>