Many articles have been written about Impermanent Loss and how to calculate it for AMM pools in Uniswap V2, and more generally for the majority of the liquidity pools we can find in Balancer, Sushiswap and so on.
With the new version of Uniswap and the concept of concentrated liquidity, things are a bit different. Let’s try to derive the formulae for the Impermanent loss in this case.
Impermanent Loss for Standard AMM Pools
To better understand how to calculate Impermanent Loss (we’ll use the IL notation) in Uniswap V3, let’s first remember what it is for standard liquidity pools.
Such pools follow two basic rules:
- They are composed of two assets (ETH-DAI, BTC-USDT…)
- The valuation of the two assets represents 50% of the pool
They are based on a really basic equation:
where:
- x is the quantity of asset A in the pool
- y is the quantity of asset B in the pool
- k is a constant
And when a trader uses the pool to swap token A for token B, the number of tokens in the pool fluctuates but the product of the two quantities has to remain the same and equal to the constant k.
Also, the ratio y/x defines the price of the token A in terms of token B. Let’s note it:
From (1) and (2), we can then write x and y with p and k. It will be useful later:
Now, a liquidity provider can decide to stake some tokens A and B for this pool. If he decides to do so, he has to follow the 50/50 rule and provide the same value of tokens A and B. For instance, if the pool is ETH-DAI and ETH trades for 2500 DAI, he has to provide 2500 times more DAI than ETH in the pool. It can be 0.1 ETH and 250 DAI, 0.5 ETH and 1250 DAI…
By providing liquidity, the user is exposed to IL. Impermanent Loss is the difference between simply holding the two assets A and B in his wallet and staking them in the pool:
Let’s assume that the liquidity provider created the pool with xₒ quantity of asset A and yₒ quantity of asset B. Then the value of his assets at the time of creation (and at any time t if he holds them outside of the pool) is:
If the same quantities of assets are staked in the pool, they fluctuate and at time t their value becomes:
Combining these results in the IL formula gives:
with r being the ratio between the current price and the initial price.
We obtain the well-known curve for IL:
Impermanent Loss for Uniswap V3 pools
The V3 of Uniswap introduces a new concept of concentrated liquidity. It means that the liquidity provider no longer deposits its liquidity for the entire price range of the assets, but only for a specific interval. The resulting V3 liquidity pool can be seen as a set of liquidity pools that are only valid for the range in which they are defined.
This concept of concentrated liquidity is detailed in the Uniswap V3 whitepaper in the section 2 CONCENTRATED LIQUIDITY. It is advised to read it to better understand the rest of this article.
Now let’s consider that the liquidity provider wants to create a new V3 pool and adds liquidity on the range [pa, pb] and the current price of asset A in terms of asset B is pᵢₙᵢₜ. We admit that pᵢₙᵢₜ is in the range [pa, pb].
In a V2 pool, if the liquidity provider deposits xₒ assets of A and yₒ assets of B and the price of asset A falls and equals pa, then the repartition of assets in the pool becomes:
Similarly, if the price goes up and equals pb:
Then the quantities of the two assets vary in the following range when the price of asset A fluctuates in [pa, pb] and:
In the case of a V3 pool, these above quantities are called virtual ones because we don’t need so many quantities if the price stays in the range defined. The real needed quantity of each asset is in fact lower and at any time t where the price is p and stays in the range:
Now that we have defined all the notations, we can derive the Impermanent Loss in V3. The definition of IL remains the same and:
Let’s try to simplify this equation so that only the different prices appear in the formula (pa, pb, pᵢₙᵢₜ and current price p):
To further simplify and be able to plot the graph of this function, we can “normalize” it by making the assumption that pᵢₙᵢₜ=1:
And IL can also be derived when the price is out of the range (I omit the details of the calculation):
We can now draw this IL curve, and compare it to the V2 one:
Finally, we can verify the coherence of the formula by extending the range to extreme values:
What’s interesting to see is that the smaller the range is, the bigger the IL is compared to V2:
More to come…
You can donate for more technical articles on DeFi:
ETH: 0x6e83F971E6e33D76353344735aB156C851E03Ee7