DeFi

AMMs & Liquidity

AMMs and Liquidity

Module 2 of DeFi


What Is an AMM?

Automated Market Maker — a smart contract that holds token reserves and enables trading via mathematical formulas instead of order books.

No counterparty needed. Trade against the pool.


The Constant Product Formula

Uniswap V2's core equation:

x × y = k

x = Reserve of Token A
y = Reserve of Token B
k = Constant (invariant)

Example Trade

Pool: 100 ETH × 200,000 USDC = 20,000,000 (k)

Buy 1 ETH:
  New ETH: 99
  New USDC: 20,000,000 / 99 = 202,020
  Cost: 202,020 - 200,000 = 2,020 USDC
  Effective price: $2,020/ETH

Larger trades = more slippage (worse price).


Liquidity Provision

How It Works

  1. Deposit equal value of both tokens
  2. Receive LP tokens (pool shares)
  3. Earn trading fees (typically 0.3%)
  4. Withdraw anytime with accumulated fees

LP Token Value

Your share = Your LP tokens / Total LP tokens

If pool has: 100 ETH + 200,000 USDC
You hold: 10% of LP tokens
Your value: 10 ETH + 20,000 USDC

Impermanent Loss

The risk of providing liquidity.

What Is It?

When prices change, LPs end up with different ratios than if they'd just held.

Initial: 10 ETH ($2,000) + 20,000 USDC = $40,000

ETH 2x to $4,000:
  If HELD: 10 ETH ($40,000) + 20,000 USDC = $60,000
  As LP:   ~7.07 ETH + 28,284 USDC = $56,568

Impermanent Loss: $3,432 (5.7%)

When Is It Worst?

Price ChangeImpermanent Loss
1.25x0.6%
1.50x2.0%
2x5.7%
3x13.4%
4x20.0%
5x25.5%

Mitigations

  • Collect enough fees to offset IL
  • Use stablecoin pairs (minimal IL)
  • Use concentrated liquidity carefully
  • Hedge with options

AMM Variations

Uniswap V3: Concentrated Liquidity

LPs choose price ranges:

Instead of: Liquidity from $0 to ∞
You choose: Liquidity from $1,800 to $2,200

Result:
  - More capital efficient (up to 4000x)
  - Earn more fees in range
  - But: Out of range = earning nothing

Curve: StableSwap

Optimized for similar-priced assets:

Constant Product: High slippage
StableSwap: Low slippage for stables

USDC/USDT trade:
  Uniswap V2: 0.3% slippage
  Curve: 0.01% slippage

Balancer: Weighted Pools

Multi-asset pools with custom weights:

Traditional: 50/50 ratio
Balancer: 80/20, 60/20/20, any combination

Key Metrics

TVL (Total Value Locked)

Assets in the protocol:

  • Uniswap: ~$5B
  • Curve: ~$2B
  • Balancer: ~$1B

Volume

Daily trading volume indicates usage.

APR/APY

Yield for liquidity providers:

APR = (Fees × 365) / TVL
APY = APR with compounding

Key Takeaways

  1. AMMs use math, not order books
  2. x × y = k is the foundation
  3. Impermanent loss is the main LP risk
  4. Concentrated liquidity improves efficiency but adds complexity
  5. Different curves for different use cases

Questions to Consider

  1. When is providing liquidity profitable?
  2. Why do stablecoin pools have lower IL?
  3. How does concentrated liquidity change the game?