use steel::*;
use super::{treasury_pda, StreakAccount};
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Treasury {
pub daily_jackpot: u64,
pub weekly_jackpot: u64,
pub buyback: u64,
pub last_close_price: i64,
pub last_close_expo: i32,
pub _pad_close: [u8; 4],
pub last_close_publish_time: i64,
pub stability_reserve: u64,
}
impl Treasury {
pub fn pda() -> (Pubkey, u8) {
treasury_pda()
}
pub const LEGACY_BODY_LEN: usize = 48;
pub fn decode_account_data(data: &[u8]) -> Result<Self, &'static str> {
const DISC: usize = 8;
let body = data.get(DISC..).ok_or("treasury account empty")?;
let full = std::mem::size_of::<Self>();
if body.len() >= full {
return Ok(*bytemuck::from_bytes(&body[..full]));
}
if body.len() >= Self::LEGACY_BODY_LEN {
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct Legacy {
daily_jackpot: u64,
weekly_jackpot: u64,
buyback: u64,
last_close_price: i64,
last_close_expo: i32,
_pad_close: [u8; 4],
last_close_publish_time: i64,
}
let leg: &Legacy = bytemuck::from_bytes(&body[..Self::LEGACY_BODY_LEN]);
return Ok(Self {
daily_jackpot: leg.daily_jackpot,
weekly_jackpot: leg.weekly_jackpot,
buyback: leg.buyback,
last_close_price: leg.last_close_price,
last_close_expo: leg.last_close_expo,
_pad_close: leg._pad_close,
last_close_publish_time: leg.last_close_publish_time,
stability_reserve: 0,
});
}
Err("treasury account too short")
}
}
account!(StreakAccount, Treasury);