Read

How it works

One pool, one hook, a population of small networks, and a set of rules that keep them from losing the vault to whoever trades against them. Every number on this page is a constant in the contracts.

1. A swap

QBTR trades in one Uniswap v4 pool, ETH against QBTR, whose hook is Qubitrage. Every swap pays 3% of its ETH side to the hook (where it goes is on Fees). Then one of two things fills it.

On an exact-input swap of at least 0.01 ETH, the four fittest agents each run their network on eight inputs the hook reads from the pool: how far the price sits from its lagged average, recent buy and sell flow, volatility, how the vault's holdings lean, the swap's size, the gas price, the side, and how long the market has been quiet. Each network answers with a signal between minus one and one. For a buy the highest signal wins, for a sell the lowest, and the winner's price is the lagged average plus the signal times 50 ticks (a tick is one hundredth of a percent).

The vault fills the whole swap at that price only if every one of these holds:

  • The pool's own price is within 50 ticks of the average. When the market runs away from its average, an average is a stale price, and a stale price is a free option for whoever trades against it. The agents step aside.
  • The trader gets the pool's spot price or up to 30 ticks worse, never better. A quote better than spot is cut back to spot: the edge stays with the vault.
  • The price respects the trader's own price limit.
  • The fill is no bigger than the agent's share of the vault: four times its weight over the whole population's weight, never more than 25% of the side the vault pays out.
  • Fewer than 64 earlier fills are waiting to be scored.

Otherwise the pool fills it, as any v4 pool would. The agents can never make a swap fail: their quote is a call with a hard gas limit of 400,000, and any failure simply means the pool fills. Swaps work through any router, with empty hookData.

2. Scoring

Every fill is written into a ring of 64, at the price it executed. At least 32 blocks later anyone may call score, which compares that price with the lagged average as the current block opened. A fill the market moved in favour of raises the agent's fitness; a fill that was picked off lowers it. Live spot is never used, so nobody can push the price inside their own transaction to move a mark, and each fill's move counts for at most 200 ticks. The caller is paid 0.00002 ETH a fill, at most a thousandth of the vault.

Scoring also keeps each agent's running profit and loss, marked: the fill's ETH size times the move. Only a new high of that running total pays out, so losing fills are netted before anything leaves the vault. Each new high, capped at 1% of the vault per fill, is split: 15% to the agent's owner, 15% to the stakers behind it, 30% to buyback and burn, and 40% stays in the vault.

3. Evolution and the Nursery

Once a UTC day anyone may call evolve and is paid 0.002 ETH (at most a thousandth of the vault). The weakest tenth of the living agents retire. The strongest tenth breed half as many children, rounded up, into the freed slots: each byte of a child's weights comes from one parent or the other, and one byte in sixteen is nudged by up to 8. The other freed slots stay open for new agents, so nobody can fill all 256 and lock everyone else out.

Children are born without an owner and sold in the Nursery: one English auction each, a one-day clock from the first bid, 5% steps, ten minutes added by a late bid. The winning ETH is owed half to each parent's owner.

A new agent costs 0.01 ETH, paid into the vault, and starts with a weight of 1000, so it gets a share of the vault before it has a record. You choose all 91 weights on Create.

4. Staking

Stake at least 1 QBTR behind a living agent. A stake earns a share of the 0.75% fee pot by size (moved to stakers at most once a UTC day), and a share of 15% of its own agent's profit. It cannot be withdrawn for 7 days. If its agent retires, a quarter of everything staked behind it is burned at once, and the owner may take the other three quarters out straight away.

5. Hash keys

Agents and stakes are owned by Winternitz one-time keys, a signature scheme that rests on nothing but the hash function. To act, the owner signs with the current key, which reveals it, and names the next key in the same message. The message binds the contract, the object, the key number, the action, the address being paid and the next key, so it cannot be replayed or redirected. Each key signs once: signing two different messages with the same key would let anyone forge a third. The Keys page keeps a ledger in your key file and refuses a second signature.

Every agent and every stake gets its own chain of keys inside your file. One key never serves two objects.

6. The canary and bunker mode

The hook holds a canary: an Ethereum address whose public key was picked by a hash, so nobody holds its private key. A valid signature from it can only mean ECDSA itself is broken. Whoever produces one is paid the whole bounty fund, and the protocol enters bunker mode for good: creating agents, opening stakes and bidding stop, because the money for them comes from ECDSA wallets. Hash-signed actions and every exit keep working, and so does trading.

The constants

Swap fee3% of the ETH side
Smallest agent fill0.01 ETH
Band around the average50 ticks
Worst price vs spot30 ticks
Largest fill25% of a side
Quote gas limit400,000
Scoring delay32 blocks
Unscored fills, at most64
Mark clamp200 ticks
Profit split15 / 15 / 30 / 40
Profit per fill, at most1% of the vault
Agents256 slots
Network8 . 9 . 1, 91 bytes
New agent0.01 ETH
Evolutiononce a UTC day
Retire / breed10% / half that
Auction1 day, +5% steps
Smallest stake1 QBTR
Stake lock7 days
Burned on retirement25% of the stake
Signature67 words, 2,144 bytes

Measured on a mainnet fork

Swap the pool fills250,261 gas
Swap the agents fill565,954 gas
Swap they quote, pool fills453,496 gas
Create an agent337,913 gas
Evolve, 65 agents1,438,469 gas