Skip to content

Commit 3176d6a

Browse files
authored
Add payload generators (#312)
* Add payload generators * Executor cli no longer a lib
1 parent 5214d18 commit 3176d6a

File tree

5 files changed

+102
-12
lines changed

5 files changed

+102
-12
lines changed

pythnet/remote-executor/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pythnet/remote-executor/cli/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name = "remote-executor-cli"
33
version = "0.1.0"
44
edition = "2018"
55

6-
[lib]
7-
name = "remote_executor_cli"
8-
96
[dependencies]
107
clap = {version ="3.2.22", features = ["derive"]}
118
remote-executor = {path = "../programs/remote-executor/"}
@@ -18,3 +15,4 @@ anyhow = "1.0.65"
1815
base64 = "0.13.0"
1916
wormhole-solana = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
2017
wormhole-core = { git = "https://github.com/guibescos/wormhole", branch = "reisen/sdk-solana"}
18+
hex = "0.4.3"

pythnet/remote-executor/cli/src/cli.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use clap::{
33
Parser,
44
Subcommand,
55
};
6-
use solana_sdk::commitment_config::CommitmentConfig;
6+
use solana_sdk::{
7+
commitment_config::CommitmentConfig,
8+
pubkey::Pubkey,
9+
};
710

811
#[derive(Parser, Debug)]
912
#[clap(
@@ -39,4 +42,31 @@ pub enum Action {
3942
)]
4043
keypair: String,
4144
},
45+
#[clap(about = "Get test wormhole payload for squads-cli")]
46+
GetTestPayload {},
47+
#[clap(about = "Get set upgrade authority payload for squads-cli")]
48+
GetSetUpgradeAuthorityPayload {
49+
#[clap(short, long, help = "Current authority")]
50+
current: Pubkey,
51+
#[clap(short, long, help = "New authority")]
52+
new: Pubkey,
53+
#[clap(short, long, help = "Program id")]
54+
program_id: Pubkey,
55+
},
56+
#[clap(about = "Get upgrade program payload for squads-cli")]
57+
GetUpgradeProgramPayload {
58+
#[clap(short, long, help = "Current authority")]
59+
authority: Pubkey,
60+
#[clap(short, long, help = "Program id")]
61+
program_id: Pubkey,
62+
#[clap(short, long, help = "New buffer")]
63+
new_buffer: Pubkey,
64+
#[clap(short, long, help = "Spill address")]
65+
spill: Pubkey,
66+
},
67+
#[clap(about = "Map solana key to pythnet key")]
68+
MapKey {
69+
#[clap(short, long, help = "Pubkey to map")]
70+
pubkey: Pubkey,
71+
},
4272
}

pythnet/remote-executor/cli/src/lib.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

pythnet/remote-executor/cli/src/main.rs

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ pub mod cli;
33

44
use std::str::FromStr;
55

6-
use anchor_client::anchor_lang::{
7-
AccountDeserialize,
8-
AnchorDeserialize,
9-
AnchorSerialize,
10-
InstructionData,
11-
Owner,
12-
ToAccountMetas,
6+
use anchor_client::{
7+
anchor_lang::{
8+
AccountDeserialize,
9+
AnchorDeserialize,
10+
AnchorSerialize,
11+
InstructionData as AnchorInstructionData,
12+
Owner,
13+
ToAccountMetas,
14+
},
15+
solana_sdk::bpf_loader_upgradeable,
1316
};
1417
use clap::Parser;
1518
use cli::{
@@ -20,6 +23,7 @@ use cli::{
2023
use anyhow::Result;
2124
use remote_executor::{
2225
accounts::ExecutePostedVaa,
26+
state::governance_payload::InstructionData,
2327
EXECUTOR_KEY_SEED,
2428
ID,
2529
};
@@ -207,6 +211,64 @@ fn main() -> Result<()> {
207211
&vec![&payer, &message_keypair],
208212
)
209213
}
214+
Action::GetTestPayload {} => {
215+
let payload = ExecutorPayload {
216+
header: GovernanceHeader::executor_governance_header(),
217+
instructions: vec![],
218+
}
219+
.try_to_vec()?;
220+
println!("Test payload : {:?}", hex::encode(payload));
221+
Ok(())
222+
}
223+
Action::MapKey { pubkey } => {
224+
let executor_key = Pubkey::find_program_address(
225+
&[EXECUTOR_KEY_SEED.as_bytes(), &pubkey.to_bytes()],
226+
&ID,
227+
)
228+
.0;
229+
println!("{:?} maps to {:?}", pubkey, executor_key);
230+
Ok(())
231+
}
232+
233+
Action::GetSetUpgradeAuthorityPayload {
234+
current,
235+
new,
236+
program_id,
237+
} => {
238+
let mut instruction =
239+
bpf_loader_upgradeable::set_upgrade_authority(&program_id, &current, Some(&new));
240+
instruction.accounts[2].is_signer = true; // Require signature of new authority for safety
241+
println!("New authority : {:}", instruction.accounts[2].pubkey);
242+
let payload = ExecutorPayload {
243+
header: GovernanceHeader::executor_governance_header(),
244+
instructions: vec![InstructionData::from(&instruction)],
245+
}
246+
.try_to_vec()?;
247+
println!("Set upgrade authority payload : {:?}", hex::encode(payload));
248+
Ok(())
249+
}
250+
251+
Action::GetUpgradeProgramPayload {
252+
program_id,
253+
authority,
254+
new_buffer,
255+
spill,
256+
} => {
257+
let instruction =
258+
bpf_loader_upgradeable::upgrade(&program_id, &new_buffer, &authority, &spill);
259+
println!("New buffer : {:}", instruction.accounts[2].pubkey);
260+
println!(
261+
"Extra PGAS will be sent to : {:}",
262+
instruction.accounts[3].pubkey
263+
);
264+
let payload = ExecutorPayload {
265+
header: GovernanceHeader::executor_governance_header(),
266+
instructions: vec![InstructionData::from(&instruction)],
267+
}
268+
.try_to_vec()?;
269+
println!("Upgrade program payload : {:?}", hex::encode(payload));
270+
Ok(())
271+
}
210272
}
211273
}
212274

0 commit comments

Comments
 (0)