Skip to content

Commit e5f158b

Browse files
committed
feat: add xtask to create serialized protocol config update instruction
1 parent 368f9f0 commit e5f158b

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

xtask/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ light-hasher = { workspace = true }
1616
light-indexed-merkle-tree = { workspace = true }
1717
light-compressed-account = { workspace = true }
1818
light-merkle-tree-metadata = { workspace = true }
19-
light-registry = { workspace = true }
2019
num-bigint = { workspace = true }
2120
rand = { workspace = true }
2221
quote = "1.0"
@@ -33,3 +32,4 @@ serde_json = "1.0.139"
3332
solana-client = { workspace = true }
3433
solana-transaction-status = { workspace = true }
3534
light-batched-merkle-tree = { workspace = true }
35+
light-registry = { workspace = true }
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use account_compression::processor::initialize_address_merkle_tree::AnchorDeserialize;
2+
use clap::Parser;
3+
use light_client::rpc::{RpcConnection, SolanaRpcConnection};
4+
use light_registry::{
5+
protocol_config::state::ProtocolConfigPda, sdk::create_update_protocol_config_instruction,
6+
utils::get_protocol_config_pda_address,
7+
};
8+
use solana_sdk::{bs58, message::Message, pubkey};
9+
10+
/// Updateable Parameters:
11+
/// 1. slot_length
12+
/// 2. cpi_context_size
13+
/// 3. min_weight
14+
#[derive(Debug, Parser)]
15+
pub struct Options {
16+
#[clap(long)]
17+
slot_length: Option<u64>,
18+
#[clap(long)]
19+
cpi_context_size: Option<u64>,
20+
#[clap(long)]
21+
min_weight: Option<u64>,
22+
}
23+
24+
/// Steps:
25+
/// 1. fetch protocol config account
26+
/// 1.1. print protocol config account
27+
/// 2. create updated protocol config based on inputs
28+
/// 2.1. print updated protocol config
29+
/// 3. create instruction
30+
/// - signer is the multisig
31+
/// 4. serialize instruction to bs58
32+
/// 5. print bs58
33+
pub async fn create_update_protocol_config_ix(options: Options) -> anyhow::Result<()> {
34+
let rpc_url = String::from("https://api.mainnet-beta.solana.com");
35+
let mut rpc = SolanaRpcConnection::new(rpc_url, None);
36+
let (protocol_config_pda, _) = get_protocol_config_pda_address();
37+
let account = rpc
38+
.get_account(protocol_config_pda)
39+
.await?
40+
.expect("Protocol Config Account not found");
41+
let mut deserialized_account = ProtocolConfigPda::deserialize(&mut &account.data[8..]).unwrap();
42+
println!("current protocol config: {:?}", deserialized_account);
43+
if let Some(slot_length) = options.slot_length {
44+
deserialized_account.config.slot_length = slot_length;
45+
}
46+
if let Some(cpi_context_size) = options.cpi_context_size {
47+
deserialized_account.config.cpi_context_size = cpi_context_size;
48+
}
49+
if let Some(min_weight) = options.min_weight {
50+
deserialized_account.config.min_weight = min_weight;
51+
}
52+
println!("updated protocol config: {:?}", deserialized_account.config);
53+
let authority = pubkey!("7PeqkcCXeqgsp5Mi15gjJh8qvSLk7n3dgNuyfPhJJgqY");
54+
let instruction = create_update_protocol_config_instruction(
55+
authority,
56+
None,
57+
Some(deserialized_account.config),
58+
);
59+
println!("instruction: {:?}", instruction);
60+
println!(
61+
"Serialized instruction data: {}",
62+
bs58::encode(instruction.data.clone()).into_string()
63+
);
64+
let message = Message::new(&[instruction], Some(&authority));
65+
let serialized_message = bs58::encode(message.serialize()).into_string();
66+
println!(
67+
"\n ----------- Use the serialized message in the squads tx builder. --------------- \n"
68+
);
69+
println!("serialized message: {}", serialized_message);
70+
71+
Ok(())
72+
}

xtask/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::{Parser, ValueEnum};
33
mod bench;
44
mod create_batch_state_tree;
55
mod create_state_tree;
6+
mod create_update_protocol_config_ix;
67
mod create_vkeyrs_from_gnark_key;
78
mod export_photon_test_data;
89
mod fee;
@@ -52,6 +53,8 @@ enum Command {
5253
/// cargo xtask init-new-deployment --keypairs ../light-keypairs --network local --num-foresters 3
5354
/// Requires program ids to be changed manually in programs.
5455
InitNewDeployment(new_deployment::Options),
56+
/// cargo xtask create-update-protocol-config --slot-length <u64>
57+
CreateUpdateProtocolConfigIx(create_update_protocol_config_ix::Options),
5558
}
5659

5760
#[tokio::main]
@@ -78,5 +81,8 @@ async fn main() -> Result<(), anyhow::Error> {
7881
create_batch_state_tree::create_batch_state_tree(opts).await
7982
}
8083
Command::InitNewDeployment(opts) => new_deployment::init_new_deployment(opts).await,
84+
Command::CreateUpdateProtocolConfigIx(opts) => {
85+
create_update_protocol_config_ix::create_update_protocol_config_ix(opts).await
86+
}
8187
}
8288
}

0 commit comments

Comments
 (0)