Single-Position Impermanent Loss of A Single Transaction for Uniswap V3

Leo Lau

Leo Lau
11 min readOct 4, 2021

In this article, the equations of the impermanent loss of a single transaction with and without fee for Uniswap V2 and V3 are presented. The price ranges where the impermanent loss is positive are discussed. If we assume ρ = 0.3%, then the maximum possible yield of a single transaction will be ~1330 times larger than Uniswap V2, in Uniswap V3. To achieve such yield, we simply need to set Pa and Pb as closer to each other as possible. The theoretical maximum can be expressed as ρ/2(1−ρ). The impermanent loss equations for range order (single-sided liquidity) are also presented. The theoretical maximum yield for range order is twice as much as the maximum when Pa < P < Pb, achieved by setting Pa and Pb as close as possible. You “can” get more yield doing range order (providing single-sided liquidity). The only caveat is the price has to actually enter your range. Otherwise, your tokens just sit there. If the price enters your range and ends below your price range or above your price range, just like how you originally set up the range order, then yield is guaranteed to be positive!

In my last medium post¹, I derived the impermanent loss equation for Uniswap V2, considering fee.

When there is no fee, the impermanent loss equation becomes:

When we add in fee, the impermanent loss can be positive, over range:

The maximum yield can be achieved when dIL/dk = 0, which leads to:

When ρ = 0.3%, the maximum yield of a single transaction will be 1.13⋅10⁻⁶ at k = 0.997 and 1.003.

Uniswap V3

A couple of months ago, Peteris Erins² derived an impermanent loss equation for Uniswap V3. However, Guillaume Lambert³ recently pointed out that equation was incomplete. Basically Erins did not consider the situation where the price goes out of the price range and the liquidity provider does not withdraw liquidity and rebalance.

Here I provide the complete equation, considering fee:

When ρ = 0, meaning no fee, the equation reduces to:

Lambert simplified this further by setting Pb/P = P/Pa = r, then the equation reduces further to:

When r approaches infinity, the impermanent loss equation reduces to the IL equation of Uniswap V2. I think the equation Lambert derived has some error in it. For example, when I set k to 0 and infinity in his equation, IL does not go to -1 (he has corrected his equation).

Below is a plot of the IL equation:

The plot should look similar with fee, if we use ρ = 0.3%. However, just like Uniswap V2, there will be a positive IL part. Surprisingly, if Pa/P ≤ (1−ρ)² and P/Pb ≤ (1−ρ)², then the positive IL price range will be the same as Uniswap V2: (1−ρ)² ≤ k ≤ 1/(1−ρ)². The complete price range can be expressed:

If we still use the formulation Lambert used, the price range can be reduced to:

The original IL equation can also be reduced to:

The difference between V2 and V3 is that part of the impermanent loss is boosted by a factor which blows up when r gets closer to 1. However, this is not a math error because the impermanent loss of Uniswap V2 also gets to zero. In fact, the narrower we set the price range, meaning Pa and Pb get closer (r gets closer to 1), the maximum yield gets bigger.

Due to this fact, the maximum yield does not happen at the same k location as Uniswap V2. In fact, setting k = klow only gets a yield of 0.0377%. The maximum yield can be calculated, using L’Hôpital’s rule:

The theoretical maximum yield of one transaction is:

We can further confirm this by setting k = 1 and r = 1 in the first and last sub-equation and get the same result. Setting ρ = 0.3% gives us a maximum yield of 0.1504%, which is ~1330 times the maximum yield of Uniswap V2!

In reality, you can only narrow the price range to a certain point. There are only certain price ticks you can choose as your lower bound and upper bound of the price range. In fact, the minimum r we can get is ~1.00005, which is equal to the square root of 1.0001 (the minimum ratio between Pb and Pa).

A zoom-in plot of the IL function is below:

The maximum yield of one transaction in reality is ~0.1492% which is close enough to the theoretical maximum.

However, concentrating liquidity as narrower as possible can cost more chances of collecting transaction fees, because once price crosses your range, your will not earn any fee. Therefore we may need to keep a balance between this strategy and the “lazy strategy”.

The “lazy strategy”, instead of narrowing the price range, just picks the boundary of the price range to be where the impermanent loss goes to zero: Pa/P = P/Pb = (1−ρ)². This will lower the maximum possible yield of one transaction to ~0.0377%, which is only 25% of the other strategy.

Not surprisingly, the maximum occurs at the same k location as Uniswap V2 because the impermanent loss is the same, by a factor, between (1−ρ)² and 1/(1−ρ)².

We also need to consider rebalancing when price goes out of range. How frequent we should rebalance to maximize our time in the positive gain region, considering gas fee, is an interesting problem for another day. I suggest you reading “Uniswap’s Financial Alchemy⁴” by Dave White et al., “A Guide for Choosing Optimal Uniswap V3 LP Positions, Part 1⁵ & Part 2⁶” by Guillaume Lambert, and “Uniswap V3: Liquidity Providing 101⁷” by Mellow Protocol.

