Skip to content

Commit

Permalink
reorg to match readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcaulfi committed Jul 26, 2022
1 parent 598ab64 commit a283104
Show file tree
Hide file tree
Showing 116 changed files with 163 additions and 31 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[features]
seeds = false
[programs.localnet]
custom_instruction_data = "DgoL5J44aspizyUs9fcnpGEUJjWTLJRCfx8eYtUMYczf"
processing_instructions = "DgoL5J44aspizyUs9fcnpGEUJjWTLJRCfx8eYtUMYczf"

[registry]
url = "https://anchor.projectserum.com"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "custom-instruction-data"
name = "processing-instructions"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "custom_instruction_data"
name = "processing_instructions"

[features]
no-entrypoint = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_lang::prelude::*;
declare_id!("DgoL5J44aspizyUs9fcnpGEUJjWTLJRCfx8eYtUMYczf");

#[program]
pub mod custom_instruction_data {
pub mod processing_instructions {
use super::*;

// With Anchor, we just put instruction data in the function signature!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as anchor from "@project-serum/anchor";
import { CustomInstructionData } from "../target/types/custom_instruction_data";
import { ProcessingInstructions } from "../target/types/processing_instructions";


describe("custom-instruction-data", () => {

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.CustomInstructionData as anchor.Program<CustomInstructionData>;
const program = anchor.workspace.ProcessingInstructions as anchor.Program<ProcessingInstructions>;

it("Go to the park!", async () => {

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub fn create_token_mint(
ctx.accounts.mint_authority.to_account_info(),
ctx.accounts.payer.to_account_info(),
ctx.accounts.mint_authority.to_account_info(),
ctx.accounts.token_metadata_program.to_account_info(),
ctx.accounts.rent.to_account_info(),
],
&[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use {
anchor_lang::prelude::*,
anchor_spl::{
token,
associated_token,
},
};
use crate::create_token_mint::MintAuthorityPda;


pub fn mint_to_another_wallet(
ctx: Context<MintToAnotherWallet>,
amount: u64,
mint_authority_pda_bump: u8,
) -> Result<()> {

msg!("Minting token to token account...");
msg!("Mint: {}", &ctx.accounts.mint_account.to_account_info().key());
msg!("Token Address: {}", &ctx.accounts.token_account.key());
token::mint_to(
CpiContext::new_with_signer(
ctx.accounts.token_program.to_account_info(),
token::MintTo {
mint: ctx.accounts.mint_account.to_account_info(),
to: ctx.accounts.token_account.to_account_info(),
authority: ctx.accounts.mint_authority.to_account_info(),
},
&[&[
b"mint_authority_",
ctx.accounts.mint_account.key().as_ref(),
&[mint_authority_pda_bump],
]]
),
amount,
)?;

msg!("Token minted to wallet successfully.");

Ok(())
}


#[derive(Accounts)]
#[instruction(amount: u64, mint_authority_pda_bump: u8)]
pub struct MintToAnotherWallet<'info> {
#[account(
mut,
mint::decimals = 9,
mint::authority = mint_authority.key(),
)]
pub mint_account: Account<'info, token::Mint>,
#[account(
mut,
seeds = [
b"mint_authority_",
mint_account.key().as_ref()
],
bump = mint_authority_pda_bump
)]
pub mint_authority: Account<'info, MintAuthorityPda>,
/// CHECK: This is for airdrops
pub recipient: UncheckedAccount<'info>,
#[account(
init,
payer = payer,
associated_token::mint = mint_account,
associated_token::authority = recipient,
)]
pub token_account: Account<'info, token::TokenAccount>,
#[account(mut)]
pub payer: Signer<'info>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, token::Token>,
pub associated_token_program: Program<'info, associated_token::AssociatedToken>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use {
use crate::create_token_mint::MintAuthorityPda;


pub fn mint_to_wallet(
ctx: Context<MintToWallet>,
pub fn mint_to_your_wallet(
ctx: Context<MintToYourWallet>,
amount: u64,
mint_authority_pda_bump: u8,
) -> Result<()> {
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn mint_to_wallet(

#[derive(Accounts)]
#[instruction(amount: u64, mint_authority_pda_bump: u8)]
pub struct MintToWallet<'info> {
pub struct MintToYourWallet<'info> {
#[account(
mut,
mint::decimals = 9,
Expand Down
10 changes: 6 additions & 4 deletions tokens/mint-2/anchor/programs/mint-2/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub mod create_token_mint;
pub mod mint_to_wallet;
pub mod transfer_to_wallet;
pub mod mint_to_your_wallet;
pub mod mint_to_another_wallet;
pub mod transfer_to_another_wallet;

pub use create_token_mint::*;
pub use mint_to_wallet::*;
pub use transfer_to_wallet::*;
pub use mint_to_your_wallet::*;
pub use mint_to_another_wallet::*;
pub use transfer_to_another_wallet::*;
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use {
};


pub fn transfer_to_wallet(
ctx: Context<TransferToWallet>,
pub fn transfer_to_another_wallet(
ctx: Context<TransferToAnotherWallet>,
amount: u64,
) -> Result<()> {

Expand All @@ -35,7 +35,7 @@ pub fn transfer_to_wallet(


#[derive(Accounts)]
pub struct TransferToWallet<'info> {
pub struct TransferToAnotherWallet<'info> {
#[account(mut)]
pub mint_account: Account<'info, token::Mint>,
#[account(
Expand All @@ -46,15 +46,15 @@ pub struct TransferToWallet<'info> {
pub owner_token_account: Account<'info, token::TokenAccount>,
#[account(
init,
payer = recipient,
payer = owner,
associated_token::mint = mint_account,
associated_token::authority = recipient,
)]
pub recipient_token_account: Account<'info, token::TokenAccount>,
#[account(mut)]
pub owner: Signer<'info>,
#[account(mut)]
pub recipient: Signer<'info>,
/// CHECK: Crediting not Debiting
pub recipient: UncheckedAccount<'info>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, token::Token>,
Expand Down
25 changes: 19 additions & 6 deletions tokens/mint-2/anchor/programs/mint-2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,38 @@ pub mod mint_2 {
)
}

pub fn mint_to_wallet(
ctx: Context<MintToWallet>,
pub fn mint_to_your_wallet(
ctx: Context<MintToYourWallet>,
amount: u64,
mint_authority_pda_bump: u8,
) -> Result<()> {

mint_to_wallet::mint_to_wallet(
mint_to_your_wallet::mint_to_your_wallet(
ctx,
amount,
mint_authority_pda_bump,
)
}

pub fn transfer_to_wallet(
ctx: Context<TransferToWallet>,
pub fn mint_to_another_wallet(
ctx: Context<MintToAnotherWallet>,
amount: u64,
mint_authority_pda_bump: u8,
) -> Result<()> {

mint_to_another_wallet::mint_to_another_wallet(
ctx,
amount,
mint_authority_pda_bump,
)
}

pub fn transfer_to_another_wallet(
ctx: Context<TransferToAnotherWallet>,
amount: u64,
) -> Result<()> {

transfer_to_wallet::transfer_to_wallet(
transfer_to_another_wallet::transfer_to_another_wallet(
ctx,
amount,
)
Expand Down
52 changes: 47 additions & 5 deletions tokens/mint-2/anchor/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("mint-token", () => {
.rpc();
});

it("Mint to a wallet!", async () => {
it("Mint to your wallet!", async () => {

const [mintAuthorityPda, mintAuthorityPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
[
Expand All @@ -75,7 +75,7 @@ describe("mint-token", () => {
});
console.log(`Token Address: ${tokenAddress}`);

await program.methods.mintToWallet(
await program.methods.mintToYourWallet(
new anchor.BN(amountToMint), mintAuthorityPdaBump
)
.accounts({
Expand All @@ -92,7 +92,49 @@ describe("mint-token", () => {
.rpc();
});

it("Transfer to a wallet!", async () => {
it("Mint to another person's wallet (airdrop)!", async () => {

const recipientKeypair = anchor.web3.Keypair.generate();
await provider.connection.confirmTransaction(
await provider.connection.requestAirdrop(recipientKeypair.publicKey, 1 * anchor.web3.LAMPORTS_PER_SOL)
);
console.log(`Recipient pubkey: ${recipientKeypair.publicKey}`);

const [mintAuthorityPda, mintAuthorityPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("mint_authority_"),
mintKeypair.publicKey.toBuffer(),
],
program.programId,
);

const amountToMint = 1;

const tokenAddress = await anchor.utils.token.associatedAddress({
mint: mintKeypair.publicKey,
owner: recipientKeypair.publicKey
});
console.log(`Token Address: ${tokenAddress}`);

await program.methods.mintToAnotherWallet(
new anchor.BN(amountToMint), mintAuthorityPdaBump
)
.accounts({
mintAccount: mintKeypair.publicKey,
mintAuthority: mintAuthorityPda,
recipient: recipientKeypair.publicKey,
tokenAccount: tokenAddress,
payer: payer.publicKey,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
systemProgram: anchor.web3.SystemProgram.programId,
tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
})
.signers([payer.payer])
.rpc();
});

it("Transfer to another person's wallet!", async () => {

const recipientWallet = anchor.web3.Keypair.generate();
await provider.connection.confirmTransaction(
Expand All @@ -113,7 +155,7 @@ describe("mint-token", () => {
});
console.log(`Recipient Token Address: ${recipientTokenAddress}`);

await program.methods.transferToWallet(
await program.methods.transferToAnotherWallet(
new anchor.BN(amountToTransfer)
)
.accounts({
Expand All @@ -127,7 +169,7 @@ describe("mint-token", () => {
tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
associatedTokenProgram: anchor.utils.token.ASSOCIATED_PROGRAM_ID,
})
.signers([payer.payer, recipientWallet])
.signers([payer.payer])
.rpc();
});
});

0 comments on commit a283104

Please sign in to comment.