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_readonly(
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: 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 creator_fee_config: solana_address::Address,
192 base_mint: solana_address::Address,
193 quote_mint: solana_address::Address,
194 destination_owner: solana_address::Address,
195 quote_token_program: solana_address::Address,
196 ) -> Self {
197 Self {
198 claimer,
199 payer,
200 bonding_curve: None,
201 creator_fee_config,
202 base_mint,
203 quote_mint,
204 quote_vault: None,
205 destination_owner,
206 destination: None,
207 quote_token_program,
208 __remaining_accounts: Vec::new(),
209 }
210 }
211 #[inline(always)]
213 pub fn bonding_curve(
214 &mut self,
215 bonding_curve: solana_address::Address,
216 ) -> &mut Self {
217 self.bonding_curve = Some(bonding_curve);
218 self
219 }
220 #[inline(always)]
222 pub fn quote_vault(
223 &mut self,
224 quote_vault: solana_address::Address,
225 ) -> &mut Self {
226 self.quote_vault = Some(quote_vault);
227 self
228 }
229 #[inline(always)]
231 pub fn destination(
232 &mut self,
233 destination: solana_address::Address,
234 ) -> &mut Self {
235 self.destination = Some(destination);
236 self
237 }
238 #[inline(always)]
240 pub fn add_remaining_account(
241 &mut self,
242 account: solana_instruction::AccountMeta,
243 ) -> &mut Self {
244 self.__remaining_accounts.push(account);
245 self
246 }
247 #[inline(always)]
249 pub fn add_remaining_accounts(
250 &mut self,
251 accounts: &[solana_instruction::AccountMeta],
252 ) -> &mut Self {
253 self.__remaining_accounts.extend_from_slice(accounts);
254 self
255 }
256 #[allow(clippy::clone_on_copy)]
257 pub fn instruction(&self) -> solana_instruction::Instruction {
258 let claimer = self.claimer;
259 let payer = self.payer;
260 let base_mint = self.base_mint;
261 let quote_mint = self.quote_mint;
262 let bonding_curve = self.bonding_curve.unwrap_or_else(|| {
263 crate::launchpad::generated::pdas::find_bonding_curve_pda(
264 &self.base_mint,
265 &self.quote_mint,
266 )
267 .0
268 });
269 let creator_fee_config = self.creator_fee_config;
270 let nexus_global_config = solana_address::address!(
271 "3bycfBeRULfXYqcg3DmiYFBjv6mMVidMuqKdFZJTGdNr"
272 );
273 let quote_token_program = self.quote_token_program;
274 let quote_vault = self.quote_vault.unwrap_or_else(|| {
275 solana_address::Address::find_program_address(
276 &[
277 bonding_curve.as_ref(),
278 self.quote_token_program.as_ref(),
279 self.quote_mint.as_ref(),
280 ],
281 &solana_address::address!(
282 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
283 ),
284 )
285 .0
286 });
287 let destination_owner = self.destination_owner;
288 let destination = self.destination.unwrap_or_else(|| {
289 solana_address::Address::find_program_address(
290 &[
291 self.destination_owner.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 associated_token_program = solana_address::address!(
302 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
303 );
304 let system_program =
305 solana_address::address!("11111111111111111111111111111111");
306 let event_authority =
307 crate::launchpad::generated::pdas::EVENT_AUTHORITY_ADDRESS;
308 let program = solana_address::address!(
309 "5R1uFyEE4oxqkm7hJDqHq6gXaLVF9dxeF3LF4yz1sfLP"
310 );
311 let accounts = ClaimCreatorFees {
312 claimer,
313 payer,
314 bonding_curve,
315 creator_fee_config,
316 nexus_global_config,
317 base_mint,
318 quote_mint,
319 quote_vault,
320 destination_owner,
321 destination,
322 quote_token_program,
323 associated_token_program,
324 system_program,
325 event_authority,
326 program,
327 };
328
329 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
330 }
331}
332
333pub struct ClaimCreatorFeesCpiAccounts<'a, 'b> {
335 pub claimer: &'b solana_program::account_info::AccountInfo<'a>,
336 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
337 pub bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
338 pub creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
339 pub nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
340 pub base_mint: &'b solana_program::account_info::AccountInfo<'a>,
341 pub quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
342 pub quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
343 pub destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
344 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
345 pub quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
346 pub associated_token_program:
347 &'b solana_program::account_info::AccountInfo<'a>,
348 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
349 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
350 pub program: &'b solana_program::account_info::AccountInfo<'a>,
351}
352
353pub struct ClaimCreatorFeesCpi<'a, 'b> {
355 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
357 pub claimer: &'b solana_program::account_info::AccountInfo<'a>,
358 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
359 pub bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
360 pub creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
361 pub nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
362 pub base_mint: &'b solana_program::account_info::AccountInfo<'a>,
363 pub quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
364 pub quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
365 pub destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
366 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
367 pub quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
368 pub associated_token_program:
369 &'b solana_program::account_info::AccountInfo<'a>,
370 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
371 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
372 pub program: &'b solana_program::account_info::AccountInfo<'a>,
373}
374
375impl<'a, 'b> ClaimCreatorFeesCpi<'a, 'b> {
376 pub fn new(
377 program: &'b solana_program::account_info::AccountInfo<'a>,
378 accounts: ClaimCreatorFeesCpiAccounts<'a, 'b>,
379 ) -> Self {
380 Self {
381 __program: program,
382 claimer: accounts.claimer,
383 payer: accounts.payer,
384 bonding_curve: accounts.bonding_curve,
385 creator_fee_config: accounts.creator_fee_config,
386 nexus_global_config: accounts.nexus_global_config,
387 base_mint: accounts.base_mint,
388 quote_mint: accounts.quote_mint,
389 quote_vault: accounts.quote_vault,
390 destination_owner: accounts.destination_owner,
391 destination: accounts.destination,
392 quote_token_program: accounts.quote_token_program,
393 associated_token_program: accounts.associated_token_program,
394 system_program: accounts.system_program,
395 event_authority: accounts.event_authority,
396 program: accounts.program,
397 }
398 }
399 #[inline(always)]
400 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
401 self.invoke_signed_with_remaining_accounts(&[], &[])
402 }
403 #[inline(always)]
404 pub fn invoke_with_remaining_accounts(
405 &self,
406 remaining_accounts: &[(
407 &'b solana_program::account_info::AccountInfo<'a>,
408 bool,
409 bool,
410 )],
411 ) -> solana_program::entrypoint::ProgramResult {
412 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
413 }
414 #[inline(always)]
415 pub fn invoke_signed(
416 &self,
417 signers_seeds: &[&[&[u8]]],
418 ) -> solana_program::entrypoint::ProgramResult {
419 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
420 }
421 #[allow(clippy::arithmetic_side_effects)]
422 #[allow(clippy::clone_on_copy)]
423 #[allow(clippy::vec_init_then_push)]
424 pub fn invoke_signed_with_remaining_accounts(
425 &self,
426 signers_seeds: &[&[&[u8]]],
427 remaining_accounts: &[(
428 &'b solana_program::account_info::AccountInfo<'a>,
429 bool,
430 bool,
431 )],
432 ) -> solana_program::entrypoint::ProgramResult {
433 let mut accounts = Vec::with_capacity(15 + remaining_accounts.len());
434 accounts.push(solana_instruction::AccountMeta::new_readonly(
435 *self.claimer.key,
436 true,
437 ));
438 accounts
439 .push(solana_instruction::AccountMeta::new(*self.payer.key, true));
440 accounts.push(solana_instruction::AccountMeta::new(
441 *self.bonding_curve.key,
442 false,
443 ));
444 accounts.push(solana_instruction::AccountMeta::new_readonly(
445 *self.creator_fee_config.key,
446 false,
447 ));
448 accounts.push(solana_instruction::AccountMeta::new_readonly(
449 *self.nexus_global_config.key,
450 false,
451 ));
452 accounts.push(solana_instruction::AccountMeta::new_readonly(
453 *self.base_mint.key,
454 false,
455 ));
456 accounts.push(solana_instruction::AccountMeta::new_readonly(
457 *self.quote_mint.key,
458 false,
459 ));
460 accounts.push(solana_instruction::AccountMeta::new(
461 *self.quote_vault.key,
462 false,
463 ));
464 accounts.push(solana_instruction::AccountMeta::new_readonly(
465 *self.destination_owner.key,
466 false,
467 ));
468 accounts.push(solana_instruction::AccountMeta::new(
469 *self.destination.key,
470 false,
471 ));
472 accounts.push(solana_instruction::AccountMeta::new_readonly(
473 *self.quote_token_program.key,
474 false,
475 ));
476 accounts.push(solana_instruction::AccountMeta::new_readonly(
477 *self.associated_token_program.key,
478 false,
479 ));
480 accounts.push(solana_instruction::AccountMeta::new_readonly(
481 *self.system_program.key,
482 false,
483 ));
484 accounts.push(solana_instruction::AccountMeta::new_readonly(
485 *self.event_authority.key,
486 false,
487 ));
488 accounts.push(solana_instruction::AccountMeta::new_readonly(
489 *self.program.key,
490 false,
491 ));
492 remaining_accounts.iter().for_each(|remaining_account| {
493 accounts.push(solana_instruction::AccountMeta {
494 pubkey: *remaining_account.0.key,
495 is_writable: remaining_account.1,
496 is_signer: remaining_account.2,
497 })
498 });
499 let data = ClaimCreatorFeesInstructionData::new().try_to_vec().unwrap();
500
501 let instruction = solana_instruction::Instruction {
502 program_id: crate::launchpad::generated::SEND_LAUNCHPAD_ID,
503 accounts,
504 data,
505 };
506 let mut account_infos =
507 Vec::with_capacity(16 + remaining_accounts.len());
508 account_infos.push(self.__program.clone());
509 account_infos.push(self.claimer.clone());
510 account_infos.push(self.payer.clone());
511 account_infos.push(self.bonding_curve.clone());
512 account_infos.push(self.creator_fee_config.clone());
513 account_infos.push(self.nexus_global_config.clone());
514 account_infos.push(self.base_mint.clone());
515 account_infos.push(self.quote_mint.clone());
516 account_infos.push(self.quote_vault.clone());
517 account_infos.push(self.destination_owner.clone());
518 account_infos.push(self.destination.clone());
519 account_infos.push(self.quote_token_program.clone());
520 account_infos.push(self.associated_token_program.clone());
521 account_infos.push(self.system_program.clone());
522 account_infos.push(self.event_authority.clone());
523 account_infos.push(self.program.clone());
524 remaining_accounts.iter().for_each(|remaining_account| {
525 account_infos.push(remaining_account.0.clone())
526 });
527
528 if signers_seeds.is_empty() {
529 solana_program::program::invoke(&instruction, &account_infos)
530 } else {
531 solana_program::program::invoke_signed(
532 &instruction,
533 &account_infos,
534 signers_seeds,
535 )
536 }
537 }
538}
539
540#[derive(Clone, Debug)]
560pub struct ClaimCreatorFeesCpiBuilder<'a, 'b> {
561 instruction: Box<ClaimCreatorFeesCpiBuilderInstruction<'a, 'b>>,
562}
563
564impl<'a, 'b> ClaimCreatorFeesCpiBuilder<'a, 'b> {
565 pub fn new(
566 __program: &'b solana_program::account_info::AccountInfo<'a>,
567 claimer: &'b solana_program::account_info::AccountInfo<'a>,
568 payer: &'b solana_program::account_info::AccountInfo<'a>,
569 bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
570 creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
571 nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
572 base_mint: &'b solana_program::account_info::AccountInfo<'a>,
573 quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
574 quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
575 destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
576 destination: &'b solana_program::account_info::AccountInfo<'a>,
577 quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
578 associated_token_program: &'b solana_program::account_info::AccountInfo<
579 'a,
580 >,
581 system_program: &'b solana_program::account_info::AccountInfo<'a>,
582 event_authority: &'b solana_program::account_info::AccountInfo<'a>,
583 program: &'b solana_program::account_info::AccountInfo<'a>,
584 ) -> Self {
585 let instruction = Box::new(ClaimCreatorFeesCpiBuilderInstruction {
586 __program,
587 claimer,
588 payer,
589 bonding_curve,
590 creator_fee_config,
591 nexus_global_config,
592 base_mint,
593 quote_mint,
594 quote_vault,
595 destination_owner,
596 destination,
597 quote_token_program,
598 associated_token_program,
599 system_program,
600 event_authority,
601 program,
602 __remaining_accounts: Vec::new(),
603 });
604 Self { instruction }
605 }
606 #[inline(always)]
608 pub fn add_remaining_account(
609 &mut self,
610 account: &'b solana_program::account_info::AccountInfo<'a>,
611 is_writable: bool,
612 is_signer: bool,
613 ) -> &mut Self {
614 self.instruction.__remaining_accounts.push((
615 account,
616 is_writable,
617 is_signer,
618 ));
619 self
620 }
621 #[inline(always)]
626 pub fn add_remaining_accounts(
627 &mut self,
628 accounts: &[(
629 &'b solana_program::account_info::AccountInfo<'a>,
630 bool,
631 bool,
632 )],
633 ) -> &mut Self {
634 self.instruction
635 .__remaining_accounts
636 .extend_from_slice(accounts);
637 self
638 }
639 #[inline(always)]
640 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
641 self.invoke_signed(&[])
642 }
643 #[allow(clippy::clone_on_copy)]
644 #[allow(clippy::vec_init_then_push)]
645 pub fn invoke_signed(
646 &self,
647 signers_seeds: &[&[&[u8]]],
648 ) -> solana_program::entrypoint::ProgramResult {
649 let instruction = ClaimCreatorFeesCpi {
650 __program: self.instruction.__program,
651 claimer: self.instruction.claimer,
652 payer: self.instruction.payer,
653 bonding_curve: self.instruction.bonding_curve,
654 creator_fee_config: self.instruction.creator_fee_config,
655 nexus_global_config: self.instruction.nexus_global_config,
656 base_mint: self.instruction.base_mint,
657 quote_mint: self.instruction.quote_mint,
658 quote_vault: self.instruction.quote_vault,
659 destination_owner: self.instruction.destination_owner,
660 destination: self.instruction.destination,
661 quote_token_program: self.instruction.quote_token_program,
662 associated_token_program: self.instruction.associated_token_program,
663 system_program: self.instruction.system_program,
664 event_authority: self.instruction.event_authority,
665 program: self.instruction.program,
666 };
667 instruction.invoke_signed_with_remaining_accounts(
668 signers_seeds,
669 &self.instruction.__remaining_accounts,
670 )
671 }
672}
673
674#[derive(Clone, Debug)]
675struct ClaimCreatorFeesCpiBuilderInstruction<'a, 'b> {
676 __program: &'b solana_program::account_info::AccountInfo<'a>,
677 claimer: &'b solana_program::account_info::AccountInfo<'a>,
678 payer: &'b solana_program::account_info::AccountInfo<'a>,
679 bonding_curve: &'b solana_program::account_info::AccountInfo<'a>,
680 creator_fee_config: &'b solana_program::account_info::AccountInfo<'a>,
681 nexus_global_config: &'b solana_program::account_info::AccountInfo<'a>,
682 base_mint: &'b solana_program::account_info::AccountInfo<'a>,
683 quote_mint: &'b solana_program::account_info::AccountInfo<'a>,
684 quote_vault: &'b solana_program::account_info::AccountInfo<'a>,
685 destination_owner: &'b solana_program::account_info::AccountInfo<'a>,
686 destination: &'b solana_program::account_info::AccountInfo<'a>,
687 quote_token_program: &'b solana_program::account_info::AccountInfo<'a>,
688 associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
689 system_program: &'b solana_program::account_info::AccountInfo<'a>,
690 event_authority: &'b solana_program::account_info::AccountInfo<'a>,
691 program: &'b solana_program::account_info::AccountInfo<'a>,
692 __remaining_accounts: Vec<(
694 &'b solana_program::account_info::AccountInfo<'a>,
695 bool,
696 bool,
697 )>,
698}