Skip to main content

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