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 rewards accrued for this position.
/// This instruction works with both Token and Token-2022.
/// ### Authority
/// - `position_authority` - authority that owns the token corresponding to this
///   desired position.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CollectRewardV2 {
    pub reward_index: u8,
    pub remaining_accounts_info: Option<RemainingAccountsInfo>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectRewardV2InstructionAccounts {
    pub whirlpool: solana_pubkey::Pubkey,
    pub position_authority: solana_pubkey::Pubkey,
    pub position: solana_pubkey::Pubkey,
    pub position_token_account: solana_pubkey::Pubkey,
    pub reward_owner_account: solana_pubkey::Pubkey,
    pub reward_mint: solana_pubkey::Pubkey,
    pub reward_vault: solana_pubkey::Pubkey,
    pub reward_token_program: solana_pubkey::Pubkey,
    pub memo_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CollectRewardV2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [177, 107, 37, 180, 160, 19, 49, 209] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CollectRewardV2 {
    type ArrangedAccounts = CollectRewardV2InstructionAccounts;

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

        let whirlpool = next_account(&mut iter)?;
        let position_authority = next_account(&mut iter)?;
        let position = next_account(&mut iter)?;
        let position_token_account = next_account(&mut iter)?;
        let reward_owner_account = next_account(&mut iter)?;
        let reward_mint = next_account(&mut iter)?;
        let reward_vault = next_account(&mut iter)?;
        let reward_token_program = next_account(&mut iter)?;
        let memo_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CollectRewardV2InstructionAccounts {
            whirlpool,
            position_authority,
            position,
            position_token_account,
            reward_owner_account,
            reward_mint,
            reward_vault,
            reward_token_program,
            memo_program,
            remaining: remaining.to_vec(),
        })
    }
}