orca_wavebreak 2.0.0

The wavebreak rust client to interact with the wavebreak 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::AccountDiscriminator;
use crate::generated::types::GraduationMethodData;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BondingCurve {
    pub discriminator: AccountDiscriminator,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub base_mint: Pubkey,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub quote_mint: Pubkey,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub creator: Pubkey,
    pub retain_mint_authority: bool,
    pub buy_requires_permission: bool,
    pub buy_permission_bitmap: [u8; 32],
    pub sell_requires_permission: bool,
    pub sell_permission_bitmap: [u8; 32],
    pub quote_fee_bps: u16,
    pub base_fee_bps: u16,
    pub control_points: [u16; 4],
    pub start_price: u128,
    pub end_price: u128,
    pub quote_amount: u64,
    pub base_amount: u64,
    pub launch_time: i64,
    pub creator_reward: u64,
    pub graduation_target: u64,
    pub graduation_time: i64,
    pub graduation_reward: u64,
    pub max_buy_amount: u64,
    pub max_sell_amount: u64,
    pub swap_fee_bps: u16,
    pub base_allocation_bps: u16,
    pub graduation_methods: [GraduationMethodData; 8],
    pub min_reserve_bps: u16,
    pub padding1: [u8; 2],
    pub preminted_supply: u64,
    #[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
    pub padding2: [u8; 728],
}

pub const BONDING_CURVE_DISCRIMINATOR: AccountDiscriminator = AccountDiscriminator::BondingCurve;

impl BondingCurve {
    pub const LEN: usize = 2048;

    #[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 BondingCurve {
    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_bonding_curve(
    rpc: &solana_client::rpc_client::RpcClient,
    address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<BondingCurve>, std::io::Error> {
    let accounts = fetch_all_bonding_curve(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_bonding_curve(
    rpc: &solana_client::rpc_client::RpcClient,
    addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<BondingCurve>>, 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<BondingCurve>> = 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 = BondingCurve::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_bonding_curve(
    rpc: &solana_client::rpc_client::RpcClient,
    address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<BondingCurve>, std::io::Error> {
    let accounts = fetch_all_maybe_bonding_curve(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

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

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

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

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

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