Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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";
15 changes: 8 additions & 7 deletions tokens/create-token/steel/api/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use steel::*;

#[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 name: [u8; 32],
pub symbol: [u8; 8],
pub uri: [u8; 128],
pub decimals: u8,
}

instruction!(SteelInstruction, Create_Token);
instruction!(TokenInstruction, CreateToken);
54 changes: 33 additions & 21 deletions tokens/create-token/steel/api/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
use steel::*;

use crate::prelude::*;
use steel::*;

pub fn create_token(
payer: PubKey,
mint_authority: PubKey,
token_name: String,
token_symbol: String,
token_uri: String,
signer: Pubkey,
mint: Pubkey,
name: [u8; 32],
symbol: [u8; 8],
uri: [u8; 128],
decimals: u8,
) -> 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");
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 {
name,
symbol,
uri,
decimals,
}
.to_bytes(),
}
}

let mint_pda = PubKey::find_program_address(&[b"mint"], &crate::ID);
let metadata_pda = PubKey::find_program_address();
// Fetch PDA of a 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,
)
}
8 changes: 8 additions & 0 deletions tokens/create-token/steel/cicd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script is for quick building & deploying of the program.
# It also serves as a reference for the commands used for building & deploying Solana programs.
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"

cargo build-sbf --manifest-path=./program/Cargo.toml
solana program deploy ./program/target/deploy/program.so
28 changes: 28 additions & 0 deletions tokens/create-token/steel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"scripts": {
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/bankrun.test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/create_token_program.so",
"postinstall": "zx prepare.mjs"
},
"dependencies": {
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
"@solana/spl-token": "^0.3.7",
"@solana/web3.js": "^1.73.0",
"borsh": "^0.7.0",
"buffer": "^6.0.3",
"fs": "^0.0.1-security"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5",
"solana-bankrun": "^0.4.0",
"zx": "^8.1.4"
}
}
Loading
Loading