HomeKnowledge BaseWhat is Milkman? CoW Swap’s Solution for Delayed Execution Trading

What is Milkman? CoW Swap’s Solution for Delayed Execution Trading

4 min read

On CoW Protocol, rather than sending on-chain transactions with predefined swap instructions, users submit signed intent-to-trade messages. These messages contain some order details, like which assets to trade in which amounts, but leave other details to be optimized by solvers.

One important parameter of these intents is min_out — the minimum amount of buy tokens a user is willing to receive for their sell tokens (or the buy amount, minus the maximum allowable slippage set by the user). Min_out works really well when a trade is intended for immediate or near-immediate execution, because it allows solvers to improve prices for users while protecting them from unfavorable price movements. However, when prices fluctuate a lot, min_out can be overly-restricting.

What is delayed execution trading?

Simply put, delayed execution trades are trades intended to execute at some point far in the near future.

Many smart contract wallet users, such as DAOs, frequently need to create these types of orders. Take the following examples:

  • DAOs that need trades to execute after passing a governance process
  • Groups that need hours to collect signatures to execute trades from a multisig wallet
  • Applications that process automated swaps years in the future (e.g. for payroll or treasury management)

With extra time, prices can fluctuate wildly — and this creates a dilemma for traders:

If the buy token price falls and the min_out is too high, the order might not execute. But if the min_out is too low, the trader risks getting an unnecessarily poor execution price. (CoW Protocol solvers compete against each other to give users better prices, but placing such a high level of trust in solvers can be undesirable for very high-volume traders.)

1-what-is-milkman.webp

If a user signs an intent to swap 1 ETH for a “min out” of 2000 USDC, there is no way for the trade to return any less than 2000 USDC

2-what-is-milkman.webp

But setting a low “min out” risks leaving money on the table

What is Milkman?

Milkman is a smart contract that solves the above dilemma for smart contract wallets.

It does this by allowing smart contracts to specify an on-chain data source (such as an oracle) to use as a reference for min_out — effectively turning min_out into a dynamic price backstop for their trade.

Let’s say you want to sell 1000 ETH for USDC, but you want to do it far in the future. To protect yourself from volatile price movements, you can supply Milkman to create the order based on with the Chainlink price feed for ETH/USDC, and Milkman at the time of order placement will dynamically adjust the minimum amount you’ll receive based on that price feed.

When the time comes to execute your trade, CoW Protocol will receive it with a min_out that accurately reflects prices at that point in time; and solvers will compete to improve the price on top of that, as they always do.

3-what-is-milkman.webp

Milkman for DAOs

Milkman is particularly well-suited to many DAO-related use cases, because DAO governance processes often delay trades and because amounts traded by DAOs can be very large.

Several well-known DAOs, including Aave and ENS, have already used Milkman to trade over $20M worth of tokens. Beyond allowing these DAOs to count on reliable prices, Milkman lets them reduce their overall number of governance votes and gives them standard CoW Swap benefits like best price execution and best-in-class MEV protection — critical for large trades.

Milkman is also natively integrated as a recipe on Tally, the widely-used DAO management platform — removing even more trading friction for DAOs.

Technical details

Milkman follows a UniV2-style interface. To interact with Milkman, smart contracts need only to call the following function:

function requestSwapExactTokensForTokens(

uint256 amountIn,

IERC20 fromToken,

IERC20 toToken,

address to,

address priceChecker,

bytes calldata priceCheckerData

)

The priceChecker is the data feed provider, and priceCheckerData is an array of arbitrary bytes that the function passes to the price checker (e.g. the desired slippage tolerance).

Price checkers have been deployed for Chainlink, Curve, SushiSwap, Uniswap V2, Uniswap V3, and combinations of these. The core Milkman code can be found here. Anyone can run a Milkman bot, which simply functions as a hook that watches for new swap requests and surfaces them to CoW Protocol. Running a bot is fairly easy if you have a Kubernetes cluster; the instructions are in the repo.

Milkman was developed by Yearn Finance in partnership with CoW Protocol, through the CoW Grants Program.

Long live Milkman! And may you benefit from his commitment to bringing you favorable prices!

4-what-is-milkman.webp