Understanding TWAMM Concepts and Analyzing Limitations

Written by Do Dive, Research Analyst @DeSpread

What is TWAMM?

TWAMM is an abbreviation for Time-weighted Automated Marker Maker which is to split large orders into several small orders used to address issues such as drastic price change, liquidity depletion, etc.

In the last article that discussed measures to supplement algorithmic stablecoin models, I mentioned that the protocol (that has a large impact on the stablecoin pegging) should adopt the TWAMM approach for large orders to supplement the algorithmic stablecoin model.

However, TWAMM, unlike Uniswap’s AMM and Curve Finance’s Stableswap, is still new in the DeFi, and though implemented first by Fraxswap of Frax Finance, the usage is still not significant. In this regard, I would like to take a look at what TWAMM is in detail, how it can be applied in the real world, and what its limitations are.

Paradigm Shift to TWAMM

Frax Finance’s Fraxswap has announced itself as the first protocol to adopt TWAMM and specified it complies with the Paradigm whitepaper. The concept of TWAMM was first coined in this paper (whitepaper) published in July 2021, and the said paper was written by Dave White and Dan Robinson, a research team of Paradigm, and Hayden Adams, a founder of Uniswap. It is not exaggerating to say that currently all discussions around TWAMM are being centered around the said whitepaper, so I would like to mention I also referred to the Paradigm’s paper to write this article.

Problem recognition: price impact and transaction avoidance

What is Market Making?

Market Making is one of the factors needed to make asset transactions. Market Making is a behavior that mitigates imbalance between the asset supply (selling) and demand (buying) in the asset trading to make sure that the market operates smoothly where a market maker earns profits using the spread between the demand and supply instead of providing liquidity. For instance, Korea adopts what is called Market Making Scheme which allows securities firms to sign a contract with Korea Exchange to lead pricing by proposing bid and ask rates for items with insufficient liquidity, thereby earning fee profits and trading yields.

CPAMM of Uniswap and DeFi

In decentralized finance, so-called DeFi, a financial system implemented based on blockchain, there is no middleman, so market makers cannot exist. Therefore, one needed a way to make trades between assets without a middleman, and the AMM (Automated Market Maker) proposed by Uniswap has established itself as the basic principle of DEX or decentralized exchange.

The constant Product Formula is what AMM uses to decide how assets will be priced. Constant Product Formula is about creating a single liquidity pool that has two types of tokens, and the price of a token is determined in proportion to the number of tokens in the said pool. The key formula is x * y = k, where x and y are the token quantities in one liquidity pool, and k is a constant. That is, the multiplication of the number of tokens in a single liquidity pool should satisfy a constant k, and this way the price of each token is determined. To help you understand better, I will take an example of the ETH/USDC liquidity pool under CPAMM (Constant Product Automated Market Makers)

An example of ETH/USDC liquidity pool under CPAMM (Constant Product Automated Market Makers)

Before change: 1 ETH(=x), 2,000 USDC(=y), k=2,000

Price: 1 ETH = 2,000 USDC

Case: A demand to purchase ETH with 2,000 USDC occurred, and the liquidity pool condition has changed as below.

k=2,000, y=4,000 so the ETH that should remain in the said liquidity pool goes as x=k/y=2,000/4,000=0.5

Therefore, a person who has purchased ETH with 2,000 USDC gets to receive 0.5 ETH.

A buyer: purchased 0.5 ETH with 2,000 USDC

Each token quantity of liquidity pool: 0.5 ETH, 4,000 USDC

Price: 1 ETH = 4,000 USDC

AMM’s price-setting principle, Source: Paradigm Research
AMM’s price-setting principle, Source: Paradigm Research

Price impact and transaction avoidance

In the example above, a buyer of ETH has come to purchase ETH at a price (4,000 USDC) two times what he has observed (2,000 USDC). Likewise, under CPAMM, large orders in a specific liquidity pool lead to a serious price impact, and the damage is shifted to the trader himself. What is happening in the DeFi world is different from the real market where the burden from the shock is on the shoulders of the market makers.

The issue of price impact makes those who trade large orders avoid making transactions, and this negatively impacts the market as a whole in terms of capital flows and trading vitalization. Even though large orders are split into small numbers of orders, the hassle of making transactions and increased trading time lead to an increase in the trading cost, which inevitably makes people avoid transactions.

