Quantitative Finance · Book 11 · Market making

Market Making and High-Frequency Trading

Market Making and High-Frequency Trading · Market making

25On-Chain Trading

A large swap on a decentralised exchange moves its pool price away from the centralised exchanges. Within the same block, searchers compete to arbitrage it back, and most of what they earn is bid away to the builder that includes their bundle. In this chapter’s first-price auction, two competing searchers leave the builder 93% of an opportunity’s value, ten leave it 98%; the arbitrage itself, on a $20 million pool over a simulated week, nets its searchers $4 300 after gas. The liquidity provider on the other side of those trades, hedged on a centralised exchange, loses $26 000 to them, the loss-versus-rebalancing a formula predicts to within 10%, and keeps $313 000 of fees net of it.

25.1 Exchange-to-chain arbitrage

A constant-product pool (One Quant Book 3, chapter 20) quotes a price that moves only when someone trades with it. When the centralised exchanges move, the pool is stale until an arbitrageur trades it back: the CEX–DEX arbitrage of One Quant Book 3, chapter 22. The optimal trade has a closed form. For a pool of xx tokens and yy dollars with fee 1−g1-g, and a centralised price pp below the pool’s price by more than the fee, the arbitrageur sells tokens into the pool until the marginal output of the last one, gxy/(x+g Δx)2gxy/(x+g\,\Delta x)^2, equals pp:

Δx∗=gxy/p−xg,profit=g Δx∗yx+g Δx∗−p Δx∗,\Delta x^\ast=\frac{\sqrt{gxy/p}-x}{g},\qquad\text{profit}=\frac{g\,\Delta x^\ast y}{x+g\,\Delta x^\ast}-p\,\Delta x^\ast,

and symmetrically with dollars when the pool is cheap (Listing 25.1). The trade leaves the pool within the fee of the centralised price. The arbitrageur’s hedge is a trade on the centralised exchange, which is not in the same block and not atomic: it carries price risk between the two legs and the risk that the block does not include the on-chain leg.

25.2 Atomic arbitrage and searching

Definition 25.1 (Atomic arbitrage)

Atomic arbitrage is an arbitrage whose legs all execute in one on-chain transaction, typically across decentralised exchanges and often with a flash loan, so that either every leg succeeds or the whole transaction reverts and only the fee for the failed attempt is lost.

Daian and co-authors documented the rise of arbitrage bots on decentralised exchanges, which, like high-frequency traders, paid high transaction fees and optimised latency to front-run ordinary users’ trades; they described priority gas auctions, in which bots bid up fees to obtain early positions in the block, and showed that fees paid for ordering posed a risk to the consensus layer. That risk is what proposer–builder separation (One Quant Book 3, chapter 22) reorganised: searchers now send bundles to builders, who assemble blocks, and proposers choose the most valuable block.

The path of an on-chain arbitrage: searchers see a user’s swap or a centralised price move, build a bundle, and bid for its inclusion in a first-price auction run by a builder, which assembles a block and pays the proposer for including it. Source: One Quant Book 3, chapter 22; this chapter.
Figure 25.1. The path of an on-chain arbitrage: searchers see a user’s swap or a centralised price move, build a bundle, and bid for its inclusion in a first-price auction run by a builder, which assembles a block and pays the proposer for including it. Source: One Quant Book 3, chapter 22; this chapter.

25.3 Bundles, builders and bidding

Definition 25.2 (Bundle bid)

A bundle bid is the payment a searcher attaches to a transaction bundle for its inclusion in a block, paid to the builder (directly or through the transaction’s priority fee) only if the bundle is included.

When many searchers see the same opportunity, the bundle auction decides who gets it and at what price (Figure 25.1). The chapter’s model (Listing 25.2): an opportunity worth $100 on public information; each searcher’s value is lower by its own cost (gas, inventory, the risk on the centralised leg), uniformly between 0% and 20%; bids are sealed and the best is paid. With uniform private values the symmetric equilibrium bid shades the value toward the lowest by 1/n1/n. One searcher pays nothing: it is a monopolist. With two, the builder receives 93% of the winner’s value; with five, 97%; with twenty, 99% (Figure 25.2). What the searcher keeps is its cost advantage over the second-best, not the opportunity.

