TWAMM Research: April 2022

Wow 🤯 we couldn’t have picked a better time to start our gas optimization development. With the results of several optimizations (discussed in detail below), we were able to shave off nearly 40% (!!) of gas used across the board in our TWAMM smart contract functions.

Gas comparison for contract functions of optimized design and FRAX TWAMM contract driven by benchmark design
Gas comparison for contract functions of optimized design and FRAX TWAMM contract driven by benchmark design

During times of network congestion, unoptimized TWAMM code would have no chance of being included in the block without paying exorbitant prices. Thus degrading the protocol performance, like frequent arbitrages, and causing orders to be filled at drastically skewed prices.


Beyond the wasted resources, the money spent on gas should be going to the protocol, LPs, and traders. The gas optimizations we are making now have compounding benefits down the road when billions of transactions are being processed by the TWAMM smart contract.

Business Development

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.

There’s also been an uptick in interest from protocols to start diversifying their treasuries into stables and ETH at attractive prices using regular old DCA methodology. This however runs into the gas cost problem since every intermediate transaction is on-chain.

Given how much money has been pouring into Crypto VC funds and the amount of alpha available in depressed blue-chip tokens, we believe these types of transactions will continue to increase in volume. This further adds credibility to a permissionless gas-efficient infinitesimal DCA product like TWAMM.

Finally, our RFP to research “first right arbitrage benefits to LPs” has been approved by the KeeperDAO token holders, see more here:

Product Development

Gas Optimizations

As usual, we’ve written up a detailed technical post on the various gas optimizations we’ve explored, measured, and benchmarked. We also have recorded how these optimizations stack up against the reference design, and FRAX’s mainnet deployed contracts to give further context to the improvements achieved.

Balancer Integration

On the Balancer Vault integration front, we’ve migrated Element FI’s example to our infrastructure and have a prototype for interacting with pools implemented atop the vault. The unique limitations of this interface, particularly in regards to restrictions on cashflows for pool transactions, present a design adaptation requirement for TWAMM implementations.

Using the userData parameters, we were able to design a solution that will allow us to implement our optimized TWAMM contract atop Balancer Vaults. More details on the implementation, gas savings, and other technical details will be released in the upcoming weeks.

Upcoming Work

Numerical Analysis

Moving forward, we’re going to be doing numerical analysis testing on all the gas optimizations implemented so far and our version of TWAMM built on top of Balancer Vaults. The importance of rigorous analysis cannot be understated given the funds that will potentially be transacted will be in the order of Billions.

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