Constant Product Formula
Published Last updated
Key Takeaway
The constant product formula is the mathematical rule used by most AMMs to price tokens, maintaining the product of two pool token quantities as a fixed constant across every trade.
Learn These First
What Is Constant Product Formula?
The constant product formula is the mathematical rule used by most AMMs to price tokens, maintaining the product of two pool token quantities as a fixed constant across every trade.
How Constant Product Formula Works
Frequently Asked Questions
What is the constant product formula in crypto AMMs?
The constant product formula — x multiplied by y equals k — is the mathematical rule that governs token pricing in most automated market maker liquidity pools. In this formula, x and y represent the current quantities of two tokens in the pool, and k is a fixed constant that cannot change after a trade. When you buy token X, you add token Y to the pool, shifting the ratio between them. The formula recalculates the new price automatically based on the updated ratio, without requiring any external price data or human input to set or adjust prices.
Why do large trades on AMMs get such bad prices?
Large trades receive worse prices on AMMs because of how the constant product formula works. Each unit of a token you remove from the pool requires you to add progressively more of the other token to keep the product constant. This means the effective exchange rate worsens continuously as trade size grows — the larger the trade relative to pool size, the more the ratio shifts against you during execution. This worsening is called price impact. Smaller pools amplify this effect because a given trade size represents a larger fraction of total pool liquidity, shifting the ratio more dramatically.
How is the constant product formula different from newer AMM designs?
The original constant product formula spreads liquidity evenly across all possible prices from zero to infinity, making it capital-inefficient — most of the deposited liquidity sits idle at prices far from the current market rate. Newer AMM designs address this. Uniswap V3 introduced concentrated liquidity, allowing providers to allocate capital within a specific price range, dramatically improving capital efficiency near the current price. Curve Finance uses a modified stableswap formula optimized for assets that should trade near a 1:1 ratio, such as stablecoins, producing much lower price impact for large stable asset swaps than the constant product model would allow.
Common Misconceptions About Constant Product Formula
The constant product formula keeps token prices stable inside a pool.
The constant product formula does not stabilize prices — it determines how prices change in response to trades. Every trade that shifts the pool's token ratio produces a new price, and the formula provides no floor or ceiling on how far prices can move. Large trades or sustained one-directional buying can shift pool prices dramatically away from market consensus prices on other exchanges. Arbitrageurs help realign pool prices with external markets by exploiting these gaps, but the formula itself has no price stabilization mechanism built into it.
The k value in x times y equals k can change when fees are added.
In the basic constant product model, k is fixed for the duration of a trade — the trade must preserve the product exactly. However, in practice most AMM protocols extract a small fee from each trade before applying the formula, which slightly increases k over time as fee income accumulates in the pool. This fee accumulation is how liquidity providers earn returns. The important distinction is that k does not change during a trade's execution; it only grows incrementally between trades as fees are collected, which increases total pool value over time.
All decentralized exchanges use the constant product formula.
The constant product formula is the most widely adopted AMM pricing model but it is not universal. Curve Finance uses a hybrid stableswap formula that combines constant product and constant sum mechanics, specifically designed to minimize price impact for stablecoin and pegged-asset swaps. Balancer uses a generalized constant product formula extended to pools with more than two tokens and customizable weightings. DODO and other DEXs use proactive market maker models that incorporate external price oracles. AMM design is an active area of innovation, and multiple competing formulas coexist across the DeFi ecosystem.