Skip to content

Commit 714a768

Browse files
authored
Add CLI for setting deposit capacity (#155)
1 parent 60b3884 commit 714a768

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

cli/src/bin/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ pub fn get_cli_config(args: &Cli) -> Result<CliConfig, anyhow::Error> {
3131
.as_ref()
3232
.ok_or_else(|| anyhow!("unable to get config file path"))?;
3333
if let Ok(config) = Config::load(config_file) {
34+
let keypair = if let Some(keypair_path) = &args.keypair {
35+
read_keypair_file(keypair_path)
36+
} else {
37+
read_keypair_file(config.keypair_path)
38+
}
39+
.map_err(|e| anyhow!(e.to_string()))?;
40+
let rpc = if let Some(rpc) = &args.rpc_url {
41+
rpc.to_string()
42+
} else {
43+
config.json_rpc_url
44+
};
45+
3446
CliConfig {
35-
rpc_url: config.json_rpc_url,
47+
rpc_url: rpc,
3648
commitment: CommitmentConfig::from_str(&config.commitment)?,
37-
keypair: Some(
38-
read_keypair_file(config.keypair_path).map_err(|e| anyhow!(e.to_string()))?,
39-
),
49+
keypair: Some(keypair),
4050
}
4151
} else {
4252
CliConfig {

cli/src/vault.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ pub enum VaultActions {
6060
},
6161
/// List all vaults
6262
List,
63+
/// Sets the deposit capacity in the vault
64+
SetCapacity {
65+
/// The vault pubkey
66+
vault: String,
67+
/// The new capacity
68+
amount: u64,
69+
},
6370
}

cli/src/vault_handler.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anyhow::{anyhow, Result};
44
use jito_bytemuck::{AccountDeserialize, Discriminator};
55
use jito_vault_client::instructions::{
66
CreateTokenMetadataBuilder, InitializeConfigBuilder, InitializeVaultBuilder,
7+
SetDepositCapacityBuilder,
78
};
89
use jito_vault_core::{config::Config, vault::Vault};
910
use jito_vault_sdk::inline_mpl_token_metadata;
@@ -93,6 +94,9 @@ impl VaultCliHandler {
9394
uri,
9495
},
9596
} => self.create_token_metadata(vault, name, symbol, uri).await,
97+
VaultCommands::Vault {
98+
action: VaultActions::SetCapacity { vault, amount },
99+
} => self.set_capacity(vault, amount).await,
96100
}
97101
}
98102

@@ -296,4 +300,42 @@ impl VaultCliHandler {
296300

297301
Ok(())
298302
}
303+
304+
pub async fn set_capacity(&self, vault: String, amount: u64) -> Result<()> {
305+
let keypair = self
306+
.cli_config
307+
.keypair
308+
.as_ref()
309+
.ok_or_else(|| anyhow!("Keypair not provided"))?;
310+
let vault_pubkey = Pubkey::from_str(&vault)?;
311+
let rpc_client = self.get_rpc_client();
312+
313+
let mut builder = SetDepositCapacityBuilder::new();
314+
builder
315+
.config(Config::find_program_address(&self.vault_program_id).0)
316+
.vault(vault_pubkey)
317+
.admin(keypair.pubkey())
318+
.amount(amount);
319+
320+
let recent_blockhash = rpc_client.get_latest_blockhash().await?;
321+
let tx = Transaction::new_signed_with_payer(
322+
&[builder.instruction()],
323+
Some(&keypair.pubkey()),
324+
&[keypair],
325+
recent_blockhash,
326+
);
327+
328+
info!("Vault capacity instruction: {:?}", builder);
329+
info!(
330+
"Vault capacity transaction signature: {:?}",
331+
tx.get_signature()
332+
);
333+
rpc_client
334+
.send_and_confirm_transaction(&tx)
335+
.await
336+
.map_err(|e| anyhow!(e.to_string()))?;
337+
info!("Transaction confirmed: {:?}", tx.get_signature());
338+
339+
Ok(())
340+
}
299341
}

docs/_tools/00_cli.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Vault commands
212212
* `create-token-metadata` — Creates token metadata for the vault's LRT token
213213
* `get` — Gets a vault
214214
* `list` — List all vaults
215+
* `set-capacity` — Sets the deposit capacity in the vault
215216

216217

217218

@@ -266,6 +267,19 @@ List all vaults
266267

267268

268269

270+
## `jito-restaking-cli vault vault set-capacity`
271+
272+
Sets the deposit capacity in the vault
273+
274+
**Usage:** `jito-restaking-cli vault vault set-capacity <VAULT> <AMOUNT>`
275+
276+
###### **Arguments:**
277+
278+
* `<VAULT>` — The vault pubkey
279+
* `<AMOUNT>` — The new capacity
280+
281+
282+
269283
<hr/>
270284

271285
<small><i>

0 commit comments

Comments
 (0)