Skip to main content

rialo_oracle_processor_interface/
event.rs

1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Events emitted by the Oracle Processor program.
5//!
6//! This module defines the events that are emitted when oracle reports are stored.
7//! Subscribers can use these events to react to oracle data updates without relying
8//! on aggregator programs.
9
10use rialo_events_core::derive::RialoEvent;
11use rialo_types::OracleId;
12use serde::Serialize;
13
14/// Event emitted when an oracle report is stored.
15///
16/// This event is emitted after a report is successfully written to the report PDA.
17/// Subscribers can listen to this event to react to oracle data updates.
18///
19/// # Topic Format
20///
21/// The event uses a parameterized topic with the oracle_id as the dynamic parameter.
22/// Topic format: `rialo_oracle_processor_interface::event::OracleReportEvent::{oracle_id}`
23/// where `oracle_id` is in the string format `{nonce}:{creator}`.
24///
25/// # Example Usage
26///
27/// Subscribers can:
28/// 1. Create an event instance: `let event = OracleReportEvent::new(oracle_id);`
29/// 2. Get the instance topic: `let topic = event.instance_topic();`
30/// 3. Subscribe to the topic for a specific oracle
31/// 4. Use `derive_report_address()` to get the report PDA from the oracle_id
32/// 5. Read the full `OracleReport` data from the PDA
33#[derive(Debug, Default, Clone, Serialize, RialoEvent)]
34pub struct OracleReportEvent {
35    /// The oracle ID - marked with #\[topic] to create instance-specific topics
36    #[topic]
37    pub oracle_id: OracleId,
38}
39
40impl OracleReportEvent {
41    /// Creates a new `OracleReportEvent`.
42    ///
43    /// # Arguments
44    ///
45    /// * `oracle_id` - The oracle ID
46    pub fn new(oracle_id: OracleId) -> Self {
47        Self { oracle_id }
48    }
49}