From 19a762785b4696f718c5a392ae4a6d2ecc594fe2 Mon Sep 17 00:00:00 2001 From: Sheng Lundquist Date: Mon, 7 Oct 2024 13:22:35 -0700 Subject: [PATCH] Flag for unit conversions in event getters for db --- src/agent0/chainsync/db/hyperdrive/chain_to_db.py | 12 ++++++++++++ src/agent0/chainsync/db/hyperdrive/event_getters.py | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/agent0/chainsync/db/hyperdrive/chain_to_db.py b/src/agent0/chainsync/db/hyperdrive/chain_to_db.py index 76c9224763..a60f1be564 100644 --- a/src/agent0/chainsync/db/hyperdrive/chain_to_db.py +++ b/src/agent0/chainsync/db/hyperdrive/chain_to_db.py @@ -147,6 +147,7 @@ def checkpoint_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.CreateCheckpoint, + trade_base_unit_conversion=False, from_block=from_block, ) ) @@ -202,6 +203,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.TransferSingle, + trade_base_unit_conversion=False, from_block=from_block, argument_filters={"to": wallet_addr}, ) @@ -210,6 +212,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.TransferSingle, + trade_base_unit_conversion=False, from_block=from_block, argument_filters={"from": wallet_addr}, ) @@ -220,6 +223,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.TransferSingle, + trade_base_unit_conversion=False, from_block=from_block, ) ) @@ -236,6 +240,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.Initialize, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=provider_arg_filter, ) @@ -244,6 +249,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.OpenLong, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=trader_arg_filter, ) @@ -252,6 +258,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.CloseLong, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=trader_arg_filter, ) @@ -260,6 +267,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.OpenShort, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=trader_arg_filter, ) @@ -268,6 +276,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.CloseShort, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=trader_arg_filter, ) @@ -276,6 +285,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.AddLiquidity, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=provider_arg_filter, numeric_args_as_str=True, @@ -285,6 +295,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.RemoveLiquidity, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=provider_arg_filter, ) @@ -293,6 +304,7 @@ def trade_events_to_db( get_event_logs_for_db( interface, interface.hyperdrive_contract.events.RedeemWithdrawalShares, + trade_base_unit_conversion=True, from_block=from_block, argument_filters=provider_arg_filter, numeric_args_as_str=True, diff --git a/src/agent0/chainsync/db/hyperdrive/event_getters.py b/src/agent0/chainsync/db/hyperdrive/event_getters.py index 5531fd0c04..703c1fe563 100644 --- a/src/agent0/chainsync/db/hyperdrive/event_getters.py +++ b/src/agent0/chainsync/db/hyperdrive/event_getters.py @@ -71,6 +71,7 @@ def _convert_event_lido_shares_to_steth(events: list[dict[str, Any]], numeric_ar def get_event_logs_for_db( hyperdrive_interface: HyperdriveReadInterface, event_class: type[ContractEvent], + trade_base_unit_conversion: bool, from_block: BlockIdentifier | None = None, argument_filters: dict[str, Any] | None = None, numeric_args_as_str: bool = True, @@ -83,6 +84,8 @@ def get_event_logs_for_db( The hyperdrive interface to use. event_class: type[ContractEvent] The event class to get logs for. + trade_base_unit_conversion: bool + Whether to convert trade base units from steth "shares" to steth. from_block: BlockIdentifier | None, optional The block to start getting events from. Defaults to "earliest", with some exceptions for specific chains. argument_filters: dict[str, Any] | None, optional @@ -96,6 +99,8 @@ def get_event_logs_for_db( list[dict[str, Any]] A list of emitted events. """ + # pylint: disable=too-many-arguments + # We look up the chain id, and define the `from_block` based on which chain it is as the default. if from_block is None: chain_id = hyperdrive_interface.web3.eth.chain_id @@ -108,7 +113,7 @@ def get_event_logs_for_db( ] # Convert output event data from lido shares to steth - if hyperdrive_interface.hyperdrive_kind == hyperdrive_interface.HyperdriveKind.STETH: + if trade_base_unit_conversion and hyperdrive_interface.hyperdrive_kind == hyperdrive_interface.HyperdriveKind.STETH: _convert_event_lido_shares_to_steth(out_events, numeric_args_as_str) return out_events