TWAMM Research: August 2022

This past month we focused on achieving feature completion, making huge strides towards that goal. Highlights include adding efficient vault accounting, oracles, and configurable partner fee distribution. Additionally, we’ve designed an elegant MEV distribution scheme that automatically reinvests rewards into the liquidity pool -- more details below.

Big Picture

The “DeFi is eating TradFi” narrative is getting stronger every day as on-chain capital continues to become more attractive for traders. Every day more institutions embrace on-chain protocols, moving large amounts of capital to leverage these efficient new financial legos.

Billion Dollar On-Chain Transactions

Speaking of large on-chain transactions, MakerDAO was even contemplating divesting their USDC position, which is approximately $3.5 Billion! However, large trades like this are difficult to execute on-chain because the tools available (DEXs, dutch auctions, aggregators) present a number of drawbacks.

Today, MakerDAO would have to move on-chain assets off-chain to an OTC desk (custody risks, inefficient, opaque execution), use custom DCA scripts (security risks, gas inefficient, coarse execution), or Dutch Auctions (inefficient price discovery, infrastructure overhead) to complete this transaction.

Instead with TWAMM, MakerDAO could simply put in an order to sell $3.5 Billion of USDC for ETH over 10,000 blocks and let the market forces (arbitrageurs) source liquidity and pay the gas costs of executing the sub-orders all while getting the best fill with very little oversight.

Toxic & Non-Toxic Order Flow

Identifying toxic order flow and attracting large uninformed (non-toxic) order flow, like the MakerDAO transaction, is the holy grail for market makers and liquidity providers. However, this is a hard problem for DEXs to solve without adding gas inefficient on-chain logic or relying on off-chain computations.

Single swap interface for both toxic & non-toxic order flows
Single swap interface for both toxic & non-toxic order flows

In most DEXs, all swaps go through the same interface and fee bucket as shown in the diagram above. In this scenario, passive liquidity providers eat the toxic order flow because arbitrageurs exploit outdated pool prices without compensating LPs with the commensurate MEV extracted.

Follow the Flow

More trades, more fees, more liquidity, more trades… and thus a self-fulfilling prophecy fulfilled. When the incentive structure is broken, somebody is left holding the bag -- passive LPs.

With the influx of sophisticated LPs, liquidity has become more fluid and moves to the right venues and even price ticks to capture the maximum amount of fees. There’s no incentive to stay in one venue (unless there are incentives) since the uninformed order flow has no Schelling point.

In order to play this game, you need to be well capitalized to pay the fees and have advanced software to manage your positions. Today there are few large winners and lots of small market makers losing. A few off-chain tools help you provision your passive liquidity, but these tools have their own drawbacks and risks.

Dual Swap Paradigm

As mentioned, identifying toxic order flow and attracting non-toxic order flow is the name of the game. Our TWAMM implementation has an elegant incentive structure baked in:

  • The short-term swap interface is somewhat more costly gas-wise than a Uniswap V2 swap and will primarily be used to correct pool prices by arbitrageurs. So, we collect and pass on a portion of the MEV extracted via a proprietary arbitrageur swap interface.

  • The long-term swap interface proxies trades that happen over multiple blocks & are inherently uninformed non-toxic flow. This user pays a standard low fee that outcompetes incumbents like OTCs on fees, and other implementations on gas costs.

Dual swap interface to cleanly separate toxic and non-toxic order flow
Dual swap interface to cleanly separate toxic and non-toxic order flow

Democratizing the Edge for Passive LPs

Now that we have a DeFi protocol that has built-in MEV extraction and novel trade execution for large uninformed order flow, we are finally able to even the playing field for passive LPs.

Sophisticated market makers have been hedging the downside of providing liquidity in DEXs by arbitraging the very same pools. With our TWAMM implementation, passive LPs will be able to hedge against impermanent loss by collecting and automatically re-investing MEV rewards from arbitrageurs.


Product Updates

After we opened our codebase to select partners last month, we got a lot of great feedback that helped us significantly improve our code and protocol design. A special thanks to the Balancer integrations team for their guidance with Vault nuances.

We also met with a great group of market makers (s/o Cumberland, Genesis, CMS, Wintermute, LedgerPrime) to understand their perspectives and discuss how they can leverage TWAMM.

Feature Completion

Achieving feature complete status has been a major focus of this development cycle. Beyond incorporating a price oracle similar to the one introduced in Uniswap V2, we also completed an efficient protocol fee implementation.

The implementation splits collected fees between Balancer and Liquidity Providers (LPs), reinvesting the LP portion into the pool after completing a swap for pro-rata distribution. Optionally, a CronFi fee collection address can be specified to enable the accumulation of fees for CronFi, split with the LPs.

Working with partners that reviewed initial versions of our contract, we were able to realize further efficiencies while introducing intelligent gas-saving optimizations that synced our accounting with Balancer’s vault by relying on differential TWAMM reserve computation instead of duplicated storage and arithmetic. Furthermore, leveraging the unique behaviors of Balancer’s custom pool, we were able to adapt our UX to be more gas efficient while reducing the complexity and steps required to perform order cancellations and withdrawals.

Automatic MEV Distribution & Reinvestment

An important part of our work since the previous update is a design feature that transfers a portion of MEV tokens (WETH) from arbitrage partners to LPs. The design balances gas use and composability while eliminating the incentive to use flash loans for just-in-time liquidity attacks to capture MEV rewards.

Example MEV Capture Attack Transaction:
1. Flash loan to provide liquidity.
2. Call "Collect MEV" to get rewards in pool.
3. Redeem LP tokens to pay off flash loan.
4. Pocket gain from MEV rewards.
MEV redistribution scheme that automatically reinvests rewards as liquidity
MEV redistribution scheme that automatically reinvests rewards as liquidity

This architecture was chosen in favor of other alternatives because of complexity and gas use--the holding period penalty should be a sufficient disincentive against MEV reward attacks while encouraging liquidity stickiness.

Numerical Analysis

We’ve also started analyzing of our earlier algorithmic optimizations to understand the limitations and performance characteristics they impose on our TWAMM implementation.

A simplified analysis of the dominant terms of a 5-dimensional function describing the number of bits required to represent the staking rewards of a TWAMM pool in a given block
A simplified analysis of the dominant terms of a 5-dimensional function describing the number of bits required to represent the staking rewards of a TWAMM pool in a given block

Further analysis of other optimizations in our implementation will be forthcoming as we transition from feature complete status to numerical analysis and gas optimization.

Subscribe to 0x70626a
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.