Skip to main content

Constant Product Pools

Constant product pools are one of the most popular AMM models, first introduced by Uniswap. They allow two tokens to be swapped while ensuring the reserves follow a mathematical rule that prevents depletion.

How the Formula Works

The fundamental formula for constant product pools is:

xy=kx \cdot y = k

Where:

  • xx = reserve of token X
  • yy = reserve of token Y
  • kk = constant product, which must remain unchanged after a swap

This relationship ensures that when a user adds some amount Δx\Delta x of token X to the pool, the output Δy\Delta y of token Y is calculated such that:

(x+Δx)(yΔy)=k(x + \Delta x)(y - \Delta y) = k

This is often referred to as the invariant equation.

Swap Output Formula

In practice, the amount of output token a user gets from a swap is computed using a derived form of the above invariant:

Δy=yΔxx+Δx\Delta y = \frac{y \cdot \Delta x}{x + \Delta x}

This shows that as more of token X is added (larger Δx\Delta x), the marginal price increases, meaning slippage occurs. The pool automatically adjusts the price based on trade size.

When to Use

Constant product pools are best suited for:

  • Tokens with high volatility
  • General-purpose pairs like ETH/USDC or BNB/BTC
  • Use cases where any-to-any swaps are needed without relying on oracles