Skip to content

Commit

Permalink
remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Dec 13, 2024
1 parent e5a65ab commit 814058b
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions crates/hyperdrive-math/src/short/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,11 @@ impl State {
)?
.change_type::<I256>()?;
let mut last_good_bond_amount = self.absolute_max_short_guess(checkpoint_exposure)?;
println!("max short guess {:#?}", last_good_bond_amount);
for iter in 0..max_iterations {
println!("");
println!("iter {:#?}", iter);
println!("last_good_bond_amount {:#?}", last_good_bond_amount);
for _ in 0..max_iterations {
// Return if we are within tolerance bonds of insolvency.
let solvency_within_tolerance = self
.solvency_after_short(last_good_bond_amount + bond_tolerance, checkpoint_exposure);
if solvency_within_tolerance.is_err() {
println!(
"RETURNING bonds {:#?}; solvency {:#?}",
last_good_bond_amount, solvency_within_tolerance
);
return Ok(last_good_bond_amount);
}

Expand All @@ -559,21 +551,12 @@ impl State {
- self
.calculate_pool_share_delta_after_open_short(last_good_bond_amount)?
.change_type::<I256>()?;
println!(
"target_pool_shares {:#?}; current_pool_shares {:#?}",
target_pool_shares, current_pool_shares
);

// The loss function is z_t - z, and its derivative is -dz/dy.
let loss = target_pool_shares - current_pool_shares;
let loss_derivative =
-self.calculate_pool_delta_shares_after_short_derivative(last_good_bond_amount)?;
let dy = loss.div_up(loss_derivative);
println!(
"loss {:#?}; loss_derivative {:#?}; dy {:#?}",
loss, loss_derivative, dy
);

// Bond amount must increase.
// Negative dy indicates that the bond amount would go up with a
// proper step of Newton's Method.
Expand All @@ -594,14 +577,10 @@ impl State {
// Calculate the current solvency & iterate w/ a good bond amount.
last_good_bond_amount =
match self.solvency_after_short(new_bond_amount, checkpoint_exposure) {
Ok(solvency) => {
println!("iterating; solvency {:#?}", solvency);
new_bond_amount
}
Ok(solvency) => new_bond_amount,
// New bond amount is too large. Use a binary search to find a
// new starting point.
Err(_) => {
println!("new_bond_amount={:#?} is not solvent", new_bond_amount);
// Start from halfway between the new bond amount and the
// last good bond amount.
let mut return_amount = new_bond_amount
Expand All @@ -612,10 +591,6 @@ impl State {
.solvency_after_short(return_amount, checkpoint_exposure)
.is_ok()
{
println!(
"BINARY SEARCH: return_amount {:#?} in {:#?} iterations",
return_amount, num_tries
);
break return_amount;
}
// Return amount is still too large, try again.
Expand All @@ -625,7 +600,6 @@ impl State {
// Avoid running forever by returning a guaranteed good
// bond amount.
if num_tries >= 100_000 {
println!("GIVE UP BINARY SEARCH after {:#?} iterations", num_tries);
break last_good_bond_amount * fixed!(0.99e18);
}
}
Expand Down Expand Up @@ -1174,10 +1148,7 @@ mod tests {
let max_iterations = 100;
// Run the fuzz tests
let mut rng = thread_rng();
for iter in 0..*FAST_FUZZ_RUNS {
println!("");
println!("-----");
println!("iter {:#?}", iter);
for _ in 0..*FAST_FUZZ_RUNS {
let state = rng.gen::<State>();
let checkpoint_exposure = {
let value = rng.gen_range(fixed!(0)..=FixedPoint::from(U256::from(U128::MAX)));
Expand Down

0 comments on commit 814058b

Please sign in to comment.