From b8c9c61b49af4c77ab21d97168e7259ef2e852a3 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 19:41:03 +0100 Subject: [PATCH 1/8] add ledger --- staking/Cargo.lock | 153 ++++++++++++-------------------- staking/cli/Cargo.toml | 2 + staking/cli/src/cli.rs | 64 ++++++++++++- staking/cli/src/instructions.rs | 40 ++++----- staking/cli/src/main.rs | 46 +++++++--- 5 files changed, 169 insertions(+), 136 deletions(-) diff --git a/staking/Cargo.lock b/staking/Cargo.lock index dfdfdb95..7e1c4523 100644 --- a/staking/Cargo.lock +++ b/staking/Cargo.lock @@ -250,7 +250,7 @@ dependencies = [ "borsh 0.10.3", "bytemuck", "getrandom 0.2.15", - "solana-program 1.18.23", + "solana-program", "thiserror", ] @@ -1897,6 +1897,19 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +[[package]] +name = "hidapi" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b876ecf37e86b359573c16c8366bc3eba52b689884a0fc42ba3f67203d2a8b" +dependencies = [ + "cc", + "cfg-if", + "libc", + "pkg-config", + "windows-sys 0.48.0", +] + [[package]] name = "histogram" version = "0.6.9" @@ -2385,7 +2398,7 @@ dependencies = [ "solana-bpf-loader-program", "solana-compute-budget-program", "solana-loader-v4-program", - "solana-program 1.18.23", + "solana-program", "solana-program-runtime", "solana-sdk", "solana-system-program", @@ -3075,7 +3088,7 @@ dependencies = [ "quickcheck", "quickcheck_macros", "rand 0.8.5", - "solana-program 1.18.23", + "solana-program", "spl-governance", "wasm-bindgen", ] @@ -3100,7 +3113,7 @@ dependencies = [ "serde_wormhole", "sha3 0.10.8", "slow_primes", - "solana-program 2.0.8", + "solana-program", "thiserror", "wormhole-vaas-serde", ] @@ -3984,7 +3997,7 @@ dependencies = [ "serde", "solana-frozen-abi", "solana-frozen-abi-macro", - "solana-program 1.18.23", + "solana-program", "solana-program-runtime", "solana-sdk", "thiserror", @@ -4333,59 +4346,13 @@ dependencies = [ "sha3 0.10.8", "solana-frozen-abi", "solana-frozen-abi-macro", - "solana-sdk-macro 1.18.23", + "solana-sdk-macro", "thiserror", "tiny-bip39", "wasm-bindgen", "zeroize", ] -[[package]] -name = "solana-program" -version = "2.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d899c2a1d37290dcfeeb9d1c0032915a29bd48f35759f19ff1e0f6b096eca0b" -dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-serialize", - "base64 0.22.1", - "bincode", - "bitflags 2.6.0", - "blake3", - "borsh 0.10.3", - "borsh 1.5.1", - "bs58 0.5.1", - "bv", - "bytemuck", - "bytemuck_derive", - "console_error_panic_hook", - "console_log", - "curve25519-dalek", - "getrandom 0.2.15", - "js-sys", - "lazy_static", - "libsecp256k1 0.6.0", - "log", - "memoffset 0.9.1", - "num-bigint 0.4.6", - "num-derive 0.4.2", - "num-traits", - "parking_lot", - "rand 0.8.5", - "rustc_version", - "rustversion", - "serde", - "serde_bytes", - "serde_derive", - "sha2 0.10.8", - "sha3 0.10.8", - "solana-sdk-macro 2.0.8", - "thiserror", - "wasm-bindgen", -] - [[package]] name = "solana-program-runtime" version = "1.18.23" @@ -4484,6 +4451,7 @@ checksum = "9651b3f2c3df39a1a6fc87fe792bdb3ec3d84a8169c0a57c86335b48d6cb1491" dependencies = [ "console", "dialoguer", + "hidapi", "log", "num-derive 0.4.2", "num-traits", @@ -4604,8 +4572,8 @@ dependencies = [ "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", - "solana-program 1.18.23", - "solana-sdk-macro 1.18.23", + "solana-program", + "solana-sdk-macro", "thiserror", "uriparse", "wasm-bindgen", @@ -4624,19 +4592,6 @@ dependencies = [ "syn 2.0.77", ] -[[package]] -name = "solana-sdk-macro" -version = "2.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23198ed620c4a61c97fe49bd907fc965659aea9a5ed0ea0cf90084eecc72a3c1" -dependencies = [ - "bs58 0.5.1", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.77", -] - [[package]] name = "solana-security-txt" version = "1.1.1" @@ -4801,7 +4756,7 @@ dependencies = [ "solana-frozen-abi", "solana-frozen-abi-macro", "solana-metrics", - "solana-program 1.18.23", + "solana-program", "solana-program-runtime", "solana-sdk", "thiserror", @@ -4829,7 +4784,7 @@ dependencies = [ "serde", "serde_json", "sha3 0.9.1", - "solana-program 1.18.23", + "solana-program", "solana-sdk", "subtle", "thiserror", @@ -4887,7 +4842,7 @@ dependencies = [ "borsh 0.10.3", "num-derive 0.4.2", "num-traits", - "solana-program 1.18.23", + "solana-program", "spl-token", "spl-token-2022 1.0.0", "thiserror", @@ -4903,7 +4858,7 @@ dependencies = [ "borsh 1.5.1", "num-derive 0.4.2", "num-traits", - "solana-program 1.18.23", + "solana-program", "spl-token", "spl-token-2022 3.0.4", "thiserror", @@ -4916,7 +4871,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator-derive 0.1.2", ] @@ -4927,7 +4882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "210101376962bb22bb13be6daea34656ea1cbc248fce2164b146e39203b55e03" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator-derive 0.2.0", ] @@ -4992,7 +4947,7 @@ dependencies = [ "num-traits", "serde", "serde_derive", - "solana-program 1.18.23", + "solana-program", "spl-governance-addin-api", "spl-governance-tools", "spl-token", @@ -5006,7 +4961,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dc1be90f8b71e336933fedbe17f645cd33d36e8451dfb6ce1210ef585dc73b6" dependencies = [ "borsh 0.10.3", - "solana-program 1.18.23", + "solana-program", "spl-governance-tools", ] @@ -5023,7 +4978,7 @@ dependencies = [ "num-traits", "serde", "serde_derive", - "solana-program 1.18.23", + "solana-program", "spl-token", "thiserror", ] @@ -5034,7 +4989,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f180b03318c3dbab3ef4e1e4d46d5211ae3c780940dd0a28695aba4b59a75a" dependencies = [ - "solana-program 1.18.23", + "solana-program", ] [[package]] @@ -5045,7 +5000,7 @@ checksum = "2881dddfca792737c0706fa0175345ab282b1b0879c7d877bad129645737c079" dependencies = [ "borsh 0.10.3", "bytemuck", - "solana-program 1.18.23", + "solana-program", "solana-zk-token-sdk", "spl-program-error 0.3.0", ] @@ -5058,7 +5013,7 @@ checksum = "c52d84c55efeef8edcc226743dc089d7e3888b8e3474569aa3eff152b37b9996" dependencies = [ "borsh 1.5.1", "bytemuck", - "solana-program 1.18.23", + "solana-program", "solana-zk-token-sdk", "spl-program-error 0.4.4", ] @@ -5071,7 +5026,7 @@ checksum = "249e0318493b6bcf27ae9902600566c689b7dfba9f1bdff5893e92253374e78c" dependencies = [ "num-derive 0.4.2", "num-traits", - "solana-program 1.18.23", + "solana-program", "spl-program-error-derive 0.3.2", "thiserror", ] @@ -5084,7 +5039,7 @@ checksum = "e45a49acb925db68aa501b926096b2164adbdcade7a0c24152af9f0742d0a602" dependencies = [ "num-derive 0.4.2", "num-traits", - "solana-program 1.18.23", + "solana-program", "spl-program-error-derive 0.4.1", "thiserror", ] @@ -5120,7 +5075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "615d381f48ddd2bb3c57c7f7fb207591a2a05054639b18a62e785117dd7a8683" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5134,7 +5089,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fab8edfd37be5fa17c9e42c1bff86abbbaf0494b031b37957f2728ad2ff842ba" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5152,7 +5107,7 @@ dependencies = [ "num-derive 0.3.3", "num-traits", "num_enum 0.6.1", - "solana-program 1.18.23", + "solana-program", "thiserror", ] @@ -5167,7 +5122,7 @@ dependencies = [ "num-derive 0.4.2", "num-traits", "num_enum 0.7.3", - "solana-program 1.18.23", + "solana-program", "solana-security-txt", "solana-zk-token-sdk", "spl-memo", @@ -5191,7 +5146,7 @@ dependencies = [ "num-derive 0.4.2", "num-traits", "num_enum 0.7.3", - "solana-program 1.18.23", + "solana-program", "solana-security-txt", "solana-zk-token-sdk", "spl-memo", @@ -5211,7 +5166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b889509d49fa74a4a033ca5dae6c2307e9e918122d97e58562f5c4ffa795c75d" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5224,7 +5179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "014817d6324b1e20c4bbc883e8ee30a5faa13e59d91d1b2b95df98b920150c17" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5237,7 +5192,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" dependencies = [ "borsh 0.10.3", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5251,7 +5206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3da00495b602ebcf5d8ba8b3ecff1ee454ce4c125c9077747be49c2d62335ba" dependencies = [ "borsh 1.5.1", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5266,7 +5221,7 @@ checksum = "7aabdb7c471566f6ddcee724beb8618449ea24b399e58d464d6b5bc7db550259" dependencies = [ "arrayref", "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5282,7 +5237,7 @@ checksum = "a9b5c08a89838e5a2931f79b17f611857f281a14a2100968a3ccef352cb7414b" dependencies = [ "arrayref", "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5297,7 +5252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5310,7 +5265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c872f93d0600e743116501eba2d53460e73a12c9a496875a42a7d70e034fe06d" dependencies = [ "bytemuck", - "solana-program 1.18.23", + "solana-program", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5335,7 +5290,9 @@ dependencies = [ "serde_wormhole", "shellexpand", "solana-client", + "solana-remote-wallet", "solana-sdk", + "uriparse", "wormhole-core-bridge-solana", "wormhole-solana", "wormhole-vaas-serde", @@ -6279,7 +6236,7 @@ dependencies = [ "cfg-if", "hex", "ruint", - "solana-program 1.18.23", + "solana-program", "wormhole-io", "wormhole-raw-vaas 0.1.3", ] @@ -6319,7 +6276,7 @@ dependencies = [ "nom", "primitive-types", "sha3 0.10.8", - "solana-program 1.18.23", + "solana-program", "thiserror", "wormhole-core", ] @@ -6331,7 +6288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95ae70b3233a1d2e799276528ad7ec0a55c9929f8eae41683a5d6f0e8ba37649" dependencies = [ "cfg-if", - "solana-program 1.18.23", + "solana-program", ] [[package]] @@ -6342,7 +6299,7 @@ checksum = "a1e8610ed0dcf4582e38910e2fc63fa7176d0919e73718e076d8a7e11b803f57" dependencies = [ "anchor-lang", "borsh 0.10.3", - "solana-program 1.18.23", + "solana-program", "wormhole-raw-vaas 0.3.0-alpha.1", "wormhole-solana-consts", ] diff --git a/staking/cli/Cargo.toml b/staking/cli/Cargo.toml index cab64a7a..47302437 100644 --- a/staking/cli/Cargo.toml +++ b/staking/cli/Cargo.toml @@ -23,3 +23,5 @@ wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "rei base64 = "0.22.1" reqwest = "0.11" serde_json = "1.0.128" +uriparse = "0.6.4" +solana-remote-wallet = "1.18.16" diff --git a/staking/cli/src/cli.rs b/staking/cli/src/cli.rs index 536e6f61..2edd836b 100644 --- a/staking/cli/src/cli.rs +++ b/staking/cli/src/cli.rs @@ -4,13 +4,21 @@ use { Parser, Subcommand, }, + solana_remote_wallet::{ + locator::Locator, + remote_keypair::generate_remote_keypair, + remote_wallet::maybe_wallet_manager, + }, solana_sdk::{ + derivation_path::DerivationPath, pubkey::Pubkey, signature::{ read_keypair_file, Keypair, }, + signer::Signer, }, + std::convert::TryFrom, }; #[derive(Parser, Debug)] @@ -25,9 +33,9 @@ pub struct Cli { long, default_value = "~/.config/solana/id.json", help = "Keypair file the funder of the transaction", - parse(try_from_str = get_keypair_from_file) + parse(try_from_str = get_signer_from_path) )] - pub keypair: Keypair, + pub keypair: Box, #[clap(subcommand)] pub action: Action, } @@ -45,9 +53,9 @@ pub enum Action { #[clap( long, help = "Keypair pool data account", - parse(try_from_str = get_keypair_from_file) + parse(try_from_str = get_signer_from_path) )] - pool_data_keypair: Keypair, + pool_data_keypair: Box, #[clap(long, help = "Y parameter")] y: u64, #[clap(long, help = "Reward program authority parameter")] @@ -102,3 +110,51 @@ pub enum Action { publisher_caps: Pubkey, }, } + +pub enum SignerSource { + Filepath(String), + Usb { + locator: Locator, + derivation_path: Option, + }, +} + +pub fn get_signer_source(source: &str) -> SignerSource { + match uriparse::URIReference::try_from(source) { + Ok(uri) => { + if let Some(scheme) = uri.scheme() { + match scheme.as_str() { + "file" => SignerSource::Filepath(uri.path().to_string()), + "usb" => SignerSource::Usb { + locator: Locator::new_from_uri(&uri).unwrap(), + derivation_path: DerivationPath::from_uri_any_query(&uri).unwrap(), + }, + _ => todo!(), + } + } else { + panic!("Invalid keypair source") + } + } + Err(_) => panic!("Invalid keypair source"), + } +} + +pub fn get_signer_from_path(source: &str) -> Result, String> { + let signer_source = get_signer_source(source); + match signer_source { + SignerSource::Filepath(path) => Ok(get_keypair_from_file(&path).unwrap().into()), + SignerSource::Usb { + locator, + derivation_path, + } => Ok(Box::new( + generate_remote_keypair( + locator, + derivation_path.unwrap_or_default(), + &maybe_wallet_manager().unwrap().unwrap(), + false, + "", + ) + .unwrap(), + )), + } +} diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index b560271d..3d4f05dd 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -77,7 +77,7 @@ use { }, }; -pub fn init_publisher_caps(rpc_client: &RpcClient, payer: &Keypair) -> Pubkey { +pub fn init_publisher_caps(rpc_client: &RpcClient, payer: &dyn Signer) -> Pubkey { let publisher_caps = Keypair::new(); let create_account_ix = create_account( &payer.pubkey(), @@ -117,7 +117,7 @@ pub fn init_publisher_caps(rpc_client: &RpcClient, payer: &Keypair) -> Pubkey { pub fn write_publisher_caps( rpc_client: &RpcClient, - payer: &Keypair, + payer: &dyn Signer, publisher_caps: Pubkey, index: usize, chunk: &[u8], @@ -141,7 +141,7 @@ pub fn write_publisher_caps( process_transaction(rpc_client, &[instruction], &[payer]); } -pub fn close_publisher_caps(rpc_client: &RpcClient, payer: &Keypair, publisher_caps: Pubkey) { +pub fn close_publisher_caps(rpc_client: &RpcClient, payer: &dyn Signer, publisher_caps: Pubkey) { let accounts = publisher_caps::accounts::ClosePublisherCaps { write_authority: payer.pubkey(), publisher_caps, @@ -161,7 +161,7 @@ pub fn close_publisher_caps(rpc_client: &RpcClient, payer: &Keypair, publisher_c pub fn verify_publisher_caps( rpc_client: &RpcClient, - payer: &Keypair, + payer: &dyn Signer, publisher_caps: Pubkey, encoded_vaa: Pubkey, merkle_proofs: Vec, @@ -203,10 +203,10 @@ pub fn deserialize_accumulator_update_data( } } -pub fn process_transaction( +pub fn process_transaction<'a>( rpc_client: &RpcClient, instructions: &[Instruction], - signers: &[&Keypair], + signers: &[&'a dyn Signer], ) { let mut transaction = Transaction::new_with_payer(instructions, Some(&signers[0].pubkey())); transaction.sign(signers, rpc_client.get_latest_blockhash().unwrap()); @@ -233,7 +233,7 @@ pub fn process_write_encoded_vaa( rpc_client: &RpcClient, vaa: &[u8], wormhole: Pubkey, - payer: &Keypair, + payer: &dyn Signer, ) -> Pubkey { let encoded_vaa_keypair = Keypair::new(); let encoded_vaa_size: usize = vaa.len() + VAA_START; @@ -310,7 +310,7 @@ pub fn process_write_encoded_vaa( pub fn write_encoded_vaa( rpc_client: &RpcClient, - payer: &Keypair, + payer: &dyn Signer, encoded_vaa: &Pubkey, wormhole: &Pubkey, index: usize, @@ -341,7 +341,7 @@ pub fn write_encoded_vaa( ); } -pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &Keypair, encoded_vaa: Pubkey) { +pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &dyn Signer, encoded_vaa: Pubkey) { let close_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::CloseEncodedVaa { write_authority: payer.pubkey(), encoded_vaa, @@ -357,7 +357,7 @@ pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &Keypair, encoded_vaa: P process_transaction(rpc_client, &[close_encoded_vaa_instruction], &[payer]); } -pub fn initialize_reward_custody(rpc_client: &RpcClient, payer: &Keypair) { +pub fn initialize_reward_custody(rpc_client: &RpcClient, payer: &dyn Signer) { let pool_config = get_pool_config_address(); let PoolConfig { @@ -380,7 +380,7 @@ pub fn initialize_reward_custody(rpc_client: &RpcClient, payer: &Keypair) { process_transaction(rpc_client, &[create_ata_ix], &[payer]); } -pub fn advance(rpc_client: &RpcClient, payer: &Keypair, publisher_caps: Pubkey) { +pub fn advance(rpc_client: &RpcClient, payer: &dyn Signer, publisher_caps: Pubkey) { let pool_config = get_pool_config_address(); let PoolConfig { @@ -425,8 +425,8 @@ pub fn advance(rpc_client: &RpcClient, payer: &Keypair, publisher_caps: Pubkey) pub fn initialize_pool( rpc_client: &RpcClient, - payer: &Keypair, - pool_data_keypair: &Keypair, + payer: &dyn Signer, + pool_data_keypair: &dyn Signer, reward_program_authority: Pubkey, y: u64, slash_custody: Pubkey, @@ -478,7 +478,7 @@ pub fn initialize_pool( pub fn fetch_publisher_caps_and_advance( rpc_client: &RpcClient, - payer: &Keypair, + payer: &dyn Signer, wormhole: Pubkey, hermes_url: String, ) { @@ -538,7 +538,7 @@ pub fn fetch_publisher_caps_and_advance( close_encoded_vaa(rpc_client, payer, encoded_vaa); } -pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &Keypair, delegation_fee: u64) { +pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &dyn Signer, delegation_fee: u64) { let pool_config = get_pool_config_address(); let PoolConfig { pool_data, .. } = PoolConfig::try_deserialize( @@ -569,7 +569,7 @@ pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &Keypair, delegation pub fn set_publisher_stake_account( rpc_client: &RpcClient, - signer: &Keypair, + signer: &dyn Signer, publisher: &Pubkey, stake_account_positions: &Pubkey, ) { @@ -605,7 +605,7 @@ pub fn set_publisher_stake_account( pub fn create_slash_event( rpc_client: &RpcClient, - signer: &Keypair, + signer: &dyn Signer, publisher: &Pubkey, slash_ratio: u64, ) { @@ -656,7 +656,7 @@ pub fn create_slash_event( pub fn update_reward_program_authority( rpc_client: &RpcClient, - signer: &Keypair, + signer: &dyn Signer, new_reward_program_authority: &Pubkey, ) { let pool_config = get_pool_config_address(); @@ -682,7 +682,7 @@ pub fn update_reward_program_authority( pub fn slash( rpc_client: &RpcClient, - signer: &Keypair, + signer: &dyn Signer, publisher: &Pubkey, stake_account_positions: &Pubkey, ) { @@ -754,7 +754,7 @@ pub fn slash( process_transaction(rpc_client, &[instruction], &[signer]); } -pub fn update_y(rpc_client: &RpcClient, signer: &Keypair, y: u64) { +pub fn update_y(rpc_client: &RpcClient, signer: &dyn Signer, y: u64) { let pool_config = get_pool_config_address(); let accounts = integrity_pool::accounts::UpdateY { diff --git a/staking/cli/src/main.rs b/staking/cli/src/main.rs index 238629ad..da9764b3 100644 --- a/staking/cli/src/main.rs +++ b/staking/cli/src/main.rs @@ -20,7 +20,13 @@ use { update_y, }, solana_client::rpc_client::RpcClient, - solana_sdk::commitment_config::CommitmentConfig, + solana_remote_wallet::locator::Locator, + solana_sdk::{ + commitment_config::CommitmentConfig, + signature::Keypair, + signer::Signer, + }, + std::convert::TryFrom, }; @@ -41,8 +47,8 @@ fn main() { } => { initialize_pool( &rpc_client, - &keypair, - &pool_data_keypair, + keypair.as_ref(), + pool_data_keypair.as_ref(), reward_program_authority, y, slash_custody, @@ -52,34 +58,46 @@ fn main() { hermes_url, wormhole, } => { - fetch_publisher_caps_and_advance(&rpc_client, &keypair, wormhole, hermes_url); + fetch_publisher_caps_and_advance(&rpc_client, keypair.as_ref(), wormhole, hermes_url); } Action::InitializePoolRewardCustody {} => { - initialize_reward_custody(&rpc_client, &keypair); + initialize_reward_custody(&rpc_client, keypair.as_ref()); } Action::UpdateDelegationFee { delegation_fee } => { - update_delegation_fee(&rpc_client, &keypair, delegation_fee) + update_delegation_fee(&rpc_client, keypair.as_ref(), delegation_fee) } Action::SetPublisherStakeAccount { publisher, stake_account_positions, - } => { - set_publisher_stake_account(&rpc_client, &keypair, &publisher, &stake_account_positions) - } + } => set_publisher_stake_account( + &rpc_client, + keypair.as_ref(), + &publisher, + &stake_account_positions, + ), Action::CreateSlashEvent { publisher, slash_ratio, - } => create_slash_event(&rpc_client, &keypair, &publisher, slash_ratio), + } => create_slash_event(&rpc_client, keypair.as_ref(), &publisher, slash_ratio), Action::UpdateRewardProgramAuthority { new_reward_program_authority, - } => update_reward_program_authority(&rpc_client, &keypair, &new_reward_program_authority), + } => update_reward_program_authority( + &rpc_client, + keypair.as_ref(), + &new_reward_program_authority, + ), Action::Slash { publisher, stake_account_positions, - } => slash(&rpc_client, &keypair, &publisher, &stake_account_positions), - Action::UpdateY { y } => update_y(&rpc_client, &keypair, y), + } => slash( + &rpc_client, + keypair.as_ref(), + &publisher, + &stake_account_positions, + ), + Action::UpdateY { y } => update_y(&rpc_client, keypair.as_ref(), y), Action::ClosePublisherCaps { publisher_caps } => { - close_publisher_caps(&rpc_client, &keypair, publisher_caps) + close_publisher_caps(&rpc_client, keypair.as_ref(), publisher_caps) } } } From 15e1a65ab3414c58bdf7ba983e2326428855eab9 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 19:50:23 +0100 Subject: [PATCH 2/8] pool becomes key again --- staking/cli/src/cli.rs | 4 ++-- staking/cli/src/instructions.rs | 2 +- staking/cli/src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/staking/cli/src/cli.rs b/staking/cli/src/cli.rs index 2edd836b..fd2fce87 100644 --- a/staking/cli/src/cli.rs +++ b/staking/cli/src/cli.rs @@ -53,9 +53,9 @@ pub enum Action { #[clap( long, help = "Keypair pool data account", - parse(try_from_str = get_signer_from_path) + parse(try_from_str = get_keypair_from_file) )] - pool_data_keypair: Box, + pool_data_keypair: Keypair, #[clap(long, help = "Y parameter")] y: u64, #[clap(long, help = "Reward program authority parameter")] diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 3d4f05dd..8bbafeab 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -426,7 +426,7 @@ pub fn advance(rpc_client: &RpcClient, payer: &dyn Signer, publisher_caps: Pubke pub fn initialize_pool( rpc_client: &RpcClient, payer: &dyn Signer, - pool_data_keypair: &dyn Signer, + pool_data_keypair: &Keypair, reward_program_authority: Pubkey, y: u64, slash_custody: Pubkey, diff --git a/staking/cli/src/main.rs b/staking/cli/src/main.rs index da9764b3..729c4722 100644 --- a/staking/cli/src/main.rs +++ b/staking/cli/src/main.rs @@ -48,7 +48,7 @@ fn main() { initialize_pool( &rpc_client, keypair.as_ref(), - pool_data_keypair.as_ref(), + &pool_data_keypair, reward_program_authority, y, slash_custody, From cca4a6d53e05bb3f94fbede4b649bc4b7e85e631 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 19:52:27 +0100 Subject: [PATCH 3/8] clippy --- staking/cli/src/instructions.rs | 4 ++-- staking/cli/src/main.rs | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 8bbafeab..3322869d 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -203,10 +203,10 @@ pub fn deserialize_accumulator_update_data( } } -pub fn process_transaction<'a>( +pub fn process_transaction( rpc_client: &RpcClient, instructions: &[Instruction], - signers: &[&'a dyn Signer], + signers: &[&dyn Signer], ) { let mut transaction = Transaction::new_with_payer(instructions, Some(&signers[0].pubkey())); transaction.sign(signers, rpc_client.get_latest_blockhash().unwrap()); diff --git a/staking/cli/src/main.rs b/staking/cli/src/main.rs index 729c4722..5c6a0cc8 100644 --- a/staking/cli/src/main.rs +++ b/staking/cli/src/main.rs @@ -20,13 +20,7 @@ use { update_y, }, solana_client::rpc_client::RpcClient, - solana_remote_wallet::locator::Locator, - solana_sdk::{ - commitment_config::CommitmentConfig, - signature::Keypair, - signer::Signer, - }, - std::convert::TryFrom, + solana_sdk::commitment_config::CommitmentConfig, }; From 73767922ff9de8de42040bd840d216236f58d36a Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 20:20:16 +0100 Subject: [PATCH 4/8] drive-by fix --- staking/cli/src/instructions.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index 3322869d..ad1a1df5 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -341,7 +341,12 @@ pub fn write_encoded_vaa( ); } -pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &dyn Signer, encoded_vaa: Pubkey) { +pub fn close_encoded_vaa( + rpc_client: &RpcClient, + payer: &dyn Signer, + encoded_vaa: Pubkey, + wormhole: &Pubkey, +) { let close_encoded_vaa_accounts = wormhole_core_bridge_solana::accounts::CloseEncodedVaa { write_authority: payer.pubkey(), encoded_vaa, @@ -349,7 +354,7 @@ pub fn close_encoded_vaa(rpc_client: &RpcClient, payer: &dyn Signer, encoded_vaa .to_account_metas(None); let close_encoded_vaa_instruction = Instruction { - program_id: wormhole_core_bridge_solana::ID, + program_id: *wormhole, accounts: close_encoded_vaa_accounts, data: wormhole_core_bridge_solana::instruction::CloseEncodedVaa {}.data(), }; @@ -533,9 +538,8 @@ pub fn fetch_publisher_caps_and_advance( publisher_caps ); - advance(rpc_client, payer, publisher_caps); close_publisher_caps(rpc_client, payer, publisher_caps); - close_encoded_vaa(rpc_client, payer, encoded_vaa); + close_encoded_vaa(rpc_client, payer, encoded_vaa, &wormhole); } pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &dyn Signer, delegation_fee: u64) { From 1e3276d0368631bb21ff9719b9fbbfbcee8498e7 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 20:20:49 +0100 Subject: [PATCH 5/8] better errors --- staking/cli/src/cli.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/staking/cli/src/cli.rs b/staking/cli/src/cli.rs index fd2fce87..f2bb33ed 100644 --- a/staking/cli/src/cli.rs +++ b/staking/cli/src/cli.rs @@ -119,30 +119,32 @@ pub enum SignerSource { }, } -pub fn get_signer_source(source: &str) -> SignerSource { +pub fn get_signer_source_from_path(source: &str) -> Result { match uriparse::URIReference::try_from(source) { Ok(uri) => { if let Some(scheme) = uri.scheme() { match scheme.as_str() { - "file" => SignerSource::Filepath(uri.path().to_string()), - "usb" => SignerSource::Usb { + "usb" => Ok(SignerSource::Usb { locator: Locator::new_from_uri(&uri).unwrap(), derivation_path: DerivationPath::from_uri_any_query(&uri).unwrap(), - }, - _ => todo!(), + }), + _ => Err(format!("Unsupported scheme: {}", scheme)), } } else { - panic!("Invalid keypair source") + Ok(std::fs::metadata(shellexpand::tilde(source).to_string()) + .map(|_| SignerSource::Filepath(source.to_string())) + .map_err(|_| format!("Invalid keypair path: {}", source)) + .unwrap()) } } - Err(_) => panic!("Invalid keypair source"), + Err(e) => Err(format!("Invalid keypair source: {}", e)), } } pub fn get_signer_from_path(source: &str) -> Result, String> { - let signer_source = get_signer_source(source); + let signer_source = get_signer_source_from_path(source)?; match signer_source { - SignerSource::Filepath(path) => Ok(get_keypair_from_file(&path).unwrap().into()), + SignerSource::Filepath(path) => Ok(get_keypair_from_file(&path)?.into()), SignerSource::Usb { locator, derivation_path, From df31ae91f411ef1336656b29a9925007c6b65a9a Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 20:28:10 +0100 Subject: [PATCH 6/8] restore advance --- staking/cli/src/instructions.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/staking/cli/src/instructions.rs b/staking/cli/src/instructions.rs index ad1a1df5..7fede889 100644 --- a/staking/cli/src/instructions.rs +++ b/staking/cli/src/instructions.rs @@ -538,6 +538,7 @@ pub fn fetch_publisher_caps_and_advance( publisher_caps ); + advance(rpc_client, payer, publisher_caps); close_publisher_caps(rpc_client, payer, publisher_caps); close_encoded_vaa(rpc_client, payer, encoded_vaa, &wormhole); } From 28d188b25287085c070a82ec0f7c02eeffef0271 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 20:36:09 +0100 Subject: [PATCH 7/8] install libudev --- .github/workflows/anchor.yml | 2 ++ .github/workflows/clippy.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/anchor.yml b/.github/workflows/anchor.yml index 99fd1e74..6d679dd2 100644 --- a/.github/workflows/anchor.yml +++ b/.github/workflows/anchor.yml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install libudev-dev + run: sudo apt-get update && sudo apt-get install libudev-dev - name: Setup Node.js uses: actions/setup-node@v2 with: diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 2d31d2d1..188c871a 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install libudev-dev + run: sudo apt-get update && sudo apt-get install libudev-dev - uses: actions-rs/toolchain@v1 with: profile: minimal From 36b881677edb9d3257f708245910c8b062595367 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 17 Sep 2024 20:43:45 +0100 Subject: [PATCH 8/8] add comment --- staking/cli/src/cli.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/staking/cli/src/cli.rs b/staking/cli/src/cli.rs index f2bb33ed..10fdb75a 100644 --- a/staking/cli/src/cli.rs +++ b/staking/cli/src/cli.rs @@ -141,6 +141,8 @@ pub fn get_signer_source_from_path(source: &str) -> Result } } +/// This is mostly borrowed from https://github.com/solana-labs/solana/blob/master/clap-utils/src/keypair.rs#L753 +/// To use ledger use `usb://ledger` or `usb://ledger?key=0/0`. pub fn get_signer_from_path(source: &str) -> Result, String> { let signer_source = get_signer_source_from_path(source)?; match signer_source {