ORRO

plate II · the mechanism, on the bench

Two experiments you can run before you put anything in.

Both figures below are computed with the hook’s own arithmetic, ported to the browser digit for digit, not drawn to make a point. Move the sliders; the numbers are what the contract would pay.

the film · one orbit, in one take
0 / 450

The same mechanism the benches below compute, shot as a film: the swap, the stream, the visitor who leaves in the block, and the crossing. It loops; hold it and drag the slider to read any frame.

fig. 1

The visitor.

A keeper holds a range through the whole orbit. A visitor arrives with ten times the keeper’s liquidity, on the same range, in the block of a large swap. In an ordinary pool the visitor takes ten elevenths of the fee and leaves. Here the fee enters a stream that runs for 1h 0m after the swap, and the visitor is paid for the time it stays, in proportion to its liquidity, and for nothing else.

Set the stay to the same block and the visitor’s share is exactly nought. Set it to ten minutes and it earns what ten minutes of a ten-to-one share is worth. Nothing about its size changes the first fact.

fee on stream
1
keeper earns
1 (100.00%)
visitor earns
0 (0.00%)
fig. 2

The crossing.

Two positions on adjacent ranges. A fee enters while the price sits in A. Part way through the orbit the price crosses the tick they share and sits in D; later it comes back. The stream follows the price: A earns while it holds the price and stops the instant it does not, D earns for exactly the interval between the two crossings, and the two shares add up to the whole fee.

The hook does not know either position exists when the tick is crossed. It flips one number on the tick, the way the pool flips its own fee growth, and each position’s share falls out of a subtraction when it is next touched.

notes

What the arithmetic is, in four lines.

on a swap  cut = unspecified × fee / 1e6  ·  rate = (cut + what the old stream still owed) / orbit

each second  acc += rate / liquidity-in-range  ·  paused while liquidity-in-range = 0

per tick  outside = acc − outside, when the price crosses it

per position  owed += L × (inside − inside at last touch),  inside = acc − below(lower) − above(upper)

Two currencies, two streams: an exact-input buy pays its fee in the token, an exact-input sell in ether, and the exact-output shapes the other way about. A position is owed both and claims both. The rates are kept scaled by 1018 so a small fee over a long orbit does not round to nothing per second, and every division saturates instead of reverting, because a hook welded into a pool key must never be the reason a pool cannot swap.