Liquid swap impermanent loss
A liquid swap is a decentralised solution to single party asset trading. A liquidity pool is a group of (usually) two assets provided by investors of both assets. A user wishing to swap one token for the other can do so without anyone taking the other side of the trade at a liquidity pool. The price they are offered is governed by a formula:
asset_a_liquidity_pool * asset_b_liquidity_pool = constant
The pool offers users the price such that the product of the two liquidity pools is the same after the trade.
asset_a_price_in_asset_b = asset_b_liquidity_pool / asset_a_liquidity_pool
Arbitrage trading is likely if the price isn't fair and thus the pool will quickly be brough inline with other markets
Investors can add liquidity by providing both of these assets to the pool at this ratio. They are given pool shares in return. Those who use the pool to swap tokens pay a fee which is retained in the pool. Since no new pool shares are created in this process the value of each share increases a little bit from thse fees. These fees are the incentive to investors to provide liquidity.
combining the formulas above we can get the pool size at a given price:
asset_a_liquidity_pool = sqrt(constant / asset_a_price_in_asset_b)
asset_b_liquidity_pool = sqrt(constant * asset_a_price_in_asset_b)
Lets neglect fees. When an investor goes to retrieve their assets they do not receive them at the same ratio in which they invested them at. Instead they receive these assets in the ratio the pool currently has. Unless the ratio is exactly the same as when they invested this will incur a loss compared with simply holding both these assets at this ratio. This loss is known as the impermanent loss because it is only realised when an investor withdraws. If the investor waits for the ratio to improve the loss reduces, Thus the loss is not permenant.
The chart below shows how much this loss is. If the ratio is has changed by 2 times then the loss is 5.7%, 4 times 20.0% and 5 times 25.5%
Quick example
We invest 1 ETH and $100 into the pool. At the time ETH was worth $100 so we are adding equal value of each. We come to withdraw it a while later ETH is now worth $200. We receive 0.707 ETH and $141. This is worth $282 vs $300 just holding. Similarly if ETh is now worth $50. We receive 1.41 ETH and $70.7. This is worth $141 vs $150 just holding, both a 5.7% loss. The loss is the same here because the ratio is the same just reversed.
Side note
There are also liquidity pools for stable coins, those which should be worth a similar amount as each other. These pools usually use a different formula which allows the value of each pool to not be constant. This allows for more trading before the price is moved significantly