In the recently introduced V4 version of Uniswap, there exists a new term or AMM model called TWAMM. TWAMM is known as a time-weighted average market maker, or pronounced “tee-wham”.
So what is TWAMM? How does it work? Let’s find out in this article!
You can read articles related to this content below:
- What is Uniswap (UNI)? Uniswap Cryptocurrency Overview
- What is Uniswap V3? Is Centralized Liquidity Changing the Crypto Market
- Uniswap V4: Creativity Is Unlimited
- What is Uniswap V4? Will Uniswap Continue to Lead the AMM Field?
- What is Gamma Strategies (GAMMA)? Overview of Cryptocurrency Gamma Strategies
- How GammaSwap Works
The Problem of Persistence
The ratio of these assets at any given time represents the instantaneous price on the AMM, or the price it will charge for a very small order. For example, if CPAMM contains 2,000 USDC and 1 ETH in reserve, its instant price for ETH will be 2,000 USDC.
When traders come to trade with the AMM, it decides what price to offer them based on the formula x * y = k, where x and y are reserve sizes and k is a constant. This means that the product has a reserve size that does not change during the transaction (ignoring fees).
And the problem here is that with orders with large volume compared to the liquidity in the Pool, the price will slip very quickly. This makes it difficult for users to transact large orders. To overcome this problem, users can split orders to trade and TWAMM was born to help automate the process of splitting orders to trade for users.
Read the example below carefully to clearly see price slippage when trading large volume orders.
- Consider an ETH/USDC pair with 2,000 USDC and 1 ETH in reserve, such that x = 2,000, y = 1 and x * y = k = 2,000. The instant price of this AMM is 2,000/1 = 2,000 USDC per ETH.
- If a trader comes in and buys 2,000 USDC worth of ETH, that means they are depositing 2,000 USDC into the X reserve, so we would have x = 2,000 + 2,000 = 4,000.
- Then, since k = 2000, we must have y = k/x = 2000/4000 = 0.5 after the transaction. Since y is initially 1, 1 – 0.5 = 0.5 ETH must be transferred to the trader.
- Since the trader purchased 0.5 ETH with their 2000 USDC, they paid an average price of 4,000 USDC per ETH. This high price relative to the instantaneous price reflects the large order size relative to the liquidity in the AMM.
- In the above case, the trader has to pay 4,000 USDC per ETH for their large order while the cost for a small order is only 2,000 USDC per ETH. This difference in price is called the price impact of the order. The larger the incoming order, the greater the price impact.
What is TWAMM?
TWAMM stands for Time-Weighted Average Market Maker, translated as time-weighted average market maker. Is a strategy of dividing large orders into small pieces for execution within a pre-specified period of time in a completely automatic manner. TWAMM contains an embedded AMM, anyone can trade with this embedded AMM at any time, just like a normal AMM.
The Time Weighted Average Market Maker (TWAMM) provides TWAP orders on the equivalent chain. TWAMM has specialized logic to split orders and connect directly to an exchange for execution, providing smooth execution with low gas costs. Arbitrageurs keep prices on TWAMM’s affiliated exchanges in line with market prices, ensuring order execution is close to the asset’s time-weighted average price.
Mechanism of Action
Essentially, the working mechanism of TWAMM divides these long-term orders into an infinite number of small virtual sub-orders, which trade with the embedded AMM at a uniform rate over time. Processing the transactions for each of these virtual sub-orders would consume infinite amounts of gas, but a closed-form mathematical formula allows calculating their cumulative effect only when needed.
Ethereum pools transactions into sequential groups called blocks, one block every 13 seconds. And the virtual instructions will be followed by each block as an instruction is executed. For example, an order that wants to be executed in 2 hours is equivalent to 553 blocks, meaning this order will be divided into 553 orders of equal volume and for each block one order will be executed.
Although dividing orders into small pieces will help you trade at a good price, executing too many orders will cause the problem of spending a lot of money to pay gas fees. However, when there are infinitely many infinitesimal virtual transactions, it is possible to include them in a single calculation, regardless of how many blocks it takes to execute them all. Read the following example to understand how to solve this problem:
- Imagine Bob places an order to sell 100 ETH in the next 100 blocks and Charlie places an order to sell 200 ETH in the next 200 blocks. Both orders are sold at a rate of 1 ETH per block.
- Let’s say no one interacts with TWAMM during these 150 blocks. For the first 100 blocks after Bob and Charlie place their orders, their orders are combined into a common order to sell 2 ETH per block. However, for 50 blocks later Charlie’s order is on its own, selling only 1 ETH per block.
- That means it has to perform two separate transaction calculations to find out what happened: one calculation for the results of the first 100 blocks and one calculation for the last 50 blocks.
Additionally, arbitrageurs can also find opportunities here. For example if going long makes ETH cheaper on the embedded AMM than on a particular centralized exchange, then arbitrageurs will buy ETH from the embedded AMM and sell it on the centralized exchange focus to make a profit.
Advantages and Disadvantages of TWAMM
Advantage
- Split orders to execute to avoid slippage and negative impact on price.
- Make prices smoother with countless small orders executed per unit of time.
- Realize complete automation and eliminate the need for human supervision and intervention.
- This densely divided order can be matched together according to the order book to get the best price.
Defect
- Vulnerable to MEV attacks
- It will cost a lot of gas fees if a bad situation takes many calculations.
- It takes a long time to execute the order, so it is affected by the price during this time period.
Personal Projection
TWAMM is a pretty cool model and it can be used in parallel with traditional AMM and complement each other. But until now, no project has successfully developed this model. Just recently, Uniswap introduced the TWAMM product in the V4 version that will launch in the future.
The development of TWAMM in Uniswap V4 is thanks to Hooks, a toolkit attached to AMM Pools on Uniswap. With this combination Uniswap can also support Limit On-chain orders. Thereby creating a new set of products that are very friendly and useful for end users.
TWAMM is not well known to the market, but when widely introduced by Uniswap V4, the market will accept and use this product. In addition, many other projects will compete to develop and come up with new ideas to optimize TWAMM in the future.
Summary
Any model or technology has its own strengths and weaknesses. A technology was born that solved this problem but created another problem, more or less. So TWAMM is a very good and optimal product for large volume orders but has some other limitations.
So I have clarified what TWAMM is? Hope this article provides you with a lot of useful knowledge!