Skip to content

Commit c8289e1

Browse files
committed
add spl token minter steel example
add bankrun tests clean clean clean add js tests complete steel tests add steel test update to steel 2.0
1 parent 3a36468 commit c8289e1

File tree

21 files changed

+2590
-0
lines changed

21 files changed

+2590
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
test-ledger
Lines changed: 27 additions & 0 deletions
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+
spl-token-minter-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+
spl-token = "^4"
23+
mpl-token-metadata = { version = "4.1.2" }
24+
const-crypto = "0.1.0"
25+
spl-associated-token-account = { version = "^2.3", features = [
26+
"no-entrypoint",
27+
] }
Lines changed: 22 additions & 0 deletions
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+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "spl-token-minter-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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// The seed of the metadata account PDA.
2+
pub const METADATA: &[u8] = b"metadata";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::str;
2+
use steel::*;
3+
4+
#[repr(u8)]
5+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
6+
pub enum SteelInstruction {
7+
Create = 0,
8+
Mint = 1,
9+
}
10+
11+
#[repr(C)]
12+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
13+
pub struct Create {
14+
pub token_name: [u8; 32],
15+
pub token_symbol: [u8; 8],
16+
pub token_uri: [u8; 64],
17+
}
18+
19+
#[repr(C)]
20+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
21+
pub struct Mint {
22+
pub quantity: [u8; 8],
23+
}
24+
25+
instruction!(SteelInstruction, Mint);
26+
instruction!(SteelInstruction, Create);
Lines changed: 16 additions & 0 deletions
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 utils;
5+
6+
pub mod prelude {
7+
pub use crate::consts::*;
8+
pub use crate::instruction::*;
9+
pub use crate::sdk::*;
10+
pub use crate::utils::*;
11+
}
12+
13+
use steel::*;
14+
15+
// TODO Set program id
16+
declare_id!("8V26fyhrQobKbvkRCV3KvT6jZQLzviovdARfGrw8kUdG");
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn create(
6+
payer: Pubkey,
7+
mint: Pubkey,
8+
token_name: [u8; 32],
9+
token_symbol: [u8; 8],
10+
token_uri: [u8; 64],
11+
) -> Instruction {
12+
let metadata_pda = Pubkey::find_program_address(
13+
&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()],
14+
&mpl_token_metadata::ID,
15+
);
16+
17+
Instruction {
18+
program_id: crate::ID,
19+
accounts: vec![
20+
AccountMeta::new(payer, true),
21+
AccountMeta::new(mint, true),
22+
AccountMeta::new(metadata_pda.0, false),
23+
AccountMeta::new_readonly(system_program::ID, false),
24+
AccountMeta::new_readonly(spl_token::ID, false),
25+
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
26+
AccountMeta::new_readonly(sysvar::rent::ID, false),
27+
],
28+
data: Create {
29+
token_name,
30+
token_symbol,
31+
token_uri,
32+
}
33+
.to_bytes(),
34+
}
35+
}
36+
pub fn mint(
37+
mint_authority: Pubkey,
38+
recipient: Pubkey,
39+
mint: Pubkey,
40+
associated_token_account: Pubkey,
41+
quantity: u64,
42+
) -> Instruction {
43+
Instruction {
44+
program_id: crate::ID,
45+
accounts: vec![
46+
AccountMeta::new(mint_authority, true),
47+
AccountMeta::new(recipient, false),
48+
AccountMeta::new(mint, false),
49+
AccountMeta::new(associated_token_account, false),
50+
AccountMeta::new_readonly(spl_token::ID, false),
51+
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
52+
AccountMeta::new_readonly(system_program::ID, false),
53+
],
54+
data: Mint {
55+
quantity: quantity.to_le_bytes(),
56+
}
57+
.to_bytes(),
58+
}
59+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn str_to_bytes<const N: usize>(str: &str) -> [u8; N] {
2+
let mut str_bytes = [0u8; N];
3+
let copy_len = str.len().min(N);
4+
str_bytes[..copy_len].copy_from_slice(&str.as_bytes()[..copy_len]);
5+
str_bytes
6+
}
Lines changed: 8 additions & 0 deletions
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

0 commit comments

Comments
 (0)