Skip to content

Commit 24499bb

Browse files
authored
add tokens/pda-mint-authority/steel (solana-developers#189)
1 parent 52b3a69 commit 24499bb

24 files changed

+2774
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
test-ledger
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["api", "program"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
7+
edition = "2021"
8+
license = "Apache-2.0"
9+
homepage = ""
10+
documentation = ""
11+
repository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
pda-mint-authority-api = { path = "./api", version = "0.1.0" }
17+
bytemuck = "1.14"
18+
num_enum = "0.7"
19+
solana-program = "1.18"
20+
steel = { version = "2.0", features = ["spl"] }
21+
thiserror = "1.0"
22+
mpl-token-metadata = { version = "4.1.2" }
23+
spl-token = "^4"
24+
const-crypto = "0.1.0"
25+
spl-associated-token-account = { version = "^2.3", features = [
26+
"no-entrypoint",
27+
] }
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Steel
2+
3+
**Steel** is a ...
4+
5+
## API
6+
- [`Consts`](api/src/consts.rs) – Program constants.
7+
- [`Error`](api/src/error.rs) – Custom program errors.
8+
- [`Event`](api/src/event.rs) – Custom program events.
9+
- [`Instruction`](api/src/instruction.rs) – Declared instructions.
10+
11+
## Instructions
12+
- [`Hello`](program/src/hello.rs) – Hello ...
13+
14+
## State
15+
- [`User`](api/src/state/user.rs) – User ...
16+
17+
## Tests
18+
19+
To run the test suit, use the Solana toolchain:
20+
```
21+
cargo test-sbf
22+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "pda-mint-authority-api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bytemuck.workspace = true
8+
num_enum.workspace = true
9+
solana-program.workspace = true
10+
steel.workspace = true
11+
thiserror.workspace = true
12+
spl-token.workspace = true
13+
mpl-token-metadata.workspace = true
14+
const-crypto.workspace = true
15+
spl-associated-token-account.workspace = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// The seed of the mint authority account PDA.
2+
pub const MINT_AUTHORITY: &[u8] = b"mint_authority";
3+
4+
/// The seed of the metadata account PDA.
5+
pub const METADATA: &[u8] = b"metadata";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum SteelInstruction {
6+
Init = 0,
7+
Create = 1,
8+
Mint = 2,
9+
}
10+
11+
#[repr(C)]
12+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
13+
pub struct Init {}
14+
15+
#[repr(C)]
16+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
17+
pub struct Create {
18+
pub token_name: [u8; 32],
19+
pub token_symbol: [u8; 8],
20+
pub token_uri: [u8; 64],
21+
}
22+
23+
#[repr(C)]
24+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
25+
pub struct Mint {
26+
pub amount: [u8; 8],
27+
}
28+
29+
instruction!(SteelInstruction, Init);
30+
instruction!(SteelInstruction, Create);
31+
instruction!(SteelInstruction, Mint);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub mod consts;
2+
pub mod instruction;
3+
pub mod sdk;
4+
pub mod state;
5+
6+
pub mod prelude {
7+
pub use crate::consts::*;
8+
pub use crate::instruction::*;
9+
pub use crate::sdk::*;
10+
pub use crate::state::*;
11+
}
12+
13+
use steel::*;
14+
15+
// TODO Set program id
16+
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn init(payer: Pubkey) -> Instruction {
6+
let mint_authority_pda = mint_authority_pda();
7+
8+
Instruction {
9+
program_id: crate::ID,
10+
accounts: vec![
11+
AccountMeta::new(mint_authority_pda.0, false),
12+
AccountMeta::new(payer, false),
13+
AccountMeta::new_readonly(system_program::ID, false),
14+
],
15+
data: Init {}.to_bytes(),
16+
}
17+
}
18+
19+
pub fn create(
20+
payer: Pubkey,
21+
mint: Pubkey,
22+
token_name: [u8; 32],
23+
token_symbol: [u8; 8],
24+
token_uri: [u8; 64],
25+
) -> Instruction {
26+
let metadata_pda = Pubkey::find_program_address(
27+
&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()],
28+
&mpl_token_metadata::ID,
29+
);
30+
let mint_authority_pda = mint_authority_pda();
31+
32+
Instruction {
33+
program_id: crate::ID,
34+
accounts: vec![
35+
AccountMeta::new(mint, true),
36+
AccountMeta::new(mint_authority_pda.0, false),
37+
AccountMeta::new(metadata_pda.0, false),
38+
AccountMeta::new(payer, true),
39+
AccountMeta::new_readonly(system_program::ID, false),
40+
AccountMeta::new_readonly(spl_token::ID, false),
41+
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
42+
AccountMeta::new_readonly(sysvar::rent::ID, false),
43+
],
44+
data: Create {
45+
token_name,
46+
token_symbol,
47+
token_uri,
48+
}
49+
.to_bytes(),
50+
}
51+
}
52+
pub fn mint(
53+
payer: Pubkey,
54+
mint: Pubkey,
55+
associated_token_account: Pubkey,
56+
amount: u64,
57+
) -> Instruction {
58+
let mint_authority_pda = mint_authority_pda();
59+
60+
Instruction {
61+
program_id: crate::ID,
62+
accounts: vec![
63+
AccountMeta::new(payer, true),
64+
AccountMeta::new(mint, false),
65+
AccountMeta::new(associated_token_account, false),
66+
AccountMeta::new(mint_authority_pda.0, false),
67+
AccountMeta::new_readonly(spl_token::ID, false),
68+
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
69+
AccountMeta::new_readonly(system_program::ID, false),
70+
],
71+
data: Mint {
72+
amount: amount.to_le_bytes(),
73+
}
74+
.to_bytes(),
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use steel::*;
2+
3+
use super::SteelAccount;
4+
5+
#[repr(C)]
6+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
7+
pub struct MintAuthorityPda {
8+
pub bump: u8,
9+
}
10+
11+
account!(SteelAccount, MintAuthorityPda);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod mint_authority;
2+
3+
pub use mint_authority::*;
4+
5+
use steel::*;
6+
7+
use crate::consts::*;
8+
9+
#[repr(u8)]
10+
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
11+
pub enum SteelAccount {
12+
MintAuthorityPda = 0,
13+
}
14+
15+
/// Fetch PDA of the mint authority account.
16+
pub fn mint_authority_pda() -> (Pubkey, u8) {
17+
Pubkey::find_program_address(&[MINT_AUTHORITY], &crate::id())
18+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script is for quick building & deploying of the program.
4+
# It also serves as a reference for the commands used for building & deploying Solana programs.
5+
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"
6+
7+
cargo build-sbf --manifest-path=./program/Cargo.toml
8+
solana program deploy ./program/target/deploy/program.so
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"scripts": {
3+
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/tests.ts",
4+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
5+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
6+
"deploy": "solana program deploy ./program/target/so/pda_mint_authority_program.so",
7+
"postinstall": "zx prepare.mjs"
8+
},
9+
"dependencies": {
10+
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
11+
"@solana/spl-token": "^0.3.7",
12+
"@solana/web3.js": "^1.73.0",
13+
"borsh": "^0.7.0",
14+
"buffer": "^6.0.3",
15+
"fs": "^0.0.1-security"
16+
},
17+
"devDependencies": {
18+
"@types/bn.js": "^5.1.0",
19+
"@types/chai": "^4.3.1",
20+
"@types/mocha": "^9.1.1",
21+
"chai": "^4.3.4",
22+
"mocha": "^9.0.3",
23+
"ts-mocha": "^10.0.0",
24+
"typescript": "^4.3.5",
25+
"solana-bankrun": "^0.4.0",
26+
"zx": "^8.1.4"
27+
}
28+
}

0 commit comments

Comments
 (0)