metadata.rs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. use anchor_lang::context::CpiContext;
  2. use anchor_lang::{Accounts, Result, ToAccountInfos};
  3. use mpl_token_metadata::state::DataV2;
  4. use mpl_token_metadata::ID;
  5. use solana_program::account_info::AccountInfo;
  6. use solana_program::pubkey::Pubkey;
  7. #[derive(Clone)]
  8. pub struct Metadata;
  9. impl anchor_lang::Id for Metadata {
  10. fn id() -> Pubkey {
  11. ID
  12. }
  13. }
  14. pub fn create_metadata_accounts_v2<'info>(
  15. ctx: CpiContext<'_, '_, '_, 'info, CreateMetadataAccountsV2<'info>>,
  16. data: DataV2,
  17. is_mutable: bool,
  18. ) -> Result<()> {
  19. let update_authority_is_signer = true;
  20. let DataV2 {
  21. name,
  22. symbol,
  23. uri,
  24. creators,
  25. seller_fee_basis_points,
  26. collection,
  27. uses,
  28. } = data;
  29. let ix = mpl_token_metadata::instruction::create_metadata_accounts_v2(
  30. ID,
  31. *ctx.accounts.metadata.key,
  32. *ctx.accounts.mint.key,
  33. *ctx.accounts.mint_authority.key,
  34. *ctx.accounts.payer.key,
  35. *ctx.accounts.update_authority.key,
  36. name,
  37. symbol,
  38. uri,
  39. creators,
  40. seller_fee_basis_points,
  41. update_authority_is_signer,
  42. is_mutable,
  43. collection,
  44. uses,
  45. );
  46. solana_program::program::invoke_signed(
  47. &ix,
  48. &ToAccountInfos::to_account_infos(&ctx),
  49. ctx.signer_seeds,
  50. )?;
  51. Ok(())
  52. }
  53. pub fn create_master_edition_v3<'info>(
  54. ctx: CpiContext<'_, '_, '_, 'info, CreateMasterEditionV3<'info>>,
  55. max_supply: Option<u64>,
  56. ) -> Result<()> {
  57. let ix = mpl_token_metadata::instruction::create_master_edition_v3(
  58. ID,
  59. *ctx.accounts.edition.key,
  60. *ctx.accounts.mint.key,
  61. *ctx.accounts.update_authority.key,
  62. *ctx.accounts.mint_authority.key,
  63. *ctx.accounts.metadata.key,
  64. *ctx.accounts.payer.key,
  65. max_supply,
  66. );
  67. solana_program::program::invoke_signed(
  68. &ix,
  69. &ToAccountInfos::to_account_infos(&ctx),
  70. ctx.signer_seeds,
  71. )?;
  72. Ok(())
  73. }
  74. pub fn mint_new_edition_from_master_edition_via_token<'info>(
  75. ctx: CpiContext<'_, '_, '_, 'info, MintNewEditionFromMasterEditionViaToken<'info>>,
  76. edition: u64,
  77. ) -> Result<()> {
  78. let ix = mpl_token_metadata::instruction::mint_new_edition_from_master_edition_via_token(
  79. ID,
  80. *ctx.accounts.new_metadata.key,
  81. *ctx.accounts.new_edition.key,
  82. *ctx.accounts.master_edition.key,
  83. *ctx.accounts.new_mint.key,
  84. *ctx.accounts.new_mint_authority.key,
  85. *ctx.accounts.payer.key,
  86. *ctx.accounts.token_account_owner.key,
  87. *ctx.accounts.token_account.key,
  88. *ctx.accounts.new_metadata_update_authority.key,
  89. *ctx.accounts.metadata.key,
  90. *ctx.accounts.metadata_mint.key,
  91. edition,
  92. );
  93. solana_program::program::invoke_signed(
  94. &ix,
  95. &ToAccountInfos::to_account_infos(&ctx),
  96. ctx.signer_seeds,
  97. )?;
  98. Ok(())
  99. }
  100. #[derive(Accounts)]
  101. pub struct CreateMetadataAccountsV2<'info> {
  102. pub metadata: AccountInfo<'info>,
  103. pub mint: AccountInfo<'info>,
  104. pub mint_authority: AccountInfo<'info>,
  105. pub payer: AccountInfo<'info>,
  106. pub update_authority: AccountInfo<'info>,
  107. pub system_program: AccountInfo<'info>,
  108. pub rent: AccountInfo<'info>,
  109. }
  110. #[derive(Accounts)]
  111. pub struct CreateMasterEditionV3<'info> {
  112. pub edition: AccountInfo<'info>,
  113. pub mint: AccountInfo<'info>,
  114. pub update_authority: AccountInfo<'info>,
  115. pub mint_authority: AccountInfo<'info>,
  116. pub payer: AccountInfo<'info>,
  117. pub metadata: AccountInfo<'info>,
  118. pub token_program: AccountInfo<'info>,
  119. pub system_program: AccountInfo<'info>,
  120. pub rent: AccountInfo<'info>,
  121. }
  122. #[derive(Accounts)]
  123. pub struct MintNewEditionFromMasterEditionViaToken<'info> {
  124. pub new_metadata: AccountInfo<'info>,
  125. pub new_edition: AccountInfo<'info>,
  126. pub master_edition: AccountInfo<'info>,
  127. pub new_mint: AccountInfo<'info>,
  128. pub edition_mark_pda: AccountInfo<'info>,
  129. pub new_mint_authority: AccountInfo<'info>,
  130. pub payer: AccountInfo<'info>,
  131. pub token_account_owner: AccountInfo<'info>,
  132. pub token_account: AccountInfo<'info>,
  133. pub new_metadata_update_authority: AccountInfo<'info>,
  134. pub metadata: AccountInfo<'info>,
  135. pub token_program: AccountInfo<'info>,
  136. pub system_program: AccountInfo<'info>,
  137. pub rent: AccountInfo<'info>,
  138. //
  139. // Not actually used by the program but still needed because it's needed
  140. // for the pda calculation in the helper. :/
  141. //
  142. // The better thing to do would be to remove this and have the instruction
  143. // helper pass in the `edition_mark_pda` directly.
  144. //
  145. pub metadata_mint: AccountInfo<'info>,
  146. }