Notes

The road to the auction table

How a solver for CoW Protocol comes to life, from reading the rules to practising on real auctions. For people who have never heard the word solver.

Orders gathering into batches over time Small marks, each an order, arrive at uneven times and curve together into a single point. Along a time line this happens again and again, one batch every few seconds. The newest batch is still filling and waits behind a dashed ring. auction auction next one a few seconds
The waiting room Orders drift in at their own pace. Every few seconds the room empties into one batch: the auction.

When someone swaps one token for another on CoW Protocol, the order doesn’t go straight to a market. It waits, briefly, with other orders that arrived around the same time. Then the protocol holds an auction for the whole group, and a small number of independent programs compete to settle it. Those programs are called solvers. This is the story of building one.

Learning the game

auction snapshot taken just now

orders , each with a worst price

  • sell a little A for B
  • sell a lot of C for A
  • buy some B with C

pools

  • A and B deep
  • A and C shallow
  • B and C deep
deadline
a few seconds
plans scored best plan wins
One auction, as a solver sees it Who wants what, where it could trade, and how long there is to answer. The best plan wins.

Each auction is a puzzle with a deadline. It lists the orders, who wants to sell what and the worst price each person will accept, and the places where trades can happen. A solver has a few seconds to answer with a plan. The protocol scores every plan by how much better off it leaves the people trading, and the best one wins the right to carry it out.

We started by reading and observing. The rules, the scoring, the long public record of auctions that had already happened and the plans that won them. Before writing anything clever, our first solver did something modest: it answered with a sensible reference plan, so we could watch the whole loop work end to end and learn what the auctions actually look like when they arrive.

Learning the terrain

How the price of a pool slides as you sell more into it A curve starts at the quoted price and bends downward as the amount sold grows. A small trade sits near the start, almost at the quoted price. A large trade sits far down the curve, and the shaded area between the quoted price and the curve shows what the extra size gives up. price for the next unit how much you sell quoted price what size gives up a little almost the quote a lot slides down the curve
Draining the pot Each extra unit fetches a bit less. The shaded part is what size gives up.

Most trading here happens against pools: shared pots of two tokens that anyone can swap with. A pool’s price moves as you trade against it. A small trade gets close to the quoted price. A large one slides down the curve, each extra unit fetching a little less.

That single fact turns out to shape almost everything. A good plan isn’t just about finding the best price. It’s about finding a plan that still looks good once the trade is as big as it really is, and finding it within the time it takes to blink a few times. Teaching our solver to do that was the first real piece of engineering, and it’s still the part we keep returning to.

The practice field

CoW runs a shadow competition. Solvers that aren’t trusted with real orders yet receive the same auctions, answer them, and get scored, but nothing they propose is ever carried out. Think of it as a flight simulator for this one very particular job.

Ideas replayed against past auctions, with few surviving Many ideas enter from the left and pass through a narrowing sieve made of past auctions. Most stop short and fade. One comes out on the right and joins the solver. past auctions ideas lost quietly into the solver
The laboratory Ideas are replayed on past auctions. Most lose quietly; a few go into the solver.

That’s where our solver lives today. It answers whatever it’s sent, day and night, and we keep a record of every auction and every answer. The record became our laboratory. When we have an idea, we replay it against auctions that already happened and compare our plan with the one that actually won. Most ideas lose there. The few that survive go into the solver, and the next day’s auctions tell us whether they really help.

Getting ready for the real thing

A price drifting while a plan waits to be carried out A time line runs from the moment a plan is checked, to when it is chosen, to when it is carried out. The price seen at the start is a flat line with a shaded band around it, the room left for the world to change. One drifting price stays inside the band and goes through with a check mark. Another leaves the band and fails. price we saw room for the world to change checked chosen carried out outside the room: fails goes through
Nothing waits Prices keep moving until the trade is carried out. A plan with room to spare goes through.

Practising is one thing; being trusted with real orders is another. A plan that wins on paper has to survive the seconds between being chosen and being carried out, while prices keep moving. Every answer is checked before it leaves, so that nobody in a plan ends up worse off than they would have trading on their own.

Around the solver we built the quieter machinery that lets a very small team run it: new versions go live on their own and step back if something looks wrong, and the system watches itself and speaks up when it needs attention.

What comes next

The next stage is the real competition, where plans are carried out and the solver starts to earn its keep. Much more interesting stuff starts to happen in the wilderness of real markets and trades.

A path from reading the rules to the real competition A winding path with four stops: reading, building, practising and competing. The first two are behind us. A flag marked “we are here” stands at practising. The road on to competing is still dashed. we are here reading building practising competing
The road so far Reading, building, practising, competing. We are on the practice field.

All notes