Uniswap V3 liquidity provision mathematical research

创宇区块链安全实验室 view 4786 2021-12-9 10:10
share to
Scan QR code with WeChat

instructions

Uniswap, a representative of exchanges in the DeFi field, launched the V3 version of the contract in May of this year. Compared to the previous V2 version, the V3 version has more differences: centralized liquidity, higher tier costs and a new oracle.

What mathematical conundrum is behind these different products, and at the same time can provide better benefits to users and reduce fall permanently?

Chuangyu Blockchain Security Lab takes you to analyze the average revenue of Uniswap V3 based on mathematical models.

What is concentrated liquidity?

In Uniswap V3, providers can "deposit" at any cost the resources they have to listen to their investment.

To illustrate this point, we first linked to the Uniswap V2 automotive market brand curve. In this curve, the user's movement is regularly spaced (0, positive infinity).

深入分析 Uniswap V3 流动性供应的数学原理

Figure 1

In version V2, value changes in many pools such as UDST / DAI pools are not common. Since their value is pegged to the US dollar, emerging markets will be close to point A in the figure above (for example, x≈y). This means that most of the treasures in the pool will not be touched.

Thus, in V3, users can concentrate their capacities on specific lines. Point B to C in the figure below.

深入分析 Uniswap V3 流动性供应的数学原理

Figure 2

Because the liquidity of several users is thus concentrated, the liquidity of the line segment from point B to point C becomes very "thick". Such a pool considerably reduces slippage in the market.

How to focus on liquidity

In actual use, the V3 relies heavily on legacy performance. Suppose some of your assets are virtualized to replace the axes and the virtual assets are x and y.

In the first Uniswap V2, the curve model was: x * y = k

Uniswap V3 modified the model by introducing the x and y tools. Here x is called the hypothetical reserve of asset x and y is called the hypothetical reserve of asset y, so the following diagram is shown:

深入分析 Uniswap V3 流动性供应的数学原理

Due to the addition of the capital layer of the assets (virtual assets), the curve in the figure below will change to the curve above with the larger one. It also means that a small group of special objects in a constrained value [xb, xc]. x, y can be used to be greater than xx, yy.

At the same time, the top is the virtual AMM curve after adding the virtual assets. In the actual trading curve (placed on the BC points), the actual curve of the asset layer is as follows.

Thus, an asset in a strong position at point B or C will disappear at zero. That is, they all turn into weak assets and market stops.

As shown in Figure 3:

深入分析 Uniswap V3 流动性供应的数学原理

Figure 3 AMM curve with virtual transition at the top

Based on an automatic shaping curve operation equivalent to V2. If we define L as k = L ^ 2, we have the formula: x * y = k = L ^ 2

Open base character. in other words,

深入分析 Uniswap V3 流动性供应的数学原理

For the value, the current value P (used y for the property value x) is

深入分析 Uniswap V3 流动性供应的数学原理

Use the square root according to formula 3.

深入分析 Uniswap V3 流动性供应的数学原理

For combinations 4 and 2, y can be eliminated at one of the closing times [B, C].

深入分析 Uniswap V3 流动性供应的数学原理

You can also delete there.

深入分析 Uniswap V3 流动性供应的数学原理

So, as long as you know P (the value of x), you can get the assets x and y when the body doesn't change (L doesn't change).

Virtual financial accounting (x / y)

深入分析 Uniswap V3 流动性供应的数学原理

Figure 4 Virtual assets x and y

Considering the heavy situation, in the figure above, after the translation, the upper image of the AMM is at point B and the user material x has been completed.

That is, x = 0, the remainder of x is completely virtual, that is, X.

Calculated according to formula 5. In this case, the value of asset x counts up to point B is

深入分析 Uniswap V3 流动性供应的数学原理

Calculate point C in the same way. During this time, the assets provided by the user are processed in real, i.e. y = 0, and the remaining y is virtual y. then

深入分析 Uniswap V3 流动性供应的数学原理

In the above, xb and yc are the number of Uniswap tokens virtualize the user, for example x and y, also the number of Uniswap tokens open to the user.

We therefore obtained an AMM curve on the complete Uniswap V3 based on operation 9.

深入分析 Uniswap V3 流动性供应的数学原理

At the same time, for each point in the selected period, the actual assets provided by the user appear as shown in the figure below.

Note: The figure below is taken from a blank sheet of Uniswap V3 [1], the spacing is [b, a] and the random point is selected as c.

深入分析 Uniswap V3 流动性供应的数学原理

Figure 5 User provides AMM curve between real and virtual assets

Hidden risk - Permanent loss

V3 focuses on the use of revenue, adding leverage based on user choice and significantly competing with users for service providers. This leads to an increase in the continuing decline.

Based on the above analysis, as long as the price hits the starting point, the liquid token provider trades unlike the negative tokens and no exchange rate appears. Try until the value reappears at the beginning.

