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