Skip to content

Commit

Permalink
remove claim
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvankhademi committed Dec 31, 2024
1 parent 7b11b22 commit 2c42865
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 199 deletions.
6 changes: 0 additions & 6 deletions staking/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ pub enum Action {
publisher_caps: Pubkey,
},
SaveStakeAccountsSnapshot {},
ClaimRewards {
#[clap(long, help = "Minimum staked tokens")]
min_staked: u64,
#[clap(long, help = "Minimum reward tokens per publisher")]
min_reward: u64,
},
CloseAllPublisherCaps {},
}

Expand Down
186 changes: 0 additions & 186 deletions staking/cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ use {
global_config::GlobalConfig,
max_voter_weight_record::MAX_VOTER_WEIGHT,
positions::{
DynamicPositionArray,
DynamicPositionArrayAccount,
PositionData,
PositionState,
Target,
},
stake_account::StakeAccountMetadataV2,
},
Expand Down Expand Up @@ -902,190 +900,6 @@ pub fn close_all_publisher_caps(rpc_client: &RpcClient, signer: &dyn Signer) {
.for_each(|(pubkey, _account)| close_publisher_caps(rpc_client, signer, pubkey));
}

pub struct FetchError {}

pub fn fetch_delegation_record(
rpc_client: &RpcClient,
key: &Pubkey,
) -> Result<DelegationRecord, FetchError> {
let delegation_record = DelegationRecord::try_deserialize(
&mut (rpc_client
.get_account_data(key)
.map_err(|_| FetchError {})?
.as_slice()),
)
.map_err(|_| FetchError {})?;

Ok(delegation_record)
}

pub fn advance_delegation_record(
rpc_client: &RpcClient,
signer: &dyn Signer,
positions: &DynamicPositionArray,
min_reward: u64,
current_epoch: u64,
) {
let positions_pubkey = positions.acc_info.key;
let pool_config = get_pool_config_address();

let PoolConfig {
pool_data: pool_data_address,
pyth_token_mint,
..
} = PoolConfig::try_deserialize(
&mut rpc_client
.get_account_data(&pool_config)
.unwrap()
.as_slice(),
)
.unwrap();

let pool_data = PoolData::try_deserialize(
&mut rpc_client.get_account_data(&pool_data_address).unwrap()[..8 + size_of::<PoolData>()]
.as_ref(),
)
.unwrap();

pool_data
.publishers
.iter()
.enumerate()
.for_each(|(publisher_index, publisher)| {
if *publisher == Pubkey::default() {
return;
}
let publisher_stake_account_positions =
if pool_data.publisher_stake_accounts[publisher_index] == Pubkey::default() {
None
} else {
Some(pool_data.publisher_stake_accounts[publisher_index])
};

let publisher_stake_account_custody =
publisher_stake_account_positions.map(get_stake_account_custody_address);

let delegation_record_pubkey =
get_delegation_record_address(*publisher, *positions_pubkey);

let delegation_record = fetch_delegation_record(rpc_client, &delegation_record_pubkey);

match delegation_record {
Ok(delegation_record) => {
if delegation_record.last_epoch == current_epoch {
return;
}
}
Err(_) => {
return;
}
}

let accounts = integrity_pool::accounts::AdvanceDelegationRecord {
delegation_record: get_delegation_record_address(*publisher, *positions_pubkey),
payer: signer.pubkey(),
pool_config,
pool_data: pool_data_address,
pool_reward_custody: get_pool_reward_custody_address(pyth_token_mint),
publisher: *publisher,
publisher_stake_account_positions,
publisher_stake_account_custody,
stake_account_positions: *positions_pubkey,
stake_account_custody: get_stake_account_custody_address(*positions_pubkey),
system_program: system_program::ID,
token_program: spl_token::ID,
};

let data = integrity_pool::instruction::AdvanceDelegationRecord {};

let ix = Instruction {
program_id: integrity_pool::ID,
accounts: accounts.to_account_metas(None),
data: data.data(),
};


println!(
"Advance delegation record for pubkey: {:?} publisher: {:?}",
positions_pubkey.to_string(),
publisher,
);
for _ in 0..10 {
if process_transaction(rpc_client, &[ix.clone()], &[signer]).is_ok() {
break;
}
}
});
}

pub fn claim_rewards(
rpc_client: &RpcClient,
signer: &dyn Signer,
min_staked: u64,
min_reward: u64,
) {
let mut data: Vec<DynamicPositionArrayAccount> = rpc_client
.get_program_accounts_with_config(
&staking::ID,
RpcProgramAccountsConfig {
filters: Some(vec![RpcFilterType::Memcmp(Memcmp::new(
0,
MemcmpEncodedBytes::Bytes(PositionData::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()
.map(|(pubkey, account)| DynamicPositionArrayAccount {
key: pubkey,
lamports: account.lamports,
data: account.data.clone(),
})
.collect::<Vec<_>>();

let current_epoch = get_current_epoch(rpc_client);

let mut data: Vec<(u64, DynamicPositionArray)> = data
.iter_mut()
.filter_map(|positions| {
let acc = positions.to_dynamic_position_array();
let exposure = acc
.get_target_exposure(&Target::IntegrityPool, current_epoch)
.unwrap();
if exposure >= min_staked {
Some((exposure, acc))
} else {
None
}
})
.collect();

data.sort_by_key(|(exposure, _)| *exposure);
data.reverse();


data.iter()
.enumerate()
// .skip(120)
.for_each(|(i, (exposure, positions))| {
println!(
"Claiming rewards for account ({} / {}). exposure: {}. pubkey: {:?}",
i,
data.len(),
exposure,
positions.acc_info.key
);
advance_delegation_record(rpc_client, signer, positions, min_reward, current_epoch);
});
}

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
7 changes: 0 additions & 7 deletions staking/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use {
Cli,
},
instructions::{
claim_rewards,
close_all_publisher_caps,
close_publisher_caps,
create_slash_event,
Expand Down Expand Up @@ -99,12 +98,6 @@ fn main() {
Action::SaveStakeAccountsSnapshot {} => {
save_stake_accounts_snapshot(&rpc_client);
}
Action::ClaimRewards {
min_staked,
min_reward,
} => {
claim_rewards(&rpc_client, keypair.as_ref(), min_staked, min_reward);
}
Action::CloseAllPublisherCaps {} => {
close_all_publisher_caps(&rpc_client, keypair.as_ref());
}
Expand Down

0 comments on commit 2c42865

Please sign in to comment.