Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cede174

Browse filesBrowse 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
Copy full SHA for cede174

File tree

Expand file treeCollapse file tree

1 file changed

+3
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-2
lines changed

‎uniswap/uniswap.py

Copy file name to clipboardExpand all lines: uniswap/uniswap.py
+3-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.