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