Skip to content

Commit

Permalink
Changing how we check for using yield as trading token
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheng Lundquist committed Oct 25, 2024
1 parent a3ebc9f commit 27548aa
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class HyperdriveKind(Enum):
MORPHO = "MorphoBlueHyperdrive"
EZETH = "EzETHHyperdrive"
RETH = "RETHHyperdrive"
STKWELL = "StkWellHyperdrive"

def __init__(
self,
Expand Down Expand Up @@ -178,25 +179,36 @@ def __init__(
base_token_contract_address = self.pool_config.base_token
vault_shares_token_address = self.pool_config.vault_shares_token

# 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
self.hyperdrive_name = self.hyperdrive_contract.functions.name().call()

# There are cases where we can't interact with hyperdrive
# with the base token:
# - The pool uses eth as base.
# - The pool does not have a base token.
# - The pool doesn't support some operations in base (i.e., Moonwell EURC, Moonwell USDC)
# In all of these cases, we use the yield token as the base.
# Calls to trades will use "as_base=False"
hyperdrive_name = self.hyperdrive_contract.functions.name().call()
if (
base_token_contract_address # pylint: disable=too-many-boolean-expressions
base_token_contract_address
in (
ETH_CONTRACT_ADDRESS,
ADDRESS_ZERO,
)
or "Moonwell USDC Hyperdrive" in hyperdrive_name
or "Moonwell EURC Hyperdrive" in hyperdrive_name
or "Moonwell StkWell Hyperdrive" in hyperdrive_name
or "Num Finance snARS Hyperdrive" in hyperdrive_name
or hyperdrive_name == "ElementDAO 182 Day sUSDe Hyperdrive"
or self.hyperdrive_kind == self.HyperdriveKind.STKWELL
or self.hyperdrive_name
in (
"ElementDAO 182 Day sUSDe Hyperdrive",
"ElementDAO 30 Day Num Finance snARS Hyperdrive",
"ElementDAO 182 Day Moonwell USDC Hyperdrive",
"ElementDAO 182 Day Moonwell EURC Hyperdrive",
)
):
self.base_is_yield = True
# We use the yield token as the base token (e.g., steth)
Expand All @@ -211,14 +223,6 @@ def __init__(
self.morpho_contract = None
self.morpho_market_id = None

# 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)(
Expand Down

0 comments on commit 27548aa

Please sign in to comment.