Skip to main content

jup_perps_client/instructions/
update_decrease_position_request2.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const UPDATE_DECREASE_POSITION_REQUEST2_DISCRIMINATOR: [u8; 8] =
11    [144, 200, 249, 255, 108, 217, 249, 116];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct UpdateDecreasePositionRequest2 {
16    pub owner: solana_program::pubkey::Pubkey,
17
18    pub perpetuals: solana_program::pubkey::Pubkey,
19
20    pub pool: solana_program::pubkey::Pubkey,
21
22    pub position: solana_program::pubkey::Pubkey,
23
24    pub position_request: solana_program::pubkey::Pubkey,
25
26    pub custody: solana_program::pubkey::Pubkey,
27
28    pub custody_doves_price_account: solana_program::pubkey::Pubkey,
29
30    pub custody_pythnet_price_account: solana_program::pubkey::Pubkey,
31}
32
33impl UpdateDecreasePositionRequest2 {
34    pub fn instruction(
35        &self,
36        args: UpdateDecreasePositionRequest2InstructionArgs,
37    ) -> solana_program::instruction::Instruction {
38        self.instruction_with_remaining_accounts(args, &[])
39    }
40    #[allow(clippy::arithmetic_side_effects)]
41    #[allow(clippy::vec_init_then_push)]
42    pub fn instruction_with_remaining_accounts(
43        &self,
44        args: UpdateDecreasePositionRequest2InstructionArgs,
45        remaining_accounts: &[solana_program::instruction::AccountMeta],
46    ) -> solana_program::instruction::Instruction {
47        let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
48        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
49            self.owner, true,
50        ));
51        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52            self.perpetuals,
53            false,
54        ));
55        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
56            self.pool, false,
57        ));
58        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
59            self.position,
60            false,
61        ));
62        accounts.push(solana_program::instruction::AccountMeta::new(
63            self.position_request,
64            false,
65        ));
66        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
67            self.custody,
68            false,
69        ));
70        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
71            self.custody_doves_price_account,
72            false,
73        ));
74        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
75            self.custody_pythnet_price_account,
76            false,
77        ));
78        accounts.extend_from_slice(remaining_accounts);
79        let mut data =
80            borsh::to_vec(&UpdateDecreasePositionRequest2InstructionData::new()).unwrap();
81        let mut args = borsh::to_vec(&args).unwrap();
82        data.append(&mut args);
83
84        solana_program::instruction::Instruction {
85            program_id: crate::PERPETUALS_ID,
86            accounts,
87            data,
88        }
89    }
90}
91
92#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
93#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
94pub struct UpdateDecreasePositionRequest2InstructionData {
95    discriminator: [u8; 8],
96}
97
98impl UpdateDecreasePositionRequest2InstructionData {
99    pub fn new() -> Self {
100        Self {
101            discriminator: [144, 200, 249, 255, 108, 217, 249, 116],
102        }
103    }
104}
105
106impl Default for UpdateDecreasePositionRequest2InstructionData {
107    fn default() -> Self {
108        Self::new()
109    }
110}
111
112#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114pub struct UpdateDecreasePositionRequest2InstructionArgs {
115    pub size_usd_delta: u64,
116    pub trigger_price: u64,
117}
118
119/// Instruction builder for `UpdateDecreasePositionRequest2`.
120///
121/// ### Accounts:
122///
123///   0. `[signer]` owner
124///   1. `[]` perpetuals
125///   2. `[]` pool
126///   3. `[]` position
127///   4. `[writable]` position_request
128///   5. `[]` custody
129///   6. `[]` custody_doves_price_account
130///   7. `[]` custody_pythnet_price_account
131#[derive(Clone, Debug, Default)]
132pub struct UpdateDecreasePositionRequest2Builder {
133    owner: Option<solana_program::pubkey::Pubkey>,
134    perpetuals: Option<solana_program::pubkey::Pubkey>,
135    pool: Option<solana_program::pubkey::Pubkey>,
136    position: Option<solana_program::pubkey::Pubkey>,
137    position_request: Option<solana_program::pubkey::Pubkey>,
138    custody: Option<solana_program::pubkey::Pubkey>,
139    custody_doves_price_account: Option<solana_program::pubkey::Pubkey>,
140    custody_pythnet_price_account: Option<solana_program::pubkey::Pubkey>,
141    size_usd_delta: Option<u64>,
142    trigger_price: Option<u64>,
143    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
144}
145
146impl UpdateDecreasePositionRequest2Builder {
147    pub fn new() -> Self {
148        Self::default()
149    }
150    #[inline(always)]
151    pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
152        self.owner = Some(owner);
153        self
154    }
155    #[inline(always)]
156    pub fn perpetuals(&mut self, perpetuals: solana_program::pubkey::Pubkey) -> &mut Self {
157        self.perpetuals = Some(perpetuals);
158        self
159    }
160    #[inline(always)]
161    pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
162        self.pool = Some(pool);
163        self
164    }
165    #[inline(always)]
166    pub fn position(&mut self, position: solana_program::pubkey::Pubkey) -> &mut Self {
167        self.position = Some(position);
168        self
169    }
170    #[inline(always)]
171    pub fn position_request(
172        &mut self,
173        position_request: solana_program::pubkey::Pubkey,
174    ) -> &mut Self {
175        self.position_request = Some(position_request);
176        self
177    }
178    #[inline(always)]
179    pub fn custody(&mut self, custody: solana_program::pubkey::Pubkey) -> &mut Self {
180        self.custody = Some(custody);
181        self
182    }
183    #[inline(always)]
184    pub fn custody_doves_price_account(
185        &mut self,
186        custody_doves_price_account: solana_program::pubkey::Pubkey,
187    ) -> &mut Self {
188        self.custody_doves_price_account = Some(custody_doves_price_account);
189        self
190    }
191    #[inline(always)]
192    pub fn custody_pythnet_price_account(
193        &mut self,
194        custody_pythnet_price_account: solana_program::pubkey::Pubkey,
195    ) -> &mut Self {
196        self.custody_pythnet_price_account = Some(custody_pythnet_price_account);
197        self
198    }
199    #[inline(always)]
200    pub fn size_usd_delta(&mut self, size_usd_delta: u64) -> &mut Self {
201        self.size_usd_delta = Some(size_usd_delta);
202        self
203    }
204    #[inline(always)]
205    pub fn trigger_price(&mut self, trigger_price: u64) -> &mut Self {
206        self.trigger_price = Some(trigger_price);
207        self
208    }
209    /// Add an additional account to the instruction.
210    #[inline(always)]
211    pub fn add_remaining_account(
212        &mut self,
213        account: solana_program::instruction::AccountMeta,
214    ) -> &mut Self {
215        self.__remaining_accounts.push(account);
216        self
217    }
218    /// Add additional accounts to the instruction.
219    #[inline(always)]
220    pub fn add_remaining_accounts(
221        &mut self,
222        accounts: &[solana_program::instruction::AccountMeta],
223    ) -> &mut Self {
224        self.__remaining_accounts.extend_from_slice(accounts);
225        self
226    }
227    #[allow(clippy::clone_on_copy)]
228    pub fn instruction(&self) -> solana_program::instruction::Instruction {
229        let accounts = UpdateDecreasePositionRequest2 {
230            owner: self.owner.expect("owner is not set"),
231            perpetuals: self.perpetuals.expect("perpetuals is not set"),
232            pool: self.pool.expect("pool is not set"),
233            position: self.position.expect("position is not set"),
234            position_request: self.position_request.expect("position_request is not set"),
235            custody: self.custody.expect("custody is not set"),
236            custody_doves_price_account: self
237                .custody_doves_price_account
238                .expect("custody_doves_price_account is not set"),
239            custody_pythnet_price_account: self
240                .custody_pythnet_price_account
241                .expect("custody_pythnet_price_account is not set"),
242        };
243        let args = UpdateDecreasePositionRequest2InstructionArgs {
244            size_usd_delta: self
245                .size_usd_delta
246                .clone()
247                .expect("size_usd_delta is not set"),
248            trigger_price: self
249                .trigger_price
250                .clone()
251                .expect("trigger_price is not set"),
252        };
253
254        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
255    }
256}
257
258/// `update_decrease_position_request2` CPI accounts.
259pub struct UpdateDecreasePositionRequest2CpiAccounts<'a, 'b> {
260    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
261
262    pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
263
264    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
265
266    pub position: &'b solana_program::account_info::AccountInfo<'a>,
267
268    pub position_request: &'b solana_program::account_info::AccountInfo<'a>,
269
270    pub custody: &'b solana_program::account_info::AccountInfo<'a>,
271
272    pub custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
273
274    pub custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
275}
276
277/// `update_decrease_position_request2` CPI instruction.
278pub struct UpdateDecreasePositionRequest2Cpi<'a, 'b> {
279    /// The program to invoke.
280    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
281
282    pub owner: &'b solana_program::account_info::AccountInfo<'a>,
283
284    pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
285
286    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
287
288    pub position: &'b solana_program::account_info::AccountInfo<'a>,
289
290    pub position_request: &'b solana_program::account_info::AccountInfo<'a>,
291
292    pub custody: &'b solana_program::account_info::AccountInfo<'a>,
293
294    pub custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
295
296    pub custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
297    /// The arguments for the instruction.
298    pub __args: UpdateDecreasePositionRequest2InstructionArgs,
299}
300
301impl<'a, 'b> UpdateDecreasePositionRequest2Cpi<'a, 'b> {
302    pub fn new(
303        program: &'b solana_program::account_info::AccountInfo<'a>,
304        accounts: UpdateDecreasePositionRequest2CpiAccounts<'a, 'b>,
305        args: UpdateDecreasePositionRequest2InstructionArgs,
306    ) -> Self {
307        Self {
308            __program: program,
309            owner: accounts.owner,
310            perpetuals: accounts.perpetuals,
311            pool: accounts.pool,
312            position: accounts.position,
313            position_request: accounts.position_request,
314            custody: accounts.custody,
315            custody_doves_price_account: accounts.custody_doves_price_account,
316            custody_pythnet_price_account: accounts.custody_pythnet_price_account,
317            __args: args,
318        }
319    }
320    #[inline(always)]
321    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
322        self.invoke_signed_with_remaining_accounts(&[], &[])
323    }
324    #[inline(always)]
325    pub fn invoke_with_remaining_accounts(
326        &self,
327        remaining_accounts: &[(
328            &'b solana_program::account_info::AccountInfo<'a>,
329            bool,
330            bool,
331        )],
332    ) -> solana_program::entrypoint::ProgramResult {
333        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
334    }
335    #[inline(always)]
336    pub fn invoke_signed(
337        &self,
338        signers_seeds: &[&[&[u8]]],
339    ) -> solana_program::entrypoint::ProgramResult {
340        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
341    }
342    #[allow(clippy::arithmetic_side_effects)]
343    #[allow(clippy::clone_on_copy)]
344    #[allow(clippy::vec_init_then_push)]
345    pub fn invoke_signed_with_remaining_accounts(
346        &self,
347        signers_seeds: &[&[&[u8]]],
348        remaining_accounts: &[(
349            &'b solana_program::account_info::AccountInfo<'a>,
350            bool,
351            bool,
352        )],
353    ) -> solana_program::entrypoint::ProgramResult {
354        let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
355        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
356            *self.owner.key,
357            true,
358        ));
359        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
360            *self.perpetuals.key,
361            false,
362        ));
363        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
364            *self.pool.key,
365            false,
366        ));
367        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
368            *self.position.key,
369            false,
370        ));
371        accounts.push(solana_program::instruction::AccountMeta::new(
372            *self.position_request.key,
373            false,
374        ));
375        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
376            *self.custody.key,
377            false,
378        ));
379        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
380            *self.custody_doves_price_account.key,
381            false,
382        ));
383        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
384            *self.custody_pythnet_price_account.key,
385            false,
386        ));
387        remaining_accounts.iter().for_each(|remaining_account| {
388            accounts.push(solana_program::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 =
395            borsh::to_vec(&UpdateDecreasePositionRequest2InstructionData::new()).unwrap();
396        let mut args = borsh::to_vec(&self.__args).unwrap();
397        data.append(&mut args);
398
399        let instruction = solana_program::instruction::Instruction {
400            program_id: crate::PERPETUALS_ID,
401            accounts,
402            data,
403        };
404        let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
405        account_infos.push(self.__program.clone());
406        account_infos.push(self.owner.clone());
407        account_infos.push(self.perpetuals.clone());
408        account_infos.push(self.pool.clone());
409        account_infos.push(self.position.clone());
410        account_infos.push(self.position_request.clone());
411        account_infos.push(self.custody.clone());
412        account_infos.push(self.custody_doves_price_account.clone());
413        account_infos.push(self.custody_pythnet_price_account.clone());
414        remaining_accounts
415            .iter()
416            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
417
418        if signers_seeds.is_empty() {
419            solana_program::program::invoke(&instruction, &account_infos)
420        } else {
421            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
422        }
423    }
424}
425
426/// Instruction builder for `UpdateDecreasePositionRequest2` via CPI.
427///
428/// ### Accounts:
429///
430///   0. `[signer]` owner
431///   1. `[]` perpetuals
432///   2. `[]` pool
433///   3. `[]` position
434///   4. `[writable]` position_request
435///   5. `[]` custody
436///   6. `[]` custody_doves_price_account
437///   7. `[]` custody_pythnet_price_account
438#[derive(Clone, Debug)]
439pub struct UpdateDecreasePositionRequest2CpiBuilder<'a, 'b> {
440    instruction: Box<UpdateDecreasePositionRequest2CpiBuilderInstruction<'a, 'b>>,
441}
442
443impl<'a, 'b> UpdateDecreasePositionRequest2CpiBuilder<'a, 'b> {
444    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
445        let instruction = Box::new(UpdateDecreasePositionRequest2CpiBuilderInstruction {
446            __program: program,
447            owner: None,
448            perpetuals: None,
449            pool: None,
450            position: None,
451            position_request: None,
452            custody: None,
453            custody_doves_price_account: None,
454            custody_pythnet_price_account: None,
455            size_usd_delta: None,
456            trigger_price: None,
457            __remaining_accounts: Vec::new(),
458        });
459        Self { instruction }
460    }
461    #[inline(always)]
462    pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
463        self.instruction.owner = Some(owner);
464        self
465    }
466    #[inline(always)]
467    pub fn perpetuals(
468        &mut self,
469        perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
470    ) -> &mut Self {
471        self.instruction.perpetuals = Some(perpetuals);
472        self
473    }
474    #[inline(always)]
475    pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
476        self.instruction.pool = Some(pool);
477        self
478    }
479    #[inline(always)]
480    pub fn position(
481        &mut self,
482        position: &'b solana_program::account_info::AccountInfo<'a>,
483    ) -> &mut Self {
484        self.instruction.position = Some(position);
485        self
486    }
487    #[inline(always)]
488    pub fn position_request(
489        &mut self,
490        position_request: &'b solana_program::account_info::AccountInfo<'a>,
491    ) -> &mut Self {
492        self.instruction.position_request = Some(position_request);
493        self
494    }
495    #[inline(always)]
496    pub fn custody(
497        &mut self,
498        custody: &'b solana_program::account_info::AccountInfo<'a>,
499    ) -> &mut Self {
500        self.instruction.custody = Some(custody);
501        self
502    }
503    #[inline(always)]
504    pub fn custody_doves_price_account(
505        &mut self,
506        custody_doves_price_account: &'b solana_program::account_info::AccountInfo<'a>,
507    ) -> &mut Self {
508        self.instruction.custody_doves_price_account = Some(custody_doves_price_account);
509        self
510    }
511    #[inline(always)]
512    pub fn custody_pythnet_price_account(
513        &mut self,
514        custody_pythnet_price_account: &'b solana_program::account_info::AccountInfo<'a>,
515    ) -> &mut Self {
516        self.instruction.custody_pythnet_price_account = Some(custody_pythnet_price_account);
517        self
518    }
519    #[inline(always)]
520    pub fn size_usd_delta(&mut self, size_usd_delta: u64) -> &mut Self {
521        self.instruction.size_usd_delta = Some(size_usd_delta);
522        self
523    }
524    #[inline(always)]
525    pub fn trigger_price(&mut self, trigger_price: u64) -> &mut Self {
526        self.instruction.trigger_price = Some(trigger_price);
527        self
528    }
529    /// Add an additional account to the instruction.
530    #[inline(always)]
531    pub fn add_remaining_account(
532        &mut self,
533        account: &'b solana_program::account_info::AccountInfo<'a>,
534        is_writable: bool,
535        is_signer: bool,
536    ) -> &mut Self {
537        self.instruction
538            .__remaining_accounts
539            .push((account, is_writable, is_signer));
540        self
541    }
542    /// Add additional accounts to the instruction.
543    ///
544    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
545    /// and a `bool` indicating whether the account is a signer or not.
546    #[inline(always)]
547    pub fn add_remaining_accounts(
548        &mut self,
549        accounts: &[(
550            &'b solana_program::account_info::AccountInfo<'a>,
551            bool,
552            bool,
553        )],
554    ) -> &mut Self {
555        self.instruction
556            .__remaining_accounts
557            .extend_from_slice(accounts);
558        self
559    }
560    #[inline(always)]
561    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
562        self.invoke_signed(&[])
563    }
564    #[allow(clippy::clone_on_copy)]
565    #[allow(clippy::vec_init_then_push)]
566    pub fn invoke_signed(
567        &self,
568        signers_seeds: &[&[&[u8]]],
569    ) -> solana_program::entrypoint::ProgramResult {
570        let args = UpdateDecreasePositionRequest2InstructionArgs {
571            size_usd_delta: self
572                .instruction
573                .size_usd_delta
574                .clone()
575                .expect("size_usd_delta is not set"),
576            trigger_price: self
577                .instruction
578                .trigger_price
579                .clone()
580                .expect("trigger_price is not set"),
581        };
582        let instruction = UpdateDecreasePositionRequest2Cpi {
583            __program: self.instruction.__program,
584
585            owner: self.instruction.owner.expect("owner is not set"),
586
587            perpetuals: self.instruction.perpetuals.expect("perpetuals is not set"),
588
589            pool: self.instruction.pool.expect("pool is not set"),
590
591            position: self.instruction.position.expect("position is not set"),
592
593            position_request: self
594                .instruction
595                .position_request
596                .expect("position_request is not set"),
597
598            custody: self.instruction.custody.expect("custody is not set"),
599
600            custody_doves_price_account: self
601                .instruction
602                .custody_doves_price_account
603                .expect("custody_doves_price_account is not set"),
604
605            custody_pythnet_price_account: self
606                .instruction
607                .custody_pythnet_price_account
608                .expect("custody_pythnet_price_account is not set"),
609            __args: args,
610        };
611        instruction.invoke_signed_with_remaining_accounts(
612            signers_seeds,
613            &self.instruction.__remaining_accounts,
614        )
615    }
616}
617
618#[derive(Clone, Debug)]
619struct UpdateDecreasePositionRequest2CpiBuilderInstruction<'a, 'b> {
620    __program: &'b solana_program::account_info::AccountInfo<'a>,
621    owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
622    perpetuals: Option<&'b solana_program::account_info::AccountInfo<'a>>,
623    pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
624    position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
625    position_request: Option<&'b solana_program::account_info::AccountInfo<'a>>,
626    custody: Option<&'b solana_program::account_info::AccountInfo<'a>>,
627    custody_doves_price_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
628    custody_pythnet_price_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
629    size_usd_delta: Option<u64>,
630    trigger_price: Option<u64>,
631    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
632    __remaining_accounts: Vec<(
633        &'b solana_program::account_info::AccountInfo<'a>,
634        bool,
635        bool,
636    )>,
637}