Learn / AMM Mechanics

AMM Mechanics Explained

How Automated Market Makers power DEX trading: constant product formula, liquidity provision, impermanent loss, and concentrated liquidity.

15 min read Intermediate DEX
The Bottom Line

AMMs replaced order books with mathematical formulas to enable permissionless trading. The constant product formula (x*y=k) determines prices automatically based on supply and demand. Understanding AMM mechanics - including impermanent loss and slippage - is essential for anyone providing liquidity or trading on DEXs.

What Are Automated Market Makers?

Traditional exchanges use order books where buyers and sellers post prices. Automated Market Makers (AMMs) replace this with liquidity pools and mathematical formulas that determine prices algorithmically.

Why AMMs Matter

  • Permissionless - Anyone can trade or provide liquidity
  • Always available - No need to wait for counterparty orders
  • Passive income - LPs earn fees from every trade
  • Foundation of DeFi - Powers most decentralized trading

The Constant Product Formula

The most common AMM formula, pioneered by Uniswap, is:

x * y = k

Where x and y are the quantities of two tokens in a pool, and k is a constant that must be maintained after every trade.

How It Works

Imagine a pool with 1,000 ETH and 2,000,000 USDC:

  • k = 1,000 * 2,000,000 = 2,000,000,000
  • Implied price: 2,000,000 / 1,000 = $2,000 per ETH

If a trader wants to buy 10 ETH:

  1. New ETH in pool: 1,000 - 10 = 990
  2. Required USDC: 2,000,000,000 / 990 = 2,020,202
  3. USDC paid: 2,020,202 - 2,000,000 = $20,202
  4. Effective price: $2,020.20 per ETH (slightly above spot)

Price Impact and Slippage

The formula creates a hyperbolic curve where larger trades move the price more:

  • Small trades: minimal price impact
  • Large trades: significant price impact (slippage)
  • Pool size matters: bigger pools = less slippage

This design prevents anyone from draining the pool entirely - as assets become scarce, their price approaches infinity.

Liquidity Provision

How LPs Add Liquidity

  1. Deposit equal values of both tokens (e.g., $10k ETH + $10k USDC)
  2. Receive LP tokens representing your pool share
  3. Earn trading fees proportional to your share
  4. Redeem LP tokens to withdraw your assets + earned fees

LP Token Math

LP tokens track your ownership percentage. If you own 1% of LP tokens, you're entitled to 1% of all assets in the pool - but those assets change based on trading activity.

Scenario Your Deposit After Trading
Price unchanged 50 ETH + 100k USDC 50 ETH + 100k USDC + fees
ETH price doubles 50 ETH + 100k USDC ~35 ETH + ~141k USDC
ETH price halves 50 ETH + 100k USDC ~71 ETH + ~71k USDC

Impermanent Loss

Impermanent loss (IL) is the difference between holding assets in a pool versus simply holding them in your wallet. It's called "impermanent" because it only becomes permanent when you withdraw.

Why It Happens

AMMs continuously rebalance to maintain the constant product formula. When prices move, arbitrageurs trade against the pool to capture the difference, causing:

  • Pool gains more of the depreciating asset
  • Pool loses some of the appreciating asset
  • LPs end up with a different asset mix than they deposited

Impermanent Loss Table

Price Change Impermanent Loss
1.25x (25% up) 0.6%
1.5x (50% up) 2.0%
2x (100% up) 5.7%
3x (200% up) 13.4%
4x (300% up) 20.0%
5x (400% up) 25.5%
IL is Symmetric

Impermanent loss is the same whether the price goes up or down by the same ratio. A 2x price increase and a 0.5x price decrease both cause 5.7% IL. The key factor is how much the price ratio between the two assets diverges from your entry point.

When LPs Profit Despite IL

LPs can still profit if trading fees exceed impermanent loss:

  • High-volume pools generate more fees
  • Stable pairs (USDC/USDT) have minimal IL
  • Token incentives (liquidity mining) offset IL
  • Mean-reverting assets eventually return to entry ratio

AMM Types and Innovations

Uniswap V2: Standard Constant Product

The baseline AMM. Simple, battle-tested, but capital-inefficient - liquidity is spread across all prices from 0 to infinity.

Uniswap V3: Concentrated Liquidity

LPs choose specific price ranges for their liquidity. This enables:

  • Up to 4000x capital efficiency
  • Lower slippage for traders in active ranges
  • Higher fee earnings for LPs in correct range
  • More IL risk if price leaves your range

Curve: Stableswap

Uses an "amplification coefficient" to flatten the curve for similar-value assets. Enables near-zero slippage for stablecoin swaps.

Balancer: Multi-Asset Pools

Supports pools with 2-8 tokens and custom weightings (e.g., 80% ETH / 20% USDC instead of 50/50).

AMM Security Vulnerabilities

Price Oracle Manipulation

