1use crate::types::Fees;
9use crate::types::Limit;
10use borsh::{BorshDeserialize, BorshSerialize};
11
12pub const ADD_POOL_DISCRIMINATOR: [u8; 8] = [115, 230, 212, 211, 175, 49, 39, 169];
13
14#[derive(Debug)]
16pub struct AddPool {
17 pub admin: solana_program::pubkey::Pubkey,
18
19 pub transfer_authority: solana_program::pubkey::Pubkey,
20
21 pub perpetuals: solana_program::pubkey::Pubkey,
22
23 pub pool: solana_program::pubkey::Pubkey,
24
25 pub lp_token_mint: solana_program::pubkey::Pubkey,
26
27 pub system_program: solana_program::pubkey::Pubkey,
28
29 pub token_program: solana_program::pubkey::Pubkey,
30
31 pub rent: solana_program::pubkey::Pubkey,
32}
33
34impl AddPool {
35 pub fn instruction(
36 &self,
37 args: AddPoolInstructionArgs,
38 ) -> solana_program::instruction::Instruction {
39 self.instruction_with_remaining_accounts(args, &[])
40 }
41 #[allow(clippy::arithmetic_side_effects)]
42 #[allow(clippy::vec_init_then_push)]
43 pub fn instruction_with_remaining_accounts(
44 &self,
45 args: AddPoolInstructionArgs,
46 remaining_accounts: &[solana_program::instruction::AccountMeta],
47 ) -> solana_program::instruction::Instruction {
48 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
49 accounts.push(solana_program::instruction::AccountMeta::new(
50 self.admin, true,
51 ));
52 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53 self.transfer_authority,
54 false,
55 ));
56 accounts.push(solana_program::instruction::AccountMeta::new(
57 self.perpetuals,
58 false,
59 ));
60 accounts.push(solana_program::instruction::AccountMeta::new(
61 self.pool, false,
62 ));
63 accounts.push(solana_program::instruction::AccountMeta::new(
64 self.lp_token_mint,
65 false,
66 ));
67 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
68 self.system_program,
69 false,
70 ));
71 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
72 self.token_program,
73 false,
74 ));
75 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
76 self.rent, false,
77 ));
78 accounts.extend_from_slice(remaining_accounts);
79 let mut data = borsh::to_vec(&AddPoolInstructionData::new()).unwrap();
80 let mut args = borsh::to_vec(&args).unwrap();
81 data.append(&mut args);
82
83 solana_program::instruction::Instruction {
84 program_id: crate::PERPETUALS_ID,
85 accounts,
86 data,
87 }
88 }
89}
90
91#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93pub struct AddPoolInstructionData {
94 discriminator: [u8; 8],
95}
96
97impl AddPoolInstructionData {
98 pub fn new() -> Self {
99 Self {
100 discriminator: [115, 230, 212, 211, 175, 49, 39, 169],
101 }
102 }
103}
104
105impl Default for AddPoolInstructionData {
106 fn default() -> Self {
107 Self::new()
108 }
109}
110
111#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, PartialEq)]
112#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
113pub struct AddPoolInstructionArgs {
114 pub name: String,
115 pub limit: Limit,
116 pub fees: Fees,
117 pub max_request_execution_sec: i64,
118}
119
120#[derive(Clone, Debug, Default)]
133pub struct AddPoolBuilder {
134 admin: Option<solana_program::pubkey::Pubkey>,
135 transfer_authority: Option<solana_program::pubkey::Pubkey>,
136 perpetuals: Option<solana_program::pubkey::Pubkey>,
137 pool: Option<solana_program::pubkey::Pubkey>,
138 lp_token_mint: Option<solana_program::pubkey::Pubkey>,
139 system_program: Option<solana_program::pubkey::Pubkey>,
140 token_program: Option<solana_program::pubkey::Pubkey>,
141 rent: Option<solana_program::pubkey::Pubkey>,
142 name: Option<String>,
143 limit: Option<Limit>,
144 fees: Option<Fees>,
145 max_request_execution_sec: Option<i64>,
146 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
147}
148
149impl AddPoolBuilder {
150 pub fn new() -> Self {
151 Self::default()
152 }
153 #[inline(always)]
154 pub fn admin(&mut self, admin: solana_program::pubkey::Pubkey) -> &mut Self {
155 self.admin = Some(admin);
156 self
157 }
158 #[inline(always)]
159 pub fn transfer_authority(
160 &mut self,
161 transfer_authority: solana_program::pubkey::Pubkey,
162 ) -> &mut Self {
163 self.transfer_authority = Some(transfer_authority);
164 self
165 }
166 #[inline(always)]
167 pub fn perpetuals(&mut self, perpetuals: solana_program::pubkey::Pubkey) -> &mut Self {
168 self.perpetuals = Some(perpetuals);
169 self
170 }
171 #[inline(always)]
172 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
173 self.pool = Some(pool);
174 self
175 }
176 #[inline(always)]
177 pub fn lp_token_mint(&mut self, lp_token_mint: solana_program::pubkey::Pubkey) -> &mut Self {
178 self.lp_token_mint = Some(lp_token_mint);
179 self
180 }
181 #[inline(always)]
183 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
184 self.system_program = Some(system_program);
185 self
186 }
187 #[inline(always)]
189 pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
190 self.token_program = Some(token_program);
191 self
192 }
193 #[inline(always)]
195 pub fn rent(&mut self, rent: solana_program::pubkey::Pubkey) -> &mut Self {
196 self.rent = Some(rent);
197 self
198 }
199 #[inline(always)]
200 pub fn name(&mut self, name: String) -> &mut Self {
201 self.name = Some(name);
202 self
203 }
204 #[inline(always)]
205 pub fn limit(&mut self, limit: Limit) -> &mut Self {
206 self.limit = Some(limit);
207 self
208 }
209 #[inline(always)]
210 pub fn fees(&mut self, fees: Fees) -> &mut Self {
211 self.fees = Some(fees);
212 self
213 }
214 #[inline(always)]
215 pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
216 self.max_request_execution_sec = Some(max_request_execution_sec);
217 self
218 }
219 #[inline(always)]
221 pub fn add_remaining_account(
222 &mut self,
223 account: solana_program::instruction::AccountMeta,
224 ) -> &mut Self {
225 self.__remaining_accounts.push(account);
226 self
227 }
228 #[inline(always)]
230 pub fn add_remaining_accounts(
231 &mut self,
232 accounts: &[solana_program::instruction::AccountMeta],
233 ) -> &mut Self {
234 self.__remaining_accounts.extend_from_slice(accounts);
235 self
236 }
237 #[allow(clippy::clone_on_copy)]
238 pub fn instruction(&self) -> solana_program::instruction::Instruction {
239 let accounts = AddPool {
240 admin: self.admin.expect("admin is not set"),
241 transfer_authority: self
242 .transfer_authority
243 .expect("transfer_authority is not set"),
244 perpetuals: self.perpetuals.expect("perpetuals is not set"),
245 pool: self.pool.expect("pool is not set"),
246 lp_token_mint: self.lp_token_mint.expect("lp_token_mint is not set"),
247 system_program: self
248 .system_program
249 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
250 token_program: self.token_program.unwrap_or(solana_program::pubkey!(
251 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
252 )),
253 rent: self.rent.unwrap_or(solana_program::pubkey!(
254 "SysvarRent111111111111111111111111111111111"
255 )),
256 };
257 let args = AddPoolInstructionArgs {
258 name: self.name.clone().expect("name is not set"),
259 limit: self.limit.clone().expect("limit is not set"),
260 fees: self.fees.clone().expect("fees is not set"),
261 max_request_execution_sec: self
262 .max_request_execution_sec
263 .clone()
264 .expect("max_request_execution_sec is not set"),
265 };
266
267 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
268 }
269}
270
271pub struct AddPoolCpiAccounts<'a, 'b> {
273 pub admin: &'b solana_program::account_info::AccountInfo<'a>,
274
275 pub transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
276
277 pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
278
279 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
280
281 pub lp_token_mint: &'b solana_program::account_info::AccountInfo<'a>,
282
283 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
284
285 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
286
287 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
288}
289
290pub struct AddPoolCpi<'a, 'b> {
292 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
294
295 pub admin: &'b solana_program::account_info::AccountInfo<'a>,
296
297 pub transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
298
299 pub perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
300
301 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
302
303 pub lp_token_mint: &'b solana_program::account_info::AccountInfo<'a>,
304
305 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
306
307 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
308
309 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
310 pub __args: AddPoolInstructionArgs,
312}
313
314impl<'a, 'b> AddPoolCpi<'a, 'b> {
315 pub fn new(
316 program: &'b solana_program::account_info::AccountInfo<'a>,
317 accounts: AddPoolCpiAccounts<'a, 'b>,
318 args: AddPoolInstructionArgs,
319 ) -> Self {
320 Self {
321 __program: program,
322 admin: accounts.admin,
323 transfer_authority: accounts.transfer_authority,
324 perpetuals: accounts.perpetuals,
325 pool: accounts.pool,
326 lp_token_mint: accounts.lp_token_mint,
327 system_program: accounts.system_program,
328 token_program: accounts.token_program,
329 rent: accounts.rent,
330 __args: args,
331 }
332 }
333 #[inline(always)]
334 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
335 self.invoke_signed_with_remaining_accounts(&[], &[])
336 }
337 #[inline(always)]
338 pub fn invoke_with_remaining_accounts(
339 &self,
340 remaining_accounts: &[(
341 &'b solana_program::account_info::AccountInfo<'a>,
342 bool,
343 bool,
344 )],
345 ) -> solana_program::entrypoint::ProgramResult {
346 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
347 }
348 #[inline(always)]
349 pub fn invoke_signed(
350 &self,
351 signers_seeds: &[&[&[u8]]],
352 ) -> solana_program::entrypoint::ProgramResult {
353 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
354 }
355 #[allow(clippy::arithmetic_side_effects)]
356 #[allow(clippy::clone_on_copy)]
357 #[allow(clippy::vec_init_then_push)]
358 pub fn invoke_signed_with_remaining_accounts(
359 &self,
360 signers_seeds: &[&[&[u8]]],
361 remaining_accounts: &[(
362 &'b solana_program::account_info::AccountInfo<'a>,
363 bool,
364 bool,
365 )],
366 ) -> solana_program::entrypoint::ProgramResult {
367 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
368 accounts.push(solana_program::instruction::AccountMeta::new(
369 *self.admin.key,
370 true,
371 ));
372 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
373 *self.transfer_authority.key,
374 false,
375 ));
376 accounts.push(solana_program::instruction::AccountMeta::new(
377 *self.perpetuals.key,
378 false,
379 ));
380 accounts.push(solana_program::instruction::AccountMeta::new(
381 *self.pool.key,
382 false,
383 ));
384 accounts.push(solana_program::instruction::AccountMeta::new(
385 *self.lp_token_mint.key,
386 false,
387 ));
388 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
389 *self.system_program.key,
390 false,
391 ));
392 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
393 *self.token_program.key,
394 false,
395 ));
396 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
397 *self.rent.key,
398 false,
399 ));
400 remaining_accounts.iter().for_each(|remaining_account| {
401 accounts.push(solana_program::instruction::AccountMeta {
402 pubkey: *remaining_account.0.key,
403 is_signer: remaining_account.1,
404 is_writable: remaining_account.2,
405 })
406 });
407 let mut data = borsh::to_vec(&AddPoolInstructionData::new()).unwrap();
408 let mut args = borsh::to_vec(&self.__args).unwrap();
409 data.append(&mut args);
410
411 let instruction = solana_program::instruction::Instruction {
412 program_id: crate::PERPETUALS_ID,
413 accounts,
414 data,
415 };
416 let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
417 account_infos.push(self.__program.clone());
418 account_infos.push(self.admin.clone());
419 account_infos.push(self.transfer_authority.clone());
420 account_infos.push(self.perpetuals.clone());
421 account_infos.push(self.pool.clone());
422 account_infos.push(self.lp_token_mint.clone());
423 account_infos.push(self.system_program.clone());
424 account_infos.push(self.token_program.clone());
425 account_infos.push(self.rent.clone());
426 remaining_accounts
427 .iter()
428 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
429
430 if signers_seeds.is_empty() {
431 solana_program::program::invoke(&instruction, &account_infos)
432 } else {
433 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
434 }
435 }
436}
437
438#[derive(Clone, Debug)]
451pub struct AddPoolCpiBuilder<'a, 'b> {
452 instruction: Box<AddPoolCpiBuilderInstruction<'a, 'b>>,
453}
454
455impl<'a, 'b> AddPoolCpiBuilder<'a, 'b> {
456 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
457 let instruction = Box::new(AddPoolCpiBuilderInstruction {
458 __program: program,
459 admin: None,
460 transfer_authority: None,
461 perpetuals: None,
462 pool: None,
463 lp_token_mint: None,
464 system_program: None,
465 token_program: None,
466 rent: None,
467 name: None,
468 limit: None,
469 fees: None,
470 max_request_execution_sec: None,
471 __remaining_accounts: Vec::new(),
472 });
473 Self { instruction }
474 }
475 #[inline(always)]
476 pub fn admin(&mut self, admin: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
477 self.instruction.admin = Some(admin);
478 self
479 }
480 #[inline(always)]
481 pub fn transfer_authority(
482 &mut self,
483 transfer_authority: &'b solana_program::account_info::AccountInfo<'a>,
484 ) -> &mut Self {
485 self.instruction.transfer_authority = Some(transfer_authority);
486 self
487 }
488 #[inline(always)]
489 pub fn perpetuals(
490 &mut self,
491 perpetuals: &'b solana_program::account_info::AccountInfo<'a>,
492 ) -> &mut Self {
493 self.instruction.perpetuals = Some(perpetuals);
494 self
495 }
496 #[inline(always)]
497 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
498 self.instruction.pool = Some(pool);
499 self
500 }
501 #[inline(always)]
502 pub fn lp_token_mint(
503 &mut self,
504 lp_token_mint: &'b solana_program::account_info::AccountInfo<'a>,
505 ) -> &mut Self {
506 self.instruction.lp_token_mint = Some(lp_token_mint);
507 self
508 }
509 #[inline(always)]
510 pub fn system_program(
511 &mut self,
512 system_program: &'b solana_program::account_info::AccountInfo<'a>,
513 ) -> &mut Self {
514 self.instruction.system_program = Some(system_program);
515 self
516 }
517 #[inline(always)]
518 pub fn token_program(
519 &mut self,
520 token_program: &'b solana_program::account_info::AccountInfo<'a>,
521 ) -> &mut Self {
522 self.instruction.token_program = Some(token_program);
523 self
524 }
525 #[inline(always)]
526 pub fn rent(&mut self, rent: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
527 self.instruction.rent = Some(rent);
528 self
529 }
530 #[inline(always)]
531 pub fn name(&mut self, name: String) -> &mut Self {
532 self.instruction.name = Some(name);
533 self
534 }
535 #[inline(always)]
536 pub fn limit(&mut self, limit: Limit) -> &mut Self {
537 self.instruction.limit = Some(limit);
538 self
539 }
540 #[inline(always)]
541 pub fn fees(&mut self, fees: Fees) -> &mut Self {
542 self.instruction.fees = Some(fees);
543 self
544 }
545 #[inline(always)]
546 pub fn max_request_execution_sec(&mut self, max_request_execution_sec: i64) -> &mut Self {
547 self.instruction.max_request_execution_sec = Some(max_request_execution_sec);
548 self
549 }
550 #[inline(always)]
552 pub fn add_remaining_account(
553 &mut self,
554 account: &'b solana_program::account_info::AccountInfo<'a>,
555 is_writable: bool,
556 is_signer: bool,
557 ) -> &mut Self {
558 self.instruction
559 .__remaining_accounts
560 .push((account, is_writable, is_signer));
561 self
562 }
563 #[inline(always)]
568 pub fn add_remaining_accounts(
569 &mut self,
570 accounts: &[(
571 &'b solana_program::account_info::AccountInfo<'a>,
572 bool,
573 bool,
574 )],
575 ) -> &mut Self {
576 self.instruction
577 .__remaining_accounts
578 .extend_from_slice(accounts);
579 self
580 }
581 #[inline(always)]
582 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
583 self.invoke_signed(&[])
584 }
585 #[allow(clippy::clone_on_copy)]
586 #[allow(clippy::vec_init_then_push)]
587 pub fn invoke_signed(
588 &self,
589 signers_seeds: &[&[&[u8]]],
590 ) -> solana_program::entrypoint::ProgramResult {
591 let args = AddPoolInstructionArgs {
592 name: self.instruction.name.clone().expect("name is not set"),
593 limit: self.instruction.limit.clone().expect("limit is not set"),
594 fees: self.instruction.fees.clone().expect("fees is not set"),
595 max_request_execution_sec: self
596 .instruction
597 .max_request_execution_sec
598 .clone()
599 .expect("max_request_execution_sec is not set"),
600 };
601 let instruction = AddPoolCpi {
602 __program: self.instruction.__program,
603
604 admin: self.instruction.admin.expect("admin is not set"),
605
606 transfer_authority: self
607 .instruction
608 .transfer_authority
609 .expect("transfer_authority is not set"),
610
611 perpetuals: self.instruction.perpetuals.expect("perpetuals is not set"),
612
613 pool: self.instruction.pool.expect("pool is not set"),
614
615 lp_token_mint: self
616 .instruction
617 .lp_token_mint
618 .expect("lp_token_mint is not set"),
619
620 system_program: self
621 .instruction
622 .system_program
623 .expect("system_program is not set"),
624
625 token_program: self
626 .instruction
627 .token_program
628 .expect("token_program is not set"),
629
630 rent: self.instruction.rent.expect("rent is not set"),
631 __args: args,
632 };
633 instruction.invoke_signed_with_remaining_accounts(
634 signers_seeds,
635 &self.instruction.__remaining_accounts,
636 )
637 }
638}
639
640#[derive(Clone, Debug)]
641struct AddPoolCpiBuilderInstruction<'a, 'b> {
642 __program: &'b solana_program::account_info::AccountInfo<'a>,
643 admin: Option<&'b solana_program::account_info::AccountInfo<'a>>,
644 transfer_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
645 perpetuals: Option<&'b solana_program::account_info::AccountInfo<'a>>,
646 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
647 lp_token_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
648 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
649 token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
650 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
651 name: Option<String>,
652 limit: Option<Limit>,
653 fees: Option<Fees>,
654 max_request_execution_sec: Option<i64>,
655 __remaining_accounts: Vec<(
657 &'b solana_program::account_info::AccountInfo<'a>,
658 bool,
659 bool,
660 )>,
661}