It's a jungle out there!
Impermanent Loss (IL, hereafter) is a serious risk in the DeFi world when depositing liquidity in pools run by Automated Market Makers. But there are ways to mitigate against it.
Before we get started, you’ll need to be up-to-speed with how a liquidity pool functions when using the constant product formula, often abbreviated as “XYK”. You can check out an informative post here.
What Is Impermanent Loss?
Liquidity pools incentivize people with coins (or liquidity) to deposit their coins so that others can borrow or trade from the pool. When borrowing and trading occurs, there is a transaction fee. Liquidity providers get a percentage of the transaction fee in return for providing assets to the pool. The more liquidity you provide as a percentage of the pool, the more you get in terms of the fee percentage.
However, while making profit on the fee-end of things, providers can suffer a loss of value on their original deposit when withdrawing their assets from the pool. This is when IL can occur.
Here’s a basic definition of IL:
IL occurs when the value of your funds, after withdrawing them from a liquidity pool, is less than the value that would have been if you had not deposited your funds in the pool to begin with.
In other words, you would have been better off just keeping those coins in a wallet. What complicates things is determining how the value at the time of withdrawal is less, because in many cases it often seems like you’re making a profit. And although liquidity providers make their money off the transaction fees when people borrow from the pool, IL can reduce those gains, or even result in a loss.
To get a more in-depth grasp of IL, there are three basic ideas to bear in mind. IL is based on
- a temporal comparison
- a percentage basis
- a “should-have-done” scenario
This last point is what philosophers like to call a “counter-factual”; it’s when we consider “what didn’t happen” in order to get a sense of whether we’re better off now. We’ll take these three points in turn.
Temporal Difference
IL involves a differential factor comparing three temporal events:
- The time of deposit. (We’ll call this T1.)
- The point in time when checking the pool value. (We’ll call this T2.)
- The hypothetical point of reference by which to compare T1 and T2. (We’ll call this TH.)
Correlatively, there must be three respective values:
- V1: The value of your deposit at the time of deposit (T1).
- V2: The value of your deposit when checking the pool value (T2).
- VH: The value of your deposit had you not deposited it in the pool (TH).
To derive VH, we’ll need to use the change in the amount of coins with respect to T1 and T2, which results from providers adding and withdrawing coins from the pool. And this is where things get complicated.
Recalling how liquidity pools are governed by the constant product formula, we know that they work by adjusting the numerical amounts of the paired coins so that their product (K) remains constant: X * Y = K. Correlatively, then, there will be two respective coin amounts:
- N1: The number of coins deposited at the time of deposit (T1).
- N2: The number of coins representative of one’s share of the pool when checking the pool value (T2).
The upshot: The actual change (from T1 to T2) in value (from V1 to V2) and the number of coins (from N1 to N2) will prompt us to ask what would have been the case (counter-factual/hypothetical/TH) if the change in value and amount did in fact occur, yet with me not depositing my coins in the pool and instead just holding them in a wallet (or VH).
IL occurs when, for any coins you deposit, VH is greater than V2.
How does this work?
Playing the Percentage
Knowing when to withdraw your deposit involves bearing in mind that your withdrawal is not based on the number of coins you deposited, nor the total value you deposited. Rather, it is based on the percentage of value your deposit represents for that pool.
That means even though the value of one of the coins has gone up, it does not mean you will earn a profit. It can actually mean you lose money on the investment.
Let’s repackage an example from Binance Academy.
Alice finds a liquidity pool pairing DAI and ETH, whose yield is attractive to her. (Though whether you should be selecting liquidity pools based on yield percentage alone is a different story.)
When depositing to a liquidity pool, one has to provide the two coins in equal value (not numerical) amounts. For the sake of simplicity, let’s say in our example that 1 ETH = 100 DAI. If Alice wants to add liquidity to the pool, she will have to consider equal values of the paired coins. Let’s say:
- Alice wants to add 1 ETH; and so has to add 100 DAI, as well.
Let’s also say:
- The total pool value including Alice’s deposit is 10 ETH and 1000 DAI.
Therefore:
- Alice’s share of the pool is 10% (1 ETH / 10 or 100 DAI / 1000).
So what else do we know about Alice’s deposit? Let’s apply our T, V, and N distinctions when using the constant produce formula.
- At the time of her deposit (T1), V1 is 1 ETH + 100 DAI.
- For the sake of the example, since DAI is pegged to the US dollar, we can say that Alice’s total investment is $200 (or 1 ETH + 100 DAI).
If, due to trading, the price of ETH rises to 400 DAI, at that time (T2) it would appear opportune for Alice to withdraw her deposit?
Assuming Alice has understood the constant product formula, where K is the constant product relating to the entire pool size (or 10 * 1000 = 10,000), she can double-check using the following formula (courtesy of Cointelegraph):
- ETH amnt = square root (K / new ETH price)
- ETH amnt = square root (10,000 / 400)
- ETH amnt = 5
Using the constant product formula, Alice can then calculate the amount of DAI:
- X * 5 = 10,000
- X = 5 / 10,000
- X = 2000 DAI
- 2000 DAI * 5 ETH = 10,000
Alice knows that she gets a 10% share of the pool at T2. To find out if her withdrawal would be lucrative, she needs to know the new amounts of the coins she would receive based on this share (N2).
- 10% of 2000 DAI = 200 DAI
- 10% of 5 ETH = 0.5 ETH
Recall from the start that the value (V1) in US dollars of Alice’s original deposit was $200.
In contrast, at T2 the value of her deposit (V2) is $400 (or 200 DAI and 0.5 ETH, which is worth $400 DAI).
That seems like a $200 profit!
Unfortunately not.
Counter-factual or “Should’ve Done”
The profit upon withdrawal (at T2) isn’t so great. It takes a counter-factual to get an idea as to why. Enter TH.
Given the change in price of ETH to 400 DAI: Had Alice alternatively kept her original deposit and held it (instead of depositing at the pool), her original 1 ETH and 100 DAI would have a value of $500.
Her original 1 ETH would then be valued at 400 DAI or $400.
Her original 100 DAI would be $100.
$400 + $100 = $500
That’s a $300 difference from the value (V2) at T2.
In short, IL is difficult to determine if you’re only looking at the value of the coins in relation to the pool and not the original percentage of the pool size your deposit represents.
Now that we’ve covered the theory, here’s a little cheat . . . an IL calculator (thanks to GabrielXYZ on the AOTB Discord channel for the link!):
https://dailydefi.org/tools/impermanent-loss-calculator/
But All Is Not Permanently Lost
One thing to note, to the benefit of Alice, is that IL is an unrealized loss. It is not actual or realized until Alice actually withdraws her funds. She can wait until arbitrage trading brings things back in her favor; in other words, at some future point in time things might be “even-Steven”.
There ARE ALSO other ways to avoid IL — namely, use liquidity pools that don’t use Automated Market Makers (AMMs).
Exchanges like Hashflow allow non-automated market makers to balance the pool:
“By using a request-for-quote (RFQ) model to allow professional market makers to manage liquidity pools, Hashflow solves these issues. In turn, traders and liquidity providers (LPs) gain access to enhanced efficiency, security, and products previously impossible in DeFi.”
In this sense, Hashflow creates access to liquidity via decentralized pooling, yet offers a backstop against impermanent loss by having reputation-vetted market makers adjust pool supply and pricing.
On the tech front, one of the reasons for using AMMs is to solve the lack of liquidity available. AMMs allow liquidity to be pooled merely by incentivizing people to deposit assets in order to profit from transaction fees.
However AMMs become redundant if an order book method — that matches buyers and sellers according to price — is possible. The problem for DeFi is that most decentralized networks don’t have a high-enough throughput to make the pricing and matching on order books function. But as you can imagine, this barrier is being pushed; and on-chain order books are on the slate.
This article was originally published on Medium and is a part of the Crypto Industry Essentials educational program presented by The Art of the Bubble.
Though this article is credited to me, it contains some written material by Sebastian Purcell, PhD from his The Art of the Bubble education series on cryptocurrencies.
If you found this helpful, Subscribe to The Art of the Bubble’s free newsletter.
Join us on Discord for live chat and daily updates.