SETTINGS
Content language
flag Vietnamese
Vietnamese
flag Vietnamese
Vietnamese
Tiếng việt
flag English
English
English
Channel logo
Coin98 Insights
Save
Copy link

Risks in AMM - what they are and how to calculate them

We've been talking about AMM. First the math, the various case studies, the models and the projects. You think we are done? I think not! With decentralised exchanges that use AMM in their system, it does not come risk free.
Avatar
Khang Kỳ
Published Oct 20 2020
Updated Jun 07 2023
4 min read
thumbnail

We've been talking about AMM. First the math, the various case studies, the models and the projects. You think we are done? I think not! With decentralised exchanges that use AMM in their system, it does not come risk free.

The 2 greatest risks are impermanent loss and price slippage. Sure, there are a lot of gains involved like constant liquidity, ease of trade, opportunities for arbitrage traders, etc. But always know the risks available. I'll share about what they are and how to calculate them.

Impermanent loss

You've probably heard about this in every other conversation. What it is really, is the potential loss on paper that exists. It only becomes "real" when you withdraw the tokens from the liquidity pool.

Let's say I own a Tesla stock. And it went from $500 to $400. The loss is $100 on paper. Until I sell that Tesla stock, the loss is not realised yet. Just the value change. The value could go up to $500 again and I have no realised loss. So the concept is similar in impermanent loss.

The Tesla example shows what loss is. A real loss. In impermanent loss, the loss is not fixed yet. Because AMM change to quickly according to price movement and recalculated at the moment. So the loss is not permanent. Yet. So we talked about loss. We talked about the idea of "impermanent". Now let's go back to our crypto liquidity pools.

How does Impermanent Loss work?


Let's use Uniswap as an example because it is easier.

Assume Uniswap has no transaction fees. A pool has 2 tokens, ETH and USDT tokens.

Currently, 1 ETH = 400 USDT. This is calculated for tokens available INSIDE THE POOL only. 

Now, let's say outside the pool, people are trading 1 ETH = 420 USDT. E.g. on Binance.

How can you profit from this?

Arbitrage traders use 400 USDT to buy 1 ETH. Then go to Binance and sell it for 420 USDT. That means 20 USDT for free! Yes, this is legal. And yes, this is done in traditional "real world" finance too.

So where is the loss coming from?

These traders buy and sell ETH until the exchange rate in the liquidity pool is 1 ETH = 420 USDT.

Now you're thinking, ok that is the normal price anyway. How does it affect me? So during this period, this is what happens:

Beginning of state: amount in the pool 100 ETH and 10,000 USDT.

Token → Quantity → Price → Value

ETH → 25 → 400 → 10,000 (in USD)

USDT → 10,000 → 1 → 10,000 (in USD)

Constant product = 25 * 10,000 = 250,000

When price goes up to 1 ETH = 420 USDT, arbitrages come in to trade.

This is the result:

Let's say we own 10% of the pool. So you are entitled to 2.43975 ETH + 1,024.695 USDT.

The value of that in USDT == 2.43975 * 420 + 1,024.695 = 2049.39 USDT

If we kept that 10% in the hardware wallet instead, we still keep out 2.5 ETH + 1,000 USDT.

The value of that in USDT == 2.5 * 420 + 1,000 = 2050 USDT

Value loss = 2050 - 2049.39 = 0.61

How to Calculate Impermanent Loss in Uniswap
 

This is the general formula to calculate the LP loss in Uniswap. Do note that this formula is only relevant to Uniswap and it does not include the trading fees!

What impermanent loss is what happens independent of you trading. It's almost like the opportunity cost of leaving your tokens in the liquidity pool VS keeping them in your wallet. A good measure is to calculate the expected returns via trading fees and minus the risk of impermanent loss.

Another thing to note is that this assume that only one side is changing at one time. E.g. ETH moves, but USDT remains. In reality, when you are trading pairs like ETHCOMP, both tokens are correlated and can move more, but in the same direction!

Price Slippage


That was what happens if you are not trading. Now, what about risks if you ARE trading?

This risk is called price slippage. Price slippage is the difference between the expected price before transaction and actual price when token is transacted. That is why on Uniswap, you have this variable of "minimum received" and price impact.

So where is price slippage coming from?

DEXes are continuously trading. The price for token #1 is different from the price of token #2 because of the autonomous market maker model. The larger the transaction size relative to the liquidity, the higher the slippage.

That means when you want to trade 9,000 tokens and there are 10,000 tokens in the pool (aka 90% of the liquidity), the price slippage will be higher. That means the risk of actual amount received vs expected amount received is larger.

Is there a way to prevent it?

Well, not really. An alternative is to pay higher gas fees so your transactions are prioritised, but that's going to be costly on your side. The transaction fee might be even more than the price slippage.

Another way is to choose liquidity pools where your trade is a small percentage of the pool. So if you want to trade COMP for ETH, you can go to Balancer, Uniswap, Bancor. Choose the pool with the greatest liquidity and trade there instead!  

RELEVANT SERIES