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