web3-mev-error-decoder 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -2
- package/dist/error-decoder/constants.d.ts +5 -0
- package/dist/error-decoder/constants.js +19 -0
- package/dist/error-decoder/constants.js.map +1 -0
- package/dist/error-decoder/decoder.d.ts +43 -0
- package/dist/error-decoder/decoder.js +98 -0
- package/dist/error-decoder/decoder.js.map +1 -0
- package/dist/error-decoder/enums.d.ts +9 -0
- package/dist/error-decoder/enums.js +11 -0
- package/dist/error-decoder/enums.js.map +1 -0
- package/dist/error-decoder/handlers.d.ts +32 -0
- package/dist/error-decoder/handlers.js +131 -0
- package/dist/error-decoder/handlers.js.map +1 -0
- package/dist/error-decoder/index.d.ts +7 -0
- package/dist/error-decoder/index.js +7 -0
- package/dist/error-decoder/index.js.map +1 -0
- package/dist/error-decoder/results.d.ts +19 -0
- package/dist/error-decoder/results.js +53 -0
- package/dist/error-decoder/results.js.map +1 -0
- package/dist/error-decoder/types.d.ts +31 -0
- package/dist/error-decoder/types.js +2 -0
- package/dist/error-decoder/types.js.map +1 -0
- package/dist/error-decoder/viem.d.ts +19 -0
- package/dist/error-decoder/viem.js +47 -0
- package/dist/error-decoder/viem.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/multicall/abi.d.ts +7 -0
- package/dist/multicall/abi.js +27 -0
- package/dist/multicall/abi.js.map +1 -0
- package/dist/multicall/ethers.d.ts +50 -0
- package/dist/multicall/ethers.js +78 -0
- package/dist/multicall/ethers.js.map +1 -0
- package/dist/multicall/index.d.ts +21 -0
- package/dist/multicall/index.js +33 -0
- package/dist/multicall/index.js.map +1 -0
- package/dist/multicall/viem.d.ts +14 -0
- package/dist/multicall/viem.js +32 -0
- package/dist/multicall/viem.js.map +1 -0
- package/dist/provider/fallback-full.d.ts +124 -0
- package/dist/provider/fallback-full.js +629 -0
- package/dist/provider/fallback-full.js.map +1 -0
- package/dist/provider/fallback.d.ts +37 -0
- package/dist/provider/fallback.js +120 -0
- package/dist/provider/fallback.js.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/index.js +5 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/viem-fallback.d.ts +47 -0
- package/dist/provider/viem-fallback.js +69 -0
- package/dist/provider/viem-fallback.js.map +1 -0
- package/dist/transaction/ethers.d.ts +27 -0
- package/dist/transaction/ethers.js +97 -0
- package/dist/transaction/ethers.js.map +1 -0
- package/dist/transaction/index.d.ts +21 -0
- package/dist/transaction/index.js +31 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/types.d.ts +46 -0
- package/dist/transaction/types.js +21 -0
- package/dist/transaction/types.js.map +1 -0
- package/dist/transaction/viem.d.ts +29 -0
- package/dist/transaction/viem.js +86 -0
- package/dist/transaction/viem.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +59 -0
- package/dist/utils.js +140 -0
- package/dist/utils.js.map +1 -0
- package/package.json +106 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 multicall-error-decoder contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# web3-mev-error-decoder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Multicall batching with per-call revert decoding, a custom error & revert reason decoder for **ethers v6** and **viem**, `waitForTransaction` with timeout and replacement handling, and RPC fallback providers with liveliness checks.
|
|
4
|
+
|
|
5
|
+
Built for **web3 developers**, **smart-contract engineers**, and builders of **MEV bots**, **sniper bots**, **arbitrage bots** and DeFi dashboards that need reliable transaction error decoding and resilient RPC infrastructure.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/web3-mev-error-decoder)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
## Why you need this
|
|
11
|
+
|
|
12
|
+
If you run an MEV bot, a sniper bot, an arbitrage bot or any dApp that batches on-chain calls, you know the pain:
|
|
13
|
+
|
|
14
|
+
- `CALL_EXCEPTION: execution reverted` with **no revert data** and no idea why the transaction failed
|
|
15
|
+
- Multicall batches where **one failing call kills the whole batch** and you can't tell which one or why
|
|
16
|
+
- Solidity **custom errors** (`0xabc12345...`) that your ABI doesn't decode
|
|
17
|
+
- `Panic(uint256)` codes (`0x4e487b71`) that mean nothing to your logs
|
|
18
|
+
- Transactions stuck because a public RPC is rate-limiting or behind
|
|
19
|
+
- `waitForTransaction` hanging forever on dropped or replaced transactions
|
|
20
|
+
|
|
21
|
+
**web3-mev-error-decoder** solves all of the above in one small, dependency-light package.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Decode revert reasons** (`Error(string)`) — including from aggregated **multicall** results, with per-call revert data
|
|
26
|
+
- **Decode Solidity custom errors** through any ABI you provide (human-readable signature + args)
|
|
27
|
+
- **Decode `Panic(uint256)` codes** into human-readable reasons (assert, overflow, division by zero, etc.)
|
|
28
|
+
- **viem-compatible error extraction** — understands `error.data`, nested `error.data` and `cause` chains
|
|
29
|
+
- **Replay mined reverted transactions** via `eth_call` to recover the original revert reason
|
|
30
|
+
- **Multicall batching** for ethers v6 and viem with graceful per-call failure handling
|
|
31
|
+
- **`waitForTransaction`** with timeout and replacement-transaction handling
|
|
32
|
+
- **RPC fallback providers** with automatic liveliness checks and rotation
|
|
33
|
+
- Zero runtime bloat: peer deps are `ethers` and/or `viem` — use one or both
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install web3-mev-error-decoder
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
or
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
yarn add web3-mev-error-decoder
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Node.js >= 20 and [`ethers`](https://www.npmjs.com/package/ethers) v6 and/or [`viem`](https://www.npmjs.com/package/viem) v2 as peer dependencies.
|
|
48
|
+
|
|
49
|
+
## Quick start — decode a thrown error (ethers v6)
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { ErrorDecoder } from 'web3-mev-error-decoder';
|
|
53
|
+
|
|
54
|
+
const decoder = new ErrorDecoder({
|
|
55
|
+
// ABIs that may contain custom errors (optional)
|
|
56
|
+
abis: [myContractAbi],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
await contract.myMethod();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const decoded = await decoder.decode(error);
|
|
63
|
+
console.log(decoded.type); // ErrorType.REVERT | CUSTOM | PANIC | ...
|
|
64
|
+
console.log(decoded.reason); // human-readable reason
|
|
65
|
+
console.log(decoded.args); // decoded custom error args
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Decode raw revert data (multicall results)
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { decodeRevertData } from 'web3-mev-error-decoder';
|
|
73
|
+
|
|
74
|
+
const decoded = decodeRevertData(revertDataHex, [myContractAbi]);
|
|
75
|
+
// -> { type, reason, fragment, args, signature }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Perfect for **multicall** / **aggregate3** batch results where each call can individually revert and you need to know exactly which call failed and why — the core requirement of MEV bots, sniper bots and arbitrage bots that must react to failures in the same block.
|
|
79
|
+
|
|
80
|
+
## Decode a mined reverted transaction
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { ErrorDecoder } from 'web3-mev-error-decoder';
|
|
84
|
+
|
|
85
|
+
const decoder = new ErrorDecoder();
|
|
86
|
+
|
|
87
|
+
// replays the transaction via eth_call at the latest block
|
|
88
|
+
const decoded = await decoder.getRevertReason(provider, txHash);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Decoded error types
|
|
92
|
+
|
|
93
|
+
| Type | Trigger | Example |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `REVERT` | `Error(string)` revert reason | `"Insufficient balance"` |
|
|
96
|
+
| `CUSTOM` | ABI-known custom error | `Unauthorized(address)` with args |
|
|
97
|
+
| `PANIC` | Solidity `Panic(uint256)` | `"Arithmetic overflow"` |
|
|
98
|
+
| `EMPTY` | Reverted with no data | `"reverted (no revert data)"` |
|
|
99
|
+
| `USER_REJECT` | Wallet rejection | `"User rejected the request"` |
|
|
100
|
+
| `RPC` | Transport / node errors | `"rate limit exceeded"` |
|
|
101
|
+
| `UNKNOWN` | Anything else | raw data preserved |
|
|
102
|
+
|
|
103
|
+
## Multicall batching
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Multicaller } from 'web3-mev-error-decoder/multicall';
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Batch hundreds of calls through a Multicall3-style aggregate contract. Failed calls are surfaced **individually** with fully decoded revert data instead of failing the whole batch — so your bot can keep running with partial results and only skip the broken routes.
|
|
110
|
+
|
|
111
|
+
## waitForTransaction with timeout & replacement
|
|
112
|
+
|
|
113
|
+
Stop hanging on stuck transactions:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { waitForTransaction } from 'web3-mev-error-decoder/transaction';
|
|
117
|
+
|
|
118
|
+
const receipt = await waitForTransaction({
|
|
119
|
+
provider,
|
|
120
|
+
hash: txHash,
|
|
121
|
+
timeoutMs: 30_000, // bail out after 30s
|
|
122
|
+
replacement: { /* bump gas and re-submit */ },
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Typical use: **sniper bots** and **arbitrage bots** racing mempool competition where a transaction must be replaced or abandoned quickly.
|
|
127
|
+
|
|
128
|
+
## RPC fallback providers
|
|
129
|
+
|
|
130
|
+
Never get stuck on a rate-limited public RPC again:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { FallbackProvider } from 'web3-mev-error-decoder/provider';
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Automatic failover across multiple RPC endpoints with liveliness checks, so your bot's error decoder and transaction pipeline keep working when a node goes down.
|
|
137
|
+
|
|
138
|
+
## Works with ethers v6 and viem
|
|
139
|
+
|
|
140
|
+
Use it with either stack — or both:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// ethers v6
|
|
144
|
+
import { ErrorDecoder } from 'web3-mev-error-decoder';
|
|
145
|
+
|
|
146
|
+
// viem-compatible error extraction is built in
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Who is this for
|
|
150
|
+
|
|
151
|
+
- **MEV bot developers** — searchers, builders, sandwich/liquidation strategies that need per-call failure decoding inside multicall batches
|
|
152
|
+
- **Sniper & arbitrage bot developers** — fast failure triage to reroute or drop failing opportunities
|
|
153
|
+
- **Smart-contract engineers** — decoding custom errors and panics during integration testing and incident response
|
|
154
|
+
- **dApp / DeFi frontend teams** — turning cryptic wallet and RPC errors into actionable messages
|
|
155
|
+
- **Infrastructure engineers** — resilient RPC fallback and transaction replacement pipelines
|
|
156
|
+
|
|
157
|
+
## API
|
|
158
|
+
|
|
159
|
+
- `ErrorDecoder` — class with `decode(error)`, `decodeData(data, error?)`, `getRevertReason(provider, txHash)`, `getTransactionError(receipt)`
|
|
160
|
+
- `decodeRevertData(data, abis?, error?)` — stateless one-shot decoder
|
|
161
|
+
- `defaultErrorHandlers` — built-in handler chain, extendable via `additionalErrorHandlers`
|
|
162
|
+
- `Multicaller` — multicall batching (ethers v6 / viem)
|
|
163
|
+
- `waitForTransaction` — timeout + replacement handling
|
|
164
|
+
- `SimpleFallbackProvider` / viem fallback transports — RPC failover
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ERROR_STRING_PREFIX = "0x08c379a0";
|
|
2
|
+
export declare const PANIC_CODE_PREFIX = "0x4e487b71";
|
|
3
|
+
/** Standard panic (assert) codes from Solidity. */
|
|
4
|
+
export declare const panicCodes: Record<number, string>;
|
|
5
|
+
export declare function panicErrorCodeToReason(code: bigint): string | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const ERROR_STRING_PREFIX = '0x08c379a0'; // keccak256("Error(string)") selector
|
|
2
|
+
export const PANIC_CODE_PREFIX = '0x4e487b71'; // keccak256("Panic(uint256)") selector
|
|
3
|
+
/** Standard panic (assert) codes from Solidity. */
|
|
4
|
+
export const panicCodes = {
|
|
5
|
+
0x00: 'Generic panic',
|
|
6
|
+
0x01: 'Assert() has failed',
|
|
7
|
+
0x11: 'Arithmetic operation underflowed or overflowed outside of an unchecked block',
|
|
8
|
+
0x12: 'Division or modulo division by zero',
|
|
9
|
+
0x21: 'Tried to convert to an invalid enum value',
|
|
10
|
+
0x22: 'Storage byte array that is incorrectly encoded',
|
|
11
|
+
0x31: 'Method is called on an empty POP array',
|
|
12
|
+
0x32: 'Array index that is out of bounds',
|
|
13
|
+
0x41: 'Allocation of too much memory or creation of an array which is too large',
|
|
14
|
+
0x51: 'Called a zero-initialized variable of an internal function type',
|
|
15
|
+
};
|
|
16
|
+
export function panicErrorCodeToReason(code) {
|
|
17
|
+
return panicCodes[Number(code)] ?? null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/error-decoder/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC,CAAC,sCAAsC;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC,CAAC,uCAAuC;AAEtF,mDAAmD;AACnD,MAAM,CAAC,MAAM,UAAU,GAA2B;IAChD,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE,8EAA8E;IACpF,IAAI,EAAE,qCAAqC;IAC3C,IAAI,EAAE,2CAA2C;IACjD,IAAI,EAAE,gDAAgD;IACtD,IAAI,EAAE,wCAAwC;IAC9C,IAAI,EAAE,mCAAmC;IACzC,IAAI,EAAE,0EAA0E;IAChF,IAAI,EAAE,iEAAiE;CACxE,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TransactionReceipt, TransactionResponse } from 'ethers';
|
|
2
|
+
import type { AbiLike } from '../types.js';
|
|
3
|
+
import type { DecodedError, ErrorHandler } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Decodes contract errors:
|
|
6
|
+
* - `Error(string)` revert reasons
|
|
7
|
+
* - Solidity `Panic(uint256)` codes
|
|
8
|
+
* - custom errors via the ABIs you provide
|
|
9
|
+
* - user rejection and JSON-RPC transport errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class ErrorDecoder {
|
|
12
|
+
private readonly errorHandlers;
|
|
13
|
+
private readonly errorInterface;
|
|
14
|
+
constructor(errorInterfaces?: ReadonlyArray<AbiLike>, opts?: {
|
|
15
|
+
additionalErrorHandlers?: ErrorHandler[];
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Decode a thrown error. Understands:
|
|
19
|
+
* - ethers `CALL_EXCEPTION` (sync `.call` revert)
|
|
20
|
+
* - errors carrying a `receipt` (mined reverted transaction), which are replayed via `eth_call`
|
|
21
|
+
* to recover the revert data
|
|
22
|
+
* - any error object with `data` / nested `error.data` / `cause` chain (viem-compatible)
|
|
23
|
+
*/
|
|
24
|
+
decode(error: unknown): Promise<DecodedError>;
|
|
25
|
+
/**
|
|
26
|
+
* Decode raw revert data directly (e.g. from a failed `eth_call` or from a
|
|
27
|
+
* multicall per-item return data).
|
|
28
|
+
*/
|
|
29
|
+
decodeData(data: string | undefined, error?: Error): DecodedError;
|
|
30
|
+
/**
|
|
31
|
+
* Recover the revert reason of a mined reverted transaction by replaying it
|
|
32
|
+
* via `eth_call` at the latest block. Returns a decoded error.
|
|
33
|
+
*/
|
|
34
|
+
getRevertReason(provider: {
|
|
35
|
+
getTransaction: (hash: string) => Promise<TransactionResponse | null>;
|
|
36
|
+
call: (tx: any) => Promise<any>;
|
|
37
|
+
}, txHash: string): Promise<DecodedError>;
|
|
38
|
+
/** Replay a reverted receipt to get the original error (or null if unrecoverable). */
|
|
39
|
+
getTransactionError(receipt: TransactionReceipt): Promise<Error | null>;
|
|
40
|
+
private getContractOrTransactionError;
|
|
41
|
+
}
|
|
42
|
+
/** Convenience: decode raw revert data without constructing an ErrorDecoder. */
|
|
43
|
+
export declare function decodeRevertData(data: string | undefined, abis?: ReadonlyArray<AbiLike>, error?: Error): DecodedError;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { callRequestFromTx, extractRevertData, mergeAbis } from '../utils.js';
|
|
2
|
+
import { defaultErrorHandlers } from './handlers.js';
|
|
3
|
+
import { unknownErrorResult } from './results.js';
|
|
4
|
+
/**
|
|
5
|
+
* Decodes contract errors:
|
|
6
|
+
* - `Error(string)` revert reasons
|
|
7
|
+
* - Solidity `Panic(uint256)` codes
|
|
8
|
+
* - custom errors via the ABIs you provide
|
|
9
|
+
* - user rejection and JSON-RPC transport errors
|
|
10
|
+
*/
|
|
11
|
+
export class ErrorDecoder {
|
|
12
|
+
errorHandlers;
|
|
13
|
+
errorInterface;
|
|
14
|
+
constructor(errorInterfaces, opts = {}) {
|
|
15
|
+
this.errorInterface =
|
|
16
|
+
errorInterfaces && errorInterfaces.length > 0 ? mergeAbis(errorInterfaces) : undefined;
|
|
17
|
+
this.errorHandlers = [...defaultErrorHandlers, ...(opts.additionalErrorHandlers ?? [])];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Decode a thrown error. Understands:
|
|
21
|
+
* - ethers `CALL_EXCEPTION` (sync `.call` revert)
|
|
22
|
+
* - errors carrying a `receipt` (mined reverted transaction), which are replayed via `eth_call`
|
|
23
|
+
* to recover the revert data
|
|
24
|
+
* - any error object with `data` / nested `error.data` / `cause` chain (viem-compatible)
|
|
25
|
+
*/
|
|
26
|
+
async decode(error) {
|
|
27
|
+
if (!(error instanceof Error)) {
|
|
28
|
+
return unknownErrorResult({ reason: error?.message ?? 'Invalid error' });
|
|
29
|
+
}
|
|
30
|
+
const targetError = await this.getContractOrTransactionError(error);
|
|
31
|
+
const data = extractRevertData(targetError);
|
|
32
|
+
return this.decodeData(data, targetError);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decode raw revert data directly (e.g. from a failed `eth_call` or from a
|
|
36
|
+
* multicall per-item return data).
|
|
37
|
+
*/
|
|
38
|
+
decodeData(data, error) {
|
|
39
|
+
for (const handler of this.errorHandlers) {
|
|
40
|
+
if (handler.predicate(data, error ?? new Error())) {
|
|
41
|
+
return handler.handle(data, { errorInterface: this.errorInterface, error: error ?? new Error() });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return unknownErrorResult({ data, reason: error?.message ?? 'Unexpected error' });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Recover the revert reason of a mined reverted transaction by replaying it
|
|
48
|
+
* via `eth_call` at the latest block. Returns a decoded error.
|
|
49
|
+
*/
|
|
50
|
+
async getRevertReason(provider, txHash) {
|
|
51
|
+
const receipt = await provider.getTransactionReceipt(txHash);
|
|
52
|
+
if (receipt && receipt.status === 1) {
|
|
53
|
+
throw new Error('Transaction succeeded — there is no revert reason');
|
|
54
|
+
}
|
|
55
|
+
const tx = await provider.getTransaction(txHash);
|
|
56
|
+
if (!tx) {
|
|
57
|
+
return unknownErrorResult({ reason: 'Transaction not found' });
|
|
58
|
+
}
|
|
59
|
+
let data;
|
|
60
|
+
try {
|
|
61
|
+
await provider.call(callRequestFromTx(tx));
|
|
62
|
+
// Call succeeded — the chain state has moved on; cannot reproduce revert.
|
|
63
|
+
data = undefined;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
data = extractRevertData(e);
|
|
67
|
+
}
|
|
68
|
+
return this.decodeData(data);
|
|
69
|
+
}
|
|
70
|
+
/** Replay a reverted receipt to get the original error (or null if unrecoverable). */
|
|
71
|
+
async getTransactionError(receipt) {
|
|
72
|
+
if (receipt.status !== 0)
|
|
73
|
+
return null;
|
|
74
|
+
const provider = receipt.provider;
|
|
75
|
+
const tx = await provider.getTransaction(receipt.hash);
|
|
76
|
+
if (!tx)
|
|
77
|
+
return null;
|
|
78
|
+
try {
|
|
79
|
+
await provider.call(callRequestFromTx(tx));
|
|
80
|
+
return null; // call succeeded — would not have reverted now
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async getContractOrTransactionError(error) {
|
|
87
|
+
const receipt = error.receipt;
|
|
88
|
+
if (!receipt || receipt.status !== 0)
|
|
89
|
+
return error;
|
|
90
|
+
const replayed = await this.getTransactionError(receipt);
|
|
91
|
+
return replayed ?? error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Convenience: decode raw revert data without constructing an ErrorDecoder. */
|
|
95
|
+
export function decodeRevertData(data, abis, error) {
|
|
96
|
+
return new ErrorDecoder(abis).decodeData(data, error);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder.js","sourceRoot":"","sources":["../../src/error-decoder/decoder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACN,aAAa,CAAiB;IAC9B,cAAc,CAAwB;IAEvD,YACE,eAAwC,EACxC,OAAqD,EAAE;QAEvD,IAAI,CAAC,cAAc;YACjB,eAAe,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzF,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,oBAAoB,EAAE,GAAG,CAAC,IAAI,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,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zD,OAAO,QAAQ,IAAI,KAAK,CAAC;IAC3B,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAC9B,IAAwB,EACxB,IAA6B,EAC7B,KAAa;IAEb,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export var ErrorType;
|
|
2
|
+
(function (ErrorType) {
|
|
3
|
+
ErrorType["EmptyError"] = "EmptyError";
|
|
4
|
+
ErrorType["RevertError"] = "RevertError";
|
|
5
|
+
ErrorType["PanicError"] = "PanicError";
|
|
6
|
+
ErrorType["CustomError"] = "CustomError";
|
|
7
|
+
ErrorType["UserRejectError"] = "UserRejectError";
|
|
8
|
+
ErrorType["RpcError"] = "RpcError";
|
|
9
|
+
ErrorType["UnknownError"] = "UnknownError";
|
|
10
|
+
})(ErrorType || (ErrorType = {}));
|
|
11
|
+
//# sourceMappingURL=enums.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../src/error-decoder/enums.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAC3B,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC,kCAAqB,CAAA;IACrB,0CAA6B,CAAA;AAC/B,CAAC,EARW,SAAS,KAAT,SAAS,QAQpB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ErrorType } from './enums.js';
|
|
2
|
+
import type { DecodedError, ErrorHandler, ErrorHandlerInput } from './types.js';
|
|
3
|
+
export declare class EmptyErrorHandler implements ErrorHandler {
|
|
4
|
+
predicate(data: string | undefined): boolean;
|
|
5
|
+
handle(data: string | undefined): DecodedError;
|
|
6
|
+
}
|
|
7
|
+
export declare class RevertErrorHandler implements ErrorHandler {
|
|
8
|
+
predicate(data: string | undefined): boolean;
|
|
9
|
+
handle(data: string | undefined): DecodedError;
|
|
10
|
+
}
|
|
11
|
+
export declare class PanicErrorHandler implements ErrorHandler {
|
|
12
|
+
predicate(data: string | undefined): boolean;
|
|
13
|
+
handle(data: string | undefined): DecodedError;
|
|
14
|
+
}
|
|
15
|
+
export declare class CustomErrorHandler implements ErrorHandler {
|
|
16
|
+
predicate(data: string | undefined): boolean;
|
|
17
|
+
handle(data: string | undefined, { errorInterface }: ErrorHandlerInput): DecodedError;
|
|
18
|
+
}
|
|
19
|
+
export declare class RevertedWithoutDataHandler implements ErrorHandler {
|
|
20
|
+
predicate(data: string | undefined, error: Error): boolean;
|
|
21
|
+
handle(_data: string | undefined, { error }: ErrorHandlerInput): DecodedError;
|
|
22
|
+
}
|
|
23
|
+
export declare class UserRejectionHandler implements ErrorHandler {
|
|
24
|
+
predicate(data: string | undefined, error: Error): boolean;
|
|
25
|
+
handle(_data: string | undefined, { error }: ErrorHandlerInput): DecodedError;
|
|
26
|
+
}
|
|
27
|
+
export declare class RpcErrorHandler implements ErrorHandler {
|
|
28
|
+
predicate(data: string | undefined, error: Error): boolean;
|
|
29
|
+
handle(_data: string | undefined, { error }: ErrorHandlerInput): DecodedError;
|
|
30
|
+
}
|
|
31
|
+
export declare const defaultErrorHandlers: ErrorHandler[];
|
|
32
|
+
export { ErrorType };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { AbiCoder, ErrorFragment } from 'ethers';
|
|
2
|
+
import { ERROR_STRING_PREFIX, PANIC_CODE_PREFIX, panicErrorCodeToReason } from './constants.js';
|
|
3
|
+
import { ErrorType } from './enums.js';
|
|
4
|
+
import { customErrorResult, emptyErrorResult, panicErrorResult, revertErrorResult, rpcErrorResult, unknownErrorResult, userRejectErrorResult, } from './results.js';
|
|
5
|
+
export class EmptyErrorHandler {
|
|
6
|
+
predicate(data) {
|
|
7
|
+
return data === '0x';
|
|
8
|
+
}
|
|
9
|
+
handle(data) {
|
|
10
|
+
return emptyErrorResult({ data, reason: 'reverted (no revert data)' });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class RevertErrorHandler {
|
|
14
|
+
predicate(data) {
|
|
15
|
+
return !!data && data.startsWith(ERROR_STRING_PREFIX);
|
|
16
|
+
}
|
|
17
|
+
handle(data) {
|
|
18
|
+
if (!data)
|
|
19
|
+
return unknownErrorResult({ reason: 'Unknown error returned', data });
|
|
20
|
+
const encodedReason = data.slice(ERROR_STRING_PREFIX.length);
|
|
21
|
+
const abi = AbiCoder.defaultAbiCoder();
|
|
22
|
+
try {
|
|
23
|
+
const fragment = ErrorFragment.from('Error(string)');
|
|
24
|
+
const args = abi.decode(fragment.inputs, `0x${encodedReason}`);
|
|
25
|
+
const reason = args[0];
|
|
26
|
+
return revertErrorResult({ data, fragment, reason, args });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return unknownErrorResult({ reason: 'Unknown error returned', data });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class PanicErrorHandler {
|
|
34
|
+
predicate(data) {
|
|
35
|
+
return !!data && data.startsWith(PANIC_CODE_PREFIX);
|
|
36
|
+
}
|
|
37
|
+
handle(data) {
|
|
38
|
+
if (!data)
|
|
39
|
+
return unknownErrorResult({ reason: 'Unknown panic error', data });
|
|
40
|
+
const encodedReason = data.slice(PANIC_CODE_PREFIX.length);
|
|
41
|
+
const abi = AbiCoder.defaultAbiCoder();
|
|
42
|
+
try {
|
|
43
|
+
const fragment = ErrorFragment.from('Panic(uint256)');
|
|
44
|
+
const args = abi.decode(fragment.inputs, `0x${encodedReason}`);
|
|
45
|
+
const reason = panicErrorCodeToReason(args[0]) ?? 'Unknown panic code';
|
|
46
|
+
return panicErrorResult({ data, fragment, reason, args });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return unknownErrorResult({ reason: 'Unknown panic error', data });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class CustomErrorHandler {
|
|
54
|
+
predicate(data) {
|
|
55
|
+
return (!!data &&
|
|
56
|
+
data !== '0x' &&
|
|
57
|
+
!data.startsWith(ERROR_STRING_PREFIX) &&
|
|
58
|
+
!data.startsWith(PANIC_CODE_PREFIX));
|
|
59
|
+
}
|
|
60
|
+
handle(data, { errorInterface }) {
|
|
61
|
+
if (!data)
|
|
62
|
+
return unknownErrorResult({ reason: 'Unknown error', data });
|
|
63
|
+
let fragment = null;
|
|
64
|
+
let reason = null;
|
|
65
|
+
let args = null;
|
|
66
|
+
let signature = null;
|
|
67
|
+
if (errorInterface) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = errorInterface.parseError(data);
|
|
70
|
+
if (parsed) {
|
|
71
|
+
fragment = parsed.fragment;
|
|
72
|
+
reason = parsed.name;
|
|
73
|
+
args = parsed.args;
|
|
74
|
+
signature = parsed.fragment.format();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// no matching fragment in the provided ABI
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return customErrorResult({ data, fragment, reason, args, signature });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export class RevertedWithoutDataHandler {
|
|
85
|
+
predicate(data, error) {
|
|
86
|
+
return !data && !!error?.message && /revert/i.test(error.message);
|
|
87
|
+
}
|
|
88
|
+
handle(_data, { error }) {
|
|
89
|
+
return emptyErrorResult({
|
|
90
|
+
data: null,
|
|
91
|
+
reason: error.message?.includes('execution reverted')
|
|
92
|
+
? 'execution reverted (no revert data)'
|
|
93
|
+
: 'reverted (no revert data)',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export class UserRejectionHandler {
|
|
98
|
+
predicate(data, error) {
|
|
99
|
+
return !data && !!error?.message && /reject(ed)?/i.test(error.message);
|
|
100
|
+
}
|
|
101
|
+
handle(_data, { error }) {
|
|
102
|
+
return userRejectErrorResult({
|
|
103
|
+
data: null,
|
|
104
|
+
reason: error.message ?? 'The transaction was rejected',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export class RpcErrorHandler {
|
|
109
|
+
predicate(data, error) {
|
|
110
|
+
return (!data &&
|
|
111
|
+
!!error.message &&
|
|
112
|
+
!error.message.includes('rejected transaction') &&
|
|
113
|
+
error.code !== undefined);
|
|
114
|
+
}
|
|
115
|
+
handle(_data, { error }) {
|
|
116
|
+
const rpcError = error;
|
|
117
|
+
const reason = rpcError.info?.error?.message ?? rpcError.shortMessage ?? rpcError.message;
|
|
118
|
+
return rpcErrorResult({ name: rpcError.code, reason });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export const defaultErrorHandlers = [
|
|
122
|
+
new EmptyErrorHandler(),
|
|
123
|
+
new RevertErrorHandler(),
|
|
124
|
+
new PanicErrorHandler(),
|
|
125
|
+
new CustomErrorHandler(),
|
|
126
|
+
new RevertedWithoutDataHandler(),
|
|
127
|
+
new UserRejectionHandler(),
|
|
128
|
+
new RpcErrorHandler(),
|
|
129
|
+
];
|
|
130
|
+
export { ErrorType };
|
|
131
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/error-decoder/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAa,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAO,iBA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c,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,KAAyB,EAAE,EAAE,KAAK,EAAqB;QAC5D,OAAO,qBAAqB,CAAC;YAC3B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,KAAK,CAAC,OAAO,IAAI,8BAA8B;SACxD,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IAC1B,SAAS,CAAC,IAAwB,EAAE,KAAY;QAC9C,OAAO,CACL,CAAC,IAAI;YACL,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC;YAC9C,KAAa,CAAC,IAAI,KAAK,SAAS,CAClC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAyB,EAAE,EAAE,KAAK,EAAqB;QAC5D,MAAM,QAAQ,GAAG,KAAY,CAAC;QAC9B,MAAM,MAAM,GACV,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY,IAAI,QAAQ,CAAC,OAAO,CAAC;QAC7E,OAAO,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACzD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAmB;IAClD,IAAI,iBAAiB,EAAE;IACvB,IAAI,kBAAkB,EAAE;IACxB,IAAI,iBAAiB,EAAE;IACvB,IAAI,kBAAkB,EAAE;IACxB,IAAI,0BAA0B,EAAE;IAChC,IAAI,oBAAoB,EAAE;IAC1B,IAAI,eAAe,EAAE;CACtB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './enums.js';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './results.js';
|
|
4
|
+
export * from './handlers.js';
|
|
5
|
+
export * from './decoder.js';
|
|
6
|
+
export * from './viem.js';
|
|
7
|
+
export type { DecodedError, ErrorHandler, ErrorHandlerInput } from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error-decoder/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorFragment, Result } from 'ethers';
|
|
2
|
+
import type { DecodedError } from './types.js';
|
|
3
|
+
type ErrorResultFormatterParam = {
|
|
4
|
+
data?: string | null;
|
|
5
|
+
reason?: string | null;
|
|
6
|
+
args?: Result | null;
|
|
7
|
+
fragment?: ErrorFragment | null;
|
|
8
|
+
selector?: string | null;
|
|
9
|
+
name?: string | null;
|
|
10
|
+
signature?: string | null;
|
|
11
|
+
};
|
|
12
|
+
export declare const emptyErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
13
|
+
export declare const userRejectErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
14
|
+
export declare const revertErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
15
|
+
export declare const unknownErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
16
|
+
export declare const panicErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
17
|
+
export declare const customErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
18
|
+
export declare const rpcErrorResult: (p: ErrorResultFormatterParam) => DecodedError;
|
|
19
|
+
export {};
|