What is the difference between time-weighted automatic market maker and AMM?

According to Golden Financial News, the founder of Uniswap is working with two research institutes of Paradigm to study a new AMM model. The research is to process large transactions on Ethereum, which can divide large transactions into fragments and dissolve them within a certain period of time.

The author consulted Paradigm’s official website display document, and organized the differences between AMM and time-weighted automatic market maker TWAMM as follows:

Automatic Market Maker (AMM)

AMM automates most of the market making process on uniswap. The logic is to use the constant product formula to allow anyone to create transactions and AMM liquidity pools for new assets.

In order to create a new constant product AMM liquidity pool between two assets X and Y, the liquidity provider (LP) needs to deposit reserves x and y in these two asset forms. The ratio of these two assets at any time represents the instantaneous price on AMM.

If an AMM reserve contains 2,000USDC and 1ETH, the instantaneous price of ETH will be 2,000USDC.

When a trader trades with the AMM liquidity pool, AMM will quote the trader according to the formula x*y=k, where x and y represent the reserves of the two assets, and k is a constant. The product of the two reserves remains constant during the transaction (the cost is ignored).

for example

An AMM containing ETH/USDC assets has 2,000USDC and 1ETH in its reserve assets, so x=2,000, y=1 and x*y=k=2,000. The instantaneous price of this AMM is 2,000/1=2,000USDC/ETH.

The trader needs to buy 2000USDC of ETH, and he needs to deposit the 2000USDC used to buy ETH into the fund reserve, so we have x=2000+2000=4000.

If k=2000, we must get y=k/x=2000/4000=0.5 after the above transaction. Since y was initially 1, 1–0.5=0.5ETH, the trader received 0.5ETH in this transaction.

The trader bought 0.5ETH with 2000USDC, and the average price he actually paid was 4,000USDC/ETH. The relationship between the rising price and the instantaneous price can reflect that large-scale orders are closely related to AMM’s liquidity.

PS: If the reserve reserve is very high, when 2000USDC buys ETH, the price will not change so fast, and the trader can buy more ETH, because the trader must hope that the price of the transaction is that ETH is equal to 2000USDC, not Rapid growth in the transaction process. Cause a loss of principal.

Time-weighted automatic market maker (TWAMM)

The working principle of the time-weighted automatic market maker (TWAMM) is to split large orders into an infinite number of small orders, and use AMM to execute them smoothly through a time span.

for example

Suppose Alice wants to buy 100 million USDC worth of ETH on the chain, and executes orders of this size on existing AMMs such as Uniswap. The cost is very expensive (high handling fees and transaction losses will be charged).

Alice’s best choice is to manually divide her order into several parts and execute them one by one within a few hours, so that the market can give her a better price. (Because large orders will have a huge impact on prices, if others see a large order, it may cause others to sell or perform other operations, and it will take time to buffer the market.)

If she sends a few very large sub-orders, each order will still have a significant impact on the price and will be vulnerable to sandwich attacks by malicious traders. On the other hand, if she sends a lot of small sub-orders, she will have to bear the workload and risks of active transactions, and pay gas fees for each transaction, thus paying high costs to the miners.

TWAMM can conduct transactions on behalf of Alice. TWAMM splits her orders into countless infinitely small virtual orders to ensure that they are perfectly executed using the time span. The special function formula of the embedded AMM is used, which can be used in these virtual orders. The gas cost is shared among small orders. Because it processes transactions between blocks, it is also less vulnerable to sandwich attacks.

How to use AMM to execute large-scale transactions?

The design mechanism of AMM determines that the cost of executing a single large order on AMM is high. Therefore, traders who wish to execute large orders on AMM should not use a single transaction to execute them. It is best for traders to split the order into several parts. This will involve sending orders to multiple AMMs at once, but the liquidity of these AMMs at any given point in time may also be limited. If the order is larger, the more attractive it is to split it by time span.

We still assume that an investor wants to buy 100 million USDC of ETH on the chain. They don’t have any short-term information about the price of ETH, so they don’t mind whether their orders need to be executed within a fixed period of time. In this case, they may split their order into 10 parts, each with 10 million dollars, and execute a part every hour, thereby limiting the price impact on each part.

If a very large order is divided into several parts, the individual sub-orders for each part are still large, which will cause a corresponding price shock. Splitting orders into smaller orders will reduce costs, but it will also bring two new problems.

