satrush-client 0.1.8

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 crate::generated::types::RoundState;
use crate::generated::types::TileStake;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Round {
pub discriminator: [u8; 8],
/// Struct version.
pub version: u16,
/// PDA bump seed.
pub bump: u8,
/// Sequential round identifier.
pub id: u32,
/// Round state
pub state: RoundState,
/// Raw blockhash entropy, read from the SlotHashes sysvar at reveal.
pub blockhash_entropy: [u8; 32],
/// Winning tile index, revealed upon settlement
pub winning_tile: Option<u8>,
/// Total net USD deployed into the round before the USD->BTC swap
pub deployed_pending_usd_amount: u64,
/// Total net USD stake after USD->BTC swap
pub deployed_usd_amount: u64,
/// Total net BTC stake after USD->BTC swap
pub deployed_btc_amount: u64,
/// Total net USD placed on the winning tile
pub deployed_usd_on_winning_tile_amount: u64,
/// Total amount of players in the round
pub miners_count: u32,
/// Number of miners whose selection is revealed.
pub revealed_miners_count: u32,
/// Total amount of winners, revealed during settlement
pub winners_count: u32,
/// Total amount of miners who claimed their winnings/hashrate, should equal to miners_count
pub settled_miners_count: u32,
/// Strike jackpot USD rolled into this round on trigger, distributed to winners.
pub strike_bonus_usd: u64,
/// Strike jackpot BTC rolled into this round on trigger, distributed to winners.
pub strike_bonus_btc: u64,
/// Per-tile deploy count and stake sum, accumulated as public miners deploy.
/// Indexed by tile (0..TILES_COUNT). Read at reveal to derive the winning
/// tile's totals without a per-deployment settlement pass.
pub public_tile_stakes: [TileStake; 21],
/// Running hash-chain accumulator of every public deploy.
pub deploy_entropy_acc: [u8; 32],
/// Slot at which the round reached `Settled` state.
pub settled_at_slot: u64,
/// Epoch Vault fee accrued by this round's deploys, in USD base units.
/// Physically sits in the board's USD pool until swept at rotation.
pub pending_epoch_fee_usd_amount: u64,
/// 1 BTC Vault fee accrued by this round's deploys; same lifecycle.
pub pending_one_btc_fee_usd_amount: u64,
/// Protocol (treasury) fee accrued by this round's deploys; same lifecycle.
pub pending_protocol_fee_usd_amount: u64,
/// Reserved.
pub reserved: [u8; 40],
}


pub const ROUND_DISCRIMINATOR: [u8; 8] = [87, 127, 165, 51, 73, 78, 116, 174];

impl Round {
  
  
  
  #[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 Round {
  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_round(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::DecodedAccount<Round>, std::io::Error> {
  let accounts = fetch_all_round(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_round(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::DecodedAccount<Round>>, 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<Round>> = 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 = Round::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_round(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::MaybeAccount<Round>, std::io::Error> {
    let accounts = fetch_all_maybe_round(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_round(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::MaybeAccount<Round>>, 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<Round>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      if let Some(account) = accounts[i].as_ref() {
        let data = Round::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 Round {
      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
        Ok(Self::deserialize(buf)?)
      }
  }

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

  #[cfg(feature = "anchor")]
  impl anchor_lang::Owner for Round {
      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 Round {}

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