TickLiquidity to fill the swap order. Liquidity is always iterated through in order of best to worst price (from the taker’s perspective.) For each swap, we completely exhaust the available reserves before moving on to the next tick. For TickLiquidity instances at the same TickIndex they are iterated through in a deterministic order as follows:
PoolReservestake priorityLimitOrderTranchesare iterated through when Pool Reserve liquidity is depletedLimitOrderTranchesare iterated through in alphabetical order of theirTrancheKey(LimitOrderTranche.Key.TrancheKey.)
PoolReserves the proceeds from the swap are added to the reserves on the reciprocal side of the pool. Ie. The output of TokenA swapped through a PoolReserves will be moved to a PoolReserves holding TokenB.
Example liquidity Placement
DEX Deposits (0 fee):- Deposit 1:
Amounts: 10ATOM0USDC. Price: 8USDCperATOM. Tick index . - Deposit 2:
**Amounts: ** 10ATOM0USDC. Price: 9USDCperATOM. Tick index . - Deposit 3:
Amounts: 10ATOM0USDC. Price: 10USDCperATOM. Tick index .
- Limit Order 1:
Amount: 10ATOM. Price:USDCperATOM: Tick index - Limit Order 2:
Amount: 10USDC. Price:ATOMperUSDC: Tick index

- Tick Index offers the cheapest
ATOMperUSDCspent. it yieldsATOMperUSDC - Tick Index offers the cheapest
USDCperATOMspent. it yieldsUSDCperATOM - It is visible that iterating left to right will always yield the best price regardless of the token being swapped.
Example Liquidity Iteration: Swap
Alice Performs a Swap using aTaker Limit Order. She wants to swap USDC for ATOM at the best possible price.
- The first available
TickLiquidityholdingATOMis aLimitOrderTrancheat tick . Since this is a limit order, when swapped through and depleted the liquidity is removed from state and theUSDCAlice paid can be later withdrawn by the limit orderReceiver - Alice swaps up to
USDCusing this pool before depleting the reserves. This will net herATOMfor the swap:
- Alice still has
USDCshe needs to swap, so we move to the next available tick: This tick offersATOMat a price ofUSDCperATOMand is of typePoolReserve. Any USDC Alice pays for this swap will be placed in the corresponding poolReserves of the Pool (USDC @ Tick .) Alice swaps the remainder of herUSDChere, resulting in an additionalATOM:
- Done. Alice has swapped
USDCforATOMwith an average price ofATOMperUSDC.
PoolReserves have a fee of zero. In a real world scenario almost all PoolReserves will have a fee. In a scenario with fees TokenIn will be added to ). Learn more about fees in the PoolReserves section.
Example liquidity Placement Post Swap
