//! Protocol USDC custody (`treasury` PDA).
//!
//! The treasury serves two roles:
//!
//! 1. **USDC custodian** — the treasury ATA holds all deposited USDC. Deposits come in via
//!    `Deposit`; payouts go out via `AdminPayout` (executor-signed).
//!
//! 2. **Price chain** — `last_close_*` carries the Pyth close price from the most recently
//!    settled period. `AdminInstantSettlement` reads it as the open reference and writes the
//!    new close price back, forming a self-perpetuating chain. Zero until `Initialize` seeds it.

use steel::*;

use super::{treasury_pda, StreakAccount};

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Treasury {
    /// Daily jackpot pool — credited on `Deposit`; debited via `AdminPayout`.
    pub daily_jackpot: u64,
    /// Weekly jackpot pool — credited on `Deposit`; debited via `AdminPayout`.
    pub weekly_jackpot: u64,
    /// Buyback reserve.
    pub buyback: u64,
    /// Close price from the most recently settled period — used as the open reference
    /// for the next settlement. Zero until `Initialize` seeds it.
    pub last_close_price: i64,
    /// Pyth exponent matching `last_close_price`.
    pub last_close_expo: i32,
    pub _pad_close: [u8; 4],
    /// `publish_time` from the Pyth feed at last settlement.
    pub last_close_publish_time: i64,
}

impl Treasury {
    pub fn pda() -> (Pubkey, u8) {
        treasury_pda()
    }
}

account!(StreakAccount, Treasury);
