Uniswap Guide
Constant Product Pools Explained: The Math Behind Automated Market Makers
If you’ve ever swapped tokens on a decentralized exchange like Uniswap, you’ve interacted with a constant product pool. In plain terms, a constant product pool is a smart contract that holds two assets and uses a simple mathematical formula—**x * y = k**—to set prices automatically. Instead of matching buyers with sellers, the pool lets anyone trade directly against its reserves, and the formula ensures the product of the two token balances never changes after a swap. That single rule is what powers most automated market makers (AMMs) today, and understanding it helps you predict slippage, fees, and why prices move the way they do.
## The Core Formula: x * y = k
The heart of a constant product pool is deceptively simple. Let **x** be the amount of token A in the pool, **y** be the amount of token B, and **k** be a fixed constant. Before any trade, the pool maintains the relationship:
- **x * y = k**
When you buy token A, you add token B to the pool, so **y** increases. To keep **k** unchanged, **x** must decrease. The price you get is not set by an order book but derived from the new ratio of reserves after your trade. The larger your trade relative to the pool’s size, the more the ratio shifts—and the more you move the price against yourself.
### Why the Product Must Stay Constant
The “constant” part is the magic. The pool doesn’t care about external market prices; it only enforces that the product of reserves stays the same after each swap (minus fees). If someone tries to drain all of token A, they would have to deposit an infinite amount of token B to keep the product constant. That mathematical barrier prevents a pool from ever being fully emptied in a single trade.
### The Role of Liquidity Providers
Liquidity providers (LPs) deposit both tokens in equal value to create the pool. Their share of the pool grows with trading fees, but they also take on impermanent loss—the risk that the value of their deposited assets diverges from simply holding them. The constant product formula is what makes this arrangement possible: LPs supply the reserves, and traders pay the price for liquidity.
## How Prices Are Calculated in Practice
The formula alone tells you the relationship, but the actual price you receive depends on the size of your trade and the pool’s current depth. Here’s the step-by-step logic a smart contract follows:
1. You send token B into the pool (increasing **y**).
2. The contract calculates the new **x** required to keep **x * y = k**.
3. The difference between the old **x** and new **x** is the amount of token A you receive.
4. A small fee is added to your input before the calculation, so **k** actually increases slightly over time—that’s how LPs earn.
### Slippage: The Cost of Moving the Curve
Slippage is the difference between the expected price and the actual executed price. In a constant product pool, slippage is unavoidable because every trade changes the reserve ratio. Small trades cause negligible slippage; large trades cause significant price impact. This is why you’ll see warnings on interfaces like Uniswap when your trade moves the price more than a few percent.
### The Fee That Breaks the Constant
Strictly speaking, the formula is **x * y = k + fees**. Each swap adds a small percentage (typically 0.3% on older Uniswap pools, with other fee tiers available) to the input before the product is recalculated. That means **k** grows slowly over time, which is exactly how the pool accrues value for LPs. Without fees, the constant would be perfectly static, but then no one would have an incentive to provide liquidity.
## Why Constant Product Pools Became the Standard
Before AMMs, decentralized exchanges relied on order books, which struggled with low liquidity and slow execution. Constant product pools solved this by offering automatic pricing and 24/7 availability. They are especially powerful for long-tail assets—tokens with little trading volume—because the formula guarantees a price for any trade size, no matter how small the reserves.
### Simplicity and Composability
The formula is easy to audit, which made it the foundation for countless DeFi protocols. Anyone can fork it, add features like concentrated liquidity (as Uniswap v3 did), or layer lending and yield farming on top. The constant product model is not the only AMM design, but it’s the most battle-tested and widely understood.
### Limitations You Should Know
Constant product pools are not perfect. They suffer from high slippage for large trades, and they are vulnerable to price manipulation if the pool is small. Also, LPs face impermanent loss when the price of one token changes dramatically. These trade-offs are why newer AMM designs use different curves or dynamic fees, but the constant product remains the baseline reference.
## A Quick Comparison: Constant Product vs. Other AMM Curves
Not all AMMs use the same math. Here’s how the constant product formula stacks up against common alternatives:
| Curve Type | Formula | Best For | Trade-off |
|------------|---------|----------|-----------|
| Constant Product | x * y = k | General-purpose pairs, long-tail tokens | High slippage on large trades |
| Constant Sum | x + y = k | Stablecoins, pegged assets | No price impact but drains reserves |
| Stableswap (hybrid) | Combined x*y and x+y | Stablecoin pools | Low slippage but limited to near-pegged assets |
| Concentrated Liquidity | x * y = k within a price range | Pools with active price ranges | More capital-efficient but complex |
The constant product curve is the simplest to reason about, which is why it remains the default mental model for AMMs.
## Practical Takeaways for Traders and LPs
If you’re trading on a constant product pool, check the pool’s total liquidity before placing a large order—slippage rises as your trade size approaches a meaningful fraction of the reserves. For LPs, understand that your returns come from fees, but you must weigh those against impermanent loss. The formula is your friend if you respect its limits: it provides liquidity where none existed, but it does not guarantee you a profit.
In short, constant product pools are a brilliant piece of financial engineering. They strip away the complexity of order matching and replace it with a single equation that anyone can verify. Whether you’re swapping a meme coin or providing liquidity for a new token, the math is always working behind the scenes—keeping the product constant, the market moving, and the DeFi ecosystem humming.