Skip to main content

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