Skip to main content

jup_perps_client/instructions/
set_max_global_sizes.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const SET_MAX_GLOBAL_SIZES_DISCRIMINATOR: [u8; 8] = [89, 2, 210, 24, 167, 227, 13, 214];
11
12/// Accounts.
13#[derive(Debug)]
14pub struct SetMaxGlobalSizes {
15    pub keeper: solana_program::pubkey::Pubkey,
16
17    pub custody: solana_program::pubkey::Pubkey,
18
19    pub pool: solana_program::pubkey::Pubkey,
20}
21
22impl SetMaxGlobalSizes {
23    pub fn instruction(
24        &self,
25        args: SetMaxGlobalSizesInstructionArgs,
26    ) -> solana_program::instruction::Instruction {
27        self.instruction_with_remaining_accounts(args, &[])
28    }
29    #[allow(clippy::arithmetic_side_effects)]
30    #[allow(clippy::vec_init_then_push)]
31    pub fn instruction_with_remaining_accounts(
32        &self,
33        args: SetMaxGlobalSizesInstructionArgs,
34        remaining_accounts: &[solana_program::instruction::AccountMeta],
35    ) -> solana_program::instruction::Instruction {
36        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
37        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38            self.keeper,
39            true,
40        ));
41        accounts.push(solana_program::instruction::AccountMeta::new(
42            self.custody,
43            false,
44        ));
45        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46            self.pool, false,
47        ));
48        accounts.extend_from_slice(remaining_accounts);
49        let mut data = borsh::to_vec(&SetMaxGlobalSizesInstructionData::new()).unwrap();
50        let mut args = borsh::to_vec(&args).unwrap();
51        data.append(&mut args);
52
53        solana_program::instruction::Instruction {
54            program_id: crate::PERPETUALS_ID,
55            accounts,
56            data,
57        }
58    }
59}
60
61#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63pub struct SetMaxGlobalSizesInstructionData {
64    discriminator: [u8; 8],
65}
66
67impl SetMaxGlobalSizesInstructionData {
68    pub fn new() -> Self {
69        Self {
70            discriminator: [89, 2, 210, 24, 167, 227, 13, 214],
71        }
72    }
73}
74
75impl Default for SetMaxGlobalSizesInstructionData {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub struct SetMaxGlobalSizesInstructionArgs {
84    pub max_global_long_size: u64,
85    pub max_global_short_size: u64,
86    pub recovery_id: u8,
87    pub signature: [u8; 64],
88    pub reference_id: [u8; 16],
89    pub timestamp: u64,
90}
91
92/// Instruction builder for `SetMaxGlobalSizes`.
93///
94/// ### Accounts:
95///
96///   0. `[signer]` keeper
97///   1. `[writable]` custody
98///   2. `[]` pool
99#[derive(Clone, Debug, Default)]
100pub struct SetMaxGlobalSizesBuilder {
101    keeper: Option<solana_program::pubkey::Pubkey>,
102    custody: Option<solana_program::pubkey::Pubkey>,
103    pool: Option<solana_program::pubkey::Pubkey>,
104    max_global_long_size: Option<u64>,
105    max_global_short_size: Option<u64>,
106    recovery_id: Option<u8>,
107    signature: Option<[u8; 64]>,
108    reference_id: Option<[u8; 16]>,
109    timestamp: Option<u64>,
110    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
111}
112
113impl SetMaxGlobalSizesBuilder {
114    pub fn new() -> Self {
115        Self::default()
116    }
117    #[inline(always)]
118    pub fn keeper(&mut self, keeper: solana_program::pubkey::Pubkey) -> &mut Self {
119        self.keeper = Some(keeper);
120        self
121    }
122    #[inline(always)]
123    pub fn custody(&mut self, custody: solana_program::pubkey::Pubkey) -> &mut Self {
124        self.custody = Some(custody);
125        self
126    }
127    #[inline(always)]
128    pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
129        self.pool = Some(pool);
130        self
131    }
132    #[inline(always)]
133    pub fn max_global_long_size(&mut self, max_global_long_size: u64) -> &mut Self {
134        self.max_global_long_size = Some(max_global_long_size);
135        self
136    }
137    #[inline(always)]
138    pub fn max_global_short_size(&mut self, max_global_short_size: u64) -> &mut Self {
139        self.max_global_short_size = Some(max_global_short_size);
140        self
141    }
142    #[inline(always)]
143    pub fn recovery_id(&mut self, recovery_id: u8) -> &mut Self {
144        self.recovery_id = Some(recovery_id);
145        self
146    }
147    #[inline(always)]
148    pub fn signature(&mut self, signature: [u8; 64]) -> &mut Self {
149        self.signature = Some(signature);
150        self
151    }
152    #[inline(always)]
153    pub fn reference_id(&mut self, reference_id: [u8; 16]) -> &mut Self {
154        self.reference_id = Some(reference_id);
155        self
156    }
157    #[inline(always)]
158    pub fn timestamp(&mut self, timestamp: u64) -> &mut Self {
159        self.timestamp = Some(timestamp);
160        self
161    }
162    /// Add an additional account to the instruction.
163    #[inline(always)]
164    pub fn add_remaining_account(
165        &mut self,
166        account: solana_program::instruction::AccountMeta,
167    ) -> &mut Self {
168        self.__remaining_accounts.push(account);
169        self
170    }
171    /// Add additional accounts to the instruction.
172    #[inline(always)]
173    pub fn add_remaining_accounts(
174        &mut self,
175        accounts: &[solana_program::instruction::AccountMeta],
176    ) -> &mut Self {
177        self.__remaining_accounts.extend_from_slice(accounts);
178        self
179    }
180    #[allow(clippy::clone_on_copy)]
181    pub fn instruction(&self) -> solana_program::instruction::Instruction {
182        let accounts = SetMaxGlobalSizes {
183            keeper: self.keeper.expect("keeper is not set"),
184            custody: self.custody.expect("custody is not set"),
185            pool: self.pool.expect("pool is not set"),
186        };
187        let args = SetMaxGlobalSizesInstructionArgs {
188            max_global_long_size: self
189                .max_global_long_size
190                .clone()
191                .expect("max_global_long_size is not set"),
192            max_global_short_size: self
193                .max_global_short_size
194                .clone()
195                .expect("max_global_short_size is not set"),
196            recovery_id: self.recovery_id.clone().expect("recovery_id is not set"),
197            signature: self.signature.clone().expect("signature is not set"),
198            reference_id: self.reference_id.clone().expect("reference_id is not set"),
199            timestamp: self.timestamp.clone().expect("timestamp is not set"),
200        };
201
202        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
203    }
204}
205
206/// `set_max_global_sizes` CPI accounts.
207pub struct SetMaxGlobalSizesCpiAccounts<'a, 'b> {
208    pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
209
210    pub custody: &'b solana_program::account_info::AccountInfo<'a>,
211
212    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
213}
214
215/// `set_max_global_sizes` CPI instruction.
216pub struct SetMaxGlobalSizesCpi<'a, 'b> {
217    /// The program to invoke.
218    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
219
220    pub keeper: &'b solana_program::account_info::AccountInfo<'a>,
221
222    pub custody: &'b solana_program::account_info::AccountInfo<'a>,
223
224    pub pool: &'b solana_program::account_info::AccountInfo<'a>,
225    /// The arguments for the instruction.
226    pub __args: SetMaxGlobalSizesInstructionArgs,
227}
228
229impl<'a, 'b> SetMaxGlobalSizesCpi<'a, 'b> {
230    pub fn new(
231        program: &'b solana_program::account_info::AccountInfo<'a>,
232        accounts: SetMaxGlobalSizesCpiAccounts<'a, 'b>,
233        args: SetMaxGlobalSizesInstructionArgs,
234    ) -> Self {
235        Self {
236            __program: program,
237            keeper: accounts.keeper,
238            custody: accounts.custody,
239            pool: accounts.pool,
240            __args: args,
241        }
242    }
243    #[inline(always)]
244    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
245        self.invoke_signed_with_remaining_accounts(&[], &[])
246    }
247    #[inline(always)]
248    pub fn invoke_with_remaining_accounts(
249        &self,
250        remaining_accounts: &[(
251            &'b solana_program::account_info::AccountInfo<'a>,
252            bool,
253            bool,
254        )],
255    ) -> solana_program::entrypoint::ProgramResult {
256        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
257    }
258    #[inline(always)]
259    pub fn invoke_signed(
260        &self,
261        signers_seeds: &[&[&[u8]]],
262    ) -> solana_program::entrypoint::ProgramResult {
263        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
264    }
265    #[allow(clippy::arithmetic_side_effects)]
266    #[allow(clippy::clone_on_copy)]
267    #[allow(clippy::vec_init_then_push)]
268    pub fn invoke_signed_with_remaining_accounts(
269        &self,
270        signers_seeds: &[&[&[u8]]],
271        remaining_accounts: &[(
272            &'b solana_program::account_info::AccountInfo<'a>,
273            bool,
274            bool,
275        )],
276    ) -> solana_program::entrypoint::ProgramResult {
277        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
278        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
279            *self.keeper.key,
280            true,
281        ));
282        accounts.push(solana_program::instruction::AccountMeta::new(
283            *self.custody.key,
284            false,
285        ));
286        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
287            *self.pool.key,
288            false,
289        ));
290        remaining_accounts.iter().for_each(|remaining_account| {
291            accounts.push(solana_program::instruction::AccountMeta {
292                pubkey: *remaining_account.0.key,
293                is_signer: remaining_account.1,
294                is_writable: remaining_account.2,
295            })
296        });
297        let mut data = borsh::to_vec(&SetMaxGlobalSizesInstructionData::new()).unwrap();
298        let mut args = borsh::to_vec(&self.__args).unwrap();
299        data.append(&mut args);
300
301        let instruction = solana_program::instruction::Instruction {
302            program_id: crate::PERPETUALS_ID,
303            accounts,
304            data,
305        };
306        let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
307        account_infos.push(self.__program.clone());
308        account_infos.push(self.keeper.clone());
309        account_infos.push(self.custody.clone());
310        account_infos.push(self.pool.clone());
311        remaining_accounts
312            .iter()
313            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
314
315        if signers_seeds.is_empty() {
316            solana_program::program::invoke(&instruction, &account_infos)
317        } else {
318            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
319        }
320    }
321}
322
323/// Instruction builder for `SetMaxGlobalSizes` via CPI.
324///
325/// ### Accounts:
326///
327///   0. `[signer]` keeper
328///   1. `[writable]` custody
329///   2. `[]` pool
330#[derive(Clone, Debug)]
331pub struct SetMaxGlobalSizesCpiBuilder<'a, 'b> {
332    instruction: Box<SetMaxGlobalSizesCpiBuilderInstruction<'a, 'b>>,
333}
334
335impl<'a, 'b> SetMaxGlobalSizesCpiBuilder<'a, 'b> {
336    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
337        let instruction = Box::new(SetMaxGlobalSizesCpiBuilderInstruction {
338            __program: program,
339            keeper: None,
340            custody: None,
341            pool: None,
342            max_global_long_size: None,
343            max_global_short_size: None,
344            recovery_id: None,
345            signature: None,
346            reference_id: None,
347            timestamp: None,
348            __remaining_accounts: Vec::new(),
349        });
350        Self { instruction }
351    }
352    #[inline(always)]
353    pub fn keeper(
354        &mut self,
355        keeper: &'b solana_program::account_info::AccountInfo<'a>,
356    ) -> &mut Self {
357        self.instruction.keeper = Some(keeper);
358        self
359    }
360    #[inline(always)]
361    pub fn custody(
362        &mut self,
363        custody: &'b solana_program::account_info::AccountInfo<'a>,
364    ) -> &mut Self {
365        self.instruction.custody = Some(custody);
366        self
367    }
368    #[inline(always)]
369    pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
370        self.instruction.pool = Some(pool);
371        self
372    }
373    #[inline(always)]
374    pub fn max_global_long_size(&mut self, max_global_long_size: u64) -> &mut Self {
375        self.instruction.max_global_long_size = Some(max_global_long_size);
376        self
377    }
378    #[inline(always)]
379    pub fn max_global_short_size(&mut self, max_global_short_size: u64) -> &mut Self {
380        self.instruction.max_global_short_size = Some(max_global_short_size);
381        self
382    }
383    #[inline(always)]
384    pub fn recovery_id(&mut self, recovery_id: u8) -> &mut Self {
385        self.instruction.recovery_id = Some(recovery_id);
386        self
387    }
388    #[inline(always)]
389    pub fn signature(&mut self, signature: [u8; 64]) -> &mut Self {
390        self.instruction.signature = Some(signature);
391        self
392    }
393    #[inline(always)]
394    pub fn reference_id(&mut self, reference_id: [u8; 16]) -> &mut Self {
395        self.instruction.reference_id = Some(reference_id);
396        self
397    }
398    #[inline(always)]
399    pub fn timestamp(&mut self, timestamp: u64) -> &mut Self {
400        self.instruction.timestamp = Some(timestamp);
401        self
402    }
403    /// Add an additional account to the instruction.
404    #[inline(always)]
405    pub fn add_remaining_account(
406        &mut self,
407        account: &'b solana_program::account_info::AccountInfo<'a>,
408        is_writable: bool,
409        is_signer: bool,
410    ) -> &mut Self {
411        self.instruction
412            .__remaining_accounts
413            .push((account, is_writable, is_signer));
414        self
415    }
416    /// Add additional accounts to the instruction.
417    ///
418    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
419    /// and a `bool` indicating whether the account is a signer or not.
420    #[inline(always)]
421    pub fn add_remaining_accounts(
422        &mut self,
423        accounts: &[(
424            &'b solana_program::account_info::AccountInfo<'a>,
425            bool,
426            bool,
427        )],
428    ) -> &mut Self {
429        self.instruction
430            .__remaining_accounts
431            .extend_from_slice(accounts);
432        self
433    }
434    #[inline(always)]
435    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
436        self.invoke_signed(&[])
437    }
438    #[allow(clippy::clone_on_copy)]
439    #[allow(clippy::vec_init_then_push)]
440    pub fn invoke_signed(
441        &self,
442        signers_seeds: &[&[&[u8]]],
443    ) -> solana_program::entrypoint::ProgramResult {
444        let args = SetMaxGlobalSizesInstructionArgs {
445            max_global_long_size: self
446                .instruction
447                .max_global_long_size
448                .clone()
449                .expect("max_global_long_size is not set"),
450            max_global_short_size: self
451                .instruction
452                .max_global_short_size
453                .clone()
454                .expect("max_global_short_size is not set"),
455            recovery_id: self
456                .instruction
457                .recovery_id
458                .clone()
459                .expect("recovery_id is not set"),
460            signature: self
461                .instruction
462                .signature
463                .clone()
464                .expect("signature is not set"),
465            reference_id: self
466                .instruction
467                .reference_id
468                .clone()
469                .expect("reference_id is not set"),
470            timestamp: self
471                .instruction
472                .timestamp
473                .clone()
474                .expect("timestamp is not set"),
475        };
476        let instruction = SetMaxGlobalSizesCpi {
477            __program: self.instruction.__program,
478
479            keeper: self.instruction.keeper.expect("keeper is not set"),
480
481            custody: self.instruction.custody.expect("custody is not set"),
482
483            pool: self.instruction.pool.expect("pool is not set"),
484            __args: args,
485        };
486        instruction.invoke_signed_with_remaining_accounts(
487            signers_seeds,
488            &self.instruction.__remaining_accounts,
489        )
490    }
491}
492
493#[derive(Clone, Debug)]
494struct SetMaxGlobalSizesCpiBuilderInstruction<'a, 'b> {
495    __program: &'b solana_program::account_info::AccountInfo<'a>,
496    keeper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
497    custody: Option<&'b solana_program::account_info::AccountInfo<'a>>,
498    pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
499    max_global_long_size: Option<u64>,
500    max_global_short_size: Option<u64>,
501    recovery_id: Option<u8>,
502    signature: Option<[u8; 64]>,
503    reference_id: Option<[u8; 16]>,
504    timestamp: Option<u64>,
505    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
506    __remaining_accounts: Vec<(
507        &'b solana_program::account_info::AccountInfo<'a>,
508        bool,
509        bool,
510    )>,
511}