Skip to main content

defi_tracker_lifecycle/
types.rs

1/// A decoded Solana instruction row as produced by the upstream indexer.
2#[derive(serde::Deserialize)]
3pub struct RawInstruction {
4    /// Database row id.
5    pub id: i64,
6    /// Transaction signature (base58).
7    pub signature: String,
8    /// Position of this instruction within the transaction.
9    pub instruction_index: i32,
10    /// Hierarchical instruction path within the transaction (for example `"4.1"`).
11    #[serde(default)]
12    pub instruction_path: Option<String>,
13    /// Top-level program that was invoked.
14    pub program_id: String,
15    /// Innermost program if this is a CPI; equals `program_id` otherwise.
16    pub inner_program_id: String,
17    /// Carbon-decoded instruction discriminator name (e.g. `"OpenDca"`).
18    pub instruction_name: String,
19    /// Parsed account list, if available.
20    pub accounts: Option<serde_json::Value>,
21    /// Parsed instruction arguments, if available.
22    pub args: Option<serde_json::Value>,
23    /// Solana slot in which the transaction landed.
24    pub slot: i64,
25}
26
27/// A decoded Solana event (log) row as produced by the upstream indexer.
28#[derive(serde::Deserialize)]
29pub struct RawEvent {
30    /// Database row id.
31    pub id: i64,
32    /// Transaction signature (base58).
33    pub signature: String,
34    /// Position of this event within the transaction logs.
35    pub event_index: i32,
36    /// Hierarchical event path within the transaction (for example `"4.1"`).
37    #[serde(default)]
38    pub event_path: Option<String>,
39    /// Top-level program that was invoked.
40    pub program_id: String,
41    /// Innermost program if this is a CPI; equals `program_id` otherwise.
42    pub inner_program_id: String,
43    /// Carbon-decoded event discriminator name (e.g. `"FilledEvent"`).
44    pub event_name: String,
45    /// Parsed event fields as `{"EventName": {..}}` JSON.
46    pub fields: Option<serde_json::Value>,
47    /// Solana slot in which the transaction landed.
48    pub slot: i64,
49}
50
51impl RawEvent {
52    /// Returns the parent instruction path for this event, if `event_path` is present.
53    pub fn parent_instruction_path(&self) -> Option<&str> {
54        self.event_path
55            .as_deref()
56            .map(Self::parent_instruction_path_from)
57    }
58
59    /// Strips the final nested segment from an event path to recover the parent instruction path.
60    pub fn parent_instruction_path_from(event_path: &str) -> &str {
61        event_path
62            .rsplit_once('.')
63            .map_or(event_path, |(instruction_path, _)| instruction_path)
64    }
65}
66
67/// Caller-supplied context needed to resolve certain events.
68///
69/// Kamino `OrderDisplayEvent` carries no order PDA in its payload.
70/// The caller should use raw path metadata when available to pre-fetch the
71/// exact order PDA from the matching instruction, then pass the result here
72/// so the adapter can correlate the event.
73pub struct ResolveContext {
74    /// Order PDAs extracted from instruction accounts for the same transaction.
75    /// Required for Kamino `OrderDisplayEvent`; `None` causes `Uncorrelated`.
76    pub pre_fetched_order_pdas: Option<Vec<String>>,
77}