A first-price bundle auction for a $100 opportunity among searchers whose values are lower by their own costs, uniform between 0 and 20%: the builder’s share of the winning searcher’s value, and what the winner keeps, against the number of competing searchers (log scale); 20 000 auctions per point. Data: hf_onchain.auctions.
Figure 25.2. A first-price bundle auction for a $100 opportunity among searchers whose values are lower by their own costs, uniform between 0 and 20%: the builder’s share of the winning searcher’s value, and what the winner keeps, against the number of competing searchers (log scale); 20 000 auctions per point. Data: hf_onchain.auctions.

As of September 2026 — The law and the block auction

In November 2025 a federal judge in Manhattan declared a mistrial in the case of Anton and James Peraire-Bueno, charged with wire fraud, conspiracy to commit wire fraud and conspiracy to commit money laundering over an alleged exploit of the MEV-Boost software that netted $25 million in twelve seconds; the jury, reports said, could not agree on how to apply the law. Prosecutors could retry the case.

25.4 Liquidations on lending protocols

Lending protocols (One Quant Book 3, chapter 23) let anyone repay an under-collateralised borrower’s debt and take its collateral at a bonus. Liquidating $1 million of debt at a 5% bonus is worth $50 000 less gas; many searchers watch every position’s health factor, and the opportunity goes to auction exactly like an arbitrage. Flash loans let a searcher liquidate without capital, borrowing, repaying the debt, selling the collateral and repaying the loan in one atomic transaction.

25.5 Just-in-time and hedged liquidity provision

A liquidity provider in the pool takes the other side of every arbitrage. Milionis, Moallemi, Roughgarden and Zhang decomposed its return into a market exposure and a microstructure part: fees earned less losses to arbitrageurs. For a constant-product pool worth VV, with the token’s volatility σ\sigma, the loss-versus-rebalancing runs at σ2V/8\sigma^2V/8 per unit time; a provider that hedges the pool’s token exposure on a centralised exchange keeps fees less that rate.

Definition 25.3 (Hedged liquidity provision)

Hedged liquidity provision is supplying liquidity to an automated market maker while hedging the position’s exposure to the token’s price on another venue, so that the provider’s result is the pool’s fees less its loss to arbitrageurs, with the token’s price risk removed.

The chapter’s pool (Listing 25.3): $20 million at a 0.3% fee, a token at $3 000 with 4% daily volatility, 12-second blocks for a week, $2 000 of noise swaps a block in random directions, arbitrage after each whenever it beats $5 of gas. Over three simulated weeks the loss-versus-rebalancing is $25 800 to $29 500 against the formula’s $28 000; the arbitrageurs also take back the price impact the noise traders paid, $20 000 to $22 500 a week, which is theirs by construction. The hedged provider earns $339 000 of fees and nets $313 000.

The hedged liquidity provider’s week on a $20 million pool against its fee tier (log scales): fees earned, loss-versus-rebalancing and the net; the noise traders’ volume is held fixed, which flatters high fees (real noise volume falls with the fee). Data: hf_onchain.by_fee.
Figure 25.3. The hedged liquidity provider’s week on a $20 million pool against its fee tier (log scales): fees earned, loss-versus-rebalancing and the net; the noise traders’ volume is held fixed, which flatters high fees (real noise volume falls with the fee). Data: hf_onchain.by_fee.

Loss-versus-rebalancing barely depends on the fee (Figure 25.3): it is set by volatility and the pool’s size. The fee decides the income, through the noise volume the pool attracts; the model holds that volume fixed, which is exactly the assumption a provider must not make when it chooses a fee tier. Just-in-time liquidity (One Quant Book 3, chapter 20) is the extreme of hedged provision: a searcher adds concentrated liquidity around a large swap it has seen in the mempool, earns the swap’s fee, and removes the liquidity in the same block.

25.6 Sandwiching and the law

