Skip to content

Commit

Permalink
Checking for base contract address instead of vault token symbol to d…
Browse files Browse the repository at this point in the history
…etect eth as base (#1435)
  • Loading branch information
slundqui authored Apr 24, 2024
1 parent aca14c4 commit bfce9e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/agent0/chainsync/db/hyperdrive/convert_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def convert_hyperdrive_transactions_for_block(
transaction_dict["hash"] = tx_hash.hex()
# Decode the transaction input
try:
method, params = hyperdrive_contract.decode_function_input(transaction["input"])
# although input may not be a required key, we catch this case
method, params = hyperdrive_contract.decode_function_input(transaction["input"]) # type: ignore
transaction_dict["input"] = {"method": method.fn_name, "params": params}
except ValueError: # if the input is not meant for the contract, ignore it
continue
Expand Down
14 changes: 7 additions & 7 deletions src/agent0/ethpy/hyperdrive/interface/_contract_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def _async_open_long(
min_output = 0 # TODO: give the user access to this parameter

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -260,7 +260,7 @@ async def _async_close_long(
min_output = 0

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -340,7 +340,7 @@ async def _async_open_short(
max_deposit = int(MAX_WEI)

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -425,7 +425,7 @@ async def _async_close_short(
min_output = 0

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -510,7 +510,7 @@ async def _async_add_liquidity(
min_lp_share_price = 0

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -574,7 +574,7 @@ async def _async_remove_liquidity(
min_output = 0

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down Expand Up @@ -635,7 +635,7 @@ async def _async_redeem_withdraw_shares(
min_output = FixedPoint(scaled_value=1)

# We use the yield as the base token in steth pools
if interface.is_steth:
if interface.base_is_eth:
as_base_option = False
else:
as_base_option = True
Expand Down
12 changes: 6 additions & 6 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ def __init__(
address=web3.to_checksum_address(vault_shares_token_address)
)

# Check symbol to see if the underlying vault is steth market
vault_shares_token_symbol = self.vault_shares_token_contract.functions.symbol().call()
if "stETH" in vault_shares_token_symbol:
self.is_steth = True
# If we're using steth, we use the yield token as the base token (i.e., steth)
# Agent0 doesn't support eth as base, so if it is, we use the yield token as the base, and
# calls to trades will use "as_base=False"
if base_token_contract_address == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
self.base_is_eth = True
# If the base token is eth, we use the yield token as the base token (e.g., steth)
# and pass in "as_base=False" to the contract calls.
# This simplifies accounting to have only one base token for steth.
# The alternative of having eth as base token requires keeping track of both
# tokens in order to support `removeLiquidity`, as we can't remove liquidity into
# eth.
base_token_contract_address = vault_shares_token_address
else:
self.is_steth = False
self.base_is_eth = False

self.base_token_contract: ERC20MintableContract = ERC20MintableContract.factory(w3=self.web3)(
web3.to_checksum_address(base_token_contract_address)
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_invariant_checks(

results: list[InvariantCheckResults] = [
_check_eth_balances(pool_state),
_check_base_balances(pool_state, interface.is_steth),
_check_base_balances(pool_state, interface.base_is_eth),
_check_total_shares(pool_state),
_check_minimum_share_reserves(pool_state),
_check_solvency(pool_state),
Expand Down

0 comments on commit bfce9e3

Please sign in to comment.