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