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
26
27 pub usd_mint: solana_address::Address,
28
29
30 pub authority_usd_ata: solana_address::Address,
31
32
33 pub automation_usd_ata: solana_address::Address,
34
35
36 pub token_program: solana_address::Address,
37 }
38
39impl TopUpPublicAutomation {
40 pub fn instruction(&self, args: TopUpPublicAutomationInstructionArgs) -> solana_instruction::Instruction {
41 self.instruction_with_remaining_accounts(args, &[])
42 }
43 #[allow(clippy::arithmetic_side_effects)]
44 #[allow(clippy::vec_init_then_push)]
45 pub fn instruction_with_remaining_accounts(&self, args: TopUpPublicAutomationInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
46 let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
47 accounts.push(solana_instruction::AccountMeta::new(
48 self.authority,
49 true
50 ));
51 accounts.push(solana_instruction::AccountMeta::new_readonly(
52 self.satrush_config,
53 false
54 ));
55 accounts.push(solana_instruction::AccountMeta::new(
56 self.public_automation,
57 false
58 ));
59 accounts.push(solana_instruction::AccountMeta::new_readonly(
60 self.usd_mint,
61 false
62 ));
63 accounts.push(solana_instruction::AccountMeta::new(
64 self.authority_usd_ata,
65 false
66 ));
67 accounts.push(solana_instruction::AccountMeta::new(
68 self.automation_usd_ata,
69 false
70 ));
71 accounts.push(solana_instruction::AccountMeta::new_readonly(
72 self.token_program,
73 false
74 ));
75 accounts.extend_from_slice(remaining_accounts);
76 let mut data = TopUpPublicAutomationInstructionData::new().try_to_vec().unwrap();
77 let mut args = args.try_to_vec().unwrap();
78 data.append(&mut args);
79
80 solana_instruction::Instruction {
81 program_id: crate::SATRUSH_ID,
82 accounts,
83 data,
84 }
85 }
86}
87
88#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
89 pub struct TopUpPublicAutomationInstructionData {
90 discriminator: [u8; 8],
91 }
92
93impl TopUpPublicAutomationInstructionData {
94 pub fn new() -> Self {
95 Self {
96 discriminator: [1, 96, 199, 199, 107, 118, 193, 87],
97 }
98 }
99
100 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
101 borsh::to_vec(self)
102 }
103 }
104
105impl Default for TopUpPublicAutomationInstructionData {
106 fn default() -> Self {
107 Self::new()
108 }
109}
110
111#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
112 pub struct TopUpPublicAutomationInstructionArgs {
113 pub amount: u64,
114 }
115
116impl TopUpPublicAutomationInstructionArgs {
117 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
118 borsh::to_vec(self)
119 }
120}
121
122
123#[derive(Clone, Debug, Default)]
135pub struct TopUpPublicAutomationBuilder {
136 authority: Option<solana_address::Address>,
137 satrush_config: Option<solana_address::Address>,
138 public_automation: Option<solana_address::Address>,
139 usd_mint: Option<solana_address::Address>,
140 authority_usd_ata: Option<solana_address::Address>,
141 automation_usd_ata: Option<solana_address::Address>,
142 token_program: Option<solana_address::Address>,
143 amount: Option<u64>,
144 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
145}
146
147impl TopUpPublicAutomationBuilder {
148 pub fn new() -> Self {
149 Self::default()
150 }
151 #[inline(always)]
152 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
153 self.authority = Some(authority);
154 self
155 }
156 #[inline(always)]
157 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
158 self.satrush_config = Some(satrush_config);
159 self
160 }
161 #[inline(always)]
162 pub fn public_automation(&mut self, public_automation: solana_address::Address) -> &mut Self {
163 self.public_automation = Some(public_automation);
164 self
165 }
166 #[inline(always)]
167 pub fn usd_mint(&mut self, usd_mint: solana_address::Address) -> &mut Self {
168 self.usd_mint = Some(usd_mint);
169 self
170 }
171 #[inline(always)]
172 pub fn authority_usd_ata(&mut self, authority_usd_ata: solana_address::Address) -> &mut Self {
173 self.authority_usd_ata = Some(authority_usd_ata);
174 self
175 }
176 #[inline(always)]
177 pub fn automation_usd_ata(&mut self, automation_usd_ata: solana_address::Address) -> &mut Self {
178 self.automation_usd_ata = Some(automation_usd_ata);
179 self
180 }
181 #[inline(always)]
183 pub fn token_program(&mut self, token_program: solana_address::Address) -> &mut Self {
184 self.token_program = Some(token_program);
185 self
186 }
187 #[inline(always)]
188 pub fn amount(&mut self, amount: u64) -> &mut Self {
189 self.amount = Some(amount);
190 self
191 }
192 #[inline(always)]
194 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
195 self.__remaining_accounts.push(account);
196 self
197 }
198 #[inline(always)]
200 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
201 self.__remaining_accounts.extend_from_slice(accounts);
202 self
203 }
204 #[allow(clippy::clone_on_copy)]
205 pub fn instruction(&self) -> solana_instruction::Instruction {
206 let accounts = TopUpPublicAutomation {
207 authority: self.authority.expect("authority is not set"),
208 satrush_config: self.satrush_config.expect("satrush_config is not set"),
209 public_automation: self.public_automation.expect("public_automation is not set"),
210 usd_mint: self.usd_mint.expect("usd_mint is not set"),
211 authority_usd_ata: self.authority_usd_ata.expect("authority_usd_ata is not set"),
212 automation_usd_ata: self.automation_usd_ata.expect("automation_usd_ata is not set"),
213 token_program: self.token_program.unwrap_or(solana_address::address!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
214 };
215 let args = TopUpPublicAutomationInstructionArgs {
216 amount: self.amount.clone().expect("amount is not set"),
217 };
218
219 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
220 }
221}
222
223 pub struct TopUpPublicAutomationCpiAccounts<'a, 'b> {
225
226
227 pub authority: &'b solana_account_info::AccountInfo<'a>,
228
229
230 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
231
232
233 pub public_automation: &'b solana_account_info::AccountInfo<'a>,
234
235
236 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
237
238
239 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
240
241
242 pub automation_usd_ata: &'b solana_account_info::AccountInfo<'a>,
243
244
245 pub token_program: &'b solana_account_info::AccountInfo<'a>,
246 }
247
248pub struct TopUpPublicAutomationCpi<'a, 'b> {
250 pub __program: &'b solana_account_info::AccountInfo<'a>,
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
262
263 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
264
265
266 pub authority_usd_ata: &'b solana_account_info::AccountInfo<'a>,
267
268
269 pub automation_usd_ata: &'b solana_account_info::AccountInfo<'a>,
270
271
272 pub token_program: &'b solana_account_info::AccountInfo<'a>,
273 pub __args: TopUpPublicAutomationInstructionArgs,
275 }
276
277impl<'a, 'b> TopUpPublicAutomationCpi<'a, 'b> {
278 pub fn new(
279 program: &'b solana_account_info::AccountInfo<'a>,
280 accounts: TopUpPublicAutomationCpiAccounts<'a, 'b>,
281 args: TopUpPublicAutomationInstructionArgs,
282 ) -> Self {
283 Self {
284 __program: program,
285 authority: accounts.authority,
286 satrush_config: accounts.satrush_config,
287 public_automation: accounts.public_automation,
288 usd_mint: accounts.usd_mint,
289 authority_usd_ata: accounts.authority_usd_ata,
290 automation_usd_ata: accounts.automation_usd_ata,
291 token_program: accounts.token_program,
292 __args: args,
293 }
294 }
295 #[inline(always)]
296 pub fn invoke(&self) -> solana_program_error::ProgramResult {
297 self.invoke_signed_with_remaining_accounts(&[], &[])
298 }
299 #[inline(always)]
300 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
301 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
302 }
303 #[inline(always)]
304 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
305 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
306 }
307 #[allow(clippy::arithmetic_side_effects)]
308 #[allow(clippy::clone_on_copy)]
309 #[allow(clippy::vec_init_then_push)]
310 pub fn invoke_signed_with_remaining_accounts(
311 &self,
312 signers_seeds: &[&[&[u8]]],
313 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
314 ) -> solana_program_error::ProgramResult {
315 let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
316 accounts.push(solana_instruction::AccountMeta::new(
317 *self.authority.key,
318 true
319 ));
320 accounts.push(solana_instruction::AccountMeta::new_readonly(
321 *self.satrush_config.key,
322 false
323 ));
324 accounts.push(solana_instruction::AccountMeta::new(
325 *self.public_automation.key,
326 false
327 ));
328 accounts.push(solana_instruction::AccountMeta::new_readonly(
329 *self.usd_mint.key,
330 false
331 ));
332 accounts.push(solana_instruction::AccountMeta::new(
333 *self.authority_usd_ata.key,
334 false
335 ));
336 accounts.push(solana_instruction::AccountMeta::new(
337 *self.automation_usd_ata.key,
338 false
339 ));
340 accounts.push(solana_instruction::AccountMeta::new_readonly(
341 *self.token_program.key,
342 false
343 ));
344 remaining_accounts.iter().for_each(|remaining_account| {
345 accounts.push(solana_instruction::AccountMeta {
346 pubkey: *remaining_account.0.key,
347 is_signer: remaining_account.1,
348 is_writable: remaining_account.2,
349 })
350 });
351 let mut data = TopUpPublicAutomationInstructionData::new().try_to_vec().unwrap();
352 let mut args = self.__args.try_to_vec().unwrap();
353 data.append(&mut args);
354
355 let instruction = solana_instruction::Instruction {
356 program_id: crate::SATRUSH_ID,
357 accounts,
358 data,
359 };
360 let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
361 account_infos.push(self.__program.clone());
362 account_infos.push(self.authority.clone());
363 account_infos.push(self.satrush_config.clone());
364 account_infos.push(self.public_automation.clone());
365 account_infos.push(self.usd_mint.clone());
366 account_infos.push(self.authority_usd_ata.clone());
367 account_infos.push(self.automation_usd_ata.clone());
368 account_infos.push(self.token_program.clone());
369 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
370
371 if signers_seeds.is_empty() {
372 solana_cpi::invoke(&instruction, &account_infos)
373 } else {
374 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
375 }
376 }
377}
378
379#[derive(Clone, Debug)]
391pub struct TopUpPublicAutomationCpiBuilder<'a, 'b> {
392 instruction: Box<TopUpPublicAutomationCpiBuilderInstruction<'a, 'b>>,
393}
394
395impl<'a, 'b> TopUpPublicAutomationCpiBuilder<'a, 'b> {
396 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
397 let instruction = Box::new(TopUpPublicAutomationCpiBuilderInstruction {
398 __program: program,
399 authority: None,
400 satrush_config: None,
401 public_automation: None,
402 usd_mint: None,
403 authority_usd_ata: None,
404 automation_usd_ata: None,
405 token_program: None,
406 amount: None,
407 __remaining_accounts: Vec::new(),
408 });
409 Self { instruction }
410 }
411 #[inline(always)]
412 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
413 self.instruction.authority = Some(authority);
414 self
415 }
416 #[inline(always)]
417 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
418 self.instruction.satrush_config = Some(satrush_config);
419 self
420 }
421 #[inline(always)]
422 pub fn public_automation(&mut self, public_automation: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
423 self.instruction.public_automation = Some(public_automation);
424 self
425 }
426 #[inline(always)]
427 pub fn usd_mint(&mut self, usd_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
428 self.instruction.usd_mint = Some(usd_mint);
429 self
430 }
431 #[inline(always)]
432 pub fn authority_usd_ata(&mut self, authority_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
433 self.instruction.authority_usd_ata = Some(authority_usd_ata);
434 self
435 }
436 #[inline(always)]
437 pub fn automation_usd_ata(&mut self, automation_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
438 self.instruction.automation_usd_ata = Some(automation_usd_ata);
439 self
440 }
441 #[inline(always)]
442 pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
443 self.instruction.token_program = Some(token_program);
444 self
445 }
446 #[inline(always)]
447 pub fn amount(&mut self, amount: u64) -> &mut Self {
448 self.instruction.amount = Some(amount);
449 self
450 }
451 #[inline(always)]
453 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
454 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
455 self
456 }
457 #[inline(always)]
462 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
463 self.instruction.__remaining_accounts.extend_from_slice(accounts);
464 self
465 }
466 #[inline(always)]
467 pub fn invoke(&self) -> solana_program_error::ProgramResult {
468 self.invoke_signed(&[])
469 }
470 #[allow(clippy::clone_on_copy)]
471 #[allow(clippy::vec_init_then_push)]
472 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
473 let args = TopUpPublicAutomationInstructionArgs {
474 amount: self.instruction.amount.clone().expect("amount is not set"),
475 };
476 let instruction = TopUpPublicAutomationCpi {
477 __program: self.instruction.__program,
478
479 authority: self.instruction.authority.expect("authority is not set"),
480
481 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
482
483 public_automation: self.instruction.public_automation.expect("public_automation is not set"),
484
485 usd_mint: self.instruction.usd_mint.expect("usd_mint is not set"),
486
487 authority_usd_ata: self.instruction.authority_usd_ata.expect("authority_usd_ata is not set"),
488
489 automation_usd_ata: self.instruction.automation_usd_ata.expect("automation_usd_ata is not set"),
490
491 token_program: self.instruction.token_program.expect("token_program is not set"),
492 __args: args,
493 };
494 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
495 }
496}
497
498#[derive(Clone, Debug)]
499struct TopUpPublicAutomationCpiBuilderInstruction<'a, 'b> {
500 __program: &'b solana_account_info::AccountInfo<'a>,
501 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
502 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
503 public_automation: Option<&'b solana_account_info::AccountInfo<'a>>,
504 usd_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
505 authority_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
506 automation_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
507 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
508 amount: Option<u64>,
509 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
511}
512