Skip to content

Commit

Permalink
Relax double signer constraints on set admin, add to CLI (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell authored Oct 30, 2024
1 parent fde8b70 commit 9c4fa2a
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 8 deletions.
6 changes: 6 additions & 0 deletions cli/src/restaking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{command, Subcommand};
use solana_program::pubkey::Pubkey;

/// The CLI handler for the restaking program
#[derive(Subcommand)]
Expand All @@ -25,6 +26,11 @@ pub enum ConfigActions {
Initialize,
/// Get the config
Get,
/// Set the config admin
SetAdmin {
/// The new admin's pubkey
new_admin: Pubkey,
},
}

#[derive(Subcommand)]
Expand Down
40 changes: 39 additions & 1 deletion cli/src/restaking_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use anyhow::{anyhow, Result};
use jito_bytemuck::{AccountDeserialize, Discriminator};
use jito_restaking_client::instructions::{
InitializeConfigBuilder, InitializeNcnBuilder, InitializeOperatorBuilder,
InitializeConfigBuilder, InitializeNcnBuilder, InitializeOperatorBuilder, SetConfigAdminBuilder,
};
use jito_restaking_core::{config::Config, ncn::Ncn, operator::Operator};
use log::{debug, info};
Expand Down Expand Up @@ -51,6 +51,9 @@ impl RestakingCliHandler {
RestakingCommands::Config {
action: ConfigActions::Get,
} => self.get_config().await,
RestakingCommands::Config {
action: ConfigActions::SetAdmin { new_admin },
} => self.set_config_admin(new_admin).await,
RestakingCommands::Ncn {
action: NcnActions::Initialize,
} => self.initialize_ncn().await,
Expand Down Expand Up @@ -288,4 +291,39 @@ impl RestakingCliHandler {
fn get_rpc_client(&self) -> RpcClient {
RpcClient::new_with_commitment(self.cli_config.rpc_url.clone(), self.cli_config.commitment)
}

async fn set_config_admin(&self, new_admin: Pubkey) -> Result<()> {
let keypair = self
.cli_config
.keypair
.as_ref()
.ok_or_else(|| anyhow!("No keypair"))?;
let rpc_client = self.get_rpc_client();

let config_address = Config::find_program_address(&self.restaking_program_id).0;
let mut ix_builder = SetConfigAdminBuilder::new();
ix_builder
.config(config_address)
.old_admin(keypair.pubkey())
.new_admin(new_admin);

let blockhash = rpc_client.get_latest_blockhash().await?;
let tx = Transaction::new_signed_with_payer(
&[ix_builder.instruction()],
Some(&keypair.pubkey()),
&[keypair],
blockhash,
);
info!(
"Setting restaking config admin parameters: {:?}",
ix_builder
);
info!(
"Setting restaking config admin transaction: {:?}",
tx.get_signature()
);
rpc_client.send_and_confirm_transaction(&tx).await?;
info!("Transaction confirmed: {:?}", tx.get_signature());
Ok(())
}
}
5 changes: 5 additions & 0 deletions cli/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub enum ConfigActions {
},
/// Fetches global config
Get,
/// Set the config admin
SetAdmin {
/// The new admin's pubkey
new_admin: Pubkey,
},
}

/// Vault commands
Expand Down
37 changes: 36 additions & 1 deletion cli/src/vault_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{anyhow, Result};
use jito_bytemuck::{AccountDeserialize, Discriminator};
use jito_vault_client::instructions::{
CreateTokenMetadataBuilder, InitializeConfigBuilder, InitializeVaultBuilder,
SetDepositCapacityBuilder,
SetConfigAdminBuilder, SetDepositCapacityBuilder,
};
use jito_vault_core::{config::Config, vault::Vault};
use jito_vault_sdk::inline_mpl_token_metadata;
Expand Down Expand Up @@ -60,6 +60,9 @@ impl VaultCliHandler {
VaultCommands::Config {
action: ConfigActions::Get,
} => self.get_config().await,
VaultCommands::Config {
action: ConfigActions::SetAdmin { new_admin },
} => self.set_config_admin(new_admin).await,
VaultCommands::Vault {
action:
VaultActions::Initialize {
Expand Down Expand Up @@ -338,4 +341,36 @@ impl VaultCliHandler {

Ok(())
}

async fn set_config_admin(&self, new_admin: Pubkey) -> Result<()> {
let keypair = self
.cli_config
.keypair
.as_ref()
.ok_or_else(|| anyhow!("Keypair not provided"))?;
let rpc_client = self.get_rpc_client();

let config_address = Config::find_program_address(&self.vault_program_id).0;
let mut ix_builder = SetConfigAdminBuilder::new();
ix_builder
.config(config_address)
.old_admin(keypair.pubkey())
.new_admin(new_admin);

let blockhash = rpc_client.get_latest_blockhash().await?;
let tx = Transaction::new_signed_with_payer(
&[ix_builder.instruction()],
Some(&keypair.pubkey()),
&[keypair],
blockhash,
);
info!("Setting vault config admin parameters: {:?}", ix_builder);
info!(
"Setting vault config admin transaction: {:?}",
tx.get_signature()
);
rpc_client.send_and_confirm_transaction(&tx).await?;
info!("Transaction confirmed: {:?}", tx.get_signature());
Ok(())
}
}
26 changes: 26 additions & 0 deletions docs/_tools/00_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Initialize, get, and set the config struct

* `initialize` — Initialize the config
* `get` — Get the config
* `set-admin` — Set the config admin



Expand All @@ -75,6 +76,18 @@ Get the config



## `jito-restaking-cli restaking config set-admin`

Set the config admin

**Usage:** `jito-restaking-cli restaking config set-admin <NEW_ADMIN>`

###### **Arguments:**

* `<NEW_ADMIN>` — The new admin's pubkey



## `jito-restaking-cli restaking ncn`

**Usage:** `jito-restaking-cli restaking ncn <COMMAND>`
Expand Down Expand Up @@ -176,6 +189,7 @@ Vault program commands

* `initialize` — Creates global config (can only be done once)
* `get` — Fetches global config
* `set-admin` — Set the config admin



Expand All @@ -200,6 +214,18 @@ Fetches global config



## `jito-restaking-cli vault config set-admin`

Set the config admin

**Usage:** `jito-restaking-cli vault config set-admin <NEW_ADMIN>`

###### **Arguments:**

* `<NEW_ADMIN>` — The new admin's pubkey



## `jito-restaking-cli vault vault`

Vault commands
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/fixtures/restaking_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ impl RestakingProgramClient {
&new_admin.pubkey(),
)],
Some(&old_admin.pubkey()),
&[old_admin, new_admin],
&[old_admin],
blockhash,
))
.await
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/fixtures/vault_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ impl VaultProgramClient {
&new_admin.pubkey(),
)],
Some(&old_admin.pubkey()),
&[old_admin, new_admin],
&[old_admin],
blockhash,
))
.await
Expand Down
1 change: 0 additions & 1 deletion restaking_program/src/set_config_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn process_set_config_admin(program_id: &Pubkey, accounts: &[AccountInfo]) -
let mut config_data = config.data.borrow_mut();
let config = Config::try_from_slice_unchecked_mut(&mut config_data)?;
load_signer(old_admin, false)?;
load_signer(new_admin, false)?;

