Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Loading

Demonstrate and explain the working principle of the new market-making model TWAMM designed by the founder of Uniswap and Paradigm’s research team from a mathematical point of view.

Written by: luffy

Recently, Paradigm research partners Dave White, Dan Robinson, and Uniswap founder Hayden Adams collaborated to design a new market- making model “Time-Weighted Average Market Maker” (The Time-Weighted Average Market Maker). According to its published article, TWAMM can effectively trade large orders on Ethereum . The working principle is to decompose long-term large orders into an infinite number of infinitely small virtual orders, and use the embedded AMM to smoothly execute these within a certain period of time. trade.

Regarding the mathematics involved in the virtual exchange of TWAMM , Dave White did not spend too much time in the article, and only gave a very simple mathematical conclusion at the end, which is very unfavorable for understanding the mathematical principles of TWAMM . This article will focus on the rigorous demonstration and explanation of the mathematical principles of TWAMM . As for the detailed design principles of the TWAMM model, you can go to the Paradiagm official website to view it . This article will not go into details.

definition

Assuming that TWAMM requires N blocks to execute large virtual transactions, the pool that sells X is sold at the rate of x rate per block, and the pool that sells Y is sold at the rate of y rate per block. Therefore, the total amount of X sold during the entire period is x in = Nx rate , and the total amount of Y sold is y in = Ny rate .

At the same time, we embed the initial reserve x reserve and y reserve of this time period into AMM as x 0 =x ammStart and y 0 =y ammStart respectively .

According to the design of TWAMM , large orders are traded along with blocks. Each block sells x rate to get y out , or sells x rate to get y out . At the same time, AMM will update the values ​​of x reserve and y reserve . The whole process A total of N transactions.

It is worth noting that each block transaction of AMM always follows a constant product to make market.

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

formula

First, after executing the transaction of the n-1th block, we assume that the x reserve and y reserve values ​​of the AMM at this time are x n-1 and y n-1 respectively .

Next, execute the transaction of the nth block, X-Pool and Y-Pool input x rate and y rate to AMM respectively, and command:

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Because the x rate and y rate are very small, and the transaction AMM of the block follows a constant product market maker, we can get,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Simplification,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

After obtaining the values ​​of x out,n and y out,n , we can further obtain the x reserve and y reserve values ​​x n and y n of the post-transaction AMM for n blocks,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Through observation, we found that x n *y n = x n-1 *y n-1 , which is exactly in line with the prerequisite requirements of AMM for market making with constant products.

Let x n *y n = x n-1 *y n-1 =…= x 1 *y 1 = x 0 *y 0 =k, which is a constant.

Fractional linear recursion

First obtain the general formula for x n , and obtain the value of x ammEnd = x N , and y n is the same.

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

The fractional linear recursive expression of y n is as follows:

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

untie

First, if y in is equal to 0 and x in is not equal to 0, then

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

and

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Calculated,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

and,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

When x in is equal to 0 and y in is not equal to 0, the discussion is the same as above.

If x in and y in are not equal to 0, we can use the fixed point method to solve the general fractional linear recursion.

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Further calculations,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

limit

The basic assumption of TWAMM is to decompose long-term large orders into an infinite number of infinitely small virtual orders, that is, N can take infinity, and the limit value of x N can be obtained at this time.

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

in,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

similar,

Hardcore: In-depth analysis of the mathematical principles of TWAMM market makers

Finally, after a simple verification x ammEnd *y ammEnd =x ammStart *y ammStart =k, it still satisfies the constant product of AMM .

At this point, we have completed the rigorous demonstration and explanation of the mathematical principles of TWAMM , and have reached the same conclusion as the article “Time-weighted market maker TWAMM .

Disclaimer: As a blockchain information platform, the articles published on this site only represent the author’s personal views, and have nothing to do with the position of ChainNews. The information, opinions, etc. in the article are for reference only, and are not intended as or regarded as actual investment advice.

Adblock test (Why?)