Skip to content

Commit b9f3d40

Browse files
committed
anchor token basics working, excluding swap and token22
1 parent 000f740 commit b9f3d40

File tree

44 files changed

+159
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+159
-284
lines changed

tokens/create-token/anchor/Anchor.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
[toolchain]
2+
13
[features]
2-
seeds = false
4+
resolution = true
35
skip-lint = false
46

57
[programs.localnet]
6-
create_token = "2B6MrsKB2pVq6W6tY8dJLcnSd3Uv1KE7yRaboBjdQoEX"
8+
create_token = "GwvQ53QTu1xz3XXYfG5m5jEqwhMBvVBudPS8TUuFYnhT"
79

810
[registry]
911
url = "https://api.apr.dev"
1012

1113
[provider]
12-
cluster = "localnet"
14+
cluster = "devnet"
1315
wallet = "~/.config/solana/id.json"
1416

1517
[scripts]
@@ -18,6 +20,7 @@ test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
1820
[test]
1921
startup_wait = 5000
2022
shutdown_wait = 2000
23+
upgradeable = false
2124

2225
[test.validator]
2326
bind_address = "0.0.0.0"

tokens/create-token/anchor/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"dependencies": {
3-
"@coral-xyz/anchor": "^0.30.0",
4-
"@metaplex-foundation/mpl-token-metadata": "^2.5.2"
3+
"@coral-xyz/anchor": "^0.30.0"
54
},
65
"devDependencies": {
76
"@types/bn.js": "^5.1.0",

tokens/create-token/anchor/programs/create-token/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
1919
[dependencies]
2020
anchor-lang = "0.30.0"
2121
anchor-spl = { version = "0.30.0", features = ["metadata"] }
22-
mpl-token-metadata = { version = "1.13.1", features = ["no-entrypoint"] }

tokens/create-token/anchor/programs/create-token/src/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
use {
44
anchor_lang::prelude::*,
55
anchor_spl::{
6-
metadata::{create_metadata_accounts_v3, CreateMetadataAccountsV3, Metadata},
6+
metadata::{
7+
create_metadata_accounts_v3, mpl_token_metadata::types::DataV2,
8+
CreateMetadataAccountsV3, Metadata,
9+
},
710
token::{Mint, Token},
811
},
9-
mpl_token_metadata::{pda::find_metadata_account, state::DataV2},
1012
};
1113

12-
declare_id!("2B6MrsKB2pVq6W6tY8dJLcnSd3Uv1KE7yRaboBjdQoEX");
14+
declare_id!("GwvQ53QTu1xz3XXYfG5m5jEqwhMBvVBudPS8TUuFYnhT");
1315

1416
#[program]
1517
pub mod create_token {
1618
use super::*;
1719

1820
pub fn create_token_mint(
1921
ctx: Context<CreateTokenMint>,
22+
_token_decimals: u8,
2023
token_name: String,
2124
token_symbol: String,
2225
token_uri: String,
23-
_token_decimals: u8,
2426
) -> Result<()> {
2527
msg!("Creating metadata account...");
2628
msg!(
@@ -69,10 +71,12 @@ pub struct CreateTokenMint<'info> {
6971
#[account(mut)]
7072
pub payer: Signer<'info>,
7173

72-
/// CHECK: Address validated using constraint
74+
/// CHECK: Validate address by deriving pda
7375
#[account(
7476
mut,
75-
address=find_metadata_account(&mint_account.key()).0
77+
seeds = [b"metadata", token_metadata_program.key().as_ref(), mint_account.key().as_ref()],
78+
bump,
79+
seeds::program = token_metadata_program.key(),
7680
)]
7781
pub metadata_account: UncheckedAccount<'info>,
7882
// Create new mint account

tokens/create-token/anchor/tests/test.ts

+3-40
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";
21
import * as anchor from "@coral-xyz/anchor";
3-
import { TOKEN_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/utils/token";
42
import { CreateToken } from "../target/types/create_token";
5-
import {
6-
PublicKey,
7-
Keypair,
8-
SYSVAR_RENT_PUBKEY,
9-
SystemProgram,
10-
} from "@solana/web3.js";
3+
import { Keypair } from "@solana/web3.js";
114

125
describe("Create Tokens", () => {
136
const provider = anchor.AnchorProvider.env();
@@ -25,27 +18,12 @@ describe("Create Tokens", () => {
2518
// Generate new keypair to use as address for mint account.
2619
const mintKeypair = new Keypair();
2720

28-
// Derive the PDA of the metadata account for the mint.
29-
const [metadataAddress] = PublicKey.findProgramAddressSync(
30-
[
31-
Buffer.from("metadata"),
32-
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
33-
mintKeypair.publicKey.toBuffer(),
34-
],
35-
TOKEN_METADATA_PROGRAM_ID
36-
);
37-
3821
// SPL Token default = 9 decimals
3922
const transactionSignature = await program.methods
40-
.createTokenMint(metadata.name, metadata.symbol, metadata.uri, 9)
23+
.createTokenMint(9, metadata.name, metadata.symbol, metadata.uri)
4124
.accounts({
4225
payer: payer.publicKey,
43-
metadataAccount: metadataAddress,
4426
mintAccount: mintKeypair.publicKey,
45-
rent: SYSVAR_RENT_PUBKEY,
46-
systemProgram: SystemProgram.programId,
47-
tokenProgram: TOKEN_PROGRAM_ID,
48-
tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
4927
})
5028
.signers([mintKeypair])
5129
.rpc();
@@ -59,27 +37,12 @@ describe("Create Tokens", () => {
5937
// Generate new keypair to use as address for mint account.
6038
const mintKeypair = new Keypair();
6139

62-
// Derive the PDA of the metadata account for the mint.
63-
const [metadataAddress] = PublicKey.findProgramAddressSync(
64-
[
65-
Buffer.from("metadata"),
66-
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
67-
mintKeypair.publicKey.toBuffer(),
68-
],
69-
TOKEN_METADATA_PROGRAM_ID
70-
);
71-
7240
// NFT default = 0 decimals
7341
const transactionSignature = await program.methods
74-
.createTokenMint(metadata.name, metadata.symbol, metadata.uri, 0)
42+
.createTokenMint(0, metadata.name, metadata.symbol, metadata.uri)
7543
.accounts({
7644
payer: payer.publicKey,
77-
metadataAccount: metadataAddress,
7845
mintAccount: mintKeypair.publicKey,
79-
rent: SYSVAR_RENT_PUBKEY,
80-
systemProgram: SystemProgram.programId,
81-
tokenProgram: TOKEN_PROGRAM_ID,
82-
tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
8346
})
8447
.signers([mintKeypair])
8548
.rpc();

tokens/nft-minter/anchor/Anchor.toml

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
[toolchain]
2+
13
[features]
2-
seeds = false
4+
resolution = true
35
skip-lint = false
6+
seeds = true
47

58
[programs.localnet]
6-
nft_minter = "3qHNM98iLTaQtwmj2NkViXnHZQjNBS5PTHT2AuPxHXYN"
9+
nft_minter = "52quezNUzc1Ej6Jh6L4bvtxPW8j6TEFHuLVAWiFvdnsc"
10+
11+
[registry]
12+
url = "https://api.apr.dev"
713

814
[provider]
9-
cluster = "localnet"
15+
cluster = "devnet"
1016
wallet = "~/.config/solana/id.json"
1117

1218
[scripts]
@@ -15,6 +21,7 @@ test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
1521
[test]
1622
startup_wait = 5000
1723
shutdown_wait = 2000
24+
upgradeable = false
1825

1926
[test.validator]
2027
bind_address = "0.0.0.0"

tokens/nft-minter/anchor/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = ["programs/*"]
3+
resolver = "2"
34

45
[profile.release]
56
overflow-checks = true
@@ -9,3 +10,4 @@ codegen-units = 1
910
opt-level = 3
1011
incremental = false
1112
codegen-units = 1
13+

tokens/nft-minter/anchor/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"dependencies": {
33
"@coral-xyz/anchor": "^0.30.0",
4-
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
54
"@solana/spl-token": "^0.3.8"
65
},
76
"devDependencies": {

tokens/nft-minter/anchor/programs/nft-minter/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
1919
[dependencies]
2020
anchor-lang = { version = "0.30.0", features = ["init-if-needed"] }
2121
anchor-spl = { version = "0.30.0", features = ["metadata"] }
22-
mpl-token-metadata = { version = "1.13.1", features = ["no-entrypoint"] }

tokens/nft-minter/anchor/programs/nft-minter/src/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ use {
55
anchor_spl::{
66
associated_token::AssociatedToken,
77
metadata::{
8-
create_master_edition_v3, create_metadata_accounts_v3, CreateMasterEditionV3,
9-
CreateMetadataAccountsV3, Metadata,
8+
create_master_edition_v3, create_metadata_accounts_v3,
9+
mpl_token_metadata::types::DataV2, CreateMasterEditionV3, CreateMetadataAccountsV3,
10+
Metadata,
1011
},
1112
token::{mint_to, Mint, MintTo, Token, TokenAccount},
1213
},
13-
mpl_token_metadata::{
14-
pda::{find_master_edition_account, find_metadata_account},
15-
state::DataV2,
16-
},
1714
};
1815

19-
declare_id!("3qHNM98iLTaQtwmj2NkViXnHZQjNBS5PTHT2AuPxHXYN");
16+
declare_id!("52quezNUzc1Ej6Jh6L4bvtxPW8j6TEFHuLVAWiFvdnsc");
2017

2118
#[program]
2219
pub mod nft_minter {
@@ -105,17 +102,21 @@ pub struct CreateToken<'info> {
105102
#[account(mut)]
106103
pub payer: Signer<'info>,
107104

108-
/// CHECK: Address validated using constraint
105+
/// CHECK: Validate address by deriving pda
109106
#[account(
110107
mut,
111-
address=find_metadata_account(&mint_account.key()).0
108+
seeds = [b"metadata", token_metadata_program.key().as_ref(), mint_account.key().as_ref()],
109+
bump,
110+
seeds::program = token_metadata_program.key(),
112111
)]
113112
pub metadata_account: UncheckedAccount<'info>,
114113

115-
/// CHECK: Address validated using constraint
114+
/// CHECK: Validate address by deriving pda
116115
#[account(
117116
mut,
118-
address=find_master_edition_account(&mint_account.key()).0
117+
seeds = [b"metadata", token_metadata_program.key().as_ref(), mint_account.key().as_ref(), b"edition"],
118+
bump,
119+
seeds::program = token_metadata_program.key(),
119120
)]
120121
pub edition_account: UncheckedAccount<'info>,
121122

tokens/nft-minter/anchor/tests/test.ts

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";
21
import * as anchor from "@coral-xyz/anchor";
32
import { NftMinter } from "../target/types/nft_minter";
4-
import {
5-
Keypair,
6-
PublicKey,
7-
SYSVAR_RENT_PUBKEY,
8-
SystemProgram,
9-
} from "@solana/web3.js";
10-
import {
11-
getAssociatedTokenAddressSync,
12-
ASSOCIATED_TOKEN_PROGRAM_ID,
13-
TOKEN_PROGRAM_ID,
14-
} from "@solana/spl-token";
3+
import { Keypair } from "@solana/web3.js";
4+
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
155

166
describe("NFT Minter", () => {
177
const provider = anchor.AnchorProvider.env();
@@ -30,27 +20,6 @@ describe("NFT Minter", () => {
3020
// Generate a keypair to use as the address of our mint account
3121
const mintKeypair = new Keypair();
3222

33-
// Derive the PDA of the metadata account for the mint.
34-
const [metadataAddress] = PublicKey.findProgramAddressSync(
35-
[
36-
Buffer.from("metadata"),
37-
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
38-
mintKeypair.publicKey.toBuffer(),
39-
],
40-
TOKEN_METADATA_PROGRAM_ID
41-
);
42-
43-
// Derive the PDA of the master edition account for the mint.
44-
const [editionAddress] = PublicKey.findProgramAddressSync(
45-
[
46-
Buffer.from("metadata"),
47-
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
48-
mintKeypair.publicKey.toBuffer(),
49-
Buffer.from("edition"),
50-
],
51-
TOKEN_METADATA_PROGRAM_ID
52-
);
53-
5423
// Derive the associated token address account for the mint and payer.
5524
const associatedTokenAccountAddress = getAssociatedTokenAddressSync(
5625
mintKeypair.publicKey,
@@ -61,15 +30,8 @@ describe("NFT Minter", () => {
6130
.mintNft(metadata.name, metadata.symbol, metadata.uri)
6231
.accounts({
6332
payer: payer.publicKey,
64-
metadataAccount: metadataAddress,
65-
editionAccount: editionAddress,
6633
mintAccount: mintKeypair.publicKey,
6734
associatedTokenAccount: associatedTokenAccountAddress,
68-
tokenProgram: TOKEN_PROGRAM_ID,
69-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
70-
tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
71-
systemProgram: SystemProgram.programId,
72-
rent: SYSVAR_RENT_PUBKEY,
7335
})
7436
.signers([mintKeypair])
7537
.rpc({ skipPreflight: true });

tokens/pda-mint-authority/anchor/Anchor.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
[toolchain]
2+
13
[features]
2-
seeds = false
4+
resolution = true
35
skip-lint = false
46

57
[programs.localnet]
6-
token_minter = "A5gNtapBvMLD6i7D2t3SSyJeFtBdfb6ibvZu1hoBLzCo"
8+
token_minter = "3LFrPHqwk5jMrmiz48BFj6NV2k4NjobgTe1jChzx3JGD"
79

810
[registry]
911
url = "https://api.apr.dev"
1012

1113
[provider]
12-
cluster = "Localnet"
14+
cluster = "Devnet"
1315
wallet = "~/.config/solana/id.json"
1416

1517
[scripts]
@@ -18,6 +20,7 @@ test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
1820
[test]
1921
startup_wait = 5000
2022
shutdown_wait = 2000
23+
upgradeable = false
2124

2225
[test.validator]
2326
bind_address = "0.0.0.0"

tokens/pda-mint-authority/anchor/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"dependencies": {
33
"@coral-xyz/anchor": "^0.30.0",
4-
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
54
"@solana/spl-token": "^0.3.8"
65
},
76
"devDependencies": {

tokens/pda-mint-authority/anchor/programs/token-minter/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
1919
[dependencies]
2020
anchor-lang = { version = "0.30.0", features = ["init-if-needed"] }
2121
anchor-spl = { version = "0.30.0", features = ["metadata"] }
22-
mpl-token-metadata = { version = "1.13.1", features = ["no-entrypoint"] }

0 commit comments

Comments
 (0)