Skip to content

Commit

Permalink
Merge pull request #1250 from eth-brownie/feat/replace-type-2
Browse files Browse the repository at this point in the history
Support EIP1559 in `TransactionReceipt.replace`
  • Loading branch information
iamdefinitelyahuman authored Sep 11, 2021
2 parents f91e3ce + 4f30952 commit 1e2741c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 19 additions & 5 deletions brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ def replace(
---------
increment : float, optional
Multiplier applied to the gas price of this transaction in order
to determine the new gas price
to determine the new gas price. For EIP1559 transactions the multiplier
is applied to the max_fee, the priority_fee is incremented by 1.1.
gas_price : Wei, optional
Absolute gas price to use in the replacement transaction
Absolute gas price to use in the replacement transaction. For EIP1559
transactions this is the new max_fee, the priority_fee is incremented
by 1.1.
silent : bool, optional
Toggle console verbosity (default is same setting as this transaction)
Expand All @@ -332,6 +335,14 @@ def replace(

if increment is not None:
gas_price = Wei(self.gas_price * increment)
else:
gas_price = Wei(gas_price)

max_fee, priority_fee = None, None
if self.max_fee is not None and self.priority_fee is not None:
max_fee = gas_price
priority_fee = Wei(self.priority_fee * 1.1)
gas_price = None

if silent is None:
silent = self._silent
Expand All @@ -351,7 +362,9 @@ def replace(
self.receiver,
self.value,
gas_limit=self.gas_limit,
gas_price=Wei(gas_price),
gas_price=gas_price,
max_fee=max_fee,
priority_fee=priority_fee,
data=self.input,
nonce=self.nonce,
required_confs=0,
Expand Down Expand Up @@ -556,8 +569,9 @@ def _set_from_tx(self, tx: Dict) -> None:
self.sender = EthAddress(tx["from"])
self.receiver = EthAddress(tx["to"]) if tx["to"] else None
self.value = Wei(tx["value"])
if "gasPrice" in tx:
self.gas_price = tx["gasPrice"]
self.gas_price = tx["gasPrice"]
self.max_fee = tx.get("maxFeePerGas")
self.priority_fee = tx.get("maxPriorityFeePerGas")
self.gas_limit = tx["gas"]
self.input = tx["input"]
self.nonce = tx["nonce"]
Expand Down
2 changes: 2 additions & 0 deletions docs/api-network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,8 @@ TransactionReceipt Methods
* ``increment``: Multiplier applied to the gas price of the current transaction in order to determine a new gas price
* ``gas_price``: Absolute gas price to use in the replacement transaction
For EIP-1559 transactions, the modification is applied to ``max_fee``. The ``priority_fee`` is always multiplied by 1.1 (the minimum increase required to be accepted by a node).
Returns a :func:`TransactionReceipt <brownie.network.transaction.TransactionReceipt>` object.
.. code-block:: python
Expand Down

0 comments on commit 1e2741c

Please sign in to comment.