1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct CreateTreeConfigV2 {
13 pub tree_config: solana_program::pubkey::Pubkey,
14
15 pub merkle_tree: solana_program::pubkey::Pubkey,
16
17 pub payer: solana_program::pubkey::Pubkey,
18 pub tree_creator: Option<solana_program::pubkey::Pubkey>,
20
21 pub log_wrapper: solana_program::pubkey::Pubkey,
22
23 pub compression_program: solana_program::pubkey::Pubkey,
24
25 pub system_program: solana_program::pubkey::Pubkey,
26}
27
28impl CreateTreeConfigV2 {
29 pub fn instruction(
30 &self,
31 args: CreateTreeConfigV2InstructionArgs,
32 ) -> solana_program::instruction::Instruction {
33 self.instruction_with_remaining_accounts(args, &[])
34 }
35 #[allow(clippy::vec_init_then_push)]
36 pub fn instruction_with_remaining_accounts(
37 &self,
38 args: CreateTreeConfigV2InstructionArgs,
39 remaining_accounts: &[solana_program::instruction::AccountMeta],
40 ) -> solana_program::instruction::Instruction {
41 let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
42 accounts.push(solana_program::instruction::AccountMeta::new(
43 self.tree_config,
44 false,
45 ));
46 accounts.push(solana_program::instruction::AccountMeta::new(
47 self.merkle_tree,
48 false,
49 ));
50 accounts.push(solana_program::instruction::AccountMeta::new(
51 self.payer, true,
52 ));
53 if let Some(tree_creator) = self.tree_creator {
54 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55 tree_creator,
56 true,
57 ));
58 } else {
59 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
60 crate::MPL_BUBBLEGUM_ID,
61 false,
62 ));
63 }
64 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
65 self.log_wrapper,
66 false,
67 ));
68 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
69 self.compression_program,
70 false,
71 ));
72 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
73 self.system_program,
74 false,
75 ));
76 accounts.extend_from_slice(remaining_accounts);
77 let mut data = CreateTreeConfigV2InstructionData::new()
78 .try_to_vec()
79 .unwrap();
80 let mut args = args.try_to_vec().unwrap();
81 data.append(&mut args);
82
83 solana_program::instruction::Instruction {
84 program_id: crate::MPL_BUBBLEGUM_ID,
85 accounts,
86 data,
87 }
88 }
89}
90
91#[derive(BorshDeserialize, BorshSerialize)]
92struct CreateTreeConfigV2InstructionData {
93 discriminator: [u8; 8],
94}
95
96impl CreateTreeConfigV2InstructionData {
97 fn new() -> Self {
98 Self {
99 discriminator: [55, 99, 95, 215, 142, 203, 227, 205],
100 }
101 }
102}
103
104#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106pub struct CreateTreeConfigV2InstructionArgs {
107 pub max_depth: u32,
108 pub max_buffer_size: u32,
109 pub public: Option<bool>,
110}
111
112#[derive(Default)]
114pub struct CreateTreeConfigV2Builder {
115 tree_config: Option<solana_program::pubkey::Pubkey>,
116 merkle_tree: Option<solana_program::pubkey::Pubkey>,
117 payer: Option<solana_program::pubkey::Pubkey>,
118 tree_creator: Option<solana_program::pubkey::Pubkey>,
119 log_wrapper: Option<solana_program::pubkey::Pubkey>,
120 compression_program: Option<solana_program::pubkey::Pubkey>,
121 system_program: Option<solana_program::pubkey::Pubkey>,
122 max_depth: Option<u32>,
123 max_buffer_size: Option<u32>,
124 public: Option<bool>,
125 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
126}
127
128impl CreateTreeConfigV2Builder {
129 pub fn new() -> Self {
130 Self::default()
131 }
132 #[inline(always)]
133 pub fn tree_config(&mut self, tree_config: solana_program::pubkey::Pubkey) -> &mut Self {
134 self.tree_config = Some(tree_config);
135 self
136 }
137 #[inline(always)]
138 pub fn merkle_tree(&mut self, merkle_tree: solana_program::pubkey::Pubkey) -> &mut Self {
139 self.merkle_tree = Some(merkle_tree);
140 self
141 }
142 #[inline(always)]
143 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
144 self.payer = Some(payer);
145 self
146 }
147 #[inline(always)]
150 pub fn tree_creator(
151 &mut self,
152 tree_creator: Option<solana_program::pubkey::Pubkey>,
153 ) -> &mut Self {
154 self.tree_creator = tree_creator;
155 self
156 }
157 #[inline(always)]
159 pub fn log_wrapper(&mut self, log_wrapper: solana_program::pubkey::Pubkey) -> &mut Self {
160 self.log_wrapper = Some(log_wrapper);
161 self
162 }
163 #[inline(always)]
165 pub fn compression_program(
166 &mut self,
167 compression_program: solana_program::pubkey::Pubkey,
168 ) -> &mut Self {
169 self.compression_program = Some(compression_program);
170 self
171 }
172 #[inline(always)]
174 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
175 self.system_program = Some(system_program);
176 self
177 }
178 #[inline(always)]
179 pub fn max_depth(&mut self, max_depth: u32) -> &mut Self {
180 self.max_depth = Some(max_depth);
181 self
182 }
183 #[inline(always)]
184 pub fn max_buffer_size(&mut self, max_buffer_size: u32) -> &mut Self {
185 self.max_buffer_size = Some(max_buffer_size);
186 self
187 }
188 #[inline(always)]
190 pub fn public(&mut self, public: bool) -> &mut Self {
191 self.public = Some(public);
192 self
193 }
194 #[inline(always)]
196 pub fn add_remaining_account(
197 &mut self,
198 account: solana_program::instruction::AccountMeta,
199 ) -> &mut Self {
200 self.__remaining_accounts.push(account);
201 self
202 }
203 #[inline(always)]
205 pub fn add_remaining_accounts(
206 &mut self,
207 accounts: &[solana_program::instruction::AccountMeta],
208 ) -> &mut Self {
209 self.__remaining_accounts.extend_from_slice(accounts);
210 self
211 }
212 #[allow(clippy::clone_on_copy)]
213 pub fn instruction(&self) -> solana_program::instruction::Instruction {
214 let accounts = CreateTreeConfigV2 {
215 tree_config: self.tree_config.expect("tree_config is not set"),
216 merkle_tree: self.merkle_tree.expect("merkle_tree is not set"),
217 payer: self.payer.expect("payer is not set"),
218 tree_creator: self.tree_creator,
219 log_wrapper: self.log_wrapper.unwrap_or(solana_program::pubkey!(
220 "mnoopTCrg4p8ry25e4bcWA9XZjbNjMTfgYVGGEdRsf3"
221 )),
222 compression_program: self.compression_program.unwrap_or(solana_program::pubkey!(
223 "mcmt6YrQEMKw8Mw43FmpRLmf7BqRnFMKmAcbxE3xkAW"
224 )),
225 system_program: self
226 .system_program
227 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
228 };
229 let args = CreateTreeConfigV2InstructionArgs {
230 max_depth: self.max_depth.clone().expect("max_depth is not set"),
231 max_buffer_size: self
232 .max_buffer_size
233 .clone()
234 .expect("max_buffer_size is not set"),
235 public: self.public.clone(),
236 };
237
238 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
239 }
240}
241
242pub struct CreateTreeConfigV2CpiAccounts<'a, 'b> {
244 pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
245
246 pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
247
248 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
249 pub tree_creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
251
252 pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
253
254 pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
255
256 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
257}
258
259pub struct CreateTreeConfigV2Cpi<'a, 'b> {
261 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
263
264 pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
265
266 pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
267
268 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
269 pub tree_creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
271
272 pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
273
274 pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
275
276 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
277 pub __args: CreateTreeConfigV2InstructionArgs,
279}
280
281impl<'a, 'b> CreateTreeConfigV2Cpi<'a, 'b> {
282 pub fn new(
283 program: &'b solana_program::account_info::AccountInfo<'a>,
284 accounts: CreateTreeConfigV2CpiAccounts<'a, 'b>,
285 args: CreateTreeConfigV2InstructionArgs,
286 ) -> Self {
287 Self {
288 __program: program,
289 tree_config: accounts.tree_config,
290 merkle_tree: accounts.merkle_tree,
291 payer: accounts.payer,
292 tree_creator: accounts.tree_creator,
293 log_wrapper: accounts.log_wrapper,
294 compression_program: accounts.compression_program,
295 system_program: accounts.system_program,
296 __args: args,
297 }
298 }
299 #[inline(always)]
300 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
301 self.invoke_signed_with_remaining_accounts(&[], &[])
302 }
303 #[inline(always)]
304 pub fn invoke_with_remaining_accounts(
305 &self,
306 remaining_accounts: &[(
307 &'b solana_program::account_info::AccountInfo<'a>,
308 bool,
309 bool,
310 )],
311 ) -> solana_program::entrypoint::ProgramResult {
312 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
313 }
314 #[inline(always)]
315 pub fn invoke_signed(
316 &self,
317 signers_seeds: &[&[&[u8]]],
318 ) -> solana_program::entrypoint::ProgramResult {
319 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
320 }
321 #[allow(clippy::clone_on_copy)]
322 #[allow(clippy::vec_init_then_push)]
323 pub fn invoke_signed_with_remaining_accounts(
324 &self,
325 signers_seeds: &[&[&[u8]]],
326 remaining_accounts: &[(
327 &'b solana_program::account_info::AccountInfo<'a>,
328 bool,
329 bool,
330 )],
331 ) -> solana_program::entrypoint::ProgramResult {
332 let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
333 accounts.push(solana_program::instruction::AccountMeta::new(
334 *self.tree_config.key,
335 false,
336 ));
337 accounts.push(solana_program::instruction::AccountMeta::new(
338 *self.merkle_tree.key,
339 false,
340 ));
341 accounts.push(solana_program::instruction::AccountMeta::new(
342 *self.payer.key,
343 true,
344 ));
345 if let Some(tree_creator) = self.tree_creator {
346 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
347 *tree_creator.key,
348 true,
349 ));
350 } else {
351 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
352 crate::MPL_BUBBLEGUM_ID,
353 false,
354 ));
355 }
356 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
357 *self.log_wrapper.key,
358 false,
359 ));
360 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
361 *self.compression_program.key,
362 false,
363 ));
364 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
365 *self.system_program.key,
366 false,
367 ));
368 remaining_accounts.iter().for_each(|remaining_account| {
369 accounts.push(solana_program::instruction::AccountMeta {
370 pubkey: *remaining_account.0.key,
371 is_signer: remaining_account.1,
372 is_writable: remaining_account.2,
373 })
374 });
375 let mut data = CreateTreeConfigV2InstructionData::new()
376 .try_to_vec()
377 .unwrap();
378 let mut args = self.__args.try_to_vec().unwrap();
379 data.append(&mut args);
380
381 let instruction = solana_program::instruction::Instruction {
382 program_id: crate::MPL_BUBBLEGUM_ID,
383 accounts,
384 data,
385 };
386 let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len());
387 account_infos.push(self.__program.clone());
388 account_infos.push(self.tree_config.clone());
389 account_infos.push(self.merkle_tree.clone());
390 account_infos.push(self.payer.clone());
391 if let Some(tree_creator) = self.tree_creator {
392 account_infos.push(tree_creator.clone());
393 }
394 account_infos.push(self.log_wrapper.clone());
395 account_infos.push(self.compression_program.clone());
396 account_infos.push(self.system_program.clone());
397 remaining_accounts
398 .iter()
399 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
400
401 if signers_seeds.is_empty() {
402 solana_program::program::invoke(&instruction, &account_infos)
403 } else {
404 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
405 }
406 }
407}
408
409pub struct CreateTreeConfigV2CpiBuilder<'a, 'b> {
411 instruction: Box<CreateTreeConfigV2CpiBuilderInstruction<'a, 'b>>,
412}
413
414impl<'a, 'b> CreateTreeConfigV2CpiBuilder<'a, 'b> {
415 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
416 let instruction = Box::new(CreateTreeConfigV2CpiBuilderInstruction {
417 __program: program,
418 tree_config: None,
419 merkle_tree: None,
420 payer: None,
421 tree_creator: None,
422 log_wrapper: None,
423 compression_program: None,
424 system_program: None,
425 max_depth: None,
426 max_buffer_size: None,
427 public: None,
428 __remaining_accounts: Vec::new(),
429 });
430 Self { instruction }
431 }
432 #[inline(always)]
433 pub fn tree_config(
434 &mut self,
435 tree_config: &'b solana_program::account_info::AccountInfo<'a>,
436 ) -> &mut Self {
437 self.instruction.tree_config = Some(tree_config);
438 self
439 }
440 #[inline(always)]
441 pub fn merkle_tree(
442 &mut self,
443 merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
444 ) -> &mut Self {
445 self.instruction.merkle_tree = Some(merkle_tree);
446 self
447 }
448 #[inline(always)]
449 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
450 self.instruction.payer = Some(payer);
451 self
452 }
453 #[inline(always)]
456 pub fn tree_creator(
457 &mut self,
458 tree_creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
459 ) -> &mut Self {
460 self.instruction.tree_creator = tree_creator;
461 self
462 }
463 #[inline(always)]
464 pub fn log_wrapper(
465 &mut self,
466 log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
467 ) -> &mut Self {
468 self.instruction.log_wrapper = Some(log_wrapper);
469 self
470 }
471 #[inline(always)]
472 pub fn compression_program(
473 &mut self,
474 compression_program: &'b solana_program::account_info::AccountInfo<'a>,
475 ) -> &mut Self {
476 self.instruction.compression_program = Some(compression_program);
477 self
478 }
479 #[inline(always)]
480 pub fn system_program(
481 &mut self,
482 system_program: &'b solana_program::account_info::AccountInfo<'a>,
483 ) -> &mut Self {
484 self.instruction.system_program = Some(system_program);
485 self
486 }
487 #[inline(always)]
488 pub fn max_depth(&mut self, max_depth: u32) -> &mut Self {
489 self.instruction.max_depth = Some(max_depth);
490 self
491 }
492 #[inline(always)]
493 pub fn max_buffer_size(&mut self, max_buffer_size: u32) -> &mut Self {
494 self.instruction.max_buffer_size = Some(max_buffer_size);
495 self
496 }
497 #[inline(always)]
499 pub fn public(&mut self, public: bool) -> &mut Self {
500 self.instruction.public = Some(public);
501 self
502 }
503 #[inline(always)]
505 pub fn add_remaining_account(
506 &mut self,
507 account: &'b solana_program::account_info::AccountInfo<'a>,
508 is_writable: bool,
509 is_signer: bool,
510 ) -> &mut Self {
511 self.instruction
512 .__remaining_accounts
513 .push((account, is_writable, is_signer));
514 self
515 }
516 #[inline(always)]
521 pub fn add_remaining_accounts(
522 &mut self,
523 accounts: &[(
524 &'b solana_program::account_info::AccountInfo<'a>,
525 bool,
526 bool,
527 )],
528 ) -> &mut Self {
529 self.instruction
530 .__remaining_accounts
531 .extend_from_slice(accounts);
532 self
533 }
534 #[inline(always)]
535 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
536 self.invoke_signed(&[])
537 }
538 #[allow(clippy::clone_on_copy)]
539 #[allow(clippy::vec_init_then_push)]
540 pub fn invoke_signed(
541 &self,
542 signers_seeds: &[&[&[u8]]],
543 ) -> solana_program::entrypoint::ProgramResult {
544 let args = CreateTreeConfigV2InstructionArgs {
545 max_depth: self
546 .instruction
547 .max_depth
548 .clone()
549 .expect("max_depth is not set"),
550 max_buffer_size: self
551 .instruction
552 .max_buffer_size
553 .clone()
554 .expect("max_buffer_size is not set"),
555 public: self.instruction.public.clone(),
556 };
557 let instruction = CreateTreeConfigV2Cpi {
558 __program: self.instruction.__program,
559
560 tree_config: self
561 .instruction
562 .tree_config
563 .expect("tree_config is not set"),
564
565 merkle_tree: self
566 .instruction
567 .merkle_tree
568 .expect("merkle_tree is not set"),
569
570 payer: self.instruction.payer.expect("payer is not set"),
571
572 tree_creator: self.instruction.tree_creator,
573
574 log_wrapper: self
575 .instruction
576 .log_wrapper
577 .expect("log_wrapper is not set"),
578
579 compression_program: self
580 .instruction
581 .compression_program
582 .expect("compression_program is not set"),
583
584 system_program: self
585 .instruction
586 .system_program
587 .expect("system_program is not set"),
588 __args: args,
589 };
590 instruction.invoke_signed_with_remaining_accounts(
591 signers_seeds,
592 &self.instruction.__remaining_accounts,
593 )
594 }
595}
596
597struct CreateTreeConfigV2CpiBuilderInstruction<'a, 'b> {
598 __program: &'b solana_program::account_info::AccountInfo<'a>,
599 tree_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
600 merkle_tree: Option<&'b solana_program::account_info::AccountInfo<'a>>,
601 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
602 tree_creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
603 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
604 compression_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
605 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
606 max_depth: Option<u32>,
607 max_buffer_size: Option<u32>,
608 public: Option<bool>,
609 __remaining_accounts: Vec<(
611 &'b solana_program::account_info::AccountInfo<'a>,
612 bool,
613 bool,
614 )>,
615}