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