A sandwich attack (One Quant Book 3, chapter 22) buys ahead of a victim’s swap and sells after it, taking the price impact the victim was willing to tolerate. On the chapter’s pool, a $100 000 purchase with a 1% slippage tolerance can be preceded by a $50 900 front-run that leaves the victim 0.33 tokens, about $990, worse off, exactly its tolerance; the attacker’s gross gain is $700, of which, in a competitive block auction, 90% goes to the builder and $10 to gas, leaving $60 (Book 3’s firm.sandwich). The victim’s loss is the attack’s revenue; the builder’s share is paid out of it. Whether that is fraud, market manipulation or neither has not been settled in court: the one prosecution that reached a jury, over an exploit that targeted sandwich bots themselves, ended in a mistrial (dated box). This chapter describes sandwiching only to price what its victims lose; it is not a strategy file.

25.7 Strategy files

Strategy file 25.1 — CEX-DEX arbitrage

Who pays you, and why. Liquidity providers in stale pools, through loss-versus-rebalancing.

Instruments and venues. Constant-product and concentrated pools; the centralised exchanges’ books.

Signal. The pool’s price against the centralised price, beyond the fee and gas.

Sizing and execution. The closed-form size; the on-chain leg in a bundle, the centralised leg as a hedge.

Costs. Gas, the bundle bid (93% to 99% of the value against competitors), the centralised leg’s risk and fees.

How it dies. Competition in the bundle auction; in the model the week’s arbitrage nets its searchers $4 300 after gas, before bids.

Horizon, capacity, infrastructure. One block; inventory on both sides; builder connections.

Backtest honestly. Block-by-block pool states, the centralised price at each block’s time, bids that would have won.

Sources. Milionis, Moallemi, Roughgarden and Zhang; One Quant Book 3, chapter 22.

Strategy file 25.2 — Atomic DEX-DEX arbitrage

Who pays you, and why. Traders whose swaps leave two pools at different prices.

Instruments and venues. Pools of the same pair, or cycles of pairs, on decentralised exchanges.

Signal. A cycle whose output exceeds its input after fees.

Sizing and execution. One atomic transaction, often flash-funded; reverts if the price moved.

Costs. Gas, including for reverted attempts; the bundle bid.

How it dies. The priority gas auctions Daian and co-authors documented, and their successor, the builder auction.

Horizon, capacity, infrastructure. One block; mempool and state simulation.

Backtest honestly. Simulate against the chain’s state at the block, including competing bundles.

Sources. Daian et al. (2019, Flash Boys 2.0).

Strategy file 25.3 — Lending-protocol liquidation searching

Who pays you, and why. Borrowers whose collateral falls, through the protocol’s liquidation bonus.

Instruments and venues. Lending protocols; the collateral’s markets to sell it.

Signal. Health factors below one, from on-chain positions and prices.

Sizing and execution. Repay the debt, take the collateral at the bonus, sell it; flash loans if needed; bid for inclusion.

Costs. Gas, the bid, the collateral’s sale in a falling market.

How it dies. Crowded auctions in crashes, when gas and the collateral’s slippage peak together.

Horizon, capacity, infrastructure. One block; oracle and position monitoring.

Backtest honestly. Oracle updates as they were, competing liquidators, sale prices in the crash.

Sources. One Quant Book 3, chapter 23.

Strategy file 25.4 — Just-in-time liquidity provision

Who pays you, and why. Large swappers, through the fee on their swap.

Instruments and venues. Concentrated-liquidity pools.

Signal. A large pending swap in the mempool or an order-flow auction.

Sizing and execution. Add liquidity around the price for the swap, remove it after, in one bundle; hedge the inventory the swap leaves.

Costs. Gas, the bundle bid, the hedge.

How it dies. Private order flow that hides swaps until they are included.

Horizon, capacity, infrastructure. One block.

Backtest honestly. Only swaps that were visible before inclusion.

Sources. One Quant Book 3, chapter 20.

Strategy file 25.5 — Bundle bidding in builder auctions

Who pays you, and why. Nobody pays the bidder: the bid decides how much of an opportunity the searcher keeps.

