Skip to main content

streak_api/state/
user.rs

1//! Per-user account — one PDA per wallet.
2//!
3//! Created on first `BuyTicket` call.
4//!
5//! * `balance`         — spendable credits in µUSDC (decremented by `PlaceBet`).
6//! * `total_purchased` — lifetime µUSDC spent on tickets (never decreases).
7//! * `last_bet_period` — period of the most recent `PlaceBet` (enforces one bet per round).
8//!
9//! PDA seeds: `[USER_TICKET, user_pubkey]`
10
11use steel::*;
12
13use super::{user_pda, StreakAccount};
14
15#[repr(C)]
16#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
17pub struct User {
18    /// Wallet that owns this account.
19    pub user: Pubkey,
20    /// Available µUSDC credits — incremented by `BuyTicket`, decremented by `PlaceBet`.
21    pub balance: u64,
22    /// Cumulative µUSDC spent on tickets (never decreases).
23    pub total_purchased: u64,
24    /// Period of the last `PlaceBet`. 0 = never bet.
25    /// Used to prevent double-betting in the same round.
26    pub last_bet_period: u64,
27}
28
29impl User {
30    pub fn pda(user: &Pubkey) -> (Pubkey, u8) {
31        user_pda(user)
32    }
33}
34
35account!(StreakAccount, User);