There is no free lunch in this world. The higher the risk, the higher the return. The more concentrated the liquidity you provide, the higher your commission income will be and the more permanent losses you will incur. ——Founder of Uniswap, Hayden Adams [2]

Uniswap V3 - Liquidity added

Specifically, we have an existing Uniswap V3 trading pool, we have an ETH / DAI trading partner, the ratio of X and Y in the pool is 10: 800, L2 is 8000 and P is 80, which means that the operating cost is 80 STI /. ETH.

The current value corresponds to point A (10,800). If you are a financial services provider, start a business of P = [20,320]. Context B (5 1600), P = 320. Point C (20 400), P = 20

深入分析 Uniswap V3 流动性供应的数学原理

The financial service provider needs to invest 3 ETH which everyone will use for xreal based on the current option price.

According to the white paper, the model is:

深入分析 Uniswap V3 流动性供应的数学原理

According to equation 10, the input △ x = 3, the ETH input replaces L of the lake. After calculation, △ L is

深入分析 Uniswap V3 流动性供应的数学原理

Then calculate Δy as ΔL.

深入分析 Uniswap V3 流动性供应的数学原理

Therefore, if Chinese decorated should be 240, 3th (Δx). The new l limit on until 143.11 (p = [20, 320] in delay).

Uniswap V3 - Swap

For Uniswap V3, when ETH suddenly rises and the price reaches 1ETH = 100DAI, arbitrage traders use DAI to arbitrate ETH on DEX. To equalize with external, P = 80 ==> P = 100, according to the white paper, Swap calculates the exchange rates as follows:

深入分析 Uniswap V3 流动性供应的数学原理

By taking the starting value P and the final value P after the base sign, one can calculate △ y≈151.09, ≈ x≈1.689.

Suppose the Swap assets are distributed by the provider at 37.5% according to the ratio L, then the provider distributes the funds x≈0.6334, y≈56.66.

We therefore get the following message:

深入分析 Uniswap V3 流动性供应的数学原理

Calculated as a percentage. IL_V3 = (540-533.31) / 540 1.239%

Concentrated liquidity amplifies the asset ratio L, improving the efficiency of the asset when consumed in constant loss. Of course, this is only the case where the urban area is smaller and the distribution is larger, and in fact more people will split the exchange based on the L-invested ratio. And since the exchange itself is large, accounting for 21.113% of total assets, the percentage of permanent losses seems huge, which also takes into account losses from the blind market. The exchange rate is also affected, IL_V3 only estimating 0.58% when P = 85.

Uniswap V2 - Liquidity added

For Uniswap V2, suppose the cost of assets in the first pool is 10 ETH and 800 DAI, that is, P is 80 DAI / ETH.

The financial service provider has invested 3ETH and 240DAI and currently owns 13ETH and 1040DAI, the price is still 80DAI / ETH, or 23.077%, with a new K of 13,520.

Uniswap V2 - Redeem

When ETH suddenly rises and the price reaches 1ETH = 100DAI, arbitrage traders use DAI to trade ETH for arbitrage.

Assuming that after trading D y DAI for △ x ETH, the value of ETH: DAI in the AMM pool increases to 1: 100 with the external balance.

Regardless of processing fees etc., include:

深入分析 Uniswap V3 流动性供应的数学原理

The drug is dx≈1.3724, dy≈122.76. In other words, the judge gave 122.76 DAI and traded 1.3724 ETH. Pool - 1.3724 ETH, 122.76 DAI

深入分析 Uniswap V3 流动性供应的数学原理

This is spread across all percentages, so the service providers will give 23.077%, which means a loss of 0.3167 ETH trade at 28.33 DAI.

深入分析 Uniswap V3 流动性供应的数学原理

IL_V2 = (540-536.66) / 540 0.6185%

The specifics depend on the urban area of ​​the V3, the smaller the leverage, the larger the x and y, the greater the permanent drop and commission income.

Of course, users can also diffuse water all over the curve instead of using special lines like V2. That is, you can trade from zero to infinite good.

深入分析 Uniswap V3 流动性供应的数学原理

P.s.

For spatial reasons, this sentence only speaks of concentrated liquidity. Uniswap V3 has revolutionized many new features and significantly increased the complexity compared to V2.

Unconventional changes in Uniswap V3 have improved Uniswap V2, and users can choose to focus on their capabilities across multiple platforms to achieve higher operating costs.

But at the same time, it leads to constant declines and rapid trading of assets, creating a lot of new features like restricted trading and other features.

Therefore, before choosing to become an LP, you should carefully consider your personal needs and do not trade blindly.

statements

[1] Application gratuite Uniswap V3

[2] Review of new functions in Uniswap V3

btcfans公众号

Scan QR code with WeChat

Link
Disclaimer:

Previous: There are more and more speculators! Australian Minister of Finance: Creation of a plan for cryptocurrency exchanges Next: The US cryptocurrency giant is expected to attend the hearing tomorrow, what will this "controversy" look like?

Related