Skip to main content

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