# CoW GRANT 2 The following document is intended to structure the [grant proposal submitted](https://forum.cow.fi/t/grant-proposal-milkman/1129) by [@charlesndalton](https://forum.cow.fi/u/charlesndalton/summary) in the CoW DAO forum. @charlesndalton is a contributor to Yearn Finance and member of the Yearn strategy team, and can be found on [GitHub](https://github.com/charlesndalton/) and [Twitter](https://twitter.com/charlesndalton). # Grant Proposal **About the grantee** Contributor to Yearn Finance and member of the Yearn strategy team. At charlesndalton on GitHub and Twitter. **Grant Category** Developer tools (SDK) **Proposal** This is a proposal to fund a smart contract system which would allow smart contracts to route their order flow through the CoW Protocol. The deliverable of the grant would be a Developer tools (SDK) with a set of smart contracts to allow DAOs, gnosis safes, and other contracts to easily route their order flow through CoW Protocol. The solution is called Milkman, and a layer that sits on top of CoW protocol. Milkman is a production-grade smart contract system that can be utilized by DAOs to securely route their order flow through CoW protocol. You can find more information about the design of such a system here. In order to be able to build such product, the following aspects are needed: (1) an audit of the core contract, (2) a good set of ‘price checkers’, peripheral contracts needed for reducing trust in solvers and Flashbots, (3) a complete testing suite, which tests all edge cases and many types of tokens. If approved, this grant would fund these three areas. **Grant Goals and impact** The goal is to build a system that allows DAOs, gnosis safes, and other contracts to easily route their order flow through CoW Protocol. Again, the problem that Milkman solves isn’t theoretical: it’s one that we encountered. You can imagine that Milkman will open up use-cases which weren’t previously possible. For example, you can imagine borrow/lend platforms using CoW to sell their collateral instead of either (1) slow collateral auctions or (2) first-come-first-serve liquidations, where a large chunk of value is extracted away from users in the form of MEV. More concretely, Felix mentioned in TG that Nouns DAO had expressed interest in using Milkman for DAO-authored swaps. # Grant Description **Summary** This is a proposal to fund a smart contract system which would allow smart contracts to route their order flow through the CoW Protocol. **Problem being solved** At Yearn, we need to do a lot of token swaps. An increasing number of those token swaps are being routed through the CoW Protocol. However, we have encountered a frequent issue when swapping through a Gnosis Safe. Although it is technically possible for smart contracts to sign order UIDs via the setPresignature function on the settlement contract, these UIDs still need to be generated off-chain. At first, we would first generate the order UIDs via the API and then pass them into multisig requests, but often the request’s minOut would go out of range by the time the multisig transaction was executed (e.g., because the price of the token we’re selling went down), meaning that we would need to repeat this process (generate another request, and submit another multisig transaction). **Milkman** Obviously, this is non-optimal. As a result, we’ve had a few discussions with the CoW team over what the best solution is. We needed something that provided the following properties: Easy-to-use Trustless: - Doesn’t add any new trust assumptions (e.g., trusted keeper) - Doesn’t weaken any existing trust assumptions (e.g., setting minOut to 0, which places more trust in solvers and Flashbots RPC) The solution is called Milkman, and it sits as a layer on top of CoW protocol. A technical description of the design & implementation is in the HackMD and codebase. I’ve been working on Milkman since July, and have high conviction that it would be a useful public good for the CoW ecosystem. Some testing and QA has been done (you can check out 0x9d763Cca6A8551283478CeC44071d72Ec3FD58Cb and 0x2aa7ff04460cddc61a2b466c9a2924603863a030 for some iterations that we tested with production Yearn swaps), but I would like to see Milkman as a production-grade smart contract system that can be utilized by DAOs to securely route their order flow through CoW protocol. # Funding request After some discussions, it has been agreed that in order to build such tool, the total grant amount awarded will be the following: $20,000, half paid up-front and half paid once the code and testing is up to the standards of member(s) of the CoW team (@fedgiac & @nlordell) + the cost of the audit*. * The audit is intended to be carried out by G0 (affiliated with Gnosis DAO). In the case that Gnosis DAO cannot deliver the code audit, the amount in the section above will change and include an additional $16K expense, totaling the grant at $36K. The standards by which the CoW Protocol assigned team members will review the code will be: * Modular code that is documented and designed for readability and maintainability (in line with the code that has been shared so far) * Documentation in github (or some other appropriate tool) with guidelines for usage, testing, contribution & overall design of the system. * Test suite for the smart contracts as well as for the SDK around it (typescript components etc). # Budget breakdown The budget for the grant would be broken down into the following: * $20k (100% of total): development / labor cost * Audit to be performed by Gnosis Security team * Fallback: $16k: quoted cost of 7-day-long yAcademy audit # Timeline The estimated timeline for this grant to be delivered is the following: ![](https://i.imgur.com/xmQCMgw.png) *Note that this timeline is a rough estimate by which the grantee will follow through, but it may be subject to changes. The Timeline is broken down in the following way: * Week of Sep 26 → During this week, the grantee and grants committee will discuss the contents of this document to iron out the final details to be included in the agreement. * Week of Oct 3 → During this week, the CoW Grants DAO will provide the first installment of 50% of the grant. The grantee will start the development of the set of contracts, working on Contract developments, Price checkers and use of Peripherals. * Week of Oct 10 → During this week, the grantee will continue with the development of the set of contracts, working on Contract developments, Price checkers and use of Peripherals. * Week of Oct 17 →During this week, the grantee will continue with the development of the set of contracts, working on Contract developments, Price checkers and use of Peripherals, as well as starting the development of the offchain bot. * Week of Oct 24 → During this week, the grantee will continue with the development of the offchain bot. The CoW Grants Committee will start reviewing the previous milestones achieved to check that they are according to the agreed standards. * Week of Oct 31 → During this week, the party in charge of auditing the contracts will begin with the work. * Week of Nov 7 → During this week, the party in charge of auditing the contracts will continue with the work. * Week of Nov 14 → Upon the completion of the audit, and that all security checks are cleared, the CoW Grants DAO will proceed to pay the outstanding amount of the grant. # Milestones Each milestone is to be completed in due time and to be reviewed by the technical team at CoW Protocol. In the event that the code needs changes, milestones and timeline will be affected. | Milestone Section | Milestone Specific Action | Performed | Date | Link | | -------- | -------- | -------- | -------- | -------- | | Contract | Allows users to request swap | -[ ] | -[ ] | -[ ] | | Contract | Allows users to cancel swaps | -[ ] | -[ ] | -[ ] | | Contract | Audit | -[ ] | -[ ] | -[ ] | | Price Checkers | Uni v2 | -[ ] | -[ ] | -[ ] | | Price Checkers | Uni v3 | -[ ] | -[ ] | -[ ] | | Price Checkers | Curve | -[ ] | -[ ] | -[ ] | | Price Checkers | Balancer | -[ ] | -[ ] | -[ ] | | Price Checkers | Where it makes sense, meta-price checkers that combine multiple lower-level price checkers (e.g., for ANGLE → DAI, ANGLE → ETH on Sushiswap and ETH → DAI on Uniswap V2) | -[ ] | -[ ] | -[ ] | | Useful peripherals | Allows off-chain services to query for the state of swaps | -[ ] | -[ ] | -[ ] | | Off-chain bot in Rust | Pairs orders against Milkman swap requests | -[ ] | -[ ] | -[ ] | | Off-chain bot in Rust | Handles other scenarios (e.g., order doesn’t go through first try) | -[ ] | -[ ] | -[ ] | | Documentation | Documentation and code examples that help developers submit orders through Milkmanext | -[ ] | -[ ] | -[ ] | | Documentation | Documentation for keepers to run the bot | -[ ] | -[ ] | -[ ] | # Gnosis Chain Address (to receive the grant): To be delivered by the grantee in an email to grants@cow.fi # Referral This project has been the culmination of discussions between myself, Nicholas Lordello, Felix Leupold, and Poolpi Tako. I’m not sure if this counts as a referral :man_shrugging: # Terms and conditions By applying for this grant, the grantees agree to be bound by the CowDAO Participation Agreement and the COWDAO Grant Terms and Conditions. # Final Grant Agreement signal Since the original application has slightly changed, this document serves as the final version of the grant description, milestones, funding and more, as well as a forum poll on https://forum.cow.fi where only the grantee, and the grants committee will be able to vote on it. The vote will serve as the final confirmation for the acceptance of the details found in this document.