Skip to main content

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