The fast loop corrects net exposure with maker orders on HyperCore. The slow loop moves inventory between venues. Both work around a delayed, one-way channel.
Swap flow is directional, so a liquidity position drifts away from its target mix. Most liquidity managers fix that by swapping their leftover tokens through an AMM, paying fees and slippage. Counterbook fixes the vault's net exposure on the deepest venue available, HyperCore's spot order book, as a maker, and leaves the pool position alone.
The vault measures how far it is from its target mix with the skew :
is the vault's total HYPE across both legs, the reference price, and the curator's target weight for HYPE (50% by default). means the vault is long HYPE relative to target. Two curator parameters split the response:
| Skew | Response |
|---|---|
softBand | Nothing. The inventory term of the fee still nudges flow. |
softBand hardBand | Maker order: ALO, a few ticks behind the touch |
hardBand | Urgent order: IOC, limit a bounded distance through the mid |
The fast loop runs at the end of afterSwap, and in poke(), which anyone can call when no swaps are flowing. It dispatches at most one order action per cooldownBlocks, and every external call inside it has a gas stipend and is wrapped in try/catch, so it can never revert a swap.
Cheap pre-check (swaps only). If the cooldown is running, or the swap left less gas than minGasForLoop, stop. With no live order, estimate the skew from the hook's cached inventory and stop if it is inside the soft band.
Full read. Call vault.nav(). Stop if NAV is not valid or a sweep's transfer is still in flight. Otherwise refresh the hook's cached inventory from the read; poke() does this even while the cooldown runs. Then stop if the cooldown is running or the CoreAgent does not yet exist as a HyperCore account.
Manage a live order. If the hook has a live order record, read the HyperCore balance on the order's side:
placedCoreBalance()), the order filled: clear the record and emit MakerOrderCancelled with reason 3. If nothing changed, the order may still be on its way, so the hook only concludes it was rejected once ttlBlocks have passed (also reason 3). If the hook had sent a cancel, it clears the record without an event.ttlBlocks, or its price has moved more than the reprice tolerance away from the mid, send a cancel (action 11), record the block in cancelSentBlock() and emit MakerOrderCancelled with reason 1 or 2. If a cancel was already sent and the order still rests, send it again once the cooldown allows (reason 4).The record stays in liveOrder() until HyperCore shows nothing on hold, and the loop sends nothing new while the order is, or may still be, live. A CoreWriter delay longer than the cooldown therefore never produces a second order, and the agent always cancels before it places.
Place an order if nothing rests on either side and is outside the soft band:
cloid = uint128(keccak256(abi.encode(block.number, nonce))) | 1. It is never zero, because zero means "no live order".Record and emit. Store the order in liveOrder() and the sold token's HyperCore total in placedCoreBalance(), then emit MakerOrderPlaced(cloid, isBuy, limitPx, sz, tif, refPx).
| Band | Time in force | Sell HYPE () | Buy HYPE () |
|---|---|---|---|
| Maker | 1 (ALO, add liquidity only) | ask + offsetTicks × tick, rounded up | bid − offsetTicks × tick, rounded down |
| Urgent | 3 (IOC, immediate or cancel) | mid × (1 − maxSlippage) | mid × (1 + maxSlippage) |
The CoreAgent checks every order again before encoding it: the asset must be the mandate's spot asset, the time in force ALO or IOC, the price on a valid tick and within maxOrderDeviation of the live mid, the size a whole lot, the notional at least 10 USDC, and the free HyperCore balance sufficient. See whitelisted actions.
Drawing diagram…
stateDiagram-v2
accTitle: Maker order lifecycle
accDescr: The hook starts idle. When the skew passes the soft band, nothing rests on HyperCore and the cooldown allows, it dispatches an order. On a later call, a balance on hold means the order rests. No hold with a changed balance means it filled; no hold and no change is treated as a rejection only after ttlBlocks. A resting order returns to idle when its hold clears, or is cancelled when it is too old or the price moved. A cancel that has not landed is sent again until the hold clears.
[*] --> Idle
Idle --> Dispatched: skew past softBand, nothing on hold, cooldown ok
Dispatched --> Resting: later call, hold > 0
Dispatched --> Idle: hold == 0 and balance moved (filled), or ttlBlocks passed (rejected)
Resting --> Idle: hold == 0 (filled)
Resting --> Cancelling: age > ttlBlocks or price moved
Cancelling --> Cancelling: still on hold after the cooldown, cancel sent again
Cancelling --> Idle: hold == 0MakerOrderCancelled.reason | Meaning | Action sent |
|---|---|---|
| 1 | Older than ttlBlocks | Cancel by cloid |
| 2 | Price moved more than the reprice tolerance from the mid | Cancel by cloid |
| 3 | Nothing on hold any more: filled (the sold balance changed), or rejected or never arrived (nothing changed after ttlBlocks) | None, inferred from balances |
| 4 | A cancel was sent earlier but the order still rests | Cancel by cloid, again |
CoreWriter is a one-way, delayed channel.
So the protocol infers state from HyperCore balances only, read through precompile 0x801:
| What the hook reads later | What it concludes |
|---|---|
hold > 0 on the order's side | The order is resting |
hold = 0 and the sold balance changed | The order filled, fully or partly |
hold = 0 and balances unchanged | It was rejected or cancelled, or has not arrived yet. The hook waits ttlBlocks before concluding. |
NAV is always computed from balances, including hold, never from order status. A missed fill therefore never corrupts accounting; it only delays the next rebalance. The app and any indexer can join MakerOrderPlaced.cloid with HyperCore's orderStatus, openOrders and userFills for the CoreAgent address to show what happened. See listen to events.
After several fast-loop rebalances the venues drift apart. Typically the pool leg ends up long the asset that flow sold to it, while the HyperCore float holds the other one. sweep() is permissionless and moves idle balances between HyperEVM and the HyperCore float. It cannot reach tokens inside the position; those only become idle when a recenter cannot fit them into the new range.
coreFloatTarget, 20% by default, capped by maxCoreFloat), split at the target weight . To avoid churn, the float only moves when it is more than 25% (relative) away from its target.0x2222222222222222222222222222222222222222;deposit(amount, type(uint32).max), which credits the spot balance.withdrawToVault. Pulls are only sent from an active HyperCore account.sweep() can run once every 4 × transitBlocks blocks; an earlier call reverts with SweepCooldown. A call that would move nothing reverts with NothingToSweep.transit0 and transit1 until the credit shows up on the other venue, or until transitBlocks pass. Until then deposits, crystallisation and another sweep revert with InTransit; redemptions, claims and recentering keep working. The fast loop neither refreshes its cache nor trades while a transfer is in flight.Transfer gas on HyperCore
A HyperCore to HyperEVM transfer of a non-HYPE token costs 200k gas at the HyperEVM base fee, paid from the account's HYPE on HyperCore. The vault therefore keeps a HYPE reserve on HyperCore (coreHypeReserveWei, 0.01 HYPE in both presets) that sell orders and redemption claims never spend. It sends a USDC pull only while free HYPE on HyperCore covers twice that cost at the current block.basefee, and a HYPE pull always leaves the larger of the reserve and twice the cost.
HyperCore's base-tier spot fees are 0.040% for makers and 0.070% for takers, from Hyperliquid's fee schedule. A maker order saves about 3 bp against taking, plus the half-spread a taker would cross, and earns whatever spread it captures. Maker orders may not fill; the IOC past the hard band pays the taker rate. There is no perp position, so no margin, funding or liquidation.
Rate limits shape the loop too: HyperCore allows each address one request per 1 USDC traded cumulatively, after an initial buffer of 10,000 requests. The cooldown, the threshold dispatch and cancel-before-place keep the CoreAgent well inside that budget. See rate limits.