Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 1afac08

Browse files
sense112joncinque
andauthored
Add Create & Update Token Commands to Stake-Pool CLI (#6805)
* Add token metadata commands * Update stake-pool/cli/src/main.rs Co-authored-by: Jon C <me@jonc.dev> * Update stake-pool/cli/src/main.rs Co-authored-by: Jon C <me@jonc.dev> * Fix formatting --------- Co-authored-by: Jon C <me@jonc.dev>
1 parent 9af36d8 commit 1afac08

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

stake-pool/cli/src/main.rs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,57 @@ fn command_create_pool(
491491
Ok(())
492492
}
493493

494+
fn create_token_metadata(
495+
config: &Config,
496+
stake_pool_address: &Pubkey,
497+
name: String,
498+
symbol: String,
499+
uri: String,
500+
) -> CommandResult {
501+
let stake_pool = get_stake_pool(&config.rpc_client, stake_pool_address)?;
502+
503+
let mut signers = vec![config.fee_payer.as_ref(), config.manager.as_ref()];
504+
let instructions = vec![spl_stake_pool::instruction::create_token_metadata(
505+
&spl_stake_pool::id(),
506+
stake_pool_address,
507+
&stake_pool.manager,
508+
&stake_pool.pool_mint,
509+
&config.fee_payer.pubkey(),
510+
name,
511+
symbol,
512+
uri,
513+
)];
514+
unique_signers!(signers);
515+
let transaction = checked_transaction_with_signers(config, &instructions, &signers)?;
516+
send_transaction(config, transaction)?;
517+
Ok(())
518+
}
519+
520+
fn update_token_metadata(
521+
config: &Config,
522+
stake_pool_address: &Pubkey,
523+
name: String,
524+
symbol: String,
525+
uri: String,
526+
) -> CommandResult {
527+
let stake_pool = get_stake_pool(&config.rpc_client, stake_pool_address)?;
528+
529+
let mut signers = vec![config.fee_payer.as_ref(), config.manager.as_ref()];
530+
let instructions = vec![spl_stake_pool::instruction::update_token_metadata(
531+
&spl_stake_pool::id(),
532+
stake_pool_address,
533+
&stake_pool.manager,
534+
&stake_pool.pool_mint,
535+
name,
536+
symbol,
537+
uri,
538+
)];
539+
unique_signers!(signers);
540+
let transaction = checked_transaction_with_signers(config, &instructions, &signers)?;
541+
send_transaction(config, transaction)?;
542+
Ok(())
543+
}
544+
494545
fn command_vsa_add(
495546
config: &Config,
496547
stake_pool_address: &Pubkey,
@@ -2175,6 +2226,78 @@ fn main() {
21752226
.help("Bypass fee checks, allowing pool to be created with unsafe fees"),
21762227
)
21772228
)
2229+
.subcommand(SubCommand::with_name("create-token-metadata")
2230+
.about("Creates stake pool token metadata")
2231+
.arg(
2232+
Arg::with_name("pool")
2233+
.index(1)
2234+
.validator(is_pubkey)
2235+
.value_name("POOL_ADDRESS")
2236+
.takes_value(true)
2237+
.required(true)
2238+
.help("Stake pool address"),
2239+
)
2240+
.arg(
2241+
Arg::with_name("name")
2242+
.index(2)
2243+
.value_name("TOKEN_NAME")
2244+
.takes_value(true)
2245+
.required(true)
2246+
.help("Name of the token"),
2247+
)
2248+
.arg(
2249+
Arg::with_name("symbol")
2250+
.index(3)
2251+
.value_name("TOKEN_SYMBOL")
2252+
.takes_value(true)
2253+
.required(true)
2254+
.help("Symbol of the token"),
2255+
)
2256+
.arg(
2257+
Arg::with_name("uri")
2258+
.index(4)
2259+
.value_name("TOKEN_URI")
2260+
.takes_value(true)
2261+
.required(true)
2262+
.help("URI of the token metadata json"),
2263+
)
2264+
)
2265+
.subcommand(SubCommand::with_name("update-token-metadata")
2266+
.about("Updates stake pool token metadata")
2267+
.arg(
2268+
Arg::with_name("pool")
2269+
.index(1)
2270+
.validator(is_pubkey)
2271+
.value_name("POOL_ADDRESS")
2272+
.takes_value(true)
2273+
.required(true)
2274+
.help("Stake pool address"),
2275+
)
2276+
.arg(
2277+
Arg::with_name("name")
2278+
.index(2)
2279+
.value_name("TOKEN_NAME")
2280+
.takes_value(true)
2281+
.required(true)
2282+
.help("Name of the token"),
2283+
)
2284+
.arg(
2285+
Arg::with_name("symbol")
2286+
.index(3)
2287+
.value_name("TOKEN_SYMBOL")
2288+
.takes_value(true)
2289+
.required(true)
2290+
.help("Symbol of the token"),
2291+
)
2292+
.arg(
2293+
Arg::with_name("uri")
2294+
.index(4)
2295+
.value_name("TOKEN_URI")
2296+
.takes_value(true)
2297+
.required(true)
2298+
.help("URI of the token metadata json"),
2299+
)
2300+
)
21782301
.subcommand(SubCommand::with_name("add-validator")
21792302
.about("Add validator account to the stake pool. Must be signed by the pool staker.")
21802303
.arg(
@@ -2900,6 +3023,20 @@ fn main() {
29003023
unsafe_fees,
29013024
)
29023025
}
3026+
("create-token-metadata", Some(arg_matches)) => {
3027+
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
3028+
let name = value_t_or_exit!(arg_matches, "name", String);
3029+
let symbol = value_t_or_exit!(arg_matches, "symbol", String);
3030+
let uri = value_t_or_exit!(arg_matches, "uri", String);
3031+
create_token_metadata(&config, &stake_pool_address, name, symbol, uri)
3032+
}
3033+
("update-token-metadata", Some(arg_matches)) => {
3034+
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
3035+
let name = value_t_or_exit!(arg_matches, "name", String);
3036+
let symbol = value_t_or_exit!(arg_matches, "symbol", String);
3037+
let uri = value_t_or_exit!(arg_matches, "uri", String);
3038+
update_token_metadata(&config, &stake_pool_address, name, symbol, uri)
3039+
}
29033040
("add-validator", Some(arg_matches)) => {
29043041
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
29053042
let vote_account_address = pubkey_of(arg_matches, "vote_account").unwrap();

0 commit comments

Comments
 (0)