Instruments and venues. Builder auctions for bundles.

Signal. The opportunity’s value, the searcher’s own cost, the number of competitors.

Sizing and execution. Shade the bid by the equilibrium: toward the lowest value by 1/n1/n with uniform costs.

Costs. Losing auctions; overbidding.

How it dies. More competitors: the winner keeps $6.7 of $100 against one rival and $1.0 against nineteen; and exploits of the auction’s software, the subject of the Peraire-Bueno prosecution (dated box).

Horizon, capacity, infrastructure. One block.

Backtest honestly. Competitors’ bids from the chain, not the searcher’s own.

Sources. This chapter; the dated box.

Strategy file 25.6 — Hedged concentrated-liquidity market making

Who pays you, and why. Swappers, through fees; less what arbitrageurs take.

Instruments and venues. Concentrated-liquidity pools; a centralised exchange for the hedge.

Signal. Fee income against the loss-versus-rebalancing rate σ2V/8\sigma^2V/8.

Sizing and execution. Provide where fees beat the rate; hedge the pool’s delta each block or beyond a band.

Costs. Loss-versus-rebalancing ($26 000 a week on $20 million at 4% daily volatility), hedging, gas.

How it dies. Volatility spikes, which raise the loss with the square of volatility while fees follow volume.

Horizon, capacity, infrastructure. Days to months.

Backtest honestly. Noise volume that responds to the fee tier.

Sources. Milionis, Moallemi, Roughgarden and Zhang.

25.8 Tutorial: bid away to the builder

Goal. Price the arbitrage, the bundle auction and the hedged liquidity provider’s week on a simulated chain. End state: the figures and the numbers in the text.

  1. The optimal arbitrage in closed form, checked against firm.amm’s integer swap.

    def optimal_arb(x: float, y: float, p: float, fee: float = 0.003) -> tuple[str, float, float]:
        """If the pool's price y/x is above p (A dear in the pool), sell A into it: input dx = (sqrt(g x y / p) - x) / g
        with g = 1 - fee, profit = out - p dx. If below, buy A from it with dollars: dy = (sqrt(g x y p) - y) / g,
        profit = p out_A - dy. Returns (direction, input, profit in dollars)."""
        g = 1.0 - fee
        if y / x > p / g:
            dx = (math.sqrt(g * x * y / p) - x) / g
            out = g * dx * y / (x + g * dx)
            return "sell_A", dx, out - p * dx
        if y / x < p * g:
            dy = (math.sqrt(g * x * y * p) - y) / g
            out = g * dy * x / (y + g * dy)
            return "buy_A", dy, p * out - dy
        return "none", 0.0, 0.0
    Listing 25.1. Sell into a dear pool or buy from a cheap one until the marginal unit earns the centralised price. code/firm/searcher/firm_searcher.py
  2. The auction among nn searchers.

    def auction(value: float, n: int, spread: float = 0.2, seed: int = 0, trials: int = 20000) -> dict:
        """Values v_i = value x (1 - spread + spread U_i). With uniform private values on [a, b] the symmetric equilibrium
        of a first-price auction bids a + (n - 1) / n (v - a). The winner pays its bid to the builder."""
        rng = np.random.default_rng(seed)
        a = value * (1.0 - spread)
        v = a + value * spread * rng.random((trials, n))
        vmax = v.max(axis=1)
        bid = a + (n - 1) / n * (vmax - a) if n > 1 else np.zeros(trials)
        return {"builder": float(bid.mean()), "searcher": float((vmax - bid).mean()),
                "share": float(bid.mean() / vmax.mean())}
    Listing 25.2. Uniform private values and the first-price equilibrium bid; the builder’s share. code/firm/searcher/firm_searcher.py
  3. The pool’s week: noise swaps, arbitrage after each block, the hedged provider’s account.

        for t in range(ch.blocks):
            p = ch.p[t]
            dn = ch.noise[t]
            if dn > 0:                                   # a noise trader buys A with dollars
                out = g * dn * x / (y + g * dn)
                noise_pnl += dn - p * out
                noise_fees += dn * fee
                y, x = y + dn, x - out
            else:                                        # sells A worth |dn| at the pool price
                dx = -dn / (y / x)
                out = g * dx * y / (x + g * dx)
                noise_pnl += p * dx - out
                noise_fees += dx * fee * p
                x, y = x + dx, y - out
            d, amt, profit = optimal_arb(x, y, p, fee)
            if profit > gas_usd:
                arbs += 1
                if d == "sell_A":
                    out = g * amt * y / (x + g * amt)
                    arb_fees += amt * fee * p
                    lvr += out - p * amt + amt * fee * p     # the pool's loss at the market price, before its fee
                    x, y = x + amt, y - out
                else:
                    out = g * amt * x / (y + g * amt)
                    arb_fees += amt * fee
                    lvr += p * out - amt + amt * fee
                    x, y = x - out, y + amt
                arb_profit += profit - gas_usd
        mispricing = noise_pnl - noise_fees
    Listing 25.3. Each block’s noise swap and arbitrage, valued at the centralised price. code/firm/searcher/firm_searcher.py

