Add payload generators (#312)
* Add payload generators * Executor cli no longer a lib
This commit is contained in:
parent
5214d185e8
commit
3176d6a07f
|
@ -2811,6 +2811,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
"clap 3.2.22",
|
"clap 3.2.22",
|
||||||
|
"hex",
|
||||||
"remote-executor",
|
"remote-executor",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
"solana-client",
|
"solana-client",
|
||||||
|
|
|
@ -3,9 +3,6 @@ name = "remote-executor-cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "remote_executor_cli"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = {version ="3.2.22", features = ["derive"]}
|
clap = {version ="3.2.22", features = ["derive"]}
|
||||||
remote-executor = {path = "../programs/remote-executor/"}
|
remote-executor = {path = "../programs/remote-executor/"}
|
||||||
|
@ -18,3 +15,4 @@ anyhow = "1.0.65"
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
|
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
|
||||||
wormhole-core = { 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"
|
||||||
|
|
|
@ -3,7 +3,10 @@ use clap::{
|
||||||
Parser,
|
Parser,
|
||||||
Subcommand,
|
Subcommand,
|
||||||
};
|
};
|
||||||
use solana_sdk::commitment_config::CommitmentConfig;
|
use solana_sdk::{
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
|
pubkey::Pubkey,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(
|
#[clap(
|
||||||
|
@ -39,4 +42,31 @@ pub enum Action {
|
||||||
)]
|
)]
|
||||||
keypair: String,
|
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,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
mod cli;
|
|
|
@ -3,13 +3,16 @@ pub mod cli;
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use anchor_client::anchor_lang::{
|
use anchor_client::{
|
||||||
|
anchor_lang::{
|
||||||
AccountDeserialize,
|
AccountDeserialize,
|
||||||
AnchorDeserialize,
|
AnchorDeserialize,
|
||||||
AnchorSerialize,
|
AnchorSerialize,
|
||||||
InstructionData,
|
InstructionData as AnchorInstructionData,
|
||||||
Owner,
|
Owner,
|
||||||
ToAccountMetas,
|
ToAccountMetas,
|
||||||
|
},
|
||||||
|
solana_sdk::bpf_loader_upgradeable,
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cli::{
|
use cli::{
|
||||||
|
@ -20,6 +23,7 @@ use cli::{
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use remote_executor::{
|
use remote_executor::{
|
||||||
accounts::ExecutePostedVaa,
|
accounts::ExecutePostedVaa,
|
||||||
|
state::governance_payload::InstructionData,
|
||||||
EXECUTOR_KEY_SEED,
|
EXECUTOR_KEY_SEED,
|
||||||
ID,
|
ID,
|
||||||
};
|
};
|
||||||
|
@ -207,6 +211,64 @@ fn main() -> Result<()> {
|
||||||
&vec![&payer, &message_keypair],
|
&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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue