@raac/rpc 1.1.0-beta.53 → 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.
package/dist/RPCLibrary.js
CHANGED
|
@@ -120,6 +120,7 @@ const vaultOpened_1 = __importDefault(require("./pools/lendingPool/vaultOpened")
|
|
|
120
120
|
const getWithdrawRequestInfo_2 = require("./pools/stabilityPool/getWithdrawRequestInfo");
|
|
121
121
|
const requestWithdraw_2 = require("./pools/stabilityPool/requestWithdraw");
|
|
122
122
|
const artifacts_1 = require("./utils/artifacts");
|
|
123
|
+
const errorDecoder_1 = require("./utils/errorDecoder");
|
|
123
124
|
class RPCLibrary {
|
|
124
125
|
signer;
|
|
125
126
|
isConnected;
|
|
@@ -139,6 +140,7 @@ class RPCLibrary {
|
|
|
139
140
|
checkAllowance;
|
|
140
141
|
getChainsConfig;
|
|
141
142
|
setChainsConfig;
|
|
143
|
+
errors;
|
|
142
144
|
constructor(privateKey) {
|
|
143
145
|
this.signer = null;
|
|
144
146
|
this.isConnected = false;
|
|
@@ -282,6 +284,11 @@ class RPCLibrary {
|
|
|
282
284
|
createZeno: createZeno_1.default,
|
|
283
285
|
getZenos: getZenos_1.default,
|
|
284
286
|
};
|
|
287
|
+
this.errors = {
|
|
288
|
+
decodeErrorName: errorDecoder_1.decodeErrorName,
|
|
289
|
+
getErrorInfo: errorDecoder_1.getErrorInfo,
|
|
290
|
+
attachDecodedError: errorDecoder_1.attachDecodedError,
|
|
291
|
+
};
|
|
285
292
|
}
|
|
286
293
|
async getWallet(privateKey, provider) {
|
|
287
294
|
// @ts-ignore
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const _helpers_1 = require("./_helpers");
|
|
5
|
+
const errorDecoder_1 = require("../../utils/errorDecoder");
|
|
5
6
|
// checked
|
|
6
7
|
async function depositToLendingPool(chainId, amount, signer) {
|
|
7
8
|
if (!signer) {
|
|
@@ -22,7 +23,8 @@ async function depositToLendingPool(chainId, amount, signer) {
|
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
25
|
console.error(`Lending Pool Deposit error:`, error);
|
|
25
|
-
|
|
26
|
+
const message = (0, errorDecoder_1.attachDecodedError)("Lending Pool Deposit failed", error);
|
|
27
|
+
throw new Error(`${message}: ${error.message}`);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
exports.default = depositToLendingPool;
|
package/dist/scripts/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const RPCLibrary_1 = __importDefault(require("../RPCLibrary"));
|
|
|
10
10
|
const contracts_1 = require("../utils/contracts");
|
|
11
11
|
const artifacts_1 = require("../utils/artifacts");
|
|
12
12
|
const _helpers_1 = require("../pools/rwaVault/_helpers");
|
|
13
|
+
const errorDecoder_1 = require("../utils/errorDecoder");
|
|
13
14
|
const chainId = 8453;
|
|
14
15
|
const config = chains_1.default[chainId];
|
|
15
16
|
const TEST_MNEMONIC = process.env.TEST_MNEMONIC;
|
|
@@ -33,6 +34,8 @@ async function createWallet(mnemonic, provider) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
async function setup() {
|
|
37
|
+
console.log((0, errorDecoder_1.decodeErrorName)("Encoded error signature 0xa9b65aba not found on ABI."));
|
|
38
|
+
return;
|
|
36
39
|
const provider = await getProvider();
|
|
37
40
|
const signer = await createWallet(TEST_MNEMONIC, provider);
|
|
38
41
|
const rpc = new RPCLibrary_1.default();
|
|
@@ -95,6 +95,7 @@ import vaultOpened from "./pools/lendingPool/vaultOpened";
|
|
|
95
95
|
import { getWithdrawRequestInfo as getStabilityPoolWithdrawRequestInfo } from "./pools/stabilityPool/getWithdrawRequestInfo";
|
|
96
96
|
import { requestWithdraw as requestStabilityPoolWithdraw } from "./pools/stabilityPool/requestWithdraw";
|
|
97
97
|
import { getABI } from "./utils/artifacts";
|
|
98
|
+
import { decodeErrorName, getErrorInfo, attachDecodedError } from "./utils/errorDecoder";
|
|
98
99
|
declare class RPCLibrary {
|
|
99
100
|
signer: Signer | null;
|
|
100
101
|
isConnected: boolean;
|
|
@@ -236,6 +237,11 @@ declare class RPCLibrary {
|
|
|
236
237
|
checkAllowance: typeof checkAllowance;
|
|
237
238
|
getChainsConfig: typeof getChainsConfig;
|
|
238
239
|
setChainsConfig: typeof setChainConfig;
|
|
240
|
+
errors: {
|
|
241
|
+
decodeErrorName: typeof decodeErrorName;
|
|
242
|
+
getErrorInfo: typeof getErrorInfo;
|
|
243
|
+
attachDecodedError: typeof attachDecodedError;
|
|
244
|
+
};
|
|
239
245
|
constructor(privateKey?: string);
|
|
240
246
|
getWallet(privateKey: string, provider: Provider): Promise<ethers.JsonRpcSigner | ethers.Wallet>;
|
|
241
247
|
getProvider(chainId: ChainId, providerRpc?: string): Promise<ethers.BrowserProvider | ethers.JsonRpcProvider>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface ErrorInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
signature: string;
|
|
4
|
+
abiItem: any;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns detailed information about the error encoded in the given data blob.
|
|
8
|
+
* @param data The revert data returned by the EVM (e.g., error.data).
|
|
9
|
+
*/
|
|
10
|
+
export declare function getErrorInfo(data?: string): ErrorInfo | null;
|
|
11
|
+
/**
|
|
12
|
+
* Returns only the error name, or null if it cannot be decoded.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeErrorName(data?: string): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Builds a user-friendly error prefix with decoded error name (if available).
|
|
17
|
+
* Usage example:
|
|
18
|
+
* const msg = attachDecodedError("Deposit failed", caughtError);
|
|
19
|
+
*/
|
|
20
|
+
export declare function attachDecodedError(prefix: string, error: any): string;
|
|
21
|
+
export {};
|
|
@@ -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
|
+
}
|