Skip to content

Commit

Permalink
feat(cli): add close publisher caps (#546)
Browse files Browse the repository at this point in the history
* feat(cli): add close publisher caps and claim rewards instruction

* wip

* remove claim

* remove unused vva data
  • Loading branch information
keyvankhademi authored Dec 31, 2024
1 parent 929ffb5 commit 8580645
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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()),
))]),
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());
}
}
}

0 comments on commit 8580645

Please sign in to comment.