Skip to main content

hypercall_db/types/
replay.rs

1//! Engine journal replay types.
2//!
3//! Wire-format command/event records fetched during engine startup to
4//! reconstruct state after a snapshot load.
5
6use serde::{Deserialize, Serialize};
7use strum::{Display, EnumString};
8
9/// Engine event type. Mirrors the `engine_event_type` Postgres enum without
10/// any ORM dependency.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Display, EnumString)]
12pub enum EventType {
13    OrderAction,
14    OrderUpdate,
15    OrderInfo,
16    MarketAction,
17    MarketUpdate,
18    OrderFilled,
19    OrderbookUpdated,
20    L2Update,
21    Trade,
22    TransactionRequest,
23    TransactionUpdate,
24    MmpTriggered,
25    PositionExpired,
26    TierUpdate,
27    HypercorePositionUpdate,
28    LiquidationStateChange,
29    RfqFilled,
30}
31
32/// A deserialized engine event used during portfolio replay after snapshot load.
33#[derive(Debug, Clone)]
34pub struct PortfolioReplayEvent {
35    pub command_id: i64,
36    pub event_type: EventType,
37    /// Raw msgpack event payload (wire format: `[version: u8][msgpack]`).
38    pub event_data: Vec<u8>,
39}
40
41/// A journal command fetched for engine replay.
42///
43/// Contains the raw wire-format bytes for both command and response. Decoding
44/// into typed messages happens in the engine layer (depends on `hypercall-types`),
45/// not at the DB trait boundary.
46#[derive(Debug, Clone)]
47pub struct ReplayCommand {
48    pub command_id: i64,
49    pub request_id: String,
50    pub command_type: String,
51    /// Wire-format bytes: `[version: u8][msgpack payload]`
52    pub command_data: Vec<u8>,
53    /// Response wire bytes. Used to determine final order state (filled, open,
54    /// partially_filled, cancelled) so replay can reconstruct correct resting
55    /// quantity without re-running matching.
56    pub response_data: Option<Vec<u8>>,
57}