diff --git a/src/agent0/hyperfuzz/system_fuzz/invariant_checks.py b/src/agent0/hyperfuzz/system_fuzz/invariant_checks.py index d09b2a266..731c568e7 100644 --- a/src/agent0/hyperfuzz/system_fuzz/invariant_checks.py +++ b/src/agent0/hyperfuzz/system_fuzz/invariant_checks.py @@ -228,21 +228,29 @@ def _check_price_spike(interface: HyperdriveReadInterface, pool_state: PoolState ) # The checkpoint weighted spot price is updated every checkpoint and every trade. - previous_weighted_spot_apr = interface.calc_rate_given_fixed_price( + previous_weighted_spot_rate = interface.calc_rate_given_fixed_price( previous_pool_state.checkpoint.weighted_spot_price, - FixedPoint(previous_pool_state.pool_config.position_duration), + FixedPoint(scaled_value=previous_pool_state.pool_config.position_duration), ) current_spot_price = interface.calc_spot_price(pool_state) + current_spot_rate = interface.calc_rate_given_fixed_price( + current_spot_price, + FixedPoint(scaled_value=previous_pool_state.pool_config.position_duration), + ) - if abs(current_spot_price - previous_weighted_spot_apr) >= delta_rate_epsilon: + if abs(current_spot_rate - previous_weighted_spot_rate) >= delta_rate_epsilon: + exception_data["invariance_check:current_spot_rate"] = current_spot_rate + exception_data["invariance_check:previous_weighted_spot_rate"] = previous_weighted_spot_rate exception_data["invariance_check:current_spot_price"] = current_spot_price - exception_data["invariance_check:previous_weighted_spot_apr"] = previous_weighted_spot_apr + exception_data["invariance_check:previous_weighted_spot_price"] = ( + previous_pool_state.checkpoint.weighted_spot_price + ) failed = True exception_message = ( "Large trade has caused the a rate circuit breaker to trip. " - f"{current_spot_price=}, {previous_weighted_spot_apr=}. " + f"{current_spot_rate=}, {previous_weighted_spot_rate=}. " "Difference: " - f"{current_spot_price- previous_weighted_spot_apr}." + f"{current_spot_rate- previous_weighted_spot_rate}." ) log_level = logging.WARNING