# Treasury Diversification: Swap 500 wstETH -> rETH via TWAMM

### tldr;

There’s been interest in diversifying [Nouns DAO treasury](https://etherscan.io/address/0x0BC3807Ec262cB779b38D65b38158acC3bfedE10), specifically `stETH => rETH`, and we have built a tool that’s tailor-made to help execute these trades: *TWAMM.* The trade will be executed completely on-chain, transparently with very low fees and minimal gas costs. 

The first trade will be for $1M, and after that completes successfully, a larger $14M trade will be proposed.

## **Background**

TWAMM is a concept introduced by [Paradigm](https://www.paradigm.xyz/2021/07/twamm) 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 swaps is essential to increase DeFi adoption and anti-fragility. Some interesting use cases for TWAMMs include [treasury diversification](https://twitter.com/HelloShreyas/status/1502177286170185735)*,* [whale liquidations](https://twitter.com/solendprotocol/status/1538553654575214592)*,* [peg maintenance](https://www.notion.so/fd88cb37208d4b0f9abaca4e276f9ddd?pvs=21)*, etc*.

We have been researching and developing TWAMMs since November 2021 and recently launched our protocol: [CronFi TWAMM](https://twitter.com/cronfinance/status/1645802789006876672). The code has been audited by SpearbitDAO, open-sourced, and verified on Etherscan. Considerable detail about the protocol is presented on the [docs page](https://docs.cronfi.com/twamm/).

## **Product Design & Incentives**

- AMM: we built our TWAMM as a custom pool on top of Balancer V2 Vault leveraging the *security, liquidity, flexibility, and gas advantages* of 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 (Nouns 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 Nouns DAO 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 have built and partnered with dedicated arbitrageurs (BloXRoute) to ensure pools are arbitraged frequently to ensure Nouns DAO gets the best swap return.
- Liquidity: there will be a minimum of $30k liquidity in the pools and we expect that to reach between $50-100k in liquidity before the trade executes. TWAMMs are extremely capital efficient given that the trades are split across multiple blocks and arbitrageurs are consistently bringing new liquidity back to the system to correct price deviations — simulation details below illustrate these efficiencies and swap performance.

## **Advantages**

- Low fees: wstETH/rETH is a stable pair and long-term swappers pay a one-time **0.03% fee.**
- Fully on-chain: zero dependencies on off-chain services, oracles, compute etc.
- Flexible: issue, withdraw, and cancel orders with ease.
    - Example new order: `sell 7_500 stETH for rETH in 100_000 blocks` ~roughly 2 weeks
    - Helpful periphery contract to issue orders
- Full control of orders and assets: non-custodial, cancellable, and withdraw proceeds at any time.
- 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 blocks gas-free: Nouns DAO would only pay gas for starting and ending suborders; arbitrageurs pay for placing suborders on-chain.
- Analytics: we will have an analytics dashboard that shows how the order is being filled so the DAO can monitor the trade. There will also be a post-trade analysis and report.
- Monitoring: we will be actively monitoring the trade as the `delegate` to ensure the order is being filled at a reasonable price. In case the trade escapes a reasonable threshold, we will cancel the trade on behalf of the DAO, refunding proceeds and the remaining unsold portion of the order to the Nouns DAO wallet.

## **Risks**

- Smart contract:
    - Fully audited: see SpearbitDAO report [here](https://github.com/spearbit/portfolio/blob/master/pdfs/CronFinance-Spearbit-Security-Review.pdf).
    - Hack Risks: built on Balancer V2 Vaults which have been battle-tested for 2+ years.
    - Bricked Pools: we’ve done extensive research and mitigations for gas, order DDoS, numerical underflows, incorrect TWAMM parameters etc – more info here: [0slippage](https://mirror.xyz/0slippage.eth).
    - Loss of Funds: open-source code, audited, verified, 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 or change fees at which point Nouns DAO can cancel and withdraw their funds.
- Lack of Arbitrage: we have built a flash swap arbitrage bot and also teamed up with BloXroute to provide a dedicated arbitrage service.
- 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 stable pair like wstETH/rETH which are like assets and have deep liquidity pools.
- 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:
    - Pros: complete trade in a single block
    - Cons: poor liquidity, slippage, MEV attack vectors
- Aggregators
    - Pros: access to liquidity, completes trade quickly
    - Cons: not on-chain, MEV attack vectors, slippage
- OTC:
    - Pros: limit orders and other novel trade execution algorithms
    - Cons: off-chain, opaque, high fees, custodial, KYC, regulations, etc

## Trade Simulations

Here are the simulation results for the trade and expected returns. The initial trade is to show Nouns DAO the power of the protocol and ensure everything works as expected. This simulation is an approximation and results might vary based on liquidity, prices, volatility, etc. We will be monitoring the trade to ensure the trade fills won’t deviate drastically from the expected outcome. 

*NOTE*: this is a full contract simulation between a Balancer pool and our contract, using a fixed wstETH:rETH price in the balancer pool, fixed gas units, and fixed USD exchange rates. The simulation is executed with the actual contracts, with certain parameters held constant to evaluate the effect of liquidity and arbitrage frequency on swap performance.

### $1M trade with $100k liquidity: 1.327% slippage

![$1M Trade](https://file.notion.so/f/s/cc37a59f-9774-4859-a61c-69f8ee99fc0f/Untitled.png?id=af6d81b7-0b73-459b-bb0d-c6cafd2546d8&table=block&spaceId=7e9c2097-8472-4264-8933-88a90befa953&expirationTimestamp=1688119200000&signature=-LrcBvyt3f3UR6P-R3vrIOmejvImtapnsevhYmY6-yM&downloadName=Untitled.png)

LPs make **1.537% ($1537)** from fees in a week, if you’re interested in adding liquidity to the pool to earn fees, you can add liquidity here: [wstETH <> rETH TWAMM Pool](https://www.app.cronfi.com/pools/0x6910C4e32D425a834Fb61e983C8083a84b0EBd01). Here’s how swap performance improves as liquidity and arbitrage frequency increase in the pool. 
![Slippage vs Liquidity](https://file.notion.so/f/s/38b87f1a-e59a-42ab-8477-50eff845de50/Untitled.jpeg?id=00633ae7-1372-4f0a-96dc-87b8a3241a95&table=block&spaceId=7e9c2097-8472-4264-8933-88a90befa953&expirationTimestamp=1688104800000&signature=ZFT7TUSzr2-CoDAk20NjvH_nq4iKvwqXNmleE0QYEys&downloadName=Untitled.jpeg)

The real benefit is in the larger trade which does better than any on-chain solution and even Cowswap’s quotes. Additionally, LPs would make **1.545% ($21,626)** from fees in a week

### $14M trade with $1.4M liquidity: 0.553% slippage

![$14M Trade](https://file.notion.so/f/s/58005a86-ccbf-4242-964b-f61d1a3d8f3c/Untitled.png?id=8901e138-7e97-4fd4-a06f-f1647147aa9a&table=block&spaceId=7e9c2097-8472-4264-8933-88a90befa953&expirationTimestamp=1688126400000&signature=TTPdCodz5QByagmT-VhmdZev_6Z6NZNlGwFhx-PzmCY&downloadName=Untitled.png)

## **Proposal Operations**

This proposal requires two on-chain proposals. The first will be a trial trade for $1M wstETH → rETH. The follow-up proposal will trade $14M wstETH → rETH. 

Note: we’re wrapping more stETH than we are selling because the price fluctuates, we want to ensure the proposed amounts of wstETH are available to sell.

1. (We are here) `sell 500 wstETH for rETH in 50_400 blocks` ~1 week
2. (Follow up) `sell 7000 wstETH for rETH in 50_400 blocks` ~ 1 week

Outcome: EXECUTED