AMM Mechanisms
Automated Market Makers (AMMs) are decentralized exchange protocols that use algorithmic pricing functions instead of traditional order books. They enable permissionless token swaps by maintaining liquidity pools governed by mathematical curves.
Constant Product Formula (x × y = k)
The foundational AMM model, pioneered by Uniswap, uses the constant product invariant:
Where:
- = Reserve of token X in the pool
- = Reserve of token Y in the pool
- = Constant that remains fixed during trades
Price Determination
The marginal price is derived from the invariant:
Trade Execution
When a trader swaps of token X for of token Y:
Price Impact
The price impact of a trade of size :
Concentrated Liquidity (Uniswap v3)
Uniswap v3 introduced concentrated liquidity, allowing LPs to allocate capital within specific price ranges.
Capital Efficiency Formula
The effective liquidity at a given price range :
Price Range Selection
LPs choose a price range where :
- Within range: Full capital utilization
- Outside range: Position composed entirely of one asset
- At price : Position value is
Fee Tiers
| Fee Tier | Use Case | Tick Spacing |
|---|---|---|
| 0.01% | Stable pairs (USDC/USDT) | 1 |
| 0.05% | Correlated pairs (ETH/stETH) | 10 |
| 0.30% | Standard pairs (ETH/USDC) | 60 |
| 1.00% | Exotic/volatile pairs | 200 |
Concentrated Liquidity Visual
Stable Swap (Curve Finance)
Curve Finance uses a hybrid invariant optimized for pegged assets:
Where:
- = Amplification coefficient (controls curve flatness)
- = Number of tokens in the pool
- = Total pool value (sum of all at equilibrium)
Amplification Coefficient Impact
| A Value | Curve Behavior | Best For |
|---|---|---|
| Low (1-50) | More volatile, like constant product | Volatile pairs |
| Medium (100-500) | Balanced curve | Moderately correlated |
| High (1000+) | Very flat, like constant sum | Stablecoins |
Stable Swap Curve Shape
Weighted Pools (Balancer)
Balancer generalizes the constant product formula to weighted multi-token pools:
Where:
- = Reserve of token
- = Weight of token (must sum to 1)
- = Number of tokens (typically 2-8)
Price Formula in Weighted Pools
The price of token in terms of token :
Swap Calculation
| Pool Type | Weights | Use Case |
|---|---|---|
| 50/50 | Equal | Standard trading pairs |
| 80/20 | Imbalanced | ETH/stablecoin |
| Weighted | Custom | Index funds |
| Stable | Pegged | Stablecoin pairs |
Flash Swaps
Flash swaps allow users to receive tokens before paying for them, enabling arbitrage within a single transaction:
- Receive token Y from pool
- Execute arbitrary operations (arbitrage, liquidation, etc.)
- Return token X to pool (or revert)
Flash Swap Fee
Where is typically 0.25% on Uniswap v2.
Impermanent Loss Mathematics
Impermanent loss occurs when the price ratio of pooled tokens changes from the entry point.
Impermanent Loss Formula
For a 50/50 pool, impermanent loss as a function of price ratio change :
Where (price ratio change).
Impermanent Loss Table
| Price Change () | Impermanent Loss |
|---|---|
| 1.25x (25% increase) | -0.6% |
| 1.50x (50% increase) | -2.0% |
| 2.00x (100% increase) | -5.7% |
| 3.00x (200% increase) | -13.4% |
| 5.00x (400% increase) | -25.5% |
| 0.50x (50% decrease) | -5.7% |
Generalized Impermanent Loss
For weighted pools with weight for the base asset:
Break-Even Fee Formula
To offset impermanent loss, the required fee APR:
Where is the time period in years.
Real-World Example: Uniswap v3 LP Position
An LP provides $100,000 in ETH/USDC with:
- Entry price: ETH = $2,000
- Range: 2,400
- Fee tier: 0.30%
Scenario 1: ETH stays in range
- Earns ~25% APR from fees
- Impermanent loss: minimal
- Net profit: ~25% minus gas costs
Scenario 2: ETH rises to $3,000
- Position converts entirely to USDC
- Impermanent loss: ~15%
- Net result: Underperforms simple HODL
LP Position Calculations
Position Value at Different Prices:
Where:
- = Liquidity depth
- = Current price
- = Lower bound price
Fee Earnings Formula
Gas Cost Considerations
| Action | Gas Units | Cost at 30 gwei |
|---|---|---|
| Add Liquidity | 200,000 | ~0.006 ETH |
| Remove Liquidity | 150,000 | ~0.0045 ETH |
| Collect Fees | 100,000 | ~0.003 ETH |
| Swap | 150,000 | ~0.0045 ETH |
Break-Even Analysis:
AMM Risk Assessment
Risk Matrix
| Risk | Constant Product | Concentrated | Stable Swap |
|---|---|---|---|
| Impermanent Loss | Medium | High | Very Low |
| Smart Contract | Low | Medium | Low |
| Oracle Dependency | Low | Low | Low |
| Gas Costs | Medium | High | Low |
| Complexity | Low | High | Medium |
Monitoring Metrics
Track these metrics for LP positions:
- Capital Utilization: How much of your liquidity is earning fees
- Fee APR vs IL: Compare fee income to impermanent loss
- Range Utilization: Percentage of time price stays in range
- Gas Efficiency: Fees earned minus gas costs
Trade-Offs
| AMM Type | Pros | Cons |
|---|---|---|
| Constant Product | Simple, battle-tested | High slippage, capital inefficient |
| Concentrated Liquidity | Capital efficient | Active management required |
| Stable Swap | Low slippage for pegged assets | Limited to correlated assets |
| Weighted Pools | Flexible multi-asset | More complex math |
| Flash Swaps | Atomic arbitrage | Complex, requires capital |
Key Trade-Offs
- Passive vs Active: Simple AMMs are passive but less efficient; concentrated liquidity requires active management
- Capital Efficiency vs Complexity: More capital-efficient designs are harder to understand and manage
- Decentralization vs Speed: On-chain AMMs are slower than order books but more censorship-resistant
- Fee Income vs Impermanent Loss: Higher fee tiers may attract less volume, reducing total income
AMM Design Evolution
Generation Comparison
| Generation | Model | Year | Innovation |
|---|---|---|---|
| 1st | Constant Product (x×y=k) | 2020 | Basic AMM |
| 2nd | Concentrated Liquidity | 2021 | Capital efficiency |
| 3rd | Stable Swap | 2020-2021 | Pegged asset optimization |
| 4th | Hybrid | 2022+ | Order book + AMM |
| 5th | Intent-based | 2023+ | User intent matching |
AMM Mathematics Summary
AMM Selection Guide
| Use Case | Recommended AMM | Reason |
|---|---|---|
| Stablecoins | Curve | Minimal slippage |
| Major pairs | Uniswap v3 | Capital efficiency |
| Long-tail assets | Uniswap v2 | Simple, passive |
| Multi-asset | Balancer | Weighted pools |
| Leveraged trading | GMX | Deep liquidity |
AMM Fee Comparison
| Protocol | Fee Range | Fee Distribution |
|---|---|---|
| Uniswap v2 | 0.30% | 100% to LPs |
| Uniswap v3 | 0.01-1% | 100% to LPs |
| Curve | 0.04% | 50% veCRV holders |
| SushiSwap | 0.30% | 81.5% LPs, 9% SUSHI stakers |
| Balancer | 0.001-10% | 87.5% LPs, 12.5% protocol |
Advanced AMM Concepts
K-factor (Constant Sum):
This provides zero slippage but is unsustainable for volatile assets.
Geometric Mean:
Used in Balancer for equal-weight pools.
AMM Performance Metrics
Key Performance Indicators
| Metric | Formula | Target |
|---|---|---|
| Capital Utilization | Volume / TVL | > 1.0 |
| Fee APR | Fees / TVL × 365 | > IL |
| Slippage | ΔP / P | < 0.5% |
| Impermanent Loss | (V_hold - V_lp) / V_hold | Minimize |
| MEV Extracted | Front-run profit | Minimize |
AMM Efficiency Formula
Higher efficiency indicates better capital utilization relative to costs.
Pool Health Indicators
Interview Questions
-
Explain the constant product formula and how it determines token prices. What are the implications of this formula for large trades?
-
How does concentrated liquidity in Uniswap v3 improve capital efficiency, and what additional risks does it introduce for liquidity providers?
-
Calculate the impermanent loss for a 50/50 pool when the price ratio doubles. How would you structure fees to offset this loss?
Quiz Questions
-
In the constant product formula x × y = k, what happens to the price of token X when a large amount of X is sold into the pool?
- A) Price increases
- B) Price decreases
- C) Price stays the same
- D) Price becomes undefined
-
What is the primary benefit of concentrated liquidity over constant product AMMs?
- A) Lower gas costs
- B) Better capital efficiency within price ranges
- C) No impermanent loss
- D) Higher total value locked
-
In Curve's stable swap invariant, what does the amplification coefficient A control?
- A) Trading fees
- B) The flatness of the curve near equilibrium
- C) Number of tokens in the pool
- D) Slippage tolerance