Skip to content

Commit

Permalink
Merge branch 'master' into joncinque-min-dele-merged
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-at-planetariummusic committed Dec 18, 2023
2 parents 53239bc + a155229 commit bc68b17
Show file tree
Hide file tree
Showing 6 changed files with 1,477 additions and 16 deletions.
1 change: 1 addition & 0 deletions bot/src/generic_stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub trait GenericStakePool {
client: &MultiClient,
dry_run: bool,
desired_validator_stake: &[ValidatorStake],
bonus_multiplier: Option<f64>,
) -> Result<
(
EpochStakeNotes,
Expand Down
5 changes: 5 additions & 0 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,11 @@ fn main() -> BoxResult<()> {
cluster_multi_client,
pre_run_dry_run || config.dry_run,
&desired_validator_stake,
if config.cluster == Testnet {
Some(0.85)
} else {
None
},
)?;

let mut summary_messages: Vec<String> = vec![format!(
Expand Down
1 change: 1 addition & 0 deletions bot/src/noop_stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl GenericStakePool for NoopStakePool {
_client: &MultiClient,
dry_run: bool,
desired_validator_stake: &[ValidatorStake],
_bonus_multiplier: Option<f64>,
) -> Result<
(
EpochStakeNotes,
Expand Down
18 changes: 11 additions & 7 deletions bot/src/stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl GenericStakePool for StakePoolOMatic {
client: &MultiClient,
dry_run: bool,
desired_validator_stake: &[ValidatorStake],
_bonus_multiplier: Option<f64>,
) -> Result<
(
EpochStakeNotes,
Expand Down Expand Up @@ -932,13 +933,13 @@ mod test {
.collect::<Vec<_>>();

stake_o_matic
.apply(client, false, &desired_validator_stake)
.apply(client, false, &desired_validator_stake, None)
.unwrap();

assert!(num_stake_accounts(client, pool_withdraw_authority) > 1 + validators.len());
let _epoch = wait_for_next_epoch(client).unwrap();
stake_o_matic
.apply(client, false, &desired_validator_stake)
.apply(client, false, &desired_validator_stake, None)
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -1095,6 +1096,7 @@ mod test {
priority: false,
})
.collect::<Vec<_>>(),
None,
)
.unwrap();

Expand Down Expand Up @@ -1156,6 +1158,7 @@ mod test {
priority: false,
})
.collect::<Vec<_>>(),
None,
)
.unwrap();

Expand Down Expand Up @@ -1203,6 +1206,7 @@ mod test {
priority: false,
})
.collect::<Vec<_>>(),
None,
)
.unwrap();

Expand Down Expand Up @@ -1253,11 +1257,11 @@ mod test {
];

stake_o_matic
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();
let _epoch = wait_for_next_epoch(&client).unwrap();
stake_o_matic
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();

info!("Check after first epoch");
Expand Down Expand Up @@ -1285,7 +1289,7 @@ mod test {
info!("Check after second epoch");
let _epoch = wait_for_next_epoch(&client).unwrap();
stake_o_matic
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();

assert_eq!(
Expand All @@ -1310,11 +1314,11 @@ mod test {
// ===========================================================
info!("remove all validators");
// deactivate all validator stake and remove from pool
stake_o_matic.apply(&client, false, &[]).unwrap();
stake_o_matic.apply(&client, false, &[], None).unwrap();

// withdraw removed validator stake into the staker
let _epoch = wait_for_next_epoch(&client).unwrap();
stake_o_matic.apply(&client, false, &[]).unwrap();
stake_o_matic.apply(&client, false, &[], None).unwrap();
// all stake has been returned to the reserve account
assert_reserve_account_only(
min_reserve_stake_balance + stake_rent_exemption + total_stake_amount,
Expand Down
21 changes: 12 additions & 9 deletions bot/src/stake_pool_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl GenericStakePool for StakePool {
client: &MultiClient,
dry_run: bool,
desired_validator_stake: &[ValidatorStake],
bonus_multiplier: Option<f64>,
) -> Result<
(
EpochStakeNotes,
Expand Down Expand Up @@ -210,10 +211,11 @@ impl GenericStakePool for StakePool {
Sol(total_bonus_stake_amount)
);

let bonus_stake_amount = if bonus_stake_node_count == 0 {
let bonus_stake_amount: u64 = if bonus_stake_node_count == 0 {
0
} else {
total_bonus_stake_amount / (bonus_stake_node_count as u64)
(bonus_multiplier.unwrap_or(1.0)
* ((total_bonus_stake_amount / bonus_stake_node_count) as f64)) as u64
};

info!("Bonus stake amount: {}", Sol(bonus_stake_amount));
Expand Down Expand Up @@ -900,7 +902,7 @@ mod test {
.collect::<Vec<_>>();

stake_pool
.apply(client, false, &desired_validator_stake)
.apply(client, false, &desired_validator_stake, None)
.unwrap();

assert_eq!(
Expand All @@ -909,7 +911,7 @@ mod test {
);
let _epoch = wait_for_next_epoch(client).unwrap();
stake_pool
.apply(client, false, &desired_validator_stake)
.apply(client, false, &desired_validator_stake, None)
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -1034,6 +1036,7 @@ mod test {
priority: false,
})
.collect::<Vec<_>>(),
None,
)
.unwrap();

Expand Down Expand Up @@ -1107,11 +1110,11 @@ mod test {
];

stake_pool
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();
let _epoch = wait_for_next_epoch(&client).unwrap();
stake_pool
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();

// after the first epoch, validators 0 and 1 are at their target levels but validator 2
Expand Down Expand Up @@ -1142,7 +1145,7 @@ mod test {

let _epoch = wait_for_next_epoch(&client).unwrap();
stake_pool
.apply(&client, false, &desired_validator_stake)
.apply(&client, false, &desired_validator_stake, None)
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -1173,10 +1176,10 @@ mod test {
info!("remove all validators");

// deactivate all validator stake
stake_pool.apply(&client, false, &[]).unwrap();
stake_pool.apply(&client, false, &[], None).unwrap();
let _epoch = wait_for_next_epoch(&client).unwrap();
// merge deactivated validator stake back into the reserve
stake_pool.apply(&client, false, &[]).unwrap();
stake_pool.apply(&client, false, &[], None).unwrap();
// all stake has returned to the reserve account
assert_reserve_account_only();
}
Expand Down
Loading

0 comments on commit bc68b17

Please sign in to comment.