Skip to content

Commit

Permalink
fix linea sepolia revert handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 8, 2024
1 parent a8c408f commit 4d097c4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/rpc/estimation/gasEstimationsV06.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
type PublicClient,
decodeErrorResult,
encodeFunctionData,
toHex
toHex,
InvalidInputRpcError
} from "viem"
import { z } from "zod"
import type { SimulateHandleOpResult } from "./types"
Expand Down Expand Up @@ -94,14 +95,19 @@ export class GasEstimatorV06 {
} as const
}

let revertCause = err.cause
if (err instanceof InvalidInputRpcError) {
revertCause = err.walk() as RpcRequestErrorType
}

const causeParseResult = z
.union([
z.object({
code: z.literal(3),
message: z.string(),
data: hexDataSchema
}),
/* Fuse RPCs return in this format. */
/* Fuse RPCs reverts in this format. */
z.object({
code: z.number(),
message: z.string().regex(/VM execution error.*/),
Expand All @@ -110,6 +116,12 @@ export class GasEstimatorV06 {
.transform((data) => data.replace("Reverted ", ""))
.pipe(hexDataSchema)
}),
/* Linea-Sepolia reverts in this format. */
z.object({
code: z.literal(-32000),
message: z.string(),
data: hexDataSchema
}),
z.object({
code: z.number(),
message: z
Expand All @@ -120,7 +132,7 @@ export class GasEstimatorV06 {
data: hexDataSchema
})
])
.safeParse(err.cause)
.safeParse(revertCause)

if (!causeParseResult.success) {
throw new Error(JSON.stringify(err.cause))
Expand Down

0 comments on commit 4d097c4

Please sign in to comment.