All writing

Curve or Book: The Ordering Rule Decides, Not the Asset Class

· 14 min read

  • architecture
  • market-structure
  • evm
  • defi

Curve or Book: The Ordering Rule Decides, Not the Asset Class

The pricing on the venue whose contract layer I took over was already a constant function curve, and I ran it and watched the fills before I replaced it with an onchain order book. What decided the replacement was how often the price moved while nothing traded, and volume never came into it.

The usual way to settle it is to sort by asset: long tail and illiquid to a curve, deep and institutional to a book. That is a summary of where the two primitives ended up, and a summary is not a reason. Price both sides in one unit and the property the asset class stands in for cancels out of the comparison. Where it comes back, it comes back through your venue and never through the asset.

This piece was written from published sources anybody can open, from one measurement of my own, and from one simulation whose script sits beside it as proof/artifact/crossing.py. No venue was instrumented for it, and no order book but mine is measured anywhere in it.

A curve is a maker who never changes his mind first

A constant function curve prices from its own reserves, so nobody who has seen the price move somewhere else can move that price to meet it without handing the pool the difference. The pair contract exposes a function anybody may call that forces its reserves to match its balances, so somebody who transfers a token to it can move the quote with no trade. the Uniswap pair contract That is the arbitrageur's job rather than the maker's: he buys the price move at full size and hands the pool the proceeds. The paper that prices that loss puts it the same way in its own hedged words, saying such a venue can be thought of as a quoting market maker who never proactively updates its price quotes. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing

An order book is the primitive in which withdrawing a quote is one operation on one message, and withdrawing it cost whatever a transaction costs on that venue. Somebody decides to pay, every time he changes his mind.

A concentrated provider can remove a resting position from the live range in a transaction of his own, with nobody trading against it, and mint another somewhere else. the Uniswap pool contract That is a cancel and a repost, on a curve, paid for in gas: the maker's bill arriving on the curve's machinery, and the inequality below prices it the way it prices a book.

Volume tells you whether a venue is alive, not which primitive to use. What separates them is who pays for a price that has moved and not yet traded. On the curve an arbitrageur takes it, buying the stale quote and selling into the market that already moved, and the difference comes out of the reserves' suppliers. On the book the maker pays it: he withdraws his quote before somebody else can take it, and pays for that whether or not anybody would have.

Both also pay something once a trade happens, which is a different comparison. Nothing here prices what happens after the trade: the gas both primitives pay to execute one, which is not the same size on both, and what a maker carries between his fill and the moment settlement clears.

The curve in its strongest form, and why concentration does not move it

The strongest live version of the curve is the concentrated one. The defining idea of Uniswap v3 is concentrated liquidity, where a provider binds his capital inside a price range he chooses instead of spreading it across every price from zero upward. the Uniswap whitepaper for concentrated liquidity A small team can run a venue on it and nobody carries a pager, which is why competent teams keep choosing it.

The next argument for concentration is that it makes the curve cheaper to be, and it does not. The paper works the concentrated pool as its own example against the full range one and reports that at the same marginal liquidity the concentrated pool's instantaneous loss is the same one the full range pool carries, and only the pool's value is lower. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing

Push the range tight enough and the loss per dollar of pool reserves grows without bound as the range is made narrow enough, which the same example says. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing Concentration lowers the capital a provider locks up to quote a given depth, not what quoting it loses.

A constant function curve quotes with nobody watching, needs no keeper, no matching engine and no relationship with any maker, and concentrating it changes the capital it ties up rather than what quoting a given depth loses.

Both sides in the same unit

Write the curve's cost first. The general form in that paper puts a pool's loss per unit of time at half the pair's variance times the pool's marginal liquidity, which is the quote currency a trade must move to shift the price by one part in one. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing Marginal liquidity also fixes the depth: the size executable inside a price move of one half spread is that same quantity times the half spread, which lets the loss be written against depth rather than capital.

