Skip to main content

orca_sol/instructions/
initialize_tick_array.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct InitializeTickArray {
14    pub whirlpool: solana_pubkey::Pubkey,
15
16    pub funder: solana_pubkey::Pubkey,
17
18    pub tick_array: solana_pubkey::Pubkey,
19
20    pub system_program: solana_pubkey::Pubkey,
21}
22
23impl InitializeTickArray {
24    pub fn instruction(
25        &self,
26        args: InitializeTickArrayInstructionArgs,
27    ) -> solana_instruction::Instruction {
28        self.instruction_with_remaining_accounts(args, &[])
29    }
30    #[allow(clippy::arithmetic_side_effects)]
31    #[allow(clippy::vec_init_then_push)]
32    pub fn instruction_with_remaining_accounts(
33        &self,
34        args: InitializeTickArrayInstructionArgs,
35        remaining_accounts: &[solana_instruction::AccountMeta],
36    ) -> solana_instruction::Instruction {
37        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
38        accounts.push(solana_instruction::AccountMeta::new_readonly(
39            self.whirlpool,
40            false,
41        ));
42        accounts.push(solana_instruction::AccountMeta::new(self.funder, true));
43        accounts.push(solana_instruction::AccountMeta::new(self.tick_array, false));
44        accounts.push(solana_instruction::AccountMeta::new_readonly(
45            self.system_program,
46            false,
47        ));
48        accounts.extend_from_slice(remaining_accounts);
49        let mut data = borsh::to_vec(&InitializeTickArrayInstructionData::new()).unwrap();
50        let mut args = borsh::to_vec(&args).unwrap();
51        data.append(&mut args);
52
53        solana_instruction::Instruction {
54            program_id: crate::WHIRLPOOL_ID,
55            accounts,
56            data,
57        }
58    }
59}
60
61#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63pub struct InitializeTickArrayInstructionData {
64    discriminator: [u8; 8],
65}
66
67impl InitializeTickArrayInstructionData {
68    pub fn new() -> Self {
69        Self {
70            discriminator: [11, 188, 193, 214, 141, 91, 149, 184],
71        }
72    }
73}
74
75impl Default for InitializeTickArrayInstructionData {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub struct InitializeTickArrayInstructionArgs {
84    pub start_tick_index: i32,
85}
86
87/// Instruction builder for `InitializeTickArray`.
88///
89/// ### Accounts:
90///
91///   0. `[]` whirlpool
92///   1. `[writable, signer]` funder
93///   2. `[writable]` tick_array
94///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
95#[derive(Clone, Debug, Default)]
96pub struct InitializeTickArrayBuilder {
97    whirlpool: Option<solana_pubkey::Pubkey>,
98    funder: Option<solana_pubkey::Pubkey>,
99    tick_array: Option<solana_pubkey::Pubkey>,
100    system_program: Option<solana_pubkey::Pubkey>,
101    start_tick_index: Option<i32>,
102    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
103}
104
105impl InitializeTickArrayBuilder {
106    pub fn new() -> Self {
107        Self::default()
108    }
109    #[inline(always)]
110    pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
111        self.whirlpool = Some(whirlpool);
112        self
113    }
114    #[inline(always)]
115    pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
116        self.funder = Some(funder);
117        self
118    }
119    #[inline(always)]
120    pub fn tick_array(&mut self, tick_array: solana_pubkey::Pubkey) -> &mut Self {
121        self.tick_array = Some(tick_array);
122        self
123    }
124    /// `[optional account, default to '11111111111111111111111111111111']`
125    #[inline(always)]
126    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
127        self.system_program = Some(system_program);
128        self
129    }
130    #[inline(always)]
131    pub fn start_tick_index(&mut self, start_tick_index: i32) -> &mut Self {
132        self.start_tick_index = Some(start_tick_index);
133        self
134    }
135    /// Add an additional account to the instruction.
136    #[inline(always)]
137    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
138        self.__remaining_accounts.push(account);
139        self
140    }
141    /// Add additional accounts to the instruction.
142    #[inline(always)]
143    pub fn add_remaining_accounts(
144        &mut self,
145        accounts: &[solana_instruction::AccountMeta],
146    ) -> &mut Self {
147        self.__remaining_accounts.extend_from_slice(accounts);
148        self
149    }
150    #[allow(clippy::clone_on_copy)]
151    pub fn instruction(&self) -> solana_instruction::Instruction {
152        let accounts = InitializeTickArray {
153            whirlpool: self.whirlpool.expect("whirlpool is not set"),
154            funder: self.funder.expect("funder is not set"),
155            tick_array: self.tick_array.expect("tick_array is not set"),
156            system_program: self
157                .system_program
158                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
159        };
160        let args = InitializeTickArrayInstructionArgs {
161            start_tick_index: self
162                .start_tick_index
163                .clone()
164                .expect("start_tick_index is not set"),
165        };
166
167        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
168    }
169}
170
171/// `initialize_tick_array` CPI accounts.
172pub struct InitializeTickArrayCpiAccounts<'a, 'b> {
173    pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
174
175    pub funder: &'b solana_account_info::AccountInfo<'a>,
176
177    pub tick_array: &'b solana_account_info::AccountInfo<'a>,
178
179    pub system_program: &'b solana_account_info::AccountInfo<'a>,
180}
181
182/// `initialize_tick_array` CPI instruction.
183pub struct InitializeTickArrayCpi<'a, 'b> {
184    /// The program to invoke.
185    pub __program: &'b solana_account_info::AccountInfo<'a>,
186
187    pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
188
189    pub funder: &'b solana_account_info::AccountInfo<'a>,
190
191    pub tick_array: &'b solana_account_info::AccountInfo<'a>,
192
193    pub system_program: &'b solana_account_info::AccountInfo<'a>,
194    /// The arguments for the instruction.
195    pub __args: InitializeTickArrayInstructionArgs,
196}
197
198impl<'a, 'b> InitializeTickArrayCpi<'a, 'b> {
199    pub fn new(
200        program: &'b solana_account_info::AccountInfo<'a>,
201        accounts: InitializeTickArrayCpiAccounts<'a, 'b>,
202        args: InitializeTickArrayInstructionArgs,
203    ) -> Self {
204        Self {
205            __program: program,
206            whirlpool: accounts.whirlpool,
207            funder: accounts.funder,
208            tick_array: accounts.tick_array,
209            system_program: accounts.system_program,
210            __args: args,
211        }
212    }
213    #[inline(always)]
214    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
215        self.invoke_signed_with_remaining_accounts(&[], &[])
216    }
217    #[inline(always)]
218    pub fn invoke_with_remaining_accounts(
219        &self,
220        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
221    ) -> solana_program_entrypoint::ProgramResult {
222        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
223    }
224    #[inline(always)]
225    pub fn invoke_signed(
226        &self,
227        signers_seeds: &[&[&[u8]]],
228    ) -> solana_program_entrypoint::ProgramResult {
229        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
230    }
231    #[allow(clippy::arithmetic_side_effects)]
232    #[allow(clippy::clone_on_copy)]
233    #[allow(clippy::vec_init_then_push)]
234    pub fn invoke_signed_with_remaining_accounts(
235        &self,
236        signers_seeds: &[&[&[u8]]],
237        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
238    ) -> solana_program_entrypoint::ProgramResult {
239        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
240        accounts.push(solana_instruction::AccountMeta::new_readonly(
241            *self.whirlpool.key,
242            false,
243        ));
244        accounts.push(solana_instruction::AccountMeta::new(*self.funder.key, true));
245        accounts.push(solana_instruction::AccountMeta::new(
246            *self.tick_array.key,
247            false,
248        ));
249        accounts.push(solana_instruction::AccountMeta::new_readonly(
250            *self.system_program.key,
251            false,
252        ));
253        remaining_accounts.iter().for_each(|remaining_account| {
254            accounts.push(solana_instruction::AccountMeta {
255                pubkey: *remaining_account.0.key,
256                is_signer: remaining_account.1,
257                is_writable: remaining_account.2,
258            })
259        });
260        let mut data = borsh::to_vec(&InitializeTickArrayInstructionData::new()).unwrap();
261        let mut args = borsh::to_vec(&self.__args).unwrap();
262        data.append(&mut args);
263
264        let instruction = solana_instruction::Instruction {
265            program_id: crate::WHIRLPOOL_ID,
266            accounts,
267            data,
268        };
269        let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
270        account_infos.push(self.__program.clone());
271        account_infos.push(self.whirlpool.clone());
272        account_infos.push(self.funder.clone());
273        account_infos.push(self.tick_array.clone());
274        account_infos.push(self.system_program.clone());
275        remaining_accounts
276            .iter()
277            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
278
279        if signers_seeds.is_empty() {
280            solana_cpi::invoke(&instruction, &account_infos)
281        } else {
282            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
283        }
284    }
285}
286
287/// Instruction builder for `InitializeTickArray` via CPI.
288///
289/// ### Accounts:
290///
291///   0. `[]` whirlpool
292///   1. `[writable, signer]` funder
293///   2. `[writable]` tick_array
294///   3. `[]` system_program
295#[derive(Clone, Debug)]
296pub struct InitializeTickArrayCpiBuilder<'a, 'b> {
297    instruction: Box<InitializeTickArrayCpiBuilderInstruction<'a, 'b>>,
298}
299
300impl<'a, 'b> InitializeTickArrayCpiBuilder<'a, 'b> {
301    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
302        let instruction = Box::new(InitializeTickArrayCpiBuilderInstruction {
303            __program: program,
304            whirlpool: None,
305            funder: None,
306            tick_array: None,
307            system_program: None,
308            start_tick_index: None,
309            __remaining_accounts: Vec::new(),
310        });
311        Self { instruction }
312    }
313    #[inline(always)]
314    pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
315        self.instruction.whirlpool = Some(whirlpool);
316        self
317    }
318    #[inline(always)]
319    pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
320        self.instruction.funder = Some(funder);
321        self
322    }
323    #[inline(always)]
324    pub fn tick_array(
325        &mut self,
326        tick_array: &'b solana_account_info::AccountInfo<'a>,
327    ) -> &mut Self {
328        self.instruction.tick_array = Some(tick_array);
329        self
330    }
331    #[inline(always)]
332    pub fn system_program(
333        &mut self,
334        system_program: &'b solana_account_info::AccountInfo<'a>,
335    ) -> &mut Self {
336        self.instruction.system_program = Some(system_program);
337        self
338    }
339    #[inline(always)]
340    pub fn start_tick_index(&mut self, start_tick_index: i32) -> &mut Self {
341        self.instruction.start_tick_index = Some(start_tick_index);
342        self
343    }
344    /// Add an additional account to the instruction.
345    #[inline(always)]
346    pub fn add_remaining_account(
347        &mut self,
348        account: &'b solana_account_info::AccountInfo<'a>,
349        is_writable: bool,
350        is_signer: bool,
351    ) -> &mut Self {
352        self.instruction
353            .__remaining_accounts
354            .push((account, is_writable, is_signer));
355        self
356    }
357    /// Add additional accounts to the instruction.
358    ///
359    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
360    /// and a `bool` indicating whether the account is a signer or not.
361    #[inline(always)]
362    pub fn add_remaining_accounts(
363        &mut self,
364        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
365    ) -> &mut Self {
366        self.instruction
367            .__remaining_accounts
368            .extend_from_slice(accounts);
369        self
370    }
371    #[inline(always)]
372    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
373        self.invoke_signed(&[])
374    }
375    #[allow(clippy::clone_on_copy)]
376    #[allow(clippy::vec_init_then_push)]
377    pub fn invoke_signed(
378        &self,
379        signers_seeds: &[&[&[u8]]],
380    ) -> solana_program_entrypoint::ProgramResult {
381        let args = InitializeTickArrayInstructionArgs {
382            start_tick_index: self
383                .instruction
384                .start_tick_index
385                .clone()
386                .expect("start_tick_index is not set"),
387        };
388        let instruction = InitializeTickArrayCpi {
389            __program: self.instruction.__program,
390
391            whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
392
393            funder: self.instruction.funder.expect("funder is not set"),
394
395            tick_array: self.instruction.tick_array.expect("tick_array is not set"),
396
397            system_program: self
398                .instruction
399                .system_program
400                .expect("system_program is not set"),
401            __args: args,
402        };
403        instruction.invoke_signed_with_remaining_accounts(
404            signers_seeds,
405            &self.instruction.__remaining_accounts,
406        )
407    }
408}
409
410#[derive(Clone, Debug)]
411struct InitializeTickArrayCpiBuilderInstruction<'a, 'b> {
412    __program: &'b solana_account_info::AccountInfo<'a>,
413    whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
414    funder: Option<&'b solana_account_info::AccountInfo<'a>>,
415    tick_array: Option<&'b solana_account_info::AccountInfo<'a>>,
416    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
417    start_tick_index: Option<i32>,
418    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
419    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
420}