Is TWAMM the next big thing in Defi? FraxSwap short analysis

Yong kang Chia
BLOCK6
Published in
5 min readJun 7, 2022
Photo : Messari

TWAMM Swap is a new form of swap that was created by Paradigm and utilized in FraxSwap

TWAMM in FraxSwap

What are Automated Market Makers?

Automated market makers (AMM) like Uniswap allow anybody to spin up a new AMM for a new pair of assets (x & y) instantaneously.

Most AMM’s utilizes constant product formula where initially users deposit token reserve x and token reserve y into the AMM.

The constant product formula is based on the formula x * y = k, where x and y are the total number of tokens for each token present in a pool and k is a constant that affects the trading ratio of the AMM. More about k here.

How does trading work on UniswapV2? Photo : Uniswap Documentation

Disadvantages of AMMs

However, the typical AMM model might be bad for traders with a larger order, as they might have a large price impact, face higher slippage, and are more susceptible to being front-run.

So how might we be able to mitigate some of the loss when transacting with a large order? We might be able to look at Traditional Finance (Tradfi) for some inspiration!

TWAP Order in traditional finance

In traditional finance, large trades are being handed over to brokers who place algorithmic trades over a period of time. One such technique is using the TWAP Order.

Time-weighted average price (TWAP) is the average price of a security over a specified time.

TWAP order is a type of algorithmic trade that allows an order to be placed over a period of time which allows trades to be safer.

The order is broken up into smaller trades and if the TWAP price is better than the current price, the order is then executed.

TWAP in AMMs: TWAMM

The Time-Weighted Average Market Maker (TWAMM) provides the on-chain equivalent of the TWAP order.

How does it work?

It is essentially broken up into 4 main parts

  1. Placement of long term order
  2. Division of long term orders into infinitely small virtual sub orders
  3. Trading long term orders against the embedded AMM
  4. Arbitrage against embedded AMM’s price to restore market price

Design of TWAMM

The TWAMM contains an embedded AMM, a standard constant-product market maker for those two assets. Anyone may trade with this embedded AMM at any time, just as if it were a normal AMM.

1. Placement of Long Term Order

Traders can submit long-term orders to the TWAMM, which are orders to sell a fixed amount of one of the assets over a fixed number of blocks — say, an order to sell 100 ETH over the next 2,000 blocks.

2. Division of long term orders into infinitely small virtual sub orders

The TWAMM breaks these long-term orders into infinitely many infinitely small virtual sub-orders, which trade against the embedded AMM at an even rate over time.

3. Trading long term orders against the embedded AMM

The execution of long-term orders in the form of small virtual sub orders will push the embedded AMM’s price away from prices in other markets over time.

Photo: LiteForex

4. Arbitrage against embedded AMM’s price to restore market price

When embedded AMM’s price is different from prices in other markethappens, arbitrageurs will trade against the embedded AMM’s price to bring it back in line, ensuring good execution for long-term orders, and earning some profits

Image showing how arbitrage is done. Photo: Forex Started

TWAMM In Action

1. Long-Term Orders (Buy USDC for ETH)

Alice wants to buy 100 million USDC worth of ETH over the next 8 hours or about 2,000 blocks. She enters a long-term order into the TWAMM to buy 100 million USDC worth of ETH over 2,000 blocks, or 50,000 USDC per block.

2. Splitting up long term orders into Virtual Orders

Every block for the next 2,000 blocks, the TWAMM has to buy 50,000 USDC worth of ETH on behalf of Alice. It will split the long term orders into trillions of tiny sub orders known as virtual orders)
Trading long term orders against the embedded AMM

3. Trading long term orders against the embedded AMM

The TWAMM then takes turns executing the virtual orders of buying eth against its embedded AMM

4. Arbitrage against embedded AMM’s price to restore market price

Because Alice is buying much more ETH than the ETH pool is selling, the price of ETH on the embedded AMM will go up each block.

When this price is sufficiently high relative to the prices for ETH elsewhere, arbitrageurs will buy that cheaper ETH on other exchanges and sell it on the embedded AMM, bringing its prices back in line with the market average and ensuring good execution for Alice.

And there you have it, folks, that's how TWAMM works in a nutshell.

Thank you for reading my article.

This article highly adapts from the original article by Paradigm and attempts to simplify & shorten it. However much of the details might be lost during the simplification and therefore I would highly recommend you to still check out the original article. Nonetheless, feedback are much appreciated :)

Contents distributed by Learn.Block6.tech

👉 Telegram — Fresh ideas

👉 Twitter — Latest articles

👉 LinkTr.ee

--

--

Yong kang Chia
BLOCK6
Writer for

Blockchain Developer. Chainlink Ex Spartan Group, Ex Netherminds