-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tokens/pda-mint-authority/steel (#189)
- Loading branch information
1 parent
52b3a69
commit 24499bb
Showing
24 changed files
with
2,774 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
test-ledger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["api", "program"] | ||
|
||
[workspace.package] | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
homepage = "" | ||
documentation = "" | ||
repository = "" | ||
readme = "./README.md" | ||
keywords = ["solana"] | ||
|
||
[workspace.dependencies] | ||
pda-mint-authority-api = { path = "./api", version = "0.1.0" } | ||
bytemuck = "1.14" | ||
num_enum = "0.7" | ||
solana-program = "1.18" | ||
steel = { version = "2.0", features = ["spl"] } | ||
thiserror = "1.0" | ||
mpl-token-metadata = { version = "4.1.2" } | ||
spl-token = "^4" | ||
const-crypto = "0.1.0" | ||
spl-associated-token-account = { version = "^2.3", features = [ | ||
"no-entrypoint", | ||
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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 ... | ||
|
||
## State | ||
- [`User`](api/src/state/user.rs) – User ... | ||
|
||
## Tests | ||
|
||
To run the test suit, use the Solana toolchain: | ||
``` | ||
cargo test-sbf | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "pda-mint-authority-api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bytemuck.workspace = true | ||
num_enum.workspace = true | ||
solana-program.workspace = true | ||
steel.workspace = true | ||
thiserror.workspace = true | ||
spl-token.workspace = true | ||
mpl-token-metadata.workspace = true | ||
const-crypto.workspace = true | ||
spl-associated-token-account.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// The seed of the mint authority account PDA. | ||
pub const MINT_AUTHORITY: &[u8] = b"mint_authority"; | ||
|
||
/// The seed of the metadata account PDA. | ||
pub const METADATA: &[u8] = b"metadata"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use steel::*; | ||
|
||
#[repr(u8)] | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)] | ||
pub enum SteelInstruction { | ||
Init = 0, | ||
Create = 1, | ||
Mint = 2, | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Pod, Zeroable)] | ||
pub struct Init {} | ||
|
||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Pod, Zeroable)] | ||
pub struct Create { | ||
pub token_name: [u8; 32], | ||
pub token_symbol: [u8; 8], | ||
pub token_uri: [u8; 64], | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Pod, Zeroable)] | ||
pub struct Mint { | ||
pub amount: [u8; 8], | ||
} | ||
|
||
instruction!(SteelInstruction, Init); | ||
instruction!(SteelInstruction, Create); | ||
instruction!(SteelInstruction, Mint); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub mod consts; | ||
pub mod instruction; | ||
pub mod sdk; | ||
pub mod state; | ||
|
||
pub mod prelude { | ||
pub use crate::consts::*; | ||
pub use crate::instruction::*; | ||
pub use crate::sdk::*; | ||
pub use crate::state::*; | ||
} | ||
|
||
use steel::*; | ||
|
||
// TODO Set program id | ||
declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use steel::*; | ||
|
||
use crate::prelude::*; | ||
|
||
pub fn init(payer: Pubkey) -> Instruction { | ||
let mint_authority_pda = mint_authority_pda(); | ||
|
||
Instruction { | ||
program_id: crate::ID, | ||
accounts: vec![ | ||
AccountMeta::new(mint_authority_pda.0, false), | ||
AccountMeta::new(payer, false), | ||
AccountMeta::new_readonly(system_program::ID, false), | ||
], | ||
data: Init {}.to_bytes(), | ||
} | ||
} | ||
|
||
pub fn create( | ||
payer: Pubkey, | ||
mint: Pubkey, | ||
token_name: [u8; 32], | ||
token_symbol: [u8; 8], | ||
token_uri: [u8; 64], | ||
) -> Instruction { | ||
let metadata_pda = Pubkey::find_program_address( | ||
&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()], | ||
&mpl_token_metadata::ID, | ||
); | ||
let mint_authority_pda = mint_authority_pda(); | ||
|
||
Instruction { | ||
program_id: crate::ID, | ||
accounts: vec![ | ||
AccountMeta::new(mint, true), | ||
AccountMeta::new(mint_authority_pda.0, false), | ||
AccountMeta::new(metadata_pda.0, false), | ||
AccountMeta::new(payer, true), | ||
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: Create { | ||
token_name, | ||
token_symbol, | ||
token_uri, | ||
} | ||
.to_bytes(), | ||
} | ||
} | ||
pub fn mint( | ||
payer: Pubkey, | ||
mint: Pubkey, | ||
associated_token_account: Pubkey, | ||
amount: u64, | ||
) -> Instruction { | ||
let mint_authority_pda = mint_authority_pda(); | ||
|
||
Instruction { | ||
program_id: crate::ID, | ||
accounts: vec![ | ||
AccountMeta::new(payer, true), | ||
AccountMeta::new(mint, false), | ||
AccountMeta::new(associated_token_account, false), | ||
AccountMeta::new(mint_authority_pda.0, false), | ||
AccountMeta::new_readonly(spl_token::ID, false), | ||
AccountMeta::new_readonly(spl_associated_token_account::ID, false), | ||
AccountMeta::new_readonly(system_program::ID, false), | ||
], | ||
data: Mint { | ||
amount: amount.to_le_bytes(), | ||
} | ||
.to_bytes(), | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tokens/pda-mint-authority/steel/api/src/state/mint_authority.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use steel::*; | ||
|
||
use super::SteelAccount; | ||
|
||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] | ||
pub struct MintAuthorityPda { | ||
pub bump: u8, | ||
} | ||
|
||
account!(SteelAccount, MintAuthorityPda); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
mod mint_authority; | ||
|
||
pub use mint_authority::*; | ||
|
||
use steel::*; | ||
|
||
use crate::consts::*; | ||
|
||
#[repr(u8)] | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] | ||
pub enum SteelAccount { | ||
MintAuthorityPda = 0, | ||
} | ||
|
||
/// Fetch PDA of the mint authority account. | ||
pub fn mint_authority_pda() -> (Pubkey, u8) { | ||
Pubkey::find_program_address(&[MINT_AUTHORITY], &crate::id()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/tests.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/pda_mint_authority_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" | ||
} | ||
} |
Oops, something went wrong.