Skip to main content

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