Liquidity Pool Math
Last updated
Last updated
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.
When a trade is executed in an AMM pool, it happens within a specific interval. Trades in Interval_i follow the Constant Sum Market Maker (CSMM) model, governed by the 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.