Skip to main content

streak_api/
instruction.rs

1//! Instruction discriminators + payload types.
2//!
3//! The on-chain program is a thin USDC custody + price-chain layer.
4//! All game logic (bets, balances, pools, leaderboards) is off-chain.
5
6use steel::*;
7
8/// One-time setup: creates `Treasury` PDA + treasury USDC ATA and seeds the genesis BTC close
9/// price from the Pyth push feed. `payer` must be `ADMIN_ADDRESS`.
10///
11/// **Accounts:** `payer`, `treasury`, `mint`, `treasury_ata`, `system_program`, `token_program`,
12/// `ata_program`, `pyth_price_feed`.
13#[repr(C)]
14#[derive(Clone, Copy, Debug, Pod, Zeroable)]
15pub struct Initialize {}
16
17/// User deposits USDC into the treasury. Emits `Deposited { user, amount }` so the server can
18/// credit the user's off-chain balance.
19///
20/// **Accounts:** `user` (signer), `user_ata`, `treasury_ata`, `mint`, `token_program`.
21#[repr(C)]
22#[derive(Clone, Copy, Debug, Pod, Zeroable)]
23pub struct Deposit {
24    pub amount: [u8; 8],
25}
26
27/// Advance the price chain: read `Treasury::last_close_*` as the open reference, read the Pyth
28/// push feed as the close price, resolve UP/DOWN, emit `PeriodSettled`, and write the close price
29/// back to `Treasury::last_close_*`.
30///
31/// **Authority**: `EXECUTOR_ADDRESS` (outcome is deterministic so could be permissionless).
32///
33/// **Accounts:** `authority` (signer), `treasury` (writable), `pyth_price_feed`.
34#[repr(C)]
35#[derive(Clone, Copy, Debug, Pod, Zeroable)]
36pub struct AdminInstantSettlement {
37    pub series_id: [u8; 2],
38    pub _pad_ix: [u8; 6],
39    pub period: [u8; 8],
40}
41
42/// Pay `amount` µUSDC from the treasury ATA to `recipient_ata`. Used for winner payouts, jackpot
43/// distributions, and withdrawals. Only `EXECUTOR_ADDRESS` may sign.
44///
45/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `recipient_ata`, `mint`,
46/// `token_program`.
47#[repr(C)]
48#[derive(Clone, Copy, Debug, Pod, Zeroable)]
49pub struct AdminPayout {
50    pub amount: [u8; 8],
51    pub series_id: [u8; 2],
52    pub _pad_ix: [u8; 6],
53    pub period: [u8; 8],
54}
55
56use num_enum::TryFromPrimitive;
57
58#[repr(u8)]
59#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
60pub enum StreakInstruction {
61    Initialize = 0,
62    Deposit = 1,
63    AdminInstantSettlement = 2,
64    AdminPayout = 3,
65}
66
67instruction!(StreakInstruction, Initialize);
68instruction!(StreakInstruction, Deposit);
69instruction!(StreakInstruction, AdminInstantSettlement);
70instruction!(StreakInstruction, AdminPayout);