Skip to main content

satrush_client/generated/accounts/
treasury.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11
12#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
13pub struct Treasury {
14pub discriminator: [u8; 8],
15/// Struct version.
16pub version: u16,
17/// PDA bump seed.
18pub bump: u8,
19/// USD protocol fees accrued and not yet withdrawn — the exact
20/// withdrawable amount, net of the affiliate share split off at rotation.
21pub protocol_fees_usd_amount: u64,
22/// BTC swept from no-winner rounds and not yet withdrawn;
23pub protocol_fees_btc_amount: u64,
24/// USD held for user airdrops (bonus funds for free rounds).
25/// Carved out of `reserved`, so pre-existing accounts read 0.
26pub grubstake_total_usd_amount: u64,
27/// Portion of the grubstake already promised to users and therefore not
28/// withdrawable. Carved out of `reserved`, so pre-existing accounts read 0.
29pub grubstake_reserved_usd_amount: u64,
30/// Total unclaimed affiliate grubstake USD: points swept in from closed
31/// rounds (their share of the protocol fee, split off before the fee
32/// joins `protocol_fees_usd_amount`) and not yet exchanged. Never touched
33/// by fee withdrawals. Carved out of `reserved`, so pre-existing accounts
34/// read 0.
35pub grubstake_affiliate_reserved_usd_amount: u64,
36/// USD buybacks fee accrued and not yet withdrawn. Kept apart from
37/// `protocol_fees_usd_amount` so buyback funds route and report
38/// separately; never touched by `withdraw_all`. Carved out of
39/// `reserved`, so pre-existing accounts read 0.
40pub buybacks_usd_amount: u64,
41}
42
43
44pub const TREASURY_DISCRIMINATOR: [u8; 8] = [238, 239, 123, 238, 89, 1, 168, 253];
45
46impl Treasury {
47      pub const LEN: usize = 59;
48  
49  
50  
51  #[inline(always)]
52  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
53    let mut data = data;
54    Self::deserialize(&mut data)
55  }
56}
57
58impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Treasury {
59  type Error = std::io::Error;
60
61  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
62      let mut data: &[u8] = &(*account_info.data).borrow();
63      Self::deserialize(&mut data)
64  }
65}
66
67#[cfg(feature = "fetch")]
68pub fn fetch_treasury(
69  rpc: &solana_rpc_client::rpc_client::RpcClient,
70  address: &solana_address::Address,
71) -> Result<crate::shared::DecodedAccount<Treasury>, std::io::Error> {
72  let accounts = fetch_all_treasury(rpc, &[*address])?;
73  Ok(accounts[0].clone())
74}
75
76#[cfg(feature = "fetch")]
77pub fn fetch_all_treasury(
78  rpc: &solana_rpc_client::rpc_client::RpcClient,
79  addresses: &[solana_address::Address],
80) -> Result<Vec<crate::shared::DecodedAccount<Treasury>>, std::io::Error> {
81    let accounts = rpc.get_multiple_accounts(addresses)
82      .map_err(|e| std::io::Error::other(e.to_string()))?;
83    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Treasury>> = Vec::new();
84    for i in 0..addresses.len() {
85      let address = addresses[i];
86      let account = accounts[i].as_ref()
87        .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
88      let data = Treasury::from_bytes(&account.data)?;
89      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
90    }
91    Ok(decoded_accounts)
92}
93
94#[cfg(feature = "fetch")]
95pub fn fetch_maybe_treasury(
96  rpc: &solana_rpc_client::rpc_client::RpcClient,
97  address: &solana_address::Address,
98) -> Result<crate::shared::MaybeAccount<Treasury>, std::io::Error> {
99    let accounts = fetch_all_maybe_treasury(rpc, &[*address])?;
100    Ok(accounts[0].clone())
101}
102
103#[cfg(feature = "fetch")]
104pub fn fetch_all_maybe_treasury(
105  rpc: &solana_rpc_client::rpc_client::RpcClient,
106  addresses: &[solana_address::Address],
107) -> Result<Vec<crate::shared::MaybeAccount<Treasury>>, std::io::Error> {
108    let accounts = rpc.get_multiple_accounts(addresses)
109      .map_err(|e| std::io::Error::other(e.to_string()))?;
110    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Treasury>> = Vec::new();
111    for i in 0..addresses.len() {
112      let address = addresses[i];
113      if let Some(account) = accounts[i].as_ref() {
114        let data = Treasury::from_bytes(&account.data)?;
115        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
116      } else {
117        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
118      }
119    }
120  Ok(decoded_accounts)
121}
122
123  #[cfg(feature = "anchor")]
124  impl anchor_lang::AccountDeserialize for Treasury {
125      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
126        Ok(Self::deserialize(buf)?)
127      }
128  }
129
130  #[cfg(feature = "anchor")]
131  impl anchor_lang::AccountSerialize for Treasury {}
132
133  #[cfg(feature = "anchor")]
134  impl anchor_lang::Owner for Treasury {
135      fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
136        anchor_lang::solana_program::pubkey::Pubkey::from(
137          crate::SATRUSH_ID.to_bytes()
138        )
139      }
140  }
141
142  #[cfg(feature = "anchor-idl-build")]
143  impl anchor_lang::IdlBuild for Treasury {}
144
145  
146  #[cfg(feature = "anchor-idl-build")]
147  impl anchor_lang::Discriminator for Treasury {
148    const DISCRIMINATOR: &[u8] = &[0; 8];
149  }
150