The Constant-Product AMM — Full Derivation

The constant-product automated market maker is the workhorse of decentralized exchange. Uniswap V2, Raydium V4, and PumpSwap all implement (variants of) the same invariant. This article derives everything from the conservation law .

Setup

A liquidity pool holds reserves of two tokens:

  • — reserve of token X (e.g., ETH)
  • — reserve of token Y (e.g., USDC)

The pool enforces the invariant:

where is a constant that changes only when liquidity is added or removed — never during a swap.

Marginal Price

The invariant defines a curve in -space. A swap moves the state along this curve. The marginal price of X in terms of Y is the (negative) slope of the curve:

The marginal price (positive, by convention) is therefore:

This is the instantaneous exchange rate: the price of one infinitesimal unit of X, paid in Y. It depends only on the current reserve ratio.

Execution Price for a Finite Trade

A trader sends of token X into the pool. The pool must return of token Y such that the invariant holds after the swap:

Solving for :

The execution price (average price paid) is:

Note that for any . The trader always receives a worse price than the marginal quote — this is price impact.

Price Impact

Define the relative trade size . Then:

where is the pre-trade marginal price. The price impact is:

Expanding for small :

For small trades (), impact is approximately linear in trade size — just like in Kyle’s model, where the price impact of an order of size is . The AMM’s effective Kyle’s lambda is:

which is inversely proportional to pool depth. Deeper pools have lower price impact, exactly as you would expect.

Convexity of Price Impact

The second derivative tells us the impact function is convex:

This means large trades are disproportionately more expensive than small ones. A trader wanting to move of the pool pays more than 10x the impact of moving . This convexity is a natural defense against pool drainage — the invariant makes it infinitely expensive to extract the last unit of either token.

In contrast, Kyle’s linear model assumes , which is linear in with no convexity. The constant-product AMM thus imposes harsher penalties on large orders than Kyle’s informed-trader model predicts. This is both a feature (manipulation resistance) and a cost (worse execution for legitimate large trades).

Numerical Comparison

Trade size AMM impactKyle linear (same )
0.01 (1%)0.99%1.00%
0.05 (5%)4.76%5.00%
0.10 (10%)9.09%10.00%
0.50 (50%)33.3%50.0%
1.00 (100%)50.0%100.0%

At small sizes, the two are nearly identical. At large sizes, the AMM’s convex impact is substantially lower than the linear extrapolation — the hyperbolic invariant “bends away” rather than extrapolating linearly off the cliff.

The Post-Trade Price

After the swap, the new reserves are and . The new marginal price is:

The post-trade price moves quadratically in relative trade size. The ratio is always less than 1 for a buy of token X (which pushes up the price of Y relative to X, i.e., pushes down the price of X in Y terms).

Fee Incorporation

In practice, pools charge a fee (e.g., for Uniswap V2’s 30 bps). The fee is deducted from the input before the invariant is applied:

The fee portion is added to the pool’s X reserves but was not used in the invariant calculation. This means the post-trade invariant is:

Since , we get . Fees monotonically increase . Every swap makes the pool slightly deeper. Over time, the invariant grows, and LP tokens appreciate against the underlying reserves — this is how fee income accrues to liquidity providers.

The fee-adjusted execution price becomes:

which is strictly worse than the no-fee price by a factor close to for small trades.

Geometric Interpretation

The constant-product curve is a rectangular hyperbola in the first quadrant. A swap is a movement along the curve. Adding liquidity scales the curve outward (higher ). Collecting fees ratchets upward after each trade.

The marginal price at any point is the slope of the tangent line to the hyperbola. The execution price is the slope of the secant between the pre-trade and post-trade points. Secant slope tangent slope, which is why execution price marginal price — the visual version of price impact.

Implementations

  • Uniswap V2 (Ethereum, 2020): canonical constant-product, 30 bps fee.
  • Raydium V4 (Solana): same invariant, different fee tiers, Solana-native accounts.
  • PumpSwap (Solana, 2025): constant-product pool for graduated tokens from Pump.fun’s bonding curve — see pumpswap.

All three implement the same math. Differences are in fee structure, governance, and how liquidity is bootstrapped.


Companion notebook: notebooks/defi/02-constant-product.py — interactive Altair plots of the invariant curve, price impact as a function of , and fee accumulation over a sequence of trades.

Questions to sit with:

  1. The AMM’s effective is . In Kyle’s model, depends on the ratio of informed-to-noise trading. What is the AMM analogue of “informed trading intensity”?
  2. If fees increase monotonically, the pool gets deeper over time even without new LP deposits. Under what conditions does this fee growth offset impermanent-loss?
  3. The constant-product rule treats both tokens symmetrically. What happens if you believe one token is fundamentally more volatile than the other — should the invariant be asymmetric?