Skip to main content

satrush_client/generated/instructions/
create_satrush_config.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use solana_address::Address;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const CREATE_SATRUSH_CONFIG_DISCRIMINATOR: [u8; 8] = [96, 175, 39, 171, 158, 44, 117, 18];
13
14/// Accounts.
15#[derive(Debug)]
16pub struct CreateSatrushConfig {
17      
18              
19          pub authority: solana_address::Address,
20          
21              
22          pub satrush_config: solana_address::Address,
23          
24              
25          pub system_program: solana_address::Address,
26      }
27
28impl CreateSatrushConfig {
29  pub fn instruction(&self, args: CreateSatrushConfigInstructionArgs) -> solana_instruction::Instruction {
30    self.instruction_with_remaining_accounts(args, &[])
31  }
32  #[allow(clippy::arithmetic_side_effects)]
33  #[allow(clippy::vec_init_then_push)]
34  pub fn instruction_with_remaining_accounts(&self, args: CreateSatrushConfigInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
35    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
36                            accounts.push(solana_instruction::AccountMeta::new(
37            self.authority,
38            true
39          ));
40                                          accounts.push(solana_instruction::AccountMeta::new(
41            self.satrush_config,
42            false
43          ));
44                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
45            self.system_program,
46            false
47          ));
48                      accounts.extend_from_slice(remaining_accounts);
49    let mut data = CreateSatrushConfigInstructionData::new().try_to_vec().unwrap();
50          let mut args = args.try_to_vec().unwrap();
51      data.append(&mut args);
52    
53    solana_instruction::Instruction {
54      program_id: crate::SATRUSH_ID,
55      accounts,
56      data,
57    }
58  }
59}
60
61#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
62 pub struct CreateSatrushConfigInstructionData {
63            discriminator: [u8; 8],
64                                          }
65
66impl CreateSatrushConfigInstructionData {
67  pub fn new() -> Self {
68    Self {
69                        discriminator: [96, 175, 39, 171, 158, 44, 117, 18],
70                                                                                                      }
71  }
72
73    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
74    borsh::to_vec(self)
75  }
76  }
77
78impl Default for CreateSatrushConfigInstructionData {
79  fn default() -> Self {
80    Self::new()
81  }
82}
83
84#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
85 pub struct CreateSatrushConfigInstructionArgs {
86                  pub owner_authority: Address,
87                pub admin_authority: Address,
88                pub round_authority: Address,
89                pub fee_recipient: Address,
90                pub usd_mint: Address,
91                pub btc_mint: Address,
92      }
93
94impl CreateSatrushConfigInstructionArgs {
95  pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
96    borsh::to_vec(self)
97  }
98}
99
100
101/// Instruction builder for `CreateSatrushConfig`.
102///
103/// ### Accounts:
104///
105                      ///   0. `[writable, signer]` authority
106                ///   1. `[writable]` satrush_config
107                ///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
108#[derive(Clone, Debug, Default)]
109pub struct CreateSatrushConfigBuilder {
110            authority: Option<solana_address::Address>,
111                satrush_config: Option<solana_address::Address>,
112                system_program: Option<solana_address::Address>,
113                        owner_authority: Option<Address>,
114                admin_authority: Option<Address>,
115                round_authority: Option<Address>,
116                fee_recipient: Option<Address>,
117                usd_mint: Option<Address>,
118                btc_mint: Option<Address>,
119        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
120}
121
122impl CreateSatrushConfigBuilder {
123  pub fn new() -> Self {
124    Self::default()
125  }
126            #[inline(always)]
127    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
128                        self.authority = Some(authority);
129                    self
130    }
131            #[inline(always)]
132    pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
133                        self.satrush_config = Some(satrush_config);
134                    self
135    }
136            /// `[optional account, default to '11111111111111111111111111111111']`
137#[inline(always)]
138    pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
139                        self.system_program = Some(system_program);
140                    self
141    }
142                    #[inline(always)]
143      pub fn owner_authority(&mut self, owner_authority: Address) -> &mut Self {
144        self.owner_authority = Some(owner_authority);
145        self
146      }
147                #[inline(always)]
148      pub fn admin_authority(&mut self, admin_authority: Address) -> &mut Self {
149        self.admin_authority = Some(admin_authority);
150        self
151      }
152                #[inline(always)]
153      pub fn round_authority(&mut self, round_authority: Address) -> &mut Self {
154        self.round_authority = Some(round_authority);
155        self
156      }
157                #[inline(always)]
158      pub fn fee_recipient(&mut self, fee_recipient: Address) -> &mut Self {
159        self.fee_recipient = Some(fee_recipient);
160        self
161      }
162                #[inline(always)]
163      pub fn usd_mint(&mut self, usd_mint: Address) -> &mut Self {
164        self.usd_mint = Some(usd_mint);
165        self
166      }
167                #[inline(always)]
168      pub fn btc_mint(&mut self, btc_mint: Address) -> &mut Self {
169        self.btc_mint = Some(btc_mint);
170        self
171      }
172        /// Add an additional account to the instruction.
173  #[inline(always)]
174  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
175    self.__remaining_accounts.push(account);
176    self
177  }
178  /// Add additional accounts to the instruction.
179  #[inline(always)]
180  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
181    self.__remaining_accounts.extend_from_slice(accounts);
182    self
183  }
184  #[allow(clippy::clone_on_copy)]
185  pub fn instruction(&self) -> solana_instruction::Instruction {
186    let accounts = CreateSatrushConfig {
187                              authority: self.authority.expect("authority is not set"),
188                                        satrush_config: self.satrush_config.expect("satrush_config is not set"),
189                                        system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
190                      };
191          let args = CreateSatrushConfigInstructionArgs {
192                                                              owner_authority: self.owner_authority.clone().expect("owner_authority is not set"),
193                                                                  admin_authority: self.admin_authority.clone().expect("admin_authority is not set"),
194                                                                  round_authority: self.round_authority.clone().expect("round_authority is not set"),
195                                                                  fee_recipient: self.fee_recipient.clone().expect("fee_recipient is not set"),
196                                                                  usd_mint: self.usd_mint.clone().expect("usd_mint is not set"),
197                                                                  btc_mint: self.btc_mint.clone().expect("btc_mint is not set"),
198                                    };
199    
200    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
201  }
202}
203
204  /// `create_satrush_config` CPI accounts.
205  pub struct CreateSatrushConfigCpiAccounts<'a, 'b> {
206          
207                    
208              pub authority: &'b solana_account_info::AccountInfo<'a>,
209                
210                    
211              pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
212                
213                    
214              pub system_program: &'b solana_account_info::AccountInfo<'a>,
215            }
216
217/// `create_satrush_config` CPI instruction.
218pub struct CreateSatrushConfigCpi<'a, 'b> {
219  /// The program to invoke.
220  pub __program: &'b solana_account_info::AccountInfo<'a>,
221      
222              
223          pub authority: &'b solana_account_info::AccountInfo<'a>,
224          
225              
226          pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
227          
228              
229          pub system_program: &'b solana_account_info::AccountInfo<'a>,
230            /// The arguments for the instruction.
231    pub __args: CreateSatrushConfigInstructionArgs,
232  }
233
234impl<'a, 'b> CreateSatrushConfigCpi<'a, 'b> {
235  pub fn new(
236    program: &'b solana_account_info::AccountInfo<'a>,
237          accounts: CreateSatrushConfigCpiAccounts<'a, 'b>,
238              args: CreateSatrushConfigInstructionArgs,
239      ) -> Self {
240    Self {
241      __program: program,
242              authority: accounts.authority,
243              satrush_config: accounts.satrush_config,
244              system_program: accounts.system_program,
245                    __args: args,
246          }
247  }
248  #[inline(always)]
249  pub fn invoke(&self) -> solana_program_error::ProgramResult {
250    self.invoke_signed_with_remaining_accounts(&[], &[])
251  }
252  #[inline(always)]
253  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
254    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
255  }
256  #[inline(always)]
257  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
258    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
259  }
260  #[allow(clippy::arithmetic_side_effects)]
261  #[allow(clippy::clone_on_copy)]
262  #[allow(clippy::vec_init_then_push)]
263  pub fn invoke_signed_with_remaining_accounts(
264    &self,
265    signers_seeds: &[&[&[u8]]],
266    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
267  ) -> solana_program_error::ProgramResult {
268    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
269                            accounts.push(solana_instruction::AccountMeta::new(
270            *self.authority.key,
271            true
272          ));
273                                          accounts.push(solana_instruction::AccountMeta::new(
274            *self.satrush_config.key,
275            false
276          ));
277                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
278            *self.system_program.key,
279            false
280          ));
281                      remaining_accounts.iter().for_each(|remaining_account| {
282      accounts.push(solana_instruction::AccountMeta {
283          pubkey: *remaining_account.0.key,
284          is_signer: remaining_account.1,
285          is_writable: remaining_account.2,
286      })
287    });
288    let mut data = CreateSatrushConfigInstructionData::new().try_to_vec().unwrap();
289          let mut args = self.__args.try_to_vec().unwrap();
290      data.append(&mut args);
291    
292    let instruction = solana_instruction::Instruction {
293      program_id: crate::SATRUSH_ID,
294      accounts,
295      data,
296    };
297    let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
298    account_infos.push(self.__program.clone());
299                  account_infos.push(self.authority.clone());
300                        account_infos.push(self.satrush_config.clone());
301                        account_infos.push(self.system_program.clone());
302              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
303
304    if signers_seeds.is_empty() {
305      solana_cpi::invoke(&instruction, &account_infos)
306    } else {
307      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
308    }
309  }
310}
311
312/// Instruction builder for `CreateSatrushConfig` via CPI.
313///
314/// ### Accounts:
315///
316                      ///   0. `[writable, signer]` authority
317                ///   1. `[writable]` satrush_config
318          ///   2. `[]` system_program
319#[derive(Clone, Debug)]
320pub struct CreateSatrushConfigCpiBuilder<'a, 'b> {
321  instruction: Box<CreateSatrushConfigCpiBuilderInstruction<'a, 'b>>,
322}
323
324impl<'a, 'b> CreateSatrushConfigCpiBuilder<'a, 'b> {
325  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
326    let instruction = Box::new(CreateSatrushConfigCpiBuilderInstruction {
327      __program: program,
328              authority: None,
329              satrush_config: None,
330              system_program: None,
331                                            owner_authority: None,
332                                admin_authority: None,
333                                round_authority: None,
334                                fee_recipient: None,
335                                usd_mint: None,
336                                btc_mint: None,
337                    __remaining_accounts: Vec::new(),
338    });
339    Self { instruction }
340  }
341      #[inline(always)]
342    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
343                        self.instruction.authority = Some(authority);
344                    self
345    }
346      #[inline(always)]
347    pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
348                        self.instruction.satrush_config = Some(satrush_config);
349                    self
350    }
351      #[inline(always)]
352    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
353                        self.instruction.system_program = Some(system_program);
354                    self
355    }
356                    #[inline(always)]
357      pub fn owner_authority(&mut self, owner_authority: Address) -> &mut Self {
358        self.instruction.owner_authority = Some(owner_authority);
359        self
360      }
361                #[inline(always)]
362      pub fn admin_authority(&mut self, admin_authority: Address) -> &mut Self {
363        self.instruction.admin_authority = Some(admin_authority);
364        self
365      }
366                #[inline(always)]
367      pub fn round_authority(&mut self, round_authority: Address) -> &mut Self {
368        self.instruction.round_authority = Some(round_authority);
369        self
370      }
371                #[inline(always)]
372      pub fn fee_recipient(&mut self, fee_recipient: Address) -> &mut Self {
373        self.instruction.fee_recipient = Some(fee_recipient);
374        self
375      }
376                #[inline(always)]
377      pub fn usd_mint(&mut self, usd_mint: Address) -> &mut Self {
378        self.instruction.usd_mint = Some(usd_mint);
379        self
380      }
381                #[inline(always)]
382      pub fn btc_mint(&mut self, btc_mint: Address) -> &mut Self {
383        self.instruction.btc_mint = Some(btc_mint);
384        self
385      }
386        /// Add an additional account to the instruction.
387  #[inline(always)]
388  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
389    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
390    self
391  }
392  /// Add additional accounts to the instruction.
393  ///
394  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
395  /// and a `bool` indicating whether the account is a signer or not.
396  #[inline(always)]
397  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
398    self.instruction.__remaining_accounts.extend_from_slice(accounts);
399    self
400  }
401  #[inline(always)]
402  pub fn invoke(&self) -> solana_program_error::ProgramResult {
403    self.invoke_signed(&[])
404  }
405  #[allow(clippy::clone_on_copy)]
406  #[allow(clippy::vec_init_then_push)]
407  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
408          let args = CreateSatrushConfigInstructionArgs {
409                                                              owner_authority: self.instruction.owner_authority.clone().expect("owner_authority is not set"),
410                                                                  admin_authority: self.instruction.admin_authority.clone().expect("admin_authority is not set"),
411                                                                  round_authority: self.instruction.round_authority.clone().expect("round_authority is not set"),
412                                                                  fee_recipient: self.instruction.fee_recipient.clone().expect("fee_recipient is not set"),
413                                                                  usd_mint: self.instruction.usd_mint.clone().expect("usd_mint is not set"),
414                                                                  btc_mint: self.instruction.btc_mint.clone().expect("btc_mint is not set"),
415                                    };
416        let instruction = CreateSatrushConfigCpi {
417        __program: self.instruction.__program,
418                  
419          authority: self.instruction.authority.expect("authority is not set"),
420                  
421          satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
422                  
423          system_program: self.instruction.system_program.expect("system_program is not set"),
424                          __args: args,
425            };
426    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
427  }
428}
429
430#[derive(Clone, Debug)]
431struct CreateSatrushConfigCpiBuilderInstruction<'a, 'b> {
432  __program: &'b solana_account_info::AccountInfo<'a>,
433            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
434                satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
435                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
436                        owner_authority: Option<Address>,
437                admin_authority: Option<Address>,
438                round_authority: Option<Address>,
439                fee_recipient: Option<Address>,
440                usd_mint: Option<Address>,
441                btc_mint: Option<Address>,
442        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
443  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
444}
445