Impermanent Loss in Crypto: How to Calculate & Avoid It
- Writer Eric Huffman
- andEditor Gary Anglebrandt
- January 19, 2023
- •4 Min Read
The Milk Road Promise
We’re committed to helping you get smart about crypto. Some articles feature products from partners who compensate us, but opinions are always our own.
- Impermanent loss is a “paper loss” unless you close your position.
- Earned swap fees and liquidity mining tokens can help offset an impermanent loss.
- The number (and ratio) of tokens you hold in a liquidity pool changes as swaps occur, sometimes leading to impermanent loss.
What is Impermanent Loss?
Impermanent loss is the difference between what your value would have been if you had held your crypto assets and the value of assets you put into a liquidity pool instead. If the value would have been higher if you just held your crypto in your wallet rather than providing liquidity, then you have an impermanent loss.
This makes an impermanent loss similar to an opportunity cost.
If a stock you own is down 10% compared to your average cost, it looks like a loss. But the stock price might go back up. It’s not really a loss unless you sell and lock in the loss. Impermanent loss is similar in that regard: It’s not a loss until you remove liquidity.
Where impermanent loss differs from an unrealized loss in stock investing is that the calculation doesn’t compare your starting value to the current value of your liquidity pool investment. Instead, it compares the value you would have had if you had just held your tokens against the value of your liquidity pool investment based on the mix of tokens remaining.
Because of the way impermanent loss is calculated, it’s possible to have an impermanent loss while also having an unrealized gain.
How Does Impermanent Loss Happen?
Most liquidity pools use a similar algorithm to keep the overall value of the pool balanced. A program called an automated market maker (AMM) adjusts the price of the tokens in the pool in response to supply and demand.
The number of tokens in the pool also changes as swaps occur, and this is the real issue that can lead to impermanent loss.
Let’s say you deposit the following assets into a new liquidity pool in which you’re the only investor:
- 10 ETH, with a starting value of $1,000 each
- $10,000 worth of a dollar-equivalent stablecoin, like DAI (10,000 tokens)
If someone uses 500 DAI to buy ETH from your pool, the supply of DAI increases by 5%. This will drive down the price of DAI in the liquidity pool and drive up the price of ETH, which decreases in quantity.
The concept is called price impact: Each purchase drives the price of the purchased token higher.
The AMM algorithm then uses the new quantities to set new prices for the tokens. The formula is based on 10,000 x 10 (100,000), the starting quantities for each token in the pool in this example.
Most liquidity pools use a constant product formula, which multiplies the starting quantity of each token in a pair, i.e., 1,000 * 1,000 = 1 million. The constant product (1 million) is then used as the basis for future price adjustments as the token balance shifts in the pool due to swaps.
You now have 10,500 (10,000 + 500) DAI in the pool and 9.5238 ETH leftover in the pool, with 0.04762 ETH going to the buyer.
Here’s the math to arrive at that figure:
- 100,000 (constant product) / 10,500 (DAI supply) = 9.5238 (remaining ETH supply)
- 10 (starting ETH supply) - 9.5238 (ending ETH supply) = 0.04762 (amount of ETH the buyer gets)
And here’s the new pool supply:
- DAI: 10,500 * $1 = $10,5000
- ETH: 9.5238* $1,000 = $9,523.80
Let’s say ETH goes to $1,250.
Here’s what your original deposit would be worth if you held:
- $10,000 (DAI) + $12,500 (ETH) = $22,500
But here’s what you have left in the pool:
- $10,500 (DAI) + $11,904.75 (ETH) = $22,404.75
The number of ETH tokens dropped to 9.5238 after the swap, giving you an exchange value of $11,904.75 (9.5238 * $1,250). The exchange value of your DAI went up by $500, but it wasn’t enough to avoid an impermanent loss.
After the swap, you have an impermanent loss of $95.25
$22,404.75 (value after swaps) - $22,500 (value if held) = -$95.25 (impermanent loss)
When Does it Happen?
Impermanent loss can happen due to a number of factors.
- Volatile tokens: Impermanent loss happens more frequently when one of the tokens in a trading pair is more volatile than the other. A DAI/USDC pair is unlikely to see impermanent loss, but a DAI/ETH could invite impermanent loss risk.
- New or thinly traded tokens: New or thinly traded tokens may not have proper price discovery or a large enough market to tempt arbitrage traders.
- Wide trading range: Impermanent loss can also occur if you allow a wider trading range. Some decentralized exchanges, like Uniswap, let you fine-tune the trading range for tokens. No trades will occur outside your defined trading range.
- Small pools: Token prices get pushed around more easily in small liquidity pools.
Where Does Impermanent Loss Happen?
You may also see impermanent loss called divergence loss or divergent loss. All these terms describe the situation. The loss is impermanent until you close the position, but the loss is caused in part by price divergence compared to the outside market.
Centralized exchanges use an order book, matching buy orders with sell orders. Decentralized exchanges use liquidity pools instead, and formulas used to balance pools lie at the heart of impermanent loss risk.
Typical liquidity pools, like Uniswap, try to maintain a 50/50 value in the pool by adjusting the price of tokens as the swaps occur. These price adjustments can bring the risk of impermanent loss.
Over time, the quantity of each token you hold in the pool may go up or down. This also plays a role in calculating impermanent loss. In our earlier example for a small pool, we showed how the supply of DAI increased by 50% while the supply of ETH decreased by 33% in a single swap.
Liquidity pool aggregators like 1inch and ParaSwap search for the best exchange rate across multiple DEXs. Coinbase wallet offers a similar feature. These tools help users find the best rates but also help to bring pool prices in line with the outside market by increasing demand for undervalued tokens in pools.
Automated Market Maker AlgorithmsExpand to learn more
The formulas used by automated market makers (programs that set prices in liquidity pools) can lead to impermanent loss. Understanding how this formula works can be helpful in knowing how supply and demand affect pool prices.
The most common algorithm used is called the constant product formula, which multiplies the quantity of each token in the pair by the other token’s quantity. This result is called a constant product, and the algorithm uses this number to calculate token prices.
Constant Product Formula: x * y = k
- X is the quantity of the first token in a pair.
- Y is the quantity of the second token.
- K is the (constant) product.
Here’s a simple example using MATIC and ETH. Grab a calculator or spreadsheet if you want to follow along.
- MATIC exchange value: $0.85
- ETH exchange value: $1327.80
- 2,343.2 MATIC ($1,991.72 exchange value)
- 1.5 ETH ($1,991.70 exchange value)
The constant product is 3,514.80 (2,343.2 * 1.5). This number remains constant, even as swaps occur.
Let’s say someone swaps 100 MATIC to buy ETH. The supply of MATIC in the pool increased (and ETH decreased).
Divide 3514.80 by 2443.2 (the new MATIC supply) to get the amount of ETH remaining in the pool.
3514.80 / 2443.2 = 1.4386 ETH remaining
The ETH buyer gets the difference between the starting quantity of ETH and the calculated amount remaining in the pool.
1.5 (starting ETH) - 1.4386 (ETH remaining) = 0.0614 ETH (the amount that goes to the buyer)
The pool supply is now:
- 2443.2 MATIC ($2,076.72 exchange value)
- 1.4386 ETH ($1,910.17 exchange value)
Now, let’s say ETH goes up to $1,500, while MATIC remains the same at $0.85.
Here’s the value of the original deposit:
- 2343.2 MATIC ($1,991.72 exchange value)
- 1.5 ETH ($2,250 exchange value)
- Total value: $4,241.72
And here’s the value of the remaining tokens after the swap.
- 2443.2 MATIC ($2,076.72 exchange value)
- 1.4386 ETH ($2,157.90 exchange value)
- Total value: $4,234.62
This example results in an impermanent loss of $7.10 (4,234.62 - 4,241.72) after the swap based on the exchange prices for MATIC and ETH.
If we repeated the same swap (another 100 MATIC for ETH), the next swap would give the buyer 0.048 ETH compared to 0.07 ETH on the first swap. Increased demand for ETH in the pool decreases the exchange rate with MATIC.
ETH is getting spendy in this example pool, but there’s likely an arbitrage play in which a trader can swap ETH to the pool to pick up MATIC they can sell elsewhere for a profit. The arbitrage trade would bring pool prices closer to the outside market by reducing the supply of MATIC (raising the price) and increasing the supply of ETH (reducing the ETH price).
This example shows how the AMM works on Uniswap. Some protocols, like Balancer and Bancor, use different algorithms to balance pools.
The Role of Liquidity Providers
When you deposit tokens into a liquidity pool, you’re a liquidity provider. You’ll earn a fee for swaps that occur in the pool. Some DeFi protocols, like Curve, also provide liquidity pool tokens to liquidity providers.
Traders drive the prices in a pool. Uneven demand causes one token to rise in value and the other to fall in value. But these price divergences create an opportunity for arbitrage. Keen traders can scoop up undervalued tokens and sell them on outside exchanges. The increased demand for these underpriced tokens in the pool helps bring the pool price closer to exchange prices. Advanced traders often use bots to search for DEX arbitrage opportunities.
Impermanent Loss Examples
Here’s a real-world example to calculate impermanent loss using a small liquidity pool investment on Uniswap.
Grab a calculator or spreadsheet if you want to follow along, but here’s a walkthrough.
The initial deposit was $119.52 and the current pool value is $126.04, so there’s a gain on Uniswap. But those numbers don’t matter when calculating the impermanent loss.
Instead, you want to compare the values based on the number of tokens you deposited to the number of tokens remaining if sold on exchanges.
The pool value for your position displayed by platforms like Uniswap can be different from the exchange prices for tokens you hold in the pool. When working with larger pool positions, the difference can be meaningful.
The position also earned six cents in swap fees. Earned fees partially offset an impermanent loss, if you have one.
|Initial deposit (tokens)||74.23||0.04728|
|Ending balance (tokens)||73.44||0.04778|
|Initial deposit exchange value||$63.10||$62.77|
|Ending balance exchange value||$62.42||$63.44|
To calculate the impermanent loss, subtract the initial deposit exchange value (the amount you would have if you just held your tokens) from the ending balance exchange value (the amount remaining).
In the table above, the total value of the deposit would have been $125.87 (63.10+62.77) and the ending balance after swaps would have been $125.86 (62.42+63.44).
This example is a loss of $0.01, but it’s a small trade.
$125.86 (ending value) - $125.87 (starting value) = -$0.01 (loss)
One factor that can lead to impermanent loss is that the mix of tokens changes as swaps occur.
Here’s another example from Uniswap, which requires a 50/50 deposit. You can see the percentage mix changed to 46/54 as swaps occurred.
The initial liquidity pool deposit was:
- 15.05 MATIC ($12.94 with MATIC at $0.86 on exchanges)
- 12.08 USDC ($12.08 with USDC at $1 on exchanges)
The total value for the initial deposit would be $25.02 (12.94+12.08) total at current exchange prices.
Compared to the current mix:
- 13.45 MATIC ($11.57 with MATIC at $0.86 on exchanges)
- 13.41 USDC ($13.41 with USDC at $1 on exchanges)
Here’s what’s left from the initial deposit of 15.05 MATIC and 12.08 USDC.
The total value for the remaining pool tokens is $24.98 (11.57+13.41) at current exchange prices.
The pool also earned $0.03 in fees thus far.
Without the fees, the liquidity pool has an impermanent loss of $0.04.
On a larger position the impermanent loss can become more meaningful. Impermanent losses can also be much larger than this real-world example.
The liquidity value ($24.96) displayed by Uniswap doesn’t factor into the impermanent loss calculation. The figure is based on pool prices and may not reflect prices in the outside world.
Instead, the quantity of tokens you can withdraw (and what they’re worth on exchanges) is what matters.
How to Calculate the Impermanent Loss?Expand to learn more
To calculate impermanent loss, you need a few figures.
- Starting token balance: Take notes or screenshots when you deposit to a liquidity pool.
- Ending token balance: You can preview the withdrawal on most DEXs (without withdrawing).
- Exchange prices for the tokens in the pool: Check an exchange for current prices.
Here are the steps:
Step 1: Multiply your starting token quantities by the current exchange prices.
(Token A quantity * Token A exchange price) + (Token B quantity * Token B exchange price)
Step 2: Multiply your ending token quantities by the current exchange prices.
(Token A quantity * Token A exchange price) + (Token B quantity * Token B exchange price)
The token quantities have likely changed since you started. On Uniswap, you can preview the token quantity by clicking on “remove liquidity” and then moving the slider to 100%.
Step 3: Subtract the result from Step 1 from the result from Step 2.
Subtract the total value you would have had from the value you have now.
Step 4: Add your earnings, including fees and liquidity mining tokens (if applicable).
Many online calculators don’t include fees or mining tokens in the calculation, but fees are a primary incentive to invest in liquidity pools. Fees and liquidity mining tokens awarded by some platforms, such as Curve, help offset any impermanent loss.
That’s it. If the final number is negative, you have an impermanent loss and would have done better by holding your tokens in a wallet. If positive, you’re earning more than holding your tokens in a wallet.
The previous section illustrates impermanent loss in action.
How to Avoid Impermanent LossExpand to learn more
There are several ways to reduce the risk of impermanent loss.
- Low volatility tokens: Providing liquidity for stablecoin pairs is the easiest way to avoid impermanent loss. You can also consider equivalent tokens, like ETH and WETH, which won’t differ in price volatility. Expect a smaller fee in exchange for added safety.
- Join larger pools: A large pool can handle big swaps without much price impact.
- Set a trading range: Uniswap lets you set a trading range for your position. Tighter trading ranges bring more safety, but positions may require more maintenance as prices move.
- Change the liquidity ratio: Protocols like Balancer let you choose a ratio other than 50/50 for deposited tokens. Setting a more volatile token as a lower percentage of your position reduces the risk of impermanent loss.
- Use a single-sided pool (with insurance): Bancor offers single-sided positions for liquidity pools, matching the deposit with Bancor’s BNT tokens (which are burned when you pull your liquidity). Bancor takes 15% of your earned fees in exchange for a guarantee that you have at least the same number of tokens when you pull your liquidity.
- Just wait: If you’re providing liquidity for high-demand tokens on a high-traffic platform, your impermanent loss may be temporary. Arbitrage players may trade the price divergence, bringing the pool’s token prices closer to exchange prices.
What is Impermanent Loss Protection?Expand to learn more
Impermanent loss protection is a type of insurance you can use to be sure you exit a position with at least the same number of tokens with which you started. Bancor is the best-known option. The platform takes 15% of the trading fees earned by liquidity providers to fund an insurance pool that keeps liquidity providers whole.
To Sum it Up
Impermanent loss is an oft-overlooked risk in funding liquidity pools. But the risk isn’t as significant as it seems in many cases, and there are several ways to reduce your risk, ranging from low-volatility pairs to single-sided liquidity pools.
The best way to approach liquidity pools may be to start with a small investment and add to your positions as you learn from the data. The math works the same whether you invest $100 or $100,000, but the former is safer.
Frequently Asked Questions
Can you recover from impermanent loss?Expand to learn more
Yes, sometimes. In-demand tokens attract arbitrage traders who can help bring token prices in a liquidity pool in line with exchange prices for the tokens.
Is impermanent loss actually a loss?Expand to learn more
It’s possible to have a gain while also having an impermanent loss. The math behind impermanent loss considers what you would have made if you just held your tokens compared to the value if you exited your position.
What is an impermanent loss in yield farming?Expand to learn more
Impermanent loss refers to investments in which you would have earned more by holding the crypto assets rather than deploying the assets in a liquidity pool. Yield farming can include several income strategies, ranging from lending to staking, with providing liquidity among the most common strategies.
Is there an impermanent loss calculator?Expand to learn more
Whiteboard Crypto offers a handy calculator you can find here.
Is there an impermanent loss formula?Expand to learn more
To calculate impermanent loss you can follow these steps.
- Step 1: Multiply your starting token quantities by the current exchange prices.
- Step 2: Multiply your ending token quantities by the current exchange prices.
- Step 3: Subtract the result from Step 1 from the result from Step 2.
A negative result is an impermanent loss.
What is an impermanent loss in staking?Expand to learn more
While impermanent loss is usually associated with liquidity pools, a similar loss can occur in staking if your stake is slashed due to improper validator behavior. In this case, you may have been in a better position by not staking.
What is impermanent loss for stablecoins?Expand to learn more
Impermanent loss isn’t a risk when providing liquidity for a stablecoin pair. But if pairing a stablecoin with a volatile asset, the quantity of each token in the pair changes as swaps occur, potentially causing impermanent loss.
What are the tax implications of impermanent loss?Expand to learn more
It’s best to discuss the tax implications or liquidity pool positions with a trusted tax advisor. Some crypto tax firms treat a liquidity pool deposit as a sale, which may create a capital gains liability. However, this take is not directly related to impermanent loss and instead comes from the transfer of assets.
Eric Huffman is a staff writer for MilkRoad.com. In addition to crypto and blockchain topics, Eric also writes extensively on insurance and personal finance matters that affect everyday households.
Gary Anglebrandt is a US-based editor, copywriter, and communications consultant with a background in business and international news. Beyond the US, he has worked from Seoul and Beijing, and continues to work with professionals based around the globe.
Get smarter about crypto
Join 250,000+ subscribers and get our 5 min daily newsletter on what matters in crypto.