Now write the book's. A maker quoting a half spread has to move his quote once the price has moved past it, or he is trading at yesterday's price on purpose. For a logarithm wandering with a given variance per unit of time, the expected time to leave a band is its half width squared over that variance, so his requotes per unit of time are the variance over the square of his half spread, and each one costs him one quote update. Both bills in one unit, and everything is a rate per year.

                        curve                book
 
  cost per year         s2 M / 2             c s2 / d2
 
    M   the pool's marginal liquidity, in quote currency
    Q   the size executable inside a price move of d,   Q = d M
    c   what one quote update costs on the venue
    d   the maker's half spread, as a fraction of price
    s2  the variance of the pair's price per year
 
  substitute M = Q / d
 
                        s2 Q / 2 d           c s2 / d2
 
  the book is cheaper when    c s2 / d2   <   s2 Q / 2 d
  s2 divides out of both sides
                              c / d       <   Q / 2
                              Q           >   2 c / d

Volatility divides out. It sits on both sides because it drives both: it is what makes the curve's quote stale and what forces the maker to move his. Price both sides in the same unit and volatility cancels wherever the maker chooses his own half spread, leaving one inequality: the book is cheaper than the curve once the size executable inside that spread exceeds twice the cost of one quote update divided by it. The asset class is a proxy for volatility and for nothing else that appears in that inequality, so the asset class decides nothing here. What is left is the cost of one quote update and the spread the maker quotes, neither a property of the asset.

Put numbers on it, with two inputs you should replace with your own. The floor under one requote on an Ethereum style chain is a transaction that reads one storage slot and rewrites it: 21,000 gas for the transaction itself and 5,000 to read and rewrite one storage slot that already holds a value, which is 26,000 gas before the book does anything a real book does. the Ethereum execution specification Two things move that floor and both move it down: a cancel that clears the slot instead of rewriting it gets 4,800 of that back, and a book that withdraws many quotes in one transaction pays the 21,000 once, so its cost falls toward 5,000 gas a quote. At a gas price of 20 gwei that is 0.00052 ether. Against a half spread of ten basis points the crossing sits at about one ether of size executable inside the spread, and every correction above moves it down rather than up.

The obvious attack is that the cancellation is bought with an asymmetry: the curve's cost comes from a model in which the arbitrageur pays nothing to trade, while the book's cost has the maker's gas in it. Give him a bill of his own and the two sides stop matching. The paper anticipates the objection and answers it the same way: its authors say a friction on the arbitrageur lowers what he keeps and moves some of what is left to whoever orders the block. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing Charge the arbitrageur for every trade he makes, on a simulated path, and his trades fell from 539,881 to 1,189 while the pool's loss moved by three parts in a thousand. The loss is his gross profit, and how much of the price a pool quotes badly over a year does not depend on how often it is collected.

The crossing itself was checked rather than asserted. On simulated paths the crossing held between 0.92 and 0.97 of the closed form at every volatility from 0.30 to 4.80. The residual tracks the simulator's own undercount of band exits row for row, and resolving the band eightfold finer at a fixed horizon moves that undercount from 0.89 to 0.96, which is what a discretisation bias does and what a moving crossing would not.

That result should make you suspicious, because onchain order books did not take Ethereum mainnet and curves did. The repricing term does not explain that and is not meant to: what kept books off mainnet is what a fill costs there, which is the term this piece leaves alone. What the repricing term explains is a dependance on something the maker does not control, and it is why the books that do exist sit on venues that sequence their own transactions.

A cancel only defends a quote if it can be sequenced ahead of the take it is defending against. Where the order of transactions inside a block is sold to whoever bids most, the arbitrageur and the maker who have both just seen the price move bid for the same position, for the same quantity, and the arbitrageur already knows how the auction pays off. His requote does not lose because it is slow. It loses because the sequence is chosen by somebody with no reason to prefer it. On Ethereum that window is one slot, twelve seconds by the network's own configuration, and over one slot at a volatility of sixty percent a year, another input you should replace with your own, the price moves about 3.7 basis points. the Ethereum consensus specification

