AMM (Automated Market Maker)¶
Introduction¶
AMM (Automated Market Maker) is a decentralized trading protocol running on smart contracts that determines asset prices through mathematical formulas rather than traditional order books. AMMs are the core infrastructure of the DeFi ecosystem, enabling anyone to create and participate in market making without permission.
Unlike traditional centralized exchanges that rely on order books to match buy and sell orders, AMMs use liquidity pools and pricing algorithms to automatically execute trades. Users deposit assets into liquidity pools, and smart contracts calculate trading prices according to preset mathematical formulas, achieving trustless, censorship-resistant, and perpetually available decentralized trading.
The emergence of AMMs fundamentally changed the paradigm of cryptocurrency trading, enabling long-tail assets to obtain liquidity, lowering the barriers to market making, and laying the foundation for DeFi's explosive growth. Since the launch of Uniswap V1 in 2018, AMMs have become one of the highest-volume and most widely adopted mechanisms in DeFi.
Core Features¶
Constant Product Formula (x * y = k)¶
The most classic AMM model is the Constant Product Market Maker (CPMM), first popularized by Uniswap, with the formula:
- x: The amount of token A in the liquidity pool
- y: The amount of token B in the liquidity pool
- k: The constant invariant
How It Works:
- Initial state: Assume the pool contains 100 ETH (x=100) and 10,000 DAI (y=10,000), then k = 1,000,000
- User trades: A user buys DAI with 10 ETH
- Pool state update: The pool now has 110 ETH (x=110), and according to k being constant, y = 1,000,000 / 110 ≈ 9,091 DAI
- User receives: 10,000 - 9,091 = 909 DAI (fees are deducted from the actual amount)
- Price change: Before the trade, 1 ETH = 100 DAI; after the trade, 1 ETH ≈ 82.6 DAI
Key Characteristics:
- Infinite liquidity: Theoretically, trades of any size can be executed (but with slippage)
- Price discovery: Prices automatically adjust based on supply and demand
- Slippage mechanism: The larger the trade size relative to the pool size, the greater the slippage — a natural expression of supply and demand dynamics
Liquidity Pools and LP Tokens¶
Liquidity Pool:
- Composed of asset pairs deposited by liquidity providers (LPs)
- Typically requires depositing two assets in proportion to the current price (e.g., 50% ETH + 50% DAI)
- All LPs share the pool's assets and trading fees
LP Token (Liquidity Provider Token):
- Proof of equity received after LPs deposit assets
- Represents the LP's proportional share in the pool
- Can be redeemed at any time, withdrawing assets proportionally from the pool
- Can be used in other DeFi protocols (e.g., staking, lending collateral)
Example:
Initial pool state: 100 ETH + 10,000 DAI
Alice deposits: 10 ETH + 1,000 DAI
Alice's share: 10% (10/110)
Alice can redeem: 10% of the pool (regardless of how pool assets change)
Trading Fee Mechanism¶
Fee Standards:
- Uniswap V2: 0.3% trading fee, all distributed to LPs
- Uniswap V3: 0.05% / 0.3% / 1% three tiers, depending on pool settings
- Curve: 0.04% for stablecoin pools, 0.4% for regular pools
- Balancer: 0.01% - 10% customizable
Revenue Distribution:
- Fees are automatically distributed proportionally to LP shares
- Compound growth (fees remain in the pool, increasing LP share value)
- Principal and accumulated fees are withdrawn together upon redemption
Revenue Calculation Example:
Assume Alice owns 1% of an ETH/DAI pool
Daily trading volume: $10,000,000
Fee rate: 0.3%
Alice's daily income: $10,000,000 × 0.3% × 1% = $300
Annualized return: $300 × 365 / invested capital = APR
Price Slippage and Price Impact¶
Slippage:
- The difference between the expected price and the actual execution price
- Determined by the trade size relative to the pool size
- The larger the trade, the higher the slippage (non-linear growth)
Price Impact Calculation:
Based on the constant product formula:
Price Impact = 1 - (k / (x + Δx)) / (y / x)
Where:
- Δx: The amount of input tokens
- x, y: Existing token amounts in the pool
Slippage Example:
Pool state: 100 ETH, 10,000 DAI (k = 1,000,000)
Current price: 1 ETH = 100 DAI
Scenario 1: Buy 1 ETH
Actual price: ≈ 101 DAI/ETH
Slippage: 1%
Scenario 2: Buy 10 ETH
Actual price: ≈ 110 DAI/ETH
Slippage: 10%
Scenario 3: Buy 50 ETH
Actual price: ≈ 200 DAI/ETH
Slippage: 100%
User Protection:
- Set a maximum slippage tolerance (e.g., 0.5%)
- The transaction reverts if slippage exceeds the tolerance
- Prevents front-running attacks and price manipulation
AMM Model Evolution¶
Uniswap V1 (2018)¶
Features: - The simplest constant product AMM implementation - All trading pairs must be paired with ETH - 0.3% fixed fee - ETH/DAI requires routing through ETH (DAI → ETH → USDC)
Limitations: - Hop trading increases costs and slippage - Only supports ERC-20 tokens - Low capital efficiency
Uniswap V2 (2020)¶
Improvements: - ERC-20 / ERC-20 direct trading pairs: No need for ETH intermediary - Price oracle: Time-Weighted Average Price (TWAP) - Flash swaps: Borrow-first-repay-later atomic transactions - Safer architecture: Core + Periphery separation
Impact: - Reduced trading costs - Provided reliable on-chain price sources - Inspired numerous forks (Sushiswap, PancakeSwap, etc.)
Uniswap V3 (2021)¶
Revolutionary Innovations:
1. Concentrated Liquidity: - LPs can specify price ranges for providing liquidity - Capital efficiency improved up to 4000x (theoretical) - Fees are only earned within the specified price range
Example:
Traditional AMM: Provides liquidity across the 0 to ∞ price range
V3: Provides liquidity only in the $1,800 - $2,200 ETH price range
Result: Same capital, significantly increased fee revenue
2. Multi-tier Fees: - 0.05%: Stablecoin pairs - 0.3%: Major token pairs - 1%: Long-tail/high-volatility token pairs
3. Non-Fungible LP (NFT): - Each liquidity position is a unique NFT - Records price range, quantity, and other parameters - No longer simple ERC-20 LP tokens
4. Advanced Oracle: - Obtain multiple historical price points in a single call - Significantly improved Gas efficiency
Trade-offs: - Higher capital efficiency - But increased LP management complexity (requires active price range management)
Uniswap V4 (2024)¶
Core Innovation - Hooks:
- Customizable liquidity pools: Developers can write Hook contracts to inject custom logic at key lifecycle points of a pool
- Supported Hook Events:
beforeInitialize/afterInitializebeforeAddLiquidity/afterAddLiquiditybeforeRemoveLiquidity/afterRemoveLiquiditybeforeSwap/afterSwap
Use Cases: - Dynamic fees (adjusted based on volatility) - On-chain limit orders - TWAMM (Time-Weighted AMM, distributing large order execution over time) - Integration with lending protocols - Automatic rebalancing strategies
Singleton Architecture: - All pools in a single contract - Significantly reduced Gas costs (especially noticeable for multi-hop trades) - Simplified upgrades and maintenance
Native ETH Support: - Uses ETH directly instead of WETH - Reduces wrapping/unwrapping costs
Curve Finance (2020)¶
Focused on Stablecoin Trading:
StableSwap Invariant:
A * n^n * Σx_i + D = A * D * n^n + D^(n+1) / (n^n * Πx_i)
Where:
- A: Amplification coefficient
- n: Number of assets
- x_i: Amount of the i-th asset
- D: Total liquidity (invariant)
Features: - Near-constant sum formula (x + y = k) around stable prices, resulting in extremely low slippage - Switches to constant product when prices deviate from the peg, protecting the pool - Amplification coefficient A can adjust curve steepness
Advantages: - Stablecoin trading slippage is tens of times lower than Uniswap - Suitable for large stablecoin swaps - Supports multi-asset pools (e.g., 3pool: DAI/USDC/USDT)
Applications: - Stablecoin swaps - Pegged asset trading (stETH/ETH, wBTC/renBTC) - Low-slippage large trades
Balancer (2020)¶
Multi-Asset Weighted Pools:
Invariant:
V = Π (B_i / W_i)^W_i
Where:
- B_i: Balance of asset i
- W_i: Weight of asset i (sum = 1)
- V: Constant value
Flexibility: - Supports pools with 2-8 assets - Custom weights (e.g., 80% WETH + 20% DAI) - Variable fees (0.01% - 10%)
Use Cases: - Index funds (e.g., 80/20 pool simulating leveraged positions) - Reducing impermanent loss (non-50/50 ratios) - Liquidity Bootstrapping Pool (LBP)
LBP (Liquidity Bootstrapping Pool): - Starts with high weight (e.g., 95/5), gradually adjusting to target weight (e.g., 50/50) - Price decreases over time, discouraging front-running - A mechanism for fair token distribution by project teams
Other Innovative AMMs¶
SushiSwap (2020): - Fork of Uniswap V2 - Introduced the $SUSHI governance token - 0.25% to LPs, 0.05% for SUSHI buybacks
PancakeSwap (2020): - AMM on BSC - Low Gas fees - Similar to Uniswap V2
Bancor V3 (2022): - Single-sided liquidity (only one token required) - Impermanent loss protection (if held long enough) - Auto-compounding
Maverick Protocol (2023): - Dynamic distribution AMM - Liquidity automatically follows price movement - LPs don't need to manually manage positions
Trader Joe (Avalanche, 2023): - Liquidity Book (discretized liquidity) - Limit order-like liquidity distribution - Zero-slippage trades (within a bin)
Impermanent Loss¶
What Is Impermanent Loss¶
Impermanent Loss (IL) is the value difference LPs experience compared to simply holding assets — it is the primary risk of AMM market making.
Causes: - AMMs require LPs to hold two assets proportionally - When prices change, arbitrageurs adjust pool ratios to reflect market prices - LPs passively "buy low, sell high" the opposite asset, missing out on unilateral gains
Calculation Formula¶
For constant product AMMs, impermanent loss can be precisely calculated:
IL = 2 * sqrt(price ratio) / (1 + price ratio) - 1
Where:
price ratio = current price / initial price
Specific Example:
Initial State: - Deposited 1 ETH + 100 DAI (1 ETH = 100 DAI) - Total value = $200
Scenario 1: ETH price doubles (1 ETH = 200 DAI)
Simply holding: - 1 ETH + 100 DAI = $300
As LP: - Pool rebalances: 0.707 ETH + 141.4 DAI - Total value = \(282.8 - Impermanent loss = (\)282.8 - $300) / $300 = -5.7%
Scenario 2: ETH price drops by half (1 ETH = 50 DAI)
Simply holding: - 1 ETH + 100 DAI = $150
As LP: - Pool rebalances: 1.414 ETH + 70.7 DAI - Total value = \(141.4 - Impermanent loss = (\)141.4 - $150) / $150 = -5.7%
Impermanent Loss Table: | Price Change | Impermanent Loss | |---------|---------| | 1.25x | -0.6% | | 1.5x | -2.0% | | 1.75x | -3.8% | | 2x | -5.7% | | 3x | -13.4% | | 4x | -20.0% | | 5x | -25.5% |
Mitigation Strategies¶
1. Choose low-volatility asset pairs: - Stablecoin pairs (DAI/USDC) - Pegged asset pairs (stETH/ETH) - Correlated asset pairs (WBTC/renBTC)
2. Fee coverage: - High-volume pool fees may exceed impermanent loss - Especially for stablecoin pools (high volume, low volatility)
3. Short-term market making: - Exit promptly when price deviation is small - "Impermanent" loss only becomes "permanent" upon redemption
4. Single-sided liquidity (Bancor): - Only provide one type of token - The protocol bears the impermanent loss risk
5. Concentrated liquidity (Uniswap V3): - Narrow the price range to increase fee revenue - But fees stop accruing when the price moves out of range
6. Impermanent loss insurance: - Bancor offers a 100-day protection period - Insurance protocols like Nexus Mutual
Use Cases¶
Decentralized Trading¶
Core Functions: - Peer-to-contract trading, no counterparty needed - Available 24/7 - No KYC required - Censorship-resistant
Advantages: - Long-tail assets can also obtain liquidity - Permissionless token listing - Globally unified market
Major Platforms: - Ethereum: Uniswap, Curve, Balancer - BSC: PancakeSwap - Polygon: QuickSwap - Arbitrum: Camelot - Solana: Raydium, Orca
Price Oracles¶
TWAP (Time-Weighted Average Price):
Uniswap V2/V3 provides manipulation-resistant on-chain prices:
Features: - High manipulation cost (requires sustained large trades) - Delayed price updates (smooths short-term volatility) - Trustless price source
Applications: - Lending protocols (Compound, Aave) - Synthetic assets (Synthetix) - Options protocols (Opyn) - Stablecoins (Frax)
Liquidity Mining¶
Pioneered by SushiSwap:
- LPs stake to earn $SUSHI rewards
- Dual yield (fees + token rewards)
- "Vampire attack" on Uniswap
Incentive Mechanism:
Token Distribution: - Bootstraps early liquidity - Fair distribution of governance tokens - Solution to the cold start problem
Risks: - Token price decline - Unsustainable high APR - Impermanent loss
Cross-Chain Bridge Liquidity¶
AMM as a Bridging Mechanism:
- THORChain: Cross-chain AMM (BTC/ETH/BNB, etc.)
- Synapse: Stablecoin cross-chain bridge + AMM
- Stargate: LayerZero's cross-chain liquidity
Principle:
Leverage and Derivatives¶
Perpetual Protocol: - vAMM (Virtual AMM) - Synthetic perpetual contracts - No real asset pool required
GMX: - GLP pool (multi-asset liquidity) - LPs serve as trading counterparties - Bear the profit and loss of traders
Advantages and Challenges¶
Advantages¶
Decentralized and Permissionless: - Anyone can create a trading pair - No centralized review required - Resistant to censorship and shutdown
Perpetual Liquidity: - Pools exist permanently (as long as there is liquidity) - No order book depth needed - Trades of any size can execute (with slippage)
Composability: - Seamless integration between smart contracts - DeFi Lego blocks - Innovative protocols can call them directly
Transparent and Verifiable: - All trades are on-chain and auditable - Pricing formulas are public - No dark pools or privileged trades
Passive Market Making: - LPs don't need to actively manage orders - Earn fees passively - Suitable for regular users
Challenges¶
Impermanent Loss: - Price volatility causes losses - May exceed fee revenue - Primary risk source for LPs
Low Capital Efficiency: - Most liquidity in traditional AMMs sits idle - V3 concentrated liquidity partially addresses this - But adds management complexity
MEV Attacks: - Front-running - Sandwich attacks - Arbitrageurs capture most of the value
Large Trade Slippage: - Inherent to the constant product formula - Requires deeper liquidity pools - Or use aggregators to split orders
Gas Costs: - Ethereum mainnet Gas fees are high - Small trades are uneconomical - Relies on L2 or other chains
Price Manipulation Risk: - Small pools are easily manipulated - Affects oracle security - Requires protections like TWAP
Smart Contract Risk: - Code vulnerabilities - Flash loan attacks - Requires audits and insurance
Future Development¶
Technical Innovation Directions¶
1. More Efficient Pricing Curves: - Adaptive curves (adjust based on market conditions) - Hybrid curves (combining CPMM and Stableswap) - Machine learning optimization
2. Active Liquidity Management: - Automatic rebalancing (e.g., Maverick) - AI-driven range adjustment - One-click strategies (e.g., Gamma, Arrakis)
3. Better **Oracles:** - Cross-chain price aggregation - Lower latency - Stronger manipulation resistance
4. Layer 2 Migration: - Uniswap on Arbitrum, Optimism - Native AMMs on zkSync, StarkNet - Significantly reduced Gas costs
5. Cross-Chain AMMs: - THORChain native cross-chain - Cosmos IBC interoperability - Unified liquidity
Regulation and Compliance¶
Challenges: - Anti-Money Laundering (AML) requirements - Securities regulations (token classification) - Tax compliance (complex yield calculations)
Trends: - Compliant AMM versions (KYC-restricted) - Regulatory sandbox experiments - Industry self-regulatory standards
Institutional Adoption¶
Traditional Finance Integration: - Market makers using AMMs for liquidity - Asset managers providing liquidity - Banks exploring AMMs for internal markets
Professional Tools: - Institutional-grade LP management platforms - Sophisticated hedging strategies - Risk management tools
Recommended Reading¶
- What is an Automated Market Maker? - Uniswap Blog
- How Uniswap works - Uniswap Docs
- Formulas for Automated Market Makers - Faisal Khan
- Automated Market Makers: Math, Risks & Solidity Code - Speed Run Ethereum
- Constant Product Automated Market Maker - Medium
- Constant Function Market Maker - Uniswap V3 Book
- What is CPAMM? - Delphi Digital
- Automated Market Makers Explained - Chainlink
Related Concepts¶
- DEX (Decentralized Exchange)
- Liquidity Provider (LP)
- Impermanent Loss
- Yield Farming
- Slippage
- DEX Aggregator
- Flash Swap
- Price Oracle
- MEV
- Layer 2