1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct InitializeBinArray {
14 pub lb_pair: solana_pubkey::Pubkey,
15
16 pub bin_array: solana_pubkey::Pubkey,
17
18 pub funder: solana_pubkey::Pubkey,
19
20 pub system_program: solana_pubkey::Pubkey,
21}
22
23impl InitializeBinArray {
24 pub fn instruction(
25 &self,
26 args: InitializeBinArrayInstructionArgs,
27 ) -> solana_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(
33 &self,
34 args: InitializeBinArrayInstructionArgs,
35 remaining_accounts: &[solana_instruction::AccountMeta],
36 ) -> solana_instruction::Instruction {
37 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
38 accounts.push(solana_instruction::AccountMeta::new_readonly(
39 self.lb_pair,
40 false,
41 ));
42 accounts.push(solana_instruction::AccountMeta::new(self.bin_array, false));
43 accounts.push(solana_instruction::AccountMeta::new(self.funder, true));
44 accounts.push(solana_instruction::AccountMeta::new_readonly(
45 self.system_program,
46 false,
47 ));
48 accounts.extend_from_slice(remaining_accounts);
49 let mut data = borsh::to_vec(&InitializeBinArrayInstructionData::new()).unwrap();
50 let mut args = borsh::to_vec(&args).unwrap();
51 data.append(&mut args);
52
53 solana_instruction::Instruction {
54 program_id: crate::LB_CLMM_ID,
55 accounts,
56 data,
57 }
58 }
59}
60
61#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63pub struct InitializeBinArrayInstructionData {
64 discriminator: [u8; 8],
65}
66
67impl InitializeBinArrayInstructionData {
68 pub fn new() -> Self {
69 Self {
70 discriminator: [35, 86, 19, 185, 78, 212, 75, 211],
71 }
72 }
73}
74
75impl Default for InitializeBinArrayInstructionData {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub struct InitializeBinArrayInstructionArgs {
84 pub index: i64,
85}
86
87#[derive(Clone, Debug, Default)]
96pub struct InitializeBinArrayBuilder {
97 lb_pair: Option<solana_pubkey::Pubkey>,
98 bin_array: Option<solana_pubkey::Pubkey>,
99 funder: Option<solana_pubkey::Pubkey>,
100 system_program: Option<solana_pubkey::Pubkey>,
101 index: Option<i64>,
102 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
103}
104
105impl InitializeBinArrayBuilder {
106 pub fn new() -> Self {
107 Self::default()
108 }
109 #[inline(always)]
110 pub fn lb_pair(&mut self, lb_pair: solana_pubkey::Pubkey) -> &mut Self {
111 self.lb_pair = Some(lb_pair);
112 self
113 }
114 #[inline(always)]
115 pub fn bin_array(&mut self, bin_array: solana_pubkey::Pubkey) -> &mut Self {
116 self.bin_array = Some(bin_array);
117 self
118 }
119 #[inline(always)]
120 pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
121 self.funder = Some(funder);
122 self
123 }
124 #[inline(always)]
126 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
127 self.system_program = Some(system_program);
128 self
129 }
130 #[inline(always)]
131 pub fn index(&mut self, index: i64) -> &mut Self {
132 self.index = Some(index);
133 self
134 }
135 #[inline(always)]
137 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
138 self.__remaining_accounts.push(account);
139 self
140 }
141 #[inline(always)]
143 pub fn add_remaining_accounts(
144 &mut self,
145 accounts: &[solana_instruction::AccountMeta],
146 ) -> &mut Self {
147 self.__remaining_accounts.extend_from_slice(accounts);
148 self
149 }
150 #[allow(clippy::clone_on_copy)]
151 pub fn instruction(&self) -> solana_instruction::Instruction {
152 let accounts = InitializeBinArray {
153 lb_pair: self.lb_pair.expect("lb_pair is not set"),
154 bin_array: self.bin_array.expect("bin_array is not set"),
155 funder: self.funder.expect("funder is not set"),
156 system_program: self
157 .system_program
158 .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
159 };
160 let args = InitializeBinArrayInstructionArgs {
161 index: self.index.clone().expect("index is not set"),
162 };
163
164 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
165 }
166}
167
168pub struct InitializeBinArrayCpiAccounts<'a, 'b> {
170 pub lb_pair: &'b solana_account_info::AccountInfo<'a>,
171
172 pub bin_array: &'b solana_account_info::AccountInfo<'a>,
173
174 pub funder: &'b solana_account_info::AccountInfo<'a>,
175
176 pub system_program: &'b solana_account_info::AccountInfo<'a>,
177}
178
179pub struct InitializeBinArrayCpi<'a, 'b> {
181 pub __program: &'b solana_account_info::AccountInfo<'a>,
183
184 pub lb_pair: &'b solana_account_info::AccountInfo<'a>,
185
186 pub bin_array: &'b solana_account_info::AccountInfo<'a>,
187
188 pub funder: &'b solana_account_info::AccountInfo<'a>,
189
190 pub system_program: &'b solana_account_info::AccountInfo<'a>,
191 pub __args: InitializeBinArrayInstructionArgs,
193}
194
195impl<'a, 'b> InitializeBinArrayCpi<'a, 'b> {
196 pub fn new(
197 program: &'b solana_account_info::AccountInfo<'a>,
198 accounts: InitializeBinArrayCpiAccounts<'a, 'b>,
199 args: InitializeBinArrayInstructionArgs,
200 ) -> Self {
201 Self {
202 __program: program,
203 lb_pair: accounts.lb_pair,
204 bin_array: accounts.bin_array,
205 funder: accounts.funder,
206 system_program: accounts.system_program,
207 __args: args,
208 }
209 }
210 #[inline(always)]
211 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
212 self.invoke_signed_with_remaining_accounts(&[], &[])
213 }
214 #[inline(always)]
215 pub fn invoke_with_remaining_accounts(
216 &self,
217 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
218 ) -> solana_program_entrypoint::ProgramResult {
219 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
220 }
221 #[inline(always)]
222 pub fn invoke_signed(
223 &self,
224 signers_seeds: &[&[&[u8]]],
225 ) -> solana_program_entrypoint::ProgramResult {
226 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
227 }
228 #[allow(clippy::arithmetic_side_effects)]
229 #[allow(clippy::clone_on_copy)]
230 #[allow(clippy::vec_init_then_push)]
231 pub fn invoke_signed_with_remaining_accounts(
232 &self,
233 signers_seeds: &[&[&[u8]]],
234 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
235 ) -> solana_program_entrypoint::ProgramResult {
236 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
237 accounts.push(solana_instruction::AccountMeta::new_readonly(
238 *self.lb_pair.key,
239 false,
240 ));
241 accounts.push(solana_instruction::AccountMeta::new(
242 *self.bin_array.key,
243 false,
244 ));
245 accounts.push(solana_instruction::AccountMeta::new(*self.funder.key, true));
246 accounts.push(solana_instruction::AccountMeta::new_readonly(
247 *self.system_program.key,
248 false,
249 ));
250 remaining_accounts.iter().for_each(|remaining_account| {
251 accounts.push(solana_instruction::AccountMeta {
252 pubkey: *remaining_account.0.key,
253 is_signer: remaining_account.1,
254 is_writable: remaining_account.2,
255 })
256 });
257 let mut data = borsh::to_vec(&InitializeBinArrayInstructionData::new()).unwrap();
258 let mut args = borsh::to_vec(&self.__args).unwrap();
259 data.append(&mut args);
260
261 let instruction = solana_instruction::Instruction {
262 program_id: crate::LB_CLMM_ID,
263 accounts,
264 data,
265 };
266 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
267 account_infos.push(self.__program.clone());
268 account_infos.push(self.lb_pair.clone());
269 account_infos.push(self.bin_array.clone());
270 account_infos.push(self.funder.clone());
271 account_infos.push(self.system_program.clone());
272 remaining_accounts
273 .iter()
274 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
275
276 if signers_seeds.is_empty() {
277 solana_cpi::invoke(&instruction, &account_infos)
278 } else {
279 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
280 }
281 }
282}
283
284#[derive(Clone, Debug)]
293pub struct InitializeBinArrayCpiBuilder<'a, 'b> {
294 instruction: Box<InitializeBinArrayCpiBuilderInstruction<'a, 'b>>,
295}
296
297impl<'a, 'b> InitializeBinArrayCpiBuilder<'a, 'b> {
298 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
299 let instruction = Box::new(InitializeBinArrayCpiBuilderInstruction {
300 __program: program,
301 lb_pair: None,
302 bin_array: None,
303 funder: None,
304 system_program: None,
305 index: None,
306 __remaining_accounts: Vec::new(),
307 });
308 Self { instruction }
309 }
310 #[inline(always)]
311 pub fn lb_pair(&mut self, lb_pair: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
312 self.instruction.lb_pair = Some(lb_pair);
313 self
314 }
315 #[inline(always)]
316 pub fn bin_array(&mut self, bin_array: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
317 self.instruction.bin_array = Some(bin_array);
318 self
319 }
320 #[inline(always)]
321 pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
322 self.instruction.funder = Some(funder);
323 self
324 }
325 #[inline(always)]
326 pub fn system_program(
327 &mut self,
328 system_program: &'b solana_account_info::AccountInfo<'a>,
329 ) -> &mut Self {
330 self.instruction.system_program = Some(system_program);
331 self
332 }
333 #[inline(always)]
334 pub fn index(&mut self, index: i64) -> &mut Self {
335 self.instruction.index = Some(index);
336 self
337 }
338 #[inline(always)]
340 pub fn add_remaining_account(
341 &mut self,
342 account: &'b solana_account_info::AccountInfo<'a>,
343 is_writable: bool,
344 is_signer: bool,
345 ) -> &mut Self {
346 self.instruction
347 .__remaining_accounts
348 .push((account, is_writable, is_signer));
349 self
350 }
351 #[inline(always)]
356 pub fn add_remaining_accounts(
357 &mut self,
358 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
359 ) -> &mut Self {
360 self.instruction
361 .__remaining_accounts
362 .extend_from_slice(accounts);
363 self
364 }
365 #[inline(always)]
366 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
367 self.invoke_signed(&[])
368 }
369 #[allow(clippy::clone_on_copy)]
370 #[allow(clippy::vec_init_then_push)]
371 pub fn invoke_signed(
372 &self,
373 signers_seeds: &[&[&[u8]]],
374 ) -> solana_program_entrypoint::ProgramResult {
375 let args = InitializeBinArrayInstructionArgs {
376 index: self.instruction.index.clone().expect("index is not set"),
377 };
378 let instruction = InitializeBinArrayCpi {
379 __program: self.instruction.__program,
380
381 lb_pair: self.instruction.lb_pair.expect("lb_pair is not set"),
382
383 bin_array: self.instruction.bin_array.expect("bin_array is not set"),
384
385 funder: self.instruction.funder.expect("funder is not set"),
386
387 system_program: self
388 .instruction
389 .system_program
390 .expect("system_program is not set"),
391 __args: args,
392 };
393 instruction.invoke_signed_with_remaining_accounts(
394 signers_seeds,
395 &self.instruction.__remaining_accounts,
396 )
397 }
398}
399
400#[derive(Clone, Debug)]
401struct InitializeBinArrayCpiBuilderInstruction<'a, 'b> {
402 __program: &'b solana_account_info::AccountInfo<'a>,
403 lb_pair: Option<&'b solana_account_info::AccountInfo<'a>>,
404 bin_array: Option<&'b solana_account_info::AccountInfo<'a>>,
405 funder: Option<&'b solana_account_info::AccountInfo<'a>>,
406 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
407 index: Option<i64>,
408 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
410}