1use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const INIT_DRIFT_CONTROLLER_S1_DISCRIMINATOR: [u8; 8] = [5, 94, 189, 154, 255, 92, 61, 193];
13
14#[derive(Debug)]
16pub struct InitDriftControllerS1 {
17
18
19 pub drift_usdc_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 InitDriftControllerS1 {
35 pub fn instruction(&self, args: InitDriftControllerS1InstructionArgs) -> 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: InitDriftControllerS1InstructionArgs, 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.drift_usdc_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 = InitDriftControllerS1InstructionData::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 InitDriftControllerS1InstructionData {
78 discriminator: [u8; 8],
79 }
80
81impl InitDriftControllerS1InstructionData {
82 pub fn new() -> Self {
83 Self {
84 discriminator: [5, 94, 189, 154, 255, 92, 61, 193],
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 InitDriftControllerS1InstructionData {
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 InitDriftControllerS1InstructionArgs {
102 pub mint: Pubkey,
103 pub recipient_addresses: Vec<Pubkey>,
104 pub recipient_cuts: Vec<u16>,
105 pub cap: u64,
106 }
107
108impl InitDriftControllerS1InstructionArgs {
109 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
110 borsh::to_vec(self)
111 }
112}
113
114
115#[derive(Clone, Debug, Default)]
125pub struct InitDriftControllerS1Builder {
126 drift_usdc_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 InitDriftControllerS1Builder {
139 pub fn new() -> Self {
140 Self::default()
141 }
142 #[inline(always)]
143 pub fn drift_usdc_controller(&mut self, drift_usdc_controller: solana_pubkey::Pubkey) -> &mut Self {
144 self.drift_usdc_controller = Some(drift_usdc_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 #[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 #[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 #[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 = InitDriftControllerS1 {
203 drift_usdc_controller: self.drift_usdc_controller.expect("drift_usdc_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 = InitDriftControllerS1InstructionArgs {
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 pub struct InitDriftControllerS1CpiAccounts<'a, 'b> {
222
223
224 pub drift_usdc_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
239pub struct InitDriftControllerS1Cpi<'a, 'b> {
241 pub __program: &'b solana_account_info::AccountInfo<'a>,
243
244
245 pub drift_usdc_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 pub __args: InitDriftControllerS1InstructionArgs,
260 }
261
262impl<'a, 'b> InitDriftControllerS1Cpi<'a, 'b> {
263 pub fn new(
264 program: &'b solana_account_info::AccountInfo<'a>,
265 accounts: InitDriftControllerS1CpiAccounts<'a, 'b>,
266 args: InitDriftControllerS1InstructionArgs,
267 ) -> Self {
268 Self {
269 __program: program,
270 drift_usdc_controller: accounts.drift_usdc_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.drift_usdc_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 = InitDriftControllerS1InstructionData::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.drift_usdc_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#[derive(Clone, Debug)]
362pub struct InitDriftControllerS1CpiBuilder<'a, 'b> {
363 instruction: Box<InitDriftControllerS1CpiBuilderInstruction<'a, 'b>>,
364}
365
366impl<'a, 'b> InitDriftControllerS1CpiBuilder<'a, 'b> {
367 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
368 let instruction = Box::new(InitDriftControllerS1CpiBuilderInstruction {
369 __program: program,
370 drift_usdc_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 drift_usdc_controller(&mut self, drift_usdc_controller: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
385 self.instruction.drift_usdc_controller = Some(drift_usdc_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 #[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 #[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 = InitDriftControllerS1InstructionArgs {
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 = InitDriftControllerS1Cpi {
457 __program: self.instruction.__program,
458
459 drift_usdc_controller: self.instruction.drift_usdc_controller.expect("drift_usdc_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 InitDriftControllerS1CpiBuilderInstruction<'a, 'b> {
476 __program: &'b solana_account_info::AccountInfo<'a>,
477 drift_usdc_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 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
488}
489