Byte layouts
The exact encodings of the payload, the state leaf and the manifest.
All three are fixed binary layouts. Integers are big-endian. Text is a 2-byte length followed by UTF-8.
Payload
The bytes in payload.hex. Its leaf hash is your entry in the users tree.
| Field | Encoding |
|---|---|
| encoding version | 1 byte (0x01) |
| operator | text |
| user | text |
| batchNum | int64 |
| prevUserBatchHash | 32 bytes |
| userSeqNum | int64 |
| eventRoot | 32 bytes |
| stateRoot | 32 bytes |
| version | int64 |
The tail is fixed-size, so the two roots can be read from the end: stateRoot is bytes
[len - 40, len - 8) and eventRoot is bytes [len - 72, len - 40).
State leaf
The bytes in state.hex. Its leaf hash is the payload's stateRoot.
| Field | Encoding |
|---|---|
| encoding version, tag | 2 bytes (0x01 0x80) |
| user | text |
| balance | amount |
| position count | uint16 |
| each position | id (text), market (text), size (amount), cost basis (cost), margin (amount), leverage (int64), margin mode (1 byte), funding entry (cost), funding tick (uint64) |
| cost dust | cost |
| withdrawal counter | int64 |
| userSeqNum | int64 |
| funding clearing | uint16 count, then market (text) and amount per entry. Always empty except on the exchange's own account |
| unclaimed referral credit | amount, present only when non-zero |
An amount is a 16-byte two's-complement integer scaled by 10¹⁰. A cost is the same, scaled
by 10²⁰. Margin mode is 0x01 for isolated and 0x02 for cross.
Manifest
The pre-image of prevManifestHash, which is a plain SHA-256 of these bytes.
| Field | Encoding |
|---|---|
| encoding version | 1 byte (0x01) |
| operator | text |
| batchNum | int64 |
| timestamp | int64, Unix nanoseconds (microsecond precision) |
| prevManifestHash | 32 bytes |
| usersRoot | 32 bytes |
| version | int64 |
| public observer party | text |
| auditor | 0x00 if none, else 0x01 then text |