1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const TOP_UP_PUBLIC_AUTOMATION_DISCRIMINATOR: [u8; 8] = [1, 96, 199, 199, 107, 118, 193, 87];
12
13#[derive(Debug)]
15pub struct TopUpPublicAutomation {
16
17
18 pub authority: solana_address::Address,
19
20
21 pub satrush_config: solana_address::Address,
22
23
24 pub public_automation: solana_address::Address,
25 pub miner: solana_address::Address,
31
32
33 pub usd_mint: solana_address::Address,
34 pub authority_usd_ata: solana_address::Address,
41
42
43 pub automation_usd_ata: solana_address::Address,
44
45
46 pub token_program: solana_address::Address,
47 }
48
49impl TopUpPublicAutomation {
50 pub fn instruction(&self, args: TopUpPublicAutomationInstructionArgs) -> solana_instruction::Instruction {
51 self.instruction_with_remaining_accounts(args, &[])
52 }
53 #[allow(clippy::arithmetic_side_effects)]
54 #[allow(clippy::vec_init_then_push)]
55 pub fn instruction_with_remaining_accounts(&self, args: TopUpPublicAutomationInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
56 let mut accounts = Vec::with_capacity(8+ remaining_accounts.len());
57 accounts.push(solana_instruction::AccountMeta::new(
58 self.authority,
59 true
60 ));
61 accounts.push(solana_instruction::AccountMeta::new_readonly(
62 self.satrush_config,
63 false
64 ));
65 accounts.push(solana_instruction::AccountMeta::new(
66 self.public_automation,
67 false
68 ));
69 accounts.push(solana_instruction::AccountMeta::new(
70 self.miner,
71 false
72 ));
73 accounts.push(solana_instruction::AccountMeta::new_readonly(
74 self.usd_mint,
75 false
76 ));
77 accounts.push(solana_instruction::AccountMeta::new(
78 self.authority_usd_ata,
79 false
80 ));
81 accounts.push(solana_instruction::AccountMeta::new(
82 self.automation_usd_ata,
83 false
84 ));
85 accounts.push(solana_instruction::AccountMeta::new_readonly(
86 self.token_program,
87 false
88 ));
89 accounts.extend_from_slice(remaining_accounts);
90 let mut data = TopUpPublicAutomationInstructionData::new().try_to_vec().unwrap();
91 let mut args = args.try_to_vec().unwrap();
92 data.append(&mut args);
93
94 solana_instruction::Instruction {
95 program_id: crate::SATRUSH_ID,
96 accounts,
97 data,
98 }
99 }
100}
101
102#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
103 pub struct TopUpPublicAutomationInstructionData {
104 discriminator: [u8; 8],
105 }
106
107impl TopUpPublicAutomationInstructionData {
108 pub fn new() -> Self {
109 Self {
110 discriminator: [1, 96, 199, 199, 107, 118, 193, 87],
111 }
112 }
113
114 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
115 borsh::to_vec(self)
116 }
117 }
118
119impl Default for TopUpPublicAutomationInstructionData {
120 fn default() -> Self {
121 Self::new()
122 }
123}
124
125#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
126 pub struct TopUpPublicAutomationInstructionArgs {
127 pub amount: u64,
128 }
129
130impl TopUpPublicAutomationInstructionArgs {
131 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
132 borsh::to_vec(self)
133 }
134}
135
136
137#[derive(Clone, Debug, Default)]
150pub struct TopUpPublicAutomationBuilder {
151 authority: Option<solana_address::Address>,
152 satrush_config: Option<solana_address::Address>,
153 public_automation: Option<solana_address::Address>,
154 miner: Option<solana_address::Address>,
155 usd_mint: Option<solana_address::Address>,
156 authority_usd_ata: Option<solana_address::Address>,
157 automation_usd_ata: Option<solana_address::Address>,
158 token_program: Option<solana_address::Address>,
159 amount: Option<u64>,
160 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
161}
162
163impl TopUpPublicAutomationBuilder {
164 pub fn new() -> Self {
165 Self::default()
166 }
167 #[inline(always)]
168 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
169 self.authority = Some(authority);
170 self
171 }
172 #[inline(always)]
173 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
174 self.satrush_config = Some(satrush_config);
175 self
176 }
177 #[inline(always)]
178 pub fn public_automation(&mut self, public_automation: solana_address::Address) -> &mut Self {
179 self.public_automation = Some(public_automation);
180 self
181 }
182 #[inline(always)]
185 pub fn miner(&mut self, miner: solana_address::Address) -> &mut Self {
186 self.miner = Some(miner);
187 self
188 }
189 #[inline(always)]
190 pub fn usd_mint(&mut self, usd_mint: solana_address::Address) -> &mut Self {
191 self.usd_mint = Some(usd_mint);
192 self
193 }
194 #[inline(always)]
198 pub fn authority_usd_ata(&mut self, authority_usd_ata: solana_address::Address) -> &mut Self {
199 self.authority_usd_ata = Some(authority_usd_ata);
200 self
201 }
202 #[inline(always)]
203 pub fn automation_usd_ata(&mut self, automation_usd_ata: solana_address::Address) -> &mut Self {
204 self.automation_usd_ata = Some(automation_usd_ata);
205 self
206 }
207 #[inline(always)]
209 pub fn token_program(&mut self, token_program: solana_address::Address) -> &mut Self {
210 self.token_program = Some(token_program);
211 self
212 }
213 #[inline(always)]
214 pub fn amount(&mut self, amount: u64) -> &mut Self {
215 self.amount = Some(amount);
216 self
217 }
218 #[inline(always)]
220 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
221 self.__remaining_accounts.push(account);
222 self
223 }
224 #[inline(always)]
226 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
227 self.__remaining_accounts.extend_from_slice(accounts);
228 self
229 }
230 #[allow(clippy::clone_on_copy)]
231 pub fn instruction(&self) -> solana_instruction::Instruction {
232 let accounts = TopUpPublicAutomation {
233 authority: self.authority.expect("authority is not set"),
234 satrush_config: self.satrush_config.expect("satrush_config is not set"),
235 public_automation: self.public_automation.expect("public_automation is not set"),
236 miner: self.miner.expect("miner is not set"),
237 usd_mint: self.usd_mint.expect("usd_mint is not set"),
238 authority_usd_ata: self.authority_usd_ata.expect("authority_usd_ata is not set"),
239 automation_usd_ata: self.automation_usd_ata.expect("automation_usd_ata is not set"),
240 token_program: self.token_program.unwrap_or(solana_address::address!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
241 };
242 let args = TopUpPublicAutomationInstructionArgs {
243 amount: self.amount.clone().expect("amount is not set"),
244 };
245
246 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
247 }
248}
249
250 pub struct TopUpPublicAutomationCpiAccounts<'a, 'b> {
252
253
254 pub authority: &'b solana_account_info::AccountInfo<'a>,
255
256
257 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
258
259
260 pub public_automation: &'b solana_account_info::AccountInfo<'a>,
261 pub miner: &'b solana_account_info::AccountInfo<'a>,
267
268
269 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
270 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
277
278
279 pub automation_usd_ata: &'b solana_account_info::AccountInfo<'a>,
280
281
282 pub token_program: &'b solana_account_info::AccountInfo<'a>,
283 }
284
285pub struct TopUpPublicAutomationCpi<'a, 'b> {
287 pub __program: &'b solana_account_info::AccountInfo<'a>,
289
290
291 pub authority: &'b solana_account_info::AccountInfo<'a>,
292
293
294 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
295
296
297 pub public_automation: &'b solana_account_info::AccountInfo<'a>,
298 pub miner: &'b solana_account_info::AccountInfo<'a>,
304
305
306 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
307 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
314
315
316 pub automation_usd_ata: &'b solana_account_info::AccountInfo<'a>,
317
318
319 pub token_program: &'b solana_account_info::AccountInfo<'a>,
320 pub __args: TopUpPublicAutomationInstructionArgs,
322 }
323
324impl<'a, 'b> TopUpPublicAutomationCpi<'a, 'b> {
325 pub fn new(
326 program: &'b solana_account_info::AccountInfo<'a>,
327 accounts: TopUpPublicAutomationCpiAccounts<'a, 'b>,
328 args: TopUpPublicAutomationInstructionArgs,
329 ) -> Self {
330 Self {
331 __program: program,
332 authority: accounts.authority,
333 satrush_config: accounts.satrush_config,
334 public_automation: accounts.public_automation,
335 miner: accounts.miner,
336 usd_mint: accounts.usd_mint,
337 authority_usd_ata: accounts.authority_usd_ata,
338 automation_usd_ata: accounts.automation_usd_ata,
339 token_program: accounts.token_program,
340 __args: args,
341 }
342 }
343 #[inline(always)]
344 pub fn invoke(&self) -> solana_program_error::ProgramResult {
345 self.invoke_signed_with_remaining_accounts(&[], &[])
346 }
347 #[inline(always)]
348 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
349 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
350 }
351 #[inline(always)]
352 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
353 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
354 }
355 #[allow(clippy::arithmetic_side_effects)]
356 #[allow(clippy::clone_on_copy)]
357 #[allow(clippy::vec_init_then_push)]
358 pub fn invoke_signed_with_remaining_accounts(
359 &self,
360 signers_seeds: &[&[&[u8]]],
361 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
362 ) -> solana_program_error::ProgramResult {
363 let mut accounts = Vec::with_capacity(8+ remaining_accounts.len());
364 accounts.push(solana_instruction::AccountMeta::new(
365 *self.authority.key,
366 true
367 ));
368 accounts.push(solana_instruction::AccountMeta::new_readonly(
369 *self.satrush_config.key,
370 false
371 ));
372 accounts.push(solana_instruction::AccountMeta::new(
373 *self.public_automation.key,
374 false
375 ));
376 accounts.push(solana_instruction::AccountMeta::new(
377 *self.miner.key,
378 false
379 ));
380 accounts.push(solana_instruction::AccountMeta::new_readonly(
381 *self.usd_mint.key,
382 false
383 ));
384 accounts.push(solana_instruction::AccountMeta::new(
385 *self.authority_usd_ata.key,
386 false
387 ));
388 accounts.push(solana_instruction::AccountMeta::new(
389 *self.automation_usd_ata.key,
390 false
391 ));
392 accounts.push(solana_instruction::AccountMeta::new_readonly(
393 *self.token_program.key,
394 false
395 ));
396 remaining_accounts.iter().for_each(|remaining_account| {
397 accounts.push(solana_instruction::AccountMeta {
398 pubkey: *remaining_account.0.key,
399 is_signer: remaining_account.1,
400 is_writable: remaining_account.2,
401 })
402 });
403 let mut data = TopUpPublicAutomationInstructionData::new().try_to_vec().unwrap();
404 let mut args = self.__args.try_to_vec().unwrap();
405 data.append(&mut args);
406
407 let instruction = solana_instruction::Instruction {
408 program_id: crate::SATRUSH_ID,
409 accounts,
410 data,
411 };
412 let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
413 account_infos.push(self.__program.clone());
414 account_infos.push(self.authority.clone());
415 account_infos.push(self.satrush_config.clone());
416 account_infos.push(self.public_automation.clone());
417 account_infos.push(self.miner.clone());
418 account_infos.push(self.usd_mint.clone());
419 account_infos.push(self.authority_usd_ata.clone());
420 account_infos.push(self.automation_usd_ata.clone());
421 account_infos.push(self.token_program.clone());
422 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
423
424 if signers_seeds.is_empty() {
425 solana_cpi::invoke(&instruction, &account_infos)
426 } else {
427 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
428 }
429 }
430}
431
432#[derive(Clone, Debug)]
445pub struct TopUpPublicAutomationCpiBuilder<'a, 'b> {
446 instruction: Box<TopUpPublicAutomationCpiBuilderInstruction<'a, 'b>>,
447}
448
449impl<'a, 'b> TopUpPublicAutomationCpiBuilder<'a, 'b> {
450 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
451 let instruction = Box::new(TopUpPublicAutomationCpiBuilderInstruction {
452 __program: program,
453 authority: None,
454 satrush_config: None,
455 public_automation: None,
456 miner: None,
457 usd_mint: None,
458 authority_usd_ata: None,
459 automation_usd_ata: None,
460 token_program: None,
461 amount: None,
462 __remaining_accounts: Vec::new(),
463 });
464 Self { instruction }
465 }
466 #[inline(always)]
467 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
468 self.instruction.authority = Some(authority);
469 self
470 }
471 #[inline(always)]
472 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
473 self.instruction.satrush_config = Some(satrush_config);
474 self
475 }
476 #[inline(always)]
477 pub fn public_automation(&mut self, public_automation: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
478 self.instruction.public_automation = Some(public_automation);
479 self
480 }
481 #[inline(always)]
484 pub fn miner(&mut self, miner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
485 self.instruction.miner = Some(miner);
486 self
487 }
488 #[inline(always)]
489 pub fn usd_mint(&mut self, usd_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
490 self.instruction.usd_mint = Some(usd_mint);
491 self
492 }
493 #[inline(always)]
497 pub fn authority_usd_ata(&mut self, authority_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
498 self.instruction.authority_usd_ata = Some(authority_usd_ata);
499 self
500 }
501 #[inline(always)]
502 pub fn automation_usd_ata(&mut self, automation_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
503 self.instruction.automation_usd_ata = Some(automation_usd_ata);
504 self
505 }
506 #[inline(always)]
507 pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
508 self.instruction.token_program = Some(token_program);
509 self
510 }
511 #[inline(always)]
512 pub fn amount(&mut self, amount: u64) -> &mut Self {
513 self.instruction.amount = Some(amount);
514 self
515 }
516 #[inline(always)]
518 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
519 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
520 self
521 }
522 #[inline(always)]
527 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
528 self.instruction.__remaining_accounts.extend_from_slice(accounts);
529 self
530 }
531 #[inline(always)]
532 pub fn invoke(&self) -> solana_program_error::ProgramResult {
533 self.invoke_signed(&[])
534 }
535 #[allow(clippy::clone_on_copy)]
536 #[allow(clippy::vec_init_then_push)]
537 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
538 let args = TopUpPublicAutomationInstructionArgs {
539 amount: self.instruction.amount.clone().expect("amount is not set"),
540 };
541 let instruction = TopUpPublicAutomationCpi {
542 __program: self.instruction.__program,
543
544 authority: self.instruction.authority.expect("authority is not set"),
545
546 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
547
548 public_automation: self.instruction.public_automation.expect("public_automation is not set"),
549
550 miner: self.instruction.miner.expect("miner is not set"),
551
552 usd_mint: self.instruction.usd_mint.expect("usd_mint is not set"),
553
554 authority_usd_ata: self.instruction.authority_usd_ata.expect("authority_usd_ata is not set"),
555
556 automation_usd_ata: self.instruction.automation_usd_ata.expect("automation_usd_ata is not set"),
557
558 token_program: self.instruction.token_program.expect("token_program is not set"),
559 __args: args,
560 };
561 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
562 }
563}
564
565#[derive(Clone, Debug)]
566struct TopUpPublicAutomationCpiBuilderInstruction<'a, 'b> {
567 __program: &'b solana_account_info::AccountInfo<'a>,
568 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
569 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
570 public_automation: Option<&'b solana_account_info::AccountInfo<'a>>,
571 miner: Option<&'b solana_account_info::AccountInfo<'a>>,
572 usd_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
573 authority_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
574 automation_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
575 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
576 amount: Option<u64>,
577 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
579}
580