Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ solana-client = { workspace = true }
solana-transaction-status = { workspace = true }
light-batched-merkle-tree = { workspace = true }
light-registry = { workspace = true }
solana-loader-v3-interface = { workspace = true, features = ["bincode"] }
light-compressible = { workspace = true }
anchor-lang = { workspace = true }
light-token = { workspace = true }
Expand Down
50 changes: 50 additions & 0 deletions xtask/src/close_buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::str::FromStr;

use clap::Parser;
use solana_loader_v3_interface::instruction as bpf_loader_instruction;
use solana_sdk::{bs58, message::Message, pubkey::Pubkey};

#[derive(Debug, Parser)]
pub struct Options {
/// The buffer account pubkey to close
#[clap(long)]
buffer: String,
/// The multisig authority pubkey
#[clap(long, default_value = "7PeqkcCXeqgsp5Mi15gjJh8qvSLk7n3dgNuyfPhJJgqY")]
authority: String,
/// The recipient pubkey for reclaimed lamports
#[clap(long)]
recipient: String,
}

/// Creates a serialized BPF Loader Close instruction for use with Squads TX builder.
///
/// Steps:
/// 1. Build the close instruction for the BPF Upgradeable Loader
/// 2. Serialize the message to bs58
/// 3. Print bs58 for use in Squads
pub fn close_buffer(options: Options) -> anyhow::Result<()> {
let buffer = Pubkey::from_str(&options.buffer)
.map_err(|e| anyhow::anyhow!("Invalid buffer pubkey: {e}"))?;
let authority = Pubkey::from_str(&options.authority)
.map_err(|e| anyhow::anyhow!("Invalid authority pubkey: {e}"))?;
let recipient = Pubkey::from_str(&options.recipient)
.map_err(|e| anyhow::anyhow!("Invalid recipient pubkey: {e}"))?;

let instruction =
bpf_loader_instruction::close_any(&buffer, &recipient, Some(&authority), None);

println!("instruction: {:?}", instruction);
println!(
"Serialized instruction data: {}",
bs58::encode(instruction.data.clone()).into_string()
);
let message = Message::new(&[instruction], Some(&authority));
let serialized_message = bs58::encode(message.serialize()).into_string();
println!(
"\n ----------- Use the serialized message in the squads tx builder. --------------- \n"
);
println!("serialized message: {}", serialized_message);

Ok(())
}
6 changes: 6 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{Parser, ValueEnum};

mod bench;
mod close_buffer;
mod create_batch_address_tree;
mod create_batch_state_tree;
mod create_compressible_config;
Expand Down Expand Up @@ -89,6 +90,10 @@ enum Command {
/// Example: cargo xtask create-ctoken-account --network devnet
/// Example with existing mint: cargo xtask create-ctoken-account --mint <MINT_PUBKEY> --network devnet
CreateCtokenAccount(create_ctoken_account::Options),
/// Close a BPF Upgradeable Loader buffer account via Squads multisig.
/// Serializes the Close instruction as a bs58 message for the Squads TX builder.
/// Example: cargo xtask close-buffer --buffer FMkzXMexKDUKGxAm7oGsjs4LGEMhzk9C6uuYJBwJbjiN
CloseBuffer(close_buffer::Options),
}

#[tokio::main]
Expand Down Expand Up @@ -131,5 +136,6 @@ async fn main() -> Result<(), anyhow::Error> {
Command::CreateCtokenAccount(opts) => {
create_ctoken_account::create_ctoken_account(opts).await
}
Command::CloseBuffer(opts) => close_buffer::close_buffer(opts),
}
}