N. P. O'Donnell, 2022
Uniswap v1 and v2 are based on constant product formula:
x * y = k
Where:
- x = Number of units of asset x (a.k.a. base currency)
- y = Number of units of asset y (a.k.a. quote currency)
- k = A constant
- In v1 and v2, liquidity was spread across the entire price range from 0 to Inf. In v3, liquidity can be concentrated in ranges. e.g. (10.0, 1000.0). This allows buyers and sellers to get a better price (less slippage) and LPs to earn more fees.
Each possible price corresponds to a tick (implemented as 24-bit signed integer).
- The tick index at point a is denoted ia - lower bound of position.
- The tick index at point b is denoted ib - upper bound of position.
- The tick index at point c is denoted ic
- Position: 2 points a and b on curve, between two ticks il and ih inclusive.
- CPF = Constant product formula
- LP = Liquidity pool
- x: Number of units of asset x (a.k.a. base currency) in LP
- y: Number of units of asset y (a.k.a. quote currency) in LP
- k: Constant in CPF
- L: Global liquidity
- l: Per-position liquidity
- a: Lower bound of a position (Asset x has lowest reserves thus highest price, asset y has highest reserves)
- b: Upper bound of a position (Asset x has highest reserves thus lowest price, asset y has lowest reserves)
- c: Some arbitrary point on the curve in the range (a, b)
xy=k
: CPFL=sqrt(k)
: Liquidity as a function of kL=sqrt(xy)
: Liquidity as a function of x and ysqrt(P)=sqrt(y/x)
: SqrtPrice as a function of x and y (obviously this implies that P=y/x)x=L/sqrt(P)
: x (base currency virtual reserves) as a function of liquidity and SqrtPricey=L*sqrt(P)
: y (quote currency virtual reserves) as a function of liquidity and SqrtPrice