Browse Source

mint authority

jpcaulfi 3 years ago
parent
commit
52db60ae47

+ 16 - 34
tokens/mint-to/anchor/programs/mint-token-to/src/instructions/create_token_mint.rs

@@ -5,7 +5,10 @@ use {
         system_program,
     },
     anchor_spl::token,
-    mpl_token_metadata::instruction as mpl_instruction,
+    mpl_token_metadata::{
+        instruction as mpl_instruction,
+        state::Metadata,
+    },
 };
 
 
@@ -19,36 +22,6 @@ pub fn create_token_mint(
 
     let mint_authority = &mut ctx.accounts.mint_authority;
 
-    msg!("Creating mint account...");
-    msg!("Mint: {}", &ctx.accounts.mint_account.key());
-    system_program::create_account(
-        CpiContext::new(
-            ctx.accounts.token_program.to_account_info(),
-            system_program::CreateAccount {
-                from: ctx.accounts.payer.to_account_info(),
-                to: ctx.accounts.mint_account.to_account_info(),
-            },
-        ),
-        (Rent::get()?).minimum_balance(token::Mint::LEN),
-        token::Mint::LEN as u64,
-        &ctx.accounts.token_program.key(),
-    )?;
-
-    msg!("Initializing mint account...");
-    msg!("Mint: {}", &ctx.accounts.mint_account.key());
-    token::initialize_mint(
-        CpiContext::new(
-            ctx.accounts.token_program.to_account_info(),
-            token::InitializeMint {
-                mint: ctx.accounts.mint_account.to_account_info(),
-                rent: ctx.accounts.rent.to_account_info(),
-            },
-        ),
-        9,                                              // 9 Decimals
-        &mint_authority.key(),
-        Some(&mint_authority.key()),
-    )?;
-
     msg!("Creating metadata account...");
     msg!("Metadata account address: {}", &ctx.accounts.metadata_account.key());
     invoke_signed(
@@ -96,13 +69,22 @@ pub struct CreateTokenMint<'info> {
     /// CHECK: We're about to create this with Metaplex
     #[account(mut)]
     pub metadata_account: UncheckedAccount<'info>,
-    #[account(mut)]
-    pub mint_account: Signer<'info>,
+    #[account(
+        init,
+        payer = payer,
+        mint::decimals = 9,
+        mint::authority = mint_authority.key(),
+        owner = token_program.key(),
+    )]
+    pub mint_account: Account<'info, token::Mint>,
     #[account(
         init, 
         payer = payer,
         space = 8 + 32,
-        seeds = [b"mint_authority_", mint_account.key().as_ref()],
+        seeds = [
+            b"mint_authority_", 
+            mint_account.key().as_ref(),
+        ],
         bump
     )]
     pub mint_authority: Account<'info, MintAuthorityPda>,

+ 2 - 2
tokens/mint-to/anchor/tests/test.ts

@@ -33,14 +33,14 @@ describe("mint-token", () => {
     console.log(`PDA: ${mintAuthorityPda}`);
     console.log(`Bump: ${mintAuthorityPdaBump}`);
 
-    const metadataAddress = (await anchor.web3.PublicKey.findProgramAddress(
+    const [metadataAddress, metadataBump] = await anchor.web3.PublicKey.findProgramAddress(
       [
         Buffer.from("metadata"),
         TOKEN_METADATA_PROGRAM_ID.toBuffer(),
         mintKeypair.publicKey.toBuffer(),
       ],
       TOKEN_METADATA_PROGRAM_ID
-    ))[0];
+    );
 
     await program.methods.createTokenMint(
       testTokenTitle, testTokenSymbol, testTokenUri, mintAuthorityPdaBump