Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethpy interface fixes #1645

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/agent0/core/hyperdrive/interactive/local_hyperdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ def _reinit_state_after_load_snapshot(self) -> None:
"""
# Set internal state block number to 0 to enusre it updates
self.interface.last_state_block_number = BlockNumber(0)
# Clear the read interface cache
self.interface._read_interface = None

def _sync_events(self) -> None:
# Making sure this function isn't called in local_hyperdrive
Expand Down
34 changes: 20 additions & 14 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ class HyperdriveReadInterface:
"""Read-only end-point API for interfacing with a deployed Hyperdrive pool."""

class HyperdriveKind(Enum):
"""Hyperdrive contract kind."""
"""Hyperdrive contract kind.

ERC4626 = "ERC4626"
STETH = "STETH"
MORPHO = "MORPHO"
NOTE the values of these enums match the output of the
`kind()` function from the hyperdrive contract.
"""

ERC4626 = "ERC4626Hyperdrive"
STETH = "StETHHyperdrive"
MORPHO = "MorphoBlueHyperdrive"
EZETH = "EzETHHyperdrive"
RETH = "RETHHyperdrive"

def __init__(
self,
Expand Down Expand Up @@ -202,15 +208,20 @@ def __init__(
self.morpho_contract = None
self.morpho_market_id = None

hyperdrive_kind = self.hyperdrive_contract.functions.kind().call()
if hyperdrive_kind == "StETHHyperdrive":
self.hyperdrive_kind = self.HyperdriveKind.STETH
# Set hyperdrive kind variable
hyperdrive_kind_str = self.hyperdrive_contract.functions.kind().call()
try:
self.hyperdrive_kind = self.HyperdriveKind(hyperdrive_kind_str)
except ValueError:
logging.warning("Unknown hyperdrive kind %s, defaulting to `ERC4626`", hyperdrive_kind_str)
self.hyperdrive_kind = self.HyperdriveKind.ERC4626

if self.hyperdrive_kind == self.HyperdriveKind.STETH:
# Redefine the vault shares token contract as the mock lido contract
self.vault_shares_token_contract = MockLidoContract.factory(w3=self.web3)(
address=web3.to_checksum_address(vault_shares_token_address)
)
elif hyperdrive_kind == "MorphoBlueHyperdrive":
self.hyperdrive_kind = self.HyperdriveKind.MORPHO
elif self.hyperdrive_kind == self.HyperdriveKind.MORPHO:
# MorphoBlue doesn't have a vault shares token
self.vault_shares_token_contract = None
# We access the vault shares token via the specific instance, so we reinitialize
Expand Down Expand Up @@ -252,11 +263,6 @@ def __init__(
self.txn_signature = bytes(0)

else:
# We default to erc4626, but print a warning if we don't recognize the kind
if hyperdrive_kind != "ERC4626Hyperdrive":
logging.warning("Unknown hyperdrive kind %s, defaulting to `ERC4626`", hyperdrive_kind)

self.hyperdrive_kind = self.HyperdriveKind.ERC4626
# TODO Although the underlying function might not be a MockERC4626Contract,
# the pypechain contract factory happily accepts any address and exposes
# all functions from that contract. The code will only break if we try to
Expand Down
18 changes: 12 additions & 6 deletions src/agent0/ethpy/hyperdrive/interface/read_write_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
txn_signature=txn_signature,
)
self.write_retry_count = write_retry_count
self._read_interface: HyperdriveReadInterface | None = None

def get_read_interface(self) -> HyperdriveReadInterface:
"""Return the current instance as an instance of the parent (HyperdriveReadInterface) class.
Expand All @@ -93,12 +94,17 @@ def get_read_interface(self) -> HyperdriveReadInterface:
HyperdriveReadInterface
This instantiated object, but as a ReadInterface.
"""
return HyperdriveReadInterface(
hyperdrive_address=self.hyperdrive_address,
web3=self.web3,
read_retry_count=self.read_retry_count,
txn_receipt_timeout=self.txn_receipt_timeout,
)

# We cache the read interface output when this function gets called multiple times
if self._read_interface is None:
self._read_interface = HyperdriveReadInterface(
hyperdrive_address=self.hyperdrive_address,
web3=self.web3,
read_retry_count=self.read_retry_count,
txn_receipt_timeout=self.txn_receipt_timeout,
)

return self._read_interface

def create_checkpoint(
self,
Expand Down
Loading