Skip to content

Commit

Permalink
fix long delta calculation; improves test to be more direct
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Jul 16, 2024
1 parent e095c56 commit 4258923
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 113 deletions.
5 changes: 0 additions & 5 deletions crates/hyperdrive-math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,12 @@ mod tests {
{
continue;
}

// Pick a random target rate that is near the current rate.
let target_rate =
state.calculate_spot_rate()? * rng.gen_range(fixed!(0.1e18)..=fixed!(10e18));

// Estimate the long that achieves a target rate.
let (target_share_reserves, target_bond_reserves) =
state.reserves_given_rate_ignoring_exposure(target_rate)?;

// Verify that the new levels are solvent.
let mut new_state = state.clone();
new_state.info.share_reserves = target_share_reserves.into();
Expand All @@ -390,15 +387,13 @@ mod tests {
{
continue;
}

// Fixed rate for the new state should equal the target rate.
let realized_rate = new_state.calculate_spot_rate()?;
let error = if realized_rate > target_rate {
realized_rate - target_rate
} else {
target_rate - realized_rate
};

assert!(
error <= test_tolerance,
"expected error={} <= tolerance={}",
Expand Down
1 change: 0 additions & 1 deletion crates/hyperdrive-math/src/long/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ mod tests {
}
};
let max_iterations = 7;
// TODO: We should use calculate_absolute_max_long here because that is what we are testing.
// We need to catch panics because of FixedPoint overflows & underflows.
let max_trade = panic::catch_unwind(|| {
state.calculate_max_long(U256::MAX, checkpoint_exposure, Some(max_iterations))
Expand Down
Loading

0 comments on commit 4258923

Please sign in to comment.