Skip to main content

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