Skip to main content

carbon_orca_whirlpool_decoder/instructions/
initialize_dynamic_tick_array.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Initialize a variable-length tick array for a Whirlpool.
4/// ### Parameters
5/// - `start_tick_index` - The starting tick index for this tick-array.
6///
7/// Has to be a multiple of TickArray size & the tick spacing of this pool.
8/// - `idempotent` - If true, the instruction will not fail if the tick array
9///   already exists.
10///
11/// Note: The idempotent option exits successfully if a FixedTickArray is
12/// present as well as a DynamicTickArray. #### Special Errors
13/// - `InvalidStartTick` - if the provided start tick is out of bounds or is not
14///   a multiple of
15///
16/// TICK_ARRAY_SIZE * tick spacing.
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
19pub struct InitializeDynamicTickArray {
20    pub start_tick_index: i32,
21    pub idempotent: bool,
22}
23
24#[derive(Debug, Clone, PartialEq)]
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26pub struct InitializeDynamicTickArrayInstructionAccounts {
27    pub whirlpool: solana_pubkey::Pubkey,
28    pub funder: solana_pubkey::Pubkey,
29    pub tick_array: solana_pubkey::Pubkey,
30    pub system_program: solana_pubkey::Pubkey,
31    pub remaining: Vec<solana_instruction::AccountMeta>,
32}
33
34impl InitializeDynamicTickArray {
35    pub fn decode(data: &[u8]) -> Option<Self> {
36        if data.len() < 8 {
37            return None;
38        }
39        let discriminator = &data[0..8];
40        if discriminator != [41, 33, 165, 200, 120, 231, 142, 50] {
41            return None;
42        }
43
44        let mut data_slice = data;
45
46        data_slice = &data_slice[8..];
47
48        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
49    }
50}
51
52impl ArrangeAccounts for InitializeDynamicTickArray {
53    type ArrangedAccounts = InitializeDynamicTickArrayInstructionAccounts;
54
55    fn arrange_accounts(
56        accounts: &[solana_instruction::AccountMeta],
57    ) -> Option<Self::ArrangedAccounts> {
58        let mut iter = accounts.iter();
59
60        let whirlpool = next_account(&mut iter)?;
61        let funder = next_account(&mut iter)?;
62        let tick_array = next_account(&mut iter)?;
63        let system_program = next_account(&mut iter)?;
64
65        let remaining = iter.as_slice();
66
67        Some(InitializeDynamicTickArrayInstructionAccounts {
68            whirlpool,
69            funder,
70            tick_array,
71            system_program,
72            remaining: remaining.to_vec(),
73        })
74    }
75}