defituna_client/generated/instructions/
update_market.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 solana_program::pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct UpdateMarket {
15      
16              
17          pub authority: solana_program::pubkey::Pubkey,
18          
19              
20          pub tuna_config: solana_program::pubkey::Pubkey,
21          
22              
23          pub market: solana_program::pubkey::Pubkey,
24      }
25
26impl UpdateMarket {
27  pub fn instruction(&self, args: UpdateMarketInstructionArgs) -> solana_program::instruction::Instruction {
28    self.instruction_with_remaining_accounts(args, &[])
29  }
30  #[allow(clippy::arithmetic_side_effects)]
31  #[allow(clippy::vec_init_then_push)]
32  pub fn instruction_with_remaining_accounts(&self, args: UpdateMarketInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
33    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
34                            accounts.push(solana_program::instruction::AccountMeta::new(
35            self.authority,
36            true
37          ));
38                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
39            self.tuna_config,
40            false
41          ));
42                                          accounts.push(solana_program::instruction::AccountMeta::new(
43            self.market,
44            false
45          ));
46                      accounts.extend_from_slice(remaining_accounts);
47    let mut data = borsh::to_vec(&UpdateMarketInstructionData::new()).unwrap();
48          let mut args = borsh::to_vec(&args).unwrap();
49      data.append(&mut args);
50    
51    solana_program::instruction::Instruction {
52      program_id: crate::TUNA_ID,
53      accounts,
54      data,
55    }
56  }
57}
58
59#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
60#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61 pub struct UpdateMarketInstructionData {
62            discriminator: [u8; 8],
63                                                                              }
64
65impl UpdateMarketInstructionData {
66  pub fn new() -> Self {
67    Self {
68                        discriminator: [153, 39, 2, 197, 179, 50, 199, 217],
69                                                                                                                                                                                          }
70  }
71}
72
73impl Default for UpdateMarketInstructionData {
74  fn default() -> Self {
75    Self::new()
76  }
77}
78
79#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
81 pub struct UpdateMarketInstructionArgs {
82                  pub address_lookup_table: Pubkey,
83                pub max_leverage: u32,
84                pub protocol_fee: u16,
85                pub protocol_fee_on_collateral: u16,
86                pub liquidation_fee: u32,
87                pub liquidation_threshold: u32,
88                pub limit_order_execution_fee: u32,
89                pub oracle_price_deviation_threshold: u32,
90                pub disabled: bool,
91                pub borrow_limit_a: u64,
92                pub borrow_limit_b: u64,
93                pub max_swap_slippage: u32,
94      }
95
96
97/// Instruction builder for `UpdateMarket`.
98///
99/// ### Accounts:
100///
101                      ///   0. `[writable, signer]` authority
102          ///   1. `[]` tuna_config
103                ///   2. `[writable]` market
104#[derive(Clone, Debug, Default)]
105pub struct UpdateMarketBuilder {
106            authority: Option<solana_program::pubkey::Pubkey>,
107                tuna_config: Option<solana_program::pubkey::Pubkey>,
108                market: Option<solana_program::pubkey::Pubkey>,
109                        address_lookup_table: Option<Pubkey>,
110                max_leverage: Option<u32>,
111                protocol_fee: Option<u16>,
112                protocol_fee_on_collateral: Option<u16>,
113                liquidation_fee: Option<u32>,
114                liquidation_threshold: Option<u32>,
115                limit_order_execution_fee: Option<u32>,
116                oracle_price_deviation_threshold: Option<u32>,
117                disabled: Option<bool>,
118                borrow_limit_a: Option<u64>,
119                borrow_limit_b: Option<u64>,
120                max_swap_slippage: Option<u32>,
121        __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
122}
123
124impl UpdateMarketBuilder {
125  pub fn new() -> Self {
126    Self::default()
127  }
128            #[inline(always)]
129    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
130                        self.authority = Some(authority);
131                    self
132    }
133            #[inline(always)]
134    pub fn tuna_config(&mut self, tuna_config: solana_program::pubkey::Pubkey) -> &mut Self {
135                        self.tuna_config = Some(tuna_config);
136                    self
137    }
138            #[inline(always)]
139    pub fn market(&mut self, market: solana_program::pubkey::Pubkey) -> &mut Self {
140                        self.market = Some(market);
141                    self
142    }
143                    #[inline(always)]
144      pub fn address_lookup_table(&mut self, address_lookup_table: Pubkey) -> &mut Self {
145        self.address_lookup_table = Some(address_lookup_table);
146        self
147      }
148                #[inline(always)]
149      pub fn max_leverage(&mut self, max_leverage: u32) -> &mut Self {
150        self.max_leverage = Some(max_leverage);
151        self
152      }
153                #[inline(always)]
154      pub fn protocol_fee(&mut self, protocol_fee: u16) -> &mut Self {
155        self.protocol_fee = Some(protocol_fee);
156        self
157      }
158                #[inline(always)]
159      pub fn protocol_fee_on_collateral(&mut self, protocol_fee_on_collateral: u16) -> &mut Self {
160        self.protocol_fee_on_collateral = Some(protocol_fee_on_collateral);
161        self
162      }
163                #[inline(always)]
164      pub fn liquidation_fee(&mut self, liquidation_fee: u32) -> &mut Self {
165        self.liquidation_fee = Some(liquidation_fee);
166        self
167      }
168                #[inline(always)]
169      pub fn liquidation_threshold(&mut self, liquidation_threshold: u32) -> &mut Self {
170        self.liquidation_threshold = Some(liquidation_threshold);
171        self
172      }
173                #[inline(always)]
174      pub fn limit_order_execution_fee(&mut self, limit_order_execution_fee: u32) -> &mut Self {
175        self.limit_order_execution_fee = Some(limit_order_execution_fee);
176        self
177      }
178                #[inline(always)]
179      pub fn oracle_price_deviation_threshold(&mut self, oracle_price_deviation_threshold: u32) -> &mut Self {
180        self.oracle_price_deviation_threshold = Some(oracle_price_deviation_threshold);
181        self
182      }
183                #[inline(always)]
184      pub fn disabled(&mut self, disabled: bool) -> &mut Self {
185        self.disabled = Some(disabled);
186        self
187      }
188                #[inline(always)]
189      pub fn borrow_limit_a(&mut self, borrow_limit_a: u64) -> &mut Self {
190        self.borrow_limit_a = Some(borrow_limit_a);
191        self
192      }
193                #[inline(always)]
194      pub fn borrow_limit_b(&mut self, borrow_limit_b: u64) -> &mut Self {
195        self.borrow_limit_b = Some(borrow_limit_b);
196        self
197      }
198                #[inline(always)]
199      pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
200        self.max_swap_slippage = Some(max_swap_slippage);
201        self
202      }
203        /// Add an additional account to the instruction.
204  #[inline(always)]
205  pub fn add_remaining_account(&mut self, account: solana_program::instruction::AccountMeta) -> &mut Self {
206    self.__remaining_accounts.push(account);
207    self
208  }
209  /// Add additional accounts to the instruction.
210  #[inline(always)]
211  pub fn add_remaining_accounts(&mut self, accounts: &[solana_program::instruction::AccountMeta]) -> &mut Self {
212    self.__remaining_accounts.extend_from_slice(accounts);
213    self
214  }
215  #[allow(clippy::clone_on_copy)]
216  pub fn instruction(&self) -> solana_program::instruction::Instruction {
217    let accounts = UpdateMarket {
218                              authority: self.authority.expect("authority is not set"),
219                                        tuna_config: self.tuna_config.expect("tuna_config is not set"),
220                                        market: self.market.expect("market is not set"),
221                      };
222          let args = UpdateMarketInstructionArgs {
223                                                              address_lookup_table: self.address_lookup_table.clone().expect("address_lookup_table is not set"),
224                                                                  max_leverage: self.max_leverage.clone().expect("max_leverage is not set"),
225                                                                  protocol_fee: self.protocol_fee.clone().expect("protocol_fee is not set"),
226                                                                  protocol_fee_on_collateral: self.protocol_fee_on_collateral.clone().expect("protocol_fee_on_collateral is not set"),
227                                                                  liquidation_fee: self.liquidation_fee.clone().expect("liquidation_fee is not set"),
228                                                                  liquidation_threshold: self.liquidation_threshold.clone().expect("liquidation_threshold is not set"),
229                                                                  limit_order_execution_fee: self.limit_order_execution_fee.clone().expect("limit_order_execution_fee is not set"),
230                                                                  oracle_price_deviation_threshold: self.oracle_price_deviation_threshold.clone().expect("oracle_price_deviation_threshold is not set"),
231                                                                  disabled: self.disabled.clone().expect("disabled is not set"),
232                                                                  borrow_limit_a: self.borrow_limit_a.clone().expect("borrow_limit_a is not set"),
233                                                                  borrow_limit_b: self.borrow_limit_b.clone().expect("borrow_limit_b is not set"),
234                                                                  max_swap_slippage: self.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
235                                    };
236    
237    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
238  }
239}
240
241  /// `update_market` CPI accounts.
242  pub struct UpdateMarketCpiAccounts<'a, 'b> {
243          
244                    
245              pub authority: &'b solana_program::account_info::AccountInfo<'a>,
246                
247                    
248              pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
249                
250                    
251              pub market: &'b solana_program::account_info::AccountInfo<'a>,
252            }
253
254/// `update_market` CPI instruction.
255pub struct UpdateMarketCpi<'a, 'b> {
256  /// The program to invoke.
257  pub __program: &'b solana_program::account_info::AccountInfo<'a>,
258      
259              
260          pub authority: &'b solana_program::account_info::AccountInfo<'a>,
261          
262              
263          pub tuna_config: &'b solana_program::account_info::AccountInfo<'a>,
264          
265              
266          pub market: &'b solana_program::account_info::AccountInfo<'a>,
267            /// The arguments for the instruction.
268    pub __args: UpdateMarketInstructionArgs,
269  }
270
271impl<'a, 'b> UpdateMarketCpi<'a, 'b> {
272  pub fn new(
273    program: &'b solana_program::account_info::AccountInfo<'a>,
274          accounts: UpdateMarketCpiAccounts<'a, 'b>,
275              args: UpdateMarketInstructionArgs,
276      ) -> Self {
277    Self {
278      __program: program,
279              authority: accounts.authority,
280              tuna_config: accounts.tuna_config,
281              market: accounts.market,
282                    __args: args,
283          }
284  }
285  #[inline(always)]
286  pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
287    self.invoke_signed_with_remaining_accounts(&[], &[])
288  }
289  #[inline(always)]
290  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> solana_program::entrypoint::ProgramResult {
291    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
292  }
293  #[inline(always)]
294  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
295    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
296  }
297  #[allow(clippy::arithmetic_side_effects)]
298  #[allow(clippy::clone_on_copy)]
299  #[allow(clippy::vec_init_then_push)]
300  pub fn invoke_signed_with_remaining_accounts(
301    &self,
302    signers_seeds: &[&[&[u8]]],
303    remaining_accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]
304  ) -> solana_program::entrypoint::ProgramResult {
305    let mut accounts = Vec::with_capacity(3+ remaining_accounts.len());
306                            accounts.push(solana_program::instruction::AccountMeta::new(
307            *self.authority.key,
308            true
309          ));
310                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
311            *self.tuna_config.key,
312            false
313          ));
314                                          accounts.push(solana_program::instruction::AccountMeta::new(
315            *self.market.key,
316            false
317          ));
318                      remaining_accounts.iter().for_each(|remaining_account| {
319      accounts.push(solana_program::instruction::AccountMeta {
320          pubkey: *remaining_account.0.key,
321          is_signer: remaining_account.1,
322          is_writable: remaining_account.2,
323      })
324    });
325    let mut data = borsh::to_vec(&UpdateMarketInstructionData::new()).unwrap();
326          let mut args = borsh::to_vec(&self.__args).unwrap();
327      data.append(&mut args);
328    
329    let instruction = solana_program::instruction::Instruction {
330      program_id: crate::TUNA_ID,
331      accounts,
332      data,
333    };
334    let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
335    account_infos.push(self.__program.clone());
336                  account_infos.push(self.authority.clone());
337                        account_infos.push(self.tuna_config.clone());
338                        account_infos.push(self.market.clone());
339              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
340
341    if signers_seeds.is_empty() {
342      solana_program::program::invoke(&instruction, &account_infos)
343    } else {
344      solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
345    }
346  }
347}
348
349/// Instruction builder for `UpdateMarket` via CPI.
350///
351/// ### Accounts:
352///
353                      ///   0. `[writable, signer]` authority
354          ///   1. `[]` tuna_config
355                ///   2. `[writable]` market
356#[derive(Clone, Debug)]
357pub struct UpdateMarketCpiBuilder<'a, 'b> {
358  instruction: Box<UpdateMarketCpiBuilderInstruction<'a, 'b>>,
359}
360
361impl<'a, 'b> UpdateMarketCpiBuilder<'a, 'b> {
362  pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
363    let instruction = Box::new(UpdateMarketCpiBuilderInstruction {
364      __program: program,
365              authority: None,
366              tuna_config: None,
367              market: None,
368                                            address_lookup_table: None,
369                                max_leverage: None,
370                                protocol_fee: None,
371                                protocol_fee_on_collateral: None,
372                                liquidation_fee: None,
373                                liquidation_threshold: None,
374                                limit_order_execution_fee: None,
375                                oracle_price_deviation_threshold: None,
376                                disabled: None,
377                                borrow_limit_a: None,
378                                borrow_limit_b: None,
379                                max_swap_slippage: None,
380                    __remaining_accounts: Vec::new(),
381    });
382    Self { instruction }
383  }
384      #[inline(always)]
385    pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
386                        self.instruction.authority = Some(authority);
387                    self
388    }
389      #[inline(always)]
390    pub fn tuna_config(&mut self, tuna_config: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
391                        self.instruction.tuna_config = Some(tuna_config);
392                    self
393    }
394      #[inline(always)]
395    pub fn market(&mut self, market: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
396                        self.instruction.market = Some(market);
397                    self
398    }
399                    #[inline(always)]
400      pub fn address_lookup_table(&mut self, address_lookup_table: Pubkey) -> &mut Self {
401        self.instruction.address_lookup_table = Some(address_lookup_table);
402        self
403      }
404                #[inline(always)]
405      pub fn max_leverage(&mut self, max_leverage: u32) -> &mut Self {
406        self.instruction.max_leverage = Some(max_leverage);
407        self
408      }
409                #[inline(always)]
410      pub fn protocol_fee(&mut self, protocol_fee: u16) -> &mut Self {
411        self.instruction.protocol_fee = Some(protocol_fee);
412        self
413      }
414                #[inline(always)]
415      pub fn protocol_fee_on_collateral(&mut self, protocol_fee_on_collateral: u16) -> &mut Self {
416        self.instruction.protocol_fee_on_collateral = Some(protocol_fee_on_collateral);
417        self
418      }
419                #[inline(always)]
420      pub fn liquidation_fee(&mut self, liquidation_fee: u32) -> &mut Self {
421        self.instruction.liquidation_fee = Some(liquidation_fee);
422        self
423      }
424                #[inline(always)]
425      pub fn liquidation_threshold(&mut self, liquidation_threshold: u32) -> &mut Self {
426        self.instruction.liquidation_threshold = Some(liquidation_threshold);
427        self
428      }
429                #[inline(always)]
430      pub fn limit_order_execution_fee(&mut self, limit_order_execution_fee: u32) -> &mut Self {
431        self.instruction.limit_order_execution_fee = Some(limit_order_execution_fee);
432        self
433      }
434                #[inline(always)]
435      pub fn oracle_price_deviation_threshold(&mut self, oracle_price_deviation_threshold: u32) -> &mut Self {
436        self.instruction.oracle_price_deviation_threshold = Some(oracle_price_deviation_threshold);
437        self
438      }
439                #[inline(always)]
440      pub fn disabled(&mut self, disabled: bool) -> &mut Self {
441        self.instruction.disabled = Some(disabled);
442        self
443      }
444                #[inline(always)]
445      pub fn borrow_limit_a(&mut self, borrow_limit_a: u64) -> &mut Self {
446        self.instruction.borrow_limit_a = Some(borrow_limit_a);
447        self
448      }
449                #[inline(always)]
450      pub fn borrow_limit_b(&mut self, borrow_limit_b: u64) -> &mut Self {
451        self.instruction.borrow_limit_b = Some(borrow_limit_b);
452        self
453      }
454                #[inline(always)]
455      pub fn max_swap_slippage(&mut self, max_swap_slippage: u32) -> &mut Self {
456        self.instruction.max_swap_slippage = Some(max_swap_slippage);
457        self
458      }
459        /// Add an additional account to the instruction.
460  #[inline(always)]
461  pub fn add_remaining_account(&mut self, account: &'b solana_program::account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
462    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
463    self
464  }
465  /// Add additional accounts to the instruction.
466  ///
467  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
468  /// and a `bool` indicating whether the account is a signer or not.
469  #[inline(always)]
470  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
471    self.instruction.__remaining_accounts.extend_from_slice(accounts);
472    self
473  }
474  #[inline(always)]
475  pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
476    self.invoke_signed(&[])
477  }
478  #[allow(clippy::clone_on_copy)]
479  #[allow(clippy::vec_init_then_push)]
480  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program::entrypoint::ProgramResult {
481          let args = UpdateMarketInstructionArgs {
482                                                              address_lookup_table: self.instruction.address_lookup_table.clone().expect("address_lookup_table is not set"),
483                                                                  max_leverage: self.instruction.max_leverage.clone().expect("max_leverage is not set"),
484                                                                  protocol_fee: self.instruction.protocol_fee.clone().expect("protocol_fee is not set"),
485                                                                  protocol_fee_on_collateral: self.instruction.protocol_fee_on_collateral.clone().expect("protocol_fee_on_collateral is not set"),
486                                                                  liquidation_fee: self.instruction.liquidation_fee.clone().expect("liquidation_fee is not set"),
487                                                                  liquidation_threshold: self.instruction.liquidation_threshold.clone().expect("liquidation_threshold is not set"),
488                                                                  limit_order_execution_fee: self.instruction.limit_order_execution_fee.clone().expect("limit_order_execution_fee is not set"),
489                                                                  oracle_price_deviation_threshold: self.instruction.oracle_price_deviation_threshold.clone().expect("oracle_price_deviation_threshold is not set"),
490                                                                  disabled: self.instruction.disabled.clone().expect("disabled is not set"),
491                                                                  borrow_limit_a: self.instruction.borrow_limit_a.clone().expect("borrow_limit_a is not set"),
492                                                                  borrow_limit_b: self.instruction.borrow_limit_b.clone().expect("borrow_limit_b is not set"),
493                                                                  max_swap_slippage: self.instruction.max_swap_slippage.clone().expect("max_swap_slippage is not set"),
494                                    };
495        let instruction = UpdateMarketCpi {
496        __program: self.instruction.__program,
497                  
498          authority: self.instruction.authority.expect("authority is not set"),
499                  
500          tuna_config: self.instruction.tuna_config.expect("tuna_config is not set"),
501                  
502          market: self.instruction.market.expect("market is not set"),
503                          __args: args,
504            };
505    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
506  }
507}
508
509#[derive(Clone, Debug)]
510struct UpdateMarketCpiBuilderInstruction<'a, 'b> {
511  __program: &'b solana_program::account_info::AccountInfo<'a>,
512            authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
513                tuna_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
514                market: Option<&'b solana_program::account_info::AccountInfo<'a>>,
515                        address_lookup_table: Option<Pubkey>,
516                max_leverage: Option<u32>,
517                protocol_fee: Option<u16>,
518                protocol_fee_on_collateral: Option<u16>,
519                liquidation_fee: Option<u32>,
520                liquidation_threshold: Option<u32>,
521                limit_order_execution_fee: Option<u32>,
522                oracle_price_deviation_threshold: Option<u32>,
523                disabled: Option<bool>,
524                borrow_limit_a: Option<u64>,
525                borrow_limit_b: Option<u64>,
526                max_swap_slippage: Option<u32>,
527        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
528  __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
529}
530