Some Properties of TWAMM
Introduction
One year ago Paradigm released a spec for a TWAMM protocol. TWAMM (time-weighted average market maker) is a Uniswap V2-like CFMM that additionally supports orders over time. It enables time-insensitive traders to make large trades on-chain with minimal slippage.
If you are unfamiliar with the protocol, I highly recommend the very readable paper.
In this piece, we'll explore some properties of a TWAMM protocol.
The Use Case
Suppose a DAO wants to sell $50m of its treasury token. It currently has a few options for execution:
DAOs need to have high transparency whenever treasury funds are involved, and should prefer to get the best execution price possible. Enter the TWAMM.
TWAMM
The TWAMM protocol allows traders to execute large orders over a period of time—e.g. sell $50m of XYZ continuously over 5000 blocks ($10k per block)—transparently on-chain, with low gas fees and low slippage. We call these orders long-term orders.
By trading small amounts per block, slippage is minimized even with a relatively small TWAMM liquidity pool, as arbitrageurs are incentivized to source liquidity from other trading venues to correct prices between them. This is also what happens implicitly when an execution services firm executes a large order: the best possible execution creates no arbitrage opportunities.
A time-averaged order executed manually on a DEX incurs gas costs linear in the number of trades (the granularity of the order). Long-term orders placed on a TWAMM protocol pay fixed gas, though they also implicitly pay for gas costs of the arbitrageurs, via slippage.
Natural Frontrunning Protection
These long-term orders are on chain and therefore public. One might assume that this makes the orders susceptible to frontrunning: once a long-term order is signaled, a frontrunner may trade in the same direction as the order, then unwind after the order has concluded. The frontrunner benefits from the market impact caused by the long-term order, at the cost of the order getting worse execution.
But long-term TWAMM orders are cancellable, and can be made by anyone. That means aggressive frontrunners can be countered by spoofers. If traders systematically frontrun long-term orders, a spoofer can profit in the following way.
Spoofer buys
Spoofer places a large long-term buy order
Frontrunner anticipates the flow and frontruns it (by buying)
Spoofer trades against the frontrunner flow (by selling)
Spoofer cancels the long-term order
In practice, spoofing has a cost, so frontrunning may still be profitable to some degree. But very aggressive frontrunners will be kept in check by the threat of spoofing.
If a CEX implemented public, cancellable, time-weighted orders, users would get the same frontrunning protection from spoofers. And this frontrunning protection by spoofing can’t exist in OTC trading, because all counterparties are known and orders are private.
Privacy
This frontrunning protection is only effective if it's not clear if a long-term order is a spoof or not. If a doxxed, high-profile DAO places an order, frontrunners may correctly deduce that the order is not a spoof and frontrun it.
Privacy solutions like a deployment on a zero-knowledge privacy rollup (e.g. Aztec) get a lot of the way there, hiding the address of whoever is placing long-term orders. But if your DAO deposits $50m of token XYZ to the rollup and the next day a large long-term sell order begins, it might still be obvious who the seller is.
Conversely, unsophisticated whales may prefer to place long-term orders from publicly doxxed wallets, to signal they are unsophisticated. In this case, the market will price in less market impact and give them a better fill.
Benefits to Passive Liquidity Providers
It is well known that passive liquidity providers (LPs) tend to get a raw deal: they are exposed to adverse selection (getting run over by sophisticated traders) and usually not compensated enough in trading fees from uninformed flow to make up for it. Providing liquidity to unsophisticated flow is profitable, while providing to sophisticated flow is not.
In a TWAMM, all of the price-insensitive long-term flow goes through the LP pool which accrues trading fees. Note that profits earned and fees incurred by arbitrageurs are implicitly paid for by the long-term order, in the form of slippage.
In addition, if a TWAMM protocol is built on top of a Uniswap V3-like concentrated liquidity model, JIT liquidity strategies that are parasitic to passive LPs don’t work since long-term orders are effectively executed between blocks.
Opportunistic Liquidity Providing
There is still room for active LP activity in the TWAMM protocol. The intuition behind any form of opportunistic liquidity providing is that you want to be providing to the unsophisticated flow while avoiding the toxic (arbitrage) flow.
In the case of TWAMM LPing, this means providing liquidity while long-term orders are executing (providing to unsophisticated flow), and removing liquidity just before it becomes profitable to arbitrage (avoiding arbitrage flow). As the sophisticated LP gets filled by long-term orders, they can hedge out on other trading venues. This is a more efficient and more risky way to keep the price fair in the TWAMM pool than arbitrage.
Opportunistic LPing benefits the long-term orders and harms passive liquidity providers, in the same way that JIT LPs give crossers better fills at the expense of passive LPs.
Note that this strategy incurs more risk than JIT LPing, since the liquidity position is held over multiple blocks.
Bootstrapping Growth
Much less liquidity is required to bootstrap a TWAMM protocol compared to a traditional DEX, because arbitrageurs effectively source liquidity from external venues when a long-term order is placed.
An interesting growth mechanism here is to incentivize people to place long-term orders, rather than directly incentivizing LPing. The presence of large long-term order volume naturally draws LP activity. As noted above, sophisticated traders should want to be large LPs because they want to trade against the unsophisticated flow. When large volume of long-term orders is guaranteed, liquidity providers compete to give them the best fill.
Limitations
While a TWAMM protocol allows large trades to be made on-chain over time with low fees and low slippage, it does not solve all use cases for large on-chain trades. For example, TWAMM does not solve the problem of market instability from Solana liquidators market dumping large, freshly liquidated positions. Liquidators using TWAMM to unload these positions take on market risk that they may not be equipped to handle.
The core problem there is that competition for the liquidation trade is based on spam, so the best spammers get the very profitable trade and this is insensitive to the execution of their hedge (happy to market dump). Contrast this with liquidations on Ethereum, where competition for the trade is based on price (Flashbots auction) and therefore the winners are those with best execution of the hedge–i.e. non-atomic liquidators.
Acknowledgements
Thanks to Dave White, Dan Robinson, and Hayden Adams for the original TWAMM design. Thanks to Jarry Xiao and @0x70626a for their helpful dialogue on this piece.