streak_api/state/user.rs
1//! Per-user account — one PDA per wallet.
2//!
3//! Created on first `BuyTicket` call.
4//!
5//! * `balance` — on-chain ticket credits in µUSDC (from `BuyTicket`).
6//! * `total_purchased` — lifetime µUSDC spent on tickets (never decreases).
7//! * `last_bet_period` — legacy field (unused; bets are server-authoritative).
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 /// On-chain ticket credits from `BuyTicket` (mirrored to DB by indexer).
21 pub balance: u64,
22 /// Cumulative µUSDC spent on tickets (never decreases).
23 pub total_purchased: u64,
24 /// Legacy — retained for account layout compatibility.
25 pub last_bet_period: u64,
26}
27
28impl User {
29 pub fn pda(user: &Pubkey) -> (Pubkey, u8) {
30 user_pda(user)
31 }
32}
33
34account!(StreakAccount, User);