Skip to content

Commit

Permalink
Hyperdrive v0.9.0 (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheng Lundquist authored Mar 11, 2024
1 parent 3446167 commit 47cc0ff
Show file tree
Hide file tree
Showing 48 changed files with 564 additions and 273 deletions.
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
### Migrations Image ###
# pinned to a specific image chosen from https://github.com/delvtech/hyperdrive/pkgs/container/hyperdrive%2Fdevnet
FROM ghcr.io/delvtech/hyperdrive/devnet:0.0.8 as migrations

# ### Python Image ###
FROM python:3.10-slim

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies = [
"pandas-stubs",
"requests",
"docker",
"pytest",
"ipython",
]


Expand All @@ -54,15 +56,13 @@ dev = [
"autodocsumm>=0.2.11",
"black==24.*",
"coverage",
"ipython",
"jupytext",
"myst-parser>=2.0.0",
"nbconvert",
"nbsphinx>=0.8.12",
"numpydoc>=1.5.0",
"pylint",
"pyright",
"pytest",
"sphinx>=6",
"sphinx-autoapi>=2.0.1",
"sphinx_autodoc_typehints>=1.21.8",
Expand Down
4 changes: 2 additions & 2 deletions src/agent0/core/hyperdrive/interactive/i_hyperdrive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def test_remote_funding_and_trades(chain: ILocalChain, check_remote_chain: bool)
hyperdrive_agent2 = interactive_remote_hyperdrive.init_agent(private_key=make_private_key())
hyperdrive_agent2.add_funds(base=FixedPoint(111_111), eth=FixedPoint(111))
hyperdrive_agent2.set_max_approval()
open_long_event_2 = hyperdrive_agent2.open_long(base=FixedPoint(33_333))
open_long_event_2 = hyperdrive_agent2.open_long(base=FixedPoint(333))

assert open_long_event_2.base_amount == FixedPoint(33_333)
assert open_long_event_2.base_amount == FixedPoint(333)
agent2_longs = list(hyperdrive_agent2.wallet.longs.values())
assert len(agent2_longs) == 1
assert agent2_longs[0].balance == open_long_event_2.bond_amount
Expand Down
9 changes: 4 additions & 5 deletions src/agent0/core/hyperdrive/interactive/i_local_hyperdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from fixedpointmath import FixedPoint
from IPython.display import IFrame
from web3._utils.threads import Timeout
from web3.constants import ADDRESS_ZERO
from web3.exceptions import TimeExhausted

from agent0.chainsync import PostgresConfig
Expand Down Expand Up @@ -470,15 +469,15 @@ def _deploy_hyperdrive(self, config: Config, chain: ILocalChain) -> DeployedHype

pool_deploy_config = PoolDeployConfig(
baseToken="", # will be determined in the deploy function
linkerFactory=ADDRESS_ZERO, # address(0)
linkerCodeHash=bytes(32), # bytes32(0)
linkerFactory="", # will be determined in the deploy function
linkerCodeHash=bytes(), # will be determined in the deploy function
minimumShareReserves=config.minimum_share_reserves.scaled_value,
minimumTransactionAmount=config.minimum_transaction_amount.scaled_value,
positionDuration=config.position_duration,
checkpointDuration=config.checkpoint_duration,
timeStretch=0,
governance=ADDRESS_ZERO, # address(0)
feeCollector=ADDRESS_ZERO, # address(0)
governance="", # will be determined in the deploy function
feeCollector="", # will be determined in the deploy function
fees=config._fees, # pylint: disable=protected-access
)

Expand Down
2 changes: 1 addition & 1 deletion src/agent0/core/tests/predict_trade_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_predict_open_long_bonds(chain: ILocalChain):
logging.info(f"discrepancy (%) for bonds is {bonds_discrepancy:e}")
logging.info(f"discrepancy (%) for shares is {shares_discrepancy:e}")

assert abs(bonds_discrepancy) < 1e-7
assert abs(bonds_discrepancy) < 1e-4
assert abs(shares_discrepancy) < 1e-7


Expand Down
4 changes: 2 additions & 2 deletions src/agent0/ethpy/base/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ def smart_contract_preview_transaction(
f"\n{return_names_and_types=}\n{return_values=}"
)
function_return_dict = {}
for var_name_and_type, var_value in zip(return_names_and_types, return_values):
for i, (var_name_and_type, var_value) in enumerate(zip(return_names_and_types, return_values)):
var_name = var_name_and_type[0]
if var_name:
function_return_dict[var_name] = var_value
else:
function_return_dict["value"] = var_value
function_return_dict[f"value{i}"] = var_value
return function_return_dict
return {f"value{idx}": value for idx, value in enumerate(return_values)}

Expand Down
15 changes: 11 additions & 4 deletions src/agent0/ethpy/hyperdrive/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ def deploy_hyperdrive_from_factory(
factory_deploy_config.feeCollector = deploy_account_addr

# Deploy the factory and base token contracts
factory_contract, deployer_contract = _deploy_hyperdrive_factory(
factory_contract, deployer_contract, factory_deploy_config = _deploy_hyperdrive_factory(
web3,
deploy_account,
factory_deploy_config,
)

base_token_contract, vault_contract = _deploy_base_and_vault(web3, deploy_account, initial_variable_rate)

# Update pool deploy config with factory settings
pool_deploy_config.baseToken = base_token_contract.address
pool_deploy_config.governance = deploy_account_addr
pool_deploy_config.feeCollector = deploy_account_addr
pool_deploy_config.linkerFactory = factory_deploy_config.linkerFactory
pool_deploy_config.linkerCodeHash = factory_deploy_config.linkerCodeHash

# Mint base and approve the initial liquidity amount for the hyperdrive factory
_mint_and_approve(
Expand Down Expand Up @@ -199,7 +204,7 @@ def _deploy_hyperdrive_factory(
web3: Web3,
deploy_account: LocalAccount,
factory_deploy_config: FactoryConfig,
) -> tuple[HyperdriveFactoryContract, ERC4626HyperdriveDeployerCoordinatorContract]:
) -> tuple[HyperdriveFactoryContract, ERC4626HyperdriveDeployerCoordinatorContract, FactoryConfig]:
"""Deploys the hyperdrive factory contract on the rpc_uri chain.
Arguments
Expand All @@ -217,8 +222,10 @@ def _deploy_hyperdrive_factory(
tuple[
HyperdriveFactoryContract,
ERC4626HyperdriveDeployerCoordinatorContract,
FactoryConfig,
]
Containing the deployed factory and the deploy coordinator contracts.
Containing the deployed factory, the deploy coordinator contracts, and the updated
factory config
"""
deploy_account_addr = Web3.to_checksum_address(deploy_account.address)
# Deploy forwarder factory
Expand Down Expand Up @@ -261,7 +268,7 @@ def _deploy_hyperdrive_factory(
*function_args,
)
assert receipt["status"] == 1, f"Failed adding the Hyperdrive deployer to the factory.\n{receipt=}"
return factory_contract, deployer_contract
return factory_contract, deployer_contract, factory_deploy_config


def _deploy_base_and_vault(
Expand Down
15 changes: 10 additions & 5 deletions src/agent0/ethpy/hyperdrive/interface/_contract_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ async def _async_open_long(
read_retry_count=interface.read_retry_count,
)
if slippage_tolerance is not None:
# ABI doesn't have output names. Return result is [maturityTime, bondProceeds]
min_output = (
FixedPoint(scaled_value=preview_result["bondProceeds"]) * (FixedPoint(1) - slippage_tolerance)
FixedPoint(scaled_value=preview_result["value1"]) * (FixedPoint(1) - slippage_tolerance)
).scaled_value
fn_args = (
trade_amount.scaled_value,
Expand Down Expand Up @@ -263,7 +264,7 @@ async def _async_close_long(
)
if slippage_tolerance is not None:
min_output = (
FixedPoint(scaled_value=preview_result["value"]) * (FixedPoint(1) - slippage_tolerance)
FixedPoint(scaled_value=preview_result["value0"]) * (FixedPoint(1) - slippage_tolerance)
).scaled_value
fn_args = (
maturity_time,
Expand Down Expand Up @@ -335,8 +336,9 @@ async def _async_open_short(
read_retry_count=interface.read_retry_count,
)
if slippage_tolerance is not None:
# ABI doesn't have output names. Return result is [maturityTime, traderDeposit]
max_deposit = (
FixedPoint(scaled_value=preview_result["traderDeposit"]) * (FixedPoint(1) + slippage_tolerance)
FixedPoint(scaled_value=preview_result["value1"]) * (FixedPoint(1) + slippage_tolerance)
).scaled_value
fn_args = (
trade_amount.scaled_value,
Expand Down Expand Up @@ -405,7 +407,7 @@ async def _async_close_short(
)
if slippage_tolerance is not None:
min_output = (
FixedPoint(scaled_value=preview_result["value"]) * (FixedPoint(1) - slippage_tolerance)
FixedPoint(scaled_value=preview_result["value0"]) * (FixedPoint(1) - slippage_tolerance)
).scaled_value
fn_args = (
maturity_time,
Expand Down Expand Up @@ -581,7 +583,10 @@ async def _async_redeem_withdraw_shares(
# Here, a preview call of redeem withdrawal shares will still be successful without logs if
# the amount of shares to redeem is larger than what's in the wallet. We want to catch this error
# here with a useful error message, so we check that explicitly here
if preview_result["withdrawalSharesRedeemed"] == 0 and trade_amount > 0:

# withdrawalSharesRedeemed is the second return value of the call
# The abi doesn't contain the name of the returned variable
if preview_result["value1"] == 0 and trade_amount > 0:
raise ValueError("Preview call for redeem withdrawal shares returned 0 for non-zero input trade amount")

try:
Expand Down
9 changes: 4 additions & 5 deletions src/agent0/ethpy/test_fixtures/deployed_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pytest
from fixedpointmath import FixedPoint
from web3.constants import ADDRESS_ZERO
from web3.types import RPCEndpoint

from agent0.ethpy.base import initialize_web3_with_http_provider
Expand Down Expand Up @@ -171,15 +170,15 @@ def launch_local_hyperdrive_pool(

pool_deploy_config = PoolDeployConfig(
baseToken="", # will be determined in the deploy function
linkerFactory=ADDRESS_ZERO, # address(0), this address needs to be in a valid address format
linkerCodeHash=bytes(32), # bytes32(0)
linkerFactory="", # will be determined in the deploy function
linkerCodeHash=bytes(), # will be determined in the deploy function
minimumShareReserves=minimum_share_reserves.scaled_value,
minimumTransactionAmount=minimum_transaction_amount.scaled_value,
positionDuration=position_duration,
checkpointDuration=checkpoint_duration,
timeStretch=0,
governance=ADDRESS_ZERO, # address(0)
feeCollector=ADDRESS_ZERO, # address(0)
governance="", # will be determined in the deploy function
feeCollector="", # will be determined in the deploy function
fees=fees,
)
return deploy_hyperdrive_from_factory(
Expand Down
Loading

0 comments on commit 47cc0ff

Please sign in to comment.