if config.admin != *old_admin.key {
return Err(RestakingError::ConfigAdminInvalid.into());
Expand Down
2 changes: 1 addition & 1 deletion restaking_sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ pub fn set_config_admin(
let accounts = vec![
AccountMeta::new(*config, false),
AccountMeta::new_readonly(*old_admin, true),
AccountMeta::new_readonly(*new_admin, true),
AccountMeta::new_readonly(*new_admin, false),
];
Instruction {
program_id: *program_id,
Expand Down
1 change: 0 additions & 1 deletion vault_program/src/set_config_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn process_set_config_admin(program_id: &Pubkey, accounts: &[AccountInfo]) -
let mut config_data = config.data.borrow_mut();
let config = Config::try_from_slice_unchecked_mut(&mut config_data)?;
load_signer(old_admin, false)?;
load_signer(new_admin, false)?;

if config.admin != *old_admin.key {
return Err(VaultError::ConfigAdminInvalid.into());
Expand Down
2 changes: 1 addition & 1 deletion vault_sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ pub fn set_config_admin(
let accounts = vec![
AccountMeta::new(*config, false),
AccountMeta::new_readonly(*old_admin, true),
AccountMeta::new_readonly(*new_admin, true),
AccountMeta::new_readonly(*new_admin, false),
];
Instruction {
program_id: *program_id,
Expand Down

0 comments on commit 9c4fa2a

Please sign in to comment.