1use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const INSTANT_DECREASE_POSITION_DISCRIMINATOR: [u8; 8] = [46, 23, 240, 44, 30, 138, 94, 140];
11
12#[derive(Debug)]
14pub struct InstantDecreasePosition {
15 pub keeper: solana_program::pubkey::Pubkey,
16
17 pub api_keeper: solana_program::pubkey::Pubkey,
18
19 pub owner: solana_program::pubkey::Pubkey,
20
21 pub receiving_account: solana_program::pubkey::Pubkey,
22
23 pub transfer_authority: solana_program::pubkey::Pubkey,
24
25 pub perpetuals: solana_program::pubkey::Pubkey,
26
27 pub pool: solana_program::pubkey::Pubkey,
28
29 pub position: solana_program::pubkey::Pubkey,
30
31 pub custody: solana_program::pubkey::Pubkey,
32
33 pub custody_doves_price_account: solana_program::pubkey::Pubkey,
34
35 pub custody_pythnet_price_account: solana_program::pubkey::Pubkey,
36
37 pub collateral_custody: solana_program::pubkey::Pubkey,
38
39 pub collateral_custody_doves_price_account: solana_program::pubkey::Pubkey,
40
41 pub collateral_custody_pythnet_price_account: solana_program::pubkey::Pubkey,
42
43 pub collateral_custody_token_account: solana_program::pubkey::Pubkey,
44
45 pub desired_mint: solana_program::pubkey::Pubkey,
46
47 pub referral: Option<solana_program::pubkey::Pubkey>,
48
49 pub token_program: solana_program::pubkey::Pubkey,
50
51 pub associated_token_program: solana_program::pubkey::Pubkey,
52
53 pub system_program: solana_program::pubkey::Pubkey,
54
55 pub event_authority: solana_program::pubkey::Pubkey,
56
57 pub program: solana_program::pubkey::Pubkey,
58}
59
60impl InstantDecreasePosition {
61 pub fn instruction(
62 &self,
63 args: InstantDecreasePositionInstructionArgs,
64 ) -> solana_program::instruction::Instruction {
65 self.instruction_with_remaining_accounts(args, &[])
66 }
67 #[allow(clippy::arithmetic_side_effects)]
68 #[allow(clippy::vec_init_then_push)]
69 pub fn instruction_with_remaining_accounts(
70 &self,
71 args: InstantDecreasePositionInstructionArgs,
72 remaining_accounts: &[solana_program::instruction::AccountMeta],
73 ) -> solana_program::instruction::Instruction {
74 let mut accounts = Vec::with_capacity(22 + remaining_accounts.len());
75 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
76 self.keeper,
77 true,
78 ));
79 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
80 self.api_keeper,
81 true,
82 ));
83 accounts.push(solana_program::instruction::AccountMeta::new(
84 self.owner, true,
85 ));
86 accounts.push(solana_program::instruction::AccountMeta::new(
87 self.receiving_account,
88 false,
89 ));
90 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
91 self.transfer_authority,
92 false,
93 ));
94 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
95 self.perpetuals,
96 false,
97 ));
98 accounts.push(solana_program::instruction::AccountMeta::new(
99 self.pool, false,
100 ));
101 accounts.push(solana_program::instruction::AccountMeta::new(
102 self.position,
103 false,
104 ));
105 accounts.push(solana_program::instruction::AccountMeta::new(
106 self.custody,
107 false,
108 ));
109 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
110 self.custody_doves_price_account,
111 false,
112 ));
113 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
114 self.custody_pythnet_price_account,
115 false,
116 ));
117 accounts.push(solana_program::instruction::AccountMeta::new(
118 self.collateral_custody,
119 false,
120 ));
121 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
122 self.collateral_custody_doves_price_account,
123 false,
124 ));
125 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
126 self.collateral_custody_pythnet_price_account,
127 false,
128 ));
129 accounts.push(solana_program::instruction::AccountMeta::new(
130 self.collateral_custody_token_account,
131 false,
132 ));
133 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
134 self.desired_mint,
135 false,
136 ));
137 if let Some(referral) = self.referral {
138 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
139 referral, false,
140 ));
141 } else {
142 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
143 crate::PERPETUALS_ID,
144 false,
145 ));
146 }
147 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
148 self.token_program,
149 false,
150 ));
151 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
152 self.associated_token_program,
153 false,
154 ));
155 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
156 self.system_program,
157 false,
158 ));
159 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
160 self.event_authority,
161 false,
162 ));
163 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
164 self.program,
165 false,
166 ));
167 accounts.extend_from_slice(remaining_accounts);
168 let mut data = borsh::to_vec(&InstantDecreasePositionInstructionData::new()).unwrap();
169 let mut args = borsh::to_vec(&args).unwrap();
170 data.append(&mut args);
171
172 solana_program::instruction::Instruction {
173 program_id: crate::PERPETUALS_ID,
174 accounts,
175 data,
176 }
177 }
178}
179
180#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
181#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
182pub struct InstantDecreasePositionInstructionData {
183 discriminator: [u8; 8],
184}
185
186impl InstantDecreasePositionInstructionData {
187 pub fn new() -> Self {
188 Self {
189 discriminator: [46, 23, 240, 44, 30, 138, 94, 140],
190 }
191 }
192}
193
194impl Default for InstantDecreasePositionInstructionData {
195 fn default() -> Self {
196 Self::new()
197 }
198}
199
200#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
201#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
202pub struct InstantDecreasePositionInstructionArgs {
203 pub collateral_usd_delta: u64,
204 pub size_usd_delta: u64,
205 pub price_slippage: u64,
206 pub entire_position: Option<bool>,
207 pub request_time: i64,
208}
209
210#[derive(Clone, Debug, Default)]
237pub struct InstantDecreasePositionBuilder {
238 keeper: Option<solana_program::pubkey::Pubkey>,
239 api_keeper: Option<solana_program::pubkey::Pubkey>,
240 owner: Option<solana_program::pubkey::Pubkey>,
241 receiving_account: Option<solana_program::pubkey::Pubkey>,
242 transfer_authority: Option<solana_program::pubkey::Pubkey>,
243 perpetuals: Option<solana_program::pubkey::Pubkey>,
244 pool: Option<solana_program::pubkey::Pubkey>,
245 position: Option<solana_program::pubkey::Pubkey>,
246 custody: Option<solana_program::pubkey::Pubkey>,
247 custody_doves_price_account: Option<solana_program::pubkey::Pubkey>,
248 custody_pythnet_price_account: Option<solana_program::pubkey::Pubkey>,
249 collateral_custody: Option<solana_program::pubkey::Pubkey>,
250 collateral_custody_doves_price_account: Option<solana_program::pubkey::Pubkey>,
251 collateral_custody_pythnet_price_account: Option<solana_program::pubkey::Pubkey>,
252 collateral_custody_token_account: Option<solana_program::pubkey::Pubkey>,
253 desired_mint: Option<solana_program::pubkey::Pubkey>,
254 referral: Option<solana_program::pubkey::Pubkey>,
255 token_program: Option<solana_program::pubkey::Pubkey>,
256 associated_token_program: Option<solana_program::pubkey::Pubkey>,
257 system_program: Option<solana_program::pubkey::Pubkey>,
258 event_authority: Option<solana_program::pubkey::Pubkey>,
259 program: Option<solana_program::pubkey::Pubkey>,
260 collateral_usd_delta: Option<u64>,
261 size_usd_delta: Option<u64>,
262 price_slippage: Option<u64>,
263 entire_position: Option<bool>,
264 request_time: Option<i64>,
265 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
266}
267
268impl InstantDecreasePositionBuilder {
269 pub fn new() -> Self {
270 Self::default()
271 }
272 #[inline(always)]
273 pub fn keeper(&mut self, keeper: solana_program::pubkey::Pubkey) -> &mut Self {
274 self.keeper = Some(keeper);
275 self
276 }
277 #[inline(always)]
278 pub fn api_keeper(&mut self, api_keeper: solana_program::pubkey::Pubkey) -> &mut Self {
279 self.api_keeper = Some(api_keeper);
280 self
281 }
282 #[inline(always)]
283 pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
284 self.owner = Some(owner);
285 self
286 }
287 #[inline(always)]
288 pub fn receiving_account(
289 &mut self,
290 receiving_account: solana_program::pubkey::Pubkey,
291 ) -> &mut Self {
292 self.receiving_account = Some(receiving_account);
293 self
294 }
295 #[inline(always)]
296 pub fn transfer_authority(
297 &mut self,
298 transfer_authority: solana_program::pubkey::Pubkey,
299 ) -> &mut Self {
300 self.transfer_authority = Some(transfer_authority);
301 self
302 }
303 #[inline(always)]
304 pub fn perpetuals(&mut self, perpetuals: solana_program::pubkey::Pubkey) -> &mut Self {
305 self.perpetuals = Some(perpetuals);
306 self
307 }
308 #[inline(always)]
309 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
310 self.pool = Some(pool);
311 self
312 }
313 #[inline(always)]
314 pub fn position(&mut self, position: solana_program::pubkey::Pubkey) -> &mut Self {
315 self.position = Some(position);
316 self
317 }
318 #[inline(always)]
319 pub fn custody(&mut self, custody: solana_program::pubkey::Pubkey) -> &mut Self {
320 self.custody = Some(custody);
321 self
322 }
323 #[inline(always)]
324 pub fn custody_doves_price_account(
325 &mut self,
326 custody_doves_price_account: solana_program::pubkey::Pubkey,
327 ) -> &mut Self {
328 self.custody_doves_price_account = Some(custody_doves_price_account);
329 self
330 }
331 #[inline(always)]
332 pub fn custody_pythnet_price_account(
333 &mut self,
334 custody_pythnet_price_account: solana_program::pubkey::Pubkey,
335 ) -> &mut Self {
336 self.custody_pythnet_price_account = Some(custody_pythnet_price_account);
337 self
338 }
339 #[inline(always)]
340 pub fn collateral_custody(
341 &mut self,
342 collateral_custody: solana_program::pubkey::Pubkey,
343 ) -> &mut Self {
344 self.collateral_custody = Some(collateral_custody);
345 self
346 }
347 #[inline(always)]
348 pub fn collateral_custody_doves_price_account(
349 &mut self,
350 collateral_custody_doves_price_account: solana_program::pubkey::Pubkey,
351 ) -> &mut Self {
352 self.collateral_custody_doves_price_account = Some(collateral_custody_doves_price_account);
353 self
354 }
355 #[inline(always)]
356 pub fn collateral_custody_pythnet_price_account(
357 &mut self,
358 collateral_custody_pythnet_price_account: solana_program::pubkey::Pubkey,
359 ) -> &mut Self {
360 self.collateral_custody_pythnet_price_account =
361 Some(collateral_custody_pythnet_price_account);
362 self
363 }
364 #[inline(always)]
365 pub fn collateral_custody_token_account(
366 &mut self,
367 collateral_custody_token_account: solana_program::pubkey::Pubkey,
368 ) -> &mut Self {
369 self.collateral_custody_token_account = Some(collateral_custody_token_account);
370 self
371 }
372 #[inline(always)]
373 pub fn desired_mint(&mut self, desired_mint: solana_program::pubkey::Pubkey) -> &mut Self {
374 self.desired_mint = Some(desired_mint);
375 self
376 }
377 #[inline(always)]
379 pub fn referral(&mut self, referral: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
380 self.referral = referral;
381 self
382 }
383 #[inline(always)]
385 pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
386 self.token_program = Some(token_program);
387 self
388 }
389 #[inline(always)]
390 pub fn associated_token_program(
391 &mut self,
392 associated_token_program: solana_program::pubkey::Pubkey,
393 ) -> &mut Self {
394 self.associated_token_program = Some(associated_token_program);
395 self
396 }
397 #[inline(always)]
399 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
400 self.system_program = Some(system_program);
401 self
402 }
403 #[inline(always)]
404 pub fn event_authority(
405 &mut self,
406 event_authority: solana_program::pubkey::Pubkey,
407 ) -> &mut Self {
408 self.event_authority = Some(event_authority);
409 self
410 }
411 #[inline(always)]
412 pub fn program(&mut self, program: solana_program::pubkey::Pubkey) -> &mut Self {
413 self.program = Some(program);
414 self
415 }
416 #[inline(always)]
417 pub fn collateral_usd_delta(&mut self, collateral_usd_delta: u64) -> &mut Self {
418 self.collateral_usd_delta = Some(collateral_usd_delta);
419 self
420 }
421 #[inline(always)]
422 pub fn size_usd_delta(&mut self, size_usd_delta: u64) -> &mut Self {
423 self.size_usd_delta = Some(size_usd_delta);
424 self
425 }
426 #[inline(always)]
427 pub fn price_slippage(&mut self, price_slippage: u64) -> &mut Self {
428 self.price_slippage = Some(price_slippage);
429 self
430 }
431 #[inline(always)]
433 pub fn entire_position(&mut self, entire_position: bool) -> &mut Self {
434 self.entire_position = Some(entire_position);
435 self
436 }
437 #[inline(always)]
438 pub fn request_time(&mut self, request_time: i64) -> &mut Self {
439 self.request_time = Some(request_time);
440 self
441 }
442 #[inline(always)]
444 pub fn add_remaining_account(
445 &mut self,
446 account: solana_program::instruction::AccountMeta,
447 ) -> &mut Self {
448 self.__remaining_accounts.push(account);
449 self
450 }
451 #[inline(always)]
453 pub fn add_remaining_accounts(
454 &mut self,
455 accounts: &[solana_program::instruction::AccountMeta],
456 ) -> &mut Self {
457 self.__remaining_accounts.extend_from_slice(accounts);
458 self
459 }
460 #[allow(clippy::clone_on_copy)]
461 pub fn instruction(&self) -> solana_program::instruction::Instruction {
462 let accounts = InstantDecreasePosition {
463 keeper: self.keeper.expect("keeper is not set"),
464 api_keeper: self.api_keeper.expect("api_keeper is not set"),
465 owner: self.owner.expect("owner is not set"),
466 receiving_account: self
467 .receiving_account
468 .expect("receiving_account is not set"),
469 transfer_authority: self
470 .transfer_authority
471 .expect("transfer_authority is not set"),
472 perpetuals: self.perpetuals.expect("perpetuals is not set"),
473 pool: self.pool.expect("pool is not set"),
474 position: self.position.expect("position is not set"),
475 custody: self.custody.expect("custody is not set"),
476 custody_doves_price_account: self
477 .custody_doves_price_account
478 .expect("custody_doves_price_account is not set"),
479 custody_pythnet_price_account: self
480 .custody_pythnet_price_account
481 .expect("custody_pythnet_price_account is not set"),
482 collateral_custody: self
483 .collateral_custody
484 .expect("collateral_custody is not set"),
485 collateral_custody_doves_price_account: self
486 .collateral_custody_doves_price_account
487 .expect("collateral_custody_doves_price_account is not set"),
488 collateral_custody_pythnet_price_account: self
489 .collateral_custody_pythnet_price_account
490 .expect("collateral_custody_pythnet_price_account is not set"),
491 collateral_custody_token_account: self
492 .collateral_custody_token_account
493 .expect("collateral_custody_token_account is not set"),
494 desired_mint: self.desired_mint.expect("desired_mint is not set"),
495 referral: self.referral,
496 token_program: self.token_program.unwrap_or(solana_program::pubkey!(
497 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
498 )),
499 associated_token_program: self
500 .associated_token_program
501 .expect("associated_token_program is not set"),
502 system_program: self
503 .system_program
504 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
505 event_authority: self.event_authority.expect("event_authority is not set"),
506 program: self.program.expect("program is not set"),
507 };
508 let args = InstantDecreasePositionInstructionArgs {
509 collateral_usd_delta: self
510 .collateral_usd_delta
511 .clone()
512 .expect("collateral_usd_delta is not set"),
513 size_usd_delta: self
514 .size_usd_delta
515 .clone()
516 .expect("size_usd_delta is not set"),
517 price_slippage: self
518 .price_slippage
519 .clone()
520 .expect("price_slippage is not set"),
521 entire_position: self.entire_position.clone(),
522 request_time: self.request_time.clone().expect("request_time is not set"),
523 };
524
525 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
526 }
527}
528
529pub struct InstantDecreasePositionCpiAccounts<'a, 'b> {
531 pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
532
533 pub api_keeper: &'b solana_program::account_info::AccountInfo<'a>,
534
535 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
536
537 pub receiving_account: &'b solana_program::account_info::AccountInfo<'a>,
538
539 pub transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
540
541 pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
542
543 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
544
545 pub position: &'b solana_program::account_info::AccountInfo<'a>,
546
547 pub custody: &'b solana_program::account_info::AccountInfo<'a>,
548
549 pub custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
550
551 pub custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
552
553 pub collateral_custody: &'b solana_program::account_info::AccountInfo<'a>,
554
555 pub collateral_custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
556
557 pub collateral_custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
558
559 pub collateral_custody_token_account: &'b solana_program::account_info::AccountInfo<'a>,
560
561 pub desired_mint: &'b solana_program::account_info::AccountInfo<'a>,
562
563 pub referral: Option<&'b solana_program::account_info::AccountInfo<'a>>,
564
565 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
566
567 pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
568
569 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
570
571 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
572
573 pub program: &'b solana_program::account_info::AccountInfo<'a>,
574}
575
576pub struct InstantDecreasePositionCpi<'a, 'b> {
578 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
580
581 pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
582
583 pub api_keeper: &'b solana_program::account_info::AccountInfo<'a>,
584
585 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
586
587 pub receiving_account: &'b solana_program::account_info::AccountInfo<'a>,
588
589 pub transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
590
591 pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
592
593 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
594
595 pub position: &'b solana_program::account_info::AccountInfo<'a>,
596
597 pub custody: &'b solana_program::account_info::AccountInfo<'a>,
598
599 pub custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
600
601 pub custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
602
603 pub collateral_custody: &'b solana_program::account_info::AccountInfo<'a>,
604
605 pub collateral_custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
606
607 pub collateral_custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
608
609 pub collateral_custody_token_account: &'b solana_program::account_info::AccountInfo<'a>,
610
611 pub desired_mint: &'b solana_program::account_info::AccountInfo<'a>,
612
613 pub referral: Option<&'b solana_program::account_info::AccountInfo<'a>>,
614
615 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
616
617 pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
618
619 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
620
621 pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
622
623 pub program: &'b solana_program::account_info::AccountInfo<'a>,
624 pub __args: InstantDecreasePositionInstructionArgs,
626}
627
628impl<'a, 'b> InstantDecreasePositionCpi<'a, 'b> {
629 pub fn new(
630 program: &'b solana_program::account_info::AccountInfo<'a>,
631 accounts: InstantDecreasePositionCpiAccounts<'a, 'b>,
632 args: InstantDecreasePositionInstructionArgs,
633 ) -> Self {
634 Self {
635 __program: program,
636 keeper: accounts.keeper,
637 api_keeper: accounts.api_keeper,
638 owner: accounts.owner,
639 receiving_account: accounts.receiving_account,
640 transfer_authority: accounts.transfer_authority,
641 perpetuals: accounts.perpetuals,
642 pool: accounts.pool,
643 position: accounts.position,
644 custody: accounts.custody,
645 custody_doves_price_account: accounts.custody_doves_price_account,
646 custody_pythnet_price_account: accounts.custody_pythnet_price_account,
647 collateral_custody: accounts.collateral_custody,
648 collateral_custody_doves_price_account: accounts.collateral_custody_doves_price_account,
649 collateral_custody_pythnet_price_account: accounts
650 .collateral_custody_pythnet_price_account,
651 collateral_custody_token_account: accounts.collateral_custody_token_account,
652 desired_mint: accounts.desired_mint,
653 referral: accounts.referral,
654 token_program: accounts.token_program,
655 associated_token_program: accounts.associated_token_program,
656 system_program: accounts.system_program,
657 event_authority: accounts.event_authority,
658 program: accounts.program,
659 __args: args,
660 }
661 }
662 #[inline(always)]
663 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
664 self.invoke_signed_with_remaining_accounts(&[], &[])
665 }
666 #[inline(always)]
667 pub fn invoke_with_remaining_accounts(
668 &self,
669 remaining_accounts: &[(
670 &'b solana_program::account_info::AccountInfo<'a>,
671 bool,
672 bool,
673 )],
674 ) -> solana_program::entrypoint::ProgramResult {
675 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
676 }
677 #[inline(always)]
678 pub fn invoke_signed(
679 &self,
680 signers_seeds: &[&[&[u8]]],
681 ) -> solana_program::entrypoint::ProgramResult {
682 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
683 }
684 #[allow(clippy::arithmetic_side_effects)]
685 #[allow(clippy::clone_on_copy)]
686 #[allow(clippy::vec_init_then_push)]
687 pub fn invoke_signed_with_remaining_accounts(
688 &self,
689 signers_seeds: &[&[&[u8]]],
690 remaining_accounts: &[(
691 &'b solana_program::account_info::AccountInfo<'a>,
692 bool,
693 bool,
694 )],
695 ) -> solana_program::entrypoint::ProgramResult {
696 let mut accounts = Vec::with_capacity(22 + remaining_accounts.len());
697 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
698 *self.keeper.key,
699 true,
700 ));
701 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
702 *self.api_keeper.key,
703 true,
704 ));
705 accounts.push(solana_program::instruction::AccountMeta::new(
706 *self.owner.key,
707 true,
708 ));
709 accounts.push(solana_program::instruction::AccountMeta::new(
710 *self.receiving_account.key,
711 false,
712 ));
713 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
714 *self.transfer_authority.key,
715 false,
716 ));
717 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
718 *self.perpetuals.key,
719 false,
720 ));
721 accounts.push(solana_program::instruction::AccountMeta::new(
722 *self.pool.key,
723 false,
724 ));
725 accounts.push(solana_program::instruction::AccountMeta::new(
726 *self.position.key,
727 false,
728 ));
729 accounts.push(solana_program::instruction::AccountMeta::new(
730 *self.custody.key,
731 false,
732 ));
733 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
734 *self.custody_doves_price_account.key,
735 false,
736 ));
737 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
738 *self.custody_pythnet_price_account.key,
739 false,
740 ));
741 accounts.push(solana_program::instruction::AccountMeta::new(
742 *self.collateral_custody.key,
743 false,
744 ));
745 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
746 *self.collateral_custody_doves_price_account.key,
747 false,
748 ));
749 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
750 *self.collateral_custody_pythnet_price_account.key,
751 false,
752 ));
753 accounts.push(solana_program::instruction::AccountMeta::new(
754 *self.collateral_custody_token_account.key,
755 false,
756 ));
757 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
758 *self.desired_mint.key,
759 false,
760 ));
761 if let Some(referral) = self.referral {
762 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
763 *referral.key,
764 false,
765 ));
766 } else {
767 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
768 crate::PERPETUALS_ID,
769 false,
770 ));
771 }
772 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
773 *self.token_program.key,
774 false,
775 ));
776 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
777 *self.associated_token_program.key,
778 false,
779 ));
780 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
781 *self.system_program.key,
782 false,
783 ));
784 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
785 *self.event_authority.key,
786 false,
787 ));
788 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
789 *self.program.key,
790 false,
791 ));
792 remaining_accounts.iter().for_each(|remaining_account| {
793 accounts.push(solana_program::instruction::AccountMeta {
794 pubkey: *remaining_account.0.key,
795 is_signer: remaining_account.1,
796 is_writable: remaining_account.2,
797 })
798 });
799 let mut data = borsh::to_vec(&InstantDecreasePositionInstructionData::new()).unwrap();
800 let mut args = borsh::to_vec(&self.__args).unwrap();
801 data.append(&mut args);
802
803 let instruction = solana_program::instruction::Instruction {
804 program_id: crate::PERPETUALS_ID,
805 accounts,
806 data,
807 };
808 let mut account_infos = Vec::with_capacity(23 + remaining_accounts.len());
809 account_infos.push(self.__program.clone());
810 account_infos.push(self.keeper.clone());
811 account_infos.push(self.api_keeper.clone());
812 account_infos.push(self.owner.clone());
813 account_infos.push(self.receiving_account.clone());
814 account_infos.push(self.transfer_authority.clone());
815 account_infos.push(self.perpetuals.clone());
816 account_infos.push(self.pool.clone());
817 account_infos.push(self.position.clone());
818 account_infos.push(self.custody.clone());
819 account_infos.push(self.custody_doves_price_account.clone());
820 account_infos.push(self.custody_pythnet_price_account.clone());
821 account_infos.push(self.collateral_custody.clone());
822 account_infos.push(self.collateral_custody_doves_price_account.clone());
823 account_infos.push(self.collateral_custody_pythnet_price_account.clone());
824 account_infos.push(self.collateral_custody_token_account.clone());
825 account_infos.push(self.desired_mint.clone());
826 if let Some(referral) = self.referral {
827 account_infos.push(referral.clone());
828 }
829 account_infos.push(self.token_program.clone());
830 account_infos.push(self.associated_token_program.clone());
831 account_infos.push(self.system_program.clone());
832 account_infos.push(self.event_authority.clone());
833 account_infos.push(self.program.clone());
834 remaining_accounts
835 .iter()
836 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
837
838 if signers_seeds.is_empty() {
839 solana_program::program::invoke(&instruction, &account_infos)
840 } else {
841 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
842 }
843 }
844}
845
846#[derive(Clone, Debug)]
873pub struct InstantDecreasePositionCpiBuilder<'a, 'b> {
874 instruction: Box<InstantDecreasePositionCpiBuilderInstruction<'a, 'b>>,
875}
876
877impl<'a, 'b> InstantDecreasePositionCpiBuilder<'a, 'b> {
878 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
879 let instruction = Box::new(InstantDecreasePositionCpiBuilderInstruction {
880 __program: program,
881 keeper: None,
882 api_keeper: None,
883 owner: None,
884 receiving_account: None,
885 transfer_authority: None,
886 perpetuals: None,
887 pool: None,
888 position: None,
889 custody: None,
890 custody_doves_price_account: None,
891 custody_pythnet_price_account: None,
892 collateral_custody: None,
893 collateral_custody_doves_price_account: None,
894 collateral_custody_pythnet_price_account: None,
895 collateral_custody_token_account: None,
896 desired_mint: None,
897 referral: None,
898 token_program: None,
899 associated_token_program: None,
900 system_program: None,
901 event_authority: None,
902 program: None,
903 collateral_usd_delta: None,
904 size_usd_delta: None,
905 price_slippage: None,
906 entire_position: None,
907 request_time: None,
908 __remaining_accounts: Vec::new(),
909 });
910 Self { instruction }
911 }
912 #[inline(always)]
913 pub fn keeper(
914 &mut self,
915 keeper: &'b solana_program::account_info::AccountInfo<'a>,
916 ) -> &mut Self {
917 self.instruction.keeper = Some(keeper);
918 self
919 }
920 #[inline(always)]
921 pub fn api_keeper(
922 &mut self,
923 api_keeper: &'b solana_program::account_info::AccountInfo<'a>,
924 ) -> &mut Self {
925 self.instruction.api_keeper = Some(api_keeper);
926 self
927 }
928 #[inline(always)]
929 pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
930 self.instruction.owner = Some(owner);
931 self
932 }
933 #[inline(always)]
934 pub fn receiving_account(
935 &mut self,
936 receiving_account: &'b solana_program::account_info::AccountInfo<'a>,
937 ) -> &mut Self {
938 self.instruction.receiving_account = Some(receiving_account);
939 self
940 }
941 #[inline(always)]
942 pub fn transfer_authority(
943 &mut self,
944 transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
945 ) -> &mut Self {
946 self.instruction.transfer_authority = Some(transfer_authority);
947 self
948 }
949 #[inline(always)]
950 pub fn perpetuals(
951 &mut self,
952 perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
953 ) -> &mut Self {
954 self.instruction.perpetuals = Some(perpetuals);
955 self
956 }
957 #[inline(always)]
958 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
959 self.instruction.pool = Some(pool);
960 self
961 }
962 #[inline(always)]
963 pub fn position(
964 &mut self,
965 position: &'b solana_program::account_info::AccountInfo<'a>,
966 ) -> &mut Self {
967 self.instruction.position = Some(position);
968 self
969 }
970 #[inline(always)]
971 pub fn custody(
972 &mut self,
973 custody: &'b solana_program::account_info::AccountInfo<'a>,
974 ) -> &mut Self {
975 self.instruction.custody = Some(custody);
976 self
977 }
978 #[inline(always)]
979 pub fn custody_doves_price_account(
980 &mut self,
981 custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
982 ) -> &mut Self {
983 self.instruction.custody_doves_price_account = Some(custody_doves_price_account);
984 self
985 }
986 #[inline(always)]
987 pub fn custody_pythnet_price_account(
988 &mut self,
989 custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
990 ) -> &mut Self {
991 self.instruction.custody_pythnet_price_account = Some(custody_pythnet_price_account);
992 self
993 }
994 #[inline(always)]
995 pub fn collateral_custody(
996 &mut self,
997 collateral_custody: &'b solana_program::account_info::AccountInfo<'a>,
998 ) -> &mut Self {
999 self.instruction.collateral_custody = Some(collateral_custody);
1000 self
1001 }
1002 #[inline(always)]
1003 pub fn collateral_custody_doves_price_account(
1004 &mut self,
1005 collateral_custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
1006 ) -> &mut Self {
1007 self.instruction.collateral_custody_doves_price_account =
1008 Some(collateral_custody_doves_price_account);
1009 self
1010 }
1011 #[inline(always)]
1012 pub fn collateral_custody_pythnet_price_account(
1013 &mut self,
1014 collateral_custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
1015 ) -> &mut Self {
1016 self.instruction.collateral_custody_pythnet_price_account =
1017 Some(collateral_custody_pythnet_price_account);
1018 self
1019 }
1020 #[inline(always)]
1021 pub fn collateral_custody_token_account(
1022 &mut self,
1023 collateral_custody_token_account: &'b solana_program::account_info::AccountInfo<'a>,
1024 ) -> &mut Self {
1025 self.instruction.collateral_custody_token_account = Some(collateral_custody_token_account);
1026 self
1027 }
1028 #[inline(always)]
1029 pub fn desired_mint(
1030 &mut self,
1031 desired_mint: &'b solana_program::account_info::AccountInfo<'a>,
1032 ) -> &mut Self {
1033 self.instruction.desired_mint = Some(desired_mint);
1034 self
1035 }
1036 #[inline(always)]
1038 pub fn referral(
1039 &mut self,
1040 referral: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1041 ) -> &mut Self {
1042 self.instruction.referral = referral;
1043 self
1044 }
1045 #[inline(always)]
1046 pub fn token_program(
1047 &mut self,
1048 token_program: &'b solana_program::account_info::AccountInfo<'a>,
1049 ) -> &mut Self {
1050 self.instruction.token_program = Some(token_program);
1051 self
1052 }
1053 #[inline(always)]
1054 pub fn associated_token_program(
1055 &mut self,
1056 associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
1057 ) -> &mut Self {
1058 self.instruction.associated_token_program = Some(associated_token_program);
1059 self
1060 }
1061 #[inline(always)]
1062 pub fn system_program(
1063 &mut self,
1064 system_program: &'b solana_program::account_info::AccountInfo<'a>,
1065 ) -> &mut Self {
1066 self.instruction.system_program = Some(system_program);
1067 self
1068 }
1069 #[inline(always)]
1070 pub fn event_authority(
1071 &mut self,
1072 event_authority: &'b solana_program::account_info::AccountInfo<'a>,
1073 ) -> &mut Self {
1074 self.instruction.event_authority = Some(event_authority);
1075 self
1076 }
1077 #[inline(always)]
1078 pub fn program(
1079 &mut self,
1080 program: &'b solana_program::account_info::AccountInfo<'a>,
1081 ) -> &mut Self {
1082 self.instruction.program = Some(program);
1083 self
1084 }
1085 #[inline(always)]
1086 pub fn collateral_usd_delta(&mut self, collateral_usd_delta: u64) -> &mut Self {
1087 self.instruction.collateral_usd_delta = Some(collateral_usd_delta);
1088 self
1089 }
1090 #[inline(always)]
1091 pub fn size_usd_delta(&mut self, size_usd_delta: u64) -> &mut Self {
1092 self.instruction.size_usd_delta = Some(size_usd_delta);
1093 self
1094 }
1095 #[inline(always)]
1096 pub fn price_slippage(&mut self, price_slippage: u64) -> &mut Self {
1097 self.instruction.price_slippage = Some(price_slippage);
1098 self
1099 }
1100 #[inline(always)]
1102 pub fn entire_position(&mut self, entire_position: bool) -> &mut Self {
1103 self.instruction.entire_position = Some(entire_position);
1104 self
1105 }
1106 #[inline(always)]
1107 pub fn request_time(&mut self, request_time: i64) -> &mut Self {
1108 self.instruction.request_time = Some(request_time);
1109 self
1110 }
1111 #[inline(always)]
1113 pub fn add_remaining_account(
1114 &mut self,
1115 account: &'b solana_program::account_info::AccountInfo<'a>,
1116 is_writable: bool,
1117 is_signer: bool,
1118 ) -> &mut Self {
1119 self.instruction
1120 .__remaining_accounts
1121 .push((account, is_writable, is_signer));
1122 self
1123 }
1124 #[inline(always)]
1129 pub fn add_remaining_accounts(
1130 &mut self,
1131 accounts: &[(
1132 &'b solana_program::account_info::AccountInfo<'a>,
1133 bool,
1134 bool,
1135 )],
1136 ) -> &mut Self {
1137 self.instruction
1138 .__remaining_accounts
1139 .extend_from_slice(accounts);
1140 self
1141 }
1142 #[inline(always)]
1143 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
1144 self.invoke_signed(&[])
1145 }
1146 #[allow(clippy::clone_on_copy)]
1147 #[allow(clippy::vec_init_then_push)]
1148 pub fn invoke_signed(
1149 &self,
1150 signers_seeds: &[&[&[u8]]],
1151 ) -> solana_program::entrypoint::ProgramResult {
1152 let args = InstantDecreasePositionInstructionArgs {
1153 collateral_usd_delta: self
1154 .instruction
1155 .collateral_usd_delta
1156 .clone()
1157 .expect("collateral_usd_delta is not set"),
1158 size_usd_delta: self
1159 .instruction
1160 .size_usd_delta
1161 .clone()
1162 .expect("size_usd_delta is not set"),
1163 price_slippage: self
1164 .instruction
1165 .price_slippage
1166 .clone()
1167 .expect("price_slippage is not set"),
1168 entire_position: self.instruction.entire_position.clone(),
1169 request_time: self
1170 .instruction
1171 .request_time
1172 .clone()
1173 .expect("request_time is not set"),
1174 };
1175 let instruction = InstantDecreasePositionCpi {
1176 __program: self.instruction.__program,
1177
1178 keeper: self.instruction.keeper.expect("keeper is not set"),
1179
1180 api_keeper: self.instruction.api_keeper.expect("api_keeper is not set"),
1181
1182 owner: self.instruction.owner.expect("owner is not set"),
1183
1184 receiving_account: self
1185 .instruction
1186 .receiving_account
1187 .expect("receiving_account is not set"),
1188
1189 transfer_authority: self
1190 .instruction
1191 .transfer_authority
1192 .expect("transfer_authority is not set"),
1193
1194 perpetuals: self.instruction.perpetuals.expect("perpetuals is not set"),
1195
1196 pool: self.instruction.pool.expect("pool is not set"),
1197
1198 position: self.instruction.position.expect("position is not set"),
1199
1200 custody: self.instruction.custody.expect("custody is not set"),
1201
1202 custody_doves_price_account: self
1203 .instruction
1204 .custody_doves_price_account
1205 .expect("custody_doves_price_account is not set"),
1206
1207 custody_pythnet_price_account: self
1208 .instruction
1209 .custody_pythnet_price_account
1210 .expect("custody_pythnet_price_account is not set"),
1211
1212 collateral_custody: self
1213 .instruction
1214 .collateral_custody
1215 .expect("collateral_custody is not set"),
1216
1217 collateral_custody_doves_price_account: self
1218 .instruction
1219 .collateral_custody_doves_price_account
1220 .expect("collateral_custody_doves_price_account is not set"),
1221
1222 collateral_custody_pythnet_price_account: self
1223 .instruction
1224 .collateral_custody_pythnet_price_account
1225 .expect("collateral_custody_pythnet_price_account is not set"),
1226
1227 collateral_custody_token_account: self
1228 .instruction
1229 .collateral_custody_token_account
1230 .expect("collateral_custody_token_account is not set"),
1231
1232 desired_mint: self
1233 .instruction
1234 .desired_mint
1235 .expect("desired_mint is not set"),
1236
1237 referral: self.instruction.referral,
1238
1239 token_program: self
1240 .instruction
1241 .token_program
1242 .expect("token_program is not set"),
1243
1244 associated_token_program: self
1245 .instruction
1246 .associated_token_program
1247 .expect("associated_token_program is not set"),
1248
1249 system_program: self
1250 .instruction
1251 .system_program
1252 .expect("system_program is not set"),
1253
1254 event_authority: self
1255 .instruction
1256 .event_authority
1257 .expect("event_authority is not set"),
1258
1259 program: self.instruction.program.expect("program is not set"),
1260 __args: args,
1261 };
1262 instruction.invoke_signed_with_remaining_accounts(
1263 signers_seeds,
1264 &self.instruction.__remaining_accounts,
1265 )
1266 }
1267}
1268
1269#[derive(Clone, Debug)]
1270struct InstantDecreasePositionCpiBuilderInstruction<'a, 'b> {
1271 __program: &'b solana_program::account_info::AccountInfo<'a>,
1272 keeper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1273 api_keeper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1274 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1275 receiving_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1276 transfer_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1277 perpetuals: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1278 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1279 position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1280 custody: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1281 custody_doves_price_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1282 custody_pythnet_price_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1283 collateral_custody: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1284 collateral_custody_doves_price_account:
1285 Option<&'b solana_program::account_info::AccountInfo<'a>>,
1286 collateral_custody_pythnet_price_account:
1287 Option<&'b solana_program::account_info::AccountInfo<'a>>,
1288 collateral_custody_token_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1289 desired_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1290 referral: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1291 token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1292 associated_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1293 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1294 event_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1295 program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1296 collateral_usd_delta: Option<u64>,
1297 size_usd_delta: Option<u64>,
1298 price_slippage: Option<u64>,
1299 entire_position: Option<bool>,
1300 request_time: Option<i64>,
1301 __remaining_accounts: Vec<(
1303 &'b solana_program::account_info::AccountInfo<'a>,
1304 bool,
1305 bool,
1306 )>,
1307}