The first problem is the complexity of the operation. Traders may make input errors and the computer may crash. Even if everything goes smoothly, the process is very time-consuming and energy-consuming.

The second problem is that every transaction incurs a fixed transaction cost, such as gas paid to Ethereum miners to process the transaction. If a trader divides her order into too many parts, it may end up spending more money on fees than actually buying ETH.

How to use TWAMM to execute large order transactions?

Let me first mention TWAP (Time Weighted Price Algorithm) orders. The most basic type of algorithmic trading is time weighted price or TWAP orders. Assuming that a TWAP order worth US$100 million in Apple’s shares is purchased within 8 hours, and the price within 4 hours is US$100 and 4 hours is US$120, the time-weighted price will be ($100*4+$120 *4)/8=$110, the executing broker will execute TWAP orders close to this price.

The executing economic agency may also execute this transaction by splitting this order into many smaller parts and sending it to the market within a day. Buying $100 million of Apple stock in 8 hours means buying approximately $350 of Apple stock every 100 milliseconds.

For so many small transactions, the execution brokers have the infrastructure to reduce or eliminate the operational complexity, and because they are directly connected to the market, they may not need to pay too much transaction costs.

Time-weighted automatic market maker (TWAMM) provides an on-chain version of TWAP orders. TWAMM has special logic for order splitting and is directly related to an embedded exchange to provide smooth execution at low gas costs. Arbitrageurs can help the price of the TWAMM embedded exchange to be consistent with the market price, ensuring execution near the time-weighted average price of the asset.

TWAMM contains an embedded AMM, anyone can use this embedded AMM to trade at any time, just like an ordinary AMM.

Traders can submit long-term orders to TWAMM. These orders are orders to sell a fixed amount of an asset in a fixed number of blocks-for example, an order to sell 100 ETH in the next 2,000 blocks.

TWAMM decomposes these long-term orders into an infinite number of infinitely small virtual sub-orders, and these sub-orders are traded at a constant speed and embedded AMM within a certain period of time.

In a certain time span, the execution of long-term orders will push the price of embedded AMM to deviate from prices in other markets. When this happens, arbitrageurs will carry out arbitrage transactions based on the price of the embedded AMM to bring it back into line with the mainstream market.

For example, if a long-term sell order makes the price of ETH on the embedded AMM cheaper than the price of a particular centralized exchange, the arbitrageur will buy ETH from the embedded AMM, causing its price to rise on the AMM, and then the centralization The exchange sells arbitrage.

for example

Alice wants to buy 100 million USDC worth of ETH in the next 8 hours (about 2,000 blocks). She entered a long-term order to buy 100 million USDC worth of ETH in TWAMM, spanning 2,000 blocks, or 50,000 USDC per block.

Bob wants to sell 500 ETH in exchange for USDC in the next 5,000 blocks, that is, sell 0.1 ETH in each block.

Charlie wants to sell 100 ETH in exchange for USDC in the next 2,000 blocks, that is, 0.05 ETH in each block.

Before Charlie’s order expires in 2,000 blocks, Bob and Charlie’s orders will be combined in an order pool.

This ETH sales pool will sell ETH at a rate of 0.15 ETH per block in the next 2,000 blocks. Of the USDC earned by the mining pool in this way, Bob will get 0.1/0.15≈66%, and Charlie will get 0.05/0.15≈33%.

For each of the next 2,000 blocks, TWAMM must buy 50,000 USDC worth of ETH on behalf of Alice and sell 0.15 ETH in exchange for USDC on behalf of the ETH sales pool.

TWAMM splits each of these two sub-orders into trillions of tiny sub-sub-orders, which we call virtual orders (in fact, they will be decomposed into countless infinitely small virtual orders). Then TWAMM takes turns with its embedded AMM to execute these virtual orders: first a virtual order from Alice, then a virtual order from the ETH sales pool, then another virtual order from Alice, and so on.

After the 2,000th block, Alice’s order has been fully executed, as is Charlie’s order. Bob’s order to sell ETH is still valid for the next 3,000 blocks. During this period, TWAMM will continue to execute this order at a rate of 0.1 ETH per block.

 

Posted by:CoinYuppie,Reprinted with attribution to:https://coinyuppie.com/what-is-the-difference-between-time-weighted-automatic-market-maker-and-amm/
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Leave a Reply