Skip to main content

Swap Pairs

Overview

Astroport supports various pool types:

Depending on your use-cases and needs as well as the types of assets you want to integrate, one of these pools will be better than the other. To learn more about Astroport pools, visit here.

Liquidity Providers

A user can provide liquidity to a pool by calling provide_liquidity. Users can also withdraw liquidity by calling withdraw_liquidity.

NOTE

Before executing the provide_liqudity operation, a user must allow the pool contract to take tokens from their wallet

Whenever liquidity is deposited into a pool, special tokens known as "liquidity tokens" are minted to the provider’s address, in proportion to how much liquidity they contributed to the pool. These tokens are a representation of a liquidity provider’s contribution to a pool. Whenever a trade occurs, the lp_commission is distributed pro-rata to all LPs in the pool at the moment of the trade. To receive the underlying liquidity back plus accrued LP fees, LPs must burn their liquidity tokens.

When providing liquidity from a smart contract, the most important thing to keep in mind is that the amount of tokens deposited into a pool and the amount of tokens withdrawn later from the pool will most likely not be the same (even if stableswap encourages a constant 1:1 ratio between all assets in the pool). In the case of PCL and constant product pools, as token prices in the pool change, so do the respective token amounts that a LP can withdraw.

Slippage Tolerance for Providing Liquidity

If an LP specifies a slippage tolerance when they provide liquidity, the pool contract makes sure that the transaction goes through only if the pool price does not change more than tolerance.

As an example, let's say someone LPs in a passive concentrated liquidity pool and specifies a 1% slippage tolerance. The user LPs 200 axlUSDC and 1 ASSET. A similar example could be set with a stableswap pool and a pair of 200 axlUSDC and 200 ASSET.

With a 1% slippage tolerance, amountaxlUSDCMin (the minimum amount of axlUSDC to LP) should be set to 198 axlUSDC, and amountASSETMin (the minimum amount of ASSET to LP) should be set to .99 ASSET. This means that, in a worst case scenario, liquidity will be added at a pool rate of 198 ASSET/1 axlUSDC or 202.02 axlUSDC/1 ASSET (200 axlUSDC + .99 ASSET). If the contract cannot add liquidity within these bounds (because the pool ratio changed more than the tolerance), the transaction will revert.

Traders

Slippage Tolerance for Swaps

Astroport has two options to protect traders against slippage during swaps:

  1. Providing max_spread - The spread is calculated as the difference between the ask amount (using the constant pool price) before and after the swap operation. Once max_spread is set, it will be compared against the actual swap spread. In case the swap spread exceeds the provided max limit, the swap will fail.

Note that the spread is calculated before commission deduction in order to properly represent the pool's ratio change.

  1. Providing max_spread + belief_price - 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.
NOTE

Astroport has the default value for the spread set to 0.5% and the max allowed spread set to 50%.