Skip to content

Commit

Permalink
feat: network base fee multiplier is now configurable [APE-1273] (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 1, 2023
1 parent b5f46f7 commit 17656f0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/ape/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/ape/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
26 changes: 18 additions & 8 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 17656f0

Please sign in to comment.