Bytecode
Docs

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

4353magic CS01version01nSlots04 0000009f 0000FUNDING, HYPE (159)00nAddrs0014condLen 2002 00LOAD slot 001 0000...0000CONST 010LT01nActions03 0000009f 0064CLOSE HYPE, slip 100 bps
if HYPE.funding < 0 then close HYPE, as registered: 42 bytes.
FieldSizeNotes
magic2CS
version10x01
nSlots + slots1 + 7 each1 to 32 slots
nAddrs + addresses1 + 20 each0 to 8 watched accounts
condLen + condition2 + condLen1 to 1024 bytes
nActions + actions1 + ...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.

KindNameParam
0x01MARK0
0x02MID0
0x03ORACLE0
0x04FUNDING0
0x05OI0
0x06IMBALANCElevels 1..20
0x07CHANGEseconds 60..43200
0x08BIGTRADEseconds 1..3600
0x09WHALEaddress index
0x0AKRATE0 (asset 0)
0x0BUS_CLOSE0 (asset: a HIP-3 market with a US listing)
0x0CSESSION1 = US regular session (asset 0); value 1.0 open, 0 closed
0x20PREVslot index: its value before the triggering update
0x21SINCEFOR 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

OpNameOperandsStack
0x01CONSTi128push
0x02LOADslot u8push slots[slot]
0x03 to 0x06ADD SUB MUL DIVa b -> a op b
0x07NEGa -> -a
0x10 to 0x13LT LE GT GEa b -> 1 or 0
0x14XUPslot u8, prevSlot u8c -> prev < c and now >= c
0x15XDNslot u8, prevSlot u8c -> prev > c and now <= c
0x20 0x21AND ORa b -> a op b
0x22NOTa -> !a
0x23FORsinceSlot u8, dur u32b -> b and snapshotTime - since >= dur

Binary ops pop b first, then a.

Actions

TypeNameFields
0x01SWAPpoolId bytes32, zeroForOne u8, amountIn u128, minOutPerIn u128
0x02ORDERasset u32, isBuy u8, notionalUsd u64 (6 decimals), reduceOnly u8, slipBps u16
0x03CLOSEasset u32, slipBps u16
0x04REDUCEasset u32, bps u16, slipBps u16
0x05TRANSFERtoken address (0x0 is native HYPE), amount u128, to address
0x06NOTIFYlen u8, url bytes (https only)
0x07TWAPasset 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.