This article is derived from UniSwaps Road to Decentralized Exchange from V1 to V3 being written by Fourteen as a reference. It is also found that the derivation formulas of market articles are quite complicated, and the important logical transformations lack descriptions, and are impermanent. Loss is an important part of AMM in Dex, so it is written separately.
If readers are interested in impermanence loss and its corresponding impact, they can also jump directly to the end of the article to read the vernacular version.
This paper derives the classic constant product formula based on AMM
A brief introduction to the AMM mechanism can be read:One article explains clearly - the AMM mechanism of SudoSwap, a rookie in the NFT market - innovation challenges and limitations
In some formulas, the dotted line formula editor is incorrectly operated, which has no practical significance
secondary title
Part 1: Calculate the initial holding value
Assuming that I hold several e 0(ETH) and several t 0(Token), the initial value of the two is equal, such as 1 e 0 = 10 t 0 , if the price of the token is expressed by the formula (in ETH standard), then p 0 is :
Then the total value I hold (in ETH) is equal to quantity*price:
secondary title
Part 2: Inject liquidity into UniSwap
We can inject both ETH and tokens into liquidity in a certain proportion. It is convenient to calculate here that it is assumed that the injection accounts for 50% of the total value. The liquidity pool will give us Lp certificates, such as 10 LpTokens are used to prove that we occupy Shares of dividend-paying equity for the current total liquidity. Due to the constant product formula, only the injection and withdrawal of LP will change the K value (the fee income is not included in this article)
finally
finally
Such a comprehensive calculation of the liquidity value VU we can extract is
Here the minuend of VU that will form part of the subsequent impermanent loss is derived, so the two formulas of the appeal with e 1 and without e 1 are derived specifically for VU
Part 3: Derivation of impermanent loss formula
According to Part 1, we obtained the value VH of holding the current token,
According to Part 2, we got the total value VU of investing in Uniswap as LP instead of holding,
Obviously: Divergence loss (impermanent loss or divergence loss) should be VD
Since the value should rise or fall according to its ratio to the original value, we divide both sides of the equation by VH
Here are the detailed formulas of VH and VU in the conclusions of Part 1 and 2 above
So the impermanent loss rate VD/VH is:
This is the most critical step. The impermanent loss occurs in two time periods with a price difference, so let’s bring in the price change rate R, which is equal to the price of the two times divided
Combining the formulas in Part 1
So R is also equal to
Combined with the impermanent loss rate VD/VH we multiply both core parts by e 0 to form the final formula with only R
In this way, the impermanent loss rate represented by only R can be simplified
Since the final impermanence loss rate value is related to the R value, it also means that as long as R changes, no matter whether it increases or decreases, impermanence loss will occur, and it is an equivalent value when measured in multiples
Part 4 Graphical Impermanence Loss Formula
We can use drawing tools to present the result of this formula. Although the following figure seems to be an asymmetrical curve, it is actually symmetrical because it is a relative magnification, that is, for the original value of 1 ETH = 100 Dai and In other words, falling to 1 ETH = 50 Dai means a double drop, equal to rising to 1 ETH = 200 Dai, a double increase, and the impermanent loss is the same at 5.72%
How to understand impermanent loss?
What does impermanence mean?
First of all, his name is inappropriate. The word impermanent loss was chosen before because if the price deviation is reversed, the loss caused by the price deviation will also be reversed. Later, more articles will use (divergence loss) to describe him.
When does impermanence loss occur?
This loss disappears if the price returns to the same value as when the liquidity provider added liquidity. This loss is only realized when liquidity providers withdraw their liquidity and is based on the price difference between deposits and withdrawals
Will the impermanent loss be more than cause LP to make ends meet?
The actual return of the liquidity provider is actually the balance between the deviation loss caused by the price difference and the accumulated fees of the exchange transaction.
As shown in the figure above, since the account became an LP, compared with only holding original funds, the account has been in a net negative position (yellow line). This is due to the ETH price movement during this period (green Line) resulting in a huge deviation loss (blue line). However, the total cost has been steadily accumulating throughout (red line). Most of the losses were reversed as the ETH price approached the price at which liquidity was provided.
Where does the impermanent loss come from?
Provide liquidity to the market as LP, that is, become a market maker,In fact, it is against users in the market. However, AMM (Automated Market Maker) passively competes with users in the market, that is, when most people in the market are optimistic about the follow-up market of ETH, they will use DAI to buy ETH, and your liquidity pool will passively increase DAI reduces ETH.
so,Providing liquidity means always doing reverse operations with the market, always tend to hold more weak assets (when ETH rises to become a strong asset, DAI is a weak asset). So when ETH rises, your liquidity will continue to throw out ETH in advance, and get more DAI. These ETH thrown out in advance become the source of impermanent loss, that is, impermanent loss at this time can be understood as your ETH The loss in the air, or the value in the pool was taken away by external arbitrageurs.
Relevant information
https://uniswap.org/whitepaper.pdf
https://pintail.medium.com/understanding-uniswap-returns-cc 593 f 3499 ef
https://pintail.medium.com/uniswap-a-good-deal-for-liquidity-providers-104 c 0 b 6816 f 2
https://hackmd.io/@HaydenAdams/HJ 9 jLsfTz
https://github.com/Dapp-Learning-DAO/Dapp-Learning/blob/main/basic/13-decentralized-exchange/uniswap-v1-like/README.md
Like and follow 14, bring you value from a technical perspective
Like and follow 14, bring you value from a technical perspective