Automated Market Makers: How DEXs Trade Without Order Books

Understanding constant product formulas, liquidity pools, impermanent loss, and why AMMs revolutionized token trading.

Trading Without an Order Book

Traditional exchanges — whether stock markets or crypto exchanges like Coinbase — use order books. Buyers post bids at specific prices; sellers post asks. A trade happens when a bid and an ask match. This model requires continuous liquidity provision from professional market makers and struggles in thin markets where few participants are actively quoting prices.

Automated Market Makers (AMMs) replace the order book with a mathematical formula. Instead of matching buyers and sellers, an AMM holds reserves of two (or more) tokens in a smart contract and uses a pricing formula to determine the exchange rate at any moment. Anyone can trade against these reserves directly. Anyone can provide liquidity and earn fees. The formula — not a human market maker — always quotes a price.

Uniswap, launched in 2018, popularized the simplest and most influential AMM formula. Its whitepaper introduced a model that now underpins hundreds of billions of dollars of daily trading volume across DeFi.

The Constant Product Formula: x × y = k

Uniswap's core formula is startlingly simple. A liquidity pool holds two tokens — call them X and Y. The protocol enforces one invariant:

x × y = k

Where x is the reserve of token X, y is the reserve of token Y, and k is a constant. Every trade must leave k unchanged (before fees).

Suppose a pool holds 100 ETH and 200,000 USDC, so k = 20,000,000. A trader wants to buy 10 ETH. After the trade, the pool must hold 90 ETH. To maintain k = 20,000,000, the pool must hold:

y = k / x = 20,000,000 / 90 ≈ 222,222 USDC

The trader must deposit 222,222 − 200,000 = 22,222 USDC to receive 10 ETH. The implied price is 2,222 USDC per ETH — higher than the pre-trade price of 2,000 USDC per ETH. This price increase is called price impact (or slippage): the larger the trade relative to pool reserves, the more the price moves against the trader.

The Pricing Function

Rearranging the constant product formula gives the marginal price at any reserve level:

price of X in terms of Y = y / x

At 100 ETH and 200,000 USDC, the marginal price is 2,000 USDC per ETH. After a large ETH purchase depletes ETH reserves, the price rises — which is exactly what should happen when demand for an asset spikes. The formula enforces this automatically.

Why k Must Stay Constant

The invariant x × y = k ensures the pool always has reserves on both sides and never runs dry. As x approaches 0 (all tokens bought), y approaches infinity (infinite cost). In practice, buyers exhaust their budgets long before this limit, but the formula guarantees the pool always has something to sell.

Liquidity Providers: Earning Fees

AMMs need capital to function. Liquidity providers (LPs) deposit tokens into the pool and receive LP tokens representing their proportional share. In Uniswap v2, a 0.3% fee is charged on every swap and added to the pool reserves (effectively increasing k slightly with each trade). LP tokens represent a claim on the growing reserves.

When an LP withdraws, they redeem their LP tokens for their share of the current reserves — the original deposited assets plus their pro-rata share of all fees earned since they joined. If the pool has traded heavily and accumulated fees, their share is worth more than what they deposited.

Impermanent Loss: The Hidden Cost

LPs face a structural risk called impermanent loss (IL) — the loss compared to simply holding the deposited tokens outside the pool.

Suppose an LP deposits 1 ETH and 2,000 USDC into a Uniswap pool (50/50 by value, k = 2,000). ETH's external market price doubles to $4,000. Arbitrageurs buy ETH from the pool until its price matches the external market. After arbitrage, the pool rebalances:

x × y = 2,000 (k unchanged)
y / x = 4,000 (new price)

→ x = √(2,000 / 4,000) ≈ 0.707 ETH
→ y = √(2,000 × 4,000) ≈ 2,828 USDC

The LP's share is worth 0.707 × $4,000 + $2,828 = $5,656. But if they had just held 1 ETH and 2,000 USDC, they'd have $4,000 + $2,000 = $6,000. The LP is worse off by $344 — that is the impermanent loss.

