Author: @charlesndalton, contributor at Yearn Finance
Contributor to Yearn Finance and member of the Yearn strategy team. At charlesndalton on GitHub and Twitter.
- Milkman HackMD
- Forum isn’t allowing more than two links, but both the milkman repo and the milkman-bot repo are pinned on my GitHub
Developer tools (SDK)
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).
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:
- 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. For this, we need (1) an audit of the core contract, (2) a good set of ‘price checkers’, peripheral contracts needed for reducing trust in solvers and Flashbots, and (3) a complete testing suite, which tests all edge cases and many types of tokens. If approved, this grant would fund these three areas.
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.
- Completed Milkman contract, which allows users to 1. request swaps and 2. cancel swaps that haven’t been picked up
- Audit by yAcademy
- Completed price checkers
- UniV2, which includes Uniswap V2 and Sushiswap
- Uniswap V3
- 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, such as a contract that allows off-chain services to query for the state of swaps
- Off-chain bot, written in Rust, that pairs orders against Milkman swap requests and handles other scenarios (e.g., order doesn’t go through first try)
- Documentation and code examples that help developers submit orders through Milkman
- Documentation for keepers to run the bot
For all of the above, this includes unit and integration testing.
The biggest dependency in the timeline is getting the audit. Assuming that yAcademy can complete the audit by the end of September, all of the above milestones should be completed by mid-October.
$45,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 (maybe @nlordell?).
- $16k (33% of total): quoted cost of 7-day-long yAcademy audit
- $32k (66% of total): development / labor cost
Any cost overruns of the audit would be paid out of the development cost, so it’s a $45k flat fee w/ no strings attached.
Gnosis Chain Address (to receive the grant):
If okay, I’d prefer not putting this on a public forum, but would be happy to share with any members of the CoW team
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
Terms and conditions:
By applying for this grant, I agree to be bound by the CowDAO Participation Agreement and the COWDAO Grant Terms and Conditions.
Many thanks for reviewing this proposal .