1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct OpenBundledPosition {
14 pub bundled_position: solana_pubkey::Pubkey,
15
16 pub position_bundle: solana_pubkey::Pubkey,
17
18 pub position_bundle_token_account: solana_pubkey::Pubkey,
19
20 pub position_bundle_authority: solana_pubkey::Pubkey,
21
22 pub whirlpool: solana_pubkey::Pubkey,
23
24 pub funder: solana_pubkey::Pubkey,
25
26 pub system_program: solana_pubkey::Pubkey,
27
28 pub rent: solana_pubkey::Pubkey,
29}
30
31impl OpenBundledPosition {
32 pub fn instruction(
33 &self,
34 args: OpenBundledPositionInstructionArgs,
35 ) -> solana_instruction::Instruction {
36 self.instruction_with_remaining_accounts(args, &[])
37 }
38 #[allow(clippy::arithmetic_side_effects)]
39 #[allow(clippy::vec_init_then_push)]
40 pub fn instruction_with_remaining_accounts(
41 &self,
42 args: OpenBundledPositionInstructionArgs,
43 remaining_accounts: &[solana_instruction::AccountMeta],
44 ) -> solana_instruction::Instruction {
45 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
46 accounts.push(solana_instruction::AccountMeta::new(
47 self.bundled_position,
48 false,
49 ));
50 accounts.push(solana_instruction::AccountMeta::new(
51 self.position_bundle,
52 false,
53 ));
54 accounts.push(solana_instruction::AccountMeta::new_readonly(
55 self.position_bundle_token_account,
56 false,
57 ));
58 accounts.push(solana_instruction::AccountMeta::new_readonly(
59 self.position_bundle_authority,
60 true,
61 ));
62 accounts.push(solana_instruction::AccountMeta::new_readonly(
63 self.whirlpool,
64 false,
65 ));
66 accounts.push(solana_instruction::AccountMeta::new(self.funder, true));
67 accounts.push(solana_instruction::AccountMeta::new_readonly(
68 self.system_program,
69 false,
70 ));
71 accounts.push(solana_instruction::AccountMeta::new_readonly(
72 self.rent, false,
73 ));
74 accounts.extend_from_slice(remaining_accounts);
75 let mut data = borsh::to_vec(&OpenBundledPositionInstructionData::new()).unwrap();
76 let mut args = borsh::to_vec(&args).unwrap();
77 data.append(&mut args);
78
79 solana_instruction::Instruction {
80 program_id: crate::WHIRLPOOL_ID,
81 accounts,
82 data,
83 }
84 }
85}
86
87#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89pub struct OpenBundledPositionInstructionData {
90 discriminator: [u8; 8],
91}
92
93impl OpenBundledPositionInstructionData {
94 pub fn new() -> Self {
95 Self {
96 discriminator: [169, 113, 126, 171, 213, 172, 212, 49],
97 }
98 }
99}
100
101impl Default for OpenBundledPositionInstructionData {
102 fn default() -> Self {
103 Self::new()
104 }
105}
106
107#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
108#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109pub struct OpenBundledPositionInstructionArgs {
110 pub bundle_index: u16,
111 pub tick_lower_index: i32,
112 pub tick_upper_index: i32,
113}
114
115#[derive(Clone, Debug, Default)]
128pub struct OpenBundledPositionBuilder {
129 bundled_position: Option<solana_pubkey::Pubkey>,
130 position_bundle: Option<solana_pubkey::Pubkey>,
131 position_bundle_token_account: Option<solana_pubkey::Pubkey>,
132 position_bundle_authority: Option<solana_pubkey::Pubkey>,
133 whirlpool: Option<solana_pubkey::Pubkey>,
134 funder: Option<solana_pubkey::Pubkey>,
135 system_program: Option<solana_pubkey::Pubkey>,
136 rent: Option<solana_pubkey::Pubkey>,
137 bundle_index: Option<u16>,
138 tick_lower_index: Option<i32>,
139 tick_upper_index: Option<i32>,
140 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
141}
142
143impl OpenBundledPositionBuilder {
144 pub fn new() -> Self {
145 Self::default()
146 }
147 #[inline(always)]
148 pub fn bundled_position(&mut self, bundled_position: solana_pubkey::Pubkey) -> &mut Self {
149 self.bundled_position = Some(bundled_position);
150 self
151 }
152 #[inline(always)]
153 pub fn position_bundle(&mut self, position_bundle: solana_pubkey::Pubkey) -> &mut Self {
154 self.position_bundle = Some(position_bundle);
155 self
156 }
157 #[inline(always)]
158 pub fn position_bundle_token_account(
159 &mut self,
160 position_bundle_token_account: solana_pubkey::Pubkey,
161 ) -> &mut Self {
162 self.position_bundle_token_account = Some(position_bundle_token_account);
163 self
164 }
165 #[inline(always)]
166 pub fn position_bundle_authority(
167 &mut self,
168 position_bundle_authority: solana_pubkey::Pubkey,
169 ) -> &mut Self {
170 self.position_bundle_authority = Some(position_bundle_authority);
171 self
172 }
173 #[inline(always)]
174 pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
175 self.whirlpool = Some(whirlpool);
176 self
177 }
178 #[inline(always)]
179 pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
180 self.funder = Some(funder);
181 self
182 }
183 #[inline(always)]
185 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
186 self.system_program = Some(system_program);
187 self
188 }
189 #[inline(always)]
191 pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
192 self.rent = Some(rent);
193 self
194 }
195 #[inline(always)]
196 pub fn bundle_index(&mut self, bundle_index: u16) -> &mut Self {
197 self.bundle_index = Some(bundle_index);
198 self
199 }
200 #[inline(always)]
201 pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
202 self.tick_lower_index = Some(tick_lower_index);
203 self
204 }
205 #[inline(always)]
206 pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
207 self.tick_upper_index = Some(tick_upper_index);
208 self
209 }
210 #[inline(always)]
212 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
213 self.__remaining_accounts.push(account);
214 self
215 }
216 #[inline(always)]
218 pub fn add_remaining_accounts(
219 &mut self,
220 accounts: &[solana_instruction::AccountMeta],
221 ) -> &mut Self {
222 self.__remaining_accounts.extend_from_slice(accounts);
223 self
224 }
225 #[allow(clippy::clone_on_copy)]
226 pub fn instruction(&self) -> solana_instruction::Instruction {
227 let accounts = OpenBundledPosition {
228 bundled_position: self.bundled_position.expect("bundled_position is not set"),
229 position_bundle: self.position_bundle.expect("position_bundle is not set"),
230 position_bundle_token_account: self
231 .position_bundle_token_account
232 .expect("position_bundle_token_account is not set"),
233 position_bundle_authority: self
234 .position_bundle_authority
235 .expect("position_bundle_authority is not set"),
236 whirlpool: self.whirlpool.expect("whirlpool is not set"),
237 funder: self.funder.expect("funder is not set"),
238 system_program: self
239 .system_program
240 .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
241 rent: self.rent.unwrap_or(solana_pubkey::pubkey!(
242 "SysvarRent111111111111111111111111111111111"
243 )),
244 };
245 let args = OpenBundledPositionInstructionArgs {
246 bundle_index: self.bundle_index.clone().expect("bundle_index is not set"),
247 tick_lower_index: self
248 .tick_lower_index
249 .clone()
250 .expect("tick_lower_index is not set"),
251 tick_upper_index: self
252 .tick_upper_index
253 .clone()
254 .expect("tick_upper_index is not set"),
255 };
256
257 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
258 }
259}
260
261pub struct OpenBundledPositionCpiAccounts<'a, 'b> {
263 pub bundled_position: &'b solana_account_info::AccountInfo<'a>,
264
265 pub position_bundle: &'b solana_account_info::AccountInfo<'a>,
266
267 pub position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
268
269 pub position_bundle_authority: &'b solana_account_info::AccountInfo<'a>,
270
271 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
272
273 pub funder: &'b solana_account_info::AccountInfo<'a>,
274
275 pub system_program: &'b solana_account_info::AccountInfo<'a>,
276
277 pub rent: &'b solana_account_info::AccountInfo<'a>,
278}
279
280pub struct OpenBundledPositionCpi<'a, 'b> {
282 pub __program: &'b solana_account_info::AccountInfo<'a>,
284
285 pub bundled_position: &'b solana_account_info::AccountInfo<'a>,
286
287 pub position_bundle: &'b solana_account_info::AccountInfo<'a>,
288
289 pub position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
290
291 pub position_bundle_authority: &'b solana_account_info::AccountInfo<'a>,
292
293 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
294
295 pub funder: &'b solana_account_info::AccountInfo<'a>,
296
297 pub system_program: &'b solana_account_info::AccountInfo<'a>,
298
299 pub rent: &'b solana_account_info::AccountInfo<'a>,
300 pub __args: OpenBundledPositionInstructionArgs,
302}
303
304impl<'a, 'b> OpenBundledPositionCpi<'a, 'b> {
305 pub fn new(
306 program: &'b solana_account_info::AccountInfo<'a>,
307 accounts: OpenBundledPositionCpiAccounts<'a, 'b>,
308 args: OpenBundledPositionInstructionArgs,
309 ) -> Self {
310 Self {
311 __program: program,
312 bundled_position: accounts.bundled_position,
313 position_bundle: accounts.position_bundle,
314 position_bundle_token_account: accounts.position_bundle_token_account,
315 position_bundle_authority: accounts.position_bundle_authority,
316 whirlpool: accounts.whirlpool,
317 funder: accounts.funder,
318 system_program: accounts.system_program,
319 rent: accounts.rent,
320 __args: args,
321 }
322 }
323 #[inline(always)]
324 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
325 self.invoke_signed_with_remaining_accounts(&[], &[])
326 }
327 #[inline(always)]
328 pub fn invoke_with_remaining_accounts(
329 &self,
330 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
331 ) -> solana_program_entrypoint::ProgramResult {
332 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
333 }
334 #[inline(always)]
335 pub fn invoke_signed(
336 &self,
337 signers_seeds: &[&[&[u8]]],
338 ) -> solana_program_entrypoint::ProgramResult {
339 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
340 }
341 #[allow(clippy::arithmetic_side_effects)]
342 #[allow(clippy::clone_on_copy)]
343 #[allow(clippy::vec_init_then_push)]
344 pub fn invoke_signed_with_remaining_accounts(
345 &self,
346 signers_seeds: &[&[&[u8]]],
347 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
348 ) -> solana_program_entrypoint::ProgramResult {
349 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
350 accounts.push(solana_instruction::AccountMeta::new(
351 *self.bundled_position.key,
352 false,
353 ));
354 accounts.push(solana_instruction::AccountMeta::new(
355 *self.position_bundle.key,
356 false,
357 ));
358 accounts.push(solana_instruction::AccountMeta::new_readonly(
359 *self.position_bundle_token_account.key,
360 false,
361 ));
362 accounts.push(solana_instruction::AccountMeta::new_readonly(
363 *self.position_bundle_authority.key,
364 true,
365 ));
366 accounts.push(solana_instruction::AccountMeta::new_readonly(
367 *self.whirlpool.key,
368 false,
369 ));
370 accounts.push(solana_instruction::AccountMeta::new(*self.funder.key, true));
371 accounts.push(solana_instruction::AccountMeta::new_readonly(
372 *self.system_program.key,
373 false,
374 ));
375 accounts.push(solana_instruction::AccountMeta::new_readonly(
376 *self.rent.key,
377 false,
378 ));
379 remaining_accounts.iter().for_each(|remaining_account| {
380 accounts.push(solana_instruction::AccountMeta {
381 pubkey: *remaining_account.0.key,
382 is_signer: remaining_account.1,
383 is_writable: remaining_account.2,
384 })
385 });
386 let mut data = borsh::to_vec(&OpenBundledPositionInstructionData::new()).unwrap();
387 let mut args = borsh::to_vec(&self.__args).unwrap();
388 data.append(&mut args);
389
390 let instruction = solana_instruction::Instruction {
391 program_id: crate::WHIRLPOOL_ID,
392 accounts,
393 data,
394 };
395 let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
396 account_infos.push(self.__program.clone());
397 account_infos.push(self.bundled_position.clone());
398 account_infos.push(self.position_bundle.clone());
399 account_infos.push(self.position_bundle_token_account.clone());
400 account_infos.push(self.position_bundle_authority.clone());
401 account_infos.push(self.whirlpool.clone());
402 account_infos.push(self.funder.clone());
403 account_infos.push(self.system_program.clone());
404 account_infos.push(self.rent.clone());
405 remaining_accounts
406 .iter()
407 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
408
409 if signers_seeds.is_empty() {
410 solana_cpi::invoke(&instruction, &account_infos)
411 } else {
412 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
413 }
414 }
415}
416
417#[derive(Clone, Debug)]
430pub struct OpenBundledPositionCpiBuilder<'a, 'b> {
431 instruction: Box<OpenBundledPositionCpiBuilderInstruction<'a, 'b>>,
432}
433
434impl<'a, 'b> OpenBundledPositionCpiBuilder<'a, 'b> {
435 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
436 let instruction = Box::new(OpenBundledPositionCpiBuilderInstruction {
437 __program: program,
438 bundled_position: None,
439 position_bundle: None,
440 position_bundle_token_account: None,
441 position_bundle_authority: None,
442 whirlpool: None,
443 funder: None,
444 system_program: None,
445 rent: None,
446 bundle_index: None,
447 tick_lower_index: None,
448 tick_upper_index: None,
449 __remaining_accounts: Vec::new(),
450 });
451 Self { instruction }
452 }
453 #[inline(always)]
454 pub fn bundled_position(
455 &mut self,
456 bundled_position: &'b solana_account_info::AccountInfo<'a>,
457 ) -> &mut Self {
458 self.instruction.bundled_position = Some(bundled_position);
459 self
460 }
461 #[inline(always)]
462 pub fn position_bundle(
463 &mut self,
464 position_bundle: &'b solana_account_info::AccountInfo<'a>,
465 ) -> &mut Self {
466 self.instruction.position_bundle = Some(position_bundle);
467 self
468 }
469 #[inline(always)]
470 pub fn position_bundle_token_account(
471 &mut self,
472 position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
473 ) -> &mut Self {
474 self.instruction.position_bundle_token_account = Some(position_bundle_token_account);
475 self
476 }
477 #[inline(always)]
478 pub fn position_bundle_authority(
479 &mut self,
480 position_bundle_authority: &'b solana_account_info::AccountInfo<'a>,
481 ) -> &mut Self {
482 self.instruction.position_bundle_authority = Some(position_bundle_authority);
483 self
484 }
485 #[inline(always)]
486 pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
487 self.instruction.whirlpool = Some(whirlpool);
488 self
489 }
490 #[inline(always)]
491 pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
492 self.instruction.funder = Some(funder);
493 self
494 }
495 #[inline(always)]
496 pub fn system_program(
497 &mut self,
498 system_program: &'b solana_account_info::AccountInfo<'a>,
499 ) -> &mut Self {
500 self.instruction.system_program = Some(system_program);
501 self
502 }
503 #[inline(always)]
504 pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
505 self.instruction.rent = Some(rent);
506 self
507 }
508 #[inline(always)]
509 pub fn bundle_index(&mut self, bundle_index: u16) -> &mut Self {
510 self.instruction.bundle_index = Some(bundle_index);
511 self
512 }
513 #[inline(always)]
514 pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
515 self.instruction.tick_lower_index = Some(tick_lower_index);
516 self
517 }
518 #[inline(always)]
519 pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
520 self.instruction.tick_upper_index = Some(tick_upper_index);
521 self
522 }
523 #[inline(always)]
525 pub fn add_remaining_account(
526 &mut self,
527 account: &'b solana_account_info::AccountInfo<'a>,
528 is_writable: bool,
529 is_signer: bool,
530 ) -> &mut Self {
531 self.instruction
532 .__remaining_accounts
533 .push((account, is_writable, is_signer));
534 self
535 }
536 #[inline(always)]
541 pub fn add_remaining_accounts(
542 &mut self,
543 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
544 ) -> &mut Self {
545 self.instruction
546 .__remaining_accounts
547 .extend_from_slice(accounts);
548 self
549 }
550 #[inline(always)]
551 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
552 self.invoke_signed(&[])
553 }
554 #[allow(clippy::clone_on_copy)]
555 #[allow(clippy::vec_init_then_push)]
556 pub fn invoke_signed(
557 &self,
558 signers_seeds: &[&[&[u8]]],
559 ) -> solana_program_entrypoint::ProgramResult {
560 let args = OpenBundledPositionInstructionArgs {
561 bundle_index: self
562 .instruction
563 .bundle_index
564 .clone()
565 .expect("bundle_index is not set"),
566 tick_lower_index: self
567 .instruction
568 .tick_lower_index
569 .clone()
570 .expect("tick_lower_index is not set"),
571 tick_upper_index: self
572 .instruction
573 .tick_upper_index
574 .clone()
575 .expect("tick_upper_index is not set"),
576 };
577 let instruction = OpenBundledPositionCpi {
578 __program: self.instruction.__program,
579
580 bundled_position: self
581 .instruction
582 .bundled_position
583 .expect("bundled_position is not set"),
584
585 position_bundle: self
586 .instruction
587 .position_bundle
588 .expect("position_bundle is not set"),
589
590 position_bundle_token_account: self
591 .instruction
592 .position_bundle_token_account
593 .expect("position_bundle_token_account is not set"),
594
595 position_bundle_authority: self
596 .instruction
597 .position_bundle_authority
598 .expect("position_bundle_authority is not set"),
599
600 whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
601
602 funder: self.instruction.funder.expect("funder is not set"),
603
604 system_program: self
605 .instruction
606 .system_program
607 .expect("system_program is not set"),
608
609 rent: self.instruction.rent.expect("rent is not set"),
610 __args: args,
611 };
612 instruction.invoke_signed_with_remaining_accounts(
613 signers_seeds,
614 &self.instruction.__remaining_accounts,
615 )
616 }
617}
618
619#[derive(Clone, Debug)]
620struct OpenBundledPositionCpiBuilderInstruction<'a, 'b> {
621 __program: &'b solana_account_info::AccountInfo<'a>,
622 bundled_position: Option<&'b solana_account_info::AccountInfo<'a>>,
623 position_bundle: Option<&'b solana_account_info::AccountInfo<'a>>,
624 position_bundle_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
625 position_bundle_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
626 whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
627 funder: Option<&'b solana_account_info::AccountInfo<'a>>,
628 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
629 rent: Option<&'b solana_account_info::AccountInfo<'a>>,
630 bundle_index: Option<u16>,
631 tick_lower_index: Option<i32>,
632 tick_upper_index: Option<i32>,
633 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
635}