Skip to main content

riptide_amm/generated/instructions/
market_initialize.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
7use borsh::{BorshDeserialize, BorshSerialize};
8
9pub const MARKET_INITIALIZE_DISCRIMINATOR: u8 = 8;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct MarketInitialize {
14    /// The authority
15    pub authority: solana_address::Address,
16    /// The market
17    pub market: solana_address::Address,
18    /// The token a mint
19    pub mint_a: solana_address::Address,
20    /// The token b mint
21    pub mint_b: solana_address::Address,
22    /// The market token account for token a
23    pub market_a: solana_address::Address,
24    /// The market token account for token b
25    pub market_b: solana_address::Address,
26    /// The system program
27    pub system_program: solana_address::Address,
28    /// The ata program
29    pub ata_program: solana_address::Address,
30    /// The token program for token a
31    pub token_program_a: solana_address::Address,
32    /// The token program for token b
33    pub token_program_b: solana_address::Address,
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)]
93pub struct MarketInitializeInstructionData {
94    discriminator: u8,
95}
96
97impl MarketInitializeInstructionData {
98    pub fn new() -> Self {
99        Self { discriminator: 8 }
100    }
101
102    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
103        borsh::to_vec(self)
104    }
105}
106
107impl Default for MarketInitializeInstructionData {
108    fn default() -> Self {
109        Self::new()
110    }
111}
112
113#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
114pub struct MarketInitializeInstructionArgs {
115    pub market_id: u32,
116}
117
118impl MarketInitializeInstructionArgs {
119    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
120        borsh::to_vec(self)
121    }
122}
123
124/// Instruction builder for `MarketInitialize`.
125///
126/// ### Accounts:
127///
128///   0. `[writable, signer]` authority
129///   1. `[writable]` market
130///   2. `[]` mint_a
131///   3. `[]` mint_b
132///   4. `[writable]` market_a
133///   5. `[writable]` market_b
134///   6. `[optional]` system_program (default to `11111111111111111111111111111111`)
135///   7. `[optional]` ata_program (default to `ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`)
136///   8. `[]` token_program_a
137///   9. `[]` token_program_b
138#[derive(Clone, Debug, Default)]
139pub struct MarketInitializeBuilder {
140    authority: Option<solana_address::Address>,
141    market: Option<solana_address::Address>,
142    mint_a: Option<solana_address::Address>,
143    mint_b: Option<solana_address::Address>,
144    market_a: Option<solana_address::Address>,
145    market_b: Option<solana_address::Address>,
146    system_program: Option<solana_address::Address>,
147    ata_program: Option<solana_address::Address>,
148    token_program_a: Option<solana_address::Address>,
149    token_program_b: Option<solana_address::Address>,
150    market_id: Option<u32>,
151    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
152}
153
154impl MarketInitializeBuilder {
155    pub fn new() -> Self {
156        Self::default()
157    }
158    /// The authority
159    #[inline(always)]
160    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
161        self.authority = Some(authority);
162        self
163    }
164    /// The market
165    #[inline(always)]
166    pub fn market(&mut self, market: solana_address::Address) -> &mut Self {
167        self.market = Some(market);
168        self
169    }
170    /// The token a mint
171    #[inline(always)]
172    pub fn mint_a(&mut self, mint_a: solana_address::Address) -> &mut Self {
173        self.mint_a = Some(mint_a);
174        self
175    }
176    /// The token b mint
177    #[inline(always)]
178    pub fn mint_b(&mut self, mint_b: solana_address::Address) -> &mut Self {
179        self.mint_b = Some(mint_b);
180        self
181    }
182    /// The market token account for token a
183    #[inline(always)]
184    pub fn market_a(&mut self, market_a: solana_address::Address) -> &mut Self {
185        self.market_a = Some(market_a);
186        self
187    }
188    /// The market token account for token b
189    #[inline(always)]
190    pub fn market_b(&mut self, market_b: solana_address::Address) -> &mut Self {
191        self.market_b = Some(market_b);
192        self
193    }
194    /// `[optional account, default to '11111111111111111111111111111111']`
195    /// The system program
196    #[inline(always)]
197    pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
198        self.system_program = Some(system_program);
199        self
200    }
201    /// `[optional account, default to 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL']`
202    /// The ata program
203    #[inline(always)]
204    pub fn ata_program(&mut self, ata_program: solana_address::Address) -> &mut Self {
205        self.ata_program = Some(ata_program);
206        self
207    }
208    /// The token program for token a
209    #[inline(always)]
210    pub fn token_program_a(&mut self, token_program_a: solana_address::Address) -> &mut Self {
211        self.token_program_a = Some(token_program_a);
212        self
213    }
214    /// The token program for token b
215    #[inline(always)]
216    pub fn token_program_b(&mut self, token_program_b: solana_address::Address) -> &mut Self {
217        self.token_program_b = Some(token_program_b);
218        self
219    }
220    #[inline(always)]
221    pub fn market_id(&mut self, market_id: u32) -> &mut Self {
222        self.market_id = Some(market_id);
223        self
224    }
225    /// Add an additional account to the instruction.
226    #[inline(always)]
227    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
228        self.__remaining_accounts.push(account);
229        self
230    }
231    /// Add additional accounts to the instruction.
232    #[inline(always)]
233    pub fn add_remaining_accounts(
234        &mut self,
235        accounts: &[solana_instruction::AccountMeta],
236    ) -> &mut Self {
237        self.__remaining_accounts.extend_from_slice(accounts);
238        self
239    }
240    #[allow(clippy::clone_on_copy)]
241    pub fn instruction(&self) -> solana_instruction::Instruction {
242        let accounts = MarketInitialize {
243            authority: self.authority.expect("authority is not set"),
244            market: self.market.expect("market is not set"),
245            mint_a: self.mint_a.expect("mint_a is not set"),
246            mint_b: self.mint_b.expect("mint_b is not set"),
247            market_a: self.market_a.expect("market_a is not set"),
248            market_b: self.market_b.expect("market_b is not set"),
249            system_program: self
250                .system_program
251                .unwrap_or(solana_address::address!("11111111111111111111111111111111")),
252            ata_program: self.ata_program.unwrap_or(solana_address::address!(
253                "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
254            )),
255            token_program_a: self.token_program_a.expect("token_program_a is not set"),
256            token_program_b: self.token_program_b.expect("token_program_b is not set"),
257        };
258        let args = MarketInitializeInstructionArgs {
259            market_id: self.market_id.clone().expect("market_id is not set"),
260        };
261
262        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
263    }
264}
265
266/// `market_initialize` CPI accounts.
267pub struct MarketInitializeCpiAccounts<'a, 'b> {
268    /// The authority
269    pub authority: &'b solana_account_info::AccountInfo<'a>,
270    /// The market
271    pub market: &'b solana_account_info::AccountInfo<'a>,
272    /// The token a mint
273    pub mint_a: &'b solana_account_info::AccountInfo<'a>,
274    /// The token b mint
275    pub mint_b: &'b solana_account_info::AccountInfo<'a>,
276    /// The market token account for token a
277    pub market_a: &'b solana_account_info::AccountInfo<'a>,
278    /// The market token account for token b
279    pub market_b: &'b solana_account_info::AccountInfo<'a>,
280    /// The system program
281    pub system_program: &'b solana_account_info::AccountInfo<'a>,
282    /// The ata program
283    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
284    /// The token program for token a
285    pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
286    /// The token program for token b
287    pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
288}
289
290/// `market_initialize` CPI instruction.
291pub struct MarketInitializeCpi<'a, 'b> {
292    /// The program to invoke.
293    pub __program: &'b solana_account_info::AccountInfo<'a>,
294    /// The authority
295    pub authority: &'b solana_account_info::AccountInfo<'a>,
296    /// The market
297    pub market: &'b solana_account_info::AccountInfo<'a>,
298    /// The token a mint
299    pub mint_a: &'b solana_account_info::AccountInfo<'a>,
300    /// The token b mint
301    pub mint_b: &'b solana_account_info::AccountInfo<'a>,
302    /// The market token account for token a
303    pub market_a: &'b solana_account_info::AccountInfo<'a>,
304    /// The market token account for token b
305    pub market_b: &'b solana_account_info::AccountInfo<'a>,
306    /// The system program
307    pub system_program: &'b solana_account_info::AccountInfo<'a>,
308    /// The ata program
309    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
310    /// The token program for token a
311    pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
312    /// The token program for token b
313    pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
314    /// The arguments for the instruction.
315    pub __args: MarketInitializeInstructionArgs,
316}
317
318impl<'a, 'b> MarketInitializeCpi<'a, 'b> {
319    pub fn new(
320        program: &'b solana_account_info::AccountInfo<'a>,
321        accounts: MarketInitializeCpiAccounts<'a, 'b>,
322        args: MarketInitializeInstructionArgs,
323    ) -> Self {
324        Self {
325            __program: program,
326            authority: accounts.authority,
327            market: accounts.market,
328            mint_a: accounts.mint_a,
329            mint_b: accounts.mint_b,
330            market_a: accounts.market_a,
331            market_b: accounts.market_b,
332            system_program: accounts.system_program,
333            ata_program: accounts.ata_program,
334            token_program_a: accounts.token_program_a,
335            token_program_b: accounts.token_program_b,
336            __args: args,
337        }
338    }
339    #[inline(always)]
340    pub fn invoke(&self) -> solana_program_error::ProgramResult {
341        self.invoke_signed_with_remaining_accounts(&[], &[])
342    }
343    #[inline(always)]
344    pub fn invoke_with_remaining_accounts(
345        &self,
346        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
347    ) -> solana_program_error::ProgramResult {
348        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
349    }
350    #[inline(always)]
351    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
352        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
353    }
354    #[allow(clippy::arithmetic_side_effects)]
355    #[allow(clippy::clone_on_copy)]
356    #[allow(clippy::vec_init_then_push)]
357    pub fn invoke_signed_with_remaining_accounts(
358        &self,
359        signers_seeds: &[&[&[u8]]],
360        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
361    ) -> solana_program_error::ProgramResult {
362        let mut accounts = Vec::with_capacity(10 + remaining_accounts.len());
363        accounts.push(solana_instruction::AccountMeta::new(
364            *self.authority.key,
365            true,
366        ));
367        accounts.push(solana_instruction::AccountMeta::new(
368            *self.market.key,
369            false,
370        ));
371        accounts.push(solana_instruction::AccountMeta::new_readonly(
372            *self.mint_a.key,
373            false,
374        ));
375        accounts.push(solana_instruction::AccountMeta::new_readonly(
376            *self.mint_b.key,
377            false,
378        ));
379        accounts.push(solana_instruction::AccountMeta::new(
380            *self.market_a.key,
381            false,
382        ));
383        accounts.push(solana_instruction::AccountMeta::new(
384            *self.market_b.key,
385            false,
386        ));
387        accounts.push(solana_instruction::AccountMeta::new_readonly(
388            *self.system_program.key,
389            false,
390        ));
391        accounts.push(solana_instruction::AccountMeta::new_readonly(
392            *self.ata_program.key,
393            false,
394        ));
395        accounts.push(solana_instruction::AccountMeta::new_readonly(
396            *self.token_program_a.key,
397            false,
398        ));
399        accounts.push(solana_instruction::AccountMeta::new_readonly(
400            *self.token_program_b.key,
401            false,
402        ));
403        remaining_accounts.iter().for_each(|remaining_account| {
404            accounts.push(solana_instruction::AccountMeta {
405                pubkey: *remaining_account.0.key,
406                is_signer: remaining_account.1,
407                is_writable: remaining_account.2,
408            })
409        });
410        let mut data = MarketInitializeInstructionData::new().try_to_vec().unwrap();
411        let mut args = self.__args.try_to_vec().unwrap();
412        data.append(&mut args);
413
414        let instruction = solana_instruction::Instruction {
415            program_id: crate::RIPTIDE_ID,
416            accounts,
417            data,
418        };
419        let mut account_infos = Vec::with_capacity(11 + remaining_accounts.len());
420        account_infos.push(self.__program.clone());
421        account_infos.push(self.authority.clone());
422        account_infos.push(self.market.clone());
423        account_infos.push(self.mint_a.clone());
424        account_infos.push(self.mint_b.clone());
425        account_infos.push(self.market_a.clone());
426        account_infos.push(self.market_b.clone());
427        account_infos.push(self.system_program.clone());
428        account_infos.push(self.ata_program.clone());
429        account_infos.push(self.token_program_a.clone());
430        account_infos.push(self.token_program_b.clone());
431        remaining_accounts
432            .iter()
433            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
434
435        if signers_seeds.is_empty() {
436            solana_cpi::invoke(&instruction, &account_infos)
437        } else {
438            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
439        }
440    }
441}
442
443/// Instruction builder for `MarketInitialize` via CPI.
444///
445/// ### Accounts:
446///
447///   0. `[writable, signer]` authority
448///   1. `[writable]` market
449///   2. `[]` mint_a
450///   3. `[]` mint_b
451///   4. `[writable]` market_a
452///   5. `[writable]` market_b
453///   6. `[]` system_program
454///   7. `[]` ata_program
455///   8. `[]` token_program_a
456///   9. `[]` token_program_b
457#[derive(Clone, Debug)]
458pub struct MarketInitializeCpiBuilder<'a, 'b> {
459    instruction: Box<MarketInitializeCpiBuilderInstruction<'a, 'b>>,
460}
461
462impl<'a, 'b> MarketInitializeCpiBuilder<'a, 'b> {
463    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
464        let instruction = Box::new(MarketInitializeCpiBuilderInstruction {
465            __program: program,
466            authority: None,
467            market: None,
468            mint_a: None,
469            mint_b: None,
470            market_a: None,
471            market_b: None,
472            system_program: None,
473            ata_program: None,
474            token_program_a: None,
475            token_program_b: None,
476            market_id: None,
477            __remaining_accounts: Vec::new(),
478        });
479        Self { instruction }
480    }
481    /// The authority
482    #[inline(always)]
483    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
484        self.instruction.authority = Some(authority);
485        self
486    }
487    /// The market
488    #[inline(always)]
489    pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
490        self.instruction.market = Some(market);
491        self
492    }
493    /// The token a mint
494    #[inline(always)]
495    pub fn mint_a(&mut self, mint_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
496        self.instruction.mint_a = Some(mint_a);
497        self
498    }
499    /// The token b mint
500    #[inline(always)]
501    pub fn mint_b(&mut self, mint_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
502        self.instruction.mint_b = Some(mint_b);
503        self
504    }
505    /// The market token account for token a
506    #[inline(always)]
507    pub fn market_a(&mut self, market_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
508        self.instruction.market_a = Some(market_a);
509        self
510    }
511    /// The market token account for token b
512    #[inline(always)]
513    pub fn market_b(&mut self, market_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
514        self.instruction.market_b = Some(market_b);
515        self
516    }
517    /// The system program
518    #[inline(always)]
519    pub fn system_program(
520        &mut self,
521        system_program: &'b solana_account_info::AccountInfo<'a>,
522    ) -> &mut Self {
523        self.instruction.system_program = Some(system_program);
524        self
525    }
526    /// The ata program
527    #[inline(always)]
528    pub fn ata_program(
529        &mut self,
530        ata_program: &'b solana_account_info::AccountInfo<'a>,
531    ) -> &mut Self {
532        self.instruction.ata_program = Some(ata_program);
533        self
534    }
535    /// The token program for token a
536    #[inline(always)]
537    pub fn token_program_a(
538        &mut self,
539        token_program_a: &'b solana_account_info::AccountInfo<'a>,
540    ) -> &mut Self {
541        self.instruction.token_program_a = Some(token_program_a);
542        self
543    }
544    /// The token program for token b
545    #[inline(always)]
546    pub fn token_program_b(
547        &mut self,
548        token_program_b: &'b solana_account_info::AccountInfo<'a>,
549    ) -> &mut Self {
550        self.instruction.token_program_b = Some(token_program_b);
551        self
552    }
553    #[inline(always)]
554    pub fn market_id(&mut self, market_id: u32) -> &mut Self {
555        self.instruction.market_id = Some(market_id);
556        self
557    }
558    /// Add an additional account to the instruction.
559    #[inline(always)]
560    pub fn add_remaining_account(
561        &mut self,
562        account: &'b solana_account_info::AccountInfo<'a>,
563        is_writable: bool,
564        is_signer: bool,
565    ) -> &mut Self {
566        self.instruction
567            .__remaining_accounts
568            .push((account, is_writable, is_signer));
569        self
570    }
571    /// Add additional accounts to the instruction.
572    ///
573    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the
574    /// account is writable or not, and a `bool` indicating whether the account is a signer or
575    /// not.
576    #[inline(always)]
577    pub fn add_remaining_accounts(
578        &mut self,
579        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
580    ) -> &mut Self {
581        self.instruction
582            .__remaining_accounts
583            .extend_from_slice(accounts);
584        self
585    }
586    #[inline(always)]
587    pub fn invoke(&self) -> solana_program_error::ProgramResult {
588        self.invoke_signed(&[])
589    }
590    #[allow(clippy::clone_on_copy)]
591    #[allow(clippy::vec_init_then_push)]
592    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
593        let args = MarketInitializeInstructionArgs {
594            market_id: self
595                .instruction
596                .market_id
597                .clone()
598                .expect("market_id is not set"),
599        };
600        let instruction = MarketInitializeCpi {
601            __program: self.instruction.__program,
602
603            authority: self.instruction.authority.expect("authority is not set"),
604
605            market: self.instruction.market.expect("market is not set"),
606
607            mint_a: self.instruction.mint_a.expect("mint_a is not set"),
608
609            mint_b: self.instruction.mint_b.expect("mint_b is not set"),
610
611            market_a: self.instruction.market_a.expect("market_a is not set"),
612
613            market_b: self.instruction.market_b.expect("market_b is not set"),
614
615            system_program: self
616                .instruction
617                .system_program
618                .expect("system_program is not set"),
619
620            ata_program: self
621                .instruction
622                .ata_program
623                .expect("ata_program is not set"),
624
625            token_program_a: self
626                .instruction
627                .token_program_a
628                .expect("token_program_a is not set"),
629
630            token_program_b: self
631                .instruction
632                .token_program_b
633                .expect("token_program_b is not set"),
634            __args: args,
635        };
636        instruction.invoke_signed_with_remaining_accounts(
637            signers_seeds,
638            &self.instruction.__remaining_accounts,
639        )
640    }
641}
642
643#[derive(Clone, Debug)]
644struct MarketInitializeCpiBuilderInstruction<'a, 'b> {
645    __program: &'b solana_account_info::AccountInfo<'a>,
646    authority: Option<&'b solana_account_info::AccountInfo<'a>>,
647    market: Option<&'b solana_account_info::AccountInfo<'a>>,
648    mint_a: Option<&'b solana_account_info::AccountInfo<'a>>,
649    mint_b: Option<&'b solana_account_info::AccountInfo<'a>>,
650    market_a: Option<&'b solana_account_info::AccountInfo<'a>>,
651    market_b: Option<&'b solana_account_info::AccountInfo<'a>>,
652    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
653    ata_program: Option<&'b solana_account_info::AccountInfo<'a>>,
654    token_program_a: Option<&'b solana_account_info::AccountInfo<'a>>,
655    token_program_b: Option<&'b solana_account_info::AccountInfo<'a>>,
656    market_id: Option<u32>,
657    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
658    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
659}