What to change next. Let noise volume fall with the fee; add a second pool and search atomic cycles; put the searchers’ latency to the centralised exchange into their costs.

25.9 Build: the searcher

Purpose. Price on-chain arbitrage and liquidations, the bundle auction that allocates them, and a hedged provider’s loss to them.

Interface. optimal_arb(x, y, p, fee), arb_exact, auction(value, n, spread, seed, trials), Chain(blocks, seed, sigma_day, p0, noise_usd), run_pool(chain, value0, fee, gas_usd), lvr_rate, liquidation_value, gas_cost. Built on Book 3’s firm.amm and firm.gasfee; the sandwich arithmetic is Book 3’s firm.sandwich.

Rules. Dollars; fees as fractions; one arbitrage a block after the noise swap.

Acceptance tests. code/firm/searcher/tests/: the arbitrage’s first-order condition and its optimality against neighbouring sizes; no arbitrage inside the fee band; agreement with the integer swap; the auction’s split by hand; loss-versus-rebalancing within 40% of the formula over three days; the hedged account adds up.

Stretch. Atomic cycles; order-flow auctions; latency-dependent searcher costs.

Sources and further reading

  • P. Daian et al., Flash Boys 2.0: frontrunning, transaction reordering, and consensus instability in decentralized exchanges, arXiv:1904.05234, 2019 (IEEE Symposium on Security and Privacy, 2020).
  • J. Milionis, C. C. Moallemi, T. Roughgarden, A. L. Zhang, Automated market making and loss-versus-rebalancing, arXiv:2208.06046.
  • The Block, report of the mistrial in United States v. Peraire-Bueno, 8 November 2025.

25.10 Exercises

Exercise 25.1 ★

A pool holds 1 000 tokens and $3 100 000; the centralised price is $3 000 and the fee 0.3%. How many tokens should the arbitrageur sell into the pool, and for what profit?

Solution

Solution of Exercise 25.1.

The pool’s price, $3 100, is above $3 000 by more than the fee: sell

Δx∗=0.997×1 000×3 100 000/3 000−1 0000.997=15.05\Delta x^\ast=\frac{\sqrt{0.997\times1\,000\times3\,100\,000/3\,000}-1\,000}{0.997}=15.05

tokens, for a profit of $677 before gas.

Exercise 25.2 ★

What is the loss-versus-rebalancing rate of a $20 million constant-product pool at 4% daily volatility, per day and per week?

Solution

Solution of Exercise 25.2.

0.042/8×20 000 000=$4 0000.04^2/8\times20\,000\,000=\$4\,000 a day, $28 000 a week.

Exercise 25.3 ★

Liquidating $1 million of debt at a 5% bonus costs $20 of gas. What is it worth?

Solution

Solution of Exercise 25.3.

1 000 000×0.05−20=$49 9801\,000\,000\times0.05-20=\$49\,980 before the bundle bid.

Exercise 25.4 ★★

Why does the builder’s share rise toward 100% as searchers are added?

Solution

Solution of Exercise 25.4.

