Skip to main content

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