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

update negative interest check to use relative tolerance for log level #1735

Merged
merged 6 commits into from
Nov 16, 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
19 changes: 15 additions & 4 deletions src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

LP_SHARE_PRICE_EPSILON = 1e-4
TOTAL_SHARES_EPSILON = 1e-9
NEGATIVE_INTEREST_EPSILON = FixedPoint(scaled_value=10) # 10 wei
NEGATIVE_INTEREST_ATOL = FixedPoint(scaled_value=10) # absolute tolerance 10 wei
NEGATIVE_INTEREST_RTOL = FixedPoint(0.001) # relative tolerance 10bp
PRESENT_VALUE_EPSILON = FixedPoint(scaled_value=1) # 1 wei
EZETH_NEG_INTEREST_TIME_DELTA = 12 * 60 * 60

Expand Down Expand Up @@ -279,6 +280,13 @@ def _check_price_spike(interface: HyperdriveReadInterface, pool_state: PoolState


def _check_negative_interest(interface: HyperdriveReadInterface, pool_state: PoolState) -> InvariantCheckResults:
"""Check for negative interest in the pool.

If the rate went down, post a log
If the pool is paused, log is warning regardless of relative rate change
If the pool is not paused and the rate went down by more than the relative tol, log is critical
If the pool is not paused, but the rate did not go down by more than the relative tol, log is warning
"""
# Hyperdrive base & eth balances should always be zero
failed = False
exception_message: str | None = None
Expand All @@ -303,13 +311,16 @@ def _check_negative_interest(interface: HyperdriveReadInterface, pool_state: Poo
previous_pool_state = interface.get_hyperdrive_state(block_identifier=previous_block_number)
previous_vault_share_price = previous_pool_state.pool_info.vault_share_price

if (current_vault_share_price - previous_vault_share_price) <= -NEGATIVE_INTEREST_EPSILON:
# Absolute check to see if the rate went down
if current_vault_share_price - previous_vault_share_price <= -NEGATIVE_INTEREST_ATOL:
log_level = logging.WARNING
if interface.get_pool_is_paused():
paused_str = "paused"
log_level = logging.WARNING
else:
paused_str = "unpaused"
log_level = logging.CRITICAL
# relative check to see if the rate went down by a lot
if previous_vault_share_price * (FixedPoint(1) - NEGATIVE_INTEREST_RTOL) >= current_vault_share_price:
log_level = logging.CRITICAL
failed = True
exception_data["invariance_check:current_vault_share_price"] = current_vault_share_price
exception_data["invariance_check:previous_vault_share_price"] = previous_vault_share_price
Expand Down
Loading