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