Skip to content
On this page
  1. Key Takeaways
  2. What It Is
  3. The Intuition
  4. How a Constant Product AMM Works
  5. Worked Example
  6. Common Mistakes
  7. Frequently Asked Questions
  8. Sources
  9. Disclaimer
← All concepts
Crypto & DeFiAdvanced6 min read

Constant-Product AMM: How x*y=k Pools Price Trades

A constant product AMM is an automated market maker that prices trades using the formula x*y=k, where x and y are the two token reserves in a pool and k must stay constant after each swap. It replaces the traditional order book with a math curve that always quotes a price.

Key Takeaways

  • A constant-product AMM keeps the product of its two reserves fixed, written as x times y equals k.
  • The pool always quotes a price, so trades execute without a matching buyer or seller.
  • Large trades move price sharply because price impact grows as reserves shift.
  • Liquidity providers earn fees but take on impermanent loss when the price ratio changes.

Key Takeaways

  • A constant-product AMM keeps the product of its two reserves fixed, written as x times y equals k.
  • The pool always quotes a price, so trades execute without a matching buyer or seller.
  • Large trades move price sharply because price impact grows as reserves shift.
  • Liquidity providers earn fees but take on impermanent loss when the price ratio changes.

What It Is

A constant-product automated market maker, or AMM, is a smart contract that lets people swap two tokens against a shared pool of reserves. Instead of matching buyers to sellers like an exchange order book, it uses a fixed mathematical rule to set prices. The rule is the constant product formula, popularized by Uniswap.

The pool holds reserves of two tokens, call them x and y. The contract enforces that the product x * y stays equal to a constant k after every trade, ignoring fees. The current price is simply the ratio of the reserves.

The Intuition

Order books need two willing parties at the same price at the same time. In thin markets that rarely happens, so trades stall. An AMM removes the matching problem by always being willing to trade, at a price the curve dictates.

The constant product curve has a useful property: it can never run dry. As you buy more of token x, the formula demands ever more of token y for each additional unit, so the price rises without limit and the pool keeps a balance of both. That guarantees a quote in any market condition, though the quote gets worse for large orders. The trade-off is built into the geometry of the curve.

How a Constant Product AMM Works

The invariant is:

x * y = k

Here x and y are the reserves of the two tokens and k is their product. The spot price of x in terms of y is y / x. When a trader sells an amount of x into the pool, the new x reserve goes up and the new y reserve must fall so the product stays at k. The trader receives the difference in y.

Solving for the output, ignoring fees, a deposit of dx returns:

dy = y - k / (x + dx)

The bigger dx is relative to the pool, the worse the rate, because the curve bends. This is price impact. Most pools also charge a fee, often around 0.3 percent, taken from the input. The fee stays in the pool, which nudges k slightly higher after each trade and is the return that compensates liquidity providers.

Anyone can become a liquidity provider by depositing both tokens in the current ratio. They receive pool tokens representing their share and can redeem them later for their portion of the reserves plus accrued fees.

The pool's price stays aligned with the outside market through arbitrage rather than any oracle. If the pool quotes ETH cheaply compared with a centralized exchange, traders buy from the pool until the price matches, and the reverse if it quotes high. Those arbitrage trades are profitable for the trader and are what keep the pool honest, but they are also the mechanism behind impermanent loss, because the pool is effectively selling the appreciating asset to the arbitrageur at each step.

Worked Example

A pool holds 10 ETH and 20,000 USDC, so the spot price is 2,000 USDC per ETH. The invariant is k = 10 * 20,000 = 200,000.

You want to buy 1 ETH. After the trade the pool holds 9 ETH. To keep k constant, the USDC reserve must become 200,000 / 9 = 22,222.22. So you must add 22,222.22 - 20,000 = 2,222.22 USDC.

You paid 2,222.22 USDC for 1 ETH, an effective price well above the 2,000 starting quote. That gap is price impact, and it grew because your order was large relative to the 10 ETH pool. In a pool with 1,000 ETH, the same 1 ETH purchase would barely move the price. Depth matters.

Common Mistakes

  1. Ignoring price impact on large orders. The quoted spot price applies only to an infinitesimal trade. Big orders walk up the curve and pay much more. Splitting an order or using a deeper pool reduces the cost.

  2. Confusing the pool price with the global market price. An AMM price only matches the wider market because arbitrageurs trade the gap away. In a fast move, the pool can lag, and the first trader effectively pays for the correction.

  3. Assuming providing liquidity is passive income with no downside. Fees are real, but so is impermanent loss when the price ratio shifts. The net result can be worse than simply holding the two tokens.

  4. Overlooking slippage settings. Without a slippage limit, a trade can execute at a far worse price than expected if the pool moves before confirmation, including from front-running.

  5. Treating all pools as equally safe. Pool depth, fees, and the quality of the token contracts vary widely. A thin pool with a low-quality token is fragile regardless of the formula.

Frequently Asked Questions

What is a constant product AMM in simple terms? A constant product AMM is a smart contract that swaps two tokens by keeping the product of its reserves constant, written x times y equals k. It always offers a price, so you can trade without waiting for a counterparty.

How does a constant-product AMM affect investment decisions? Because price impact rises with order size, the formula tells you that trading large amounts in a small pool is expensive. Checking pool depth before a trade helps you estimate how much the price will move against you.

What is a real-world example of a constant-product AMM? An ETH-and-stablecoin pool that quotes a price from its reserves is the classic case. When you buy ETH, the pool's ETH reserve falls and its stablecoin reserve rises to keep the product fixed.

How can investors avoid bad fills on a constant-product AMM? Set a slippage tolerance, prefer deeper pools, and split large orders so each piece moves the price less. These habits limit price impact and front-running losses.

How is a constant-product AMM different from a StableSwap AMM? A constant-product AMM uses x times y equals k for all pairs, which suits volatile assets but charges high slippage near the edges. A StableSwap AMM flattens the curve for assets meant to trade near a fixed ratio, giving lower slippage for stablecoin pairs.

Sources

  1. Uniswap. "What Is an Automated Market Maker?" https://blog.uniswap.org/what-is-an-automated-market-maker
  2. Uniswap Docs. "Protocol Overview: How Uniswap Works." https://developers.uniswap.org/contracts/v2/concepts/protocol-overview/how-uniswap-works
  3. Uniswap V3 Development Book. "Constant Function Market Maker." https://uniswapv3book.com/milestone_0/constant-function-market-maker.html
  4. Ethereum.org. "Decentralized Finance (DeFi)." https://ethereum.org/en/defi/

Disclaimer

This article is educational content only and is not financial advice. Nothing here is a recommendation to buy, sell, or hold any security. Consult a licensed advisor before making investment decisions.

Back to your knowledge path

The IWP Substack

You understand the concept. Now see it applied.

The Investing With Purpose Substack turns ideas like this into research and risk-managed trade plans on real stocks, updated every week.

Read on Substack (opens in a new tab)

Related concepts