Skip to main content

satrush_client/generated/instructions/
migrate_treasury.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 borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const MIGRATE_TREASURY_DISCRIMINATOR: [u8; 8] = [13, 5, 40, 102, 230, 124, 105, 118];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct MigrateTreasury {
16      
17              
18          pub authority: solana_address::Address,
19          
20              
21          pub satrush_config: solana_address::Address,
22                /// version are validated in the handler against the raw v1 bytes.
23
24    
25              
26          pub treasury: solana_address::Address,
27          
28              
29          pub system_program: solana_address::Address,
30      }
31
32impl MigrateTreasury {
33  pub fn instruction(&self) -> solana_instruction::Instruction {
34    self.instruction_with_remaining_accounts(&[])
35  }
36  #[allow(clippy::arithmetic_side_effects)]
37  #[allow(clippy::vec_init_then_push)]
38  pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
39    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
40                            accounts.push(solana_instruction::AccountMeta::new(
41            self.authority,
42            true
43          ));
44                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
45            self.satrush_config,
46            false
47          ));
48                                          accounts.push(solana_instruction::AccountMeta::new(
49            self.treasury,
50            false
51          ));
52                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
53            self.system_program,
54            false
55          ));
56                      accounts.extend_from_slice(remaining_accounts);
57    let data = MigrateTreasuryInstructionData::new().try_to_vec().unwrap();
58    
59    solana_instruction::Instruction {
60      program_id: crate::SATRUSH_ID,
61      accounts,
62      data,
63    }
64  }
65}
66
67#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
68 pub struct MigrateTreasuryInstructionData {
69            discriminator: [u8; 8],
70      }
71
72impl MigrateTreasuryInstructionData {
73  pub fn new() -> Self {
74    Self {
75                        discriminator: [13, 5, 40, 102, 230, 124, 105, 118],
76                  }
77  }
78
79    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
80    borsh::to_vec(self)
81  }
82  }
83
84impl Default for MigrateTreasuryInstructionData {
85  fn default() -> Self {
86    Self::new()
87  }
88}
89
90
91
92/// Instruction builder for `MigrateTreasury`.
93///
94/// ### Accounts:
95///
96                      ///   0. `[writable, signer]` authority
97          ///   1. `[]` satrush_config
98                ///   2. `[writable]` treasury
99                ///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
100#[derive(Clone, Debug, Default)]
101pub struct MigrateTreasuryBuilder {
102            authority: Option<solana_address::Address>,
103                satrush_config: Option<solana_address::Address>,
104                treasury: Option<solana_address::Address>,
105                system_program: Option<solana_address::Address>,
106                __remaining_accounts: Vec<solana_instruction::AccountMeta>,
107}
108
109impl MigrateTreasuryBuilder {
110  pub fn new() -> Self {
111    Self::default()
112  }
113            #[inline(always)]
114    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
115                        self.authority = Some(authority);
116                    self
117    }
118            #[inline(always)]
119    pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
120                        self.satrush_config = Some(satrush_config);
121                    self
122    }
123            /// version are validated in the handler against the raw v1 bytes.
124#[inline(always)]
125    pub fn treasury(&mut self, treasury: solana_address::Address) -> &mut Self {
126                        self.treasury = Some(treasury);
127                    self
128    }
129            /// `[optional account, default to '11111111111111111111111111111111']`
130#[inline(always)]
131    pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
132                        self.system_program = Some(system_program);
133                    self
134    }
135            /// Add an additional account to the instruction.
136  #[inline(always)]
137  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
138    self.__remaining_accounts.push(account);
139    self
140  }
141  /// Add additional accounts to the instruction.
142  #[inline(always)]
143  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
144    self.__remaining_accounts.extend_from_slice(accounts);
145    self
146  }
147  #[allow(clippy::clone_on_copy)]
148  pub fn instruction(&self) -> solana_instruction::Instruction {
149    let accounts = MigrateTreasury {
150                              authority: self.authority.expect("authority is not set"),
151                                        satrush_config: self.satrush_config.expect("satrush_config is not set"),
152                                        treasury: self.treasury.expect("treasury is not set"),
153                                        system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
154                      };
155    
156    accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
157  }
158}
159
160  /// `migrate_treasury` CPI accounts.
161  pub struct MigrateTreasuryCpiAccounts<'a, 'b> {
162          
163                    
164              pub authority: &'b solana_account_info::AccountInfo<'a>,
165                
166                    
167              pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
168                        /// version are validated in the handler against the raw v1 bytes.
169
170      
171                    
172              pub treasury: &'b solana_account_info::AccountInfo<'a>,
173                
174                    
175              pub system_program: &'b solana_account_info::AccountInfo<'a>,
176            }
177
178/// `migrate_treasury` CPI instruction.
179pub struct MigrateTreasuryCpi<'a, 'b> {
180  /// The program to invoke.
181  pub __program: &'b solana_account_info::AccountInfo<'a>,
182      
183              
184          pub authority: &'b solana_account_info::AccountInfo<'a>,
185          
186              
187          pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
188                /// version are validated in the handler against the raw v1 bytes.
189
190    
191              
192          pub treasury: &'b solana_account_info::AccountInfo<'a>,
193          
194              
195          pub system_program: &'b solana_account_info::AccountInfo<'a>,
196        }
197
198impl<'a, 'b> MigrateTreasuryCpi<'a, 'b> {
199  pub fn new(
200    program: &'b solana_account_info::AccountInfo<'a>,
201          accounts: MigrateTreasuryCpiAccounts<'a, 'b>,
202          ) -> Self {
203    Self {
204      __program: program,
205              authority: accounts.authority,
206              satrush_config: accounts.satrush_config,
207              treasury: accounts.treasury,
208              system_program: accounts.system_program,
209                }
210  }
211  #[inline(always)]
212  pub fn invoke(&self) -> solana_program_error::ProgramResult {
213    self.invoke_signed_with_remaining_accounts(&[], &[])
214  }
215  #[inline(always)]
216  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
217    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
218  }
219  #[inline(always)]
220  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
221    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
222  }
223  #[allow(clippy::arithmetic_side_effects)]
224  #[allow(clippy::clone_on_copy)]
225  #[allow(clippy::vec_init_then_push)]
226  pub fn invoke_signed_with_remaining_accounts(
227    &self,
228    signers_seeds: &[&[&[u8]]],
229    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
230  ) -> solana_program_error::ProgramResult {
231    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
232                            accounts.push(solana_instruction::AccountMeta::new(
233            *self.authority.key,
234            true
235          ));
236                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
237            *self.satrush_config.key,
238            false
239          ));
240                                          accounts.push(solana_instruction::AccountMeta::new(
241            *self.treasury.key,
242            false
243          ));
244                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
245            *self.system_program.key,
246            false
247          ));
248                      remaining_accounts.iter().for_each(|remaining_account| {
249      accounts.push(solana_instruction::AccountMeta {
250          pubkey: *remaining_account.0.key,
251          is_signer: remaining_account.1,
252          is_writable: remaining_account.2,
253      })
254    });
255    let data = MigrateTreasuryInstructionData::new().try_to_vec().unwrap();
256    
257    let instruction = solana_instruction::Instruction {
258      program_id: crate::SATRUSH_ID,
259      accounts,
260      data,
261    };
262    let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
263    account_infos.push(self.__program.clone());
264                  account_infos.push(self.authority.clone());
265                        account_infos.push(self.satrush_config.clone());
266                        account_infos.push(self.treasury.clone());
267                        account_infos.push(self.system_program.clone());
268              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
269
270    if signers_seeds.is_empty() {
271      solana_cpi::invoke(&instruction, &account_infos)
272    } else {
273      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
274    }
275  }
276}
277
278/// Instruction builder for `MigrateTreasury` via CPI.
279///
280/// ### Accounts:
281///
282                      ///   0. `[writable, signer]` authority
283          ///   1. `[]` satrush_config
284                ///   2. `[writable]` treasury
285          ///   3. `[]` system_program
286#[derive(Clone, Debug)]
287pub struct MigrateTreasuryCpiBuilder<'a, 'b> {
288  instruction: Box<MigrateTreasuryCpiBuilderInstruction<'a, 'b>>,
289}
290
291impl<'a, 'b> MigrateTreasuryCpiBuilder<'a, 'b> {
292  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
293    let instruction = Box::new(MigrateTreasuryCpiBuilderInstruction {
294      __program: program,
295              authority: None,
296              satrush_config: None,
297              treasury: None,
298              system_program: None,
299                                __remaining_accounts: Vec::new(),
300    });
301    Self { instruction }
302  }
303      #[inline(always)]
304    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
305                        self.instruction.authority = Some(authority);
306                    self
307    }
308      #[inline(always)]
309    pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
310                        self.instruction.satrush_config = Some(satrush_config);
311                    self
312    }
313      /// version are validated in the handler against the raw v1 bytes.
314#[inline(always)]
315    pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
316                        self.instruction.treasury = Some(treasury);
317                    self
318    }
319      #[inline(always)]
320    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
321                        self.instruction.system_program = Some(system_program);
322                    self
323    }
324            /// Add an additional account to the instruction.
325  #[inline(always)]
326  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
327    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
328    self
329  }
330  /// Add additional accounts to the instruction.
331  ///
332  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
333  /// and a `bool` indicating whether the account is a signer or not.
334  #[inline(always)]
335  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
336    self.instruction.__remaining_accounts.extend_from_slice(accounts);
337    self
338  }
339  #[inline(always)]
340  pub fn invoke(&self) -> solana_program_error::ProgramResult {
341    self.invoke_signed(&[])
342  }
343  #[allow(clippy::clone_on_copy)]
344  #[allow(clippy::vec_init_then_push)]
345  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
346        let instruction = MigrateTreasuryCpi {
347        __program: self.instruction.__program,
348                  
349          authority: self.instruction.authority.expect("authority is not set"),
350                  
351          satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
352                  
353          treasury: self.instruction.treasury.expect("treasury is not set"),
354                  
355          system_program: self.instruction.system_program.expect("system_program is not set"),
356                    };
357    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
358  }
359}
360
361#[derive(Clone, Debug)]
362struct MigrateTreasuryCpiBuilderInstruction<'a, 'b> {
363  __program: &'b solana_account_info::AccountInfo<'a>,
364            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
365                satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
366                treasury: Option<&'b solana_account_info::AccountInfo<'a>>,
367                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
368                /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
369  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
370}
371