carbon-meteora-vault-decoder 1.0.0

Meteora vault program decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Withdraw v2. Withdraw from token vault if no remaining accounts are
/// available. Else, it will attempt to withdraw from strategy and token vault.
/// This method just proxy between 2 methods. Protocol integration should be
/// using withdraw instead of this function.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Withdraw2 {
    pub unmint_amount: u64,
    pub min_out_amount: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Withdraw2InstructionAccounts {
    pub vault: solana_pubkey::Pubkey,
    pub token_vault: solana_pubkey::Pubkey,
    pub lp_mint: solana_pubkey::Pubkey,
    pub user_token: solana_pubkey::Pubkey,
    pub user_lp: solana_pubkey::Pubkey,
    pub user: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl Withdraw2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [80, 6, 111, 73, 174, 211, 66, 132] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}

impl ArrangeAccounts for Withdraw2 {
    type ArrangedAccounts = Withdraw2InstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let vault = next_account(&mut iter)?;
        let token_vault = next_account(&mut iter)?;
        let lp_mint = next_account(&mut iter)?;
        let user_token = next_account(&mut iter)?;
        let user_lp = next_account(&mut iter)?;
        let user = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(Withdraw2InstructionAccounts {
            vault,
            token_vault,
            lp_mint,
            user_token,
            user_lp,
            user,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}