satrush-client 0.1.14

Rust client to interact with SatRush's on-chain program.
Documentation
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Board {
pub discriminator: [u8; 8],
/// Struct version.
pub version: u16,
/// PDA bump seed.
pub bump: u8,
/// Current active round id.
pub round_id: u32,
/// Round duration in slots.
pub round_duration: u32,
/// The slot at which the current round starts mining.
pub start_slot: u64,
/// The slot at which the current round ends mining.
pub end_slot: u64,
/// Strike jackpot USD amount waiting to be swapped.
/// Swaps are executed in the background when pending
/// amount reaches the certain threshold.
pub strike_pending_usd_amount: u64,
/// Strike jackpot USD amount after the swap
pub strike_usd_amount: u64,
/// Strike jackpot BTC amount after the swap
pub strike_btc_amount: u64,
/// Last round_id when Strike jackpot was triggered
pub strike_last_trigger_round_id: u32,
/// Strike reserve USD: a savings jar fed 5% of the pot on each trigger,
/// contributing 10% of its balance back into the next carry seed.
pub strike_reserve_usd_amount: u64,
/// Strike reserve BTC leg.
pub strike_reserve_btc_amount: u64,
/// The round rotor's settlement counter (`index + burned`), snapshotted
/// when the current round was activated and its rotor armed at `end_slot`.
/// Rotation requires the live counter to have advanced past this — the
/// proof that the rotor settled randomness for this round (the armed
/// `reveal_slot` itself is zeroed on settlement, so this is the binder).
pub rotor_arm_counter: u64,
/// Strike jackpot token pot: the 14% strike leg of every round's mint
/// (plus rerouted player legs with no claimant), physically in the
/// board's token ATA. Starts where the v1 layout's 6 zeroed reserved
/// bytes were; `migrate_board` grows the account and zero-fills from
/// there, so it reads 0 after the migration.
pub strike_token_amount: u64,
/// Strike reserve token leg (5% of the pot on each trigger).
pub strike_reserve_token_amount: u64,
/// Reserved. Sized so the data after the discriminator is a multiple of
/// 8 (144 bytes): a future `#[repr(C)]` zero-copy layout of `u64`s needs
/// exactly that to cast the account in place.
pub reserved: [u8; 49],
}


pub const BOARD_DISCRIMINATOR: [u8; 8] = [79, 48, 160, 63, 153, 132, 240, 56];

impl Board {
      pub const LEN: usize = 152;
  
  
  
  #[inline(always)]
  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
    let mut data = data;
    Self::deserialize(&mut data)
  }
}

impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Board {
  type Error = std::io::Error;

  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
      let mut data: &[u8] = &(*account_info.data).borrow();
      Self::deserialize(&mut data)
  }
}

#[cfg(feature = "fetch")]
pub fn fetch_board(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::DecodedAccount<Board>, std::io::Error> {
  let accounts = fetch_all_board(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_board(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::DecodedAccount<Board>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::other(e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Board>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      let account = accounts[i].as_ref()
        .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
      let data = Board::from_bytes(&account.data)?;
      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
    }
    Ok(decoded_accounts)
}

#[cfg(feature = "fetch")]
pub fn fetch_maybe_board(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::MaybeAccount<Board>, std::io::Error> {
    let accounts = fetch_all_maybe_board(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_board(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::MaybeAccount<Board>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::other(e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Board>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      if let Some(account) = accounts[i].as_ref() {
        let data = Board::from_bytes(&account.data)?;
        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
      } else {
        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
      }
    }
  Ok(decoded_accounts)
}

  #[cfg(feature = "anchor")]
  impl anchor_lang::AccountDeserialize for Board {
      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
        Ok(Self::deserialize(buf)?)
      }
  }

  #[cfg(feature = "anchor")]
  impl anchor_lang::AccountSerialize for Board {}

  #[cfg(feature = "anchor")]
  impl anchor_lang::Owner for Board {
      fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
        anchor_lang::solana_program::pubkey::Pubkey::from(
          crate::SATRUSH_ID.to_bytes()
        )
      }
  }

  #[cfg(feature = "anchor-idl-build")]
  impl anchor_lang::IdlBuild for Board {}

  
  #[cfg(feature = "anchor-idl-build")]
  impl anchor_lang::Discriminator for Board {
    const DISCRIMINATOR: &[u8] = &[0; 8];
  }