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/// Indexer reads this to insert into `bets` and update `markets` pool totals.
59#[repr(C)]
60#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
61pub struct BetPlaced {
62 /// Wallet that placed the bet.
63 pub user: Pubkey,
64 /// 5-min period: `floor(unix_ts / 300)`.
65 pub period: u64,
66 /// µUSDC staked.
67 pub amount: u64,
68 /// 0 = UP, 1 = DOWN.
69 pub side: u8,
70 pub _pad: [u8; 7],
71}
72
73event!(Initialized);
74event!(TicketPurchased);
75event!(BetPlaced);
76event!(FeesRouted);
77event!(Paid);