Explaining Impermanent Loss

By fred_nurk | pragprog | 5 Dec 2024


Providing liquidity pairs is very attractive but there is a dark cloud that hovers over new investors, impermanent loss, which might seem confusing so I will try to explain here with examples. In short, we can say that Impermanent loss is when the value of the liquidity pair is less then what it would have been if the tokens were simply held outside of the pool. The liquidity pools most effected are the ones that require a proportional amount of both tokens at 50/50. So let's say we have a pool with token A / token B for example's sake. So the value of token B you put in is equivalent to the value of token A you also put in. You will typically receive newly minted LP tokens in exchange for the tokens you put in, which also entitles you to withdraw the tokens you have offer up for liquidity. When a user interacts with this pool on an exchange, the ratio of these tokens will change. This will affect the price of these tokens.

 

Impermanent loss happens when the price of the tokens diverges. So say if both tokens appreciate or depreciate in value, like for example by 20%, there won't be any impermanent loss. Only if one rises and the other decreases will there be impermanent loss, or if one rises and the other stays the same.

 

One thing to keep in mind when talking about impermanent losses, is the fact that every impermanent loss comes in a different shape or size. Sometimes, IL is negligent, others can lead to massive losses. Second, is the fact that Impermanent loss happens regardless of the direction of the price divergence. IL happens when price diverges in any direction.

 

If you want to calculate the amount of impermanent loss that will occur after a certain price change you can use the Impermanent Loss Calculator. But if you're a nerd like me and want to get into the calculation of it, stick around.

 

Let's say we have an RDNT / wETH liquidity pool with a 50/50 token ratio. Say at the time the value of wETH is $2000 and we have 2.5 wETH with a value of $5000. Also let's suppose the value of RDNT is $250 at the moment. So we have 20 RDNT also with a value of $5000 also. We deposite our tokens into a liquidity pool and receive liquidity provider tokens equivalent to the $10,000 joint. We leave this position in there for a while and when we come back to check on it, it turns out that RDNT has doubled in value, now at $500, equivalent to an 100% move. In this time, wETH is at $2300, only a movement of 15%. Please note and remember what I said a while ago about impermanent loss being present regardless of the individual price directions, what only matters is the fact that the prices of the tokens diverged, even if they both went up oddly enough. We now know that we have impermanent loss, we don't know how much yet but we do know that we have faced it.

 

Strictly speaking we still have made gains due to the rewards we have obtained from fees of the users of our liquidity pool. This is one way liquidity pools try to compensate IL, by offering enough incentives to make it worth it. 

 

First we'll calculate the invariant, taking into account the fact that the "weights" W of this pool are going to be 0.5 being the ratio 50 / 50 for this pool. Taking into account these weights we will calculate the invariant with the invariant function, based on the amount of tokens we initially placed into the pool. The invariant is practically just the weighted product of the tokens in the pool, this formula actually work fair beyond paired liquidity pools, it can work with weighted multi token pools, but that is a topic for another day. The invariant function is the following:

 

b803ae8b5029ef27f52c82444edb208b45da3528efeec8cf5e85dcf65713b78c.png

So in this case where we only have two tokens at a 50 /50 ratio we have:

 

018277cf219ec66e2872ac65c4b2da3eacddb21c5a3e97c74527c10c94ee95e3.png

 

Now we calculate the invariante taking into account the price doubling of RDNT and the 15% gain of wETH:

 

7cd957900314977bf44834141b6e031339639d374a26200ec48438a5e7d2257d.png

 

So now, our gains will be based by the ratio of the invariants. Note how the actual tokens and ISD amount get cancelled out and thus the only thing that matters is the actual ratio of the invariants:

 

57c39059e17839aff03bbf19172699426e1331ea014abd43362ffde28df5a3a3.png

 

We will now calculate the ratio of holding these tokens:

 

e88c8b7c6b25ef9fa5bd6ee4ad4b4bee218ab3afed0406c644472eff3ff31d0b.png

 

Now that we have both ratios we can take a look at the formula for impermanent loss:

 

ff1705623a0e74d4f2024d14cb01d4a695ae1e2af561467de212e194eaaa43a4.png

 

In this formula we will plug in our values to get the impermanent loss:

 

a8bd1dcd93ef04f4cb6d11ffa48c560f72936bb2de88c6652472946a8ef8abfc.png

 

So this gives us an impermanent loss of 3.71% approximately. If we look in the calculator I mentioned earlier we get the same result:

 

8aec9d9efb64a34a00320c9cfbab8cea01ba7eb07fc013bd3cfc94631593e3d5.jpg

How do you rate this article?

3


fred_nurk
fred_nurk

I like programming and this whole new blockchain world.


pragprog
pragprog

This is a side project from my main blog (termuxuser01.blogspot.com) mainly dedicated to my exploracion into blockchain technology and the new fronteirs it opens. I like learning and sharing what I find in the digital sea.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.