streak-api 0.3.18

API for interacting with the STREAK directional markets protocol on Solana
Documentation
//! Instruction discriminators + payload types.

use steel::*;

/// One-time setup: creates `Treasury` PDA + treasury USDC ATA. `payer` must be `ADMIN_ADDRESS`.
///
/// **Accounts:** `payer`, `treasury`, `mint`, `treasury_ata`, `system_program`, `token_program`,
/// `ata_program`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {}

/// Purchase tickets (gaming credits) with USDC.
///
/// Buying tickets is separate from placing a bet. The user first buys credits here
/// (on-chain, USDC split immediately), then places bets off-chain via the server
/// using those credits.
///
/// 1. Transfers `amount` µUSDC from the user's ATA into the treasury ATA.
/// 2. Updates `Treasury` PDA counters: `daily_accrual += 70%`, `weekly_jackpot += 15%`,
///    `buyback += 10%`.
/// 3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
/// 4. Creates or increments the user's `UserCredits` PDA (`total_purchased += amount`).
/// 5. Emits `TicketPurchased { user, amount }`.
///
/// The indexer reads `TicketPurchased` events to credit the user's off-chain spendable
/// balance. Bets are placed and debited server-side against that balance.
///
/// **Accounts:** `user` (signer/payer), `user_ata`, `treasury`, `treasury_ata`, `credits`,
///               `fee_collector_ata`, `mint`, `token_program`, `system_program`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct BuyTicket {
    /// Amount in µUSDC (6 decimals).
    pub amount: [u8; 8],
}

/// Route claimed DBC / DAMM v2 trading fees into the treasury and split them on-chain.
///
/// The executor bot claims pool creator/LP fees off-chain via the Meteora SDK, receiving USDC
/// into its own ATA. This instruction then:
///   1. Transfers `amount` µUSDC from the executor's ATA into the treasury ATA (CPI).
///   2. Splits the amount according to `TICKET_*_BPS` and updates `Treasury` counters.
///   3. Forwards the team share (5%) from the treasury ATA to `FEE_COLLECTOR` (CPI).
///   4. Emits `FeesRouted`.
///
/// **Accounts:** `executor` (signer), `executor_ata`, `treasury`, `treasury_ata`,
///               `fee_collector_ata`, `mint`, `token_program`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AdminRouteFees {
    pub amount: [u8; 8],
}

/// Transfer µUSDC from the treasury vault to a recipient ATA.
///
/// `pool` selects which jackpot counter to debit:
/// - `DISBURSE_POOL_NONE` — bet-round winners (vault only; counters unchanged)
/// - `DISBURSE_POOL_DAILY` — daily jackpot winners
/// - `DISBURSE_POOL_WEEKLY` — weekly jackpot winners (partial release; call
///   `AdminFinalizeWeekly` afterward to sweep leftover accrual → stability)
///
/// Only `EXECUTOR_ADDRESS` may sign. Emits `Paid`.
///
/// **Accounts:** `executor` (signer), `treasury`, `treasury_ata`, `recipient_ata`, `mint`,
/// `token_program`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AdminDisburseFromTreasury {
    pub amount: [u8; 8],
    pub series_id: [u8; 2],
    /// Which treasury counter to debit (`DISBURSE_POOL_*`).
    pub pool: u8,
    pub _pad_ix: [u8; 5],
    pub period: [u8; 8],
}

/// Executor-only: sweep remaining `weekly_jackpot` into `stability_reserve` at week end.
///
/// No USDC transfer — accounting only. Emits `WeeklyFinalized`.
///
/// **Accounts:** `executor` (signer), `treasury`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AdminFinalizeWeekly {}

/// Executor-only: sweep remaining `daily_jackpot` into `stability_reserve` at UTC day end.
///
/// No USDC transfer — accounting only. Emits `DailyFinalized`.
///
/// **Accounts:** `executor` (signer), `treasury`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AdminFinalizeDaily {}

/// T+1 rotation: move `daily_accrual` → `daily_jackpot` for the next UTC day.
///
/// Requires `daily_jackpot == 0` (call `AdminFinalizeDaily` first). Emits `DailyRotated`.
///
/// **Accounts:** `executor` (signer), `treasury`.
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AdminRotateDailyVault {}

use num_enum::TryFromPrimitive;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum StreakInstruction {
    Initialize = 0,
    BuyTicket = 1,
    AdminRouteFees = 2,
    AdminDisburseFromTreasury = 3,
    /// Reserved — was `PlaceBet` (removed; bets are server-authoritative).
    _ReservedPlaceBet = 4,
    /// Reserved — was `AdminSetTreasuryPools` (one-shot reconcile; removed post-migration).
    _ReservedSetTreasuryPools = 5,
    AdminFinalizeWeekly = 6,
    AdminFinalizeDaily = 7,
    AdminRotateDailyVault = 8,
}

instruction!(StreakInstruction, Initialize);
instruction!(StreakInstruction, BuyTicket);
instruction!(StreakInstruction, AdminRouteFees);
instruction!(StreakInstruction, AdminDisburseFromTreasury);
instruction!(StreakInstruction, AdminFinalizeWeekly);
instruction!(StreakInstruction, AdminFinalizeDaily);
instruction!(StreakInstruction, AdminRotateDailyVault);