carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// (permissionless) Harvest rewards from admin deposits in Drift spot markets.
/// Rewards are always sent to the global fee wallet's canonical ATA.
/// The harvest spot market must be different from the bank's main drift spot
/// market.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct DriftHarvestReward {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DriftHarvestRewardInstructionAccounts {
    pub bank: solana_pubkey::Pubkey,
    pub fee_state: solana_pubkey::Pubkey,
    pub liquidity_vault_authority: solana_pubkey::Pubkey,
    pub intermediary_token_account: solana_pubkey::Pubkey,
    pub destination_token_account: solana_pubkey::Pubkey,
    pub drift_state: solana_pubkey::Pubkey,
    pub integration_acc2: solana_pubkey::Pubkey,
    pub integration_acc3: solana_pubkey::Pubkey,
    pub harvest_drift_spot_market: solana_pubkey::Pubkey,
    pub harvest_drift_spot_market_vault: solana_pubkey::Pubkey,
    pub drift_signer: solana_pubkey::Pubkey,
    pub reward_mint: solana_pubkey::Pubkey,
    pub drift_program: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl DriftHarvestReward {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [167, 161, 240, 194, 138, 54, 87, 189] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for DriftHarvestReward {
    type ArrangedAccounts = DriftHarvestRewardInstructionAccounts;

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

        let bank = next_account(&mut iter)?;
        let fee_state = next_account(&mut iter)?;
        let liquidity_vault_authority = next_account(&mut iter)?;
        let intermediary_token_account = next_account(&mut iter)?;
        let destination_token_account = next_account(&mut iter)?;
        let drift_state = next_account(&mut iter)?;
        let integration_acc2 = next_account(&mut iter)?;
        let integration_acc3 = next_account(&mut iter)?;
        let harvest_drift_spot_market = next_account(&mut iter)?;
        let harvest_drift_spot_market_vault = next_account(&mut iter)?;
        let drift_signer = next_account(&mut iter)?;
        let reward_mint = next_account(&mut iter)?;
        let drift_program = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(DriftHarvestRewardInstructionAccounts {
            bank,
            fee_state,
            liquidity_vault_authority,
            intermediary_token_account,
            destination_token_account,
            drift_state,
            integration_acc2,
            integration_acc3,
            harvest_drift_spot_market,
            harvest_drift_spot_market_vault,
            drift_signer,
            reward_mint,
            drift_program,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}