AMM spot prices are "trivial to manipulate" within a single transaction. Protocols that use instantaneous AMM prices as oracles are vulnerable to:

  • Flash loan attacks
  • Sandwich attacks on dependent protocols
  • Collateral manipulation exploits
Security Rule

Never use instantaneous AMM spot prices as critical oracle data for lending, collateral valuation, or other high-stakes operations. Use TWAP (time-weighted average price) or external oracles like Chainlink instead.

Sandwich Attacks

Attackers detect pending large trades and:

  1. Buy before the victim's trade (frontrun)
  2. Let victim trade at worse price
  3. Sell after victim's trade (backrun)

Defense: Use private transaction relays (Flashbots Protect) and set tight slippage limits.

Uniswap V4: Programmable Liquidity

Uniswap V4 (launched October 2024) introduced hooks — custom smart contract modules that execute at 14 different points in a pool’s lifecycle. This makes AMM behavior programmable for the first time:

  • Dynamic fee hooks — Fees adjust automatically based on realized volatility, protecting LPs during high-volatility periods. Research shows optimal fees are proportional to volatility: fees set too low relative to an asset’s volatility consistently underperform a simple hold strategy.
  • TWAMM hooks — Time-Weighted AMM for large orders split over time to minimize price impact
  • Limit order hooks — On-chain limit orders executed within the AMM framework
  • Oracle hooks — Custom price feed logic integrated directly into pools
  • KYC/compliance hooks — Permissioned pools for institutional DeFi

V4 consolidates all pools into a single “singleton” contract (instead of one contract per pool), dramatically reducing gas costs for multi-hop trades. The design space is open-ended — anyone can write and deploy a hook, enabling AMM experimentation without forking the protocol.

LP Profitability: The Empirical Reality

A comprehensive study of 17 major Uniswap V3 pools found a striking result:

LPs Lost Money Overall

Total fees earned: $199.3 million. Total impermanent loss: $260.1 million. Net loss: $60.8 million. On average, V3 LPs would have been better off simply holding their assets.

However, profitability varies dramatically by pool type:

  • Stable pairs (USDC/USDT) — Consistently profitable because price barely moves, so IL is negligible while fees accumulate steadily
  • Volatile pairs (ETH/USDT, WBTC/ETH) — Net-negative for most LPs because large price swings generate IL that exceeds fee income

The Professional LP Advantage

Volume and profits are heavily concentrated among professional participants:

  • Top 10 pools capture >85% of total Uniswap V3 volume
  • Top 10% of LPs (by capital) capture >60% of fees within each pool
  • Professional LPs (market makers, MEV bots, JIT providers) outperform retail LPs by 5–10× on a per-capital basis

Just-In-Time (JIT) Liquidity

JIT liquidity is a sophisticated MEV strategy where providers front-run large swaps:

  1. Observe a large pending swap in the mempool
  2. In the same block, before the swap: deposit concentrated liquidity in the exact tick range the swap will traverse
  3. The swap executes against the JIT provider’s liquidity, earning the full swap fee
  4. Immediately after the swap: remove the liquidity

The JIT provider earns fees from a single swap with minimal IL (liquidity held for only one block). Regular LPs are harmed because JIT providers dilute their fee share during the highest-value swaps.

Concentrated Liquidity as a Short Straddle

Research reveals that a concentrated liquidity position is economically equivalent to selling a short straddle (short put + short call) in options. The LP position has negative gamma — it loses value as volatility increases, just like a short options position. This explains why:

  • LP returns are negatively correlated with realized volatility
  • Providing liquidity is essentially selling volatility insurance to traders
  • Dynamic hedging of concentrated positions requires continuous delta adjustments
  • LPs should think of fees as the “options premium” they collect for bearing volatility risk

Evaluating LP Opportunities

Factor Good Sign Warning Sign
Fee APR Sustainable trading volume Incentive-dependent volume
Asset Correlation Correlated or stable pairs (lower IL) Volatile, uncorrelated pairs
Pool Size Sufficient liquidity for trading Too small (slippage) or too large (diluted fees)
Historical IL Fees exceed historical IL Persistent IL exceeds fees
Incentives Sustainable token emissions Unsustainable farm rewards

Key Takeaways

Summary
  • x*y=k — The constant product formula determines AMM pricing
  • Slippage increases with trade size relative to pool size
  • Impermanent loss occurs when prices diverge from your entry ratio
  • LP profitability is not guaranteed — Across 17 major Uniswap V3 pools, LPs lost $60.8M net. Stable pairs profit; volatile pairs typically don’t
  • Professional LPs dominate — Top 10% of LPs capture >60% of fees; JIT liquidity extracts value from retail LPs
  • Uniswap V4 hooks make AMM behavior programmable — dynamic fees, TWAMM, limit orders, and compliance modules
  • Concentrated liquidity = selling volatility — LP positions are economically equivalent to short straddles in options markets
  • Security risk — Never use spot AMM prices as oracle data; use TWAP or Chainlink