Skip to main content
Use this section when you operate your own event-derived state store. Applications using Kuru’s hosted market data and account data do not need to implement these reducers just to start an integration. The goal is to reconstruct account balances, orders, executions, and liquidity positions from chain events, with enough provenance to undo and replay state after a reorg. Index AccountCore as the custody ledger, each OrderBook as a market ledger, SpotRouter as the market registry, and each delegated trading-wallet EOA as its own intent store.

Ordering and identity

Process logs in (blockNumber, transactionIndex, logIndex) order. Preserve block hash and parent hash so every derived write can be rolled back on a reorg. Canonical keys include:
Slots are reused. Never identify historical orders without orderId.

Bootstrap

  1. Start from the component and market fromBlock values on Testnet Deployments.
  2. Discover markets from SpotRouter registration events and confirm them against AccountCore registration.
  3. Cache immutable market fields and current application-visible configuration.
  4. Replay all logs in order.
  5. Periodically compare balances, active slots, band state, and top-of-book views against the chain.

Source precedence

  • TradesPacked is required for execution-induced active and passive depth changes.
  • BookUpdatesPacked covers newly resting state and non-trade removals.
  • MATCH_END partitions fee and settlement groups inside one packed action.
  • SpotReserveUpdated is an AccountCore post-state snapshot. Apply every snapshot in log order; do not also apply Deposit, Withdrawal, or transfer as a second balance mutation.
  • PassiveBandUpdated is the passive inventory snapshot.
  • SpotSwap is a taker summary, not a complete trade tape.
Unknown record lengths, flags, enum values, or implementation code hashes must fail closed into an unsupported-version path rather than being decoded heuristically.