Skip to main content

streak_api/
event.rs

1//! On-chain events (`sol_log_data` via Steel `event!` / `.log()`).
2//!
3//! ## Event contract
4//!
5//! | Event | Trigger | Observer |
6//! |---|---|---|
7//! | `TicketPurchased` | `BuyTicket` ix | Indexer records ticket; bot uses for payout calculation |
8//! | `FeesRouted` | `AdminRouteFees` ix | Off-chain ledger updates protocol revenue |
9//! | `Paid` | `AdminDisburseFromTreasury` ix | Bot confirms payout in DB |
10//! | `DailyFinalized` | `AdminFinalizeDaily` ix | Indexer syncs pool counters |
11//! | `DailyRotated` | `AdminRotateDailyVault` ix | Indexer syncs pool counters |
12//! | `Initialized` | `Initialize` ix | One-time setup confirmation |
13
14use steel::*;
15
16/// Emitted by `Initialize`.
17#[repr(C)]
18#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
19pub struct Initialized {
20    pub admin: Pubkey,
21}
22
23/// Emitted by `BuyTicket`.
24///
25/// Indexer reads this event to credit the user's spendable balance in `user_balances`.
26/// Buying tickets is separate from placing a bet; the bet is placed off-chain by the server.
27#[repr(C)]
28#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
29pub struct TicketPurchased {
30    /// Wallet that purchased the credits.
31    pub user: Pubkey,
32    /// µUSDC spent (gross, before split).
33    pub amount: u64,
34}
35
36/// Emitted by `AdminRouteFees`.
37#[repr(C)]
38#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
39pub struct FeesRouted {
40    pub amount: u64,
41    pub daily_share: u64,
42    pub weekly_share: u64,
43    pub buyback_share: u64,
44    pub team_share: u64,
45}
46
47/// Emitted by `AdminDisburseFromTreasury`.
48#[repr(C)]
49#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
50pub struct Paid {
51    pub recipient: Pubkey,
52    pub amount: u64,
53    pub series_id: u16,
54    pub _pad: [u8; 6],
55    pub period: u64,
56}
57
58/// Emitted by `AdminFinalizeWeekly`.
59#[repr(C)]
60#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
61pub struct WeeklyFinalized {
62    pub moved_to_stability: u64,
63}
64
65/// Emitted by `AdminFinalizeDaily`.
66#[repr(C)]
67#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
68pub struct DailyFinalized {
69    pub moved_to_stability: u64,
70}
71
72/// Emitted by `AdminRotateDailyVault`.
73#[repr(C)]
74#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
75pub struct DailyRotated {
76    pub vault_locked: u64,
77}
78
79event!(Initialized);
80event!(TicketPurchased);
81event!(FeesRouted);
82event!(Paid);
83event!(WeeklyFinalized);
84event!(DailyFinalized);
85event!(DailyRotated);