# Grant Application: Composable Conditional Orders

**URL:** <https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451>\
**Category:** Funded Grants\
**Tags:** complete, grant-funded\
**Created:** [February 10, 2023, 5:31pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451 "2023-02-10T17:31:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [February 10, 2023, 5:31pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/1 "2023-02-10T17:31:02Z")

</div>

# Safe Composable Conditional Orders

**Grant Title** : Safe Composable Conditional Orders

**Author** :

- GitHub: [mfw78 (mfw78) · GitHub](https://github.com/mfw78) (see also [rndlabs · GitHub](https://github.com/rndlabs)).
- Gitcoin: [https://gitcoin.co/mfw78](https://gitcoin.co/mfw78)
- Mirror: [https://mirror.xyz/mfw78.eth](https://mirror.xyz/mfw78.eth)

**About You** :

- Experience in technical systems analysis, design and implementation with a strong emphasis on risk management / gap analysis.
- Experienced technical writer in mission-critical, highly regulated, and technical industries.
- Actively independently developing with emerging decentralised technologies, including Swarm and Waku.

**Additional Links** :

- safe-cow: [GitHub - rndlabs/safe-cow: Gasless EIP-1271 token swaps on Cowswap](https://github.com/rndlabs/safe-cow) - implementing EIP-1271 signature aggregation for _Safe_ trading via Cowswap API.
- cowswap-twap-orders: [GitHub - rndlabs/cowswap-twap-orders: 🐄🐮 Time-weighted average price orders for CoW Protocol](https://github.com/rndlabs/cowswap-twap-orders) - implementing TWAP orders for _Safe_ trading via Cowswap API.

**Grant category** : Protocol Order Flow / Developer Tools

**Grant Description** :

_Problem_: With the limitless options available for EIP-1271 orders, there becomes a need to develop a standard by which orders can inherit from, such as to reduce the number of contract deployments required, increase gas efficiency and smooth the UX.

For example, the recent [Cowswap TWAP Orders](https://github.com/rndlabs/cowswap-twap-orders) while providing an innovative method for storing only a signature of the TWAP and therefore providing gas efficiency, this method requires a new Fallback handler for each type of conditional order.

_Solution_: Implement a “Conditional Order Router” Fallback handler, with Conditional Orders being summarised in a merkle tree, whose root is signed by the Safe to assert truthfulness. This method would allow limitless simultaneous conditional orders meeting innumerable use cases.

**Grant Goals and impact**

- Increase CoW protocol utility through composable DeFi-market unique order types.
- Reduce UX friction for multiple conditional order types.

**Milestones** :

1. Implement a `MerkleConditionalOrderFallbackHandler` contract that provides stock Safe functionality, while allowing authorisation of limitless types of conditional orders.
2. Update TWAP orders:  
a. Add support for new Merkle Tree storage.  
b. Add support for Milkman price checkers.
3. Adapt `PerpetualStableSwap` and `TradeAboveThreshold` for Merkle Tree storage (implementation of these conditional order types out of scope for audit).
4. Revise the Tenderly Web3 Action to support composable conditional orders.
5. Revise the `CLI` tool to allow creation of composable conditional orders (eg. create TWAP **and** `TradeAboveThreshold`).

**Grant Timeline** :

Phase 1: 4 weeks FTE.

_Note 1: Full-Time Equivalent (FTE) corresponds to 40 hrs / week_  
_Note 2: The above timelines do not make for allowances / timing associated with audit completion._

**Funding Request** :

Phase 1: $10,000.

_Payment terms:_ Half paid up-front at the commencement of each phase with the remainder paid upon satisfactory completion of code as determined by the member(s) of the CoW team.

**Budget Breakdown** :

- $10k: development / labor cost

This budget does _not_ include any costs associated with audit by a 3rd party. It is expected that CoW would undertake the necessary steps / cost for audit. Any cost overruns associated with meeting the standards of an external audit (additional testing / code fixes) would be paid out of the development cost.

**Gnosis Chain Address (to receive the grant)**:

0x070E0a700E36D303a0Ce3fe37976dD70974D7883

**Other Information** : As an active member of the CowDAO Grants Committee, I hereby refrain from voting / signing on this proposal so as to eliminate conflicts of interest. In determining the timelines associated with this Grant, I have taken into consideration workloads due to my position as a Committee member, 3rd party work, and allowed appropriate buffer to ensure the Grant Committee’s continuance.

**Referral** : N/A

**Terms and conditions** :

By applying for this grant, I agree to be bound by the [CowDAO Participation Agreement](https://cloudflare-ipfs.com/ipfs/Qmf9MYhcG2pFrDoVy13p6FWeVF4nG9HbJvRfYYbhazTCFe) and the [COWDAO Grant Terms and Conditions](https://cloudflare-ipfs.com/ipfs/QmePuufRisDpGrnaPYJo7By6sFRaGhWcoP7zQhS5FiJaT7)

---

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [February 10, 2023, 5:37pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/2 "2023-02-10T17:37:19Z")

</div>

To elaborate on the above Grant Application, Composable Conditional Orders would allow for example the following conditional orders to be implemented - simultaneously:

1. Alice is an OG developer in crypto and maintains a 1 year runway of costs in USDC.
2. If Alice has anymore USDC than the 1 year runway requirements, she wants to sell this and hold ETH as a reserve currency.
3. Alice receives payments in numerous different types of tokens, and sells these in batches to USDC.

Using Composable Conditional Orders, Alice would be able to:

1. TWAP automatically sell tokens to USDC.
2. If USDC balance exceeds 1 year runway, use the residual to buy ETH.

The primary advantage of composable conditional orders allow for many other conditional orders to be specified, with a relatively fixed gas cost.

---

<div class="post-metadata">

**Author:** ![netrunner.eth](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/netrunner.eth/32/252_2.png) [@netrunner.eth](https://forum.cow.fi/u/netrunner.eth)\
**Post date:** [February 12, 2023, 10:24pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/3 "2023-02-12T22:24:10Z")

</div>

I support this application as it will allow for unlimited conditional orders and improved DeFi composibility.

---

<div class="post-metadata">

**Author:** ![middleway.eth](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/middleway.eth/32/12_2.png) [@middleway.eth](https://forum.cow.fi/u/middleway.eth)\
**Post date:** [February 13, 2023, 2:38pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/4 "2023-02-13T14:38:31Z")

</div>

I’m in support of funding this proposal.  
@mfw78 has implemented the TWAP/DCA smart orders which have passed an audit and is now available for use as a gas-efficient alternative to the milkman implementation.  
His demonstrated experience and familiarity with CoW Protocol’s smart order is giving additional confidence in good execution of this proposal.

An efficient way to deploy composable conditional smart orders will open many use cases for DAOs and teams that want to deploy trustless onchain trading strategies.

---

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [February 17, 2023, 5:04pm UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/5 "2023-02-17T17:04:51Z")

</div>

Based on the signalling and feedback here, this Grant Application has been moved to [snapshot](https://snapshot.org/#/cowgrants.eth/proposal/0xb7815ca1f5aea2ec537295fd452332680eb1be379f3356950dc8ba151d83f9c5) voting by the committee.

---

<div class="post-metadata">

**Author:** ![Chim9](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/chim9/32/417_2.png) [@Chim9](https://forum.cow.fi/u/Chim9)\
**Post date:** [February 20, 2023, 11:34am UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/6 "2023-02-20T11:34:56Z")

</div>

Voted in favour of the Grant on Snapshot based on the past successful work of Mfw78, and I’m excited to see these new use possibilities for CoW Protocol once the developpement will be done and they are deployed.

---

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [May 10, 2023, 7:22am UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/7 "2023-05-10T07:22:46Z")

</div>

First of all, apologies for the significant gap in communication on this grant (well, public release of such communication).

Currently, this grant was somewhat split into two “phases”:

1. `ExtensibleFallbackHandler` - a new `Safe` fallback handler that allows for increased composability with `Safe`. See: [Grant Application: Extensible Fallback Handler for Safe (Retrospective)](https://forum.cow.fi/t/grant-application-extensible-fallback-handler-for-safe-retrospective/1676).
2. `ComposableCoW` - providing a unified, composable conditional order framework, allowing users to specify either a single order, or a multitude of orders using a merkle root and associated proof.

Both of the above phases are feature complete, with the code for both currently undergoing audit.

---

<div class="post-metadata">

**Author:** ![mfw78](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.cow.fi/mfw78/32/1598_2.png) [@mfw78](https://forum.cow.fi/u/mfw78)\
**Post date:** [February 24, 2025, 9:11am UTC](https://forum.cow.fi/t/grant-application-composable-conditional-orders/1451/8 "2025-02-24T09:11:10Z")

</div>

Closed on February 24, 2025, 9:11am UTC


