Skip to main content

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