diff --git a/src/ape/api/networks.py b/src/ape/api/networks.py index bb45a69b89..4d76b28b55 100644 --- a/src/ape/api/networks.py +++ b/src/ape/api/networks.py @@ -717,6 +717,13 @@ def auto_gas_multiplier(self) -> float: """ return self.gas_limit.multiplier if isinstance(self.gas_limit, AutoGasLimit) else 1.0 + @property + def base_fee_multiplier(self) -> float: + """ + A multiplier to apply to a transaction base fee. + """ + return self._network_config.get("base_fee_multiplier", 1.0) + @property def chain_id(self) -> int: """ diff --git a/src/ape/api/providers.py b/src/ape/api/providers.py index 400c3ab209..6c24b8cf76 100644 --- a/src/ape/api/providers.py +++ b/src/ape/api/providers.py @@ -1411,7 +1411,8 @@ def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI: txn.max_priority_fee = self.priority_fee if txn.max_fee is None: - txn.max_fee = self.base_fee * 2 + txn.max_priority_fee + multiplier = self.network.base_fee_multiplier + txn.max_fee = int(self.base_fee * multiplier + txn.max_priority_fee) # else: Assume user specified the correct amount or txn will fail and waste gas if txn.gas_limit is None: diff --git a/src/ape/utils/__init__.py b/src/ape/utils/__init__.py index 3ca3146d10..84bff51e82 100644 --- a/src/ape/utils/__init__.py +++ b/src/ape/utils/__init__.py @@ -18,6 +18,7 @@ ) from ape.utils.github import GithubClient, github_client from ape.utils.misc import ( + DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER, DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, EMPTY_BYTES32, @@ -64,6 +65,7 @@ "BaseInterface", "BaseInterfaceModel", "cached_property", + "DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER", "DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT", "DEFAULT_NUMBER_OF_TEST_ACCOUNTS", "DEFAULT_TEST_CHAIN_ID", diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index b0724e5261..fefa6fff94 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -24,6 +24,7 @@ ZERO_ADDRESS: AddressType = cast(AddressType, "0x0000000000000000000000000000000000000000") DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT = 120 DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT = 20 +DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER = 1.4 DEFAULT_MAX_RETRIES_TX = 20 _python_version = ( diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index abf2307da9..9ca170741e 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -39,6 +39,7 @@ TransactionSignature, ) from ape.utils import ( + DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER, DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, EMPTY_BYTES32, @@ -103,6 +104,9 @@ class NetworkConfig(PluginConfig): The default for local networks is ``"max"``, otherwise ``"auto"``. """ + base_fee_multiplier: float = 1.0 + """A multiplier to apply to a transaction base fee.""" + class Config: smart_union = True @@ -131,16 +135,25 @@ def validate_gas_limit(cls, value): def _create_local_config(default_provider: Optional[str] = None, **kwargs) -> NetworkConfig: return _create_config( - required_confirmations=0, + base_fee_multiplier=1.0, default_provider=default_provider, - transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, gas_limit="max", + required_confirmations=0, + transaction_acceptance_timeout=DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, **kwargs, ) -def _create_config(required_confirmations: int = 2, **kwargs) -> NetworkConfig: - return NetworkConfig(required_confirmations=required_confirmations, **kwargs) +def _create_config( + required_confirmations: int = 2, + base_fee_multiplier: float = DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER, + **kwargs, +) -> NetworkConfig: + return NetworkConfig( + base_fee_multiplier=base_fee_multiplier, + required_confirmations=required_confirmations, + **kwargs, + ) class EthereumConfig(PluginConfig): @@ -183,10 +196,7 @@ class Block(BlockAPI): pre=True, ) def validate_ints(cls, value): - if not value: - return 0 - - return to_int(value) + return to_int(value) if value else 0 class Ethereum(EcosystemAPI): diff --git a/tests/functional/test_networks.py b/tests/functional/test_networks.py index 2fe78ff771..f527bd45fd 100644 --- a/tests/functional/test_networks.py +++ b/tests/functional/test_networks.py @@ -238,3 +238,8 @@ def test_gas_limits(networks, config, project_with_source_files_contract): _ = project_with_source_files_contract # Ensure use of project with default config assert networks.ethereum.goerli.gas_limit == "auto" assert networks.ethereum.local.gas_limit == "max" + + +def test_base_fee_multiplier(networks): + assert networks.ethereum.mainnet.base_fee_multiplier == 1.4 + assert networks.ethereum.local.base_fee_multiplier == 1.0