Browse Source

added rent

jpcaulfi 3 years ago
parent
commit
501e6e45bc

+ 15 - 2
tokens/README.md

@@ -1,3 +1,16 @@
-## :warning: All token examples are on devnet!
+### :warning: All token examples are on devnet!
 
-`https://api.devnet.solana.com/`
+`https://api.devnet.solana.com/`
+
+### About Tokens
+
+Tokens on Solana are - like everything else on Solana - accounts! They:
+- are owned by the Token Program
+- can only be changed by the Token Program
+- have an associated Mint Authority - the only account that can mint new tokens (by calling the Token program)
+
+How they work:   
+:apple: `Mint Account` - stores information about the token.
+:handbag: `Associated Token Account` - stores a specific balance of the Mint Account (this is essentially a counter).
+
+> You can read all about tokens in [Solana's official SPL Token documentation](https://spl.solana.com/token).

+ 8 - 12
tokens/mint/README.md

@@ -2,15 +2,11 @@
 
 This example demonstrates how to create an SPl Token on Solana with some metadata such as a token symbol and icon.
 
-### About Tokens
-
-Tokens on Solana are - like everything else on Solana - accounts! They:
-- are owned by the Token Program
-- can only be changed by the Token Program
-- have an associated Mint Authority - the only account that can mint new tokens (by calling the Token program)
-
-How they work:   
-:apple: `Mint Account` - stores information about the token.
-:handbag: `Associated Token Account` - stores a specific balance of the Mint Account (this is essentially a counter).
-
-> You can read all about tokens in [Solana's official SPL Token documentation](https://spl.solana.com/token).
+### :key: Keys:
+
+- SPL Tokens by default have **9 decimals**, and **NFTs have 0 decimals**. "Decimals" here means the number of decimal; ie. a token with 3 decimals will be tracked in increments of 0.001.   
+- You can use [Metaplex's Token Metadata Program](https://docs.metaplex.com/) to create metadata for your token.
+- Steps:
+    1. Create an account for the Mint.
+    2. Initialize that account as a Mint Account.
+    3. Create a metadata account associated with that Mint Account.

+ 21 - 22
tokens/mint/anchor/programs/mint-token/src/lib.rs

@@ -5,10 +5,7 @@ use {
         system_program,
     },
     anchor_spl::token,
-    mpl_token_metadata::{
-        ID as TOKEN_METADATA_ID,
-        instruction as mpl_instruction,
-    },
+    mpl_token_metadata::instruction as mpl_instruction,
 };
 
 
@@ -26,6 +23,8 @@ pub mod mint_token {
         metadata_uri: String,
     ) -> Result<()> {
 
+        const MINT_SIZE: u64 = 82;
+
         msg!("Creating mint account...");
         msg!("Mint: {}", &ctx.accounts.mint_account.key());
         system_program::create_account(
@@ -36,8 +35,8 @@ pub mod mint_token {
                     to: ctx.accounts.mint_account.to_account_info(),
                 },
             ),
-            10000000,
-            82,
+            (Rent::get()?).minimum_balance(MINT_SIZE as usize),
+            MINT_SIZE,
             &ctx.accounts.token_program.key(),
         )?;
 
@@ -51,7 +50,7 @@ pub mod mint_token {
                     rent: ctx.accounts.rent.to_account_info(),
                 },
             ),
-            9,
+            9,                                              // 9 Decimals
             &ctx.accounts.mint_authority.key(),
             Some(&ctx.accounts.mint_authority.key()),
         )?;
@@ -60,21 +59,21 @@ pub mod mint_token {
         msg!("Metadata account address: {}", &ctx.accounts.metadata_account.key());
         invoke(
             &mpl_instruction::create_metadata_accounts_v2(
-                TOKEN_METADATA_ID, 
-                ctx.accounts.metadata_account.key(), 
-                ctx.accounts.mint_account.key(), 
-                ctx.accounts.mint_authority.key(), 
-                ctx.accounts.mint_authority.key(), 
-                ctx.accounts.mint_authority.key(), 
-                metadata_title, 
-                metadata_symbol, 
-                metadata_uri, 
-                None,
-                1,
-                true, 
-                false, 
-                None, 
-                None,
+                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
+                metadata_title,                                 // Name
+                metadata_symbol,                                // Symbol
+                metadata_uri,                                   // URI
+                None,                                           // Creators
+                0,                                              // Seller fee basis points
+                true,                                           // Update authority is signer
+                false,                                          // Is mutable
+                None,                                           // Collection
+                None,                                           // Uses
             ),
             &[
                 ctx.accounts.metadata_account.to_account_info(),

+ 22 - 19
tokens/mint/native/program/src/lib.rs

@@ -7,10 +7,11 @@ use {
         entrypoint, 
         entrypoint::ProgramResult, 
         msg, 
-        native_token::LAMPORTS_PER_SOL,
         program::invoke,
         pubkey::Pubkey,
+        rent::Rent,
         system_instruction,
+        sysvar::Sysvar,
     },
     spl_token::{
         instruction as token_instruction,
@@ -30,6 +31,8 @@ fn process_instruction(
     instruction_data: &[u8],
 ) -> ProgramResult {
 
+    const MINT_SIZE: u64 = 82;
+
     let accounts_iter = &mut accounts.iter();
 
     let mint_account = next_account_info(accounts_iter)?;
@@ -48,8 +51,8 @@ fn process_instruction(
         &system_instruction::create_account(
             &mint_authority.key,
             &mint_account.key,
-            LAMPORTS_PER_SOL,
-            82,
+            (Rent::get()?).minimum_balance(MINT_SIZE as usize),
+            MINT_SIZE,
             &token_program.key,
         ),
         &[
@@ -67,7 +70,7 @@ fn process_instruction(
             &mint_account.key,
             &mint_authority.key,
             Some(&mint_authority.key),
-            9,
+            9,                              // 9 Decimals
         )?,
         &[
             mint_account.clone(),
@@ -81,21 +84,21 @@ fn process_instruction(
     msg!("Metadata account address: {}", metadata_account.key);
     invoke(
         &mpl_instruction::create_metadata_accounts_v2(
-            *token_metadata_program.key, 
-            *metadata_account.key, 
-            *mint_account.key, 
-            *mint_authority.key, 
-            *mint_authority.key, 
-            *mint_authority.key, 
-            token_metadata.title,
-            token_metadata.symbol,
-            token_metadata.uri,
-            None,
-            1,
-            true, 
-            false, 
-            None, 
-            None,
+            *token_metadata_program.key,    // Program ID (the Token Metadata Program)
+            *metadata_account.key,          // Metadata Account
+            *mint_account.key,              // Mint Account
+            *mint_authority.key,            // Mint Authority
+            *mint_authority.key,            // Payer
+            *mint_authority.key,            // Update Authority
+            token_metadata.title,           // Name
+            token_metadata.symbol,          // Symbol
+            token_metadata.uri,             // URI
+            None,                           // Creators
+            0,                              // Seller fee basis points
+            true,                           // Update authority is signer
+            false,                          // Is mutable
+            None,                           // Collection
+            None,                           // Uses
         ),
         &[
             metadata_account.clone(),