Popular Science: An easy way to calculate the changes in your own LP liquidity pool funds
加密乌托邦
2021-01-22 09:23
本文约1964字,阅读全文需要约8分钟
Changes in the amount of your LP funds, most of the time there is no need to calculate the so-called "impermanent loss".

DeFi liquidity mining has been going on for so long, but many people still don't know how to calculate how the amount of funds they inject into the liquidity pool LP changes.

First determine two principles:

First, most of the time the amount of your LP funds changes, there is no need to calculate the so-called "impermanent loss", so don't worry about it.

secondary title

Accounting formula

The general LP pool adopts the same rules as Uniswap, and injects 1:1 equivalent encrypted assets.

The quantities of these two encrypted assets are defined as: a and b

The latest price definition of encrypted asset a is: Pa

K=a*b

The moment of joining the liquidity pool determines K, which is a constant and does not change.

With b as the benchmark, whoever is more valuable or whose volatility is smaller is the benchmark. We uniformly define this as b.

Calculation method:

a*b=K Get K first, this value is constant and does not change

Quantity b= root sign (K*Pa)

Now the total value of your LP is equal to: twice of b

The simple formula is summarized as: amount of funds = 2*square root (K*Pa)

Remarks: For the convenience of expression, USDT and U.S. dollars are used in the following, 1USDT=1 U.S. dollar.

It is also possible to calculate the current quantity of a, but it does not need to be memorized, just remember how to calculate b, because the valuation is based on b.

secondary title

Take ETH-USDT as an example:

Status when injecting LP

ETH-USDT LP Liquidity Mining

The benchmark above is b, and the benchmark b here is USDT.

When liquidity is injected, the price of 1ETH is 1000USDT.

so:

10000USDT,b=10000

so:

When LP is injected, your personal capital amount is 20,000 US dollars

K=a*b=100000

Current state:

The price of ETH has risen to $2,000, how much money is left in the pool?

Formula: b=square root (K*Pa)=square root (100000*2000)=14142

Fund change: 14142*2=28284USDT

So, your LP pool has changed from $20,000 to $28,284.

Has an impermanent loss occurred? produced. Has the amount of money increased? grew. The two are not contradictory.

If I didn't participate in LP mining at the beginning, but just held ETH and USDT, how much is it worth now?

10 ETH doubled, so it is worth 20,000 US dollars;

The 10,000 USDT in hand has not been moved, so the combination of the two is 30,000 US dollars.

The difference between $30,000 and $28,248 is impermanent loss.

However, when participating in liquidity mining, it is often not necessary to calculate the impermanent loss. What I need to calculate is whether my funds at that time are growing now. Taking b as the benchmark, as long as the price of a increases relative to b, my funds (based on b) will increase.

Conversely, with the same conditions, the price of ETH has changed from $1,000 when I joined LP to $600 now. How much will my LP principal lose?

Similarly, the current amount of funds = 2* root sign (K*Pa) = 2* root sign (100000*600) = 15492USDT

It was originally 20,000 US dollars, but now it has become 15,492 US dollars.

If you don't add LP if you don't move, how much should it be?

The 10,000 USDT remains unchanged, and the value of ETH changes from 10,000 US dollars, 10*600=6,000 US dollars.

A total of 16,000 US dollars.

secondary title

Take BTC-ETH as an example:

ETH as the benchmark, which is b

When put in, 1BTC=27ETH.

You put in 1BTC and 27ETH, the value is 1:1.

K=1*27=27

Now the price of ETH has increased (the price of BTC has increased), and now 1BTC=10ETH.

That is Pa=10

How to calculate how much money is worth in the pool now? How to calculate how much BTC and how much ETH are left in the pool?

b= root sign (27*10)=16.43

This is the number of b. That is to say, there are 16.43 ETH in the pool now, and now 1BTC=10ETH, so the number of bitcoins should be 16.43÷10=1.643

Now lying in the pool: 1.643BTC and 16.43ETH

When joining: 1BTC and 27 ETH

The total value now is of course equal to: 16.43*2=32.86ETH

When joining, the total value is equal to: 27*2=54ETH

secondary title

Going one step further:

With BTC as the benchmark, the current amount of funds has changed from 2BTC to 1.643BTC*2=3.286 BTC

So, the amount of funds denominated in Bitcoin has increased, and the amount of funds denominated in ETH has decreased. Has my amount of funds increased or decreased? Find the actual price of ETH or BTC at that time, and you will know it by multiplying it.

This is the pool of the small currency-ETH. When the small currency drops sharply against ETH, the ETH will decrease rapidly, and the reason for leaving a bunch of this small currency in hand is because the quantity b is the quantity of ETH. It rises with the increase of Pa and decreases with the decrease of Pa.

A benchmark should be selected when calculating. Generally, the LP pool is composed of a small currency plus a stable currency (DAI or USDC or USDT, etc.) or ETH or BTC, then these latter more stable currencies (USDT, USDT, etc.) DAI, USDC, BTC, ETH, etc.) as the benchmark is calculated by b. The increase or decrease in the amount of funds is also calculated based on these more stable targets.

The above calculations, if you readers study carefully and repeatedly deduce, you will suddenly see the light.

Remarks: For the convenience of reading, the formulas in this article are expressed with "under the root sign". If you add a formula in the Excel table, you can use "Sqrt" to calculate the root sign.

加密乌托邦
作者文库