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