From ceb032e75620725c93e9d5a288feb671ee3312eb Mon Sep 17 00:00:00 2001 From: Volod <141863857+volod-vana@users.noreply.github.com> Date: Sun, 22 Dec 2024 23:36:34 -0500 Subject: [PATCH] Switch to EIP-1559 style transactions (#58) --- pyproject.toml | 2 +- vana/__init__.py | 2 +- vana/utils/transaction.py | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 74acf42..901ba98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vana" -version = "0.40.0" +version = "0.41.0" description = "" authors = ["Tim Nunamaker ", "Volodymyr Isai ", "Kahtaf Alam "] readme = "README.md" diff --git a/vana/__init__.py b/vana/__init__.py index f8299ef..dbf6b39 100644 --- a/vana/__init__.py +++ b/vana/__init__.py @@ -15,7 +15,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__version__ = "0.40.0" +__version__ = "0.41.0" import rich diff --git a/vana/utils/transaction.py b/vana/utils/transaction.py index 6f0083b..1507fb7 100644 --- a/vana/utils/transaction.py +++ b/vana/utils/transaction.py @@ -144,19 +144,23 @@ def send_transaction( }) gas_limit = int(gas_estimate * 2) - # Calculate gas price - use base price for first attempt - base_gas_price = self.web3.eth.gas_price + # Calculate gas prices for EIP-1559 + base_fee = self.web3.eth.get_block('latest')['baseFeePerGas'] gas_multiplier = base_gas_multiplier * (1.5 ** retry_count) - gas_price = int(base_gas_price * gas_multiplier) + priority_fee = self.web3.eth.max_priority_fee + max_fee_per_gas = int(base_fee * gas_multiplier) + priority_fee + max_priority_fee_per_gas = priority_fee # Build transaction tx = function.build_transaction({ 'from': account.address, 'value': value, 'gas': gas_limit, - 'gasPrice': gas_price, + 'maxFeePerGas': max_fee_per_gas, + 'maxPriorityFeePerGas': max_priority_fee_per_gas, 'nonce': nonce, - 'chainId': self.chain_id + 'chainId': self.chain_id, + 'type': 2 }) try: @@ -167,7 +171,9 @@ def send_transaction( 'data': tx['data'], 'value': tx['value'], 'gas': tx['gas'], - 'gasPrice': tx['gasPrice'], + 'maxFeePerGas': tx['maxFeePerGas'], + 'maxPriorityFeePerGas': tx['maxPriorityFeePerGas'], + 'type': 2 }) except ContractLogicError as e: vana.logging.error(f"Transaction would revert: {str(e)}") @@ -177,7 +183,7 @@ def send_transaction( vana.logging.info( f"Sending transaction with nonce {nonce}, " - f"gas price {gas_price} ({gas_multiplier:.1f}x base) " + f"gas limit {gas_limit}, gas price {max_fee_per_gas} ({max_priority_fee_per_gas})" f"(retry {retry_count})" )