Liquidity Pools: How DEXs Work
What is a Liquidity Pool?
A liquidity pool is a collection of cryptocurrency tokens locked in a smart contract on a blockchain. These pools serve as the foundation for decentralized exchanges (DEXs) like Uniswap, SushiSwap, and Curve. Unlike traditional exchanges that rely on order books—where buyers and sellers place bids and offers—a liquidity pool uses an algorithmic approach to facilitate trades automatically and continuously.
When you swap one token for another on a DEX, you're not trading directly with another person. Instead, you're trading against the liquidity pool itself. The pool holds reserves of both tokens in the pair, and the trade is executed instantly at a price determined by the pool's algorithm. This is why DEXs can offer immediate execution without waiting for a counterparty.
How Automated Market Makers (AMMs) Work
Automated Market Makers are the mathematical formulas that determine how prices change in a liquidity pool. The most common model is the Constant Product Market Maker, which uses the formula:
The Constant Product Formula
x × y = k
Where:
x = amount of Token A in the pool
y = amount of Token B in the pool
k = constant product (always remains the same)
This formula ensures that the product of the two token quantities always equals the same constant. When you buy Token A from the pool, you add Token B and remove Token A, which increases the price of Token A relative to Token B. The larger the trade relative to the pool size, the more the price moves—this is known as price impact or slippage.
Simplified Example
Imagine a ETH/USDC pool with 100 ETH and 200,000 USDC (k = 20,000,000). If you want to buy 10 ETH:
- You add USDC to the pool
- The pool now has 110 ETH
- To maintain k = 20,000,000, the USDC side must be: 20,000,000 ÷ 110 = 181,818 USDC
- You pay 200,000 - 181,818 = 18,182 USDC for 10 ETH
- Your effective price: $1,818.2 per ETH (vs. $2,000 mid-price)
Providing Liquidity: Earning Fees
When you provide liquidity to a pool, you deposit both tokens in the pair according to the pool's required ratio. In return, you receive LP (Liquidity Provider) tokens that represent your share of the pool. Every time someone trades through the pool, a fee (typically 0.3% on Uniswap v2) is charged and distributed proportionally to all liquidity providers.
LP tokens accrue value over time as fees accumulate. You can redeem your LP tokens at any time to withdraw your share of the pool plus any earned fees. This makes providing liquidity a way to earn passive income on your crypto holdings, though it comes with significant risks that we'll cover next.
Impermanent Loss: The Hidden Risk
Impermanent loss (IL) is the reduction in value that liquidity providers experience compared to simply holding their tokens. It occurs because the AMM constantly rebalances the pool as prices change.
Impermanent Loss Calculation Example
Scenario: You deposit 1 ETH + 2,000 USDC into a pool (ETH at $2,000)
After price change: ETH rises to $4,000 (2x)
If you simply held: 1 ETH ($4,000) + 2,000 USDC = $6,000
In the pool: 0.707 ETH ($2,828) + 2,828 USDC = $5,656
Impermanent Loss: $6,000 - $5,656 = $344 (5.7% loss)
The math behind IL shows that a 2x price change results in approximately 5.7% loss, a 3x change results in about 13.4% loss, and a 5x change results in roughly 25.5% loss. However, fees earned from trading can offset this loss depending on pool volume.
Concentrated Liquidity: Uniswap v3
Uniswap v3 introduced concentrated liquidity, allowing providers to allocate their capital within specific price ranges rather than across the entire price curve. This innovation dramatically increases capital efficiency—providers can earn significantly more fees with less capital—but also amplifies both returns and risks.
When you concentrate liquidity in a narrow range, you earn more fees per dollar deposited because your capital is active across a smaller portion of the price range. However, if the price moves outside your range, your position becomes 100% one token and you earn zero fees until the price returns to your range.
Single-Sided Liquidity
Some protocols offer single-sided liquidity provision, where you can deposit just one token instead of the required pair. These protocols automatically rebalance your position, selling half your deposit for the other token in the pair. While more convenient, single-sided positions often come with higher fees or less favorable execution.
Risks of Providing Liquidity
Beyond impermanent loss, liquidity providers face several additional risks:
- Smart Contract Risk: Bugs or exploits in the pool's code could lead to loss of funds
- Rug Pull Risk: Malicious developers could drain the pool's liquidity
- Token Risk: If one token in the pair goes to zero, you're left holding only the worthless token
- Gas Fees: Ethereum gas fees can eat into profits, especially for smaller positions
- Regulatory Risk: Changing regulations could affect liquidity provision legality or tax treatment
Before providing liquidity, always research the protocol's audit status, the pool's trading volume relative to its TVL, and the historical price correlation between the tokens in the pair. Higher volume relative to TVL generally means more fee income to offset potential impermanent loss.