Skip to content

Commit cede174

Browse files
author
Roman Shterenzon
authored
feat: estimate gas using RPC (#190)
This will allow using it on Arbitrum (see #177).
1 parent 3cf179b commit cede174

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

uniswap/uniswap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ def _build_and_send_tx(
10851085
if not tx_params:
10861086
tx_params = self._get_tx_params()
10871087
transaction = function.buildTransaction(tx_params)
1088+
# Uniswap3 uses 20% margin for transactions
1089+
transaction["gas"] = Wei(int(self.w3.eth.estimate_gas(transaction) * 1.2))
10881090
signed_txn = self.w3.eth.account.sign_transaction(
10891091
transaction, private_key=self.private_key
10901092
)
@@ -1096,12 +1098,11 @@ def _build_and_send_tx(
10961098
logger.debug(f"nonce: {tx_params['nonce']}")
10971099
self.last_nonce = Nonce(tx_params["nonce"] + 1)
10981100

1099-
def _get_tx_params(self, value: Wei = Wei(0), gas: Wei = Wei(250000)) -> TxParams:
1101+
def _get_tx_params(self, value: Wei = Wei(0)) -> TxParams:
11001102
"""Get generic transaction parameters."""
11011103
return {
11021104
"from": _addr_to_str(self.address),
11031105
"value": value,
1104-
"gas": gas,
11051106
"nonce": max(
11061107
self.last_nonce, self.w3.eth.get_transaction_count(self.address)
11071108
),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy