streak_api/instruction.rs
1//! Instruction discriminators + payload types.
2
3use steel::*;
4
5/// One-time setup: creates `Treasury` PDA + treasury USDC ATA. `payer` must be `ADMIN_ADDRESS`.
6///
7/// **Accounts:** `payer`, `treasury`, `mint`, `treasury_ata`, `system_program`, `token_program`,
8/// `ata_program`.
9#[repr(C)]
10#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11pub struct Initialize {}
12
13/// Purchase tickets (gaming credits) with USDC.
14///
15/// Buying tickets is separate from placing a bet. The user first buys credits here
16/// (on-chain, USDC split immediately), then places bets off-chain via the server
17/// using those credits.
18///
19/// 1. Transfers `amount` µUSDC from the user's ATA into the treasury ATA.
20/// 2. Updates `Treasury` PDA counters: `daily_jackpot += 70%`, `weekly_jackpot += 15%`,
21/// `buyback += 10%`.
22/// 3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
23/// 4. Creates or increments the user's `UserCredits` PDA (`total_purchased += amount`).
24/// 5. Emits `TicketPurchased { user, amount }`.
25///
26/// The indexer reads `TicketPurchased` events to credit the user's off-chain spendable
27/// balance. Bets are placed and debited server-side against that balance.
28///
29/// **Accounts:** `user` (signer/payer), `user_ata`, `treasury`, `treasury_ata`, `credits`,
30/// `fee_collector_ata`, `mint`, `token_program`, `system_program`.
31#[repr(C)]
32#[derive(Clone, Copy, Debug, Pod, Zeroable)]
33pub struct BuyTicket {
34 /// Amount in µUSDC (6 decimals).
35 pub amount: [u8; 8],
36}
37
38/// Route claimed DBC / DAMM v2 trading fees into the treasury and split them on-chain.
39///
40/// The executor bot claims pool creator/LP fees off-chain via the Meteora SDK, receiving USDC
41/// into its own ATA. This instruction then:
42/// 1. Transfers `amount` µUSDC from the executor's ATA into the treasury ATA (CPI).
43/// 2. Splits the amount according to `TICKET_*_BPS` and updates `Treasury` counters.
44/// 3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
45/// 4. Emits `FeesRouted`.
46///
47/// **Accounts:** `executor` (signer), `executor_ata`, `treasury`, `treasury_ata`,
48/// `fee_collector_ata`, `mint`, `token_program`.
49#[repr(C)]
50#[derive(Clone, Copy, Debug, Pod, Zeroable)]
51pub struct AdminRouteFees {
52 pub amount: [u8; 8],
53}
54
55/// Pay `amount` µUSDC from the treasury ATA to `recipient_ata`. Used for winner payouts and
56/// jackpot distributions. Only `EXECUTOR_ADDRESS` may sign.
57///
58/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `recipient_ata`, `mint`,
59/// `token_program`.
60#[repr(C)]
61#[derive(Clone, Copy, Debug, Pod, Zeroable)]
62pub struct AdminPayout {
63 pub amount: [u8; 8],
64 pub series_id: [u8; 2],
65 /// Which treasury counter to debit (`PAYOUT_POOL_*`). Zero = bet payout only.
66 pub pool: u8,
67 pub _pad_ix: [u8; 5],
68 pub period: [u8; 8],
69}
70
71/// Executor-only: overwrite treasury pool counters (one-shot reconcile).
72///
73/// Enforces `daily + weekly + buyback + stability <= treasury_ata.amount`.
74///
75/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `mint`, `token_program`,
76/// `system_program`.
77#[repr(C)]
78#[derive(Clone, Copy, Debug, Pod, Zeroable)]
79pub struct AdminSetTreasuryPools {
80 pub daily_jackpot: [u8; 8],
81 pub weekly_jackpot: [u8; 8],
82 pub buyback: [u8; 8],
83 pub stability_reserve: [u8; 8],
84}
85
86use num_enum::TryFromPrimitive;
87
88#[repr(u8)]
89#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
90pub enum StreakInstruction {
91 Initialize = 0,
92 BuyTicket = 1,
93 AdminRouteFees = 2,
94 AdminPayout = 3,
95 /// Reserved — was `PlaceBet` (removed; bets are server-authoritative).
96 _ReservedPlaceBet = 4,
97 AdminSetTreasuryPools = 5,
98}
99
100instruction!(StreakInstruction, Initialize);
101instruction!(StreakInstruction, BuyTicket);
102instruction!(StreakInstruction, AdminRouteFees);
103instruction!(StreakInstruction, AdminPayout);
104instruction!(StreakInstruction, AdminSetTreasuryPools);