Skip to content

Commit 34213b2

Browse files
Merge pull request #6 from candidelabs/fix/maxFees
Fix max fees and return error on gas estimation failure
2 parents 79385b0 + 29b5474 commit 34213b2

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

bundler/bundler.py

Lines changed: 20 additions & 12 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)
@@ -223,9 +227,9 @@ def eth_sendUserOperation(request) -> Result:
223227
return Error(2, "Bundle operation failed", data=str(inst))
224228

225229
@method
226-
def eth_getRequestId(request) -> Result:
230+
def eth_getRequestIds(request) -> Result:
227231

228-
serialzer = OperationSerialzer(data=request)
232+
serialzer = OperationSerialzer(data=request, many=True)
229233

230234
if serialzer.is_valid():
231235
serialzer.save()
@@ -237,11 +241,15 @@ def eth_getRequestId(request) -> Result:
237241
abi = [{"inputs":[{"components":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"initCode","type":"bytes"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"callGas","type":"uint256"},{"internalType":"uint256","name":"verificationGas","type":"uint256"},{"internalType":"uint256","name":"preVerificationGas","type":"uint256"},{"internalType":"uint256","name":"maxFeePerGas","type":"uint256"},{"internalType":"uint256","name":"maxPriorityFeePerGas","type":"uint256"},{"internalType":"address","name":"paymaster","type":"address"},{"internalType":"bytes","name":"paymasterData","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct UserOperation","name":"userOp","type":"tuple"}],"name":"getRequestId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"initCode","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"getSenderAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
238242

239243
entryPoint = w3.eth.contract(address=env('entryPoint_add'), abi=abi)
240-
opDict = serialzer.data
241-
242-
requestId = entryPoint.functions.getRequestId(opDict).call()
243244

244-
return Success(requestId.hex())
245+
ops = serialzer.data
246+
result = []
247+
for operation in ops:
248+
opDict = dict(operation)
249+
requestId = entryPoint.functions.getRequestId(opDict).call()
250+
result.append(requestId.hex())
251+
252+
return Success(result)
245253

246254

247255
@method

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)