In the next two blog posts, we will walk you through one of the most innovative designs in DeFi, TWAMM, how Integral SIZE was inspired by this idea, and which DeFi protocols implement this design. This is part 1.
TL; DR: A time-weighted automated market maker is a new type of DEX that lets traders place long-term orders that execute at time-weighted average prices. It works through a combination of fancy math, arbitrage opportunities and shadowy super coding.
What is TWAP?
First it is going to be helpful to understand the basics that make up the TWAMM, first is TWAP.
Time-weighted average price (TWAP) is a strategy used by traders that aims to track the price of an asset over a set time. A TWAP can better reflect the true market price of an asset by averaging its price over time. It is a more sophisticated strategy often used in traditional financial markets to execute large orders.
When trading with size in traditional financial markets, brokers will often act as intermediaries to execute individual trades. For example, a broker looking to buy $10m of ETH over the course of a day might execute 1 trade of $35,000 every five minutes and complete buying in just under 24 hours. Trading this way with small orders can minimize the price impact of the overall trade and the final execution price will be a weighted average of the day’s price.
What is an AMM?
The next part of a TWAMM is the AMM.
An automated market maker (AMM) is a type of DeFi protocol that allows users to trade assets. This works by creating a pool of two or more assets and opening users to trade against these liquidity providers.
As we’ve looked at in previous posts, traditional AMMs run with different constraints. While they allow for permissionless trading and market making, there are a host of downsides for traders and LPs.
- Traders encounter high price impact when trading in large amounts on chain.
- Liquidity providers are subject to impermanent loss and adverse selection, often greater than what they gain in income from fees.
What is a TWAMM?
A time-weighted automated market maker (TWAMM) is an idea proposed by Paradigm that brings together the ideas in AMMs and TWAP.
The TWAMM protocol contains an embedded AMM and allows traders to place block orders that execute over a set time. As time passes and the trades in the embedded AMM cause its price to deviate from the market, arbitragers will trade against the pool to bring the price back in line with the market. This allows trades with the TWAMM to track TWAP of an asset.
Say that 0xDorsal wants to sell 1,000 ETH and 0xLegoshi wants to buy 100 ETH.
- 0xDorsal sends 1,000 ETH sell order to TWAMM with a duration of 1 day.
- 0xLegoshi sends USDC to the TWAMM with an order to buy 100 ETH and a duration of a half day.
- The TWAMM takes both orders and simulates their impact on the TWAMM price as infinite small orders over the selected periods.
- As blocks tick by, 0xLegoshi’s order is quickly filled by the offsetting sell pressure from 0xDorsal.
- If no other buyers step in, the sell will continue to push the internal TWAMM price down.
- If the price gets low enough, outside arbitragers can step in buy from the TWAMM at a low price and sell to the market for a spread.
Conducting large trades on a traditional AMM like Uniswap can have a bad price impact and is vulnerable to MEV frontrunning or sandwich attacks. Splitting the trade into smaller orders means paying gas fees for each transaction. The TWAMM solves this problem by representing these orders in the smart contracts state.
The TWAMM opens itself up for arbitrage opportunities. Yet it ticks along, continuing to calculate the price impact of the infinitely-spaced long-term orders from the book. This makes the final execution price of the long-term orders traded in to a TWAMM roughly track the TWAP over the specified period.
Why use a TWAMM?
Traders that are not time-sensitive can use a TWAMM to execute large orders without adverse price impact. By splitting large orders up into infinite small orders, the TWAMM replicates a strategy similar to a TWAP broker order.
By executing the just a single transaction, the trader saves fees. Furthermore,TWAP transactions are more resistant to MEV sandwich and frontrunning attacks since they occur over multiple blocks.
LPs can also benefit from the model. Since trades against the TWAMM are not as rushed, they are less likely to suffer from adverse selection that hurt LP returns.
One use case that is still to be explored is how DAOs can benefit from trading with a TWAMM or a TWAP exchange like SIZE. Many DAOs already run into issues when trying to diversify their treasury or sell tokens to fund operations. It often has negative effects on the token price, made worse in cases where tokens have low liquidity on a distributed exchange. By using a TWAP model, DAOs can buy and sell tokens with a lower price impact.
Difference between TWAMM and SIZE?
As explained above, the TWAMM uses an embedded AMM that takes long term-orders in to account by evenly spacing their price impact.
While SIZE is also inspired by Paradigm’s TWAMM concept, our implementation is a bit different. Instead of representing trades in an embedded AMM, SIZE takes the 30-minute TWAP from an on-chain oracle like Uniswap v2. Then the trade is executed against the SIZE liquidity at the 30-minute TWAP with no price impact.
The protocols also have different defense mechanisms against MEV. Since the internal market of the TWAMM works similar to the familiar Uniswap v2 AMM, and it is open to outside arbitrage, the TWAMM could still be frontrun. In addition there is a larger attack surface for MEV arbitrage that results in toxic flows to the TWAMM.
Since Size doesn’t require large orders to touch the outside market at all, there is no arbitrage within the SIZE protocol, making it resistant to MEV.
SIZE’s TWAP is zero impact and offers magnitudes higher MEV resistance.
Trade on SIZE today at https://size.integral.link.
If you would like to reach out to us to discuss it more deeply, or want to suggest a topic for us, feel free to email us email@example.com.