TWAMM: on-chain non-custodial DeFi protocol for large asset swaps

Hi All,

There’s been some discussion about ENS DAO treasury diversification, and we wanted to inform the DAO of a tool that’s tailor-made to help execute these trades: TWAMM.

Background

TWAMM is a concept introduced by Paradigm in July 2021.

It works by breaking long-term orders into infinitely many infinitely small pieces and executing them against an embedded constant-product AMM smoothly over time.

An on-chain AMM protocol to enable large token swap is essential to increase DeFi adoption and anti-fragility. Some interesting use cases for TWAMMs include treasury diversification, whale liquidations, peg maintenance, onboarding collateral, etc.

We have been researching and developing TWAMMs since November 2021 and have posted monthly blog/tweet threads updates of our findings and progress – see compilation on our GitHub - Cron-Finance/Cron-Finance

The development of our protocol has been funded by grants from Balancer & KeeperDAO. We’ve also raised a small angel round from the founders of Balancer, BloXRoute, KeeperDAO, and SpearbitDAO.

Product Design & Incentives

  • AMM: we built our TWAMM as a custom pool on top of Balancer V2 Vaults given the security, liquidity, flexibility, and gas advantages of leveraging Balancer. Additionally, Balancer has become a Schelling point for protocols that want to leverage their AMM, thus creating network effects & composability advantages.

  • Traders: as a long-term trader (ENS DAO), you only have to pay gas for starting, canceling, or withdrawing proceeds from your order. All the other sub-orders of the DCA are done virtually and cost the trader no gas fees. Virtual orders are only written on-chain when the next user interacts with the protocol (generally an arbitrageur).

  • Arbitrageurs: as seen on other AMMs like Uniswap, arbitrageurs are important to keep the price of the assets in line with external venues. Arbitrageurs are critical for TWAMMs because trade sizes are significantly larger and last for multiple blocks. Therefore we partnered with dedicated arbitrageurs (KeeperDAO, BloXRoute) to ensure pools are arbitraged frequently thus giving traders a smooth fill.

  • Liquidity: the final piece of the puzzle is the liquidity needed to actually execute the trade. Because we use dedicated arbitrage (PFoF) system, we can collect and pass a share of the MEV back to LPs. Additionally, we reinvest the MEV rewards into the pool thus adding liquidity to the pool and increasing LP returns in pool tokens.

Here is a schematic of our TWAMM implementation, API, and different features:

Advantages

  • Low fees: ETH/USDC is a liquid pair and long-term swappers pay a one-time 0.15% fee
  • Fully on-chain: zero dependencies on off-chain services, oracles, compute etc.
  • Flexible: issue, change, and cancel orders with ease. Example new order: sell 10_000 ETH for USDC in 100_000 blocks
  • Full control of order and assets: non-custodial, cancellable and withdraw proceeds at anytime
  • Withdraw multiple times: users can withdraw once at the end, or every set number of blocks – they just pay gas fees
  • DCA over 1000’s of intervals gas-free: traders only pay gas for starting and ending orders, arbitrageurs pay for placing suborders on-chain
  • Composable: other protocols/products that can be built on top of TWAMMs include retail DCA via wallets, superfluid like token streaming without wrapping tokens, etc

Risks

  • Nascent technology:
    • Audit: we’re getting an audit by SpearbitDAO on January 23rd, expected to launch at Eth Denver pending a successful audit. To mitigate this issue, the DAO can execute a smaller order to test out the efficacy of the protocol.
    • Other customers: Olympus DAOs new RBS system will be leveraging our TWAMM to constrain OHM price to predictable bounds.
  • Smart contract:
    • Hack Risks: built on Balancer V2 Vaults which have been battle-tested for 2+ years. As a trader, t
    • Bricked Pools: we’ve done extensive research and mitigations for gas, order DDoS, numerical underflows, incorrect TWAMM parameters etc – more info here: 0slippage
    • Loss of Funds: open-source code, audited, non-custodial, users in full control of funds, trade happens over multiple blocks so it can be canceled at any time by the user.
    • Malicious Pool Admin: all pool administrators can do is pause the pool at which point traders can cancel and withdraw their funds
  • Lack of Arbitrage: we have teamed up with KeeperDAO and BloXroute to provide dedicated arbitrage service. On the off chance neither service arbitrages the pool, the open market will arbitrage the pool
  • Poor Execution: orders are cancellable at any time i.e if the price escapes preferred bounds restart the order at another time. Also, DCA is generally a better strategy than spot purchase for large orders.
  • Information Leakage: this is not a big concern for a liquid pair like ETH/USDC, the most popular and deeply traded pair on crypto exchanges
  • MEV/Sandwich Attacks: orders are broken into small pieces and thus the benefit of front/back running orders is minimal – see the Paradigm paper for further details.

Competition

Here are the alternatives and how they stack up against TWAMM. Note this isn’t a comprehensive list, but a short summary.

  • Gnosis Auction:
    • Pros: well-tested technology
    • Cons: reliant on well-funded keepers, minimum buy lots, price upside capped, infrastructure overhead, limited timeframe, poor execution vs DCA over long periods.
  • Manual DCA:
    • Pros: can execute it today
    • Cons: need to write a smart contract or fat finger mistakes, fees for each sub-order, gas costs of sub-orders, limited # of sub-orders
  • DEX/Aggregators:
    • Pros: complete trade in a single block
    • Cons: slippage, MEV attack vectors
  • OTC:
    • Pros: limit orders and other novel trade execution algorithms
    • Cons: off-chain, opaque, high fees, custodial, KYC, regulations, etc
1 Like