Skip to content

Commit

Permalink
Flag for unit conversions in event getters for db
Browse files Browse the repository at this point in the history
  • Loading branch information
slundqui committed Oct 7, 2024
1 parent 6d67437 commit 19a7627
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/agent0/chainsync/db/hyperdrive/chain_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Expand Down Expand Up @@ -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},
)
Expand All @@ -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},
)
Expand All @@ -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,
)
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
Expand All @@ -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,
)
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/agent0/chainsync/db/hyperdrive/event_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 19a7627

Please sign in to comment.