Finally, I raised a question in my last medium article: “As of now, we do not know what the purpose is for restricting the token type for range order.” I think I understand why now.

Range order is basically single-sided liquidity provision. Of course, the type of token is restricted because the other type of token is “sold out”. The equivalent liquidity provided can be calculated easily:

if the price range is completely above the current price (only token x can be deposited).

if the price range is completely below the current price (only token y can be deposited).

In fact, there are 2 more impermanent loss equations we need to consider because of this single-sided liquidity feature.

  1. PPa

In this case, one parameter r is not enough anymore. Thus, we introduce two parameters r1 and r2, where P/Pa = r1, Pb/P = r2. Then the equation reduces to:

If we assume no fee, then the equation can be further reduced to:

r1 ≤ 1, r2 > 1, and r1r2 > 1.

If we pick r1 = 1, then the impermanent loss function will look like this:

If we pick r1 = 0.5, then the function will look like this:

Key takeaways are: 1. the smaller r1 is, the wider the range where IL = 0; 2. the bigger r2 is, the slower impermanent loss decreases.

If we assume ρ = 0.3%, then the maximum will be at: k = r2 (if r1r2 < 4/(2−ρ)²), or k = 4/(2−ρr1 (if r1r2 ≥ 4/(2−ρ)²).

The theoretical maximum yield of a single transaction will be:

The theoretical maximum yield is twice as much as the yield when Pa < P < Pb as discussed above. In reality, the minimum r1r2 can take is 1.0001. Therefore the maximum yield for range order (single-sided liquidity) is ~0.2959%. In this case, just pick a price range as narrow as possible and you will get the maximum yield. If time is a consideration, then simply choose P = Pa. Below are how the IL function looks like under those conditions:

Next we discuss the price range where IL ≥ 0.

The widest price range where IL ≥0 happens when r1 approaches 0. However, we need to wait a very long time if Pa is significantly larger than P. If you want to maximize the chance the price enters your range, set r1 = 1. The maximum range you can get in this case:

r2 does not affect this range as long as r1r2 ≥ 1/(1−ρ)².

The plot of the IL function under this condition looks like this:

Choosing a smaller r2 gives us a better maximum as shown above. Therefore, the best “lazy strategy” is r1 = 1, r2 = 1/(1−ρ)². This gives us ~25% of the maximum yield of the other strategy where r1 = 1, r2 = 1.0001, but wider range where IL ≥ 0.

2. PPb

Similarly, the equation reduces to:

If we assume no fee, then the equation can be further reduced to:

r2 ≤ 1, r1 > 1, and r1r2 > 1.

If we pick r2 = 1, then the impermanent loss function will look like this:

If we pick r2 = 0.5, then the function will look like this:

Key takeaways are: 1. the smaller r2 is, the wider the range where IL = 0; 2. the bigger r1 is, the slower impermanent loss decreases.

If we assume ρ = 0.3%, then the maximum will be at: k = 1 / r1 (if r1r2 < 4/(2−ρ)²), or k = (2−ρr2/4 (if r1r2 ≥ 4/(2−ρ)²).

The theoretical maximum yield of a single transaction will be:

The theoretical maximum yield is also twice as much as the yield when Pa < P < Pb as discussed above. In reality, the minimum r1r2 can take is 1.0001. Therefore the maximum yield for range order (single-sided liquidity) is ~0.2959%. In this case, just pick a price range as narrow as possible and you will get the maximum yield. If time is a consideration, then simply choose P = Pb. Below are how the IL function looks like under those conditions:

Next we discuss the price range where IL ≥ 0.

The widest price range where IL ≥0 happens when r2 approaches 1. The maximum range you can get in this case:

r1 does not affect this range as long as r1r2 ≥ 1/(1−ρ)².

The plot of the IL function under this condition looks like this:

Choosing a smaller r1 gives us a better maximum as shown above. Therefore, the best “lazy strategy” is r2 = 1, r1 = 1/(1−ρ)². This gives us ~25% of the maximum yield of the other strategy where r2 = 1, r1 = 1.0001, but wider range where IL ≥ 0.

To summarize, range order will give us twice of the maximum yield of a single transaction when Pa < P < Pb. The “lazy strategy” in the range order case is: r1 = 1, r2 = 1/(1−ρ)² or r1 = 1/(1−ρ)², r2 = 1. If you just want the maximum possible yield, then choose the smallest r1r2 possible.

We have only considered how impermanent loss changes for a single position, meaning the liquidity provider’s liquidity is either in PPa, or PPb, or Pa < P < Pb. In reality, the liquidity provider can split his liquidity into multiple positions. Besides, the impermanent loss equations in this article are based on only a single transaction. I plan to investigate how the impermanent loss of multiple positions behaves over a period of time in the future!

Too many papers to read! I wish there were more than 24 hours a day…

--

--