1use borsh::{BorshDeserialize, BorshSerialize};
8
9pub const MARKET_INITIALIZE_DISCRIMINATOR: u8 = 8;
10
11#[derive(Debug)]
13pub struct MarketInitialize {
14 pub authority: solana_pubkey::Pubkey,
16 pub market: solana_pubkey::Pubkey,
18 pub mint_a: solana_pubkey::Pubkey,
20 pub mint_b: solana_pubkey::Pubkey,
22 pub market_a: solana_pubkey::Pubkey,
24 pub market_b: solana_pubkey::Pubkey,
26 pub system_program: solana_pubkey::Pubkey,
28 pub ata_program: solana_pubkey::Pubkey,
30 pub token_program_a: solana_pubkey::Pubkey,
32 pub token_program_b: solana_pubkey::Pubkey,
34}
35
36impl MarketInitialize {
37 pub fn instruction(
38 &self,
39 args: MarketInitializeInstructionArgs,
40 ) -> solana_instruction::Instruction {
41 self.instruction_with_remaining_accounts(args, &[])
42 }
43 #[allow(clippy::arithmetic_side_effects)]
44 #[allow(clippy::vec_init_then_push)]
45 pub fn instruction_with_remaining_accounts(
46 &self,
47 args: MarketInitializeInstructionArgs,
48 remaining_accounts: &[solana_instruction::AccountMeta],
49 ) -> solana_instruction::Instruction {
50 let mut accounts = Vec::with_capacity(10 + remaining_accounts.len());
51 accounts.push(solana_instruction::AccountMeta::new(self.authority, true));
52 accounts.push(solana_instruction::AccountMeta::new(self.market, false));
53 accounts.push(solana_instruction::AccountMeta::new_readonly(
54 self.mint_a,
55 false,
56 ));
57 accounts.push(solana_instruction::AccountMeta::new_readonly(
58 self.mint_b,
59 false,
60 ));
61 accounts.push(solana_instruction::AccountMeta::new(self.market_a, false));
62 accounts.push(solana_instruction::AccountMeta::new(self.market_b, false));
63 accounts.push(solana_instruction::AccountMeta::new_readonly(
64 self.system_program,
65 false,
66 ));
67 accounts.push(solana_instruction::AccountMeta::new_readonly(
68 self.ata_program,
69 false,
70 ));
71 accounts.push(solana_instruction::AccountMeta::new_readonly(
72 self.token_program_a,
73 false,
74 ));
75 accounts.push(solana_instruction::AccountMeta::new_readonly(
76 self.token_program_b,
77 false,
78 ));
79 accounts.extend_from_slice(remaining_accounts);
80 let mut data = MarketInitializeInstructionData::new().try_to_vec().unwrap();
81 let mut args = args.try_to_vec().unwrap();
82 data.append(&mut args);
83
84 solana_instruction::Instruction {
85 program_id: crate::RIPTIDE_ID,
86 accounts,
87 data,
88 }
89 }
90}
91
92#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
93#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
94pub struct MarketInitializeInstructionData {
95 discriminator: u8,
96}
97
98impl MarketInitializeInstructionData {
99 pub fn new() -> Self {
100 Self { discriminator: 8 }
101 }
102
103 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
104 borsh::to_vec(self)
105 }
106}
107
108impl Default for MarketInitializeInstructionData {
109 fn default() -> Self {
110 Self::new()
111 }
112}
113
114#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
115#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
116pub struct MarketInitializeInstructionArgs {
117 pub market_id: u32,
118}
119
120impl MarketInitializeInstructionArgs {
121 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
122 borsh::to_vec(self)
123 }
124}
125
126#[derive(Clone, Debug, Default)]
141pub struct MarketInitializeBuilder {
142 authority: Option<solana_pubkey::Pubkey>,
143 market: Option<solana_pubkey::Pubkey>,
144 mint_a: Option<solana_pubkey::Pubkey>,
145 mint_b: Option<solana_pubkey::Pubkey>,
146 market_a: Option<solana_pubkey::Pubkey>,
147 market_b: Option<solana_pubkey::Pubkey>,
148 system_program: Option<solana_pubkey::Pubkey>,
149 ata_program: Option<solana_pubkey::Pubkey>,
150 token_program_a: Option<solana_pubkey::Pubkey>,
151 token_program_b: Option<solana_pubkey::Pubkey>,
152 market_id: Option<u32>,
153 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
154}
155
156impl MarketInitializeBuilder {
157 pub fn new() -> Self {
158 Self::default()
159 }
160 #[inline(always)]
162 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
163 self.authority = Some(authority);
164 self
165 }
166 #[inline(always)]
168 pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
169 self.market = Some(market);
170 self
171 }
172 #[inline(always)]
174 pub fn mint_a(&mut self, mint_a: solana_pubkey::Pubkey) -> &mut Self {
175 self.mint_a = Some(mint_a);
176 self
177 }
178 #[inline(always)]
180 pub fn mint_b(&mut self, mint_b: solana_pubkey::Pubkey) -> &mut Self {
181 self.mint_b = Some(mint_b);
182 self
183 }
184 #[inline(always)]
186 pub fn market_a(&mut self, market_a: solana_pubkey::Pubkey) -> &mut Self {
187 self.market_a = Some(market_a);
188 self
189 }
190 #[inline(always)]
192 pub fn market_b(&mut self, market_b: solana_pubkey::Pubkey) -> &mut Self {
193 self.market_b = Some(market_b);
194 self
195 }
196 #[inline(always)]
199 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
200 self.system_program = Some(system_program);
201 self
202 }
203 #[inline(always)]
206 pub fn ata_program(&mut self, ata_program: solana_pubkey::Pubkey) -> &mut Self {
207 self.ata_program = Some(ata_program);
208 self
209 }
210 #[inline(always)]
212 pub fn token_program_a(&mut self, token_program_a: solana_pubkey::Pubkey) -> &mut Self {
213 self.token_program_a = Some(token_program_a);
214 self
215 }
216 #[inline(always)]
218 pub fn token_program_b(&mut self, token_program_b: solana_pubkey::Pubkey) -> &mut Self {
219 self.token_program_b = Some(token_program_b);
220 self
221 }
222 #[inline(always)]
223 pub fn market_id(&mut self, market_id: u32) -> &mut Self {
224 self.market_id = Some(market_id);
225 self
226 }
227 #[inline(always)]
229 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
230 self.__remaining_accounts.push(account);
231 self
232 }
233 #[inline(always)]
235 pub fn add_remaining_accounts(
236 &mut self,
237 accounts: &[solana_instruction::AccountMeta],
238 ) -> &mut Self {
239 self.__remaining_accounts.extend_from_slice(accounts);
240 self
241 }
242 #[allow(clippy::clone_on_copy)]
243 pub fn instruction(&self) -> solana_instruction::Instruction {
244 let accounts = MarketInitialize {
245 authority: self.authority.expect("authority is not set"),
246 market: self.market.expect("market is not set"),
247 mint_a: self.mint_a.expect("mint_a is not set"),
248 mint_b: self.mint_b.expect("mint_b is not set"),
249 market_a: self.market_a.expect("market_a is not set"),
250 market_b: self.market_b.expect("market_b is not set"),
251 system_program: self
252 .system_program
253 .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
254 ata_program: self.ata_program.unwrap_or(solana_pubkey::pubkey!(
255 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
256 )),
257 token_program_a: self.token_program_a.expect("token_program_a is not set"),
258 token_program_b: self.token_program_b.expect("token_program_b is not set"),
259 };
260 let args = MarketInitializeInstructionArgs {
261 market_id: self.market_id.clone().expect("market_id is not set"),
262 };
263
264 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
265 }
266}
267
268pub struct MarketInitializeCpiAccounts<'a, 'b> {
270 pub authority: &'b solana_account_info::AccountInfo<'a>,
272 pub market: &'b solana_account_info::AccountInfo<'a>,
274 pub mint_a: &'b solana_account_info::AccountInfo<'a>,
276 pub mint_b: &'b solana_account_info::AccountInfo<'a>,
278 pub market_a: &'b solana_account_info::AccountInfo<'a>,
280 pub market_b: &'b solana_account_info::AccountInfo<'a>,
282 pub system_program: &'b solana_account_info::AccountInfo<'a>,
284 pub ata_program: &'b solana_account_info::AccountInfo<'a>,
286 pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
288 pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
290}
291
292pub struct MarketInitializeCpi<'a, 'b> {
294 pub __program: &'b solana_account_info::AccountInfo<'a>,
296 pub authority: &'b solana_account_info::AccountInfo<'a>,
298 pub market: &'b solana_account_info::AccountInfo<'a>,
300 pub mint_a: &'b solana_account_info::AccountInfo<'a>,
302 pub mint_b: &'b solana_account_info::AccountInfo<'a>,
304 pub market_a: &'b solana_account_info::AccountInfo<'a>,
306 pub market_b: &'b solana_account_info::AccountInfo<'a>,
308 pub system_program: &'b solana_account_info::AccountInfo<'a>,
310 pub ata_program: &'b solana_account_info::AccountInfo<'a>,
312 pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
314 pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
316 pub __args: MarketInitializeInstructionArgs,
318}
319
320impl<'a, 'b> MarketInitializeCpi<'a, 'b> {
321 pub fn new(
322 program: &'b solana_account_info::AccountInfo<'a>,
323 accounts: MarketInitializeCpiAccounts<'a, 'b>,
324 args: MarketInitializeInstructionArgs,
325 ) -> Self {
326 Self {
327 __program: program,
328 authority: accounts.authority,
329 market: accounts.market,
330 mint_a: accounts.mint_a,
331 mint_b: accounts.mint_b,
332 market_a: accounts.market_a,
333 market_b: accounts.market_b,
334 system_program: accounts.system_program,
335 ata_program: accounts.ata_program,
336 token_program_a: accounts.token_program_a,
337 token_program_b: accounts.token_program_b,
338 __args: args,
339 }
340 }
341 #[inline(always)]
342 pub fn invoke(&self) -> solana_program_error::ProgramResult {
343 self.invoke_signed_with_remaining_accounts(&[], &[])
344 }
345 #[inline(always)]
346 pub fn invoke_with_remaining_accounts(
347 &self,
348 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
349 ) -> solana_program_error::ProgramResult {
350 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
351 }
352 #[inline(always)]
353 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
354 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
355 }
356 #[allow(clippy::arithmetic_side_effects)]
357 #[allow(clippy::clone_on_copy)]
358 #[allow(clippy::vec_init_then_push)]
359 pub fn invoke_signed_with_remaining_accounts(
360 &self,
361 signers_seeds: &[&[&[u8]]],
362 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
363 ) -> solana_program_error::ProgramResult {
364 let mut accounts = Vec::with_capacity(10 + remaining_accounts.len());
365 accounts.push(solana_instruction::AccountMeta::new(
366 *self.authority.key,
367 true,
368 ));
369 accounts.push(solana_instruction::AccountMeta::new(
370 *self.market.key,
371 false,
372 ));
373 accounts.push(solana_instruction::AccountMeta::new_readonly(
374 *self.mint_a.key,
375 false,
376 ));
377 accounts.push(solana_instruction::AccountMeta::new_readonly(
378 *self.mint_b.key,
379 false,
380 ));
381 accounts.push(solana_instruction::AccountMeta::new(
382 *self.market_a.key,
383 false,
384 ));
385 accounts.push(solana_instruction::AccountMeta::new(
386 *self.market_b.key,
387 false,
388 ));
389 accounts.push(solana_instruction::AccountMeta::new_readonly(
390 *self.system_program.key,
391 false,
392 ));
393 accounts.push(solana_instruction::AccountMeta::new_readonly(
394 *self.ata_program.key,
395 false,
396 ));
397 accounts.push(solana_instruction::AccountMeta::new_readonly(
398 *self.token_program_a.key,
399 false,
400 ));
401 accounts.push(solana_instruction::AccountMeta::new_readonly(
402 *self.token_program_b.key,
403 false,
404 ));
405 remaining_accounts.iter().for_each(|remaining_account| {
406 accounts.push(solana_instruction::AccountMeta {
407 pubkey: *remaining_account.0.key,
408 is_signer: remaining_account.1,
409 is_writable: remaining_account.2,
410 })
411 });
412 let mut data = MarketInitializeInstructionData::new().try_to_vec().unwrap();
413 let mut args = self.__args.try_to_vec().unwrap();
414 data.append(&mut args);
415
416 let instruction = solana_instruction::Instruction {
417 program_id: crate::RIPTIDE_ID,
418 accounts,
419 data,
420 };
421 let mut account_infos = Vec::with_capacity(11 + remaining_accounts.len());
422 account_infos.push(self.__program.clone());
423 account_infos.push(self.authority.clone());
424 account_infos.push(self.market.clone());
425 account_infos.push(self.mint_a.clone());
426 account_infos.push(self.mint_b.clone());
427 account_infos.push(self.market_a.clone());
428 account_infos.push(self.market_b.clone());
429 account_infos.push(self.system_program.clone());
430 account_infos.push(self.ata_program.clone());
431 account_infos.push(self.token_program_a.clone());
432 account_infos.push(self.token_program_b.clone());
433 remaining_accounts
434 .iter()
435 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
436
437 if signers_seeds.is_empty() {
438 solana_cpi::invoke(&instruction, &account_infos)
439 } else {
440 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
441 }
442 }
443}
444
445#[derive(Clone, Debug)]
460pub struct MarketInitializeCpiBuilder<'a, 'b> {
461 instruction: Box<MarketInitializeCpiBuilderInstruction<'a, 'b>>,
462}
463
464impl<'a, 'b> MarketInitializeCpiBuilder<'a, 'b> {
465 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
466 let instruction = Box::new(MarketInitializeCpiBuilderInstruction {
467 __program: program,
468 authority: None,
469 market: None,
470 mint_a: None,
471 mint_b: None,
472 market_a: None,
473 market_b: None,
474 system_program: None,
475 ata_program: None,
476 token_program_a: None,
477 token_program_b: None,
478 market_id: None,
479 __remaining_accounts: Vec::new(),
480 });
481 Self { instruction }
482 }
483 #[inline(always)]
485 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
486 self.instruction.authority = Some(authority);
487 self
488 }
489 #[inline(always)]
491 pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
492 self.instruction.market = Some(market);
493 self
494 }
495 #[inline(always)]
497 pub fn mint_a(&mut self, mint_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
498 self.instruction.mint_a = Some(mint_a);
499 self
500 }
501 #[inline(always)]
503 pub fn mint_b(&mut self, mint_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
504 self.instruction.mint_b = Some(mint_b);
505 self
506 }
507 #[inline(always)]
509 pub fn market_a(&mut self, market_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
510 self.instruction.market_a = Some(market_a);
511 self
512 }
513 #[inline(always)]
515 pub fn market_b(&mut self, market_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
516 self.instruction.market_b = Some(market_b);
517 self
518 }
519 #[inline(always)]
521 pub fn system_program(
522 &mut self,
523 system_program: &'b solana_account_info::AccountInfo<'a>,
524 ) -> &mut Self {
525 self.instruction.system_program = Some(system_program);
526 self
527 }
528 #[inline(always)]
530 pub fn ata_program(
531 &mut self,
532 ata_program: &'b solana_account_info::AccountInfo<'a>,
533 ) -> &mut Self {
534 self.instruction.ata_program = Some(ata_program);
535 self
536 }
537 #[inline(always)]
539 pub fn token_program_a(
540 &mut self,
541 token_program_a: &'b solana_account_info::AccountInfo<'a>,
542 ) -> &mut Self {
543 self.instruction.token_program_a = Some(token_program_a);
544 self
545 }
546 #[inline(always)]
548 pub fn token_program_b(
549 &mut self,
550 token_program_b: &'b solana_account_info::AccountInfo<'a>,
551 ) -> &mut Self {
552 self.instruction.token_program_b = Some(token_program_b);
553 self
554 }
555 #[inline(always)]
556 pub fn market_id(&mut self, market_id: u32) -> &mut Self {
557 self.instruction.market_id = Some(market_id);
558 self
559 }
560 #[inline(always)]
562 pub fn add_remaining_account(
563 &mut self,
564 account: &'b solana_account_info::AccountInfo<'a>,
565 is_writable: bool,
566 is_signer: bool,
567 ) -> &mut Self {
568 self.instruction
569 .__remaining_accounts
570 .push((account, is_writable, is_signer));
571 self
572 }
573 #[inline(always)]
579 pub fn add_remaining_accounts(
580 &mut self,
581 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
582 ) -> &mut Self {
583 self.instruction
584 .__remaining_accounts
585 .extend_from_slice(accounts);
586 self
587 }
588 #[inline(always)]
589 pub fn invoke(&self) -> solana_program_error::ProgramResult {
590 self.invoke_signed(&[])
591 }
592 #[allow(clippy::clone_on_copy)]
593 #[allow(clippy::vec_init_then_push)]
594 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
595 let args = MarketInitializeInstructionArgs {
596 market_id: self
597 .instruction
598 .market_id
599 .clone()
600 .expect("market_id is not set"),
601 };
602 let instruction = MarketInitializeCpi {
603 __program: self.instruction.__program,
604
605 authority: self.instruction.authority.expect("authority is not set"),
606
607 market: self.instruction.market.expect("market is not set"),
608
609 mint_a: self.instruction.mint_a.expect("mint_a is not set"),
610
611 mint_b: self.instruction.mint_b.expect("mint_b is not set"),
612
613 market_a: self.instruction.market_a.expect("market_a is not set"),
614
615 market_b: self.instruction.market_b.expect("market_b is not set"),
616
617 system_program: self
618 .instruction
619 .system_program
620 .expect("system_program is not set"),
621
622 ata_program: self
623 .instruction
624 .ata_program
625 .expect("ata_program is not set"),
626
627 token_program_a: self
628 .instruction
629 .token_program_a
630 .expect("token_program_a is not set"),
631
632 token_program_b: self
633 .instruction
634 .token_program_b
635 .expect("token_program_b is not set"),
636 __args: args,
637 };
638 instruction.invoke_signed_with_remaining_accounts(
639 signers_seeds,
640 &self.instruction.__remaining_accounts,
641 )
642 }
643}
644
645#[derive(Clone, Debug)]
646struct MarketInitializeCpiBuilderInstruction<'a, 'b> {
647 __program: &'b solana_account_info::AccountInfo<'a>,
648 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
649 market: Option<&'b solana_account_info::AccountInfo<'a>>,
650 mint_a: Option<&'b solana_account_info::AccountInfo<'a>>,
651 mint_b: Option<&'b solana_account_info::AccountInfo<'a>>,
652 market_a: Option<&'b solana_account_info::AccountInfo<'a>>,
653 market_b: Option<&'b solana_account_info::AccountInfo<'a>>,
654 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
655 ata_program: Option<&'b solana_account_info::AccountInfo<'a>>,
656 token_program_a: Option<&'b solana_account_info::AccountInfo<'a>>,
657 token_program_b: Option<&'b solana_account_info::AccountInfo<'a>>,
658 market_id: Option<u32>,
659 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
661}