diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cc7305..b82e384 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml @@ -10,7 +10,7 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black name: black @@ -21,7 +21,7 @@ repos: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.6.1 hooks: - id: mypy additional_dependencies: [types-setuptools, pydantic] diff --git a/ape_polygon/__init__.py b/ape_polygon/__init__.py index f381155..b010db5 100644 --- a/ape_polygon/__init__.py +++ b/ape_polygon/__init__.py @@ -1,6 +1,5 @@ from ape import plugins -from ape.api import NetworkAPI, create_network_type -from ape.api.networks import LOCAL_NETWORK_NAME +from ape.api.networks import LOCAL_NETWORK_NAME, ForkedNetworkAPI, NetworkAPI, create_network_type from ape_geth import GethProvider from ape_test import LocalProvider @@ -21,7 +20,7 @@ def ecosystems(): def networks(): for network_name, network_params in NETWORKS.items(): yield "polygon", network_name, create_network_type(*network_params) - yield "polygon", f"{network_name}-fork", NetworkAPI + yield "polygon", f"{network_name}-fork", ForkedNetworkAPI # NOTE: This works for development providers, as they get chain_id from themselves yield "polygon", LOCAL_NETWORK_NAME, NetworkAPI diff --git a/ape_polygon/ecosystem.py b/ape_polygon/ecosystem.py index b347681..522c973 100644 --- a/ape_polygon/ecosystem.py +++ b/ape_polygon/ecosystem.py @@ -1,9 +1,9 @@ -from typing import cast +from typing import Type, cast from ape.api.config import PluginConfig from ape.api.networks import LOCAL_NETWORK_NAME from ape.utils import DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT -from ape_ethereum.ecosystem import Ethereum, NetworkConfig +from ape_ethereum.ecosystem import Ethereum, ForkedNetworkConfig, NetworkConfig NETWORKS = { # chain_id, network_id @@ -12,30 +12,32 @@ } -def _create_network_config( - required_confirmations: int = 1, block_time: int = 2, **kwargs +def _create_config( + required_confirmations: int = 1, + block_time: int = 2, + cls: Type[NetworkConfig] = NetworkConfig, + **kwargs, ) -> NetworkConfig: - return NetworkConfig( - required_confirmations=required_confirmations, block_time=block_time, **kwargs - ) + return cls(required_confirmations=required_confirmations, block_time=block_time, **kwargs) -def _create_local_config(**kwargs) -> NetworkConfig: - return _create_network_config( +def _create_local_config(**kwargs): + return _create_config( block_time=0, default_provider=kwargs.pop("default_provider", None), gas_limit="max", required_confirmations=0, transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, + cls=ForkedNetworkConfig if kwargs.pop("use_fork", False) else NetworkConfig, **kwargs, ) class PolygonConfig(PluginConfig): - mainnet: NetworkConfig = _create_network_config() - mainnet_fork: NetworkConfig = _create_local_config() - mumbai: NetworkConfig = _create_network_config() - mumbai_fork: NetworkConfig = _create_local_config() + mainnet: NetworkConfig = _create_config() + mainnet_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) + mumbai: NetworkConfig = _create_config() + mumbai_fork: ForkedNetworkConfig = _create_local_config(use_fork=True) local: NetworkConfig = _create_local_config(default_provider="test") default_network: str = LOCAL_NETWORK_NAME diff --git a/setup.py b/setup.py index 6a694f4..2fbdf6f 100644 --- a/setup.py +++ b/setup.py @@ -10,8 +10,8 @@ "hypothesis>=6.2.0,<7", # Strategy-based fuzzer ], "lint": [ - "black>=23.9.1,<24", # Auto-formatter and linter - "mypy>=1.5.1,<2", # Static type analyzer + "black>=23.10.1,<24", # Auto-formatter and linter + "mypy>=1.6.1,<2", # Static type analyzer "types-setuptools", # Needed due to mypy typeshed "flake8>=6.1.0,<7", # Style linter "isort>=5.10.1,<6", # Import sorting linter