Skip to main content

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