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

Commit 253d520

Browse files
committed
single-pool-cli: move initialize/reactivate/metadata into subcommand
1 parent fec706d commit 253d520

File tree

3 files changed

+71
-25
lines changed

3 files changed

+71
-25
lines changed

single-pool/cli/src/cli.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,9 @@ pub struct Cli {
7171

7272
#[derive(Clone, Debug, Subcommand)]
7373
pub enum Command {
74-
/// Permissionlessly create the single-validator stake pool for a given validator vote account
75-
/// if one does not already exist. The fee payer also pays rent-exemption for accounts,
76-
/// along with the cluster-configured minimum stake delegation
77-
Initialize(InitializeCli),
78-
79-
/// Permissionlessly re-stake the pool stake account in the case when it has been deactivated.
80-
/// This may happen if the validator is force-deactivated, and then later reactivated using
81-
/// the same address for its vote account.
82-
Reactivate(ReactivateCli),
74+
/// Commands used to initialize or manage existing single-validator stake pools.
75+
/// Other than initializing new pools, most users should never need to use these.
76+
Manage(ManageCli),
8377

8478
/// Deposit delegated stake into a pool in exchange for pool tokens, closing out
8579
/// the original stake account. Provide either a stake account address, or a
@@ -92,20 +86,39 @@ pub enum Command {
9286
/// or the ALL keyword to burn all.
9387
Withdraw(WithdrawCli),
9488

89+
/// Create and delegate a new stake account to a given validator, using a default address
90+
/// linked to the intended depository pool
91+
CreateDefaultStake(CreateStakeCli),
92+
93+
/// Display info for one or all single single-validator stake pool(s)
94+
Display(DisplayCli),
95+
}
96+
97+
#[derive(Clone, Debug, Parser)]
98+
pub struct ManageCli {
99+
#[clap(subcommand)]
100+
pub manage: ManageCommand,
101+
}
102+
103+
#[derive(Clone, Debug, Subcommand)]
104+
pub enum ManageCommand {
105+
/// Permissionlessly create the single-validator stake pool for a given validator vote account
106+
/// if one does not already exist. The fee payer also pays rent-exemption for accounts,
107+
/// along with the cluster-configured minimum stake delegation
108+
Initialize(InitializeCli),
109+
110+
/// Permissionlessly re-stake the pool stake account in the case when it has been deactivated.
111+
/// This may happen if the validator is force-deactivated, and then later reactivated using
112+
/// the same address for its vote account.
113+
Reactivate(ReactivateCli),
114+
95115
/// Permissionlessly create default MPL token metadata for the pool mint. Normally this is done
96116
/// automatically upon initialization, so this does not need to be called.
97117
CreateTokenMetadata(CreateMetadataCli),
98118

99119
/// Modify the MPL token metadata associated with the pool mint. This action can only be
100120
/// performed by the validator vote account's withdraw authority
101121
UpdateTokenMetadata(UpdateMetadataCli),
102-
103-
/// Create and delegate a new stake account to a given validator, using a default address
104-
/// linked to the intended depository pool
105-
CreateDefaultStake(CreateStakeCli),
106-
107-
/// Display info for one or all single single-validator stake pool(s)
108-
Display(DisplayCli),
109122
}
110123

111124
#[derive(Clone, Debug, Args)]
@@ -408,7 +421,9 @@ impl Command {
408421
"token_authority",
409422
)?;
410423
}
411-
Command::UpdateTokenMetadata(ref mut config) => {
424+
Command::Manage(ManageCli {
425+
manage: ManageCommand::UpdateTokenMetadata(ref mut config),
426+
}) => {
412427
config.authorized_withdrawer = with_signer(
413428
matches,
414429
wallet_manager,

single-pool/cli/src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ pub type CommandResult = Result<String, Error>;
6060
impl Command {
6161
pub async fn execute(self, config: &Config) -> CommandResult {
6262
match self {
63-
Command::Initialize(command_config) => command_initialize(config, command_config).await,
64-
Command::Reactivate(command_config) => command_reactivate(config, command_config).await,
63+
Command::Manage(command) => match command.manage {
64+
ManageCommand::Initialize(command_config) => {
65+
command_initialize(config, command_config).await
66+
}
67+
ManageCommand::Reactivate(command_config) => {
68+
command_reactivate(config, command_config).await
69+
}
70+
ManageCommand::CreateTokenMetadata(command_config) => {
71+
command_create_metadata(config, command_config).await
72+
}
73+
ManageCommand::UpdateTokenMetadata(command_config) => {
74+
command_update_metadata(config, command_config).await
75+
}
76+
},
6577
Command::Deposit(command_config) => command_deposit(config, command_config).await,
6678
Command::Withdraw(command_config) => command_withdraw(config, command_config).await,
67-
Command::CreateTokenMetadata(command_config) => {
68-
command_create_metadata(config, command_config).await
69-
}
70-
Command::UpdateTokenMetadata(command_config) => {
71-
command_update_metadata(config, command_config).await
72-
}
7379
Command::CreateDefaultStake(command_config) => {
7480
command_create_stake(config, command_config).await
7581
}

single-pool/cli/tests/test.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct Env {
3939
pub rpc_client: Arc<RpcClient>,
4040
pub program_client: PClient,
4141
pub payer: Keypair,
42+
pub keypair_file_path: String,
4243
pub config_file_path: String,
4344
pub vote_account: Pubkey,
4445

@@ -79,6 +80,7 @@ async fn setup(initialize: bool) -> Env {
7980
if initialize {
8081
let status = Command::new(SVSP_CLI)
8182
.args([
83+
"manage",
8284
"initialize",
8385
"-C",
8486
config_file_path,
@@ -93,6 +95,7 @@ async fn setup(initialize: bool) -> Env {
9395
rpc_client,
9496
program_client,
9597
payer,
98+
keypair_file_path: keypair_file.path().to_str().unwrap().to_string(),
9699
config_file_path: config_file_path.to_string(),
97100
vote_account,
98101
validator,
@@ -257,6 +260,7 @@ async fn reactivate() {
257260
// so we just make sure the cli can send a well-formed instruction
258261
let output = Command::new(SVSP_CLI)
259262
.args([
263+
"manage",
260264
"reactivate",
261265
"-C",
262266
&env.config_file_path,
@@ -360,6 +364,7 @@ async fn create_metadata() {
360364

361365
let status = Command::new(SVSP_CLI)
362366
.args([
367+
"manage",
363368
"initialize",
364369
"-C",
365370
&env.config_file_path,
@@ -372,6 +377,7 @@ async fn create_metadata() {
372377

373378
let status = Command::new(SVSP_CLI)
374379
.args([
380+
"manage",
375381
"create-token-metadata",
376382
"-C",
377383
&env.config_file_path,
@@ -390,6 +396,7 @@ async fn update_metadata() {
390396

391397
let status = Command::new(SVSP_CLI)
392398
.args([
399+
"manage",
393400
"update-token-metadata",
394401
"-C",
395402
&env.config_file_path,
@@ -401,4 +408,22 @@ async fn update_metadata() {
401408
.status()
402409
.unwrap();
403410
assert!(status.success());
411+
412+
// testing this flag because the match is rather torturous
413+
let status = Command::new(SVSP_CLI)
414+
.args([
415+
"manage",
416+
"update-token-metadata",
417+
"-C",
418+
&env.config_file_path,
419+
"--vote-account",
420+
&env.vote_account.to_string(),
421+
"--authorized-withdrawer",
422+
&env.keypair_file_path,
423+
"something",
424+
"new",
425+
])
426+
.status()
427+
.unwrap();
428+
assert!(status.success());
404429
}

0 commit comments

Comments
 (0)