Skip to content

Commit

Permalink
Update simulation error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovdog committed Nov 7, 2024
1 parent c7fabb9 commit e152cfc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 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 Address,
decodeErrorResult,
encodeFunctionData,
toHex
toHex,
RpcRequestError
} from "viem"
import { z } from "zod"
import type { SimulateHandleOpResult } from "./types"
Expand Down Expand Up @@ -179,6 +180,10 @@ export class GasEstimatorV06 {
} as const
}

const cause = err.walk(
(err) => err instanceof RpcRequestError
)

const causeParseResult = z
.union([
z.object({
Expand All @@ -203,12 +208,18 @@ export class GasEstimatorV06 {
/VM Exception while processing transaction:.*/
),
data: hexDataSchema
}),
/* Monad devnet RPC return in this format */
z.object({
code: z.literal(-32603),
message: z.string().regex(/execution reverted.*/),
data: hexDataSchema
})
])
.safeParse(err.cause)
.safeParse(cause?.cause)

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

const data = causeParseResult.data.data
Expand Down

0 comments on commit e152cfc

Please sign in to comment.