Skip to main content

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