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