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 solana_address::Address;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct SatrushConfig {
pub discriminator: [u8; 8],
/// Struct version.
pub version: u16,
/// Bump seed for the config account.
pub bump: u8,
/// Owner of the program. Can change ownership and set the admin of the program.
pub owner_authority: Address,
/// Current update authority address for both Config and other PDAs - can be updated.
pub admin_authority: Address,
/// Address of the authority controlling the round flow.
pub round_authority: Address,
/// Protocol fees recipient address.
pub fee_recipient: Address,
/// USD mint address, initially USDC
pub usd_mint: Address,
/// BTC mint address, initially cbBTC
pub btc_mint: Address,
/// Strike jackpot fee in basis points.
pub strike_fee_bps: u32,
/// Epoch Vault fee in basis points.
pub epoch_fee_bps: u32,
/// 1 BTC Vault fee in basis points.
pub one_btc_fee_bps: u32,
/// Sats Vault fee in basis points of the gross deployed amount. Charged
/// at swap time against the pending pile (gross net of the deploy-time
/// legs), so `Round::swap_amount` rescales it by `deploy_fees_bps`.
pub sats_vault_round_fee_bps: u32,
/// Sats Vault claim fee in basis points.
pub sats_vault_claim_fee_bps: u32,
/// Protocol fee in basis points.
pub protocol_fee_bps: u32,
/// Share of each settled play's hashrate reward deferred until the sats claim in basis points.
pub unclaimed_hashrate_bps: u32,
/// Minimum gross deploy size per round, manual or automated, in USD mint (6 decimals).
pub min_deploy_usd_amount: u64,
/// Epoch Vault iteration length in slots.
pub epoch_vault_iteration_duration: u64,
/// Grace window, in slots after `Round::settled_at_slot`, during which
/// only the normal settle path applies; afterward stale deployments
/// become eligible for third-party cleanup
pub deployment_settle_grace_duration: u64,
/// Sat Strike odds: the jackpot fires when `rng % strike_trigger_modulus == 0`
/// (seeded at 1_440 for ~1/1440 odds; 1 = every round triggers).
pub strike_trigger_modulus: u16,
/// Reserved
pub reserved: [u8; 30],
}


pub const SATRUSH_CONFIG_DISCRIMINATOR: [u8; 8] = [113, 169, 164, 118, 148, 217, 160, 200];

impl SatrushConfig {
      pub const LEN: usize = 287;
  
  
  
  #[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 SatrushConfig {
  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_satrush_config(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::DecodedAccount<SatrushConfig>, std::io::Error> {
  let accounts = fetch_all_satrush_config(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

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

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

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

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

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