Introduction: Trading Without Middlemen
If you've ever swapped tokens on Uniswap, SushiSwap, or Curve, you've used an automated market maker (AMM). AMMs are the core innovation that makes decentralized exchanges (DEXs) possible โ they replace traditional order books with smart contracts and mathematical formulas to determine asset prices.
But how exactly do they work under the hood? In this guide, we'll break down AMM mechanics, explore different models, and explain the risks and rewards of participating as a liquidity provider.
The Problem AMMs Solve
On centralized exchanges like Coinbase or Binance, trading relies on an order book model: buyers post bids, sellers post asks, and a matching engine pairs them together. This works well when there's high volume and many participants, but it has significant drawbacks in decentralized environments:
- Low liquidity on long-tail token pairs makes order books inefficient
- On-chain order books are expensive due to gas costs for every order placement and cancellation
- Market makers on traditional order books need sophisticated infrastructure
AMMs solve this by removing the need for counterparties entirely. Instead, you trade against a liquidity pool โ a smart contract holding reserves of two (or more) tokens.
The Constant Product Formula
The most common AMM model, pioneered by Uniswap, uses the constant product formula:
x ร y = k
Where:
- x = the quantity of Token A in the pool
- y = the quantity of Token B in the pool
- k = a constant that must remain the same after every trade
A Practical Example
Imagine a pool with:
- 10 ETH (Token A)
- 30,000 USDC (Token B)
- k = 10 ร 30,000 = 300,000
The implied price of ETH is 30,000 / 10 = 3,000 USDC per ETH.
Now, a trader wants to buy 1 ETH. After the trade, the pool must still satisfy x ร y = 300,000:
- New ETH in pool: 9
- New USDC needed: 300,000 / 9 = 33,333.33 USDC
- The trader pays: 33,333.33 - 30,000 = 3,333.33 USDC for 1 ETH
Notice the trader paid 3,333 USDC instead of the "spot price" of 3,000. This difference is called price impact โ and it increases with larger trades relative to pool size. This is why deep liquidity matters.
Liquidity Providers: The Backbone of AMMs
AMMs don't generate liquidity from thin air. Liquidity providers (LPs) deposit equal values of both tokens into the pool and receive LP tokens representing their share.
Why Provide Liquidity?
- Trading fees: Every swap incurs a fee (typically 0.3% on Uniswap v2), which is distributed proportionally to LPs
- Liquidity mining rewards: Many protocols offer additional token incentives to attract LPs
- Passive income: Your capital earns fees 24/7 without active management
The Risk: Impermanent Loss
Impermanent loss (IL) is the most important risk LPs face. It occurs when the price ratio of the deposited tokens changes compared to when you deposited them.
Example: You deposit 1 ETH and 3,000 USDC when ETH = $3,000. If ETH rises to $4,000, the pool rebalances (arbitrageurs buy the cheaper ETH from your pool). When you withdraw, you'll have less ETH and more USDC than you started with. Compared to simply holding the original assets, you've experienced a loss.
Key facts about impermanent loss:
- It's called "impermanent" because if prices return to the original ratio, the loss disappears
- It becomes permanent when you withdraw at a different price ratio
- A 2x price change results in roughly a 5.7% loss vs. holding
- A 5x price change results in roughly a 25.5% loss vs. holding
- Trading fees can offset IL if volume is high enough
AMM Models Beyond Constant Product
The DeFi ecosystem has evolved well beyond the basic x ร y = k formula:
Concentrated Liquidity (Uniswap v3/v4)
LPs choose a specific price range to provide liquidity in. This dramatically improves capital efficiency โ you can earn the same fees with far less capital โ but requires active management and increases impermanent loss risk within your range.
StableSwap (Curve Finance)
Curve uses a hybrid formula optimized for assets that should trade near a 1:1 ratio (e.g., USDC/USDT, stETH/ETH). This creates extremely low slippage for stablecoin and pegged-asset swaps, making Curve the go-to DEX for stable pairs.
Weighted Pools (Balancer)
Balancer generalizes the AMM concept to allow pools with unequal token weights (e.g., 80/20 instead of 50/50) and even pools with more than two tokens. This reduces impermanent loss for LPs who are bullish on one asset.
Virtual AMMs (vAMMs)
Used by perpetual DEXs like Drift Protocol, vAMMs use the AMM pricing formula without actual token reserves โ they're purely for price discovery in derivatives trading.
How Prices Stay Accurate: The Role of Arbitrage
AMMs don't connect to external price feeds to set prices. Instead, they rely on arbitrageurs โ traders who profit by correcting price discrepancies between the AMM and the broader market.
If ETH trades at $3,000 globally but an AMM prices it at $2,950, arbitrageurs will buy the cheap ETH from the pool and sell it elsewhere, pushing the AMM price back to $3,000. This process happens constantly and usually within seconds.
Key Metrics to Evaluate an AMM Pool
Before providing liquidity, assess these factors:
- Total Value Locked (TVL): Higher TVL generally means lower price impact and more stable returns
- Volume-to-TVL ratio: Higher ratios mean more fees generated per dollar of liquidity โ look for ratios above 0.1 daily
- Fee tier: Some DEXs offer multiple fee tiers (0.01%, 0.05%, 0.3%, 1%) โ volatile pairs usually warrant higher fees
- Historical impermanent loss: Tools like Revert Finance and DeFiLlama can help you estimate IL
- Smart contract risk: Stick to audited, battle-tested protocols
Security Considerations
AMMs are not without risks beyond impermanent loss:
- Smart contract vulnerabilities: Always check audit reports and protocol track records
- Rug pulls: Avoid pools with unknown tokens that could be malicious
- Oracle manipulation: Some AMM-based protocols can be exploited through flash loan attacks
- MEV (Maximal Extractable Value): Sandwich attacks can front-run your trades, increasing your costs. Use MEV-protected RPCs or private transaction pools when possible
Conclusion: The Foundation of DeFi
AMMs fundamentally transformed how we think about trading and market making. By replacing intermediaries with mathematical formulas and open liquidity pools, they've enabled a permissionless financial system where anyone can trade or earn yield on their assets.
As AMM designs continue to evolve โ with innovations like Uniswap v4 hooks, intent-based trading, and hybrid on-chain/off-chain models โ understanding these core mechanics will be essential for navigating the DeFi landscape in 2025 and beyond.
Whether you're swapping tokens or providing liquidity, knowing what happens beneath the surface helps you make smarter decisions and manage risk effectively.