defituna_client/generated/instructions/
set_default_max_swap_slippage.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//!
7
8use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11/// Accounts.
12#[derive(Debug)]
13pub struct SetDefaultMaxSwapSlippage {
14      
15              
16          pub authority: solana_program::pubkey::Pubkey,
17          
18              
19          pub tuna_config: solana_program::pubkey::Pubkey,
20      }
21
22impl SetDefaultMaxSwapSlippage {
23  pub fn instruction(&self, args: SetDefaultMaxSwapSlippageInstructionArgs) -> solana_program::instruction::Instruction {
24    self.instruction_with_remaining_accounts(args, &[])
25  }
26  #[allow(clippy::arithmetic_side_effects)]
27  #[allow(clippy::vec_init_then_push)]
28  pub fn instruction_with_remaining_accounts(&self, args: SetDefaultMaxSwapSlippageInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
29    let mut accounts = Vec::with_capacity(2+ remaining_accounts.len());
30                            accounts.push(solana_program::instruction::AccountMeta::new(
31            self.authority,
32            true
33          ));
34                                          accounts.push(solana_program::instruction::AccountMeta::new(
35            self.tuna_config,
36            false
37          ));
38                      accounts.extend_from_slice(remaining_accounts);
39    let mut data = borsh::to_vec(&SetDefaultMaxSwapSlippageInstructionData::new()).unwrap();
40          let mut args = borsh::to_vec(&args).unwrap();
41      data.append(&mut args);
42    
43    solana_program::instruction::Instruction {
44      program_id: crate::TUNA_ID,
45      accounts,
46      data,
47    }
48  }
49}
50
51#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
52#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53 pub struct SetDefaultMaxSwapSlippageInstructionData {
54            discriminator: [u8; 8],
55            }
56
57impl SetDefaultMaxSwapSlippageInstructionData {
58  pub fn new() -> Self {
59    Self {
60                        discriminator: [122, 22, 122, 128, 248, 196, 227, 181],
61                                }
62  }
63}
64
65impl Default for SetDefaultMaxSwapSlippageInstructionData {
66  fn default() -> Self {
67    Self::new()
68  }
69}
70
71#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73 pub struct SetDefaultMaxSwapSlippageInstructionArgs {
74                  pub max_swap_slippage: u32,
75      }
76
77
78/// Instruction builder for `SetDefaultMaxSwapSlippage`.
79///
80/// ### Accounts:
81///
82                      ///   0. `[writable, signer]` authority
83                ///   1. `[writable]` tuna_config
84#[derive(Clone, Debug, Default)]
85pub struct SetDefaultMaxSwapSlippageBuilder {
86            authority: Option<solana_program::pubkey::Pubkey>,
87                tuna_config: Option<solana_program::pubkey::Pubkey>,
88                        max_swap_slippage: Option<u32>,
89        __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
90}
91
92impl SetDefaultMaxSwapSlippageBuilder {
93  pub fn new() -> Self {
94    Self::default()
95  }
96            #[inline(always)]
97    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
98                        self.authority = Some(authority);
99                    self
100    }
101            #[inline(always)]
102    pub fn tuna_config(&mut self, tuna_config: solana_program::pubkey::Pubkey) -> &mut Self {
103                        self.tuna_config = Some(tuna_config);
104                    self
105    }
106                    #[inline(always)]
107      pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
108        self.max_swap_slippage = Some(max_swap_slippage);
109        self
110      }
111        /// Add an additional account to the instruction.
112  #[inline(always)]
113  pub fn add_remaining_account(&mut self, account: solana_program::instruction::AccountMeta) -> &mut Self {
114    self.__remaining_accounts.push(account);
115    self
116  }
117  /// Add additional accounts to the instruction.
118  #[inline(always)]
119  pub fn add_remaining_accounts(&mut self, accounts: &[solana_program::instruction::AccountMeta]) -> &mut Self {
120    self.__remaining_accounts.extend_from_slice(accounts);
121    self
122  }
123  #[allow(clippy::clone_on_copy)]
124  pub fn instruction(&self) -> solana_program::instruction::Instruction {
125    let accounts = SetDefaultMaxSwapSlippage {
126                              authority: self.authority.expect("authority is not set"),
127                                        tuna_config: self.tuna_config.expect("tuna_config is not set"),
128                      };
129          let args = SetDefaultMaxSwapSlippageInstructionArgs {
130                                                              max_swap_slippage: self.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
131                                    };
132    
133    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
134  }
135}
136
137  /// `set_default_max_swap_slippage` CPI accounts.
138  pub struct SetDefaultMaxSwapSlippageCpiAccounts<'a, 'b> {
139          
140                    
141              pub authority: &'b solana_program::account_info::AccountInfo<'a>,
142                
143                    
144              pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
145            }
146
147/// `set_default_max_swap_slippage` CPI instruction.
148pub struct SetDefaultMaxSwapSlippageCpi<'a, 'b> {
149  /// The program to invoke.
150  pub __program: &'b solana_program::account_info::AccountInfo<'a>,
151      
152              
153          pub authority: &'b solana_program::account_info::AccountInfo<'a>,
154          
155              
156          pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
157            /// The arguments for the instruction.
158    pub __args: SetDefaultMaxSwapSlippageInstructionArgs,
159  }
160
161impl<'a, 'b> SetDefaultMaxSwapSlippageCpi<'a, 'b> {
162  pub fn new(
163    program: &'b solana_program::account_info::AccountInfo<'a>,
164          accounts: SetDefaultMaxSwapSlippageCpiAccounts<'a, 'b>,
165              args: SetDefaultMaxSwapSlippageInstructionArgs,
166      ) -> Self {
167    Self {
168      __program: program,
169              authority: accounts.authority,
170              tuna_config: accounts.tuna_config,
171                    __args: args,
172          }
173  }
174  #[inline(always)]
175  pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
176    self.invoke_signed_with_remaining_accounts(&[], &[])
177  }
178  #[inline(always)]
179  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> solana_program::entrypoint::ProgramResult {
180    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
181  }
182  #[inline(always)]
183  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
184    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
185  }
186  #[allow(clippy::arithmetic_side_effects)]
187  #[allow(clippy::clone_on_copy)]
188  #[allow(clippy::vec_init_then_push)]
189  pub fn invoke_signed_with_remaining_accounts(
190    &self,
191    signers_seeds: &[&[&[u8]]],
192    remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]
193  ) -> solana_program::entrypoint::ProgramResult {
194    let mut accounts = Vec::with_capacity(2+ remaining_accounts.len());
195                            accounts.push(solana_program::instruction::AccountMeta::new(
196            *self.authority.key,
197            true
198          ));
199                                          accounts.push(solana_program::instruction::AccountMeta::new(
200            *self.tuna_config.key,
201            false
202          ));
203                      remaining_accounts.iter().for_each(|remaining_account| {
204      accounts.push(solana_program::instruction::AccountMeta {
205          pubkey: *remaining_account.0.key,
206          is_signer: remaining_account.1,
207          is_writable: remaining_account.2,
208      })
209    });
210    let mut data = borsh::to_vec(&SetDefaultMaxSwapSlippageInstructionData::new()).unwrap();
211          let mut args = borsh::to_vec(&self.__args).unwrap();
212      data.append(&mut args);
213    
214    let instruction = solana_program::instruction::Instruction {
215      program_id: crate::TUNA_ID,
216      accounts,
217      data,
218    };
219    let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
220    account_infos.push(self.__program.clone());
221                  account_infos.push(self.authority.clone());
222                        account_infos.push(self.tuna_config.clone());
223              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
224
225    if signers_seeds.is_empty() {
226      solana_program::program::invoke(&instruction, &account_infos)
227    } else {
228      solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
229    }
230  }
231}
232
233/// Instruction builder for `SetDefaultMaxSwapSlippage` via CPI.
234///
235/// ### Accounts:
236///
237                      ///   0. `[writable, signer]` authority
238                ///   1. `[writable]` tuna_config
239#[derive(Clone, Debug)]
240pub struct SetDefaultMaxSwapSlippageCpiBuilder<'a, 'b> {
241  instruction: Box<SetDefaultMaxSwapSlippageCpiBuilderInstruction<'a, 'b>>,
242}
243
244impl<'a, 'b> SetDefaultMaxSwapSlippageCpiBuilder<'a, 'b> {
245  pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
246    let instruction = Box::new(SetDefaultMaxSwapSlippageCpiBuilderInstruction {
247      __program: program,
248              authority: None,
249              tuna_config: None,
250                                            max_swap_slippage: None,
251                    __remaining_accounts: Vec::new(),
252    });
253    Self { instruction }
254  }
255      #[inline(always)]
256    pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
257                        self.instruction.authority = Some(authority);
258                    self
259    }
260      #[inline(always)]
261    pub fn tuna_config(&mut self, tuna_config: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
262                        self.instruction.tuna_config = Some(tuna_config);
263                    self
264    }
265                    #[inline(always)]
266      pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
267        self.instruction.max_swap_slippage = Some(max_swap_slippage);
268        self
269      }
270        /// Add an additional account to the instruction.
271  #[inline(always)]
272  pub fn add_remaining_account(&mut self, account: &'b solana_program::account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
273    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
274    self
275  }
276  /// Add additional accounts to the instruction.
277  ///
278  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
279  /// and a `bool` indicating whether the account is a signer or not.
280  #[inline(always)]
281  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
282    self.instruction.__remaining_accounts.extend_from_slice(accounts);
283    self
284  }
285  #[inline(always)]
286  pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
287    self.invoke_signed(&[])
288  }
289  #[allow(clippy::clone_on_copy)]
290  #[allow(clippy::vec_init_then_push)]
291  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
292          let args = SetDefaultMaxSwapSlippageInstructionArgs {
293                                                              max_swap_slippage: self.instruction.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
294                                    };
295        let instruction = SetDefaultMaxSwapSlippageCpi {
296        __program: self.instruction.__program,
297                  
298          authority: self.instruction.authority.expect("authority is not set"),
299                  
300          tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
301                          __args: args,
302            };
303    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
304  }
305}
306
307#[derive(Clone, Debug)]
308struct SetDefaultMaxSwapSlippageCpiBuilderInstruction<'a, 'b> {
309  __program: &'b solana_program::account_info::AccountInfo<'a>,
310            authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
311                tuna_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
312                        max_swap_slippage: Option<u32>,
313        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
314  __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
315}
316