Skip to main content

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