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 a variable-length tick array for a Whirlpool.
/// ### Parameters
/// - `start_tick_index` - The starting tick index for this tick-array.
///
/// Has to be a multiple of TickArray size & the tick spacing of this pool.
/// - `idempotent` - If true, the instruction will not fail if the tick array
///   already exists.
///
/// Note: The idempotent option exits successfully if a FixedTickArray is
/// present as well as a DynamicTickArray. #### Special Errors
/// - `InvalidStartTick` - if the provided start tick is out of bounds or is not
///   a multiple of
///
/// TICK_ARRAY_SIZE * tick spacing.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeDynamicTickArray {
    pub start_tick_index: i32,
    pub idempotent: bool,
}

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

impl InitializeDynamicTickArray {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [41, 33, 165, 200, 120, 231, 142, 50] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializeDynamicTickArray {
    type ArrangedAccounts = InitializeDynamicTickArrayInstructionAccounts;

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

        let whirlpool = next_account(&mut iter)?;
        let funder = next_account(&mut iter)?;
        let tick_array = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeDynamicTickArrayInstructionAccounts {
            whirlpool,
            funder,
            tick_array,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}