Skip to content

Commit

Permalink
capture reverts from compressed ops
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed May 29, 2024
1 parent 8038613 commit f5d6674
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions src/executor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import {
concat,
decodeErrorResult,
hexToBytes,
numberToHex
numberToHex,
formatTransactionRequest,
RpcRequestError
} from "viem"

export function simulatedOpsToResults(
Expand Down Expand Up @@ -192,15 +194,19 @@ export async function filterOpsAndEstimateGas(
.mempoolUserOperation as CompressedUserOperation
)

gasLimit = await publicClient.estimateGas({
const tx = formatTransactionRequest({
to: bundleBulker,
account: wallet,
from: wallet.address,
data: createCompressedCalldata(opsToSend, perOpInflatorId),
gas: fixedGasLimitForEstimation,
nonce: nonce,
blockTag,
...gasOptions
})

gasLimit = await publicClient.request({
method: "eth_estimateGas",
params: [tx, blockTag]
})
}

return { simulatedOps, gasLimit, resubmitAllOps: false }
Expand Down Expand Up @@ -321,6 +327,57 @@ export async function filterOpsAndEstimateGas(
{ error: JSON.stringify(err) },
"failed to parse error result"
)
return {
simulatedOps: [],
gasLimit: 0n,
resubmitAllOps: false
}
}
} else if (err instanceof RpcRequestError) {
try {
const errorHexData = (err.cause as unknown as any).data

const errorResult = decodeErrorResult({
abi: isUserOpV06 ? EntryPointV06Abi : EntryPointV07Abi,
data: errorHexData
})
logger.debug(
{
errorName: errorResult.errorName,
args: errorResult.args,
userOpHashes: simulatedOps
.filter((op) => op.reason === undefined)
.map((op) => op.owh.userOperationHash)
},
"user op in batch invalid"
)

if (errorResult.errorName !== "FailedOp") {
logger.error(
{
errorName: errorResult.errorName,
args: errorResult.args
},
"unexpected error result"
)
return {
simulatedOps: [],
gasLimit: 0n,
resubmitAllOps: false
}
}

const failingOp = simulatedOps.filter(
(op) => op.reason === undefined
)[Number(errorResult.args[0])]

failingOp.reason = errorResult.args[1]
} catch (e: unknown) {
logger.error(
{ error: JSON.stringify(e) },
"failed to parse error result"
)

return {
simulatedOps: [],
gasLimit: 0n,
Expand Down

0 comments on commit f5d6674

Please sign in to comment.