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