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