the language
Everything a rule can say, on one page.
A rule is a list of lines. Each line is when, up to four conditions joined by and, a colon, and one or two actions. A line without when always applies. Lines run top to bottom: the last fee wins, takes add up, one refusal stops the swap. Case does not matter, and # starts a comment.
Conditions
| buy · sell | which way the swap goes. A buy acquires the token; a sell gives it up. also: buy, sells, selling, a buy |
| age < 10 min | time since the pool opened. s, min, h, d, w. also: in the first 10 minutes · after 1 h |
| price < -20% | the token, against the price it opened at. also: price down 20% · up 2x · above +50% |
| hour >= 22 | the hour of day, UTC, 0 to 23. also: hour is 9 · hour under 6 |
| size > 2 ETH | ether the swap moves. Known only after the swap. also: bigger than 2 eth · over 0.5 |
| impact > 3% | how far the swap moved the price. Known only after. also: it moves the price more than 3% |
Comparisons: < > <= >= =, or the words under, over, below, above, less than, more than, at most, at least, before, after.
Actions
| fee 1% | the rate this swap pays, in place of the standing one. Up to 25%; above 10% only inside an age window of a day or less. also: charge a fee of 1% |
| refuse | the swap does not happen. Must be tied to size, impact, or an age window of at most 30 days. also: reject, deny, block |
| take 2% to lps | a share of what the swap moves, donated to the pool's liquidity providers. also: give 2% to the pool |
| take 1% to 0x… | the same share, sent to that address. All takes together: 10% at most. also: send 1% to 0x… |
A take lands on the side of the swap the trader did not name: on an exact-input swap that is the output, and they receive that much less; on an exact-output swap it is the input, and they pay that much more.
A rule with everything in it
Written loosely, read back strictly. What the chain stores is the strict form; this page and the launcher both compile to the same bytes.
fee 0.3% when selling in the first 10 minutes: fee 10% when a buy is bigger than 2 eth: refuse when sell and it moves the price more than 3%: take 2% to lps when price down 20% and sell: fee 5% when hour >= 22: take 0.5% to 0x…beef
What the chain holds
- 1fee 0.3%
- 2when sell and age < 10 min: fee 10%
- 3when buy and size > 2 ETH: refuse
- 4when sell and impact > 3%: take 2% to lps
- 5when price < -20% and sell: fee 5%
- 6when hour >= 22: take 0.5% to 0x000000000000000000000000000000000000beef
0x010600010000000bb800000000000000000000000000000000000000000200000000000000000001010100000000000002580100000186a000000000000000000000000000000000000000000200000000000000000000040200000000001e848001010000000000000000000000000000000000000000000000000200000000000000000001050200000000000001280102000000c80000000000000000000000000000000000000000020201fffffffffffff7480000000000000000000101000000c35000000000000000000000000000000000000000000103040000000000000016010200000032000000000000000000000000000000000000beef
The bytes
A program is a version byte, a count, then each rule: the number of conditions, ten bytes per condition (field, comparison, a signed 64-bit value), the number of actions, twenty-five bytes per action (kind, a 32-bit value, an address). Values carry the field’s own unit: seconds for age, ticks against the opening tick for price and impact, UTC hours, millionths of an ether for size. Fees are in pips (a million is 100%), takes in basis points.
Rulebook.check runs on every write and returns a numbered reason, the same numbers this page shows. Rulebook.run runs twice per swap: once before it, with what is known then, and once after, with the deltas in hand.