@raac/rpc 1.1.0-beta.52 → 1.1.0-beta.54

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.
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorInfo = getErrorInfo;
4
+ exports.decodeErrorName = decodeErrorName;
5
+ exports.attachDecodedError = attachDecodedError;
6
+ const ethers_1 = require("ethers");
7
+ const artifacts_1 = require("./artifacts");
8
+ const ERROR_SIGNATURE_MAP = {};
9
+ (function buildErrorSignatureMap() {
10
+ for (const abiKey in artifacts_1.ABIS) {
11
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
+ // @ts-ignore – ABIS may contain unknown items
13
+ const abi = artifacts_1.ABIS[abiKey];
14
+ if (!Array.isArray(abi))
15
+ continue;
16
+ for (const item of abi) {
17
+ if (item.type !== "error")
18
+ continue;
19
+ const inputs = (item.inputs || []);
20
+ const signature = `${item.name}(${inputs.map((input) => input.type).join(",")})`;
21
+ const selector = (0, ethers_1.id)(signature).slice(0, 10).toLowerCase();
22
+ if (!ERROR_SIGNATURE_MAP[selector]) {
23
+ ERROR_SIGNATURE_MAP[selector] = {
24
+ name: item.name,
25
+ signature,
26
+ abiItem: item,
27
+ };
28
+ }
29
+ }
30
+ }
31
+ })();
32
+ /**
33
+ * Returns detailed information about the error encoded in the given data blob.
34
+ * @param data The revert data returned by the EVM (e.g., error.data).
35
+ */
36
+ function getErrorInfo(data) {
37
+ if (!data || typeof data !== "string")
38
+ return null;
39
+ let selector;
40
+ if (data.startsWith("0x")) {
41
+ selector = data.slice(0, 10).toLowerCase();
42
+ }
43
+ else {
44
+ // look for first 4-byte hex inside the string (e.g., error message)
45
+ const match = data.match(/0x[0-9a-fA-F]{8}/);
46
+ if (match)
47
+ selector = match[0].toLowerCase();
48
+ }
49
+ if (!selector)
50
+ return null;
51
+ return ERROR_SIGNATURE_MAP[selector] ?? null;
52
+ }
53
+ /**
54
+ * Returns only the error name, or null if it cannot be decoded.
55
+ */
56
+ function decodeErrorName(data) {
57
+ const info = getErrorInfo(data);
58
+ return info?.name ?? null;
59
+ }
60
+ /**
61
+ * Builds a user-friendly error prefix with decoded error name (if available).
62
+ * Usage example:
63
+ * const msg = attachDecodedError("Deposit failed", caughtError);
64
+ */
65
+ function attachDecodedError(prefix, error) {
66
+ // ethers@6 nests the original error under error.error
67
+ // viem/ethcall surface it directly on error.data
68
+ const data = (error && ((error.data ?? error.error?.data) ||
69
+ // viem error format: error.shortMessage
70
+ undefined));
71
+ // If data not found, attempt to extract selector from message like
72
+ // "Encoded error signature \"0xa9b65aba\" not found on ABI"
73
+ let selector;
74
+ if (data && data.startsWith("0x")) {
75
+ selector = data.slice(0, 10).toLowerCase();
76
+ }
77
+ else if (typeof error?.message === "string") {
78
+ const SIGNATURE_REGEX = /Encoded error signature \"(0x[0-9a-fA-F]{8})\"/;
79
+ const match = error.message.match(SIGNATURE_REGEX);
80
+ if (match)
81
+ selector = match[1].toLowerCase();
82
+ }
83
+ if (!selector)
84
+ return prefix; // unable to determine
85
+ const decodedName = ERROR_SIGNATURE_MAP[selector]?.name ?? null;
86
+ // console.debug("Decoded", selector, decodedName);
87
+ return decodedName ? `${prefix} (${decodedName})` : prefix;
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raac/rpc",
3
- "version": "1.1.0-beta.52",
3
+ "version": "1.1.0-beta.54",
4
4
  "description": "RPC Library for RAAC ",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",