Skip to content

Commit

Permalink
Switch to EIP-1559 style transactions (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
volod-vana authored Dec 23, 2024
1 parent d2f1c95 commit ceb032e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vana"
version = "0.40.0"
version = "0.41.0"
description = ""
authors = ["Tim Nunamaker <[email protected]>", "Volodymyr Isai <[email protected]>", "Kahtaf Alam <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion vana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 13 additions & 7 deletions vana/utils/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)}")
Expand All @@ -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})"
)

Expand Down

0 comments on commit ceb032e

Please sign in to comment.