carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Initialize reward for a Whirlpool. A pool can only support up to a set
/// number of rewards. ### Authority
/// - "reward_authority" - assigned authority by the reward_super_authority for
///   the specified
///
/// reward-index in this Whirlpool
/// ### Parameters
/// - `reward_index` - The reward index that we'd like to initialize. (0 <=
///   index <= NUM_REWARDS)
///
/// #### Special Errors
/// - `InvalidRewardIndex` - If the provided reward index doesn't match the
///   lowest uninitialized
///
/// index in this pool, or exceeds NUM_REWARDS, or
/// all reward slots for this pool has been initialized.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeReward {
    pub reward_index: u8,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeRewardInstructionAccounts {
    pub reward_authority: solana_pubkey::Pubkey,
    pub funder: solana_pubkey::Pubkey,
    pub whirlpool: solana_pubkey::Pubkey,
    pub reward_mint: solana_pubkey::Pubkey,
    pub reward_vault: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl InitializeReward {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [95, 135, 192, 196, 242, 129, 230, 68] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializeReward {
    type ArrangedAccounts = InitializeRewardInstructionAccounts;

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

        let reward_authority = next_account(&mut iter)?;
        let funder = next_account(&mut iter)?;
        let whirlpool = next_account(&mut iter)?;
        let reward_mint = next_account(&mut iter)?;
        let reward_vault = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeRewardInstructionAccounts {
            reward_authority,
            funder,
            whirlpool,
            reward_mint,
            reward_vault,
            token_program,
            system_program,
            rent,
            remaining: remaining.to_vec(),
        })
    }
}