The constant product formula (x × y = k) is the mathematical foundation of AMMs like Uniswap. Understanding this formula helps you predict prices, calculate slippage, and make better trading decisions.
The Formula Explained
x × y = k
- x = Reserve of Token A
- y = Reserve of Token B
- k = Constant (product of reserves)
Why It Works
The constant product creates a hyperbolic curve:
- As one token is removed, more of the other is required
- Price increases exponentially as supply depletes
- Liquidity is always available (never zero)
- Large trades have increasing price impact (slippage)
Price Discovery
The price at any moment equals the ratio of reserves:
Price of A = y / x
Example: 10 ETH and 20,000 USDC
- Price of ETH = 20,000 / 10 = 2,000 USDC
Calculating Trade Output
For a swap of Δx tokens of A:
Δy = (y × Δx) / (x + Δx)
This formula accounts for the price impact of your trade.
Key Takeaways
- x × y = k ensures liquidity never runs out
- Price = ratio of reserves (y/x)
- Larger trades have higher slippage
- The curve is elegant but has limitations for stablecoins
- Understanding the math helps you trade smarter