# Lido Stonks: Treasury Swaps via Optimistic Governance

**URL:** https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860
**Category:** Proposals
**Created:** [March 14, 2024, 2:18pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860 "2024-03-14T14:18:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_L](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/alex_l/32/994_2.png) [@Alex\_L](https://research.lido.fi/u/Alex_L)
#### Post date: [March 14, 2024, 2:18pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/1 "2024-03-14T14:18:24Z")

</div>

### Problem statement

The [Treasury Management Committee (TMC)](https://research.lido.fi/t/proposal-to-approve-lido-dao-treasury-management-principles-and-authorize-the-formation-of-a-treasury-management-committee/4279) was introduced last April as a result of [Snapshot vote](https://snapshot.org/#/lido-snapshot.eth/proposal/0xac31f800288c68e32d1eb3cea7a525022faae3eb3bf805d1b3d248cda5375a13). The committee’s purpose is to develop constrained strategies, execute actions within [Treasury Management Principles](https://research.lido.fi/t/proposal-to-approve-lido-dao-treasury-management-principles-and-authorize-the-formation-of-a-treasury-management-committee/4279#treasury-management-principles-3), and eventually automate itself away.

Key aspects include keeping ETH as the primary unit of account, supporting the Lido protocols’ integrity, growth, and robustness, minimizing risk of loss, and ensuring all treasury ETH is staked using Lido.

Its capabilities are presently confined to proposing votes via [Aragon](https://vote.lido.fi/), such as [TMC-0](https://research.lido.fi/t/tmc-0-stake-all-treasury-eth-in-lido/4744/8) ([vote #161](https://vote.lido.fi/vote/161)), highlighting the need for more flexible tools to enhance treasury agility and rebalancing. [TMC-1](https://research.lido.fi/t/tmc-1-pipeline-to-sell-steth-at-regular-intervals-for-dai/) introduces the notion of an automated swapper triggered through an optimistic governance (like [Easy Track](https://easytrack.lido.fi/)).

A treasury swapper is an example of on-chain tooling that can implement TMC-1 and execute constrained actions, with optimistic purview by Lido DAO token holders. The swapper should adhere to the following requirements:

### General requirements

- proposed solution should be able to be used by the TMC multisig
- Lido DAO token holders should always be able to veto any actions
- funds should only be available for a limited set of transactions, pre-approved by Lido DAO token holders;
- proposed solution should have restricted access to the Lido DAO treasury.

### Technical requirements

- every trade should be MEV-protected;
- every trade should be “price-guaranteed” (the trade is expected to be cancelled if the minimum exchange amount is not received);
- beneficiary of every trade should be Lido DAO ([treasury](https://etherscan.io/address/0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c));
- variety of tokens for trade (both input and output) should be strictly limited by DAO;
- TMC should has the ability to operate trades (move funds from treasury, place orders, move funds back to treasury in case of unsuccessful trade);
- TMC should never take custody of Aragon funds;

### Primary use-cases

- selling stETHs to stables (DAI/USDC/USDT)
- rebalancing the amounts of different stables (DAI/USDC/USDT)

Considering mentioned requirements it is proposed to develop a new technical solution Stonks, which will contain a fixed set of necessary operations for exchanging funds and managing the treasury.

### Solution components

1. [Easy Track](https://github.com/lidofinance/easy-track) motion or Aragon vote (in case of emergency) for token transfering. These contracts will be used as is.
2. [Stonks](https://github.com/lidofinance/stonks) - a set of contracts which act as a receiver of tokens from the first step and a container of swap operations set by Lido DAO;
3. [Cow Protocol](https://cow.fi) - a fully permissionless trading protocol that enables batch auctions to maximize liquidity via Coincidence of Wants (CoWs) in addition to tapping all available on-chain liquidity;
4. [ChainLink](https://chain.link) - a decentralized oracle network that provides the USD price of Ethereum’s native cryptocurrency and tokens.

There are two directions of tokens movement between components:

1. Swap (happy path) - when tokens are transferred from the DAO Treasury to Stonks for swapping using CoW Protocol. Swap proceeds are sent directly to the DAO Treasury (CoW Protocol API allows it).
2. Recovery (contingency) - if the swap doesn’t execute for any reason, tokens must be returned to the DAO Treasury.

### Happy path illustration

 ![](https://europe1.discourse-cdn.com/flex013/uploads/lido/original/2X/3/339c7268c69ff0dca76180a946794e5dfb8bd23a.png)

**Step 0**. A new Stonks instance is created with specific params and the DAO is proposed to add that contract to the Easy Track allowed recipients.

**Step 1**. Tokens are transferred from the DAO Treasury to the Stonks instance via Easy Track top up factories or Aragon vote.

**Step 2**. Order placement. TMC requests Stonks to deploy a new Order contract via placeOrder function and it automatically sends all available assets there. After deployment the Order emits an event about it’s creation, sets an allowance to the CoW vault relayer contract and waits until this order is completed.

**Step 3**. Order creation. Easy Track UI checks for `Order Created` events and if it detects one, allows TMC to create an offchain order on Cow Protocol. This UI is trustless and can be used by anyone. The order price is checked against price tolerance parameters to simultaneously provide some margin to cover CoW Protocol fees + minor price fluctuations, but restrict from executing significantly unfavourable swaps (more details are in the [specification](https://hackmd.io/6fmMnLqoQcq3LqFYcIdMwQ?view#Price-checking)).

**Step 4**. The Swap. At the moment of order fulfilment CoW Protocol debits funds from Order contract & sends all exchanged assets to the DAO Treasury.

## Recovery (contingency) flow illustration

 ![](https://europe1.discourse-cdn.com/flex013/uploads/lido/original/2X/e/ea4390d859fc8b2180306afa645ae7027cae8637.png)

If for any reason swap isn’t going through, there must be a method to recover the tokens. Tokens can be at Stonks (before the swap is requested) or at Order (once the swap is requested on Stonks).

**Step 4**. The swap hasn’t happened and the order has expired. Anyone can return all funds to the Stonks contract for further actions in a permissionless manner. From this moment Order contract becomes inactive.

**Step 5**. At the moment, in case of market turbulence the DAO can decide what to do next:

- send all funds to the DAO Treasury back;
- create a new order again.

For more details about each step please read the [specification](https://hackmd.io/6fmMnLqoQcq3LqFYcIdMwQ?view).

### Voting actions

Lido DAO is proposed to add following contracts to the set of Lido on Ethereum protocol in case of successful Aragon vote:

**new TopUpAllowedRecipients ET factory addresses**

These factories are used to request tokens from the Treasury, to be swapped in Stonks orders (TMC multisig selects a factory according to the swap direction, for example stETH → DAI, and enters the amount to be swapped).

TopUpAllowedRecipients for STETH → DAI / USDC / USDT (ADDRESS\_TBA)

parameters:

- AllowedRecipientsRegistry (_[0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0](https://etherscan.io/address/0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0)_);
- TopUpAllowedRecipients (_[0x6e04aED774B7c89BB43721AcDD7D03C872a51B69](https://etherscan.io/address/0x6e04aED774B7c89BB43721AcDD7D03C872a51B69)_);
- Top up limit: 9\_000 \* 10 \*\*18 ($30M equivalent using [30d TWAP](https://dune.com/queries/1080098?symbol_t6c1ea=stETH) rounded to the nearest thousand);
- Limit refresh frequency: every six months

TopUpAllowedRecipients for DAI /USDC / USDT → USDC / USDT / DAI (ADDRESS\_TBA)

parameters:

- AllowedRecipientsRegistry (_[0x3f0534CCcFb952470775C516DC2eff8396B8A368](https://etherscan.io/address/0x3f0534CCcFb952470775C516DC2eff8396B8A368)_)
- TopUpAllowedRecipients (_[0x0d2aefA542aFa8d9D1Ec35376068B88042FEF5f6](https://etherscan.io/address/0x0d2aefA542aFa8d9D1Ec35376068B88042FEF5f6)_)
- Top up limit: 10\_000\_000 \* 10 \*\*18 ($10M);
- Limit refresh frequency: every three months

**Stonks contracts**

These contracts create order instances initiating CoW swap orders using tokens and parameters received from TopUpAllowedRecipients and AmountConverter. CoW orders are created via ET UI, following a preliminary double check of the minimal amount that the treasury should receive in case of success.

- STETH→DAI (_[0x3e2D251275A92a8169A3B17A2C49016e2de492a7](https://etherscan.io/address/0x3e2D251275A92a8169A3B17A2C49016e2de492a7)_)
- STETH→USDC (_[0xf4F6A03E3dbf0aA22083be80fDD340943d275Ea5](https://etherscan.io/address/0xf4F6A03E3dbf0aA22083be80fDD340943d275Ea5)_)
- STETH→USDT (_[0x7C2a1E25cA6D778eCaEBC8549371062487846aAF](https://etherscan.io/address/0x7C2a1E25cA6D778eCaEBC8549371062487846aAF)_)
- DAI→USDC (_[0x79f5E20996abE9f6a48AF6f9b13f1E55AED6f06D](https://etherscan.io/address/0x79f5E20996abE9f6a48AF6f9b13f1E55AED6f06D)_)
- DAI→USDT (_[0x8Ba6D367D15Ebc52f3eBBdb4a8710948C0918d42](https://etherscan.io/address/0x8Ba6D367D15Ebc52f3eBBdb4a8710948C0918d42)_)
- USDT→USDC (_[0x281e6BB6F26A94250aCEb24396a8E4190726C97e](https://etherscan.io/address/0x281e6BB6F26A94250aCEb24396a8E4190726C97e)_)
- USDT→DAI (_[0x64B6aF9A108dCdF470E48e4c0147127F26221A7C](https://etherscan.io/address/0x64B6aF9A108dCdF470E48e4c0147127F26221A7C)_)
- USDC→USDT (_[0x278f7B6CBB3Cc37374e6a40bDFEBfff08f65A5C7](https://etherscan.io/address/0x278f7B6CBB3Cc37374e6a40bDFEBfff08f65A5C7)_)
- USDC→DAI (_[0x2B5a3944A654439379B206DE999639508bA2e850](https://etherscan.io/address/0x2B5a3944A654439379B206DE999639508bA2e850)_)

In addition to mentioned ET factories and Stonks the AmountConverter contract is to be deployed.

**AmountConverter (_[0x12cc60eea45F705f069B43095FbF2Fb3c7f874c1](https://etherscan.io/address/0x12cc60eea45F705f069B43095FbF2Fb3c7f874c1)_)**

This contract provides functionality to retrieve expected token conversion rates based on the Chainlink Price Feed. It also sets immutable variables:

- FEED\_REGISTRY = [0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf](https://docs.chain.link/data-feeds/feed-registry#contract-addresses) (ChainLink price feed registry)
- CONVERSION\_TARGET = [0x0000000000000000000000000000000000000348 - USD](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/Denominations.sol) (‘840’ in decimal notation)
- ALLOWED\_TOKENS\_TO\_SELL = [STETH, DAI, USDC, USDT]
  - STETH = [0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84](https://etherscan.io/address/0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84)
  - DAI = [0x6B175474E89094C44Da98b954EedeAC495271d0F](https://etherscan.io/address/0x6B175474E89094C44Da98b954EedeAC495271d0F)
  - USDC = [0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48](https://etherscan.io/address/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
  - USDT = [0xdAC17F958D2ee523a2206206994597C13D831ec7](https://etherscan.io/address/0xdAC17F958D2ee523a2206206994597C13D831ec7)

- ALLOWED\_TOKENS\_TO\_BUY = [DAI, USDC, USDT] (same addresses as in previous bullet point)
- PRICE\_FEEDS\_HEARTBEAT\_TIMEOUTS = [
  - 3600n + 15n \* 60n, - 1 hour 15 minutes for the stETH/USD feed
  - 3600n + 15n \* 60n, - 1 hour 15 minutes for the DAI/USD feed
  - 24n \* 3600n + 30n \* 60n, - 24 hours 30 minutes for the USDC/USD feed
  - 24n \* 3600n + 30n \* 60n, - 24 hours 30 minutes for the USDT/USD feed]
  - Here 15/30 minutes are added to the default heartbeat values to compensate for non-critical delays of the updates ([more details here](https://docs.chain.link/data-feeds/price-feeds/addresses?network=ethereum&page=1#ethereum-mainnet))

Audit of Stonks contracts is being finalized and the report to be provided in the comments to this post before the Aragon vote starts.

**UPDATE** Added addresses and corrected limit for TopUpAllowedRecipients stables factory to $10M quarterly.

---

<div class="post-metadata">

### Author: ![steakhouse](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/steakhouse/32/1878_2.png) [@steakhouse](https://research.lido.fi/u/steakhouse)
#### Post date: [March 14, 2024, 2:26pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/2 "2024-03-14T14:26:16Z")

</div>

Really excited to see this come to life!

The modular approach of this design makes it possible to iterate very quickly on a next step of this function. Today, the TMC will be in charge of the trigger and selecting thresholds, but there is no reason why this level-setting and execution couldn’t be done permissionlessly also. One way in which this could be done is by allowing an Aragon vote to set a maximum ceiling of swaps permitted in a rolling 12mo period (~2.6m blocks):

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/lido/original/2X/6/654de5568d5741ca981b283f7a2b96f34105d0bc.png)

Consistent with the TMC mandate, this will allow an extension of the implementation to remove the multisig from the picture altogether.

> [@Proposal to approve Lido DAO Treasury Management Principles and authorize the formation of a Treasury Management Committee](https://research.lido.fi/t/proposal-to-approve-lido-dao-treasury-management-principles-and-authorize-the-formation-of-a-treasury-management-committee/4279/1):
>
> **Committee’s ultimate objective is to automate itself**
> 
> 1. The **Committee** is charged, in the long-term, with identifying and implementing ways of automating its deliberations and replacing the function of the **Committee** with permissionless smart contracts with no dependencies, capable of replacing the above workflow in a neutral manner

More research is needed on this matter, but will likely form the basis of a a new TMC resolution in due time.

---

<div class="post-metadata">

### Author: ![marcbcs](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/marcbcs/32/2659_2.png) [@marcbcs](https://research.lido.fi/u/marcbcs)
#### Post date: [March 15, 2024, 12:10pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/3 "2024-03-15T12:10:36Z")

</div>

Keen to see Stonks working soon.

It may be obvious but to be extra clear, this post should be read in conjunction with [TMC-2](https://research.lido.fi/t/tmc-2-research-and-implement-permissionless-stonks-execution/6861).

@Alex_L when do you expect to start the Aragon vote?

---

<div class="post-metadata">

### Author: ![zuzu\_eeka](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/zuzu_eeka/32/1157_2.png) [@zuzu\_eeka](https://research.lido.fi/u/zuzu_eeka)
#### Post date: [March 16, 2024, 12:36pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/4 "2024-03-16T12:36:43Z")

</div>

Hi @marcbcs!  
The on-chain vote is planned to start on March 19 at 14:00 UTC with the regular 48 hours for the main phase and 24 hours for the objection phase.  
Keep your keys ready to cast a vote! 😀

---

<div class="post-metadata">

### Author: ![zuzu\_eeka](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/zuzu_eeka/32/1157_2.png) [@zuzu\_eeka](https://research.lido.fi/u/zuzu_eeka)
#### Post date: [March 19, 2024, 5:19pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/5 "2024-03-19T17:19:02Z")

</div>

Voting has officially begun!  
[https://vote.lido.fi/vote/173](https://vote.lido.fi/vote/173)

The main phase will end on Mar 21, 2024 at 17:12 UTC.  
Make your voice heard and cast your vote!

---

<div class="post-metadata">

### Author: ![kadmil](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/kadmil/32/1958_2.png) [@kadmil](https://research.lido.fi/u/kadmil)
#### Post date: [March 19, 2024, 5:28pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/6 "2024-03-19T17:28:17Z")

</div>

The solution audit report can be found here: [GitHub - lidofinance/audits](https://github.com/lidofinance/audits?tab=readme-ov-file#03-2024-ackee-blockchain-lido-stonks-audit)

---

<div class="post-metadata">

### Author: ![zuzu\_eeka](https://dub1.discourse-cdn.com/flex013/user_avatar/research.lido.fi/zuzu_eeka/32/1157_2.png) [@zuzu\_eeka](https://research.lido.fi/u/zuzu_eeka)
#### Post date: [March 22, 2024, 6:04pm UTC](https://research.lido.fi/t/lido-stonks-treasury-swaps-via-optimistic-governance/6860/7 "2024-03-22T18:04:34Z")

</div>

The on-chain vote was successfully enacted! Easy Track Factories to transfer tokens from Treasury for swaps were added to Easy Track registry!  
[https://vote.lido.fi/vote/173](https://vote.lido.fi/vote/173)  
Thank you for you participation! ❤
