Skip to content

Commit

Permalink
feat(cli-vault): command show to vaults by index
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Oct 15, 2024
1 parent 19597dc commit ac0e078
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cli/src/command/display_vault.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use squads_multisig::pda::get_vault_pda;
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;

use clap::Args;

#[derive(Args)]
pub struct DisplayVault {
/// Multisig Program ID
#[arg(long)]
program_id: Option<String>,

/// Path to the Program Config Initializer Keypair
#[arg(long)]
multisig_address: String,

// index to derive the vault, default 0
#[arg(long)]
vault_index: Option<u8>,
}

impl DisplayVault {
pub async fn execute(self) -> eyre::Result<()> {
let Self {
program_id,
multisig_address,
vault_index,
} = self;

let program_id = program_id.unwrap_or_else(|| {
"SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf".to_string()
});

let program_id = Pubkey::from_str(&program_id).expect("Invalid program ID");

let multisig_address = Pubkey::from_str(&multisig_address).expect("Invalid multisig address");

let vault_index = vault_index.unwrap_or(0);

let vault_address = get_vault_pda(&multisig_address, vault_index, Some(&program_id));

println!("Vault: {:?}", vault_address);

Ok(())
}
}
3 changes: 3 additions & 0 deletions cli/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::command::proposal_vote::ProposalVote;
use crate::command::vault_transaction_accounts_close::VaultTransactionAccountsClose;
use crate::command::vault_transaction_create::VaultTransactionCreate;
use crate::command::vault_transaction_execute::VaultTransactionExecute;
use crate::command::display_vault::DisplayVault;

use clap::Subcommand;

Expand All @@ -21,6 +22,7 @@ pub mod proposal_vote;
pub mod vault_transaction_accounts_close;
pub mod vault_transaction_create;
pub mod vault_transaction_execute;
pub mod display_vault;

#[derive(Subcommand)]
pub enum Command {
Expand All @@ -34,4 +36,5 @@ pub enum Command {
VaultTransactionAccountsClose(VaultTransactionAccountsClose),
InitiateTransfer(InitiateTransfer),
InitiateProgramUpgrade(InitiateProgramUpgrade),
DisplayVault(DisplayVault),
}
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ async fn main() -> eyre::Result<()> {
Command::VaultTransactionAccountsClose(command) => command.execute().await,
Command::InitiateTransfer(command) => command.execute().await,
Command::InitiateProgramUpgrade(command) => command.execute().await,
Command::DisplayVault(command) => command.execute().await,
}
}

0 comments on commit ac0e078

Please sign in to comment.