1use crate::types::Fees;
9use crate::types::Limit;
10use borsh::{BorshDeserialize, BorshSerialize};
11
12pub const OPERATOR_SET_POOL_CONFIG_DISCRIMINATOR: [u8; 8] = [76, 201, 80, 18, 199, 92, 246, 105];
13
14#[derive(Debug)]
16pub struct OperatorSetPoolConfig {
17 pub operator: solana_program::pubkey::Pubkey,
18
19 pub pool: solana_program::pubkey::Pubkey,
20}
21
22impl OperatorSetPoolConfig {
23 pub fn instruction(
24 &self,
25 args: OperatorSetPoolConfigInstructionArgs,
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: OperatorSetPoolConfigInstructionArgs,
34 remaining_accounts: &[solana_program::instruction::AccountMeta],
35 ) -> solana_program::instruction::Instruction {
36 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
37 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38 self.operator,
39 true,
40 ));
41 accounts.push(solana_program::instruction::AccountMeta::new(
42 self.pool, false,
43 ));
44 accounts.extend_from_slice(remaining_accounts);
45 let mut data = borsh::to_vec(&OperatorSetPoolConfigInstructionData::new()).unwrap();
46 let mut args = borsh::to_vec(&args).unwrap();
47 data.append(&mut args);
48
49 solana_program::instruction::Instruction {
50 program_id: crate::PERPETUALS_ID,
51 accounts,
52 data,
53 }
54 }
55}
56
57#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub struct OperatorSetPoolConfigInstructionData {
60 discriminator: [u8; 8],
61}
62
63impl OperatorSetPoolConfigInstructionData {
64 pub fn new() -> Self {
65 Self {
66 discriminator: [76, 201, 80, 18, 199, 92, 246, 105],
67 }
68 }
69}
70
71impl Default for OperatorSetPoolConfigInstructionData {
72 fn default() -> Self {
73 Self::new()
74 }
75}
76
77#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
78#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79pub struct OperatorSetPoolConfigInstructionArgs {
80 pub fees: Fees,
81 pub limit: Limit,
82 pub max_request_execution_sec: i64,
83 pub max_trigger_price_diff_bps: u64,
84 pub disable_close_position_request: bool,
85 pub max_lp_token_price_change_bps: u64,
86}
87
88#[derive(Clone, Debug, Default)]
95pub struct OperatorSetPoolConfigBuilder {
96 operator: Option<solana_program::pubkey::Pubkey>,
97 pool: Option<solana_program::pubkey::Pubkey>,
98 fees: Option<Fees>,
99 limit: Option<Limit>,
100 max_request_execution_sec: Option<i64>,
101 max_trigger_price_diff_bps: Option<u64>,
102 disable_close_position_request: Option<bool>,
103 max_lp_token_price_change_bps: Option<u64>,
104 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
105}
106
107impl OperatorSetPoolConfigBuilder {
108 pub fn new() -> Self {
109 Self::default()
110 }
111 #[inline(always)]
112 pub fn operator(&mut self, operator: solana_program::pubkey::Pubkey) -> &mut Self {
113 self.operator = Some(operator);
114 self
115 }
116 #[inline(always)]
117 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
118 self.pool = Some(pool);
119 self
120 }
121 #[inline(always)]
122 pub fn fees(&mut self, fees: Fees) -> &mut Self {
123 self.fees = Some(fees);
124 self
125 }
126 #[inline(always)]
127 pub fn limit(&mut self, limit: Limit) -> &mut Self {
128 self.limit = Some(limit);
129 self
130 }
131 #[inline(always)]
132 pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
133 self.max_request_execution_sec = Some(max_request_execution_sec);
134 self
135 }
136 #[inline(always)]
137 pub fn max_trigger_price_diff_bps(&mut self, max_trigger_price_diff_bps: u64) -> &mut Self {
138 self.max_trigger_price_diff_bps = Some(max_trigger_price_diff_bps);
139 self
140 }
141 #[inline(always)]
142 pub fn disable_close_position_request(
143 &mut self,
144 disable_close_position_request: bool,
145 ) -> &mut Self {
146 self.disable_close_position_request = Some(disable_close_position_request);
147 self
148 }
149 #[inline(always)]
150 pub fn max_lp_token_price_change_bps(
151 &mut self,
152 max_lp_token_price_change_bps: u64,
153 ) -> &mut Self {
154 self.max_lp_token_price_change_bps = Some(max_lp_token_price_change_bps);
155 self
156 }
157 #[inline(always)]
159 pub fn add_remaining_account(
160 &mut self,
161 account: solana_program::instruction::AccountMeta,
162 ) -> &mut Self {
163 self.__remaining_accounts.push(account);
164 self
165 }
166 #[inline(always)]
168 pub fn add_remaining_accounts(
169 &mut self,
170 accounts: &[solana_program::instruction::AccountMeta],
171 ) -> &mut Self {
172 self.__remaining_accounts.extend_from_slice(accounts);
173 self
174 }
175 #[allow(clippy::clone_on_copy)]
176 pub fn instruction(&self) -> solana_program::instruction::Instruction {
177 let accounts = OperatorSetPoolConfig {
178 operator: self.operator.expect("operator is not set"),
179 pool: self.pool.expect("pool is not set"),
180 };
181 let args = OperatorSetPoolConfigInstructionArgs {
182 fees: self.fees.clone().expect("fees is not set"),
183 limit: self.limit.clone().expect("limit is not set"),
184 max_request_execution_sec: self
185 .max_request_execution_sec
186 .clone()
187 .expect("max_request_execution_sec is not set"),
188 max_trigger_price_diff_bps: self
189 .max_trigger_price_diff_bps
190 .clone()
191 .expect("max_trigger_price_diff_bps is not set"),
192 disable_close_position_request: self
193 .disable_close_position_request
194 .clone()
195 .expect("disable_close_position_request is not set"),
196 max_lp_token_price_change_bps: self
197 .max_lp_token_price_change_bps
198 .clone()
199 .expect("max_lp_token_price_change_bps is not set"),
200 };
201
202 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
203 }
204}
205
206pub struct OperatorSetPoolConfigCpiAccounts<'a, 'b> {
208 pub operator: &'b solana_program::account_info::AccountInfo<'a>,
209
210 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
211}
212
213pub struct OperatorSetPoolConfigCpi<'a, 'b> {
215 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
217
218 pub operator: &'b solana_program::account_info::AccountInfo<'a>,
219
220 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
221 pub __args: OperatorSetPoolConfigInstructionArgs,
223}
224
225impl<'a, 'b> OperatorSetPoolConfigCpi<'a, 'b> {
226 pub fn new(
227 program: &'b solana_program::account_info::AccountInfo<'a>,
228 accounts: OperatorSetPoolConfigCpiAccounts<'a, 'b>,
229 args: OperatorSetPoolConfigInstructionArgs,
230 ) -> Self {
231 Self {
232 __program: program,
233 operator: accounts.operator,
234 pool: accounts.pool,
235 __args: args,
236 }
237 }
238 #[inline(always)]
239 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
240 self.invoke_signed_with_remaining_accounts(&[], &[])
241 }
242 #[inline(always)]
243 pub fn invoke_with_remaining_accounts(
244 &self,
245 remaining_accounts: &[(
246 &'b solana_program::account_info::AccountInfo<'a>,
247 bool,
248 bool,
249 )],
250 ) -> solana_program::entrypoint::ProgramResult {
251 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
252 }
253 #[inline(always)]
254 pub fn invoke_signed(
255 &self,
256 signers_seeds: &[&[&[u8]]],
257 ) -> solana_program::entrypoint::ProgramResult {
258 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
259 }
260 #[allow(clippy::arithmetic_side_effects)]
261 #[allow(clippy::clone_on_copy)]
262 #[allow(clippy::vec_init_then_push)]
263 pub fn invoke_signed_with_remaining_accounts(
264 &self,
265 signers_seeds: &[&[&[u8]]],
266 remaining_accounts: &[(
267 &'b solana_program::account_info::AccountInfo<'a>,
268 bool,
269 bool,
270 )],
271 ) -> solana_program::entrypoint::ProgramResult {
272 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
273 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
274 *self.operator.key,
275 true,
276 ));
277 accounts.push(solana_program::instruction::AccountMeta::new(
278 *self.pool.key,
279 false,
280 ));
281 remaining_accounts.iter().for_each(|remaining_account| {
282 accounts.push(solana_program::instruction::AccountMeta {
283 pubkey: *remaining_account.0.key,
284 is_signer: remaining_account.1,
285 is_writable: remaining_account.2,
286 })
287 });
288 let mut data = borsh::to_vec(&OperatorSetPoolConfigInstructionData::new()).unwrap();
289 let mut args = borsh::to_vec(&self.__args).unwrap();
290 data.append(&mut args);
291
292 let instruction = solana_program::instruction::Instruction {
293 program_id: crate::PERPETUALS_ID,
294 accounts,
295 data,
296 };
297 let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
298 account_infos.push(self.__program.clone());
299 account_infos.push(self.operator.clone());
300 account_infos.push(self.pool.clone());
301 remaining_accounts
302 .iter()
303 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
304
305 if signers_seeds.is_empty() {
306 solana_program::program::invoke(&instruction, &account_infos)
307 } else {
308 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
309 }
310 }
311}
312
313#[derive(Clone, Debug)]
320pub struct OperatorSetPoolConfigCpiBuilder<'a, 'b> {
321 instruction: Box<OperatorSetPoolConfigCpiBuilderInstruction<'a, 'b>>,
322}
323
324impl<'a, 'b> OperatorSetPoolConfigCpiBuilder<'a, 'b> {
325 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
326 let instruction = Box::new(OperatorSetPoolConfigCpiBuilderInstruction {
327 __program: program,
328 operator: None,
329 pool: None,
330 fees: None,
331 limit: None,
332 max_request_execution_sec: None,
333 max_trigger_price_diff_bps: None,
334 disable_close_position_request: None,
335 max_lp_token_price_change_bps: None,
336 __remaining_accounts: Vec::new(),
337 });
338 Self { instruction }
339 }
340 #[inline(always)]
341 pub fn operator(
342 &mut self,
343 operator: &'b solana_program::account_info::AccountInfo<'a>,
344 ) -> &mut Self {
345 self.instruction.operator = Some(operator);
346 self
347 }
348 #[inline(always)]
349 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
350 self.instruction.pool = Some(pool);
351 self
352 }
353 #[inline(always)]
354 pub fn fees(&mut self, fees: Fees) -> &mut Self {
355 self.instruction.fees = Some(fees);
356 self
357 }
358 #[inline(always)]
359 pub fn limit(&mut self, limit: Limit) -> &mut Self {
360 self.instruction.limit = Some(limit);
361 self
362 }
363 #[inline(always)]
364 pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
365 self.instruction.max_request_execution_sec = Some(max_request_execution_sec);
366 self
367 }
368 #[inline(always)]
369 pub fn max_trigger_price_diff_bps(&mut self, max_trigger_price_diff_bps: u64) -> &mut Self {
370 self.instruction.max_trigger_price_diff_bps = Some(max_trigger_price_diff_bps);
371 self
372 }
373 #[inline(always)]
374 pub fn disable_close_position_request(
375 &mut self,
376 disable_close_position_request: bool,
377 ) -> &mut Self {
378 self.instruction.disable_close_position_request = Some(disable_close_position_request);
379 self
380 }
381 #[inline(always)]
382 pub fn max_lp_token_price_change_bps(
383 &mut self,
384 max_lp_token_price_change_bps: u64,
385 ) -> &mut Self {
386 self.instruction.max_lp_token_price_change_bps = Some(max_lp_token_price_change_bps);
387 self
388 }
389 #[inline(always)]
391 pub fn add_remaining_account(
392 &mut self,
393 account: &'b solana_program::account_info::AccountInfo<'a>,
394 is_writable: bool,
395 is_signer: bool,
396 ) -> &mut Self {
397 self.instruction
398 .__remaining_accounts
399 .push((account, is_writable, is_signer));
400 self
401 }
402 #[inline(always)]
407 pub fn add_remaining_accounts(
408 &mut self,
409 accounts: &[(
410 &'b solana_program::account_info::AccountInfo<'a>,
411 bool,
412 bool,
413 )],
414 ) -> &mut Self {
415 self.instruction
416 .__remaining_accounts
417 .extend_from_slice(accounts);
418 self
419 }
420 #[inline(always)]
421 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
422 self.invoke_signed(&[])
423 }
424 #[allow(clippy::clone_on_copy)]
425 #[allow(clippy::vec_init_then_push)]
426 pub fn invoke_signed(
427 &self,
428 signers_seeds: &[&[&[u8]]],
429 ) -> solana_program::entrypoint::ProgramResult {
430 let args = OperatorSetPoolConfigInstructionArgs {
431 fees: self.instruction.fees.clone().expect("fees is not set"),
432 limit: self.instruction.limit.clone().expect("limit is not set"),
433 max_request_execution_sec: self
434 .instruction
435 .max_request_execution_sec
436 .clone()
437 .expect("max_request_execution_sec is not set"),
438 max_trigger_price_diff_bps: self
439 .instruction
440 .max_trigger_price_diff_bps
441 .clone()
442 .expect("max_trigger_price_diff_bps is not set"),
443 disable_close_position_request: self
444 .instruction
445 .disable_close_position_request
446 .clone()
447 .expect("disable_close_position_request is not set"),
448 max_lp_token_price_change_bps: self
449 .instruction
450 .max_lp_token_price_change_bps
451 .clone()
452 .expect("max_lp_token_price_change_bps is not set"),
453 };
454 let instruction = OperatorSetPoolConfigCpi {
455 __program: self.instruction.__program,
456
457 operator: self.instruction.operator.expect("operator is not set"),
458
459 pool: self.instruction.pool.expect("pool is not set"),
460 __args: args,
461 };
462 instruction.invoke_signed_with_remaining_accounts(
463 signers_seeds,
464 &self.instruction.__remaining_accounts,
465 )
466 }
467}
468
469#[derive(Clone, Debug)]
470struct OperatorSetPoolConfigCpiBuilderInstruction<'a, 'b> {
471 __program: &'b solana_program::account_info::AccountInfo<'a>,
472 operator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
473 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
474 fees: Option<Fees>,
475 limit: Option<Limit>,
476 max_request_execution_sec: Option<i64>,
477 max_trigger_price_diff_bps: Option<u64>,
478 disable_close_position_request: Option<bool>,
479 max_lp_token_price_change_bps: Option<u64>,
480 __remaining_accounts: Vec<(
482 &'b solana_program::account_info::AccountInfo<'a>,
483 bool,
484 bool,
485 )>,
486}