Each searcher’s value differs from the others’ only by its costs; with more competitors the second-best value approaches the best, and in a first-price auction the winner must bid close to it: what it keeps is only its cost advantage.

Exercise 25.5 ★★

Why does loss-versus-rebalancing barely depend on the pool’s fee in the model?

Solution

Solution of Exercise 25.5.

Loss-versus-rebalancing is set by how far the market price moves between arbitrages, which depends on volatility and the pool’s size; the fee only widens the band inside which arbitrage does not pay, which changes the loss slightly.

Exercise 25.6 ★★

Why is a CEX–DEX arbitrage not atomic, and what risk does that leave?

Solution

Solution of Exercise 25.6.

Its hedge is on a centralised exchange, outside the chain’s transaction: one leg can execute without the other, leaving price risk and the risk of inclusion failure.

Exercise 25.7 ★★★

Coding. Double the token’s volatility in firm.searcher.Chain. What happens to loss-versus-rebalancing and to the hedged provider’s net?

Solution

Solution of Exercise 25.7.

Loss-versus-rebalancing rises to $96 300 over the week (the formula: $112 000, four times the base case); the hedged provider nets $294 000 instead of $313 000, with more fees from the larger arbitrage volume offsetting part of it.

Exercise 25.8 ★★★

Find the flaw. “Arbitrage opportunities on our pools were worth $11 400 last week; our searcher will make that.”

Solution

Solution of Exercise 25.8.

$11 400 is the gross value before gas and the bundle bids; after $7 100 of gas the searchers’ net is $4 300, and in a competitive auction most of that goes to builders: the searcher keeps its cost advantage over the next-best.

25.11 Problem: Bid Away to the Builder

Problem 25.1

Weekend problem — bid away to the builder

A firm runs searchers and a hedged liquidity position on a decentralised exchange.

Part I — Arbitrage.

  1. Derive the optimal CEX–DEX trade size.
  2. Define atomic arbitrage and contrast it with CEX–DEX arbitrage.
  3. What did Daian and co-authors document?
  4. Describe the path of a bundle from searcher to block.

Part II — Auctions.

  1. Define a bundle bid.
  2. Give the equilibrium bid with uniform private values, and the builder’s share for 2, 5 and 20 searchers.
  3. What does the winner keep, and why?
  4. How is a liquidation auctioned?

Part III — Liquidity.

  1. Define hedged liquidity provision and the loss-versus-rebalancing rate.
  2. Compare the simulated loss with the formula.
  3. What else do arbitrageurs take from the pool, and who paid for it?
  4. Why is the model’s fee comparison flattering to high fees?

Part IV — The verdict.

  1. State the named result: the share of arbitrage profit paid to builders as the number of competing searchers grows, and the hedged liquidity provider’s net return after loss-versus-rebalancing.
  2. What does a searcher need to keep more than 1%?
  3. What does the sandwich example show about who pays whom?
  4. Summarise the dated box.
  5. Which strategy file is most exposed to private order flow?
  6. How would you choose a pool’s fee tier?
  7. What would an order-flow auction change for the swapper?
  8. In one sentence: who earns an on-chain arbitrage?
Solution

