diff --git a/pythnet/remote-executor/Cargo.lock b/pythnet/remote-executor/Cargo.lock index a02aacff..8c1b6f5a 100644 --- a/pythnet/remote-executor/Cargo.lock +++ b/pythnet/remote-executor/Cargo.lock @@ -2811,6 +2811,7 @@ dependencies = [ "anyhow", "base64 0.13.0", "clap 3.2.22", + "hex", "remote-executor", "shellexpand", "solana-client", diff --git a/pythnet/remote-executor/cli/Cargo.toml b/pythnet/remote-executor/cli/Cargo.toml index 164a334e..b4fdae7c 100644 --- a/pythnet/remote-executor/cli/Cargo.toml +++ b/pythnet/remote-executor/cli/Cargo.toml @@ -3,9 +3,6 @@ name = "remote-executor-cli" version = "0.1.0" edition = "2018" -[lib] -name = "remote_executor_cli" - [dependencies] clap = {version ="3.2.22", features = ["derive"]} remote-executor = {path = "../programs/remote-executor/"} @@ -18,3 +15,4 @@ anyhow = "1.0.65" base64 = "0.13.0" wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"} wormhole-core = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"} +hex = "0.4.3" diff --git a/pythnet/remote-executor/cli/src/cli.rs b/pythnet/remote-executor/cli/src/cli.rs index 8e6f60e1..2d2f7871 100644 --- a/pythnet/remote-executor/cli/src/cli.rs +++ b/pythnet/remote-executor/cli/src/cli.rs @@ -3,7 +3,10 @@ use clap::{ Parser, Subcommand, }; -use solana_sdk::commitment_config::CommitmentConfig; +use solana_sdk::{ + commitment_config::CommitmentConfig, + pubkey::Pubkey, +}; #[derive(Parser, Debug)] #[clap( @@ -39,4 +42,31 @@ pub enum Action { )] keypair: String, }, + #[clap(about = "Get test wormhole payload for squads-cli")] + GetTestPayload {}, + #[clap(about = "Get set upgrade authority payload for squads-cli")] + GetSetUpgradeAuthorityPayload { + #[clap(short, long, help = "Current authority")] + current: Pubkey, + #[clap(short, long, help = "New authority")] + new: Pubkey, + #[clap(short, long, help = "Program id")] + program_id: Pubkey, + }, + #[clap(about = "Get upgrade program payload for squads-cli")] + GetUpgradeProgramPayload { + #[clap(short, long, help = "Current authority")] + authority: Pubkey, + #[clap(short, long, help = "Program id")] + program_id: Pubkey, + #[clap(short, long, help = "New buffer")] + new_buffer: Pubkey, + #[clap(short, long, help = "Spill address")] + spill: Pubkey, + }, + #[clap(about = "Map solana key to pythnet key")] + MapKey { + #[clap(short, long, help = "Pubkey to map")] + pubkey: Pubkey, + }, } diff --git a/pythnet/remote-executor/cli/src/lib.rs b/pythnet/remote-executor/cli/src/lib.rs deleted file mode 100644 index 26710c10..00000000 --- a/pythnet/remote-executor/cli/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -mod cli; diff --git a/pythnet/remote-executor/cli/src/main.rs b/pythnet/remote-executor/cli/src/main.rs index acc0fef0..f113b57d 100644 --- a/pythnet/remote-executor/cli/src/main.rs +++ b/pythnet/remote-executor/cli/src/main.rs @@ -3,13 +3,16 @@ pub mod cli; use std::str::FromStr; -use anchor_client::anchor_lang::{ - AccountDeserialize, - AnchorDeserialize, - AnchorSerialize, - InstructionData, - Owner, - ToAccountMetas, +use anchor_client::{ + anchor_lang::{ + AccountDeserialize, + AnchorDeserialize, + AnchorSerialize, + InstructionData as AnchorInstructionData, + Owner, + ToAccountMetas, + }, + solana_sdk::bpf_loader_upgradeable, }; use clap::Parser; use cli::{ @@ -20,6 +23,7 @@ use cli::{ use anyhow::Result; use remote_executor::{ accounts::ExecutePostedVaa, + state::governance_payload::InstructionData, EXECUTOR_KEY_SEED, ID, }; @@ -207,6 +211,64 @@ fn main() -> Result<()> { &vec![&payer, &message_keypair], ) } + Action::GetTestPayload {} => { + let payload = ExecutorPayload { + header: GovernanceHeader::executor_governance_header(), + instructions: vec![], + } + .try_to_vec()?; + println!("Test payload : {:?}", hex::encode(payload)); + Ok(()) + } + Action::MapKey { pubkey } => { + let executor_key = Pubkey::find_program_address( + &[EXECUTOR_KEY_SEED.as_bytes(), &pubkey.to_bytes()], + &ID, + ) + .0; + println!("{:?} maps to {:?}", pubkey, executor_key); + Ok(()) + } + + Action::GetSetUpgradeAuthorityPayload { + current, + new, + program_id, + } => { + let mut instruction = + bpf_loader_upgradeable::set_upgrade_authority(&program_id, ¤t, Some(&new)); + instruction.accounts[2].is_signer = true; // Require signature of new authority for safety + println!("New authority : {:}", instruction.accounts[2].pubkey); + let payload = ExecutorPayload { + header: GovernanceHeader::executor_governance_header(), + instructions: vec![InstructionData::from(&instruction)], + } + .try_to_vec()?; + println!("Set upgrade authority payload : {:?}", hex::encode(payload)); + Ok(()) + } + + Action::GetUpgradeProgramPayload { + program_id, + authority, + new_buffer, + spill, + } => { + let instruction = + bpf_loader_upgradeable::upgrade(&program_id, &new_buffer, &authority, &spill); + println!("New buffer : {:}", instruction.accounts[2].pubkey); + println!( + "Extra PGAS will be sent to : {:}", + instruction.accounts[3].pubkey + ); + let payload = ExecutorPayload { + header: GovernanceHeader::executor_governance_header(), + instructions: vec![InstructionData::from(&instruction)], + } + .try_to_vec()?; + println!("Upgrade program payload : {:?}", hex::encode(payload)); + Ok(()) + } } }