Skip to main content

satrush_client/generated/accounts/
round.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 crate::generated::types::RoundState;
9use crate::generated::types::TileStake;
10use borsh::BorshSerialize;
11use borsh::BorshDeserialize;
12
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15pub struct Round {
16pub discriminator: [u8; 8],
17/// Struct version.
18pub version: u16,
19/// PDA bump seed.
20pub bump: u8,
21/// Sequential round identifier.
22pub id: u32,
23/// Round state
24pub state: RoundState,
25/// Entropy value, derived from the slot hashes
26pub entropy: [u8; 32],
27/// Winning tile index, revealed upon settlement
28pub winning_tile: Option<u8>,
29/// Total net USD deployed into the round before the USD->BTC swap
30pub deployed_pending_usd_amount: u64,
31/// Total net USD stake after USD->BTC swap
32pub deployed_usd_amount: u64,
33/// Total net BTC stake after USD->BTC swap
34pub deployed_btc_amount: u64,
35/// Total net USD placed on the winning tile
36pub deployed_usd_on_winning_tile_amount: u64,
37/// Total amount of players in the round
38pub miners_count: u32,
39/// Number of miners whose selection is revealed. Public deploys are revealed
40/// by construction, so they advance this counter at deploy time; future
41/// private deploys join `miners_count` first and catch up here on reveal.
42/// The round can only settle once it equals `miners_count`.
43pub revealed_miners_count: u32,
44/// Total amount of winners, revealed during settlement
45pub winners_count: u32,
46/// Total amount of miners who claimed their winnings/hashrate, should equal to miners_count
47pub settled_miners_count: u32,
48/// Strike jackpot USD rolled into this round on trigger, distributed to winners.
49pub strike_bonus_usd: u64,
50/// Strike jackpot BTC rolled into this round on trigger, distributed to winners.
51pub strike_bonus_btc: u64,
52/// Per-tile deploy count and stake sum, accumulated as public miners deploy.
53/// Indexed by tile (0..TILES_COUNT). Read at reveal to derive the winning
54/// tile's totals without a per-deployment settlement pass.
55pub public_tile_stakes: [TileStake; 21],
56/// Reserved.
57pub reserved: [u8; 32],
58}
59
60
61pub const ROUND_DISCRIMINATOR: [u8; 8] = [87, 127, 165, 51, 73, 78, 116, 174];
62
63impl Round {
64  
65  
66  
67  #[inline(always)]
68  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
69    let mut data = data;
70    Self::deserialize(&mut data)
71  }
72}
73
74impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Round {
75  type Error = std::io::Error;
76
77  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
78      let mut data: &[u8] = &(*account_info.data).borrow();
79      Self::deserialize(&mut data)
80  }
81}
82
83#[cfg(feature = "fetch")]
84pub fn fetch_round(
85  rpc: &solana_rpc_client::rpc_client::RpcClient,
86  address: &solana_address::Address,
87) -> Result<crate::shared::DecodedAccount<Round>, std::io::Error> {
88  let accounts = fetch_all_round(rpc, &[*address])?;
89  Ok(accounts[0].clone())
90}
91
92#[cfg(feature = "fetch")]
93pub fn fetch_all_round(
94  rpc: &solana_rpc_client::rpc_client::RpcClient,
95  addresses: &[solana_address::Address],
96) -> Result<Vec<crate::shared::DecodedAccount<Round>>, std::io::Error> {
97    let accounts = rpc.get_multiple_accounts(addresses)
98      .map_err(|e| std::io::Error::other(e.to_string()))?;
99    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Round>> = Vec::new();
100    for i in 0..addresses.len() {
101      let address = addresses[i];
102      let account = accounts[i].as_ref()
103        .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
104      let data = Round::from_bytes(&account.data)?;
105      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
106    }
107    Ok(decoded_accounts)
108}
109
110#[cfg(feature = "fetch")]
111pub fn fetch_maybe_round(
112  rpc: &solana_rpc_client::rpc_client::RpcClient,
113  address: &solana_address::Address,
114) -> Result<crate::shared::MaybeAccount<Round>, std::io::Error> {
115    let accounts = fetch_all_maybe_round(rpc, &[*address])?;
116    Ok(accounts[0].clone())
117}
118
119#[cfg(feature = "fetch")]
120pub fn fetch_all_maybe_round(
121  rpc: &solana_rpc_client::rpc_client::RpcClient,
122  addresses: &[solana_address::Address],
123) -> Result<Vec<crate::shared::MaybeAccount<Round>>, std::io::Error> {
124    let accounts = rpc.get_multiple_accounts(addresses)
125      .map_err(|e| std::io::Error::other(e.to_string()))?;
126    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Round>> = Vec::new();
127    for i in 0..addresses.len() {
128      let address = addresses[i];
129      if let Some(account) = accounts[i].as_ref() {
130        let data = Round::from_bytes(&account.data)?;
131        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
132      } else {
133        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
134      }
135    }
136  Ok(decoded_accounts)
137}
138
139  #[cfg(feature = "anchor")]
140  impl anchor_lang::AccountDeserialize for Round {
141      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
142        Ok(Self::deserialize(buf)?)
143      }
144  }
145
146  #[cfg(feature = "anchor")]
147  impl anchor_lang::AccountSerialize for Round {}
148
149  #[cfg(feature = "anchor")]
150  impl anchor_lang::Owner for Round {
151      fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
152        anchor_lang::solana_program::pubkey::Pubkey::from(
153          crate::SATRUSH_ID.to_bytes()
154        )
155      }
156  }
157
158  #[cfg(feature = "anchor-idl-build")]
159  impl anchor_lang::IdlBuild for Round {}
160
161  
162  #[cfg(feature = "anchor-idl-build")]
163  impl anchor_lang::Discriminator for Round {
164    const DISCRIMINATOR: &[u8] = &[0; 8];
165  }
166