How THORChain’s IL protection works, by example
Let’s say you provide 100 RUNE and 1,000 USDC, at the price of $10 per RUNE.
After a while, RUNE goes to $60. You should now have these amounts of assets in your LP position:
100 / sqrt(6) = 40.82 RUNE
1000 * sqrt(6) = 2,449.49 USDC
Your IL protection is calculated then as follows:
(initialRuneAmount — currentRuneAmount) + (initialUsdcAmount — currentUsdcAmount) * currentPriceOfUsdcInRune
= (100 – 40.82) + (1,000 – 2,449.49) * (1 / 60)
= 35.02 RUNE
If you withdraw at this point, you will get 35.02 RUNE, in addition to your pool assets (40.82 RUNE + 2,449.49 USDC).
Why does this calculation make sense? Let’s consider what if you chose to passively hold the assets instead of LP.
In this case, you would still have 100 RUNE + 1,000 USDC.
With RUNE at $60, this stack would worth
100 + 1,000 * (1 / 60) = 116.67 RUNE
However, due to IL, your LP position now is only worth
40.82 + 2,449.49 * (1 / 60) = 81.64 RUNE
Which is 35.02 RUNE short of the value if you passively held. The IL protection makes up exactly this difference.
Note: This example assumes no transaction fee is accumulated in the pool.
In reality, transaction fees mean you will have a bit more than 40.82 RUNE and a bit more than 2,449.49 USDC in the end.
In this case, you will receive slightly less than 35.02 RUNE as IL protection.
In other words, IL protection makes up the difference that’s not already made up by transaction fees.