AMMs (Automated Market Makers)

AMMs (Automated Market Makers)

On-chain liquidity mechanisms that replace order books with a mathematical formula. A smart contract holds two (or more) tokens and quotes prices algorithmically. No market maker, no bid/ask book — just a function that determines what you get for what you give.

AMMs enable trading for any token pair without requiring a counterparty to be online. This is why every long-tail token has liquid markets on-chain while those same tokens would fail to list on centralized exchanges.

The Constant Product Formula

Uniswap V1 (2018) popularized the simplest AMM formula:

x · y = k

Where x is the reserve of token A, y is the reserve of token B, and k is a constant. Any swap must preserve k. If you add Δx of token A to the pool, you receive Δy of token B such that (x + Δx)(y - Δy) = k.

What this means in practice:

  • The price of A in terms of B is y/x at any moment
  • Larger trades move price more (the curve is convex)
  • The pool never runs out of liquidity — but price becomes extreme for large trades

Price impact is unavoidable under the constant product formula. Slippage is the difference between the quoted price and the execution price; it scales with trade size relative to pool depth.

Liquidity Providers

Anyone can supply both tokens to a pool in proportion and receive LP (liquidity provider) tokens representing their share. LP tokens earn a fee (typically 0.30% or 0.05% per trade) distributed proportionally. Redeeming LP tokens returns the underlying tokens plus accumulated fees.

Impermanent loss (IL) is the principal risk. If the price ratio of the two tokens changes after you deposit, you end up with less value than if you had just held the tokens. The loss is "impermanent" because it disappears if prices return to the deposit ratio — but if you withdraw while prices are different, it becomes realized.

The intuition: the AMM formula continuously rebalances your position toward the token that's falling in value. You always sell the appreciating token and accumulate the depreciating one. Fees compensate for IL in high-volume pools; low-volume pools with volatile assets can result in net losses for LPs.

Concentrated Liquidity (Uniswap V3)

Uniswap V3 (2021) let LPs specify price ranges for their liquidity. Instead of being deployed across the full price curve from 0 to ∞, liquidity sits only where the LP chooses — e.g., ETH between $1,800 and $2,200.

Benefits:

  • Capital efficiency: 4,000× better at the midpoint of a narrow range vs V2
  • Higher fee income: the same capital earns more fees when concentrated around the active price
  • Customizable risk: stablecoin pairs can be concentrated in [0.999, 1.001]; volatile pairs spread wider

Trade-offs:

  • Active management required: out-of-range liquidity earns no fees
  • Higher IL: concentrated positions take more IL per dollar when price moves out of range
  • Complexity: V3 positions are ERC-721 NFTs (each range is unique) rather than fungible LP tokens

Curve StableSwap

Curve (2020) introduced a hybrid formula that combines the constant product curve with a constant sum formula (x + y = k). The result: nearly zero slippage near the target peg and natural price discovery away from it.

Optimized for correlated assets: stablecoin pairs (USDC/USDT/DAI), wrapped asset pairs (stETH/ETH, wBTC/renBTC). The stable assumption breaks during depegs — Curve pools suffered significant LP losses during the 3pool imbalances of 2023 when USDC temporarily depegged following SVB.

TWAP Oracles

AMMs compute a time-weighted average price (TWAP) by accumulating price-time products. The TWAP over a window of N blocks is much harder to manipulate than a spot price: an attacker must sustain an artificial price for the entire window, requiring capital proportional to the window length.

Uniswap V3 makes TWAP observation gas-efficient via geometric mean price accumulators. Many protocols use Uniswap TWAPs as their on-chain price feed for assets without Chainlink support. See mev for why spot prices are dangerous and TWAPs are the safer oracle pattern.

Balancer Weighted Pools

Balancer (2020) generalized the constant product formula to arbitrary token weights and pool sizes. An 80/20 ETH/USDC pool rebalances at a different rate than a 50/50 pool — ETH holders can maintain exposure while still earning fees. Balancer also introduced multi-token pools (up to 8 assets) and managed pools with dynamic weights.

AMMs vs Order Books

AMM Order Book
Liquidity Always available Requires market makers
Long-tail support Any token pair Only liquid pairs
Price discovery Algorithmic, reactive Active, predictive
Large trades High slippage Better for size
MEV exposure High (sandwich attacks) Lower
Capital efficiency Low (V2) to high (V3) High

Centralized exchanges use order books. On-chain, AMMs dominate because they require no off-chain infrastructure. mev sandwich attacks exploit AMM mempool visibility — order books don't have this problem because orders aren't broadcast before matching.

Related

mev · flash-loans · defi-risks · stablecoins · liquidity-flows

Sources