Skip to content

Commit

Permalink
update Checkpoint, remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal committed May 7, 2024
1 parent 2a2bfac commit 4e86c51
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 51 deletions.
9 changes: 2 additions & 7 deletions crates/hyperdrive-math/src/long/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl State {
mod tests {
use ethers::{signers::LocalWallet, types::U256};
use fixed_point_macros::{fixed, uint256};
use hyperdrive_wrappers::wrappers::ihyperdrive::{Checkpoint, Options};
use hyperdrive_wrappers::wrappers::ihyperdrive::Options;
use rand::{thread_rng, Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use test_utils::{
Expand Down Expand Up @@ -363,11 +363,6 @@ mod tests {

// Get state and trade details.
let state = alice.get_state().await?;
let Checkpoint {
vault_share_price: open_vault_share_price,
} = alice
.get_checkpoint(state.to_checkpoint(alice.now().await?))
.await?;
let max_long = bob.calculate_max_long(None).await?;
let min_base_amount = FixedPoint::from(state.config.minimum_transaction_amount)
* FixedPoint::from(state.info.vault_share_price);
Expand Down Expand Up @@ -405,7 +400,7 @@ mod tests {
tolerance
);
}
Err(err) => {
Err(_) => {
assert!(bonds_purchased.is_err());
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/hyperdrive-math/src/short/max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ mod tests {
let state = alice.get_state().await?;
let Checkpoint {
vault_share_price: open_vault_share_price,
weighted_spot_price: _,
last_weighted_spot_price_update_time: _,
} = alice
.get_checkpoint(state.to_checkpoint(alice.now().await?))
.await?;
Expand Down Expand Up @@ -691,6 +693,8 @@ mod tests {
let state = alice.get_state().await?;
let Checkpoint {
vault_share_price: open_vault_share_price,
weighted_spot_price: _,
last_weighted_spot_price_update_time: _,
} = alice
.get_checkpoint(state.to_checkpoint(alice.now().await?))
.await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/hyperdrive-math/src/short/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ mod tests {
let state = alice.get_state().await?;
let Checkpoint {
vault_share_price: open_vault_share_price,
weighted_spot_price: _,
last_weighted_spot_price_update_time: _,
} = alice
.get_checkpoint(state.to_checkpoint(alice.now().await?))
.await?;
Expand Down
44 changes: 0 additions & 44 deletions crates/hyperdrive-math/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ mod tests {
use test_utils::{chain::TestChain, constants::FAST_FUZZ_RUNS};

use super::*;
use crate::State;

#[tokio::test]
async fn fuzz_calculate_time_stretch() -> Result<()> {
Expand Down Expand Up @@ -172,47 +171,4 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn fuzz_calculate_initial_bond_reserves() -> Result<()> {
let chain = TestChain::new().await?;

// Fuzz the rust and solidity implementations against each other.
let mut rng = thread_rng();
for _ in 0..*FAST_FUZZ_RUNS {
// Get the current state of the mock contract
let state = rng.gen::<State>();
let effective_share_reserves = calculate_effective_share_reserves(
state.info.share_reserves.into(),
state.info.share_adjustment.into(),
);
// Calculate the bonds
let actual = calculate_initial_bond_reserves(
effective_share_reserves,
state.config.initial_vault_share_price.into(),
fixed!(0.01e18),
state.config.position_duration.into(),
state.config.time_stretch.into(),
);
match chain
.mock_hyperdrive_math()
.calculate_initial_bond_reserves(
effective_share_reserves.into(),
state.config.initial_vault_share_price,
fixed!(0.01e18).into(),
state.config.position_duration,
state.config.time_stretch,
)
.call()
.await
{
Ok(expected_y) => {
assert_eq!(actual, FixedPoint::from(expected_y));
}
Err(_) => panic!("Test failed."),
}
}

Ok(())
}
}
2 changes: 2 additions & 0 deletions crates/hyperdrive-math/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub async fn test_integration_calculate_max_short() -> Result<()> {
let state = alice.get_state().await?;
let Checkpoint {
vault_share_price: open_vault_share_price,
weighted_spot_price: _,
last_weighted_spot_price_update_time: _,
} = alice
.get_checkpoint(state.to_checkpoint(alice.now().await?))
.await?;
Expand Down

0 comments on commit 4e86c51

Please sign in to comment.