meteora-pools-sdk 0.1.1

Rust SDK for Meteora Pools 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::types::Bootstrapping;
use crate::types::CurveType;
use crate::types::Padding;
use crate::types::PartnerInfo;
use crate::types::PoolFees;
use crate::types::PoolType;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

/// State of pool account

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pool {
    pub discriminator: [u8; 8],
    /// LP token mint of the pool
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub lp_mint: Pubkey,
    /// Token A mint of the pool. Eg: USDT
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub token_a_mint: Pubkey,
    /// Token B mint of the pool. Eg: USDC
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub token_b_mint: Pubkey,
    /// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub a_vault: Pubkey,
    /// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub b_vault: Pubkey,
    /// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub a_vault_lp: Pubkey,
    /// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub b_vault_lp: Pubkey,
    /// "A" vault lp bump. Used to create signer seeds.
    pub a_vault_lp_bump: u8,
    /// Flag to determine whether the pool is enabled, or disabled.
    pub enabled: bool,
    /// Protocol fee token account for token A. Used to receive trading fee.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub protocol_token_a_fee: Pubkey,
    /// Protocol fee token account for token B. Used to receive trading fee.
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub protocol_token_b_fee: Pubkey,
    /// Fee last updated timestamp
    pub fee_last_updated_at: u64,
    pub padding0: [u8; 24],
    /// Store the fee charges setting.
    pub fees: PoolFees,
    /// Pool type
    pub pool_type: PoolType,
    /// Stake pubkey of SPL stake pool
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub stake: Pubkey,
    /// Total locked lp token
    pub total_locked_lp: u64,
    /// bootstrapping config
    pub bootstrapping: Bootstrapping,
    pub partner_info: PartnerInfo,
    /// Padding for future pool field
    pub padding: Padding,
    /// The type of the swap curve supported by the pool.
    pub curve_type: CurveType,
}

impl Pool {
    #[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_program::account_info::AccountInfo<'a>> for Pool {
    type Error = std::io::Error;

    fn try_from(
        account_info: &solana_program::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_pool(
    rpc: &solana_client::rpc_client::RpcClient,
    address: &Pubkey,
) -> Result<super::DecodedAccount<Pool>, Error> {
    let accounts = fetch_all_pool(rpc, vec![address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_pool(
    rpc: &solana_client::rpc_client::RpcClient,
    addresses: Vec<Pubkey>,
) -> Result<Vec<super::DecodedAccount<Pool>>, Error> {
    let accounts = rpc.get_multiple_accounts(&addresses)?;
    let mut decoded_accounts: Vec<super::DecodedAccount<Pool>> = Vec::new();
    for i in 0..addresses.len() {
        let address = addresses[i];
        let account = accounts[i]
            .as_ref()
            .ok_or(format!("Account not found: {}", address))?;
        let data = Pool::from_bytes(&account.data)?;
        decoded_accounts.push(super::DecodedAccount {
            address,
            account: account.clone(),
            data,
        });
    }
    Ok(decoded_accounts)
}

#[cfg(feature = "fetch")]
pub fn fetch_maybe_pool(
    rpc: &solana_client::rpc_client::RpcClient,
    address: &Pubkey,
) -> Result<super::MaybeAccount<Pool>, Error> {
    let accounts = fetch_all_maybe_pool(rpc, vec![address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_pool(
    rpc: &solana_client::rpc_client::RpcClient,
    addresses: Vec<Pubkey>,
) -> Result<Vec<super::MaybeAccount<Pool>>, Error> {
    let accounts = rpc.get_multiple_accounts(&addresses)?;
    let mut decoded_accounts: Vec<super::MaybeAccount<Pool>> = Vec::new();
    for i in 0..addresses.len() {
        let address = addresses[i];
        if let Some(account) = accounts[i].as_ref() {
            let data = Pool::from_bytes(&account.data)?;
            decoded_accounts.push(super::MaybeAccount::Exists(super::DecodedAccount {
                address,
                account: account.clone(),
                data,
            }));
        } else {
            decoded_accounts.push(super::MaybeAccount::NotFound(address));
        }
    }
    Ok(decoded_accounts)
}

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

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

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

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

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