streak_api/event.rs
1//! On-chain events (`sol_log_data` via Steel `event!` / `.log()`).
2//!
3//! The server and indexer subscribe to these events to maintain the off-chain state:
4//! user balances, bet records, market outcomes, leaderboard history.
5//!
6//! ## Event contract
7//!
8//! | Event | Trigger | Observer action |
9//! |---|---|---|
10//! | `Deposited` | `Deposit` ix | Indexer credits user's off-chain USDC balance |
11//! | `PeriodSettled` | `AdminInstantSettlement` | Bot computes + dispatches payouts; DB records outcome |
12//! | `Paid` | `AdminPayout` | Bot confirms payout in DB |
13//! | `Initialized` | `Initialize` | One-time setup confirmation |
14
15use steel::*;
16
17/// Emitted by `Initialize`.
18#[repr(C)]
19#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
20pub struct Initialized {
21 pub admin: Pubkey,
22}
23
24/// Emitted by `Deposit`. Server credits `user`'s off-chain balance by `amount` µUSDC.
25#[repr(C)]
26#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
27pub struct Deposited {
28 pub user: Pubkey,
29 pub amount: u64,
30}
31
32/// Emitted by `AdminInstantSettlement`. Server reads this to compute and enqueue payouts.
33///
34/// `outcome` = `0` (UP) or `1` (DOWN).
35/// `close_price` / `close_expo` / `close_publish_time` are the Pyth values read at settlement.
36/// The open reference was `Treasury::last_close_*` immediately before this instruction ran.
37#[repr(C)]
38#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
39pub struct PeriodSettled {
40 pub series_id: u16,
41 pub outcome: u8,
42 pub _pad: [u8; 5],
43 pub period: u64,
44 pub close_price: i64,
45 pub close_expo: i32,
46 pub _pad2: [u8; 4],
47 pub close_publish_time: i64,
48 /// Open reference price that was in Treasury before this settlement.
49 pub open_price: i64,
50 pub open_expo: i32,
51 pub _pad3: [u8; 4],
52}
53
54/// Emitted by `AdminPayout`. Bot confirms the payout was delivered.
55#[repr(C)]
56#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
57pub struct Paid {
58 pub recipient: Pubkey,
59 pub amount: u64,
60 pub series_id: u16,
61 pub _pad: [u8; 6],
62 pub period: u64,
63}
64
65event!(Initialized);
66event!(Deposited);
67event!(PeriodSettled);
68event!(Paid);