Intermediate DeFi · 🕑 9 min read

Automated Market Makers (AMMs): How Decentralized Exchanges Actually Work

Learn how AMMs replace traditional order books, why the constant product formula matters, and how to calculate slippage and price impact before you trade. Understanding AMM mechanics is essential for evaluating DeFi protocols and optimizing your execution strategy.

Introduction: From Order Books to Algorithms

If you've used a decentralized exchange (DEX) like Uniswap, you've interacted with an Automated Market Maker (AMM). But most traders don't understand what's actually happening under the hood.

Traditional centralized exchanges use order books—matching buyers and sellers at specific prices. Decentralized exchanges can't work this way because they need to function without a central matching engine. Instead, they use AMMs: algorithmic systems that set prices automatically based on available liquidity.

This fundamental difference affects everything—from slippage to fees to which tokens you can trade. By the end of this lesson, you'll understand the math behind AMMs, evaluate which DEXs offer better execution, and optimize your trades for minimal price impact.

The Constant Product Formula: The Math Behind It All

The most common AMM design uses what's called the constant product formula. Uniswap popularized this model, and it's now the dominant standard across DeFi.

The formula is deceptively simple:

x × y = k

Here's what this means:

  • x = the quantity of one token in the pool (e.g., ETH)
  • y = the quantity of the other token in the pool (e.g., USDC)
  • k = a constant (the product of x and y never changes)

Let's work through a concrete example. Suppose a Uniswap pool contains:

  • 100 ETH
  • 300,000 USDC

The constant k = 100 × 300,000 = 30,000,000

Now someone wants to buy 10 ETH with USDC. Here's what happens:

After the trade, the pool must still satisfy x × y = k. So:

  • New ETH in pool: 100 - 10 = 90
  • New USDC needed: 30,000,000 ÷ 90 = 333,333
  • USDC required: 333,333 - 300,000 = 33,333 USDC

So the trader pays 33,333 USDC for 10 ETH. That's an average price of 3,333 USDC per ETH—higher than the starting price of 3,000 USDC per ETH.

This is the critical insight: as you buy an asset, its price increases automatically. The larger your trade relative to the pool size, the more price impact you experience.

Liquidity, Slippage, and Price Impact

Understanding slippage requires understanding liquidity. In an AMM, liquidity is the total value of tokens in a pool. Larger pools mean larger k, which means more stable prices.

Let's compare two pools, both trading ETH/USDC:

  • Pool A: 100 ETH + 300,000 USDC (k = 30,000,000)
  • Pool B: 1,000 ETH + 3,000,000 USDC (k = 3,000,000,000)

If you buy 10 ETH from Pool A (as we calculated above), you pay 33,333 USDC—a 11.1% price impact.

Now buy 10 ETH from Pool B:

  • New ETH: 1,000 - 10 = 990
  • New USDC: 3,000,000,000 ÷ 990 = 3,030,303
  • USDC required: 3,030,303 - 3,000,000 = 30,303 USDC
  • Price: 3,030 USDC per ETH—only a 1% impact

Price impact is the difference between the expected price (based on current ratio) and the execution price you actually pay. In the second example, your expected price was 3,000 USDC/ETH, but you paid 3,030—a 1% slippage.

This is why liquidity matters so much:

  • Deep liquidity = small price impact for normal-sized trades
  • Shallow liquidity = severe price impact, even for modest trades
  • This is why new tokens with tiny pools are extremely risky

When you see a DEX quote with "slippage tolerance," you're setting a maximum acceptable price impact. If actual impact exceeds this, your transaction reverts. This protects you from sandwiching attacks or extreme market movement.

Why Prices Stay in Balance (And When They Don't)

One elegant feature of AMMs: they naturally maintain prices across multiple pools through arbitrage.

Suppose the ETH/USDC price on Uniswap is 3,000, but Curve (another DEX) offers 3,100 due to different pool balance. An arbitrageur can instantly:

  • Buy 1 ETH on Uniswap for 3,000 USDC
  • Sell 1 ETH on Curve for 3,100 USDC
  • Profit 100 USDC with zero risk

This arbitrage trade rebalances both pools until prices converge. In this way, AMM prices track real market prices through competition and arbitrage, not through a central price mechanism.

However, AMM prices can still diverge from external prices during volatile periods or when liquidity is fragmented. This is why serious traders use price oracles—external data feeds that track prices across markets. Some advanced protocols use multiple oracle sources to prevent manipulation.

One critical risk: if an AMM price severely diverges from the real market price, MEV bots and arbitrageurs will exploit the gap, often at the expense of regular traders who execute at unfavorable prices during volatility.

Fee Structure and Why It Matters

When you trade on an AMM, you pay a swap fee—typically 0.25% to 1%, depending on the DEX and pool tier.

Here's how it works on Uniswap:

  • Standard pools charge 0.30% on every swap
  • This fee is added to the pool and distributed to liquidity providers
  • You don't see it as a separate line item—it's embedded in the price impact calculation

So when you execute a trade, your actual cost is: price impact + swap fee.

This is why DEX selection matters:

  • Uniswap v3: Offers multiple fee tiers (0.01%, 0.05%, 0.30%, 1%) for different pairs. Low-fee tiers attract stablecoin pairs; high-fee tiers are used for volatile pairs
  • Curve: Specializes in stablecoin swaps with very low fees (0.04%) and shallow slippage due to optimized math
  • Balancer: Allows custom pool structures with weighted tokens, often lower fees for certain pairs

For large trades, comparing execution costs across DEXs can save thousands of dollars. Many traders use aggregators like 1inch or Paraswap that automatically route your trade through the best path.

Key Takeaways

  • The constant product formula (x × y = k) is the foundation of most AMMs. It ensures prices adjust automatically based on supply and demand within the pool.
  • Pool liquidity directly determines slippage. Deeper pools offer better prices for the same trade size. Always check pool size before trading small-cap tokens.
  • Price impact increases exponentially with trade size. A 1% trade on a pool causes minimal impact; a 50% trade causes severe impact. Know your pool size before you commit.
  • Arbitrage keeps AMM prices aligned with market prices. If an AMM price diverges too far, bots profit by rebalancing pools. This is usually good for price accuracy but can hurt retail traders during volatile periods.
  • Fee selection matters. Compare swap fees and price impact across DEXs before executing large trades. Aggregators can save you significant costs by routing through optimal paths.
  • AMMs have trade-offs. They offer permissionless trading and deep liquidity for major pairs, but worse execution than order books for small or volatile tokens. Understanding these mechanics helps you trade smarter.
← Back to all lessons
Scroll to Top