Skip to main content

How V2 Works

V2 pools use the constant product formula, the same model pioneered by Uniswap V2. Each pool holds reserves of exactly two tokens and maintains the invariant: x×y=kx \times y = k Where:
  • x = reserve of token A
  • y = reserve of token B
  • k = constant (increases only from fees)

Price Determination

The price of token A in terms of token B is simply the ratio of reserves: PriceA=yx\text{Price}_A = \frac{y}{x} When a trader swaps token A for token B, they deposit A and withdraw B. The new reserves must still satisfy x * y = k (after fees), which naturally adjusts the price.

Swap Mechanics

For a swap of dx amount of token A into the pool:
  1. The input amount minus the 0.3% fee is added to reserve A
  2. The output amount dy is calculated such that the invariant holds:
(x+dx×0.997)×(ydy)=k(x + dx \times 0.997) \times (y - dy) = k Solving for dy: dy=y×dx×0.997x+dx×0.997dy = \frac{y \times dx \times 0.997}{x + dx \times 0.997}

Price Impact

Larger trades relative to pool reserves cause greater price movement. This is called price impact and is inherent to the constant product curve — the price moves along a hyperbola. For a trade of size dx against reserve x: Price Impactdxx+dx\text{Price Impact} \approx \frac{dx}{x + dx} A trade that equals 1% of the reserve causes roughly 1% price impact.

Liquidity Provision

LPs deposit both tokens in proportion to the current reserves. In return, they receive LP tokens representing their share of the pool. When adding liquidity:
  • If the pool exists: tokens must be deposited at the current price ratio
  • If the pool is new: the first depositor sets the initial price
The LP’s share of the pool is: Share=LP tokens mintedTotal LP token supply\text{Share} = \frac{\text{LP tokens minted}}{\text{Total LP token supply}} See LP Tokens for more details.

Arbitrage and Price Discovery

V2 pools rely on arbitrageurs to keep prices in line with external markets. When the pool price deviates from the true market price, arbitrageurs profit by trading against the pool, pushing the price back to equilibrium.