1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const CLAIM_SATS_DISCRIMINATOR: [u8; 8] = [196, 77, 168, 181, 6, 119, 249, 154];
12
13#[derive(Debug)]
15pub struct ClaimSats {
16
17
18 pub authority: solana_address::Address,
19
20
21 pub satrush_config: solana_address::Address,
22 pub sats_vault: solana_address::Address,
27 pub miner: solana_address::Address,
32
33
34 pub btc_mint: solana_address::Address,
35 pub sats_vault_btc_ata: solana_address::Address,
40 pub authority_btc_ata: solana_address::Address,
45
46
47 pub token_program: solana_address::Address,
48
49
50 pub associated_token_program: solana_address::Address,
51
52
53 pub system_program: solana_address::Address,
54
55
56 pub event_authority: solana_address::Address,
57
58
59 pub program: solana_address::Address,
60 }
61
62impl ClaimSats {
63 pub fn instruction(&self, args: ClaimSatsInstructionArgs) -> solana_instruction::Instruction {
64 self.instruction_with_remaining_accounts(args, &[])
65 }
66 #[allow(clippy::arithmetic_side_effects)]
67 #[allow(clippy::vec_init_then_push)]
68 pub fn instruction_with_remaining_accounts(&self, args: ClaimSatsInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
69 let mut accounts = Vec::with_capacity(12+ remaining_accounts.len());
70 accounts.push(solana_instruction::AccountMeta::new(
71 self.authority,
72 true
73 ));
74 accounts.push(solana_instruction::AccountMeta::new_readonly(
75 self.satrush_config,
76 false
77 ));
78 accounts.push(solana_instruction::AccountMeta::new(
79 self.sats_vault,
80 false
81 ));
82 accounts.push(solana_instruction::AccountMeta::new(
83 self.miner,
84 false
85 ));
86 accounts.push(solana_instruction::AccountMeta::new_readonly(
87 self.btc_mint,
88 false
89 ));
90 accounts.push(solana_instruction::AccountMeta::new(
91 self.sats_vault_btc_ata,
92 false
93 ));
94 accounts.push(solana_instruction::AccountMeta::new(
95 self.authority_btc_ata,
96 false
97 ));
98 accounts.push(solana_instruction::AccountMeta::new_readonly(
99 self.token_program,
100 false
101 ));
102 accounts.push(solana_instruction::AccountMeta::new_readonly(
103 self.associated_token_program,
104 false
105 ));
106 accounts.push(solana_instruction::AccountMeta::new_readonly(
107 self.system_program,
108 false
109 ));
110 accounts.push(solana_instruction::AccountMeta::new_readonly(
111 self.event_authority,
112 false
113 ));
114 accounts.push(solana_instruction::AccountMeta::new_readonly(
115 self.program,
116 false
117 ));
118 accounts.extend_from_slice(remaining_accounts);
119 let mut data = ClaimSatsInstructionData::new().try_to_vec().unwrap();
120 let mut args = args.try_to_vec().unwrap();
121 data.append(&mut args);
122
123 solana_instruction::Instruction {
124 program_id: crate::SATRUSH_ID,
125 accounts,
126 data,
127 }
128 }
129}
130
131#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
132 pub struct ClaimSatsInstructionData {
133 discriminator: [u8; 8],
134 }
135
136impl ClaimSatsInstructionData {
137 pub fn new() -> Self {
138 Self {
139 discriminator: [196, 77, 168, 181, 6, 119, 249, 154],
140 }
141 }
142
143 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
144 borsh::to_vec(self)
145 }
146 }
147
148impl Default for ClaimSatsInstructionData {
149 fn default() -> Self {
150 Self::new()
151 }
152}
153
154#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
155 pub struct ClaimSatsInstructionArgs {
156 pub shares: u64,
157 }
158
159impl ClaimSatsInstructionArgs {
160 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
161 borsh::to_vec(self)
162 }
163}
164
165
166#[derive(Clone, Debug, Default)]
183pub struct ClaimSatsBuilder {
184 authority: Option<solana_address::Address>,
185 satrush_config: Option<solana_address::Address>,
186 sats_vault: Option<solana_address::Address>,
187 miner: Option<solana_address::Address>,
188 btc_mint: Option<solana_address::Address>,
189 sats_vault_btc_ata: Option<solana_address::Address>,
190 authority_btc_ata: Option<solana_address::Address>,
191 token_program: Option<solana_address::Address>,
192 associated_token_program: Option<solana_address::Address>,
193 system_program: Option<solana_address::Address>,
194 event_authority: Option<solana_address::Address>,
195 program: Option<solana_address::Address>,
196 shares: Option<u64>,
197 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
198}
199
200impl ClaimSatsBuilder {
201 pub fn new() -> Self {
202 Self::default()
203 }
204 #[inline(always)]
205 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
206 self.authority = Some(authority);
207 self
208 }
209 #[inline(always)]
210 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
211 self.satrush_config = Some(satrush_config);
212 self
213 }
214 #[inline(always)]
216 pub fn sats_vault(&mut self, sats_vault: solana_address::Address) -> &mut Self {
217 self.sats_vault = Some(sats_vault);
218 self
219 }
220 #[inline(always)]
222 pub fn miner(&mut self, miner: solana_address::Address) -> &mut Self {
223 self.miner = Some(miner);
224 self
225 }
226 #[inline(always)]
227 pub fn btc_mint(&mut self, btc_mint: solana_address::Address) -> &mut Self {
228 self.btc_mint = Some(btc_mint);
229 self
230 }
231 #[inline(always)]
233 pub fn sats_vault_btc_ata(&mut self, sats_vault_btc_ata: solana_address::Address) -> &mut Self {
234 self.sats_vault_btc_ata = Some(sats_vault_btc_ata);
235 self
236 }
237 #[inline(always)]
239 pub fn authority_btc_ata(&mut self, authority_btc_ata: solana_address::Address) -> &mut Self {
240 self.authority_btc_ata = Some(authority_btc_ata);
241 self
242 }
243 #[inline(always)]
245 pub fn token_program(&mut self, token_program: solana_address::Address) -> &mut Self {
246 self.token_program = Some(token_program);
247 self
248 }
249 #[inline(always)]
251 pub fn associated_token_program(&mut self, associated_token_program: solana_address::Address) -> &mut Self {
252 self.associated_token_program = Some(associated_token_program);
253 self
254 }
255 #[inline(always)]
257 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
258 self.system_program = Some(system_program);
259 self
260 }
261 #[inline(always)]
262 pub fn event_authority(&mut self, event_authority: solana_address::Address) -> &mut Self {
263 self.event_authority = Some(event_authority);
264 self
265 }
266 #[inline(always)]
267 pub fn program(&mut self, program: solana_address::Address) -> &mut Self {
268 self.program = Some(program);
269 self
270 }
271 #[inline(always)]
272 pub fn shares(&mut self, shares: u64) -> &mut Self {
273 self.shares = Some(shares);
274 self
275 }
276 #[inline(always)]
278 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
279 self.__remaining_accounts.push(account);
280 self
281 }
282 #[inline(always)]
284 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
285 self.__remaining_accounts.extend_from_slice(accounts);
286 self
287 }
288 #[allow(clippy::clone_on_copy)]
289 pub fn instruction(&self) -> solana_instruction::Instruction {
290 let accounts = ClaimSats {
291 authority: self.authority.expect("authority is not set"),
292 satrush_config: self.satrush_config.expect("satrush_config is not set"),
293 sats_vault: self.sats_vault.expect("sats_vault is not set"),
294 miner: self.miner.expect("miner is not set"),
295 btc_mint: self.btc_mint.expect("btc_mint is not set"),
296 sats_vault_btc_ata: self.sats_vault_btc_ata.expect("sats_vault_btc_ata is not set"),
297 authority_btc_ata: self.authority_btc_ata.expect("authority_btc_ata is not set"),
298 token_program: self.token_program.unwrap_or(solana_address::address!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
299 associated_token_program: self.associated_token_program.unwrap_or(solana_address::address!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL")),
300 system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
301 event_authority: self.event_authority.expect("event_authority is not set"),
302 program: self.program.expect("program is not set"),
303 };
304 let args = ClaimSatsInstructionArgs {
305 shares: self.shares.clone().expect("shares is not set"),
306 };
307
308 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
309 }
310}
311
312 pub struct ClaimSatsCpiAccounts<'a, 'b> {
314
315
316 pub authority: &'b solana_account_info::AccountInfo<'a>,
317
318
319 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
320 pub sats_vault: &'b solana_account_info::AccountInfo<'a>,
325 pub miner: &'b solana_account_info::AccountInfo<'a>,
330
331
332 pub btc_mint: &'b solana_account_info::AccountInfo<'a>,
333 pub sats_vault_btc_ata: &'b solana_account_info::AccountInfo<'a>,
338 pub authority_btc_ata: &'b solana_account_info::AccountInfo<'a>,
343
344
345 pub token_program: &'b solana_account_info::AccountInfo<'a>,
346
347
348 pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
349
350
351 pub system_program: &'b solana_account_info::AccountInfo<'a>,
352
353
354 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
355
356
357 pub program: &'b solana_account_info::AccountInfo<'a>,
358 }
359
360pub struct ClaimSatsCpi<'a, 'b> {
362 pub __program: &'b solana_account_info::AccountInfo<'a>,
364
365
366 pub authority: &'b solana_account_info::AccountInfo<'a>,
367
368
369 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
370 pub sats_vault: &'b solana_account_info::AccountInfo<'a>,
375 pub miner: &'b solana_account_info::AccountInfo<'a>,
380
381
382 pub btc_mint: &'b solana_account_info::AccountInfo<'a>,
383 pub sats_vault_btc_ata: &'b solana_account_info::AccountInfo<'a>,
388 pub authority_btc_ata: &'b solana_account_info::AccountInfo<'a>,
393
394
395 pub token_program: &'b solana_account_info::AccountInfo<'a>,
396
397
398 pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
399
400
401 pub system_program: &'b solana_account_info::AccountInfo<'a>,
402
403
404 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
405
406
407 pub program: &'b solana_account_info::AccountInfo<'a>,
408 pub __args: ClaimSatsInstructionArgs,
410 }
411
412impl<'a, 'b> ClaimSatsCpi<'a, 'b> {
413 pub fn new(
414 program: &'b solana_account_info::AccountInfo<'a>,
415 accounts: ClaimSatsCpiAccounts<'a, 'b>,
416 args: ClaimSatsInstructionArgs,
417 ) -> Self {
418 Self {
419 __program: program,
420 authority: accounts.authority,
421 satrush_config: accounts.satrush_config,
422 sats_vault: accounts.sats_vault,
423 miner: accounts.miner,
424 btc_mint: accounts.btc_mint,
425 sats_vault_btc_ata: accounts.sats_vault_btc_ata,
426 authority_btc_ata: accounts.authority_btc_ata,
427 token_program: accounts.token_program,
428 associated_token_program: accounts.associated_token_program,
429 system_program: accounts.system_program,
430 event_authority: accounts.event_authority,
431 program: accounts.program,
432 __args: args,
433 }
434 }
435 #[inline(always)]
436 pub fn invoke(&self) -> solana_program_error::ProgramResult {
437 self.invoke_signed_with_remaining_accounts(&[], &[])
438 }
439 #[inline(always)]
440 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
441 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
442 }
443 #[inline(always)]
444 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
445 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
446 }
447 #[allow(clippy::arithmetic_side_effects)]
448 #[allow(clippy::clone_on_copy)]
449 #[allow(clippy::vec_init_then_push)]
450 pub fn invoke_signed_with_remaining_accounts(
451 &self,
452 signers_seeds: &[&[&[u8]]],
453 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
454 ) -> solana_program_error::ProgramResult {
455 let mut accounts = Vec::with_capacity(12+ remaining_accounts.len());
456 accounts.push(solana_instruction::AccountMeta::new(
457 *self.authority.key,
458 true
459 ));
460 accounts.push(solana_instruction::AccountMeta::new_readonly(
461 *self.satrush_config.key,
462 false
463 ));
464 accounts.push(solana_instruction::AccountMeta::new(
465 *self.sats_vault.key,
466 false
467 ));
468 accounts.push(solana_instruction::AccountMeta::new(
469 *self.miner.key,
470 false
471 ));
472 accounts.push(solana_instruction::AccountMeta::new_readonly(
473 *self.btc_mint.key,
474 false
475 ));
476 accounts.push(solana_instruction::AccountMeta::new(
477 *self.sats_vault_btc_ata.key,
478 false
479 ));
480 accounts.push(solana_instruction::AccountMeta::new(
481 *self.authority_btc_ata.key,
482 false
483 ));
484 accounts.push(solana_instruction::AccountMeta::new_readonly(
485 *self.token_program.key,
486 false
487 ));
488 accounts.push(solana_instruction::AccountMeta::new_readonly(
489 *self.associated_token_program.key,
490 false
491 ));
492 accounts.push(solana_instruction::AccountMeta::new_readonly(
493 *self.system_program.key,
494 false
495 ));
496 accounts.push(solana_instruction::AccountMeta::new_readonly(
497 *self.event_authority.key,
498 false
499 ));
500 accounts.push(solana_instruction::AccountMeta::new_readonly(
501 *self.program.key,
502 false
503 ));
504 remaining_accounts.iter().for_each(|remaining_account| {
505 accounts.push(solana_instruction::AccountMeta {
506 pubkey: *remaining_account.0.key,
507 is_signer: remaining_account.1,
508 is_writable: remaining_account.2,
509 })
510 });
511 let mut data = ClaimSatsInstructionData::new().try_to_vec().unwrap();
512 let mut args = self.__args.try_to_vec().unwrap();
513 data.append(&mut args);
514
515 let instruction = solana_instruction::Instruction {
516 program_id: crate::SATRUSH_ID,
517 accounts,
518 data,
519 };
520 let mut account_infos = Vec::with_capacity(13 + remaining_accounts.len());
521 account_infos.push(self.__program.clone());
522 account_infos.push(self.authority.clone());
523 account_infos.push(self.satrush_config.clone());
524 account_infos.push(self.sats_vault.clone());
525 account_infos.push(self.miner.clone());
526 account_infos.push(self.btc_mint.clone());
527 account_infos.push(self.sats_vault_btc_ata.clone());
528 account_infos.push(self.authority_btc_ata.clone());
529 account_infos.push(self.token_program.clone());
530 account_infos.push(self.associated_token_program.clone());
531 account_infos.push(self.system_program.clone());
532 account_infos.push(self.event_authority.clone());
533 account_infos.push(self.program.clone());
534 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
535
536 if signers_seeds.is_empty() {
537 solana_cpi::invoke(&instruction, &account_infos)
538 } else {
539 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
540 }
541 }
542}
543
544#[derive(Clone, Debug)]
561pub struct ClaimSatsCpiBuilder<'a, 'b> {
562 instruction: Box<ClaimSatsCpiBuilderInstruction<'a, 'b>>,
563}
564
565impl<'a, 'b> ClaimSatsCpiBuilder<'a, 'b> {
566 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
567 let instruction = Box::new(ClaimSatsCpiBuilderInstruction {
568 __program: program,
569 authority: None,
570 satrush_config: None,
571 sats_vault: None,
572 miner: None,
573 btc_mint: None,
574 sats_vault_btc_ata: None,
575 authority_btc_ata: None,
576 token_program: None,
577 associated_token_program: None,
578 system_program: None,
579 event_authority: None,
580 program: None,
581 shares: None,
582 __remaining_accounts: Vec::new(),
583 });
584 Self { instruction }
585 }
586 #[inline(always)]
587 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
588 self.instruction.authority = Some(authority);
589 self
590 }
591 #[inline(always)]
592 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
593 self.instruction.satrush_config = Some(satrush_config);
594 self
595 }
596 #[inline(always)]
598 pub fn sats_vault(&mut self, sats_vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
599 self.instruction.sats_vault = Some(sats_vault);
600 self
601 }
602 #[inline(always)]
604 pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
605 self.instruction.miner = Some(miner);
606 self
607 }
608 #[inline(always)]
609 pub fn btc_mint(&mut self, btc_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
610 self.instruction.btc_mint = Some(btc_mint);
611 self
612 }
613 #[inline(always)]
615 pub fn sats_vault_btc_ata(&mut self, sats_vault_btc_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
616 self.instruction.sats_vault_btc_ata = Some(sats_vault_btc_ata);
617 self
618 }
619 #[inline(always)]
621 pub fn authority_btc_ata(&mut self, authority_btc_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
622 self.instruction.authority_btc_ata = Some(authority_btc_ata);
623 self
624 }
625 #[inline(always)]
626 pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
627 self.instruction.token_program = Some(token_program);
628 self
629 }
630 #[inline(always)]
631 pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
632 self.instruction.associated_token_program = Some(associated_token_program);
633 self
634 }
635 #[inline(always)]
636 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
637 self.instruction.system_program = Some(system_program);
638 self
639 }
640 #[inline(always)]
641 pub fn event_authority(&mut self, event_authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
642 self.instruction.event_authority = Some(event_authority);
643 self
644 }
645 #[inline(always)]
646 pub fn program(&mut self, program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
647 self.instruction.program = Some(program);
648 self
649 }
650 #[inline(always)]
651 pub fn shares(&mut self, shares: u64) -> &mut Self {
652 self.instruction.shares = Some(shares);
653 self
654 }
655 #[inline(always)]
657 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
658 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
659 self
660 }
661 #[inline(always)]
666 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
667 self.instruction.__remaining_accounts.extend_from_slice(accounts);
668 self
669 }
670 #[inline(always)]
671 pub fn invoke(&self) -> solana_program_error::ProgramResult {
672 self.invoke_signed(&[])
673 }
674 #[allow(clippy::clone_on_copy)]
675 #[allow(clippy::vec_init_then_push)]
676 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
677 let args = ClaimSatsInstructionArgs {
678 shares: self.instruction.shares.clone().expect("shares is not set"),
679 };
680 let instruction = ClaimSatsCpi {
681 __program: self.instruction.__program,
682
683 authority: self.instruction.authority.expect("authority is not set"),
684
685 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
686
687 sats_vault: self.instruction.sats_vault.expect("sats_vault is not set"),
688
689 miner: self.instruction.miner.expect("miner is not set"),
690
691 btc_mint: self.instruction.btc_mint.expect("btc_mint is not set"),
692
693 sats_vault_btc_ata: self.instruction.sats_vault_btc_ata.expect("sats_vault_btc_ata is not set"),
694
695 authority_btc_ata: self.instruction.authority_btc_ata.expect("authority_btc_ata is not set"),
696
697 token_program: self.instruction.token_program.expect("token_program is not set"),
698
699 associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"),
700
701 system_program: self.instruction.system_program.expect("system_program is not set"),
702
703 event_authority: self.instruction.event_authority.expect("event_authority is not set"),
704
705 program: self.instruction.program.expect("program is not set"),
706 __args: args,
707 };
708 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
709 }
710}
711
712#[derive(Clone, Debug)]
713struct ClaimSatsCpiBuilderInstruction<'a, 'b> {
714 __program: &'b solana_account_info::AccountInfo<'a>,
715 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
716 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
717 sats_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
718 miner: Option<&'b solana_account_info::AccountInfo<'a>>,
719 btc_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
720 sats_vault_btc_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
721 authority_btc_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
722 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
723 associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
724 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
725 event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
726 program: Option<&'b solana_account_info::AccountInfo<'a>>,
727 shares: Option<u64>,
728 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
730}
731