Skip to content

Commit

Permalink
Use pypechain package (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal authored Oct 12, 2023
1 parent 02621eb commit 46ee1d7
Show file tree
Hide file tree
Showing 39 changed files with 1,245 additions and 17,013 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Our current supported packages are:
- chainsync ([README](https://github.com/delvtech/elf-simulations/tree/main/lib/chainsync/README.md))
- elfpy ([README](https://github.com/delvtech/elf-simulations/tree/main/lib/elfpy/README.md))
- ethpy ([README](https://github.com/delvtech/elf-simulations/tree/main/lib/ethpy/README.md))
- pypechain ([README](https://github.com/delvtech/elf-simulations/tree/main/lib/pypechain/README.md))

## Install

Expand Down Expand Up @@ -75,11 +74,13 @@ In that example, the internal representation is `8`, so casting it to a float wo

To understand more, we recommend that you study the fixed point tests and source implementation in `elfpy/math/`.

Warning! Using floating point as a constructor to FixedPoint can cause loss of precision. For example,
Warning! Using floating point as a constructor to FixedPoint can cause loss of precision. For example,

```
>>> FixedPoint(1e18)
FixedPoint("1000000000000000042.420637374017961984")
```

Allowing floating point in the constructor of FixedPoint will be removed in a future version of `fixedpointmath`.

## Modifying configuration for agent deployment
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tomli

# list all packages
packages = ["agent0", "chainsync", "elfpy", "ethpy", "pypechain"]
packages = ["agent0", "chainsync", "elfpy", "ethpy"]

# indicate where the elfpy Python package lives
package_root = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
Expand Down
2 changes: 1 addition & 1 deletion lib/ethpy/ethpy/hyperdrive/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _deploy_hyperdrive_factory(
deploy_account_addr, # governance
deploy_account_addr, # hyperdriveGovernance
deploy_account_addr, # feeCollector
_dataclass_to_tuple(pool_config.Fees), # curve, flat, governance
_dataclass_to_tuple(pool_config.fees), # curve, flat, governance
_dataclass_to_tuple(max_fees), # max_curve, max_flat, max_governance
[], # defaultPausers (new address[](1))
),
Expand Down
4 changes: 3 additions & 1 deletion lib/hypertypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Generate the requisite Python files by running:

```bash
sh scripts/build_type_files.sh path/to/ABIs num_chars_per_line
sh pypechain path/to/ABIs --output_dir path/to/temp_dir
```

and then moving the generated files to lib/hypertypes/hypertypes

You can then pip install the package from the project root with

```bash
Expand Down
8 changes: 4 additions & 4 deletions lib/hypertypes/hypertypes/ERC20MintableContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class ERC20MintableBurnContractFunction(ContractFunction):

def __call__(self, amount: int, destination: str | None = None) -> "ERC20MintableBurnContractFunction":
if all([destination is None]):
super().__call__(amount)
super().__call__()
return self

else:
super().__call__(destination, amount)
super().__call__()
return self

# TODO: add call def so we can get return types for the calls
Expand Down Expand Up @@ -127,11 +127,11 @@ class ERC20MintableMintContractFunction(ContractFunction):

def __call__(self, amount: int, destination: str | None = None) -> "ERC20MintableMintContractFunction":
if all([destination is not None]):
super().__call__(destination, amount)
super().__call__()
return self

else:
super().__call__(amount)
super().__call__()
return self

# TODO: add call def so we can get return types for the calls
Expand Down
2 changes: 2 additions & 0 deletions lib/hypertypes/hypertypes/ERC20MintableTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# pylint: disable=no-else-return
from __future__ import annotations


from web3.types import ABIEvent

from web3.types import ABIEventParams


Approval = ABIEvent(
anonymous=False,
inputs=[
Expand Down
4 changes: 3 additions & 1 deletion lib/hypertypes/hypertypes/ERC4626DataProviderContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ class ERC4626DataProviderGetUncollectedGovernanceFeesContractFunction(ContractFu
# super() call methods are generic, while our version adds values & types
# pylint: disable=arguments-differ

def __call__(self) -> "ERC4626DataProviderGetUncollectedGovernanceFeesContractFunction":
def __call__(
self,
) -> "ERC4626DataProviderGetUncollectedGovernanceFeesContractFunction":
super().__call__()
return self

Expand Down
51 changes: 26 additions & 25 deletions lib/hypertypes/hypertypes/ERC4626DataProviderTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,8 @@
# pylint: disable=no-else-return
from __future__ import annotations

from dataclasses import dataclass


@dataclass
class Checkpoint:
"""Checkpoint struct."""

sharePrice: int
longExposure: int


@dataclass
class MarketState:
"""MarketState struct."""

shareReserves: int
bondReserves: int
shareAdjustment: int
longExposure: int
longsOutstanding: int
shortsOutstanding: int
longAverageMaturityTime: int
shortAverageMaturityTime: int
isInitialized: bool
isPaused: bool
from dataclasses import dataclass


@dataclass
Expand All @@ -62,11 +39,35 @@ class PoolConfig:
timeStretch: int
governance: str
feeCollector: str
Fees: Fees
fees: Fees
oracleSize: int
updateGap: int


@dataclass
class Checkpoint:
"""Checkpoint struct."""

sharePrice: int
longExposure: int


@dataclass
class MarketState:
"""MarketState struct."""

shareReserves: int
bondReserves: int
shareAdjustment: int
longExposure: int
longsOutstanding: int
shortsOutstanding: int
longAverageMaturityTime: int
shortAverageMaturityTime: int
isInitialized: bool
isPaused: bool


@dataclass
class PoolInfo:
"""PoolInfo struct."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ class ERC4626HyperdriveDeployerDeployContractFunction(ContractFunction):
# pylint: disable=arguments-differ

def __call__(
self, PoolConfig: tuple, _dataProvider: str, _linkerCodeHash: bytes, _linkerFactory: str, _extraData: bytes
self,
_config: tuple,
_dataProvider: str,
_linkerCodeHash: bytes,
_linkerFactory: str,
_extraData: list[bytes],
) -> "ERC4626HyperdriveDeployerDeployContractFunction":
super().__call__(PoolConfig, _dataProvider, _linkerCodeHash, _linkerFactory, _extraData)
super().__call__(_config, _dataProvider, _linkerCodeHash, _linkerFactory, _extraData)
return self

# TODO: add call def so we can get return types for the calls
Expand Down
3 changes: 2 additions & 1 deletion lib/hypertypes/hypertypes/ERC4626HyperdriveDeployerTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# pylint: disable=no-else-return
from __future__ import annotations


from dataclasses import dataclass


Expand All @@ -38,6 +39,6 @@ class PoolConfig:
timeStretch: int
governance: str
feeCollector: str
Fees: Fees
fees: Fees
oracleSize: int
updateGap: int
Loading

1 comment on commit 46ee1d7

@vercel
Copy link

@vercel vercel bot commented on 46ee1d7 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.