Skip to main content

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