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