Liquidity Pool Math

Terminology

To understand the process, let’s define key terms specific to the AMM:

  • Pool: Vessel’s AMM pool consists of two assets, the base asset and the quote asset, which align with trading pair terminology. For example, in an ETH/USDT pool, ETH is the base asset while USDT is the quote asset.

  • Tick: A tick represents discrete prices within the AMM pool. Each pool is instantiated with a predefined set of ticks that remain constant throughout its lifecycle. In Vessel, ticks are defined in an arithmetic sequence, represented as a tuple

<𝑇𝑖𝑐𝑘0,𝑇𝑜𝑡𝑎𝑙𝑇𝑖𝑐𝑘𝑠,𝑇𝑖𝑐𝑘𝑆𝑝𝑎𝑐𝑖𝑛𝑔>

𝑇𝑖𝑐𝑘0=𝑀𝑖𝑛𝑃𝑟𝑖𝑐𝑒

𝑇𝑖𝑐𝑘𝑖=𝑇𝑖𝑐𝑘0+𝑇𝑖𝑐𝑘𝑆𝑝𝑎𝑐𝑖𝑛𝑔×(𝑖−1),0≤𝑖<𝑇𝑜𝑡𝑎𝑙𝑇𝑖𝑐𝑘𝑠

  • Interval: An interval is the minimal divisible price range in the AMM pool. Interval_i covers the price range,

[𝑇𝑖𝑐𝑘𝑖,𝑇𝑖𝑐𝑘𝑖+1]

  • managing buy orders at Tick_i and sell orders at Tick_{i+1}.

  • Liquidity: Liquidity is the total size in base asset of orders managed by the AMM within a specific range. The liquidity of Interval_i is the sum of buy order sizes at Tick_i and sell order sizes at Tick_{i+1}. The pool's total liquidity is the sum across all intervals.

  • Position: A position indicates how an LP provides liquidity within a specific range, defined by <Tick_l, Tick_r, L>, covering [Tick_l, Tick_r], with L liquidity in each interval.

Trading Function

𝑓(𝑥,𝑦)=𝑥𝑝+𝑦=𝑙

where x is the quantity of the quote asset (USDT), y is the quantity of the base asset (ETH), p is the price at Tick_i, and I is the liquidity in this interval.

However, Integrating this AMM trading function into the order book can cause complications. Users might see both buy and sell orders at price Tick_i if x and y are not zero. To resolve this, we slightly adjust the AMM pool’s operations: for each Interval_i, buy orders are placed at price Tick_i while sell orders are placed at price Tick_{i+1}. Consequently, a spread equal to TickSpacing is incurred when AMM orders are fulfilled in different directions. The spread reward is distributed to LPs as well.

This trading function allows each interval to manage incoming trades automatically, provided x ory reserves are sufficient. When these reserves are depleted, the process moves to the adjacent interval based on the trading direction. Each AMM pool tracks the current interval, aligning with the order book's trading pair price.

Last updated