Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cli/src/command/multisig_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use squads_multisig::squads_multisig_program::state::ProgramConfig;
use squads_multisig::squads_multisig_program::MultisigCreateArgsV2;
use squads_multisig::state::{Member, Permissions};

use crate::utils::{create_signer_from_path, send_and_confirm_transaction};
use crate::utils::{
create_keypair_from_path, create_signer_from_path, send_and_confirm_transaction,
};

#[derive(Args)]
pub struct MultisigCreate {
Expand Down Expand Up @@ -55,6 +57,10 @@ pub struct MultisigCreate {

#[arg(long)]
priority_fee_lamports: Option<u64>,

/// Optional path to create keypair, for creating deterministic vaults
#[arg(long)]
create_key: Option<String>,
}

impl MultisigCreate {
Expand All @@ -68,6 +74,7 @@ impl MultisigCreate {
threshold,
rent_collector,
priority_fee_lamports,
create_key,
} = self;

let program_id =
Expand Down Expand Up @@ -134,9 +141,13 @@ impl MultisigCreate {
.await
.expect("Failed to get blockhash");

let random_keypair = Keypair::new();
let create_keypair = if let Some(create_key) = create_key {
create_keypair_from_path(create_key).unwrap()
} else {
Keypair::new()
};

let multisig_key = get_multisig_pda(&random_keypair.pubkey(), Some(&program_id));
let multisig_key = get_multisig_pda(&create_keypair.pubkey(), Some(&program_id));

let program_config_pda = get_program_config_pda(Some(&program_id));

Expand All @@ -159,7 +170,7 @@ impl MultisigCreate {
),
Instruction {
accounts: MultisigCreateV2Accounts {
create_key: random_keypair.pubkey(),
create_key: create_keypair.pubkey(),
creator: transaction_creator,
multisig: multisig_key.0,
system_program: system_program::id(),
Expand Down Expand Up @@ -190,7 +201,7 @@ impl MultisigCreate {
VersionedMessage::V0(message),
&[
&*transaction_creator_keypair,
&random_keypair as &dyn Signer,
&create_keypair as &dyn Signer,
],
)
.expect("Failed to create transaction");
Expand Down
9 changes: 8 additions & 1 deletion cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ use clap_v3::ArgMatches;
use colored::Colorize;
use eyre::eyre;
use solana_clap_v3_utils::keypair::signer_from_path;
use solana_sdk::{signer::Signer, transaction::VersionedTransaction};
use solana_sdk::signature::read_keypair_file;
use solana_sdk::{signer::keypair::Keypair, signer::Signer, transaction::VersionedTransaction};
use squads_multisig::solana_client::nonblocking::rpc_client::RpcClient;
use squads_multisig::solana_client::{
client_error::ClientErrorKind,
rpc_request::{RpcError, RpcResponseErrorData},
rpc_response::RpcSimulateTransactionResult,
};

pub fn create_keypair_from_path(
keypair_path: String,
) -> Result<Keypair, Box<dyn std::error::Error>> {
read_keypair_file(&keypair_path).map_err(|e| e.into())
}

pub fn create_signer_from_path(
keypair_path: String,
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
Expand Down