Skip to content

Commit

Permalink
update negative interest check to use relative tolerance for log level (
Browse files Browse the repository at this point in the history
#1735)

    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
  • Loading branch information
dpaiton authored Nov 16, 2024
1 parent 464a21f commit 401e2d9
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit 401e2d9

Please sign in to comment.