1#![allow(
2 clippy::all,
3 clippy::pedantic,
4 clippy::nursery,
5 clippy::expect_used,
6 clippy::unwrap_used,
7 clippy::indexing_slicing,
8 clippy::allow_attributes,
9 clippy::allow_attributes_without_reason,
10 clippy::mem_forget,
11 unfulfilled_lint_expectations,
12 unexpected_cfgs,
13 unused_imports
14)]
15
16use borsh::BorshDeserialize;
24use borsh::BorshSerialize;
25
26pub const CLAIM_CREATOR_FEES_DISCRIMINATOR: [u8; 8] =
27 [0, 23, 125, 234, 156, 118, 134, 89];
28
29#[derive(Debug)]
31pub struct ClaimCreatorFees {
32 pub claimer: solana_address::Address,
33 pub payer: solana_address::Address,
34 pub bonding_curve: solana_address::Address,
35 pub creator_fee_config: solana_address::Address,
36 pub nexus_global_config: solana_address::Address,
37 pub base_mint: solana_address::Address,
38 pub quote_mint: solana_address::Address,
39 pub quote_vault: solana_address::Address,
40 pub destination_owner: solana_address::Address,
41 pub destination: solana_address::Address,
42 pub quote_token_program: solana_address::Address,
43 pub associated_token_program: solana_address::Address,
44 pub system_program: solana_address::Address,
45 pub event_authority: solana_address::Address,
46 pub program: solana_address::Address,
47}
48
49impl ClaimCreatorFees {
50 pub fn instruction(&self) -> solana_instruction::Instruction {
51 self.instruction_with_remaining_accounts(&[])
52 }
53 #[allow(clippy::arithmetic_side_effects)]
54 #[allow(clippy::vec_init_then_push)]
55 pub fn instruction_with_remaining_accounts(
56 &self,
57 remaining_accounts: &[solana_instruction::AccountMeta],
58 ) -> solana_instruction::Instruction {
59 let mut accounts = Vec::with_capacity(15 + remaining_accounts.len());
60 accounts.push(solana_instruction::AccountMeta::new_readonly(
61 self.claimer,
62 true,
63 ));
64 accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
65 accounts.push(solana_instruction::AccountMeta::new(
66 self.bonding_curve,
67 false,
68 ));
69 accounts.push(solana_instruction::AccountMeta::new(
70 self.creator_fee_config,
71 false,
72 ));
73 accounts.push(solana_instruction::AccountMeta::new_readonly(
74 self.nexus_global_config,
75 false,
76 ));
77 accounts.push(solana_instruction::AccountMeta::new_readonly(
78 self.base_mint,
79 false,
80 ));
81 accounts.push(solana_instruction::AccountMeta::new_readonly(
82 self.quote_mint,
83 false,
84 ));
85 accounts.push(solana_instruction::AccountMeta::new(
86 self.quote_vault,
87 false,
88 ));
89 accounts.push(solana_instruction::AccountMeta::new_readonly(
90 self.destination_owner,
91 false,
92 ));
93 accounts.push(solana_instruction::AccountMeta::new(
94 self.destination,
95 false,
96 ));
97 accounts.push(solana_instruction::AccountMeta::new_readonly(
98 self.quote_token_program,
99 false,
100 ));
101 accounts.push(solana_instruction::AccountMeta::new_readonly(
102 self.associated_token_program,
103 false,
104 ));
105 accounts.push(solana_instruction::AccountMeta::new_readonly(
106 self.system_program,
107 false,
108 ));
109 accounts.push(solana_instruction::AccountMeta::new_readonly(
110 self.event_authority,
111 false,
112 ));
113 accounts.push(solana_instruction::AccountMeta::new_readonly(
114 self.program,
115 false,
116 ));
117 accounts.extend_from_slice(remaining_accounts);
118 let data = ClaimCreatorFeesInstructionData::new().try_to_vec().unwrap();
119
120 solana_instruction::Instruction {
121 program_id: crate::launchpad::generated::SEND_LAUNCHPAD_ID,
122 accounts,
123 data,
124 }
125 }
126}
127
128#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
129#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
130#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
131pub struct ClaimCreatorFeesInstructionData {
132 discriminator: [u8; 8],
133}
134
135impl ClaimCreatorFeesInstructionData {
136 pub fn new() -> Self {
137 Self {
138 discriminator: [0, 23, 125, 234, 156, 118, 134, 89],
139 }
140 }
141
142 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
143 borsh::to_vec(self)
144 }
145}
146
147impl Default for ClaimCreatorFeesInstructionData {
148 fn default() -> Self {
149 Self::new()
150 }
151}
152
153#[derive(Clone, Debug)]
173pub struct ClaimCreatorFeesBuilder {
174 claimer: solana_address::Address,
175 payer: solana_address::Address,
176 bonding_curve: Option<solana_address::Address>,
177 creator_fee_config: Option<solana_address::Address>,
178 base_mint: solana_address::Address,
179 quote_mint: solana_address::Address,
180 quote_vault: Option<solana_address::Address>,
181 destination_owner: solana_address::Address,
182 destination: Option<solana_address::Address>,
183 quote_token_program: solana_address::Address,
184 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
185}
186
187impl ClaimCreatorFeesBuilder {
188 pub fn new(
189 claimer: solana_address::Address,
190 payer: solana_address::Address,
191 base_mint: solana_address::Address,
192 quote_mint: solana_address::Address,
193 destination_owner: solana_address::Address,
194 quote_token_program: solana_address::Address,
195 ) -> Self {
196 Self {
197 claimer,
198 payer,
199 bonding_curve: None,
200 creator_fee_config: None,
201 base_mint,
202 quote_mint,
203 quote_vault: None,
204 destination_owner,
205 destination: None,
206 quote_token_program,
207 __remaining_accounts: Vec::new(),
208 }
209 }
210 #[inline(always)]
212 pub fn bonding_curve(
213 &mut self,
214 bonding_curve: solana_address::Address,
215 ) -> &mut Self {
216 self.bonding_curve = Some(bonding_curve);
217 self
218 }
219 #[inline(always)]
221 pub fn creator_fee_config(
222 &mut self,
223 creator_fee_config: solana_address::Address,
224 ) -> &mut Self {
225 self.creator_fee_config = Some(creator_fee_config);
226 self
227 }
228 #[inline(always)]
230 pub fn quote_vault(
231 &mut self,
232 quote_vault: solana_address::Address,
233 ) -> &mut Self {
234 self.quote_vault = Some(quote_vault);
235 self
236 }
237 #[inline(always)]
239 pub fn destination(
240 &mut self,
241 destination: solana_address::Address,
242 ) -> &mut Self {
243 self.destination = Some(destination);
244 self
245 }
246 #[inline(always)]
248 pub fn add_remaining_account(
249 &mut self,
250 account: solana_instruction::AccountMeta,
251 ) -> &mut Self {
252 self.__remaining_accounts.push(account);
253 self
254 }
255 #[inline(always)]
257 pub fn add_remaining_accounts(
258 &mut self,
259 accounts: &[solana_instruction::AccountMeta],
260 ) -> &mut Self {
261 self.__remaining_accounts.extend_from_slice(accounts);
262 self
263 }
264 #[allow(clippy::clone_on_copy)]
265 pub fn instruction(&self) -> solana_instruction::Instruction {
266 let claimer = self.claimer;
267 let payer = self.payer;
268 let base_mint = self.base_mint;
269 let quote_mint = self.quote_mint;
270 let bonding_curve = self.bonding_curve.unwrap_or_else(|| {
271 crate::launchpad::generated::pdas::find_bonding_curve_pda(
272 &self.base_mint,
273 &self.quote_mint,
274 )
275 .0
276 });
277 let creator_fee_config = self.creator_fee_config.unwrap_or_else(|| {
278 crate::launchpad::generated::pdas::find_creator_fee_config_pda(
279 &self.base_mint,
280 &self.quote_mint,
281 )
282 .0
283 });
284 let nexus_global_config = solana_address::address!(
285 "3bycfBeRULfXYqcg3DmiYFBjv6mMVidMuqKdFZJTGdNr"
286 );
287 let quote_token_program = self.quote_token_program;
288 let quote_vault = self.quote_vault.unwrap_or_else(|| {
289 solana_address::Address::find_program_address(
290 &[
291 bonding_curve.as_ref(),
292 self.quote_token_program.as_ref(),
293 self.quote_mint.as_ref(),
294 ],
295 &solana_address::address!(
296 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
297 ),
298 )
299 .0
300 });
301 let destination_owner = self.destination_owner;
302 let destination = self.destination.unwrap_or_else(|| {
303 solana_address::Address::find_program_address(
304 &[
305 self.destination_owner.as_ref(),
306 self.quote_token_program.as_ref(),
307 self.quote_mint.as_ref(),
308 ],
309 &solana_address::address!(
310 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
311 ),
312 )
313 .0
314 });
315 let associated_token_program = solana_address::address!(
316 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
317 );
318 let system_program =
319 solana_address::address!("11111111111111111111111111111111");
320 let event_authority =
321 crate::launchpad::generated::pdas::EVENT_AUTHORITY_ADDRESS;
322 let program = solana_address::address!(
323 "5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP"
324 );
325 let accounts = ClaimCreatorFees {
326 claimer,
327 payer,
328 bonding_curve,
329 creator_fee_config,
330 nexus_global_config,
331 base_mint,
332 quote_mint,
333 quote_vault,
334 destination_owner,
335 destination,
336 quote_token_program,
337 associated_token_program,
338 system_program,
339 event_authority,
340 program,
341 };
342
343 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
344 }
345}
346
347pub struct ClaimCreatorFeesCpiAccounts<'a, 'b> {
349 pub claimer: &'b solana_program::account_info::AccountInfo<'a>,
350 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
351 pub bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
352 pub creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
353 pub nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
354 pub base_mint: &'b solana_program::account_info::AccountInfo<'a>,
355 pub quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
356 pub quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
357 pub destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
358 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
359 pub quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
360 pub associated_token_program:
361 &'b solana_program::account_info::AccountInfo<'a>,
362 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
363 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
364 pub program: &'b solana_program::account_info::AccountInfo<'a>,
365}
366
367pub struct ClaimCreatorFeesCpi<'a, 'b> {
369 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
371 pub claimer: &'b solana_program::account_info::AccountInfo<'a>,
372 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
373 pub bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
374 pub creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
375 pub nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
376 pub base_mint: &'b solana_program::account_info::AccountInfo<'a>,
377 pub quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
378 pub quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
379 pub destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
380 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
381 pub quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
382 pub associated_token_program:
383 &'b solana_program::account_info::AccountInfo<'a>,
384 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
385 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
386 pub program: &'b solana_program::account_info::AccountInfo<'a>,
387}
388
389impl<'a, 'b> ClaimCreatorFeesCpi<'a, 'b> {
390 pub fn new(
391 program: &'b solana_program::account_info::AccountInfo<'a>,
392 accounts: ClaimCreatorFeesCpiAccounts<'a, 'b>,
393 ) -> Self {
394 Self {
395 __program: program,
396 claimer: accounts.claimer,
397 payer: accounts.payer,
398 bonding_curve: accounts.bonding_curve,
399 creator_fee_config: accounts.creator_fee_config,
400 nexus_global_config: accounts.nexus_global_config,
401 base_mint: accounts.base_mint,
402 quote_mint: accounts.quote_mint,
403 quote_vault: accounts.quote_vault,
404 destination_owner: accounts.destination_owner,
405 destination: accounts.destination,
406 quote_token_program: accounts.quote_token_program,
407 associated_token_program: accounts.associated_token_program,
408 system_program: accounts.system_program,
409 event_authority: accounts.event_authority,
410 program: accounts.program,
411 }
412 }
413 #[inline(always)]
414 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
415 self.invoke_signed_with_remaining_accounts(&[], &[])
416 }
417 #[inline(always)]
418 pub fn invoke_with_remaining_accounts(
419 &self,
420 remaining_accounts: &[(
421 &'b solana_program::account_info::AccountInfo<'a>,
422 bool,
423 bool,
424 )],
425 ) -> solana_program::entrypoint::ProgramResult {
426 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
427 }
428 #[inline(always)]
429 pub fn invoke_signed(
430 &self,
431 signers_seeds: &[&[&[u8]]],
432 ) -> solana_program::entrypoint::ProgramResult {
433 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
434 }
435 #[allow(clippy::arithmetic_side_effects)]
436 #[allow(clippy::clone_on_copy)]
437 #[allow(clippy::vec_init_then_push)]
438 pub fn invoke_signed_with_remaining_accounts(
439 &self,
440 signers_seeds: &[&[&[u8]]],
441 remaining_accounts: &[(
442 &'b solana_program::account_info::AccountInfo<'a>,
443 bool,
444 bool,
445 )],
446 ) -> solana_program::entrypoint::ProgramResult {
447 let mut accounts = Vec::with_capacity(15 + remaining_accounts.len());
448 accounts.push(solana_instruction::AccountMeta::new_readonly(
449 *self.claimer.key,
450 true,
451 ));
452 accounts
453 .push(solana_instruction::AccountMeta::new(*self.payer.key, true));
454 accounts.push(solana_instruction::AccountMeta::new(
455 *self.bonding_curve.key,
456 false,
457 ));
458 accounts.push(solana_instruction::AccountMeta::new(
459 *self.creator_fee_config.key,
460 false,
461 ));
462 accounts.push(solana_instruction::AccountMeta::new_readonly(
463 *self.nexus_global_config.key,
464 false,
465 ));
466 accounts.push(solana_instruction::AccountMeta::new_readonly(
467 *self.base_mint.key,
468 false,
469 ));
470 accounts.push(solana_instruction::AccountMeta::new_readonly(
471 *self.quote_mint.key,
472 false,
473 ));
474 accounts.push(solana_instruction::AccountMeta::new(
475 *self.quote_vault.key,
476 false,
477 ));
478 accounts.push(solana_instruction::AccountMeta::new_readonly(
479 *self.destination_owner.key,
480 false,
481 ));
482 accounts.push(solana_instruction::AccountMeta::new(
483 *self.destination.key,
484 false,
485 ));
486 accounts.push(solana_instruction::AccountMeta::new_readonly(
487 *self.quote_token_program.key,
488 false,
489 ));
490 accounts.push(solana_instruction::AccountMeta::new_readonly(
491 *self.associated_token_program.key,
492 false,
493 ));
494 accounts.push(solana_instruction::AccountMeta::new_readonly(
495 *self.system_program.key,
496 false,
497 ));
498 accounts.push(solana_instruction::AccountMeta::new_readonly(
499 *self.event_authority.key,
500 false,
501 ));
502 accounts.push(solana_instruction::AccountMeta::new_readonly(
503 *self.program.key,
504 false,
505 ));
506 remaining_accounts.iter().for_each(|remaining_account| {
507 accounts.push(solana_instruction::AccountMeta {
508 pubkey: *remaining_account.0.key,
509 is_writable: remaining_account.1,
510 is_signer: remaining_account.2,
511 })
512 });
513 let data = ClaimCreatorFeesInstructionData::new().try_to_vec().unwrap();
514
515 let instruction = solana_instruction::Instruction {
516 program_id: crate::launchpad::generated::SEND_LAUNCHPAD_ID,
517 accounts,
518 data,
519 };
520 let mut account_infos =
521 Vec::with_capacity(16 + remaining_accounts.len());
522 account_infos.push(self.__program.clone());
523 account_infos.push(self.claimer.clone());
524 account_infos.push(self.payer.clone());
525 account_infos.push(self.bonding_curve.clone());
526 account_infos.push(self.creator_fee_config.clone());
527 account_infos.push(self.nexus_global_config.clone());
528 account_infos.push(self.base_mint.clone());
529 account_infos.push(self.quote_mint.clone());
530 account_infos.push(self.quote_vault.clone());
531 account_infos.push(self.destination_owner.clone());
532 account_infos.push(self.destination.clone());
533 account_infos.push(self.quote_token_program.clone());
534 account_infos.push(self.associated_token_program.clone());
535 account_infos.push(self.system_program.clone());
536 account_infos.push(self.event_authority.clone());
537 account_infos.push(self.program.clone());
538 remaining_accounts.iter().for_each(|remaining_account| {
539 account_infos.push(remaining_account.0.clone())
540 });
541
542 if signers_seeds.is_empty() {
543 solana_program::program::invoke(&instruction, &account_infos)
544 } else {
545 solana_program::program::invoke_signed(
546 &instruction,
547 &account_infos,
548 signers_seeds,
549 )
550 }
551 }
552}
553
554#[derive(Clone, Debug)]
574pub struct ClaimCreatorFeesCpiBuilder<'a, 'b> {
575 instruction: Box<ClaimCreatorFeesCpiBuilderInstruction<'a, 'b>>,
576}
577
578impl<'a, 'b> ClaimCreatorFeesCpiBuilder<'a, 'b> {
579 pub fn new(
580 __program: &'b solana_program::account_info::AccountInfo<'a>,
581 claimer: &'b solana_program::account_info::AccountInfo<'a>,
582 payer: &'b solana_program::account_info::AccountInfo<'a>,
583 bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
584 creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
585 nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
586 base_mint: &'b solana_program::account_info::AccountInfo<'a>,
587 quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
588 quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
589 destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
590 destination: &'b solana_program::account_info::AccountInfo<'a>,
591 quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
592 associated_token_program: &'b solana_program::account_info::AccountInfo<
593 'a,
594 >,
595 system_program: &'b solana_program::account_info::AccountInfo<'a>,
596 event_authority: &'b solana_program::account_info::AccountInfo<'a>,
597 program: &'b solana_program::account_info::AccountInfo<'a>,
598 ) -> Self {
599 let instruction = Box::new(ClaimCreatorFeesCpiBuilderInstruction {
600 __program,
601 claimer,
602 payer,
603 bonding_curve,
604 creator_fee_config,
605 nexus_global_config,
606 base_mint,
607 quote_mint,
608 quote_vault,
609 destination_owner,
610 destination,
611 quote_token_program,
612 associated_token_program,
613 system_program,
614 event_authority,
615 program,
616 __remaining_accounts: Vec::new(),
617 });
618 Self { instruction }
619 }
620 #[inline(always)]
622 pub fn add_remaining_account(
623 &mut self,
624 account: &'b solana_program::account_info::AccountInfo<'a>,
625 is_writable: bool,
626 is_signer: bool,
627 ) -> &mut Self {
628 self.instruction.__remaining_accounts.push((
629 account,
630 is_writable,
631 is_signer,
632 ));
633 self
634 }
635 #[inline(always)]
640 pub fn add_remaining_accounts(
641 &mut self,
642 accounts: &[(
643 &'b solana_program::account_info::AccountInfo<'a>,
644 bool,
645 bool,
646 )],
647 ) -> &mut Self {
648 self.instruction
649 .__remaining_accounts
650 .extend_from_slice(accounts);
651 self
652 }
653 #[inline(always)]
654 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
655 self.invoke_signed(&[])
656 }
657 #[allow(clippy::clone_on_copy)]
658 #[allow(clippy::vec_init_then_push)]
659 pub fn invoke_signed(
660 &self,
661 signers_seeds: &[&[&[u8]]],
662 ) -> solana_program::entrypoint::ProgramResult {
663 let instruction = ClaimCreatorFeesCpi {
664 __program: self.instruction.__program,
665 claimer: self.instruction.claimer,
666 payer: self.instruction.payer,
667 bonding_curve: self.instruction.bonding_curve,
668 creator_fee_config: self.instruction.creator_fee_config,
669 nexus_global_config: self.instruction.nexus_global_config,
670 base_mint: self.instruction.base_mint,
671 quote_mint: self.instruction.quote_mint,
672 quote_vault: self.instruction.quote_vault,
673 destination_owner: self.instruction.destination_owner,
674 destination: self.instruction.destination,
675 quote_token_program: self.instruction.quote_token_program,
676 associated_token_program: self.instruction.associated_token_program,
677 system_program: self.instruction.system_program,
678 event_authority: self.instruction.event_authority,
679 program: self.instruction.program,
680 };
681 instruction.invoke_signed_with_remaining_accounts(
682 signers_seeds,
683 &self.instruction.__remaining_accounts,
684 )
685 }
686}
687
688#[derive(Clone, Debug)]
689struct ClaimCreatorFeesCpiBuilderInstruction<'a, 'b> {
690 __program: &'b solana_program::account_info::AccountInfo<'a>,
691 claimer: &'b solana_program::account_info::AccountInfo<'a>,
692 payer: &'b solana_program::account_info::AccountInfo<'a>,
693 bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
694 creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
695 nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
696 base_mint: &'b solana_program::account_info::AccountInfo<'a>,
697 quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
698 quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
699 destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
700 destination: &'b solana_program::account_info::AccountInfo<'a>,
701 quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
702 associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
703 system_program: &'b solana_program::account_info::AccountInfo<'a>,
704 event_authority: &'b solana_program::account_info::AccountInfo<'a>,
705 program: &'b solana_program::account_info::AccountInfo<'a>,
706 __remaining_accounts: Vec<(
708 &'b solana_program::account_info::AccountInfo<'a>,
709 bool,
710 bool,
711 )>,
712}