Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add close publisher caps #546

Merged
merged 4 commits into from
Dec 31, 2024
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
3 changes: 2 additions & 1 deletion staking/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum Action {
)]
hermes_url: String,

#[clap(long, default_value = "3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5")]
#[clap(long, default_value = "HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ")]
wormhole: Pubkey,
},
InitializePoolRewardCustody {},
Expand Down Expand Up @@ -110,6 +110,7 @@ pub enum Action {
publisher_caps: Pubkey,
},
SaveStakeAccountsSnapshot {},
CloseAllPublisherCaps {},
}

pub enum SignerSource {
Expand Down
27 changes: 25 additions & 2 deletions staking/cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn process_transaction(
rpc_client: &RpcClient,
instructions: &[Instruction],
signers: &[&dyn Signer],
) -> Result<Signature, TransactionError> {
) -> Result<Signature, Option<TransactionError>> {
let mut transaction = Transaction::new_with_payer(instructions, Some(&signers[0].pubkey()));
transaction.sign(
signers,
Expand All @@ -275,7 +275,7 @@ pub fn process_transaction(
}
Err(err) => {
println!("transaction err: {err:?}");
Err(err.get_transaction_error().unwrap())
Err(err.get_transaction_error())
}
}
}
Expand Down Expand Up @@ -870,6 +870,29 @@ pub fn update_y(rpc_client: &RpcClient, signer: &dyn Signer, y: u64) {
process_transaction(rpc_client, &[instruction], &[signer]).unwrap();
}

pub fn close_all_publisher_caps(rpc_client: &RpcClient, signer: &dyn Signer) {
rpc_client
.get_program_accounts_with_config(
&publisher_caps::ID,
RpcProgramAccountsConfig {
filters: Some(vec![RpcFilterType::Memcmp(Memcmp::new(
0,
MemcmpEncodedBytes::Bytes(PublisherCaps::DISCRIMINATOR.to_vec()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should filter on data here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/A anymore

))]),
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64Zstd),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: None,
},
)
.unwrap()
.into_iter()
.for_each(|(pubkey, _account)| close_publisher_caps(rpc_client, signer, pubkey));
}

pub fn save_stake_accounts_snapshot(rpc_client: &RpcClient) {
let data: Vec<(Pubkey, DynamicPositionArrayAccount, Pubkey, Pubkey, Pubkey)> = rpc_client
.get_program_accounts_with_config(
Expand Down
4 changes: 4 additions & 0 deletions staking/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
Cli,
},
instructions::{
close_all_publisher_caps,
close_publisher_caps,
create_slash_event,
fetch_publisher_caps_and_advance,
Expand Down Expand Up @@ -97,5 +98,8 @@ fn main() {
Action::SaveStakeAccountsSnapshot {} => {
save_stake_accounts_snapshot(&rpc_client);
}
Action::CloseAllPublisherCaps {} => {
close_all_publisher_caps(&rpc_client, keypair.as_ref());
}
}
}
Loading