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};
/// user withdraw liquidity from vault, if vault reserve doesn't have enough
/// liquidity, it will withdraw from the strategy firstly
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct WithdrawDirectlyFromStrategy {
    pub unmint_amount: u64,
    pub min_out_amount: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WithdrawDirectlyFromStrategyInstructionAccounts {
    pub vault: solana_pubkey::Pubkey,
    pub strategy: solana_pubkey::Pubkey,
    pub reserve: solana_pubkey::Pubkey,
    pub strategy_program: solana_pubkey::Pubkey,
    pub collateral_vault: solana_pubkey::Pubkey,
    pub token_vault: solana_pubkey::Pubkey,
    pub lp_mint: solana_pubkey::Pubkey,
    pub fee_vault: 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 WithdrawDirectlyFromStrategy {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [201, 141, 146, 46, 173, 116, 198, 22] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for WithdrawDirectlyFromStrategy {
    type ArrangedAccounts = WithdrawDirectlyFromStrategyInstructionAccounts;

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

        let vault = next_account(&mut iter)?;
        let strategy = next_account(&mut iter)?;
        let reserve = next_account(&mut iter)?;
        let strategy_program = next_account(&mut iter)?;
        let collateral_vault = next_account(&mut iter)?;
        let token_vault = next_account(&mut iter)?;
        let lp_mint = next_account(&mut iter)?;
        let fee_vault = 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(WithdrawDirectlyFromStrategyInstructionAccounts {
            vault,
            strategy,
            reserve,
            strategy_program,
            collateral_vault,
            token_vault,
            lp_mint,
            fee_vault,
            user_token,
            user_lp,
            user,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}