diff --git a/bot/src/rpc_client_utils.rs b/bot/src/rpc_client_utils.rs index b03612d6..c538efd8 100644 --- a/bot/src/rpc_client_utils.rs +++ b/bot/src/rpc_client_utils.rs @@ -285,6 +285,26 @@ pub fn send_and_confirm_transactions_with_spinner( Err("Max retries exceeded".into()) } +pub(crate) fn get_stake_with_fallback( + rpc_client: &RpcClient, + stake_address: &Pubkey, +) -> Result<(u64, u64), Box> { + let stake_activation = rpc_client.get_stake_activation(*stake_address, None); + if let Ok(stake_activation) = stake_activation { + Ok((stake_activation.active, stake_activation.inactive)) + } else { + Ok(( + 0, + rpc_client.get_balance(stake_address).map_err(|err| { + format!( + "Unable to get stake account balance: {}: {}", + stake_address, err + ) + })?, + )) + } +} + pub struct VoteAccountInfo { pub identity: Pubkey, pub vote_address: Pubkey, diff --git a/bot/src/stake_pool_v0.rs b/bot/src/stake_pool_v0.rs index 798180f4..2d64d348 100644 --- a/bot/src/stake_pool_v0.rs +++ b/bot/src/stake_pool_v0.rs @@ -2,7 +2,8 @@ use { crate::{ generic_stake_pool::*, rpc_client_utils::{ - get_all_stake_by_staker, send_and_confirm_transactions_with_spinner, MultiClient, + get_all_stake_by_staker, get_stake_with_fallback, + send_and_confirm_transactions_with_spinner, MultiClient, }, }, log::*, @@ -654,19 +655,9 @@ where validator_stake.vote_address, ); - let balance = client.get_balance(&stake_address).map_err(|err| { - format!( - "Unable to get stake account balance: {}: {}", - stake_address, err - ) - })? + client - .get_balance(&transient_stake_address) - .map_err(|err| { - format!( - "Unable to get transient stake account balance: {}: {}", - transient_stake_address, err - ) - })?; + let (active_balance, inactive_balance) = get_stake_with_fallback(client, &stake_address)?; + let (transient_active_balance, transient_inactive_balance) = + get_stake_with_fallback(client, &transient_stake_address)?; let list = if validator_stake.priority { &mut priority_stake @@ -678,7 +669,8 @@ where } }; list.push(( - balance, + active_balance + transient_active_balance, + inactive_balance + transient_inactive_balance, stake_address, transient_stake_address, validator_stake, @@ -696,7 +688,8 @@ where let mut transactions = vec![]; for ( - balance, + active_balance, + inactive_balance, stake_address, transient_stake_address, ValidatorStake { @@ -711,8 +704,11 @@ where .chain(baseline_stake) .chain(bonus_stake) { + let balance = active_balance + inactive_balance; let desired_balance = match stake_state { - ValidatorStakeState::None => MIN_STAKE_ACCOUNT_BALANCE, + // there might be some additional inactive balance due to merges, + // so be sure to leave `MIN_STAKE_DELEGATION` + inactive balance + ValidatorStakeState::None => MIN_STAKE_DELEGATION + inactive_balance, ValidatorStakeState::Baseline => baseline_stake_amount, ValidatorStakeState::Bonus => bonus_stake_amount, };