Theory

How Liquidity Pools Work - AMM Mathematics and the Nature of Impermanent Loss

Reading time: about 3 min

DEX (decentralized exchange) liquidity pools determine prices through a fundamentally different mechanism than traditional order books. This article explains the Constant Product Formula mathematics, the Impermanent Loss formula for liquidity providers, and the design philosophy of concentrated liquidity.

This article takes about 7 minutes to read

Conclusion - Liquidity Provision Is a Trade-off Between Fee Income and IL

In AMM (Automated Market Maker) DEXs, liquidity providers (LPs) deposit token pairs into a pool, and traders transact directly with the pool. LPs earn trading fees in exchange for bearing Impermanent Loss (IL) during price movements. IL disappears if the price returns to its original level, but becomes a realized loss if the price continues moving in one direction. The profit or loss from liquidity provision equals fee income minus IL, and profit only occurs when fees exceed IL.

The Mathematics of the Constant Product Formula

The basic AMM represented by Uniswap v2 maintains the invariant x * y = k, where x is the quantity of token A, y is the quantity of token B, and k is a constant. When a trader inputs dx of token A, the pool pays out dy = y - k/(x + dx) of token B to maintain x * y = k. The effective price derived from this formula is dy/dx, and larger trade sizes result in greater slippage (price impact). For example, in an ETH/USDC pool with 100 ETH and 200,000 USDC (k = 20,000,000), selling 1 ETH yields approximately 1,980 USDC (about 1% slippage versus the theoretical price of 2,000 USDC).

Calculating Impermanent Loss

IL is the difference between the value of assets in the pool and the value of simply holding them. When the price ratio changes by a factor of r, IL = 2 * sqrt(r) / (1 + r) - 1. As a concrete example, if you deposit 1 ETH (USD 2,000) + 2,000 USDC = USD 4,000 into an ETH/USDC pool and ETH doubles to USD 4,000, the pool assets are worth approximately USD 5,657, but simply holding would yield USD 6,000. The difference of approximately USD 343 (5.7%) is the IL. If ETH increases 5x, IL reaches approximately 25.5%. Conversely, if ETH halves, IL is also approximately 5.7%, the same ratio as when it rises (symmetry). IL disappears if the price returns to its original level, but is realized as a loss if it does not.

Uniswap v3 Concentrated Liquidity

Uniswap v3 (released May 2021) introduced concentrated liquidity, allowing LPs to specify the price range in which they provide liquidity. In v2, liquidity was distributed uniformly from zero to infinity, but in v3, LPs can concentrate liquidity within a specific range, for example ETH/USDC between USD 1,800 and USD 2,200. This achieves up to 4,000x capital efficiency with the same capital (per the Uniswap v3 whitepaper). However, if the price moves outside the specified range, the liquidity becomes inactive with zero fee income, and IL is also larger than in v2. Concentrated liquidity is only advantageous when the prediction that the price will stay within range is correct, and risk increases during high-volatility periods.

Break-even Between Fee Income and IL

The real return for LPs equals cumulative fee income minus IL. For Uniswap v3's major pools (ETH/USDC 0.3% tier), the annual fee APR ranged from approximately 10-30% in 2023, while considering ETH's annual volatility (approximately 60-80%), IL often amounts to 5-15%. There are periods when fees exceed IL and periods when sharp price movements cause IL to far exceed fees. According to Dune Analytics on-chain data, approximately 50% of Uniswap v3 LPs underperform simple holding when IL is factored in.

Practical Considerations and Disclaimer

Practical considerations when evaluating liquidity provision include: (1) pair selection (stablecoin pairs have minimal IL but also low fee rates), (2) fee tier selection (0.01%, 0.05%, 0.3%, 1% - four tiers), (3) concentrated liquidity range setting (narrower ranges mean higher capital efficiency but more frequent rebalancing), (4) gas costs (each position adjustment incurs gas fees, making small amounts unprofitable), and (5) smart contract risk (loss of funds due to protocol bugs or hacks). This article is intended to explain the technical mechanisms of AMMs and does not recommend liquidity provision. Use of DeFi protocols is at your own risk.

Related Terms

Related Articles