Skip to main content

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