Ethereum-Solidity Quiz Q16: What is impermanent loss?
Source: Dev.to
What is impermanent loss?
Impermanent loss is the difference in value you would have if you simply held your tokens versus if you provided them as liquidity in an Automated Market Maker (AMM).
How it happens
When you provide liquidity to an AMM, you deposit two tokens of equal value. The AMM automatically adjusts prices based on supply and demand using the constant‑product formula
[ x \times y = k ]
If the price of one token changes significantly, the pool rebalances, leaving you with a different token ratio than when you started. That ratio shift can result in a loss compared to just holding the assets.
Why “impermanent”?
- If the price returns to the original ratio, the loss disappears.
- You only realize the loss when you withdraw while prices are imbalanced.
- Trading fees earned by the pool can offset or even exceed the impermanent loss.
Example: ETH‑USDC pool
Initial deposit
| Token | Amount | USD value |
|---|---|---|
| ETH | 1 | $2,000 |
| USDC | 2,000 | $2,000 |
| Total | — | $4,000 |
The constant‑product is
[ k = 1 \times 2{,}000 = 2{,}000 ]
Price change: ETH rises to $4,000
Using the constant‑product formula (x \times y = k) with the new price ratio (y/x = 4{,}000):
x × y = 2,000
y = 4,000x
x × 4,000x = 2,000
4,000x² = 2,000
x² = 0.5
x = √0.5 ≈ 0.707 ETH
y = 4,000 × 0.707 ≈ 2,828 USDC
New LP position
- ETH: 0.707 ETH (lost 0.293 ETH)
- USDC: 2,828 USDC (gained 828 USDC)
Value:
[ (0.707 \text{ ETH} \times $4{,}000) + (2{,}828 \text{ USDC} \times $1) = $2{,}828 + $2{,}828 = $5{,}656 ]
Comparison
| Scenario | ETH (value) | USDC (value) | Total value |
|---|---|---|---|
| Just holding | 1 ETH = $4,000 | 2,000 USDC = $2,000 | $6,000 |
| Providing liquidity | 0.707 ETH = $2,828 | 2,828 USDC = $2,828 | $5,656 |
Impermanent loss calculation
[ \text{Impermanent loss} = $6{,}000 - $5{,}656 = $344 \approx 5.7% ]
What actually happens
- Lost: 0.293 ETH (sold as the price rose)
- Gained: 828 USDC (bought as the price rose)
The AMM rebalanced the position to maintain the constant product, effectively selling ETH at lower prices than the market peak. Trading fees earned by the pool can mitigate this loss.