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` | `AdminPayout` ix | Bot confirms payout in DB |
10//! | `Initialized` | `Initialize` ix | One-time setup confirmation |
11
12use steel::*;
13
14/// Emitted by `Initialize`.
15#[repr(C)]
16#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
17pub struct Initialized {
18    pub admin: Pubkey,
19}
20
21/// Emitted by `BuyTicket`.
22///
23/// Indexer reads this event to credit the user's spendable balance in `user_balances`.
24/// Buying tickets is separate from placing a bet; the bet is placed off-chain by the server.
25#[repr(C)]
26#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
27pub struct TicketPurchased {
28    /// Wallet that purchased the credits.
29    pub user: Pubkey,
30    /// µUSDC spent (gross, before split).
31    pub amount: u64,
32}
33
34/// Emitted by `AdminRouteFees`.
35#[repr(C)]
36#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
37pub struct FeesRouted {
38    pub amount: u64,
39    pub daily_share: u64,
40    pub weekly_share: u64,
41    pub buyback_share: u64,
42    pub team_share: u64,
43}
44
45/// Emitted by `AdminPayout`.
46#[repr(C)]
47#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
48pub struct Paid {
49    pub recipient: Pubkey,
50    pub amount: u64,
51    pub series_id: u16,
52    pub _pad: [u8; 6],
53    pub period: u64,
54}
55
56/// Emitted by `PlaceBet`.
57///
58/// Cost is always `TICKET_PRICE_MICROS` (1 USDC) — no amount field needed.
59/// Indexer reads this to insert into `bets` and update `markets` pool totals.
60#[repr(C)]
61#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
62pub struct BetPlaced {
63    /// Wallet that placed the bet.
64    pub user: Pubkey,
65    /// 5-min period: `floor(unix_ts / 300)`.
66    pub period: u64,
67    /// 0 = UP, 1 = DOWN.
68    pub side: u8,
69    pub _pad: [u8; 7],
70}
71
72event!(Initialized);
73event!(TicketPurchased);
74event!(BetPlaced);
75event!(FeesRouted);
76event!(Paid);