Skip to content

Commit

Permalink
sync with main + handle tx underpriced errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 14, 2024
1 parent 3a8dc79 commit e76804b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
35 changes: 17 additions & 18 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ import {
import * as sentry from "@sentry/node"
import { Mutex } from "async-mutex"
import {
type Account,
FeeCapTooLowError,
InsufficientFundsError,
IntrinsicGasTooLowError,
NonceTooLowError,
encodeFunctionData,
getContract,
type Account,
type Chain,
type PublicClient,
type Transport,
type WalletClient,
type Hex,
TransactionExecutionError
} from "viem"
Expand Down Expand Up @@ -528,15 +523,18 @@ export class Executor {
nonce: number
}
) {
const request = await this.walletClient.prepareTransactionRequest({
to: entryPoint,
data: encodeFunctionData({
abi: isUserOpVersion06 ? EntryPointV06Abi : EntryPointV07Abi,
functionName: "handleOps",
args: [userOps, opts.account.address]
}),
...opts
})
const request =
await this.config.walletClient.prepareTransactionRequest({
to: entryPoint,
data: encodeFunctionData({
abi: isUserOpVersion06
? EntryPointV06Abi
: EntryPointV07Abi,
functionName: "handleOps",
args: [userOps, opts.account.address]
}),
...opts
})

let attempts = 0
let transactionHash: Hex | undefined
Expand All @@ -546,32 +544,33 @@ export class Executor {
while (attempts < maxAttempts) {
try {
transactionHash =
await this.walletClient.sendTransaction(request)
await this.config.walletClient.sendTransaction(request)

break
} catch (e: unknown) {
const error = e as SendTransactionErrorType
let isErrorHandled = false

if (error instanceof TransactionExecutionError) {
const cause = error.cause

if (cause instanceof NonceTooLowError) {
this.logger.warn("Nonce too low, retrying")
request.nonce += 1
isErrorHandled = true
}

if (cause instanceof IntrinsicGasTooLowError) {
this.logger.warn("Intrinsic gas too low, retrying")
request.gas = scaleBigIntByPercent(request.gas, 150)
isErrorHandled = true
}
}

attempts++
if (attempts === maxAttempts) {
if (attempts === maxAttempts || !isErrorHandled) {
throw error
}

this.logger.warn(`Attempt ${attempts} failed. Retrying...`)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
getContract,
serializeTransaction,
toBytes,
toFunctionSelector
toFunctionSelector,
InternalRpcError
} from "viem"
import { base, baseGoerli, baseSepolia } from "viem/chains"
import { maxBigInt, minBigInt, scaleBigIntByPercent } from "./bigInt"
Expand Down Expand Up @@ -706,7 +707,7 @@ export function parseViemError(err: unknown) {
if (e instanceof EstimateGasExecutionError) {
return e
}
if (e instanceof TransactionExecutionError) {
if (e instanceof InternalRpcError) {
return e
}
return
Expand Down

0 comments on commit e76804b

Please sign in to comment.