Bytecode
The canonical form of a strategy: a short, versioned byte string that the Rust compiler writes and the Solidity VM runs.
Bytecode is immutable once registered and its keccak256 is the strategy's identity. Shared test vectors run through both the Rust VM and the Solidity VM, so the two agree byte for byte. All integers are big-endian.
Numbers
Every value is a signed fixed-point integer with 8 decimals: 1.0 is 100000000. Every intermediate result must stay within int128. MUL is a * b / 1e8 and DIV is a * 1e8 / b, both truncated toward zero. Comparisons and logic push 1 or 0.
Any error stops the evaluation and the strategy does not fire: overflow, division by zero, stack underflow or overflow (depth 32), an unknown opcode, a truncated operand, a slot out of range, or a final stack that does not hold exactly one value.
Layout
| Field | Size | Notes |
|---|---|---|
| magic | 2 | CS |
| version | 1 | 0x01 |
| nSlots + slots | 1 + 7 each | 1 to 32 slots |
| nAddrs + addresses | 1 + 20 each | 0 to 8 watched accounts |
| condLen + condition | 2 + condLen | 1 to 1024 bytes |
| nActions + actions | 1 + ... | 1 to 4; nothing may follow the last action |
Slots
The condition reads values only from slots: kind u8, asset u32, param u16. The keeper supplies one int256 per slot when it fires; the contract re-runs the program on exactly those values and commits them. Asset is the HyperCore asset id: a perp index, 10000 plus a spot index, or 100000 + dex x 10000 + index for a HIP-3 perp.
| Kind | Name | Param |
|---|---|---|
| 0x01 | MARK | 0 |
| 0x02 | MID | 0 |
| 0x03 | ORACLE | 0 |
| 0x04 | FUNDING | 0 |
| 0x05 | OI | 0 |
| 0x06 | IMBALANCE | levels 1..20 |
| 0x07 | CHANGE | seconds 60..43200 |
| 0x08 | BIGTRADE | seconds 1..3600 |
| 0x09 | WHALE | address index |
| 0x0A | KRATE | 0 (asset 0) |
| 0x0B | US_CLOSE | 0 (asset: a HIP-3 market with a US listing) |
| 0x0C | SESSION | 1 = US regular session (asset 0); value 1.0 open, 0 closed |
| 0x20 | PREV | slot index: its value before the triggering update |
| 0x21 | SINCE | FOR index: unix seconds since the inner condition is true |
MARK and ORACLE are the slots the chain can check against HyperCore. PREV and SINCE come from the keeper's own history.
Condition opcodes
| Op | Name | Operands | Stack |
|---|---|---|---|
| 0x01 | CONST | i128 | push |
| 0x02 | LOAD | slot u8 | push slots[slot] |
| 0x03 to 0x06 | ADD SUB MUL DIV | a b -> a op b | |
| 0x07 | NEG | a -> -a | |
| 0x10 to 0x13 | LT LE GT GE | a b -> 1 or 0 | |
| 0x14 | XUP | slot u8, prevSlot u8 | c -> prev < c and now >= c |
| 0x15 | XDN | slot u8, prevSlot u8 | c -> prev > c and now <= c |
| 0x20 0x21 | AND OR | a b -> a op b | |
| 0x22 | NOT | a -> !a | |
| 0x23 | FOR | sinceSlot u8, dur u32 | b -> b and snapshotTime - since >= dur |
Binary ops pop b first, then a.
Actions
| Type | Name | Fields |
|---|---|---|
| 0x01 | SWAP | poolId bytes32, zeroForOne u8, amountIn u128, minOutPerIn u128 |
| 0x02 | ORDER | asset u32, isBuy u8, notionalUsd u64 (6 decimals), reduceOnly u8, slipBps u16 |
| 0x03 | CLOSE | asset u32, slipBps u16 |
| 0x04 | REDUCE | asset u32, bps u16, slipBps u16 |
| 0x05 | TRANSFER | token address (0x0 is native HYPE), amount u128, to address |
| 0x06 | NOTIFY | len u8, url bytes (https only) |
| 0x07 | TWAP | asset u32, isBuy u8, totalUsd u64, slices u8, intervalSecs u32, slipBps u16 |
For a SWAP the keeper passes minOut, which must be at least amountIn * minOutPerIn / 1e18. ORDER, CLOSE, REDUCE and TWAP slices are IOC limit orders through CoreWriter at the mark moved by slipBps against the trader, rounded to HyperCore's tick rules.
Fire record
snapshotHash = keccak256(abi.encode(uint256 strategyId, uint64 trigger, uint64 snapshotTime, int256[] values))
trigger counts rising edges of the condition as the keeper saw them. It must be strictly greater than the last fired trigger, so each trigger fires at most once. The hash is stored with the fire and is what a challenger opens.