Skip to main content

riptide_amm/generated/instructions/
swap_exact_out.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 crate::generated::types::SlippageTolerance;
8use borsh::{BorshDeserialize, BorshSerialize};
9
10pub const SWAP_EXACT_OUT_DISCRIMINATOR: u8 = 3;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct SwapExactOut {
15    /// The authority
16    pub authority: solana_pubkey::Pubkey,
17    /// The market
18    pub market: solana_pubkey::Pubkey,
19    /// The token a mint
20    pub mint_a: solana_pubkey::Pubkey,
21    /// The token b mint
22    pub mint_b: solana_pubkey::Pubkey,
23    /// The authority's token account for token a
24    pub authority_a: solana_pubkey::Pubkey,
25    /// The authority's token account for token b
26    pub authority_b: solana_pubkey::Pubkey,
27    /// The treasury token account for token a
28    pub market_a: solana_pubkey::Pubkey,
29    /// The treasury token account for token b
30    pub market_b: solana_pubkey::Pubkey,
31    /// The token program for token a
32    pub token_program_a: solana_pubkey::Pubkey,
33    /// The token program for token b
34    pub token_program_b: solana_pubkey::Pubkey,
35    /// The memo program
36    pub memo_program: solana_pubkey::Pubkey,
37    /// The instructions sysvar
38    pub instructions_sysvar: solana_pubkey::Pubkey,
39}
40
41impl SwapExactOut {
42    pub fn instruction(
43        &self,
44        args: SwapExactOutInstructionArgs,
45    ) -> solana_instruction::Instruction {
46        self.instruction_with_remaining_accounts(args, &[])
47    }
48    #[allow(clippy::arithmetic_side_effects)]
49    #[allow(clippy::vec_init_then_push)]
50    pub fn instruction_with_remaining_accounts(
51        &self,
52        args: SwapExactOutInstructionArgs,
53        remaining_accounts: &[solana_instruction::AccountMeta],
54    ) -> solana_instruction::Instruction {
55        let mut accounts = Vec::with_capacity(12 + remaining_accounts.len());
56        accounts.push(solana_instruction::AccountMeta::new_readonly(
57            self.authority,
58            true,
59        ));
60        accounts.push(solana_instruction::AccountMeta::new(self.market, false));
61        accounts.push(solana_instruction::AccountMeta::new_readonly(
62            self.mint_a,
63            false,
64        ));
65        accounts.push(solana_instruction::AccountMeta::new_readonly(
66            self.mint_b,
67            false,
68        ));
69        accounts.push(solana_instruction::AccountMeta::new(
70            self.authority_a,
71            false,
72        ));
73        accounts.push(solana_instruction::AccountMeta::new(
74            self.authority_b,
75            false,
76        ));
77        accounts.push(solana_instruction::AccountMeta::new(self.market_a, false));
78        accounts.push(solana_instruction::AccountMeta::new(self.market_b, false));
79        accounts.push(solana_instruction::AccountMeta::new_readonly(
80            self.token_program_a,
81            false,
82        ));
83        accounts.push(solana_instruction::AccountMeta::new_readonly(
84            self.token_program_b,
85            false,
86        ));
87        accounts.push(solana_instruction::AccountMeta::new_readonly(
88            self.memo_program,
89            false,
90        ));
91        accounts.push(solana_instruction::AccountMeta::new_readonly(
92            self.instructions_sysvar,
93            false,
94        ));
95        accounts.extend_from_slice(remaining_accounts);
96        let mut data = SwapExactOutInstructionData::new().try_to_vec().unwrap();
97        let mut args = args.try_to_vec().unwrap();
98        data.append(&mut args);
99
100        solana_instruction::Instruction {
101            program_id: crate::RIPTIDE_ID,
102            accounts,
103            data,
104        }
105    }
106}
107
108#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub struct SwapExactOutInstructionData {
111    discriminator: u8,
112}
113
114impl SwapExactOutInstructionData {
115    pub fn new() -> Self {
116        Self { discriminator: 3 }
117    }
118
119    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
120        borsh::to_vec(self)
121    }
122}
123
124impl Default for SwapExactOutInstructionData {
125    fn default() -> Self {
126        Self::new()
127    }
128}
129
130#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
131#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
132pub struct SwapExactOutInstructionArgs {
133    pub amount_out: u64,
134    pub amount_is_token_a: bool,
135    pub slippage_tolerance: SlippageTolerance,
136    pub allow_partial_fill: bool,
137}
138
139impl SwapExactOutInstructionArgs {
140    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
141        borsh::to_vec(self)
142    }
143}
144
145/// Instruction builder for `SwapExactOut`.
146///
147/// ### Accounts:
148///
149///   0. `[signer]` authority
150///   1. `[writable]` market
151///   2. `[]` mint_a
152///   3. `[]` mint_b
153///   4. `[writable]` authority_a
154///   5. `[writable]` authority_b
155///   6. `[writable]` market_a
156///   7. `[writable]` market_b
157///   8. `[]` token_program_a
158///   9. `[]` token_program_b
159///   10. `[]` memo_program
160///   11. `[optional]` instructions_sysvar (default to
161///       `Sysvar1nstructions1111111111111111111111111`)
162#[derive(Clone, Debug, Default)]
163pub struct SwapExactOutBuilder {
164    authority: Option<solana_pubkey::Pubkey>,
165    market: Option<solana_pubkey::Pubkey>,
166    mint_a: Option<solana_pubkey::Pubkey>,
167    mint_b: Option<solana_pubkey::Pubkey>,
168    authority_a: Option<solana_pubkey::Pubkey>,
169    authority_b: Option<solana_pubkey::Pubkey>,
170    market_a: Option<solana_pubkey::Pubkey>,
171    market_b: Option<solana_pubkey::Pubkey>,
172    token_program_a: Option<solana_pubkey::Pubkey>,
173    token_program_b: Option<solana_pubkey::Pubkey>,
174    memo_program: Option<solana_pubkey::Pubkey>,
175    instructions_sysvar: Option<solana_pubkey::Pubkey>,
176    amount_out: Option<u64>,
177    amount_is_token_a: Option<bool>,
178    slippage_tolerance: Option<SlippageTolerance>,
179    allow_partial_fill: Option<bool>,
180    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
181}
182
183impl SwapExactOutBuilder {
184    pub fn new() -> Self {
185        Self::default()
186    }
187    /// The authority
188    #[inline(always)]
189    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
190        self.authority = Some(authority);
191        self
192    }
193    /// The market
194    #[inline(always)]
195    pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
196        self.market = Some(market);
197        self
198    }
199    /// The token a mint
200    #[inline(always)]
201    pub fn mint_a(&mut self, mint_a: solana_pubkey::Pubkey) -> &mut Self {
202        self.mint_a = Some(mint_a);
203        self
204    }
205    /// The token b mint
206    #[inline(always)]
207    pub fn mint_b(&mut self, mint_b: solana_pubkey::Pubkey) -> &mut Self {
208        self.mint_b = Some(mint_b);
209        self
210    }
211    /// The authority's token account for token a
212    #[inline(always)]
213    pub fn authority_a(&mut self, authority_a: solana_pubkey::Pubkey) -> &mut Self {
214        self.authority_a = Some(authority_a);
215        self
216    }
217    /// The authority's token account for token b
218    #[inline(always)]
219    pub fn authority_b(&mut self, authority_b: solana_pubkey::Pubkey) -> &mut Self {
220        self.authority_b = Some(authority_b);
221        self
222    }
223    /// The treasury token account for token a
224    #[inline(always)]
225    pub fn market_a(&mut self, market_a: solana_pubkey::Pubkey) -> &mut Self {
226        self.market_a = Some(market_a);
227        self
228    }
229    /// The treasury token account for token b
230    #[inline(always)]
231    pub fn market_b(&mut self, market_b: solana_pubkey::Pubkey) -> &mut Self {
232        self.market_b = Some(market_b);
233        self
234    }
235    /// The token program for token a
236    #[inline(always)]
237    pub fn token_program_a(&mut self, token_program_a: solana_pubkey::Pubkey) -> &mut Self {
238        self.token_program_a = Some(token_program_a);
239        self
240    }
241    /// The token program for token b
242    #[inline(always)]
243    pub fn token_program_b(&mut self, token_program_b: solana_pubkey::Pubkey) -> &mut Self {
244        self.token_program_b = Some(token_program_b);
245        self
246    }
247    /// The memo program
248    #[inline(always)]
249    pub fn memo_program(&mut self, memo_program: solana_pubkey::Pubkey) -> &mut Self {
250        self.memo_program = Some(memo_program);
251        self
252    }
253    /// `[optional account, default to 'Sysvar1nstructions1111111111111111111111111']`
254    /// The instructions sysvar
255    #[inline(always)]
256    pub fn instructions_sysvar(&mut self, instructions_sysvar: solana_pubkey::Pubkey) -> &mut Self {
257        self.instructions_sysvar = Some(instructions_sysvar);
258        self
259    }
260    #[inline(always)]
261    pub fn amount_out(&mut self, amount_out: u64) -> &mut Self {
262        self.amount_out = Some(amount_out);
263        self
264    }
265    #[inline(always)]
266    pub fn amount_is_token_a(&mut self, amount_is_token_a: bool) -> &mut Self {
267        self.amount_is_token_a = Some(amount_is_token_a);
268        self
269    }
270    #[inline(always)]
271    pub fn slippage_tolerance(&mut self, slippage_tolerance: SlippageTolerance) -> &mut Self {
272        self.slippage_tolerance = Some(slippage_tolerance);
273        self
274    }
275    #[inline(always)]
276    pub fn allow_partial_fill(&mut self, allow_partial_fill: bool) -> &mut Self {
277        self.allow_partial_fill = Some(allow_partial_fill);
278        self
279    }
280    /// Add an additional account to the instruction.
281    #[inline(always)]
282    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
283        self.__remaining_accounts.push(account);
284        self
285    }
286    /// Add additional accounts to the instruction.
287    #[inline(always)]
288    pub fn add_remaining_accounts(
289        &mut self,
290        accounts: &[solana_instruction::AccountMeta],
291    ) -> &mut Self {
292        self.__remaining_accounts.extend_from_slice(accounts);
293        self
294    }
295    #[allow(clippy::clone_on_copy)]
296    pub fn instruction(&self) -> solana_instruction::Instruction {
297        let accounts = SwapExactOut {
298            authority: self.authority.expect("authority is not set"),
299            market: self.market.expect("market is not set"),
300            mint_a: self.mint_a.expect("mint_a is not set"),
301            mint_b: self.mint_b.expect("mint_b is not set"),
302            authority_a: self.authority_a.expect("authority_a is not set"),
303            authority_b: self.authority_b.expect("authority_b is not set"),
304            market_a: self.market_a.expect("market_a is not set"),
305            market_b: self.market_b.expect("market_b is not set"),
306            token_program_a: self.token_program_a.expect("token_program_a is not set"),
307            token_program_b: self.token_program_b.expect("token_program_b is not set"),
308            memo_program: self.memo_program.expect("memo_program is not set"),
309            instructions_sysvar: self.instructions_sysvar.unwrap_or(solana_pubkey::pubkey!(
310                "Sysvar1nstructions1111111111111111111111111"
311            )),
312        };
313        let args = SwapExactOutInstructionArgs {
314            amount_out: self.amount_out.clone().expect("amount_out is not set"),
315            amount_is_token_a: self
316                .amount_is_token_a
317                .clone()
318                .expect("amount_is_token_a is not set"),
319            slippage_tolerance: self
320                .slippage_tolerance
321                .clone()
322                .expect("slippage_tolerance is not set"),
323            allow_partial_fill: self
324                .allow_partial_fill
325                .clone()
326                .expect("allow_partial_fill is not set"),
327        };
328
329        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
330    }
331}
332
333/// `swap_exact_out` CPI accounts.
334pub struct SwapExactOutCpiAccounts<'a, 'b> {
335    /// The authority
336    pub authority: &'b solana_account_info::AccountInfo<'a>,
337    /// The market
338    pub market: &'b solana_account_info::AccountInfo<'a>,
339    /// The token a mint
340    pub mint_a: &'b solana_account_info::AccountInfo<'a>,
341    /// The token b mint
342    pub mint_b: &'b solana_account_info::AccountInfo<'a>,
343    /// The authority's token account for token a
344    pub authority_a: &'b solana_account_info::AccountInfo<'a>,
345    /// The authority's token account for token b
346    pub authority_b: &'b solana_account_info::AccountInfo<'a>,
347    /// The treasury token account for token a
348    pub market_a: &'b solana_account_info::AccountInfo<'a>,
349    /// The treasury token account for token b
350    pub market_b: &'b solana_account_info::AccountInfo<'a>,
351    /// The token program for token a
352    pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
353    /// The token program for token b
354    pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
355    /// The memo program
356    pub memo_program: &'b solana_account_info::AccountInfo<'a>,
357    /// The instructions sysvar
358    pub instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
359}
360
361/// `swap_exact_out` CPI instruction.
362pub struct SwapExactOutCpi<'a, 'b> {
363    /// The program to invoke.
364    pub __program: &'b solana_account_info::AccountInfo<'a>,
365    /// The authority
366    pub authority: &'b solana_account_info::AccountInfo<'a>,
367    /// The market
368    pub market: &'b solana_account_info::AccountInfo<'a>,
369    /// The token a mint
370    pub mint_a: &'b solana_account_info::AccountInfo<'a>,
371    /// The token b mint
372    pub mint_b: &'b solana_account_info::AccountInfo<'a>,
373    /// The authority's token account for token a
374    pub authority_a: &'b solana_account_info::AccountInfo<'a>,
375    /// The authority's token account for token b
376    pub authority_b: &'b solana_account_info::AccountInfo<'a>,
377    /// The treasury token account for token a
378    pub market_a: &'b solana_account_info::AccountInfo<'a>,
379    /// The treasury token account for token b
380    pub market_b: &'b solana_account_info::AccountInfo<'a>,
381    /// The token program for token a
382    pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
383    /// The token program for token b
384    pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
385    /// The memo program
386    pub memo_program: &'b solana_account_info::AccountInfo<'a>,
387    /// The instructions sysvar
388    pub instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
389    /// The arguments for the instruction.
390    pub __args: SwapExactOutInstructionArgs,
391}
392
393impl<'a, 'b> SwapExactOutCpi<'a, 'b> {
394    pub fn new(
395        program: &'b solana_account_info::AccountInfo<'a>,
396        accounts: SwapExactOutCpiAccounts<'a, 'b>,
397        args: SwapExactOutInstructionArgs,
398    ) -> Self {
399        Self {
400            __program: program,
401            authority: accounts.authority,
402            market: accounts.market,
403            mint_a: accounts.mint_a,
404            mint_b: accounts.mint_b,
405            authority_a: accounts.authority_a,
406            authority_b: accounts.authority_b,
407            market_a: accounts.market_a,
408            market_b: accounts.market_b,
409            token_program_a: accounts.token_program_a,
410            token_program_b: accounts.token_program_b,
411            memo_program: accounts.memo_program,
412            instructions_sysvar: accounts.instructions_sysvar,
413            __args: args,
414        }
415    }
416    #[inline(always)]
417    pub fn invoke(&self) -> solana_program_error::ProgramResult {
418        self.invoke_signed_with_remaining_accounts(&[], &[])
419    }
420    #[inline(always)]
421    pub fn invoke_with_remaining_accounts(
422        &self,
423        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
424    ) -> solana_program_error::ProgramResult {
425        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
426    }
427    #[inline(always)]
428    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
429        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
430    }
431    #[allow(clippy::arithmetic_side_effects)]
432    #[allow(clippy::clone_on_copy)]
433    #[allow(clippy::vec_init_then_push)]
434    pub fn invoke_signed_with_remaining_accounts(
435        &self,
436        signers_seeds: &[&[&[u8]]],
437        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
438    ) -> solana_program_error::ProgramResult {
439        let mut accounts = Vec::with_capacity(12 + remaining_accounts.len());
440        accounts.push(solana_instruction::AccountMeta::new_readonly(
441            *self.authority.key,
442            true,
443        ));
444        accounts.push(solana_instruction::AccountMeta::new(
445            *self.market.key,
446            false,
447        ));
448        accounts.push(solana_instruction::AccountMeta::new_readonly(
449            *self.mint_a.key,
450            false,
451        ));
452        accounts.push(solana_instruction::AccountMeta::new_readonly(
453            *self.mint_b.key,
454            false,
455        ));
456        accounts.push(solana_instruction::AccountMeta::new(
457            *self.authority_a.key,
458            false,
459        ));
460        accounts.push(solana_instruction::AccountMeta::new(
461            *self.authority_b.key,
462            false,
463        ));
464        accounts.push(solana_instruction::AccountMeta::new(
465            *self.market_a.key,
466            false,
467        ));
468        accounts.push(solana_instruction::AccountMeta::new(
469            *self.market_b.key,
470            false,
471        ));
472        accounts.push(solana_instruction::AccountMeta::new_readonly(
473            *self.token_program_a.key,
474            false,
475        ));
476        accounts.push(solana_instruction::AccountMeta::new_readonly(
477            *self.token_program_b.key,
478            false,
479        ));
480        accounts.push(solana_instruction::AccountMeta::new_readonly(
481            *self.memo_program.key,
482            false,
483        ));
484        accounts.push(solana_instruction::AccountMeta::new_readonly(
485            *self.instructions_sysvar.key,
486            false,
487        ));
488        remaining_accounts.iter().for_each(|remaining_account| {
489            accounts.push(solana_instruction::AccountMeta {
490                pubkey: *remaining_account.0.key,
491                is_signer: remaining_account.1,
492                is_writable: remaining_account.2,
493            })
494        });
495        let mut data = SwapExactOutInstructionData::new().try_to_vec().unwrap();
496        let mut args = self.__args.try_to_vec().unwrap();
497        data.append(&mut args);
498
499        let instruction = solana_instruction::Instruction {
500            program_id: crate::RIPTIDE_ID,
501            accounts,
502            data,
503        };
504        let mut account_infos = Vec::with_capacity(13 + remaining_accounts.len());
505        account_infos.push(self.__program.clone());
506        account_infos.push(self.authority.clone());
507        account_infos.push(self.market.clone());
508        account_infos.push(self.mint_a.clone());
509        account_infos.push(self.mint_b.clone());
510        account_infos.push(self.authority_a.clone());
511        account_infos.push(self.authority_b.clone());
512        account_infos.push(self.market_a.clone());
513        account_infos.push(self.market_b.clone());
514        account_infos.push(self.token_program_a.clone());
515        account_infos.push(self.token_program_b.clone());
516        account_infos.push(self.memo_program.clone());
517        account_infos.push(self.instructions_sysvar.clone());
518        remaining_accounts
519            .iter()
520            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
521
522        if signers_seeds.is_empty() {
523            solana_cpi::invoke(&instruction, &account_infos)
524        } else {
525            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
526        }
527    }
528}
529
530/// Instruction builder for `SwapExactOut` via CPI.
531///
532/// ### Accounts:
533///
534///   0. `[signer]` authority
535///   1. `[writable]` market
536///   2. `[]` mint_a
537///   3. `[]` mint_b
538///   4. `[writable]` authority_a
539///   5. `[writable]` authority_b
540///   6. `[writable]` market_a
541///   7. `[writable]` market_b
542///   8. `[]` token_program_a
543///   9. `[]` token_program_b
544///   10. `[]` memo_program
545///   11. `[]` instructions_sysvar
546#[derive(Clone, Debug)]
547pub struct SwapExactOutCpiBuilder<'a, 'b> {
548    instruction: Box<SwapExactOutCpiBuilderInstruction<'a, 'b>>,
549}
550
551impl<'a, 'b> SwapExactOutCpiBuilder<'a, 'b> {
552    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
553        let instruction = Box::new(SwapExactOutCpiBuilderInstruction {
554            __program: program,
555            authority: None,
556            market: None,
557            mint_a: None,
558            mint_b: None,
559            authority_a: None,
560            authority_b: None,
561            market_a: None,
562            market_b: None,
563            token_program_a: None,
564            token_program_b: None,
565            memo_program: None,
566            instructions_sysvar: None,
567            amount_out: None,
568            amount_is_token_a: None,
569            slippage_tolerance: None,
570            allow_partial_fill: None,
571            __remaining_accounts: Vec::new(),
572        });
573        Self { instruction }
574    }
575    /// The authority
576    #[inline(always)]
577    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
578        self.instruction.authority = Some(authority);
579        self
580    }
581    /// The market
582    #[inline(always)]
583    pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
584        self.instruction.market = Some(market);
585        self
586    }
587    /// The token a mint
588    #[inline(always)]
589    pub fn mint_a(&mut self, mint_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
590        self.instruction.mint_a = Some(mint_a);
591        self
592    }
593    /// The token b mint
594    #[inline(always)]
595    pub fn mint_b(&mut self, mint_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
596        self.instruction.mint_b = Some(mint_b);
597        self
598    }
599    /// The authority's token account for token a
600    #[inline(always)]
601    pub fn authority_a(
602        &mut self,
603        authority_a: &'b solana_account_info::AccountInfo<'a>,
604    ) -> &mut Self {
605        self.instruction.authority_a = Some(authority_a);
606        self
607    }
608    /// The authority's token account for token b
609    #[inline(always)]
610    pub fn authority_b(
611        &mut self,
612        authority_b: &'b solana_account_info::AccountInfo<'a>,
613    ) -> &mut Self {
614        self.instruction.authority_b = Some(authority_b);
615        self
616    }
617    /// The treasury token account for token a
618    #[inline(always)]
619    pub fn market_a(&mut self, market_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
620        self.instruction.market_a = Some(market_a);
621        self
622    }
623    /// The treasury token account for token b
624    #[inline(always)]
625    pub fn market_b(&mut self, market_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
626        self.instruction.market_b = Some(market_b);
627        self
628    }
629    /// The token program for token a
630    #[inline(always)]
631    pub fn token_program_a(
632        &mut self,
633        token_program_a: &'b solana_account_info::AccountInfo<'a>,
634    ) -> &mut Self {
635        self.instruction.token_program_a = Some(token_program_a);
636        self
637    }
638    /// The token program for token b
639    #[inline(always)]
640    pub fn token_program_b(
641        &mut self,
642        token_program_b: &'b solana_account_info::AccountInfo<'a>,
643    ) -> &mut Self {
644        self.instruction.token_program_b = Some(token_program_b);
645        self
646    }
647    /// The memo program
648    #[inline(always)]
649    pub fn memo_program(
650        &mut self,
651        memo_program: &'b solana_account_info::AccountInfo<'a>,
652    ) -> &mut Self {
653        self.instruction.memo_program = Some(memo_program);
654        self
655    }
656    /// The instructions sysvar
657    #[inline(always)]
658    pub fn instructions_sysvar(
659        &mut self,
660        instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
661    ) -> &mut Self {
662        self.instruction.instructions_sysvar = Some(instructions_sysvar);
663        self
664    }
665    #[inline(always)]
666    pub fn amount_out(&mut self, amount_out: u64) -> &mut Self {
667        self.instruction.amount_out = Some(amount_out);
668        self
669    }
670    #[inline(always)]
671    pub fn amount_is_token_a(&mut self, amount_is_token_a: bool) -> &mut Self {
672        self.instruction.amount_is_token_a = Some(amount_is_token_a);
673        self
674    }
675    #[inline(always)]
676    pub fn slippage_tolerance(&mut self, slippage_tolerance: SlippageTolerance) -> &mut Self {
677        self.instruction.slippage_tolerance = Some(slippage_tolerance);
678        self
679    }
680    #[inline(always)]
681    pub fn allow_partial_fill(&mut self, allow_partial_fill: bool) -> &mut Self {
682        self.instruction.allow_partial_fill = Some(allow_partial_fill);
683        self
684    }
685    /// Add an additional account to the instruction.
686    #[inline(always)]
687    pub fn add_remaining_account(
688        &mut self,
689        account: &'b solana_account_info::AccountInfo<'a>,
690        is_writable: bool,
691        is_signer: bool,
692    ) -> &mut Self {
693        self.instruction
694            .__remaining_accounts
695            .push((account, is_writable, is_signer));
696        self
697    }
698    /// Add additional accounts to the instruction.
699    ///
700    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the
701    /// account is writable or not, and a `bool` indicating whether the account is a signer or
702    /// not.
703    #[inline(always)]
704    pub fn add_remaining_accounts(
705        &mut self,
706        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
707    ) -> &mut Self {
708        self.instruction
709            .__remaining_accounts
710            .extend_from_slice(accounts);
711        self
712    }
713    #[inline(always)]
714    pub fn invoke(&self) -> solana_program_error::ProgramResult {
715        self.invoke_signed(&[])
716    }
717    #[allow(clippy::clone_on_copy)]
718    #[allow(clippy::vec_init_then_push)]
719    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
720        let args = SwapExactOutInstructionArgs {
721            amount_out: self
722                .instruction
723                .amount_out
724                .clone()
725                .expect("amount_out is not set"),
726            amount_is_token_a: self
727                .instruction
728                .amount_is_token_a
729                .clone()
730                .expect("amount_is_token_a is not set"),
731            slippage_tolerance: self
732                .instruction
733                .slippage_tolerance
734                .clone()
735                .expect("slippage_tolerance is not set"),
736            allow_partial_fill: self
737                .instruction
738                .allow_partial_fill
739                .clone()
740                .expect("allow_partial_fill is not set"),
741        };
742        let instruction = SwapExactOutCpi {
743            __program: self.instruction.__program,
744
745            authority: self.instruction.authority.expect("authority is not set"),
746
747            market: self.instruction.market.expect("market is not set"),
748
749            mint_a: self.instruction.mint_a.expect("mint_a is not set"),
750
751            mint_b: self.instruction.mint_b.expect("mint_b is not set"),
752
753            authority_a: self
754                .instruction
755                .authority_a
756                .expect("authority_a is not set"),
757
758            authority_b: self
759                .instruction
760                .authority_b
761                .expect("authority_b is not set"),
762
763            market_a: self.instruction.market_a.expect("market_a is not set"),
764
765            market_b: self.instruction.market_b.expect("market_b is not set"),
766
767            token_program_a: self
768                .instruction
769                .token_program_a
770                .expect("token_program_a is not set"),
771
772            token_program_b: self
773                .instruction
774                .token_program_b
775                .expect("token_program_b is not set"),
776
777            memo_program: self
778                .instruction
779                .memo_program
780                .expect("memo_program is not set"),
781
782            instructions_sysvar: self
783                .instruction
784                .instructions_sysvar
785                .expect("instructions_sysvar is not set"),
786            __args: args,
787        };
788        instruction.invoke_signed_with_remaining_accounts(
789            signers_seeds,
790            &self.instruction.__remaining_accounts,
791        )
792    }
793}
794
795#[derive(Clone, Debug)]
796struct SwapExactOutCpiBuilderInstruction<'a, 'b> {
797    __program: &'b solana_account_info::AccountInfo<'a>,
798    authority: Option<&'b solana_account_info::AccountInfo<'a>>,
799    market: Option<&'b solana_account_info::AccountInfo<'a>>,
800    mint_a: Option<&'b solana_account_info::AccountInfo<'a>>,
801    mint_b: Option<&'b solana_account_info::AccountInfo<'a>>,
802    authority_a: Option<&'b solana_account_info::AccountInfo<'a>>,
803    authority_b: Option<&'b solana_account_info::AccountInfo<'a>>,
804    market_a: Option<&'b solana_account_info::AccountInfo<'a>>,
805    market_b: Option<&'b solana_account_info::AccountInfo<'a>>,
806    token_program_a: Option<&'b solana_account_info::AccountInfo<'a>>,
807    token_program_b: Option<&'b solana_account_info::AccountInfo<'a>>,
808    memo_program: Option<&'b solana_account_info::AccountInfo<'a>>,
809    instructions_sysvar: Option<&'b solana_account_info::AccountInfo<'a>>,
810    amount_out: Option<u64>,
811    amount_is_token_a: Option<bool>,
812    slippage_tolerance: Option<SlippageTolerance>,
813    allow_partial_fill: Option<bool>,
814    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
815    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
816}