📊 Constant Product Formula: x * y = k

Understand the mathematical formula powering all AMM swaps

🔢 The Constant Product Formula

The constant product formula (x × y = k) is the mathematical foundation of AMMs. It ensures that the product of the two token reserves remains constant during trades, automatically adjusting prices based on supply and demand.

How the Formula Works

📐

The Equation: x × y = k

x and y are the reserves of two tokens in the pool. k is a constant that never changes (except when liquidity is added/removed).

💹

Automatic Pricing

When someone trades, they add one token and remove another. The formula maintains the constant k, causing the price to adjust automatically.

⚖️

Self-Balancing

Large trades have bigger price impact. This incentivizes arbitrageurs to balance the pool when it deviates from market prices.

🎮 Interactive: Trade Simulator

Execute trades and watch how the constant product formula maintains equilibrium:

Token A Reserve
100.00
Initial
Token B Reserve
100.00
Initial
Constant k:
10000 (unchanged)

Why This Formula?

Infinite Liquidity

The pool never runs out of either token. As reserves decrease, the price increases exponentially, making it prohibitively expensive to drain the pool.

📊

Price Impact

Larger trades have exponentially larger price impact. This naturally limits manipulation and incentivizes splitting large trades.

💡

Mathematical Properties

The constant product formula creates a hyperbolic curve. This means the price curve is smooth and continuous, but the rate of price change accelerates as reserves deplete.

Price = y / x
As x decreases, y increases proportionally
Result: Price increases as Token A is bought