Skip to content

Commit 6195ac8

Browse files
committed
clean clean clean
1 parent 3c20c66 commit 6195ac8

File tree

8 files changed

+56
-84
lines changed

8 files changed

+56
-84
lines changed
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
1-
use const_crypto::ed25519;
2-
use solana_program::pubkey::Pubkey;
3-
4-
/// The seed of the mint account PDA.
5-
pub const MINT: &[u8] = b"mint";
6-
7-
/// Noise for deriving the mint pda
8-
pub const MINT_NOISE: [u8; 16] = [
9-
89, 157, 88, 232, 243, 249, 197, 132, 199, 49, 19, 234, 91, 94, 150, 41,
10-
];
11-
121
/// The seed of the metadata account PDA.
132
pub const METADATA: &[u8] = b"metadata";
14-
15-
/// The bump of the mint account.
16-
pub const MINT_BUMP: u8 = ed25519::derive_program_address(&[MINT, &MINT_NOISE], &PROGRAM_ID).1;
17-
18-
/// Program id for const pda derivations
19-
const PROGRAM_ID: [u8; 32] = unsafe { *(&crate::id() as *const Pubkey as *const [u8; 32]) };

tokens/spl-token-minter/steel/api/src/error.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tokens/spl-token-minter/steel/api/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
pub mod consts;
2-
pub mod error;
32
pub mod instruction;
43
pub mod sdk;
54
pub mod utils;
65

