|
@@ -1,7 +1,7 @@
|
|
|
use {
|
|
|
anchor_lang::{
|
|
|
prelude::*,
|
|
|
- solana_program::program::invoke,
|
|
|
+ solana_program::program::invoke_signed,
|
|
|
system_program,
|
|
|
},
|
|
|
anchor_spl::token,
|
|
@@ -14,9 +14,10 @@ pub fn create_token_mint(
|
|
|
metadata_title: String,
|
|
|
metadata_symbol: String,
|
|
|
metadata_uri: String,
|
|
|
+ mint_authority_pda_bump: u8,
|
|
|
) -> Result<()> {
|
|
|
|
|
|
- const MINT_SIZE: u64 = 82;
|
|
|
+ let mint_authority = &mut ctx.accounts.mint_authority;
|
|
|
|
|
|
msg!("Creating mint account...");
|
|
|
msg!("Mint: {}", &ctx.accounts.mint_account.key());
|
|
@@ -24,12 +25,12 @@ pub fn create_token_mint(
|
|
|
CpiContext::new(
|
|
|
ctx.accounts.token_program.to_account_info(),
|
|
|
system_program::CreateAccount {
|
|
|
- from: ctx.accounts.mint_authority.to_account_info(),
|
|
|
+ from: ctx.accounts.payer.to_account_info(),
|
|
|
to: ctx.accounts.mint_account.to_account_info(),
|
|
|
},
|
|
|
),
|
|
|
- (Rent::get()?).minimum_balance(MINT_SIZE as usize),
|
|
|
- MINT_SIZE,
|
|
|
+ (Rent::get()?).minimum_balance(token::Mint::LEN),
|
|
|
+ token::Mint::LEN as u64,
|
|
|
&ctx.accounts.token_program.key(),
|
|
|
)?;
|
|
|
|
|
@@ -44,20 +45,20 @@ pub fn create_token_mint(
|
|
|
},
|
|
|
),
|
|
|
9, // 9 Decimals
|
|
|
- &ctx.accounts.mint_authority.key(),
|
|
|
- Some(&ctx.accounts.mint_authority.key()),
|
|
|
+ &mint_authority.key(),
|
|
|
+ Some(&mint_authority.key()),
|
|
|
)?;
|
|
|
|
|
|
msg!("Creating metadata account...");
|
|
|
msg!("Metadata account address: {}", &ctx.accounts.metadata_account.key());
|
|
|
- invoke(
|
|
|
+ invoke_signed(
|
|
|
&mpl_instruction::create_metadata_accounts_v2(
|
|
|
ctx.accounts.token_metadata_program.key(), // Program ID (the Token Metadata Program)
|
|
|
ctx.accounts.metadata_account.key(), // Metadata account
|
|
|
ctx.accounts.mint_account.key(), // Mint account
|
|
|
- ctx.accounts.mint_authority.key(), // Mint authority
|
|
|
- ctx.accounts.mint_authority.key(), // Payer
|
|
|
- ctx.accounts.mint_authority.key(), // Update authority
|
|
|
+ mint_authority.key(), // Mint authority
|
|
|
+ ctx.accounts.payer.key(), // Payer
|
|
|
+ mint_authority.key(), // Update authority
|
|
|
metadata_title, // Name
|
|
|
metadata_symbol, // Symbol
|
|
|
metadata_uri, // URI
|
|
@@ -71,10 +72,17 @@ pub fn create_token_mint(
|
|
|
&[
|
|
|
ctx.accounts.metadata_account.to_account_info(),
|
|
|
ctx.accounts.mint_account.to_account_info(),
|
|
|
- ctx.accounts.mint_authority.to_account_info(),
|
|
|
+ mint_authority.to_account_info(),
|
|
|
+ ctx.accounts.payer.to_account_info(),
|
|
|
+ mint_authority.to_account_info(),
|
|
|
ctx.accounts.token_metadata_program.to_account_info(),
|
|
|
ctx.accounts.rent.to_account_info(),
|
|
|
],
|
|
|
+ &[&[
|
|
|
+ b"mint_authority_",
|
|
|
+ ctx.accounts.mint_account.key().as_ref(),
|
|
|
+ &[mint_authority_pda_bump],
|
|
|
+ ]]
|
|
|
)?;
|
|
|
|
|
|
msg!("Token mint created successfully.");
|
|
@@ -90,11 +98,22 @@ pub struct CreateTokenMint<'info> {
|
|
|
pub metadata_account: UncheckedAccount<'info>,
|
|
|
#[account(mut)]
|
|
|
pub mint_account: Signer<'info>,
|
|
|
+ #[account(
|
|
|
+ init,
|
|
|
+ payer = payer,
|
|
|
+ space = 8 + 32,
|
|
|
+ seeds = [b"mint_authority_", mint_account.key().as_ref()],
|
|
|
+ bump
|
|
|
+ )]
|
|
|
+ pub mint_authority: Account<'info, MintAuthorityPda>,
|
|
|
#[account(mut)]
|
|
|
- pub mint_authority: Signer<'info>,
|
|
|
+ pub payer: Signer<'info>,
|
|
|
pub rent: Sysvar<'info, Rent>,
|
|
|
pub system_program: Program<'info, System>,
|
|
|
pub token_program: Program<'info, token::Token>,
|
|
|
/// CHECK: Metaplex will check this
|
|
|
pub token_metadata_program: UncheckedAccount<'info>,
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+#[account]
|
|
|
+pub struct MintAuthorityPda {}
|