Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix price spike check to use correct scaling and compare rates #1691

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading