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};
/// Initializes a fixed-length tick_array account to represent a tick-range in 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.
/// #### 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 InitializeTickArray {
    pub start_tick_index: i32,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeTickArrayInstructionAccounts {
    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 InitializeTickArray {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [11, 188, 193, 214, 141, 91, 149, 184] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializeTickArray {
    type ArrangedAccounts = InitializeTickArrayInstructionAccounts;

    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(InitializeTickArrayInstructionAccounts {
            whirlpool,
            funder,
            tick_array,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}