Solution of Problem 25.1.

  1. Maximise gΔx y/(x+gΔx)−pΔxg\Delta x\,y/(x+g\Delta x)-p\Delta x: gxy/(x+gΔx)2=pg xy/(x+g\Delta x)^2=p, so Δx∗=(gxy/p−x)/g\Delta x^\ast=(\sqrt{gxy/p}-x)/g.
  2. See Definition 25.1; CEX–DEX has an off-chain leg.
  3. Arbitrage bots paying high fees and optimising latency to front-run users; priority gas auctions; consensus risk from ordering fees.
  4. Searcher to builder with a bid; builder to proposer with a payment; the best block is proposed.
  5. See Definition 25.2.
  6. a+n−1n(v−a)a+\frac{n-1}{n}(v-a); 93%, 97% and 99%.
  7. Its cost advantage over the second-best: $6.7 of $100 against one rival, $1.0 against nineteen.
  8. The same way: many searchers watch health factors; the best bid wins the liquidation.
  9. See Definition 25.3; σ2V/8\sigma^2V/8 per unit time.
  10. $25 800 to $29 500 a week against the formula’s $28 000.
  11. The price impact the noise traders paid, $20 000 to $22 500 a week; the noise traders.
  12. It holds noise volume fixed, while real volume falls with the fee.
  13. Builders receive 93% of the winner’s value with two searchers and 99% with twenty; the hedged provider nets $313 000 on $20 million in a week at a 0.3% fee, after $26 000 of loss-versus-rebalancing.
  14. Lower costs than its rivals: better latency, inventory, gas.
  15. The victim’s loss ($990) funds the attacker’s gross ($700), of which the builder takes most.
  16. A mistrial in November 2025 in the Peraire-Bueno MEV-Boost case; the law’s application unsettled.
  17. Just-in-time liquidity.
  18. Fees from realistic volume against σ2V/8\sigma^2V/8.
  19. The value of its trade’s impact would be auctioned back to it.
  20. The builder, mostly.

25.12 Interview questions

Interview question 25.1 ★ trader

Ether moves 1% on the centralised exchanges. What happens to a constant-product pool of ether in the next block, and who profits?

Solution

Solution of Interview question 25.1.

The pool is stale; the first arbitrage in the next block trades it back to within the fee of the new price; the searchers compete, and the builder receives most of the value; the liquidity providers bear the loss.

What the interviewer is looking for: arbitrage, auction, loss-versus-rebalancing.

Interview question 25.2 ★★ researcher

Derive the loss-versus-rebalancing rate of a constant-product pool.

Solution

Solution of Interview question 25.2.

Arbitrage keeps the pool at the market price; for a constant-product pool the value is 2kP2\sqrt{kP}, whose second derivative in PP is −12kP−3/2-\frac12\sqrt k P^{-3/2}; the loss rate is −12σ2P2V′′=σ28V-\frac12\sigma^2P^2V^{\prime\prime}=\frac{\sigma^2}{8}V.

What the interviewer is looking for: the pool value’s concavity.

Interview question 25.3 ★★ developer

Design a searcher that finds, simulates and bids for arbitrage bundles within one block time.

Solution

Solution of Interview question 25.3.

Stream pending transactions and state; simulate candidate bundles against the latest state; estimate the value and competitors’ bids; submit to several builders before the deadline; track inclusion.

What the interviewer is looking for: simulation against state, deadline, multiple builders.

Interview question 25.4 ★★ risk

Your CEX–DEX arbitrage’s on-chain leg was not included but the centralised hedge was filled. What is your position, and what should the system do?

Solution

Solution of Interview question 25.4.

A naked position on the centralised exchange: unwind it at once, or resubmit the on-chain leg if still profitable; the system must treat inclusion failure as a normal event.

What the interviewer is looking for: legging risk on-chain.

Interview question 25.5 ★★ trader

How would you bid against a competitor whose costs are lower than yours?

Solution

Solution of Interview question 25.5.

Bid below your value by less than you would against equals; if the competitor’s value is surely higher, bid only when yours is close to it, or do not bid.

What the interviewer is looking for: asymmetric auctions.

Interview question 25.6 ★★★ researcher

Show that with nn bidders whose values are uniform on [a,b][a,b], bidding a+n−1n(v−a)a+\frac{n-1}{n}(v-a) is a symmetric equilibrium of the first-price auction.

Solution

Solution of Interview question 25.6.

Against others bidding β(v)=a+n−1n(v−a)\beta(v)=a+\frac{n-1}{n}(v-a), a bid bb wins with probability (b−an−1n(bmax⁡−a))n−1\bigl(\frac{b-a}{\frac{n-1}{n}(b_{\max}-a)}\bigr)^{n-1} up to scale; maximising (v−b)(b−a)n−1(v-b)(b-a)^{n-1} gives b=a+n−1n(v−a)b=a+\frac{n-1}{n}(v-a).

What the interviewer is looking for: the first-order condition.

Terms defined in this chapter

See all 2333 terms in the glossary