76
pub mod prelude {
87
pub use crate::consts::*;
9-
pub use crate::error::*;
108
pub use crate::instruction::*;
119
pub use crate::sdk::*;
1210
pub use crate::utils::*;

tokens/spl-token-minter/steel/api/src/sdk.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ use crate::prelude::*;
44

55
pub fn create(
66
payer: Pubkey,
7+
mint: Pubkey,
78
token_name: [u8; 32],
89
token_symbol: [u8; 8],
910
token_uri: [u8; 64],
1011
) -> Instruction {
11-
let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
1212
let metadata_pda = Pubkey::find_program_address(
13-
&[
14-
METADATA,
15-
mpl_token_metadata::ID.as_ref(),
16-
mint_pda.0.as_ref(),
17-
],
13+
&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()],
1814
&mpl_token_metadata::ID,
1915
);
2016

2117
Instruction {
2218
program_id: crate::ID,
2319
accounts: vec![
2420
AccountMeta::new(payer, true),
25-
AccountMeta::new(mint_pda.0, false),
21+
AccountMeta::new(mint, true),
2622
AccountMeta::new(metadata_pda.0, false),
2723
AccountMeta::new_readonly(system_program::ID, false),
2824
AccountMeta::new_readonly(spl_token::ID, false),
@@ -40,16 +36,16 @@ pub fn create(
4036
pub fn mint(
4137
mint_authority: Pubkey,
4238
recipient: Pubkey,
39+
mint: Pubkey,
4340
associated_token_account: Pubkey,
4441
quantity: u64,
4542
) -> Instruction {
46-
let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
4743
Instruction {
4844
program_id: crate::ID,
4945
accounts: vec![
5046
AccountMeta::new(mint_authority, true),
5147
AccountMeta::new(recipient, false),
52-
AccountMeta::new(mint_pda.0, false),
48+
AccountMeta::new(mint, false),
5349
AccountMeta::new(associated_token_account, false),
5450
AccountMeta::new_readonly(spl_token::ID, false),
5551
AccountMeta::new_readonly(spl_associated_token_account::ID, false),

tokens/spl-token-minter/steel/program/src/create.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,40 @@ pub fn process_create(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
2929
//
3030
msg!("Creating mint account...");
3131
msg!("Mint: {}", mint_info.key);
32-
allocate_account_with_bump(
33-
mint_info,
34-
system_program,
35-
payer_info,
36-
Mint::LEN,
37-
&spl_token::ID,
38-
&[MINT, MINT_NOISE.as_slice()],
39-
MINT_BUMP,
32+
solana_program::program::invoke(
33+
&solana_program::system_instruction::create_account(
34+
payer_info.key,
35+
mint_info.key,
36+
(solana_program::rent::Rent::get()?).minimum_balance(Mint::LEN),
37+
Mint::LEN as u64,
38+
token_program.key,
39+
),
40+
&[
41+
mint_info.clone(),
42+
payer_info.clone(),
43+
system_program.clone(),
44+
token_program.clone(),
45+
],
4046
)?;
4147

4248
// Now initialize that account as a Mint (standard Mint)
4349
//
4450
msg!("Initializing mint account...");
4551
msg!("Mint: {}", mint_info.key);
46-
initialize_mint_signed_with_bump(
47-
mint_info,
48-
payer_info,
49-
None,
50-
token_program,
51-
rent_sysvar,
52-
9, // 9 Decimals for the default SPL Token standard
53-
&[MINT, MINT_NOISE.as_slice()],
54-
MINT_BUMP,
52+
solana_program::program::invoke(
53+
&spl_token::instruction::initialize_mint(
54+
token_program.key,
55+
mint_info.key,
56+
payer_info.key,
57+
Some(payer_info.key),
58+
9, // 9 Decimals for the default SPL Token standard
59+
)?,
60+
&[
61+
mint_info.clone(),
62+
payer_info.clone(),
63+
token_program.clone(),
64+
rent_sysvar.clone(),
65+
],
5566
)?;
5667

5768
// Now create the account for that Mint's metadata

tokens/spl-token-minter/steel/program/src/mint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn process_mint(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
1313
else {
1414
return Err(ProgramError::NotEnoughAccountKeys);
1515
};
16-
1716
mint_authority_info.is_signer()?;
1817
mint_info.as_mint()?;
1918
token_program.is_program(&spl_token::ID)?;

tokens/spl-token-minter/steel/program/tests/test.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use solana_program::hash::Hash;
22
use solana_program_test::{processor, BanksClient, ProgramTest};
33
use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
44
use spl_token_minter_api::prelude::*;
5-
use steel::*;
65

76
async fn setup() -> (BanksClient, Keypair, Hash) {
87
let mut program_test = ProgramTest::new(
@@ -21,29 +20,38 @@ async fn setup() -> (BanksClient, Keypair, Hash) {
2120
async fn run_test() {
2221
// Setup test
2322
let (mut banks, payer, blockhash) = setup().await;
23+
let mint_keypair = Keypair::new();
2424

2525
let name = str_to_bytes::<32>("Solana Gold");
2626
let symbol = str_to_bytes::<8>("GOLDSOL");
2727
let uri = str_to_bytes::<64>("https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json");
2828

2929
// Submit create transaction.
30-
let ix = create(payer.pubkey(), name, symbol, uri);
31-
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
30+
let ix = create(payer.pubkey(), mint_keypair.pubkey(), name, symbol, uri);
31+
let tx = Transaction::new_signed_with_payer(
32+
&[ix],
33+
Some(&payer.pubkey()),
34+
&[&payer, &mint_keypair],
35+
blockhash,
36+
);
3237
let res = banks.process_transaction(tx).await;
3338
assert!(res.is_ok());
3439

35-
let mint_pda =
36-
Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &spl_token_minter_api::ID);
37-
3840
let recipient = Keypair::new();
3941

4042
let to_ata = spl_associated_token_account::get_associated_token_address(
4143
&recipient.pubkey(),
42-
&mint_pda.0,
44+
&mint_keypair.pubkey(),
4345
);
4446

4547
// Submit mint transaction.
46-
let ix = mint(payer.pubkey(), recipient.pubkey(), to_ata, 100);
48+
let ix = mint(
49+
payer.pubkey(),
50+
recipient.pubkey(),
51+
mint_keypair.pubkey(),
52+
to_ata,
53+
100,
54+
);
4755
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
4856
let res = banks.process_transaction(tx).await;
4957
assert!(res.is_ok());

tokens/spl-token-minter/steel/tests/test.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,19 @@ describe("SPL Token Minter", () => {
3838
`${require("node:os").homedir()}/.config/solana/id.json`,
3939
);
4040

41-
const MINT = Buffer.from("mint");
42-
const MINT_NOISE = Buffer.from([
43-
89, 157, 88, 232, 243, 249, 197, 132, 199, 49, 19, 234, 91, 94, 150, 41,
44-
]);
41+
const mintKeypair: Keypair = Keypair.generate();
4542

4643
const PROGRAM_ID = new PublicKey(
4744
"8V26fyhrQobKbvkRCV3KvT6jZQLzviovdARfGrw8kUdG",
4845
);
4946

5047
it("Create SPL Token", async () => {
5148
try {
52-
const [mintPDA] = PublicKey.findProgramAddressSync(
53-
[MINT, MINT_NOISE],
54-
PROGRAM_ID,
55-
);
56-
5749
const [metadataPDA] = PublicKey.findProgramAddressSync(
5850
[
5951
Buffer.from("metadata"),
6052
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
61-
mintPDA.toBuffer(),
53+
mintKeypair.publicKey.toBuffer(),
6254
],
6355
TOKEN_METADATA_PROGRAM_ID,
6456
);
@@ -72,7 +64,7 @@ describe("SPL Token Minter", () => {
7264
const createTokenIx = new TransactionInstruction({
7365
keys: [
7466
{ pubkey: payer.publicKey, isSigner: true, isWritable: true },
75-
{ pubkey: mintPDA, isSigner: false, isWritable: true },
67+
{ pubkey: mintKeypair.publicKey, isSigner: true, isWritable: true },
7668
{ pubkey: metadataPDA, isSigner: false, isWritable: true },
7769
{
7870
pubkey: SystemProgram.programId,
@@ -94,7 +86,7 @@ describe("SPL Token Minter", () => {
9486
const signature = await sendAndConfirmTransaction(
9587
connection,
9688
new Transaction().add(createTokenIx),
97-
[payer],
89+
[payer, mintKeypair],
9890
{ skipPreflight: true },
9991
);
10092
console.log("Create transaction:", signature);
@@ -108,13 +100,8 @@ describe("SPL Token Minter", () => {
108100

109101
it("Mint tokens", async () => {
110102
try {
111-
const [mintPDA] = PublicKey.findProgramAddressSync(
112-
[MINT, MINT_NOISE],
113-
PROGRAM_ID,
114-
);
115-
116103
const recipientATA = await getAssociatedTokenAddress(
117-
mintPDA,
104+
mintKeypair.publicKey,
118105
payer.publicKey,
119106
);
120107

@@ -126,7 +113,7 @@ describe("SPL Token Minter", () => {
126113
payer.publicKey, // Payer
127114
recipientATA, // ATA Address
128115
payer.publicKey, // Owner
129-
mintPDA, // Mint
116+
mintKeypair.publicKey, // Mint
130117
),
131118
);
132119
}
@@ -137,7 +124,7 @@ describe("SPL Token Minter", () => {
137124
keys: [
138125
{ pubkey: payer.publicKey, isSigner: true, isWritable: true }, // mint_authority
139126
{ pubkey: payer.publicKey, isSigner: false, isWritable: false }, // recipient
140-
{ pubkey: mintPDA, isSigner: false, isWritable: true }, // mint_pda must be writable
127+
{ pubkey: mintKeypair.publicKey, isSigner: false, isWritable: true }, // mint_pda must be writable
141128
{ pubkey: recipientATA, isSigner: false, isWritable: true }, // associated_token_account must be writable
142129
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // spl_token::ID
143130
{

0 commit comments

Comments
 (0)