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