Skip to content

Commit

Permalink
Don't checkpoint on paused pools. Don't check for previous checkpoint…
Browse files Browse the repository at this point in the history
…s in invariance checks if pool is paused (#1682)
  • Loading branch information
slundqui authored Sep 11, 2024
1 parent 1b121bf commit fe2adbe
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
22 changes: 21 additions & 1 deletion scripts/checkpoint_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from agent0.core.base.make_key import make_private_key
from agent0.ethpy.base import get_account_balance, smart_contract_preview_transaction, smart_contract_transact
from agent0.ethpy.hyperdrive import get_hyperdrive_pool_config, get_hyperdrive_registry_from_artifacts
from agent0.ethpy.hyperdrive.interface._event_logs import EARLIEST_BLOCK_LOOKUP
from agent0.hyperlogs.rollbar_utilities import initialize_rollbar, log_rollbar_exception, log_rollbar_message

# Checkpoint bot has a lot going on
Expand Down Expand Up @@ -217,7 +218,26 @@ async def run_checkpoint_bot(
log_level=logging.INFO,
)

if enough_time_has_elapsed and checkpoint_doesnt_exist:
# Check to see if the pool is paused. We don't run checkpoint bots on this pool if it's paused.
paused_events = hyperdrive_contract.events.PauseStatusUpdated.get_logs(
from_block=EARLIEST_BLOCK_LOOKUP.get(chain_id, "earliest")
)
is_paused = False
if len(list(paused_events)) > 0:
# Get the latest pause event
# TODO get_logs likely returns events in an ordered
# fashion, but we iterate and find the latest one
# just in case
latest_pause_event = None
max_block_number = 0
for event in paused_events:
if event["blockNumber"] > max_block_number:
max_block_number = event["blockNumber"]
latest_pause_event = event
assert latest_pause_event is not None
is_paused = latest_pause_event["args"]["isPaused"]

if enough_time_has_elapsed and checkpoint_doesnt_exist and not is_paused:
logging_str = f"Pool {pool_name} for {checkpoint_time=}: submitting checkpoint"
logging.info(logging_str)
if log_to_rollbar:
Expand Down
25 changes: 25 additions & 0 deletions src/agent0/ethpy/hyperdrive/interface/_event_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,31 @@ def _get_initialize_events(
return out_events


def _get_pool_is_paused(
hyperdrive_interface: HyperdriveReadInterface,
) -> bool:
chain_id = hyperdrive_interface.web3.eth.chain_id
# Check to see if the pool is paused. We don't run checkpoint bots on this pool if it's paused.
paused_events = hyperdrive_interface.hyperdrive_contract.events.PauseStatusUpdated.get_logs(
from_block=EARLIEST_BLOCK_LOOKUP.get(chain_id, "earliest")
)
is_paused = False
if len(list(paused_events)) > 0:
# Get the latest pause event
# TODO get_logs likely returns events in an ordered
# fashion, but we iterate and find the latest one
# just in case
latest_pause_event = None
max_block_number = 0
for event in paused_events:
if event["blockNumber"] > max_block_number:
max_block_number = event["blockNumber"]
latest_pause_event = event
assert latest_pause_event is not None
is_paused = latest_pause_event["args"]["isPaused"]
return is_paused


# TODO we can add a helper function to get all trading events here
def _get_open_long_events(
hyperdrive_interface: HyperdriveReadInterface,
Expand Down
11 changes: 11 additions & 0 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
_get_initialize_events,
_get_open_long_events,
_get_open_short_events,
_get_pool_is_paused,
_get_redeem_withdrawal_shares_events,
_get_remove_liquidity_events,
_get_transfer_single_events,
Expand Down Expand Up @@ -646,6 +647,16 @@ def get_gov_fees_accrued(self, block_identifier: BlockIdentifier | None = None)
"""
return _get_gov_fees_accrued(self.hyperdrive_contract, block_identifier)

def get_pool_is_paused(self) -> bool:
"""Get whether or not the pool is paused from events.
Returns
-------
bool
Whether or not the pool is paused.
"""
return _get_pool_is_paused(self)

def get_transfer_single_events(
self,
from_block: BlockIdentifier | None = None,
Expand Down
4 changes: 4 additions & 0 deletions src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ def _check_previous_checkpoint_exists(
):
return InvariantCheckResults(failed=False, exception_message=None, exception_data={}, log_level=None)

# We ignore this test if the pool is paused
if interface.get_pool_is_paused():
return InvariantCheckResults(failed=False, exception_message=None, exception_data={}, log_level=None)

# Otherwise, we ensure the previous checkpoint exists
previous_checkpoint = get_hyperdrive_checkpoint(
interface.hyperdrive_contract, Timestamp(previous_checkpoint_time), pool_state.block_number
Expand Down

0 comments on commit fe2adbe

Please sign in to comment.