Skip to content

Commit

Permalink
cleanup comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal committed Jan 17, 2024
1 parent 2b1f50f commit 29d1725
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/agent0/bin/fuzz_bot_invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,15 @@ def run_invariant_checks(
exception_message: list[str] = ["Continuous Fuzz Bots Invariant Checks"]
exception_data: dict[str, Any] = {}

# Hyperdrive base & eth balances should always be zero
eth_balances_results = _check_eth_balances(latest_block_number, pool_state)
base_balances_results = _check_base_balances(latest_block_number, pool_state)

# Total shares is correctly calculated
total_share_results = _check_total_shares(latest_block_number, test_epsilon, pool_state)

# The pool has more than the minimum share reserves
minimum_share_reserves_results = _check_minimum_share_reserves(latest_block_number, pool_state)

# The system should always be solvent
solvency_results = _check_solvency(latest_block_number, pool_state)

# Present value is always greater than or equal to idle
present_values_greater_than_idle_shares_results = _check_present_value_greater_than_idle_shares(
latest_block_number, interface, pool_state
)

# LP share price
# for any trade, LP share price shouldn't change by more than 0.1%
lp_share_price_results = _check_lp_share_price(latest_block_number, interface, test_epsilon, pool_state)

# Creating a checkpoint should never fail
# TODO: add get_block_transactions() to interface
# NOTE: This wold be prone to false positives.
# If the transaction would have failed anyway, then we don't know
# that it failed bc of checkpoint failure or bc e.g., open long was for too much
checkpointing_results = _check_checkpointing_should_never_fail(
latest_block, latest_block_number, interface, pool_state
)
Expand All @@ -177,6 +159,7 @@ def run_invariant_checks(
lp_share_price_results,
checkpointing_results,
]

for failed, message, data in results:
any_check_failed = failed | any_check_failed
if message:
Expand All @@ -198,6 +181,7 @@ class InvariantCheckResults(NamedTuple):


def _check_eth_balances(latest_block_number, pool_state) -> InvariantCheckResults:
# Hyperdrive base & eth balances should always be zero
failed = False
exception_message: str | None = None
exception_data: dict[str, Any] = {}
Expand All @@ -211,6 +195,7 @@ def _check_eth_balances(latest_block_number, pool_state) -> InvariantCheckResult


def _check_base_balances(latest_block_number, pool_state) -> InvariantCheckResults:
# Hyperdrive base & eth balances should always be zero
failed = False
exception_message: str | None = None
exception_data: dict[str, Any] = {}
Expand All @@ -226,6 +211,11 @@ def _check_base_balances(latest_block_number, pool_state) -> InvariantCheckResul
def _check_checkpointing_should_never_fail(
latest_block, latest_block_number, interface, pool_state
) -> InvariantCheckResults:
# Creating a checkpoint should never fail
# TODO: add get_block_transactions() to interface
# NOTE: This wold be prone to false positives.
# If the transaction would have failed anyway, then we don't know
# that it failed bc of checkpoint failure or bc e.g., open long was for too much
failed = False
exception_message: str | None = None
exception_data: dict[str, Any] = {}
Expand Down Expand Up @@ -253,6 +243,7 @@ def _check_checkpointing_should_never_fail(


def _check_solvency(block_number: BlockNumber, pool_state: PoolState) -> InvariantCheckResults:
# The system should always be solvent
failed = False
exception_message: str | None = None
exception_data: dict[str, Any] = {}
Expand All @@ -275,6 +266,7 @@ def _check_solvency(block_number: BlockNumber, pool_state: PoolState) -> Invaria


def _check_minimum_share_reserves(block_number: BlockNumber, pool_state: PoolState) -> InvariantCheckResults:
# The pool has more than the minimum share reserves
failed = False
exception_message = ""
exception_data: dict[str, Any] = {}
Expand All @@ -297,6 +289,7 @@ def _check_minimum_share_reserves(block_number: BlockNumber, pool_state: PoolSta


def _check_total_shares(block_number: BlockNumber, test_epsilon: float, pool_state: PoolState) -> InvariantCheckResults:
# Total shares is correctly calculated
failed = False
exception_message = ""
exception_data: dict[str, Any] = {}
Expand Down Expand Up @@ -379,6 +372,9 @@ def _check_lp_share_price(
-------
InvariantCheckResults
"""
# LP share price
# for any trade, LP share price shouldn't change by more than 0.1%

failed = False
exception_message = ""
exception_data: dict[str, Any] = {}
Expand Down

0 comments on commit 29d1725

Please sign in to comment.