Skip to content

Commit

Permalink
allow vanity mints for single mint commands (#314)
Browse files Browse the repository at this point in the history
* allow vanity mints for single mint commands

* fix naming inconsistency
  • Loading branch information
samuelvanderwaal authored Dec 24, 2023
1 parent c49a03c commit 5df43f0
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ indicatif = { version = "0.16.2", features = ["rayon"] }
jib = "0.4.1"
lazy_static = "1.4.0"
log = "0.4.20"
metaboss_lib = "0.16.1"
metaboss_lib = "0.17.0"
mpl-token-metadata = { version = "3.2.3", features = ["serde"] }
num_cpus = "1.16.0"
phf = { version = "0.10", features = ["macros"] }
Expand Down
9 changes: 8 additions & 1 deletion src/create/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct CreateFungibleArgs {
pub client: RpcClient,
pub keypair: Option<String>,
pub metadata: String,
pub mint_path: Option<String>,
pub decimals: u8,
pub initial_supply: Option<f64>,
pub immutable: bool,
Expand Down Expand Up @@ -111,7 +112,13 @@ pub fn create_fungible(args: CreateFungibleArgs) -> Result<()> {
let solana_opts = parse_solana_config();
let keypair = parse_keypair(args.keypair, solana_opts);

let mint = Keypair::new();
let mint = if let Some(path) = args.mint_path {
read_keypair_file(&path)
.map_err(|e| anyhow!(format!("Failed to read mint keypair file: {e}")))?
} else {
Keypair::new()
};

let metadata_pubkey = derive_metadata_pda(&mint.pubkey());

let f = File::open(args.metadata)?;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn main() -> Result<()> {
additional_bytes,
} => process_extend_program(client, keypair_path, program_address, additional_bytes)?,
Command::Find { find_subcommands } => process_find(&client, find_subcommands)?,
Command::Mint { mint_subcommands } => process_mint(&client, mint_subcommands)?,
Command::Mint { mint_subcommands } => process_mint(client, mint_subcommands)?,
Command::ParseErrors {
parse_errors_file_subcommands,
} => process_parse_errors_file(parse_errors_file_subcommands)?,
Expand Down
49 changes: 38 additions & 11 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn mint_from_files(
immutable,
primary_sale_happened,
max_editions,
None, // Generate new mint keypair.
sign,
sized,
) {
Expand Down Expand Up @@ -194,6 +195,7 @@ pub fn mint_from_uris(
immutable,
primary_sale_happened,
max_editions,
None,
sign,
false,
) {
Expand Down Expand Up @@ -227,6 +229,7 @@ pub fn mint_from_uris(
immutable,
primary_sale_happened,
max_editions,
None,
sign,
false,
) {
Expand Down Expand Up @@ -274,6 +277,7 @@ pub fn mint_one<P: AsRef<Path>>(
immutable: bool,
primary_sale_happened: bool,
max_editions: i64,
mint_path: Option<String>,
sign: bool,
sized: bool,
) -> Result<String> {
Expand Down Expand Up @@ -327,6 +331,7 @@ pub fn mint_one<P: AsRef<Path>>(
immutable,
primary_sale_happened,
max_editions,
mint_path,
sized,
)?;
info!("Tx sig: {:?}\nMint account: {:?}", &tx_id, &mint_account);
Expand Down Expand Up @@ -583,10 +588,15 @@ pub fn mint(
immutable: bool,
primary_sale_happened: bool,
max_editions: i64,
mint_path: Option<String>,
sized: bool,
) -> Result<(Signature, Pubkey)> {
let metaplex_program_id = Pubkey::from_str(METAPLEX_PROGRAM_ID)?;
let mint = Keypair::new();
let mint = if let Some(mint_path) = mint_path {
read_keypair(&mint_path).expect("Invalid mint keypair path")
} else {
Keypair::new()
};

// Max editions of -1 means infinite supply (max_supply = None)
// Otherwise max_supply is the number of editions
Expand Down Expand Up @@ -734,15 +744,29 @@ pub fn mint(
Ok((sig, mint.pubkey()))
}

pub fn process_mint_asset(
client: &RpcClient,
keypair_path: Option<String>,
receiver: Option<String>,
asset_data: PathBuf,
decimals: u8,
amount: u64,
max_print_edition_supply: Option<Supply>,
) -> Result<()> {
pub struct MintAssetParams {
pub client: RpcClient,
pub keypair_path: Option<String>,
pub receiver: Option<String>,
pub mint_path: Option<String>,
pub asset_data: PathBuf,
pub decimals: u8,
pub amount: u64,
pub max_print_edition_supply: Option<Supply>,
}

pub fn process_mint_asset(args: MintAssetParams) -> Result<()> {
let MintAssetParams {
client,
keypair_path,
receiver,
mint_path,
asset_data,
decimals,
amount,
max_print_edition_supply,
} = args;

let solana_opts = parse_solana_config();
// Authority is the payer as well.
let authority = parse_keypair(keypair_path, solana_opts);
Expand All @@ -758,18 +782,21 @@ pub fn process_mint_asset(

let print_supply = max_print_edition_supply.map(|s| s.into());

let mint = mint_path.map(|path| read_keypair(&path).expect("Invalid mint keypair path"));

let args = MintAssetArgs::V1 {
payer: None,
authority: &authority,
receiver,
mint,
asset_data,
amount,
mint_decimals: Some(decimals),
print_supply,
authorization_data: None,
};

let mint_result = mint_asset(client, args)?;
let mint_result = mint_asset(&client, args)?;

println!("Minted asset: {:?}", mint_result.mint);
println!("Transaction signature: {:?}", mint_result.signature);
Expand Down
14 changes: 13 additions & 1 deletion src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub enum CreateSubcommands {
#[structopt(short, long)]
keypair: Option<String>,

/// Mint account
/// Existing mint account created elsewhere
#[structopt(short = "a", long)]
mint: String,

Expand All @@ -342,6 +342,10 @@ pub enum CreateSubcommands {
#[structopt(short, long)]
metadata: String,

/// Vanity mint: path to a keypair file to use for the mint address.
#[structopt(long)]
mint_path: Option<String>,

/// SPL token decmials, defaults to 0.
#[structopt(short, long, default_value = "0")]
decimals: u8,
Expand Down Expand Up @@ -813,6 +817,10 @@ pub enum MintSubcommands {
#[structopt(short = "R", long)]
receiver: Option<String>,

/// Path to mint keypair file, if minting from existing keypair.
#[structopt(short, long)]
mint_path: Option<String>,

/// Asset data
#[structopt(short = "d", long)]
asset_data: PathBuf,
Expand Down Expand Up @@ -841,6 +849,10 @@ pub enum MintSubcommands {
#[structopt(short = "R", long)]
receiver: Option<String>,

/// Path to the keypair of the mint account to use for the new NFT
#[structopt(long)]
mint_path: Option<String>,

/// On-chain formatted metadata for the new NFT
#[structopt(short = "d", long)]
nft_data_file: Option<String>,
Expand Down
26 changes: 17 additions & 9 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use crate::derive::{
get_generic_pda, get_metadata_pda, get_token_record_pda,
};
use crate::find::find_missing_editions_process;
use crate::mint::{mint_editions, mint_list, mint_missing_editions, mint_one, process_mint_asset};
use crate::mint::{
mint_editions, mint_list, mint_missing_editions, mint_one, process_mint_asset, MintAssetParams,
};
use crate::opt::*;
use crate::parse::{is_only_one_option, parse_errors_code, parse_errors_file};
use crate::sign::{sign_all, sign_one};
Expand Down Expand Up @@ -323,13 +325,15 @@ pub fn process_create(client: RpcClient, commands: CreateSubcommands) -> Result<
CreateSubcommands::Fungible {
keypair,
metadata,
mint_path,
decimals,
initial_supply,
immutable,
} => create_fungible(CreateFungibleArgs {
client,
keypair,
metadata,
mint_path,
decimals,
initial_supply,
immutable,
Expand Down Expand Up @@ -471,27 +475,30 @@ pub fn process_find(client: &RpcClient, commands: FindSubcommands) -> Result<()>
}
}

pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()> {
pub fn process_mint(client: RpcClient, commands: MintSubcommands) -> Result<()> {
match commands {
MintSubcommands::Asset {
keypair,
receiver,
mint_path,
asset_data,
amount,
decimals,
max_print_edition_supply,
} => process_mint_asset(
} => process_mint_asset(MintAssetParams {
client,
keypair,
keypair_path: keypair,
receiver,
mint_path,
asset_data,
decimals,
amount,
max_print_edition_supply,
),
}),
MintSubcommands::One {
keypair,
receiver,
mint_path,
nft_data_file,
external_metadata_uri,
immutable,
Expand All @@ -500,14 +507,15 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
sign,
sized,
} => mint_one(
client,
&client,
keypair,
&receiver,
nft_data_file,
external_metadata_uri.as_ref(),
immutable,
primary_sale_happened,
max_editions,
mint_path,
sign,
sized,
)
Expand All @@ -519,15 +527,15 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
next_editions,
specific_editions,
} => mint_editions(
client,
&client,
keypair,
account,
&receiver,
next_editions,
specific_editions,
),
MintSubcommands::MissingEditions { keypair, account } => {
mint_missing_editions(client, &keypair, &account)
mint_missing_editions(&client, &keypair, &account)
}
MintSubcommands::List {
keypair,
Expand All @@ -539,7 +547,7 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
sign,
track,
} => mint_list(
client,
&client,
keypair,
receiver,
nft_data_dir,
Expand Down

0 comments on commit 5df43f0

Please sign in to comment.