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