Resolution: Understanding of TWAMM and limitations

Adoption of TWAP order method

TWAP is a trading algorithm used to execute the total orders over a specified time. Using this strategy, a trader can execute an order at a price near the average price in the market. TWAMM is a strategy that makes TWAP on-chain, and it splits large orders into several small orders and executes serially over a long time. Therefore, a TWAMM user can make a transaction based on the market average price without price impact.

TWAMM Mechanism

Theoretically, TWAMM is about making large trades by splitting them into small units. However, executing the infinite number of transactions that contain details of the transaction on-chain (on the Ethereum network in particular) incurs a substantial amount of network fees and is therefore unrealistic. Therefore, the actual TWAMM mechanism that is feasible on-chain is as below.

  1. TWAMM is operated separately from the AMM, so submitting an order via TWAMM does not affect the liquidity in the AMM, meaning the order is submitted to an independent AMM and generates a single Order Pool.
  2. At the same time, infinite numbers of small virtual orders are executed over time based on the first market price of the asset by the trader’s funding scale and the set transaction period. There is no change to the actual liquidity as it is a virtual order, but over time, it causes changes to the asset exchange ratio, namely a price as if an actual order was executed.
  3. A transaction on Order Pool created on TWAMM is independent of the market liquidity so there is a discrepancy between the asset’s market price and its price on TWAMM.
  4. What’s more, Order Pool is open to ordinary traders so there is a demand for an arbitrage transaction due to price differences, therefore. the participants make an arbitrage trading on Order Pool and as a result, the transaction is executed at a price near to the weighted average price which is TWAP.
  5. Until the period set by a trader expires, the arbitrage transaction continues through the above mechanism, minimizing the impact of price and executing large-scale assets transactions.
An example of TWAMM order in Fraxswap, Source: Frax Finance Docs
An example of TWAMM order in Fraxswap, Source: Frax Finance Docs

An example for better understanding is as below.

1. Initial condition: the liquidity pool except for the TWAMM pool owns 100 ETH and 200,000 USDC (the price of 1 ETH = 2,000 USDC)

2. A trader who wants to sell 10 ETH for USDC submits a transaction to TWAMM under the condition of making a transaction within 24 hours and creates an Order Pool

3. A virtual order is executed and the ETH price on TWAMM gradually drops

3–1. For instance, there is no new arbitrage trader and a virtual order is executed every one hour, after the first order, around 0.417 (=10/24) ETH by the ETH market price, is added to the liquidity pool. Around 833 USDC is removed from the liquidity pool, so the virtual ETH/USDC liquidity pool on TWAMM and the price change as below

3–2 The virtual pool ratio after the first virtual order execution: 100.417 ETH / 199,167 USDC (the price of1 ETH = around 1983.4 USDC)

3–3. Therefore, from one hour after the order execution, the arbitrage trader can purchase 0.417 ETH at a price discounted from the market price (1 ETH = 2,000 USDC)

4. In reality, an infinite number of virtual orders is executed, meaning the price of ETH decreases in real-time, and when the price is low enough for an arbitrage transaction to take place, there is a pressure to sell ETH and the price of ETH converges to the market price

5. Until the 24-hour expires, 10 ETH becomes available for transaction sequentially, and through a consistent arbitrage transaction, it can be traded at a price near the market price.

Limitations of TWAMM

Possibility of Sandwich Attack

A sandwich attack is an act of pocketing a profit by executing front- and back- running — a trader looks at a pending transaction on the network and places an order right before and after the trade. For instance, when a trader finds a transaction that purchases 10 ETH at an AMM pool on the Ethereum network, an attacker spends a gas fee higher than the transaction itself, buys the ETH right before the trade takes place, sells the ETH right after the trade to gain profits from the price differences, and on the opposite, a transaction submitter suffers a property damage and loss.

In the case of transactions using TWAMM, it seems that the transaction is also vulnerable to sandwich attacks because the contents of the transaction are open to the public. However, orders using TWAMM run on multiple blocks and increase in size sequentially over time, making it difficult for sandwich attackers to identify targets and make solid profits because multiple arbitrage traders participate. Therefore, there is little risk of sandwich attacks running on a single block, but TWAMM may no longer be safe from that risk if sandwich attack techniques targeting multiple blocks are developed. Paradigm’s paper also recognizes the potential for these risks and states:

