📚
Duality Documentation
  • What is Duality?
  • Concepts
    • AMMs and Orderbooks
    • Liquidity Pools
    • Ticks
    • TickLiquidity
      • Pool Reserves
        • Fees
      • Limit Order Tranches
    • Liquidity Iteration
    • Swaps
    • Overview
  • Module Documentation for Developers
    • DEX Module
      • Transaction Messages
        • Deposit
        • Withdrawal
        • MultiHop Swap
        • Place Limit Order
        • Cancel Limit Order Message
        • Withdraw Filled Limit Order
      • Queries
  • Dictionary
  • Advanced Concepts
    • Replicating Market Makers
    • Shared Liquidity
  • User Interface
Powered by GitBook
On this page
  1. Concepts

Liquidity Iteration

An explanation of how liquidity is iterated through on duality

When swapping through liquidity via a Swap, Multi-Hop Swap, or a Taker Limit Order we iterate through the available TickLiquidity to fill the swap order. Liquidity is always iterated through in order of best to worst price. In the case of swapping Token0 (tokenIn) for Token1 (tokenOut) we iterate through tick indexes left to right (eg. -1, 0, 1, 2...) and for Token1 for Token0 we iterate from right to left (eg. 2, 1, 0, -1…) For each swap we completely exhaust the available reserves before moving onto the next tick. For TickLiquidity instances at the same TickIndex they are iterated through in a deterministic order as follows:

  • PoolReserves: In Ascending Fee order

  • LimitOrderTranches: In ascending TrancheKey order

When swapping through 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 at tick 1, fee 1 will moved to a PoolReserves holding TokenB at tick -1 fee 1.

PreviousLimit Order TranchesNextSwaps

Last updated 1 year ago