|
| 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 | +} |
0 commit comments