Skip to content

Commit 29b5474

Browse files
committed
Fix max fees and return error on gas estimation failure
1 parent 08427f5 commit 29b5474

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

bundler/bundler.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def deployModuleManager(salt) -> bool:
120120
})
121121
else:
122122
txnDict.update({
123-
'maxFeePerGas': math.ceil(float(gasFees["medium"]["suggestedMaxFeePerGas"])),
124-
'maxPriorityFeePerGas': math.ceil(float(gasFees["medium"]["suggestedMaxPriorityFeePerGas"]))
123+
'maxFeePerGas': w3.toWei(gasFees["medium"]["suggestedMaxFeePerGas"], 'gwei'),
124+
'maxPriorityFeePerGas': w3.toWei(gasFees["medium"]["suggestedMaxPriorityFeePerGas"], 'gwei'),
125125
})
126126

127127
transaction = transactionTemplate.build_transaction(txnDict)
@@ -170,14 +170,18 @@ def eth_sendUserOperation(request) -> Result:
170170
transactionTemplate = entryPoint.functions.handleOps([dict(op) for op in bundleDict],
171171
address)
172172

173-
gasEstimation = transactionTemplate.estimate_gas()
173+
try:
174+
gasEstimation = transactionTemplate.estimate_gas()
175+
except Exception as inst:
176+
print('\033[91m' + "Bundle operation failed (Gas estimation reverted): " + str(inst) + '\033[39m')
177+
return Error(2, "Bundle operation failed", data=str(inst))
174178
gasFees = getGasFees()
175179

176180
txnDict = {
177181
"chainId": 5,
178182
"from": env('bundler_pub'),
179183
"nonce": w3.eth.get_transaction_count(env('bundler_pub')),
180-
'gas': math.ceil(gasEstimation * 1.2),
184+
'gas': math.ceil(gasEstimation * 1.4),
181185
}
182186

183187
if(env('isGanache') == "True"): #as ganache evm doesn't support maxFeePerGas & maxPriorityFeePerGas
@@ -186,8 +190,8 @@ def eth_sendUserOperation(request) -> Result:
186190
})
187191
else:
188192
txnDict.update({
189-
'maxFeePerGas': math.ceil(float(gasFees["medium"]["suggestedMaxFeePerGas"])),
190-
'maxPriorityFeePerGas': math.ceil(float(gasFees["medium"]["suggestedMaxPriorityFeePerGas"]))
193+
'maxFeePerGas': w3.toWei(gasFees["medium"]["suggestedMaxFeePerGas"], 'gwei'),
194+
'maxPriorityFeePerGas': w3.toWei(gasFees["medium"]["suggestedMaxPriorityFeePerGas"], 'gwei'),
191195
})
192196

193197
transaction = transactionTemplate.build_transaction(txnDict)

bundler/paymaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def eth_paymaster_approved_tokens() -> Result:
107107
return Success([
108108
str({
109109
"address":aprrovedToken.address,
110-
"tokenToEthPrice":aprrovedToken.tokenToEthPrice
110+
"tokenToEthPrice": str(aprrovedToken.tokenToEthPrice)
111111
}) for aprrovedToken in aprrovedTokens]
112112
)
113113

0 commit comments

Comments
 (0)