A maker who cannot get a cancel sequenced ahead of a take inside that window is not quoting the spread he chose. He is quoting a floor the chain chose for him, and that floor is the move above: he cannot hold anything tighter, because inside one slot the chain holds his quote open. And here volatility comes back. It cancelled out of the inequality because the maker chose the spread the inequality was measured against. Where the chain chooses the tightest spread he can hold, that number is a volatility number, so the venue's whole quoting range moves with volatility even though the crossing does not. It is still not the asset class deciding anything. The same asset on a venue that sequences its own transactions can be quoted as tight as its maker likes, and on a fee auction cannot be quoted inside the move over one block. So the two axes are not parallel: the second sets the tightest value the first may divide by. An exchange running its own sequencer owns it, and so does one that matches off chain and settles on chain. An exchange posting into an open fee auction does not.

Settle the repricing comparison on your venue's ordering rule first, because it decides whether volatility cancels out of the comparison or sets the maker's spread for him.

What the book costs, and what my own number is not

Choosing the book moves the cost of a moved price from the liquidity provider, who never chose to pay it, onto a maker who now pays for every change of mind, and onto a venue that has to keep a matching path alive for any quote to mean anything at all.

  • the maker pays for every quote he withdraws, where the curve charged him nothing for being wrong
  • the taker pays it back as spread, because a maker who cannot recover it stops quoting
  • the venue pays for a matching path that has to stay alive, because a book whose matcher is down has no price at all
  • the engineer who inherits the venue pays the maker relationship, because the book stops the day the last one leaves

That last row is not decoration. The venue I built ran with a small maker set, single digits, and every choice on the quote path was priced against whether it would keep them.

I measured the order book's own settlement path at 142,000 gas per trade before one redesign of its data structures and 28,000 after, the same book against an earlier version of itself, token transfer gas excluded. That number is here for one reason, and it is no term in the comparison above, which prices nothing that happens after a trade. It is not the curve compared to the book, and I do not present it that way. The reason is that what it costs to touch a book's storage is a design variable rather than a constant of the chain, and one design of the same book sat a factor of five above another on the same path.

There is a cost that decision imposed and it is mine to name. A taker pays for every level it consumes, and rebalancing makes the per trade cost a distribution rather than a constant. The figure above is that distribution's level. A taker who sweeps several levels pays more, no figure for the tail was ever recorded, and I will not produce one now.

The condition that reverses it

The inequality assumes somebody is standing outside your venue with a better price. The curve's loss is what an arbitrageur takes, and the model that prices it assumes an infinitely deep exchange outside the venue where the risky asset can be traded. Milionis, Moallemi, Roughgarden and Zhang on loss versus rebalancing Where that exchange does not exist, nobody takes the stale quote, the curve's side of the comparison collapses toward nothing, and the inequality confidently returns the wrong primitive. A token whose only venue is yours is the case: its price moves as much as anything else, which is the reading the sorting rule would take as arguing for a book, and no arbitrageur exists to make a curve pay for standing still.

The second blind spot is plainer. Both axes price a quote update, and neither reads whether anybody will make one. The recommendation reverses on either of two conditions the arithmetic cannot see: no venue outside yours prices the pair, or nobody will quote your book.

This section does not price either case. There is no closed form for what a curve loses with no reference market, and no number at all for a maker who has not agreed to be one, so naming the conditions and stopping beats putting a shape on them.

Where this stops applying to you

Three conditions of your own system end this. If trades on your pair outnumber the moves in its price, what a fill costs dominates what a requote costs and a different comparison decides. If no market outside yours prices the pair, the arithmetic returns the wrong primitive. And if your venue chooses none of its own transaction order while no maker will take the floor that imposes, the book has no quote to defend.


Abdel KIARI

I’ve owned the EVM side of a DeFi protocol. I redesigned its architecture from scratch and built the Solidity infrastructure end to end.

Always happy to talk about interesting opportunities

abdel.kiari@gmail.com