Skip to content

Commit

Permalink
update to hyperdrive 5 (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton authored Jan 17, 2024
1 parent 64747c1 commit 18054c9
Show file tree
Hide file tree
Showing 43 changed files with 3,513 additions and 140 deletions.
19 changes: 13 additions & 6 deletions lib/ethpy/ethpy/hyperdrive/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from hypertypes.types import (
ERC20MintableContract,
ERC4626HyperdriveCoreDeployerContract,
ERC4626HyperdriveDeployerContract,
ERC4626HyperdriveDeployerCoordinatorContract,
ERC4626Target0DeployerContract,
ERC4626Target1DeployerContract,
ERC4626Target2DeployerContract,
Expand Down Expand Up @@ -194,7 +194,9 @@ def _deploy_hyperdrive_factory(
initial_variable_rate: FixedPoint,
pool_deploy_config: PoolDeployConfig,
max_fees: Fees,
) -> tuple[ERC20MintableContract, HyperdriveFactoryContract, MockERC4626Contract, ERC4626HyperdriveDeployerContract]:
) -> tuple[
ERC20MintableContract, HyperdriveFactoryContract, MockERC4626Contract, ERC4626HyperdriveDeployerCoordinatorContract
]:
"""Deploys the hyperdrive factory contract on the rpc_uri chain.
Arguments
Expand All @@ -213,7 +215,12 @@ def _deploy_hyperdrive_factory(
Returns
-------
tuple[ERC20MintableContract, HyperdriveFactoryContract, MockERC4626Contract, ERC4626HyperdriveDeployerContract]
tuple[
ERC20MintableContract,
HyperdriveFactoryContract,
MockERC4626Contract,
ERC4626HyperdriveDeployerCoordinatorContract,
]
Containing the deployed base token, factory, the pool, and the deploy contracts.
"""
base_token_contract = ERC20MintableContract.deploy(
Expand Down Expand Up @@ -263,11 +270,11 @@ def _deploy_hyperdrive_factory(
w3=web3,
account=deploy_account_addr,
)
deployer_contract = ERC4626HyperdriveDeployerContract.deploy(
deployer_contract = ERC4626HyperdriveDeployerCoordinatorContract.deploy(
w3=web3,
account=deploy_account_addr,
constructorArgs=ERC4626HyperdriveDeployerContract.ConstructorArgs(
hyperdriveCoreDeployer=core_deployer_contract.address,
constructorArgs=ERC4626HyperdriveDeployerCoordinatorContract.ConstructorArgs(
coreDeployer=core_deployer_contract.address,
target0Deployer=target0_contract.address,
target1Deployer=target1_contract.address,
target2Deployer=target2_contract.address,
Expand Down
11 changes: 10 additions & 1 deletion lib/ethpy/ethpy/hyperdrive/interface/_mock_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _calc_bonds_given_shares_and_rate(
target_shares = _calc_effective_share_reserves(pool_state)
return FixedPoint(
scaled_value=int(
hyperdrivepy.calculate_bonds_given_shares_and_rate(
hyperdrivepy.calculate_initial_bond_reserves(
str(target_shares.scaled_value),
str(pool_state.pool_config.initial_share_price.scaled_value),
str(target_rate.scaled_value),
Expand Down Expand Up @@ -288,3 +288,12 @@ def _calc_present_value(pool_state: PoolState, current_block_timestamp: int) ->
)
)
)


def _calc_time_stretch(target_rate: FixedPoint, target_position_duration: FixedPoint) -> FixedPoint:
"""See API for documentation."""
return FixedPoint(
scaled_value=int(
hyperdrivepy.get_time_stretch(str(target_rate.scaled_value), str(int(target_position_duration)))
)
)
18 changes: 18 additions & 0 deletions lib/ethpy/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
_calc_shares_in_given_bonds_out_up,
_calc_shares_out_given_bonds_in_down,
_calc_spot_price,
_calc_time_stretch,
)

# We expect to have many instance attributes & public methods since this is a large API.
Expand Down Expand Up @@ -649,6 +650,23 @@ def calc_position_duration_in_years(self, pool_state: PoolState | None = None) -
pool_state = self.current_pool_state
return _calc_position_duration_in_years(pool_state)

def calc_time_stretch(self, target_rate: FixedPoint, target_position_duration: FixedPoint) -> FixedPoint:
"""Returns the time stretch parameter given a target fixed rate and position duration.
Arguments
---------
target_rate: FixedPoint
The fixed rate that the Hyperdrive pool will be initialized with.
target_position_duration: FixedPoint
The position duration that the Hyperdrive pool will be initialized with.
Returns
-------
FixedPoint
The time stretch constant.
"""
return _calc_time_stretch(target_rate, target_position_duration)

def calc_checkpoint_id(
self, checkpoint_duration: int | None = None, block_timestamp: Timestamp | None = None
) -> Timestamp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_deployed_values(self, hyperdrive_read_interface: HyperdriveReadInterfac
expected_pool_info_keys = {
"share_reserves",
"bond_reserves",
"zombie_base_proceeds",
"zombie_share_reserves",
"lp_total_supply",
"share_price",
Expand Down
1 change: 1 addition & 0 deletions lib/hypertypes/hypertypes/fixedpoint_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PoolInfoFP:

share_reserves: FixedPoint
share_adjustment: FixedPoint
zombie_base_proceeds: FixedPoint
zombie_share_reserves: FixedPoint
bond_reserves: FixedPoint
lp_total_supply: FixedPoint
Expand Down
Loading

0 comments on commit 18054c9

Please sign in to comment.