meteora-dbc-client 0.1.1

Rust SDK for Meteora Dynamic Bonding Curve 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::VolatilityTracker;
use solana_pubkey::Pubkey;
use crate::generated::types::PoolMetrics;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VirtualPool {
pub discriminator: [u8; 8],
/// volatility tracker
pub volatility_tracker: VolatilityTracker,
/// config key
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
pub config: Pubkey,
/// creator
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
pub creator: Pubkey,
/// base mint
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
pub base_mint: Pubkey,
/// base vault
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
pub base_vault: Pubkey,
/// quote vault
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
pub quote_vault: Pubkey,
/// base reserve
pub base_reserve: u64,
/// quote reserve
pub quote_reserve: u64,
/// protocol base fee
pub protocol_base_fee: u64,
/// protocol quote fee
pub protocol_quote_fee: u64,
/// partner base fee
pub partner_base_fee: u64,
/// trading quote fee
pub partner_quote_fee: u64,
/// current price
pub sqrt_price: u128,
/// Activation point
pub activation_point: u64,
/// pool type, spl token or token2022
pub pool_type: u8,
/// is migrated
pub is_migrated: u8,
/// is partner withdraw surplus
pub is_partner_withdraw_surplus: u8,
/// is protocol withdraw surplus
pub is_protocol_withdraw_surplus: u8,
/// migration progress
pub migration_progress: u8,
/// is withdraw leftover
pub is_withdraw_leftover: u8,
/// is creator withdraw surplus
pub is_creator_withdraw_surplus: u8,
/// migration fee withdraw status, first bit is for partner, second bit is for creator
pub migration_fee_withdraw_status: u8,
/// pool metrics
pub metrics: PoolMetrics,
/// The time curve is finished
pub finish_curve_timestamp: u64,
/// creator base fee
pub creator_base_fee: u64,
/// creator quote fee
pub creator_quote_fee: u64,
pub creation_fee_bits: u8,
pub padding0: [u8; 7],
/// Padding for further use
pub padding1: [u64; 6],
}


pub const VIRTUAL_POOL_DISCRIMINATOR: [u8; 8] = [213, 224, 5, 209, 98, 69, 119, 92];

impl VirtualPool {
      pub const LEN: usize = 424;
  
  
  
  #[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 VirtualPool {
  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_virtual_pool(
  rpc: &solana_client::rpc_client::RpcClient,
  address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<VirtualPool>, std::io::Error> {
  let accounts = fetch_all_virtual_pool(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_virtual_pool(
  rpc: &solana_client::rpc_client::RpcClient,
  addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<VirtualPool>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<VirtualPool>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      let account = accounts[i].as_ref()
        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
      let data = VirtualPool::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_virtual_pool(
  rpc: &solana_client::rpc_client::RpcClient,
  address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<VirtualPool>, std::io::Error> {
    let accounts = fetch_all_maybe_virtual_pool(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_virtual_pool(
  rpc: &solana_client::rpc_client::RpcClient,
  addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::MaybeAccount<VirtualPool>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<VirtualPool>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      if let Some(account) = accounts[i].as_ref() {
        let data = VirtualPool::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 VirtualPool {
      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
        Ok(Self::deserialize(buf)?)
      }
  }

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

  #[cfg(feature = "anchor")]
  impl anchor_lang::Owner for VirtualPool {
      fn owner() -> Pubkey {
        crate::DYNAMIC_BONDING_CURVE_ID
      }
  }

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

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