Skip to main content

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