At present, there is no way for an attacker to guarantee that they will only trade at the end of a given block if they also get to trade at the beginning of the next block. When such multi-block MEV becomes more common, allowing traders to sandwich across multiple blocks, this may become more of an issue. — Paradigm, TWAMM

Not enough motivation for commercialization

The disadvantages of using TWAMM compared to other large-scale transactions include 1) the details of transactions such as the size of the fund and the transaction period disclosed, and 2) taking a relatively long time. These disadvantages make large traders shy away from using TWAMM, and make them prefer alternatives such as P2P transactions using the OTC market.

Therefore, TWAMM has a strong incentive to 1)traders who want to avoid price impacts from large capital transactions, and 2) who can stand long trading periods. This is why there has been much discussion about the concept and realization of TWAMM, but it has not yet been commercialized.

Case of application in the real world and expectation: Status of Fraxswap and the role as a tool for defense

Fraxswap, the first TWAMM, what is its current status?

The daily transaction processing of FRAX-FXS pool records around 10 or less, Source: Etherscan
The daily transaction processing of FRAX-FXS pool records around 10 or less, Source: Etherscan

In early April, Fraxswap, DEX of Frax Finance, was launched as the first TWAMM exchange. Regarding the launch, Sam Kazemian, the founder of Frax Finance, said it had introduced TWAMM to provide services for fund rebalancing of POL (Protocol-owned Liquidity) DAO protocols (source: Do Dive, ‘Fraxswap, the last piece of the puzzle for ‘Next Curve’). POL DAOs have a continuous demand for funding rebalancing and have a strong anti-price incentive for their governance token transactions, which meets the major user requirements of the TWAMM mentioned earlier, so they are presumed to have served the stated purpose.

However, the history of TWAMM usage has been very low since the launch of Fraxswap, and it has been confirmed that transactions between FRAX-FXS assets, which have recorded the highest transaction throughput, have only been processed about 10 times a day on Etherscan since May 16. The low usage may be attributable to the fact that Fraxswap does not handle many assets, but it also shows that TWAMM is not an easy model to commercialize.

Low incentive to use, nevertheless…

Although many disadvantages and limitations of TWAMM have questioned the feasibility of its commercialization of TWAMM, I think the significance of TWAMM as a way to prevent price impacts is strong. This is because the incentive to use TWAMM increases when demand for fund rebalancing occurs at the protocol level, such as Frax Finance’s AMO (Algorithmic Market Operation) policy and MakerDAO’s asset sales at vault liquidations. A report by a developer who is conducting TWAMM research and service development confirmed that there is a possibility for large-scale funds or DAOs to use TWAMM as the TWAMM’s performance improves and services materialized.

We’ve continued our conversations with large funds and DAOs to better understand their pain points and learn how TWAMM can potentially help. One common request we’ve heard in these conversations is the ability to automate long-term orders. Below is one such example order:

Buy 2–5% of an illiquid network’s publically available tokens over the next 8–12 months with a target price of less than 3x of current price for $5M USD.

The current implementation of TWAMM doesn’t have the ability to pause orders when they’re out of price range. Therefore, traders would have to monitor their orders in order to cancel and re-start orders in case of market volatility or generic front-running attacks. — 0x70626a, TWAMM Research: April 2022

Also, I think it implies a measure to supplement the algorithmic stablecoin models, which served as a starting point to write this article. For instance, forcing the use of TWAMM in the event of large-scale fund transactions on DEX protocols, such as Curve Finance which is deeply involved in algorithm stablecoins’ pegging, will be able to act as a way to prevent intentional protocol attacks.

DeSpread — Website | Twitter | Telegram | Facebook

DeSpread is a multi-chain ecosystem builders founded by blockchain content creators to help projects to accelerate together with the sustainable ecosystem. Our mission is to establish strong ecosystem foundation for anyone through eye-to-eye communication and education.

Subscribe to DeSpread
Receive the latest updates directly to your inbox.
This entry has been permanently stored onchain and signed by its creator.