1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const DEPLOY_PUBLIC_DISCRIMINATOR: [u8; 8] = [193, 31, 240, 159, 30, 224, 157, 85];
12
13#[derive(Debug)]
15pub struct DeployPublic {
16
17
18 pub authority: solana_address::Address,
19
20
21 pub satrush_config: solana_address::Address,
22
23
24 pub board: solana_address::Address,
25 pub round: solana_address::Address,
32
33
34 pub usd_mint: solana_address::Address,
35 pub authority_usd_ata: solana_address::Address,
40 pub board_usd_ata: solana_address::Address,
45 pub public_deployment: solana_address::Address,
51 pub miner: solana_address::Address,
57
58
59 pub token_program: solana_address::Address,
60
61
62 pub system_program: solana_address::Address,
63 }
64
65impl DeployPublic {
66 pub fn instruction(&self, args: DeployPublicInstructionArgs) -> solana_instruction::Instruction {
67 self.instruction_with_remaining_accounts(args, &[])
68 }
69 #[allow(clippy::arithmetic_side_effects)]
70 #[allow(clippy::vec_init_then_push)]
71 pub fn instruction_with_remaining_accounts(&self, args: DeployPublicInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
72 let mut accounts = Vec::with_capacity(11+ remaining_accounts.len());
73 accounts.push(solana_instruction::AccountMeta::new(
74 self.authority,
75 true
76 ));
77 accounts.push(solana_instruction::AccountMeta::new_readonly(
78 self.satrush_config,
79 false
80 ));
81 accounts.push(solana_instruction::AccountMeta::new(
82 self.board,
83 false
84 ));
85 accounts.push(solana_instruction::AccountMeta::new(
86 self.round,
87 false
88 ));
89 accounts.push(solana_instruction::AccountMeta::new_readonly(
90 self.usd_mint,
91 false
92 ));
93 accounts.push(solana_instruction::AccountMeta::new(
94 self.authority_usd_ata,
95 false
96 ));
97 accounts.push(solana_instruction::AccountMeta::new(
98 self.board_usd_ata,
99 false
100 ));
101 accounts.push(solana_instruction::AccountMeta::new(
102 self.public_deployment,
103 false
104 ));
105 accounts.push(solana_instruction::AccountMeta::new(
106 self.miner,
107 false
108 ));
109 accounts.push(solana_instruction::AccountMeta::new_readonly(
110 self.token_program,
111 false
112 ));
113 accounts.push(solana_instruction::AccountMeta::new_readonly(
114 self.system_program,
115 false
116 ));
117 accounts.extend_from_slice(remaining_accounts);
118 let mut data = DeployPublicInstructionData::new().try_to_vec().unwrap();
119 let mut args = args.try_to_vec().unwrap();
120 data.append(&mut args);
121
122 solana_instruction::Instruction {
123 program_id: crate::SATRUSH_ID,
124 accounts,
125 data,
126 }
127 }
128}
129
130#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
131 pub struct DeployPublicInstructionData {
132 discriminator: [u8; 8],
133 }
134
135impl DeployPublicInstructionData {
136 pub fn new() -> Self {
137 Self {
138 discriminator: [193, 31, 240, 159, 30, 224, 157, 85],
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 DeployPublicInstructionData {
148 fn default() -> Self {
149 Self::new()
150 }
151}
152
153#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
154 pub struct DeployPublicInstructionArgs {
155 pub selection_mask: u32,
156 pub amount: u64,
157 }
158
159impl DeployPublicInstructionArgs {
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)]
182pub struct DeployPublicBuilder {
183 authority: Option<solana_address::Address>,
184 satrush_config: Option<solana_address::Address>,
185 board: Option<solana_address::Address>,
186 round: Option<solana_address::Address>,
187 usd_mint: Option<solana_address::Address>,
188 authority_usd_ata: Option<solana_address::Address>,
189 board_usd_ata: Option<solana_address::Address>,
190 public_deployment: Option<solana_address::Address>,
191 miner: Option<solana_address::Address>,
192 token_program: Option<solana_address::Address>,
193 system_program: Option<solana_address::Address>,
194 selection_mask: Option<u32>,
195 amount: Option<u64>,
196 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
197}
198
199impl DeployPublicBuilder {
200 pub fn new() -> Self {
201 Self::default()
202 }
203 #[inline(always)]
204 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
205 self.authority = Some(authority);
206 self
207 }
208 #[inline(always)]
209 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
210 self.satrush_config = Some(satrush_config);
211 self
212 }
213 #[inline(always)]
214 pub fn board(&mut self, board: solana_address::Address) -> &mut Self {
215 self.board = Some(board);
216 self
217 }
218 #[inline(always)]
222 pub fn round(&mut self, round: solana_address::Address) -> &mut Self {
223 self.round = Some(round);
224 self
225 }
226 #[inline(always)]
227 pub fn usd_mint(&mut self, usd_mint: solana_address::Address) -> &mut Self {
228 self.usd_mint = Some(usd_mint);
229 self
230 }
231 #[inline(always)]
233 pub fn authority_usd_ata(&mut self, authority_usd_ata: solana_address::Address) -> &mut Self {
234 self.authority_usd_ata = Some(authority_usd_ata);
235 self
236 }
237 #[inline(always)]
239 pub fn board_usd_ata(&mut self, board_usd_ata: solana_address::Address) -> &mut Self {
240 self.board_usd_ata = Some(board_usd_ata);
241 self
242 }
243 #[inline(always)]
246 pub fn public_deployment(&mut self, public_deployment: solana_address::Address) -> &mut Self {
247 self.public_deployment = Some(public_deployment);
248 self
249 }
250 #[inline(always)]
253 pub fn miner(&mut self, miner: solana_address::Address) -> &mut Self {
254 self.miner = Some(miner);
255 self
256 }
257 #[inline(always)]
259 pub fn token_program(&mut self, token_program: solana_address::Address) -> &mut Self {
260 self.token_program = Some(token_program);
261 self
262 }
263 #[inline(always)]
265 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
266 self.system_program = Some(system_program);
267 self
268 }
269 #[inline(always)]
270 pub fn selection_mask(&mut self, selection_mask: u32) -> &mut Self {
271 self.selection_mask = Some(selection_mask);
272 self
273 }
274 #[inline(always)]
275 pub fn amount(&mut self, amount: u64) -> &mut Self {
276 self.amount = Some(amount);
277 self
278 }
279 #[inline(always)]
281 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
282 self.__remaining_accounts.push(account);
283 self
284 }
285 #[inline(always)]
287 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
288 self.__remaining_accounts.extend_from_slice(accounts);
289 self
290 }
291 #[allow(clippy::clone_on_copy)]
292 pub fn instruction(&self) -> solana_instruction::Instruction {
293 let accounts = DeployPublic {
294 authority: self.authority.expect("authority is not set"),
295 satrush_config: self.satrush_config.expect("satrush_config is not set"),
296 board: self.board.expect("board is not set"),
297 round: self.round.expect("round is not set"),
298 usd_mint: self.usd_mint.expect("usd_mint is not set"),
299 authority_usd_ata: self.authority_usd_ata.expect("authority_usd_ata is not set"),
300 board_usd_ata: self.board_usd_ata.expect("board_usd_ata is not set"),
301 public_deployment: self.public_deployment.expect("public_deployment is not set"),
302 miner: self.miner.expect("miner is not set"),
303 token_program: self.token_program.unwrap_or(solana_address::address!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
304 system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
305 };
306 let args = DeployPublicInstructionArgs {
307 selection_mask: self.selection_mask.clone().expect("selection_mask is not set"),
308 amount: self.amount.clone().expect("amount is not set"),
309 };
310
311 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
312 }
313}
314
315 pub struct DeployPublicCpiAccounts<'a, 'b> {
317
318
319 pub authority: &'b solana_account_info::AccountInfo<'a>,
320
321
322 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
323
324
325 pub board: &'b solana_account_info::AccountInfo<'a>,
326 pub round: &'b solana_account_info::AccountInfo<'a>,
333
334
335 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
336 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
341 pub board_usd_ata: &'b solana_account_info::AccountInfo<'a>,
346 pub public_deployment: &'b solana_account_info::AccountInfo<'a>,
352 pub miner: &'b solana_account_info::AccountInfo<'a>,
358
359
360 pub token_program: &'b solana_account_info::AccountInfo<'a>,
361
362
363 pub system_program: &'b solana_account_info::AccountInfo<'a>,
364 }
365
366pub struct DeployPublicCpi<'a, 'b> {
368 pub __program: &'b solana_account_info::AccountInfo<'a>,
370
371
372 pub authority: &'b solana_account_info::AccountInfo<'a>,
373
374
375 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
376
377
378 pub board: &'b solana_account_info::AccountInfo<'a>,
379 pub round: &'b solana_account_info::AccountInfo<'a>,
386
387
388 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
389 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
394 pub board_usd_ata: &'b solana_account_info::AccountInfo<'a>,
399 pub public_deployment: &'b solana_account_info::AccountInfo<'a>,
405 pub miner: &'b solana_account_info::AccountInfo<'a>,
411
412
413 pub token_program: &'b solana_account_info::AccountInfo<'a>,
414
415
416 pub system_program: &'b solana_account_info::AccountInfo<'a>,
417 pub __args: DeployPublicInstructionArgs,
419 }
420
421impl<'a, 'b> DeployPublicCpi<'a, 'b> {
422 pub fn new(
423 program: &'b solana_account_info::AccountInfo<'a>,
424 accounts: DeployPublicCpiAccounts<'a, 'b>,
425 args: DeployPublicInstructionArgs,
426 ) -> Self {
427 Self {
428 __program: program,
429 authority: accounts.authority,
430 satrush_config: accounts.satrush_config,
431 board: accounts.board,
432 round: accounts.round,
433 usd_mint: accounts.usd_mint,
434 authority_usd_ata: accounts.authority_usd_ata,
435 board_usd_ata: accounts.board_usd_ata,
436 public_deployment: accounts.public_deployment,
437 miner: accounts.miner,
438 token_program: accounts.token_program,
439 system_program: accounts.system_program,
440 __args: args,
441 }
442 }
443 #[inline(always)]
444 pub fn invoke(&self) -> solana_program_error::ProgramResult {
445 self.invoke_signed_with_remaining_accounts(&[], &[])
446 }
447 #[inline(always)]
448 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
449 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
450 }
451 #[inline(always)]
452 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
453 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
454 }
455 #[allow(clippy::arithmetic_side_effects)]
456 #[allow(clippy::clone_on_copy)]
457 #[allow(clippy::vec_init_then_push)]
458 pub fn invoke_signed_with_remaining_accounts(
459 &self,
460 signers_seeds: &[&[&[u8]]],
461 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
462 ) -> solana_program_error::ProgramResult {
463 let mut accounts = Vec::with_capacity(11+ remaining_accounts.len());
464 accounts.push(solana_instruction::AccountMeta::new(
465 *self.authority.key,
466 true
467 ));
468 accounts.push(solana_instruction::AccountMeta::new_readonly(
469 *self.satrush_config.key,
470 false
471 ));
472 accounts.push(solana_instruction::AccountMeta::new(
473 *self.board.key,
474 false
475 ));
476 accounts.push(solana_instruction::AccountMeta::new(
477 *self.round.key,
478 false
479 ));
480 accounts.push(solana_instruction::AccountMeta::new_readonly(
481 *self.usd_mint.key,
482 false
483 ));
484 accounts.push(solana_instruction::AccountMeta::new(
485 *self.authority_usd_ata.key,
486 false
487 ));
488 accounts.push(solana_instruction::AccountMeta::new(
489 *self.board_usd_ata.key,
490 false
491 ));
492 accounts.push(solana_instruction::AccountMeta::new(
493 *self.public_deployment.key,
494 false
495 ));
496 accounts.push(solana_instruction::AccountMeta::new(
497 *self.miner.key,
498 false
499 ));
500 accounts.push(solana_instruction::AccountMeta::new_readonly(
501 *self.token_program.key,
502 false
503 ));
504 accounts.push(solana_instruction::AccountMeta::new_readonly(
505 *self.system_program.key,
506 false
507 ));
508 remaining_accounts.iter().for_each(|remaining_account| {
509 accounts.push(solana_instruction::AccountMeta {
510 pubkey: *remaining_account.0.key,
511 is_signer: remaining_account.1,
512 is_writable: remaining_account.2,
513 })
514 });
515 let mut data = DeployPublicInstructionData::new().try_to_vec().unwrap();
516 let mut args = self.__args.try_to_vec().unwrap();
517 data.append(&mut args);
518
519 let instruction = solana_instruction::Instruction {
520 program_id: crate::SATRUSH_ID,
521 accounts,
522 data,
523 };
524 let mut account_infos = Vec::with_capacity(12 + remaining_accounts.len());
525 account_infos.push(self.__program.clone());
526 account_infos.push(self.authority.clone());
527 account_infos.push(self.satrush_config.clone());
528 account_infos.push(self.board.clone());
529 account_infos.push(self.round.clone());
530 account_infos.push(self.usd_mint.clone());
531 account_infos.push(self.authority_usd_ata.clone());
532 account_infos.push(self.board_usd_ata.clone());
533 account_infos.push(self.public_deployment.clone());
534 account_infos.push(self.miner.clone());
535 account_infos.push(self.token_program.clone());
536 account_infos.push(self.system_program.clone());
537 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
538
539 if signers_seeds.is_empty() {
540 solana_cpi::invoke(&instruction, &account_infos)
541 } else {
542 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
543 }
544 }
545}
546
547#[derive(Clone, Debug)]
563pub struct DeployPublicCpiBuilder<'a, 'b> {
564 instruction: Box<DeployPublicCpiBuilderInstruction<'a, 'b>>,
565}
566
567impl<'a, 'b> DeployPublicCpiBuilder<'a, 'b> {
568 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
569 let instruction = Box::new(DeployPublicCpiBuilderInstruction {
570 __program: program,
571 authority: None,
572 satrush_config: None,
573 board: None,
574 round: None,
575 usd_mint: None,
576 authority_usd_ata: None,
577 board_usd_ata: None,
578 public_deployment: None,
579 miner: None,
580 token_program: None,
581 system_program: None,
582 selection_mask: None,
583 amount: None,
584 __remaining_accounts: Vec::new(),
585 });
586 Self { instruction }
587 }
588 #[inline(always)]
589 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
590 self.instruction.authority = Some(authority);
591 self
592 }
593 #[inline(always)]
594 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
595 self.instruction.satrush_config = Some(satrush_config);
596 self
597 }
598 #[inline(always)]
599 pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
600 self.instruction.board = Some(board);
601 self
602 }
603 #[inline(always)]
607 pub fn round(&mut self, round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
608 self.instruction.round = Some(round);
609 self
610 }
611 #[inline(always)]
612 pub fn usd_mint(&mut self, usd_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
613 self.instruction.usd_mint = Some(usd_mint);
614 self
615 }
616 #[inline(always)]
618 pub fn authority_usd_ata(&mut self, authority_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
619 self.instruction.authority_usd_ata = Some(authority_usd_ata);
620 self
621 }
622 #[inline(always)]
624 pub fn board_usd_ata(&mut self, board_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
625 self.instruction.board_usd_ata = Some(board_usd_ata);
626 self
627 }
628 #[inline(always)]
631 pub fn public_deployment(&mut self, public_deployment: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
632 self.instruction.public_deployment = Some(public_deployment);
633 self
634 }
635 #[inline(always)]
638 pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
639 self.instruction.miner = Some(miner);
640 self
641 }
642 #[inline(always)]
643 pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
644 self.instruction.token_program = Some(token_program);
645 self
646 }
647 #[inline(always)]
648 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
649 self.instruction.system_program = Some(system_program);
650 self
651 }
652 #[inline(always)]
653 pub fn selection_mask(&mut self, selection_mask: u32) -> &mut Self {
654 self.instruction.selection_mask = Some(selection_mask);
655 self
656 }
657 #[inline(always)]
658 pub fn amount(&mut self, amount: u64) -> &mut Self {
659 self.instruction.amount = Some(amount);
660 self
661 }
662 #[inline(always)]
664 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
665 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
666 self
667 }
668 #[inline(always)]
673 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
674 self.instruction.__remaining_accounts.extend_from_slice(accounts);
675 self
676 }
677 #[inline(always)]
678 pub fn invoke(&self) -> solana_program_error::ProgramResult {
679 self.invoke_signed(&[])
680 }
681 #[allow(clippy::clone_on_copy)]
682 #[allow(clippy::vec_init_then_push)]
683 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
684 let args = DeployPublicInstructionArgs {
685 selection_mask: self.instruction.selection_mask.clone().expect("selection_mask is not set"),
686 amount: self.instruction.amount.clone().expect("amount is not set"),
687 };
688 let instruction = DeployPublicCpi {
689 __program: self.instruction.__program,
690
691 authority: self.instruction.authority.expect("authority is not set"),
692
693 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
694
695 board: self.instruction.board.expect("board is not set"),
696
697 round: self.instruction.round.expect("round is not set"),
698
699 usd_mint: self.instruction.usd_mint.expect("usd_mint is not set"),
700
701 authority_usd_ata: self.instruction.authority_usd_ata.expect("authority_usd_ata is not set"),
702
703 board_usd_ata: self.instruction.board_usd_ata.expect("board_usd_ata is not set"),
704
705 public_deployment: self.instruction.public_deployment.expect("public_deployment is not set"),
706
707 miner: self.instruction.miner.expect("miner is not set"),
708
709 token_program: self.instruction.token_program.expect("token_program is not set"),
710
711 system_program: self.instruction.system_program.expect("system_program is not set"),
712 __args: args,
713 };
714 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
715 }
716}
717
718#[derive(Clone, Debug)]
719struct DeployPublicCpiBuilderInstruction<'a, 'b> {
720 __program: &'b solana_account_info::AccountInfo<'a>,
721 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
722 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
723 board: Option<&'b solana_account_info::AccountInfo<'a>>,
724 round: Option<&'b solana_account_info::AccountInfo<'a>>,
725 usd_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
726 authority_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
727 board_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
728 public_deployment: Option<&'b solana_account_info::AccountInfo<'a>>,
729 miner: Option<&'b solana_account_info::AccountInfo<'a>>,
730 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
731 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
732 selection_mask: Option<u32>,
733 amount: Option<u64>,
734 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
736}
737