Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,014 changes: 4,014 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const ANCHOR_DESCRIMINATOR_SIZE: usize = 8;
pub const ANCHOR_DISCRIMINATOR_SIZE: usize = 8;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{constants::ANCHOR_DESCRIMINATOR_SIZE, state::AddressInfo};
use crate::{constants::ANCHOR_DISCRIMINATOR_SIZE, state::AddressInfo};
use anchor_lang::prelude::*;

#[derive(Accounts)]
Expand All @@ -9,7 +9,7 @@ pub struct CreateAddressInfo<'info> {
#[account(
init,
payer = payer,
space = ANCHOR_DESCRIMINATOR_SIZE + AddressInfo::INIT_SPACE,
space = ANCHOR_DISCRIMINATOR_SIZE + AddressInfo::INIT_SPACE,
)]
address_info: Account<'info, AddressInfo>,
system_program: Program<'info, System>,
Expand Down
2 changes: 0 additions & 2 deletions tokens/create-token/steel/.gitignore

This file was deleted.

9 changes: 6 additions & 3 deletions tokens/create-token/steel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ edition = "2021"
license = "Apache-2.0"
homepage = ""
documentation = ""
respository = ""
repository = ""
readme = "./README.md"
keywords = ["solana"]

[workspace.dependencies]
steel-api = { path = "./api", version = "0.1.0" }
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "1.3"
solana-program = "2.1"
steel = "3.0"
thiserror = "1.0"
mpl-token-metadata = { version = "5.1.0", features = ["no-entrypoint"] }
spl-token = { version = "7.0.0", features = ["no-entrypoint"] }

22 changes: 16 additions & 6 deletions tokens/create-token/steel/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
# Steel

**Steel** is a ...

## API

- [`Consts`](api/src/consts.rs) – Program constants.
- [`Error`](api/src/error.rs) – Custom program errors.
- [`Event`](api/src/event.rs) – Custom program events.
- [`Instruction`](api/src/instruction.rs) – Declared instructions.

## Instructions
- [`Hello`](program/src/hello.rs) – Hello ...

- [`Create-Token`](program/src/create_token.rs) – Create Token ...

## State
- [`User`](api/src/state/user.rs) – User ...

## Tests
- [`Token`](api/src/state/token.rs) – Token ...

## Get started

To run the test suit, use the Solana toolchain:
Compile your program:

```sh
steel build
```
cargo test-sbf

Run unit and integration tests:

```sh
steel test
```
15 changes: 11 additions & 4 deletions tokens/create-token/steel/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
[package]
name = "steel-api"
version = "0.1.0"
edition = "2021"
description = "API for interacting with the Steel program"
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
readme.workspace = true
keywords.workspace = true

[dependencies]
bytemuck.workspace = true
mpl-token-metadata = "5.1.0"
num_enum.workspace = true
solana-program.workspace = true
spl-token = "6.0.0"
spl-token.workspace = true
steel.workspace = true
steel-program = { version = "0.1.0", path = "../program" }
thiserror.workspace = true
8 changes: 1 addition & 7 deletions tokens/create-token/steel/api/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
/// Seed of the counter account PDA.
pub const MINT: &[u8] = b"mint";

pub const MINT_NOISE: [u8; 16] = [
89, 157, 88, 232, 243, 249, 197, 132, 199, 49, 19, 234, 91, 94, 150, 41,
];