Impermanent loss is "impermanent" because if ETH returns to $2,000, the loss disappears. But if ETH stays at $4,000, the loss is realized upon withdrawal. For highly volatile or directional token pairs, IL can exceed fee revenue, making LP positions unprofitable. For stablecoin pairs (USDC/USDT), where prices rarely diverge, IL is minimal and fee revenue dominates.

Concentrated Liquidity: Uniswap v3

Uniswap v2's liquidity is spread uniformly across all possible prices — from zero to infinity. This is inefficient: the vast majority of trading happens within a narrow price range, so most LP capital sits idle at extreme prices.

Uniswap v3, launched in 2021, introduced concentrated liquidity. LPs now specify a price range — say, 1,800 to 2,200 USDC per ETH — within which they provide liquidity. Their capital is concentrated in that range and is not deployed outside it. This makes each dollar of LP capital far more efficient: a v3 LP with a narrow range can earn the same fees as a v2 LP with 100x more capital, assuming the price stays within range.

The Trade-Off: Active Management

The price-range model transforms LP positions from passive set-and-forget investments into active positions. If ETH's price moves outside an LP's specified range, their position stops earning fees entirely (all capital converts to whichever token the price moved toward) until they rebalance into a new range. This requires gas fees and active monitoring, making concentrated liquidity better suited to sophisticated LPs, often running automated rebalancing strategies.

Non-Fungible LP Positions

In Uniswap v3, LP positions are represented as NFTs rather than fungible tokens, because each position has unique parameters (range, token pair, fee tier). This breaks composability with protocols that expected fungible LP tokens — a deliberate design decision accepted to enable the efficiency gains of concentrated liquidity.

Fee Tiers and Pool Selection

Uniswap v3 offers multiple fee tiers — 0.01%, 0.05%, 0.3%, and 1% — reflecting the appropriate compensation for different asset risk profiles:

  • 0.01% — Stablecoin pairs (USDC/USDT) with minimal IL and high volume
  • 0.05% — Major liquid pairs like ETH/USDC where competition is tight
  • 0.3% — Standard for mid-cap token pairs
  • 1% — Exotic or illiquid pairs with high IL risk

Market forces naturally route most volume to pools with the best combination of price (low fees) and depth (low slippage). Uniswap v3's architecture allows multiple pools to exist for the same pair at different fee tiers, with aggregators routing trades to minimize total cost.

Beyond Two Tokens: Curve and Balancer

Uniswap's binary-pool model is not the only AMM design. Curve Finance introduced a hybrid invariant optimized for assets that trade near parity — stablecoin pairs and liquid staking derivatives. Curve's formula combines constant sum (x + y = k, which gives zero slippage but can be drained) and constant product, producing a curve that is nearly flat near the peg and curves sharply at extremes. This yields dramatically lower slippage for stablecoin swaps.

Balancer generalized the constant product formula to pools with more than two tokens and arbitrary weights:

∏ (x_i ^ w_i) = k

A Balancer pool might hold 50% ETH, 30% WBTC, and 20% LINK, with the formula enforcing that the weighted product remains constant. This enables index-fund-like pools that automatically rebalance as prices change — an LP essentially holds a self-rebalancing portfolio and earns fees from traders who arbitrage the weights back into balance.

AMMs as Market Infrastructure

AMMs have proven to be remarkably robust and composable DeFi primitives. Because they are smart contracts rather than companies, they operate 24/7 without counterparty risk, are accessible to anyone with an Ethereum wallet, and can be composed with other protocols — a lending protocol can automatically swap collateral types, a yield aggregator can route deposits through an AMM to find the best rate.

The constant product formula's genius is its simplicity: four lines of math replace an entire exchange infrastructure. The cost of that simplicity — impermanent loss, price impact on large trades — has driven a decade of AMM research seeking better formulas, better capital efficiency, and better user experience for liquidity providers.

Related Stories