DeFi & AMM

Constant Product Formula (x*y=k)

The mathematical formula used by Uniswap v2-style AMMs where the product of two token reserves must remain constant after every trade.

Constant Product Formula (x*y=k) — The constant product formula (x * y = k) is the mathematical pricing mechanism used by AMMs like Uniswap V2, where x and y represent the reserves of two tokens in a pool and k is a constant that must be maintained after every trade. This formula creates a hyperbolic price curve that ensures a pool can never be fully drained of either token.

What Is the Constant Product Formula?

The constant product formula is the core pricing algorithm behind most automated market makers. Expressed as x * y = k, it defines the relationship between two token reserves in a liquidity pool. After every trade, the product of the reserves must remain equal to k (minus fees), which automatically determines the price of each token based on supply and demand.

Introduced by Uniswap in 2018, this formula revolutionized on-chain trading by replacing order books with a simple, deterministic pricing mechanism that anyone can interact with.

How the Constant Product Formula Works

Consider a pool with 100 ETH and 300,000 USDC, giving k = 30,000,000. If a trader buys 1 ETH, the pool must maintain k: the new ETH reserve drops to 99, so the required USDC reserve is 30,000,000 / 99 which is approximately 303,030. The trader pays approximately 3,030 USDC for 1 ETH, slightly above the 3,000 spot price due to price impact.

The formula creates a curved price relationship where larger trades cause proportionally more slippage. A trade representing 1% of pool reserves produces roughly 2% price impact. This design ensures the pool always has liquidity at every price point from zero to infinity.

Why the Constant Product Formula Matters

The constant product formula is the foundation of DeFi trading. Its simplicity, a single equation, makes it gas-efficient to implement on-chain and easy for developers to build on. It guarantees that trades can always execute (there is always a price), which is essential for permissionless markets.

However, the formula is capital-inefficient because it spreads liquidity across all prices. This led to innovations like concentrated liquidity (Uniswap V3) and invariant curves (Curve) that modify the basic formula for specific use cases.

Common questions about Constant Product Formula (x*y=k) in cryptocurrency and DeFi.

In practice, k increases over time because swap fees add tokens to the pool without removing any. Each trade adds a small fee (e.g., 0.3%) to the reserves, gradually growing k. When LPs deposit or withdraw, k changes directly. The constant refers to k remaining unchanged within a single trade excluding fees.

The main limitation is capital inefficiency. Liquidity is spread across all prices from zero to infinity, but most trades occur near the current market price. This means most capital sits idle. Concentrated liquidity models address this by letting LPs focus capital in active price ranges.

No. Uniswap V2 and similar DEXs use x * y = k, but Curve uses a stableswap invariant optimized for similarly-priced assets, Balancer uses weighted pools, and Uniswap V3 uses a modified version with concentrated ranges. Each formula creates different price curves suited to different trading needs.

Ready to put your knowledge into practice?

Start Boosting