carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::RemainingAccountsInfo,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Collect the protocol fees accrued in this Whirlpool
/// This instruction works with both Token and Token-2022.
/// ### Authority
/// - `collect_protocol_fees_authority` - assigned authority in the
///   WhirlpoolConfig that can collect protocol fees
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CollectProtocolFeesV2 {
    pub remaining_accounts_info: Option<RemainingAccountsInfo>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectProtocolFeesV2InstructionAccounts {
    pub whirlpools_config: solana_pubkey::Pubkey,
    pub whirlpool: solana_pubkey::Pubkey,
    pub collect_protocol_fees_authority: solana_pubkey::Pubkey,
    pub token_mint_a: solana_pubkey::Pubkey,
    pub token_mint_b: solana_pubkey::Pubkey,
    pub token_vault_a: solana_pubkey::Pubkey,
    pub token_vault_b: solana_pubkey::Pubkey,
    pub token_destination_a: solana_pubkey::Pubkey,
    pub token_destination_b: solana_pubkey::Pubkey,
    pub token_program_a: solana_pubkey::Pubkey,
    pub token_program_b: solana_pubkey::Pubkey,
    pub memo_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CollectProtocolFeesV2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [103, 128, 222, 134, 114, 200, 22, 200] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CollectProtocolFeesV2 {
    type ArrangedAccounts = CollectProtocolFeesV2InstructionAccounts;

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

        let whirlpools_config = next_account(&mut iter)?;
        let whirlpool = next_account(&mut iter)?;
        let collect_protocol_fees_authority = next_account(&mut iter)?;
        let token_mint_a = next_account(&mut iter)?;
        let token_mint_b = next_account(&mut iter)?;
        let token_vault_a = next_account(&mut iter)?;
        let token_vault_b = next_account(&mut iter)?;
        let token_destination_a = next_account(&mut iter)?;
        let token_destination_b = next_account(&mut iter)?;
        let token_program_a = next_account(&mut iter)?;
        let token_program_b = next_account(&mut iter)?;
        let memo_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CollectProtocolFeesV2InstructionAccounts {
            whirlpools_config,
            whirlpool,
            collect_protocol_fees_authority,
            token_mint_a,
            token_mint_b,
            token_vault_a,
            token_vault_b,
            token_destination_a,
            token_destination_b,
            token_program_a,
            token_program_b,
            memo_program,
            remaining: remaining.to_vec(),
        })
    }
}