How AMMs Work: A Technical Deep Dive
The mechanics of automated market makers — constant product formulas, concentrated liquidity, fee structures, and the implications for builders.
Automated Market Makers replaced order books with mathematical formulas. Instead of matching buyers and sellers, AMMs let anyone trade against a pool of tokens at a price determined by an equation. Understanding the mechanics is essential for anyone building in DeFi.
The Constant Product Formula
Uniswap v2 popularized the x × y = k formula. A pool holds two tokens (x and y). The product of their quantities must always equal a constant (k). When you buy token X, you add Y to the pool — the formula recalculates and you receive the resulting amount of X. The more you buy relative to pool size, the worse your price gets (slippage).
This elegantly solves the cold start problem: the pool always has liquidity, prices self-adjust to reflect demand, and anyone can trade without a counterparty.
Why Spot AMM Prices Are Dangerous
The price at any instant in an AMM can be manipulated — a flash loan can temporarily skew it dramatically. This is why protocols must never use AMM spot prices for price-sensitive operations like collateralization ratios or liquidation triggers. Use TWAPs (time-weighted average prices) instead, which smooth out short-term manipulation.
Concentrated Liquidity (Uniswap v3)
In v2, liquidity is distributed across all possible prices from zero to infinity. Most of that capital is wasted — stablecoin pairs, for instance, trade in a tiny range around $1. Uniswap v3 lets LPs concentrate their liquidity in a specific price range, dramatically increasing capital efficiency. A stablecoin LP can concentrate around $0.99–$1.01 and earn fees only on that range rather than the entire price curve.
The tradeoff: if the price moves out of your range, you stop earning fees and your position becomes 100% one token (effectively sold or fully unsold). This makes v3 LP positions significantly more complex to manage than v2.
Fee Tiers and Their Impact
Uniswap v3 introduced multiple fee tiers (0.01%, 0.05%, 0.3%, 1%). Lower fees make sense for stable-stable pairs where traders are price-sensitive; higher fees make sense for volatile long-tail assets where LPs take more risk. Choosing the wrong fee tier when deploying a pool can starve it of liquidity or make it uncompetitive.
AMM Variants and Their Use Cases
Curve Finance uses a hybrid formula that's more efficient for similar-valued assets (stablecoin-stablecoin, ETH-wstETH). It's extremely capital-efficient near the peg but less flexible for uncorrelated assets. Balancer supports weighted pools (e.g., 80/20 ETH/USDC) and multi-token pools, enabling crypto index funds as liquidity pools.
Uniswap v4 Hooks
Uniswap v4 introduced hooks — callback points that let developers add custom logic to pool operations (before/after swap, before/after liquidity provision). This enables building custom AMM behavior (TWAP orders, dynamic fees, KYC-gated pools) on top of Uniswap's battle-tested core without forking it. A significant architectural shift for DeFi builders.
What AMMs Mean for Your Protocol
If your protocol needs token liquidity for launch, you'll likely seed a Uniswap or Curve pool. Understanding the AMM mechanics lets you design smarter: what fee tier to choose, how much initial liquidity to provide, whether to use protocol-owned liquidity or LM incentives, and how to protect against price manipulation on your oracle.
Frequently Asked Questions
Related Guides
Ready to build your Web3 project?
Tell us about your project and get a precise quote.
Get a Project Quote