A full breakdown of Impermanent Loss

Fikunmi Ajayi-Peters
8 min readFeb 27, 2024

An explanation and an ELI5 derivation.

For anyone who has ever LPd, you’ve heard the term Impermanent Loss.

There’s a good chance you’ve even tried to study it, but the math aint mathing.

Fear not, I’ll break down Impermanent Loss and, more importantly, do a full derivation of the equation. I won’t use fancy math, just algebra and surds.

By the time you finish this, you’ll not only understand Impermanent Loss, you’ll know how to calculate it in any situation.

Let’s dive right in.

Photo by Behnam Norouzi on Unsplash

Impermanent Loss: the bane of LPing

Impermanent Loss (IL) is the loss you incur (relative to holding) when the price of your tokens in a liquidity pool diverge from the price when you originally put them in the pool.

In reality, IL isn’t much of a loss.

A more appropriate way to think of it is as an opportunity cost.

When you deposit tokens into a liquidity pool and people swap through your pool, the token distribution will change.

Say a token A/token B pool.

If more people buy token A, you’ll have more token B in your pool, and vice versa.

Turns out this divergence (no matter which one goes up) will always cause you some loss.

Let’s go through the math.

The Math of Impermanent Loss

Most, (don’t get me started on complex pools) LPs are governed by the constant product algorithm.

which means,

This algorithm controls the prices and distribution of tokens X and Y in pools.

Let’s see how the pools work in practice.

Let’s say you create a SOL/USDC pool. SOL is our base token, and USDC is the quote token.

Say 1 SOL is worth 100 USDC at the time and you want to add 10 SOL to the pool.

You’re expected to add 1000 USDC tokens too, because if you don’t, your pool quotes will be different from market prices.

If you’re wondering why your pool just doesn’t quote current market prices from CoinGecko or something, it’s because obtaining those prices adds complexity and trust assumptions.

By having the pool set its own prices, it aligns better with blockchain ethos and arbitrage traders will ensure that all pool prices are in sync with market prices.

Back to our example:

In our example pool, USDC is the quote token, so we’re valuing everything in USDC (not USD). Remember, the pool has no outside information. I’m using the USDC token because it’s stable and that makes the concept easier to grok.

Ok, let’s say the value of SOL is 100 USDC per SOL.

Let’s call that P.

P was calculated by dividing the amount of quote tokens (USDC) by base tokens (SOL)

Now our constant product K for this example is

I kept the units in because it makes the next step more intuitive.

Since we already know 1 SOL is equivalent to 100 USDC, we can plug that into K, and we find that K is also 1,000,000 USDC²

Again, the units just help with understanding.

USDC² is an abstract metric so let’s find the square root of K.

If you notice, this is the exact same value as the initial amount of USDC tokens we put in. It’s also the initial value (in USDC) of the base token.

You’ll sometimes hear this called the liquidity L of the pool.

Mathematically,

With this relation, we can rewrite our constant product equation in terms of liquidity since it’s less abstract.

Ok, where are we?

We’ve established that the constant product formula dictates that the amount of token X (x) multiplied by the amount of token Y (y) is always equal to the square of pool liquidity (L2).

Ok, now we’ll derive x and y in terms of L and P since these are real quantities.

So, starting with equations:

First rewrite equation 1 in terms of x

Next, we take the square root of both sides of equation 2.

Putting equation 3 in 4.2, we get:

That leaves us with:

Now we know how the amounts of token x and y are related to the initial liquidity in the pool (L) and the price of token x with respect to y (P).

Continuing with our example pool,

Let’s say the price of our base token (SOL) goes up to 200 USDC.

The question now is: what is the distribution of tokens in the new pool since the pool value must always be equal to 10,000 SOL.USDC?

Well, we can find x from our previous derivation and that works out to:

So the amount of SOL (x) in the pool is 7.071.

The amount of USDC (y) can be found directly from x, in this case, it’s 1414.21.

If you’re wondering why we used K instead of L, it’s because using L gives us a result in a non-standard unit:

The math is pretty solid but feel free to test it for yourself.

With all that out of the way, we can finally look at Impermanent Loss (IL).

Impermanent Loss (IL)

If you decided to close the liquidity pool now (after SOL has doubled in USDC value), you’d have 7.071 SOL and 1414.21 USDC.

The total value of this pool in USDC is now 1414.21 USDC + 1414.21 USDC (notice it’s the same value), which is a grand total of 2,828.42 USDC.

If you never created this pool, you’d have 10 SOL and 1000 USDC, which totals to 3000 USDC at current market prices.

So by virtue of price diverging from the original prices, you’ve missed out on some gains compared to just holding.

This divergence “loss” is what is called impermanent loss.

If the price of SOL drops back to what it was when you deposited into the pool, the impermanent loss is reversed. That’s why it’s called impermanent.

Keep in mind, impermanent loss will occur no matter which direction prices diverge.

Now that you understand impermanent loss, let’s derive a general formula for it.

General Formula for Impermanent Loss

We start by writing an expression for impermanent loss:

We can derive the value if held and value if LPd from our previous calculations:

We can say the new and old prices of x are related by the equation:

Where r is any positive number depending on the new price.

That means the new price is always some positive multiple of the old price.

If the new price is half the old price, r = 0.5; if it’s double, r = 2, and so on.

This step just makes the equations cleaner by relating the new variable to one that already exists.

We can now write equations 7 and 8 in familiar terms, starting with 7.

Since everything is priced in token Y, the price of y is always 1, so equation 7 becomes:

Equation 8 can be rewritten in a similar manner:

xₙ and yₙ are the new amounts of tokens X and Y calculated with the new price of X.

Ok, we can now write a general formula for Impermanent Loss from equation 6.

This works out to:

That’s the formula for impermanent loss but you’ll find it more helpful if it’s calculated with respect to holding the tokens.

To calculate this we simply divide equation 11 by equation 9.

This works out to:

And that is the general formula for impermanent loss.

As you can see, it only depends on the divergence ratio:

We can now plot the relationship between r and IL.

Impermanent Loss in an AMM

In english:

  • a 0.5x divergence results in 5.7% loss relative to HODL
  • a 0.6x divergence results in 3.2% loss relative to HODL
  • a 1.25x divergence results in a 0.6% loss relative to HODL
  • a 1.50x divergence results in a 2.0% loss relative to HODL
  • a 1.75x divergence results in a 3.8% loss relative to HODL
  • a 2x divergence results in a 5.7% loss relative to HODL
  • a 3x divergence results in a 13.4% loss relative to HODL
  • a 4x divergence results in a 20.0% loss relative to HODL
  • a 5x divergence results in a 25.5% loss relative to HODL

And that’s Impermanent Loss.

I believe you now have a solid grasp on the concept.

If you’re confused, feel free to go over it on paper. I tried to keep as many steps in as possible so it shouldn’t be too hard.

Overall, be careful out there.

That’s all!

References

  1. https://pintail.medium.com/uniswap-a-good-deal-for-liquidity-providers-104c0b6816f2
  2. https://medium.com/auditless/how-to-calculate-impermanent-loss-full-derivation-803e8b2497b7

--

--

Fikunmi Ajayi-Peters

Hi, I'm Fikunmi I write a lot about crypto and coding, sometimes about my other hobbies. I hope you enjoy reading my pieces as much as I do writing.