/// Seed of the token metadata account PDA.
pub const METADATA: &[u8] = b"metadata";
13 changes: 6 additions & 7 deletions tokens/create-token/steel/api/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use steel::*;
use crate::state::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum SteelInstruction {
Create_Token = 0,
pub enum TokenInstruction {
CreateToken = 0,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Create_Token {
pub token_name: [u8; 32],
pub token_symbol: [u8; 8],
pub token_uri: [u8; 64],
pub struct CreateToken {
pub data: Token
}

instruction!(SteelInstruction, Create_Token);
instruction!(TokenInstruction, CreateToken);
4 changes: 3 additions & 1 deletion tokens/create-token/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ pub mod consts;
pub mod error;
pub mod instruction;
pub mod sdk;
pub mod state;

pub mod prelude {
pub use crate::consts::*;
pub use crate::error::*;
pub use crate::instruction::*;
pub use crate::sdk::*;
pub use crate::state::*;
}

use steel::*;

// TODO Set program id
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
37 changes: 16 additions & 21 deletions tokens/create-token/steel/api/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
use steel::*;

use crate::prelude::*;

pub fn create_token(
payer: PubKey,
mint_authority: PubKey,
token_name: String,
token_symbol: String,
token_uri: String,
signer: Pubkey,
mint: Pubkey,
data: Token
) -> Instruction {
let token_name: [u8; 32] = token_name
.as_bytes()
.try_into()
.expect("token_name must be 32 bytes");
let token_symbol: [u8; 8] = token_symbol
.as_bytes()
.try_into()
.expect("token_symbol must be 32 bytes");
let token_uri: [u8; 64] = token_uri
.as_bytes()
.try_into()
.expect("token_uri must be 32 bytes");

let mint_pda = PubKey::find_program_address(&[b"mint"], &crate::ID);
let metadata_pda = PubKey::find_program_address();
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(mint, true),
AccountMeta::new(metadata_pda(&mint).0, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
AccountMeta::new_readonly(sysvar::rent::ID, false)
],
data: CreateToken { data }.to_bytes()
}
}
18 changes: 18 additions & 0 deletions tokens/create-token/steel/api/src/state/mod.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the state mod in this example, especially the Token type

Add the token fields in api::instruction::CreateToken like so:

pub struct CreateToken {
    pub name: [u8; 32],
    pub symbol: [u8; 8],
    pub uri: [u8; 128],
    pub decimals: u8,
}

since you're removing the state mod, you'd need get the metadata pda pubkey in api::sdk:: create_token function. This would work:

  let metadata_pda = Pubkey::find_program_address(
        &[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()],
        &mpl_token_metadata::ID,
    );

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod token;

pub use token::*;

use steel::*;

use crate::consts::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum TokenAccount {
Token = 0
}

/// Fetch PDA of the token metadata account.
pub fn metadata_pda(mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()], &mpl_token_metadata::ID)
}
14 changes: 14 additions & 0 deletions tokens/create-token/steel/api/src/state/token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use steel::*;

use super::TokenAccount;

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Token {
pub name: [u8; 32],
pub symbol: [u8; 8],
pub uri: [u8; 128],
pub decimals: u8
}

account!(TokenAccount, Token);
21 changes: 16 additions & 5 deletions tokens/create-token/steel/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[package]
name = "steel-program"
version = "0.1.0"
edition = "2021"
description = ""
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
readme.workspace = true
keywords.workspace = true

[lib]
crate-type = ["cdylib", "lib"]
Expand All @@ -10,10 +17,14 @@ crate-type = ["cdylib", "lib"]
steel-api.workspace = true
solana-program.workspace = true
steel.workspace = true
spl-token.workspace = true
mpl-token-metadata = "5.1.0"

[dev-dependencies]
bs64 = "0.1.2"
base64 = "0.21"
rand = "0.8.5"
solana-program-test = "1.18"
solana-sdk = "1.18"
solana-program-test = "2.1"
solana-sdk = "2.1"
tokio = { version = "1.35", features = ["full"] }
bytemuck_derive = ">=1.8.1, <1.9.0"
half = "=2.4.1"
24 changes: 24 additions & 0 deletions tokens/create-token/steel/program/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// build.rs
use std::fs;
use std::process::Command;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

// Create the fixtures directory path
fs::create_dir_all("tests/fixtures").expect("Failed to create fixtures directory");

let status = Command::new("solana")
.args([
"program",
"dump",
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
"tests/fixtures/token_metadata.so",
])
.status()
.expect("Failed to run solana program dump command");

if !status.success() {
panic!("Failed to dump Solana program");
}
}
Loading