@defillama/sdk 5.0.9 → 5.0.11
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/build/Balances.d.ts +5 -0
- package/build/Balances.js +47 -107
- package/build/ChainApi.d.ts +1 -0
- package/build/ChainApi.js +152 -253
- package/build/abi/abi2.js +47 -144
- package/build/abi/convertResults.js +9 -29
- package/build/abi/index.js +220 -326
- package/build/abi/multicall.js +115 -217
- package/build/abi/multicall3.js +59 -123
- package/build/abi/rpcCall.js +43 -106
- package/build/abi/tron.js +153 -283
- package/build/api.js +3 -4
- package/build/computeTVL/humanizeNumber.js +6 -7
- package/build/computeTVL/prices.js +55 -145
- package/build/erc20/index.js +34 -122
- package/build/eth/index.js +37 -107
- package/build/general.js +22 -23
- package/build/generalUtil.js +72 -130
- package/build/index.js +2 -2
- package/build/providers.json +1 -1
- package/build/util/blocks.js +212 -371
- package/build/util/blockscout.js +13 -58
- package/build/util/cache.js +112 -274
- package/build/util/computeTVL.js +70 -150
- package/build/util/cosmos.js +21 -75
- package/build/util/debugLog.js +6 -14
- package/build/util/env.d.ts +1 -1
- package/build/util/env.js +24 -35
- package/build/util/index.js +72 -132
- package/build/util/internal-cache.js +7 -8
- package/build/util/logs.d.ts +1 -2
- package/build/util/logs.js +152 -225
- package/build/util/promisePool.js +11 -62
- package/build/util/r2.js +36 -95
- package/build/util/updateProviderList.js +23 -83
- package/package.json +2 -3
package/build/general.js
CHANGED
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setProvider = exports.ETHER_ADDRESS = exports.handleDecimals = exports.TEN = exports.getProvider = exports.providers = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function createProvider(name, rpcString, chainId) {
|
|
7
|
+
const debugLog_1 = require("./util/debugLog");
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const providers_json_1 = __importDefault(require("./providers.json"));
|
|
10
|
+
const env_1 = require("./util/env");
|
|
11
|
+
function createProvider(name, rpcString, chainId = 400069) {
|
|
12
12
|
chainId = (0, env_1.getChainId)(name, chainId);
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const networkish = { name, chainId };
|
|
14
|
+
const rpcList = rpcString.split(',');
|
|
15
15
|
if ((0, env_1.getEnvValue)('HISTORICAL')) {
|
|
16
16
|
if (chainId === 1) {
|
|
17
17
|
(0, debugLog_1.debugLog)("RPC providers set to historical, only the first RPC provider will be used");
|
|
@@ -20,7 +20,8 @@ function createProvider(name, rpcString, chainId) {
|
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
const providerList = rpcList.map((url, i) => ({ provider: getProviderObject(url, name), chainId, }));
|
|
24
|
+
return new ethers_1.ethers.FallbackProvider(providerList, networkish, { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, });
|
|
24
25
|
}
|
|
25
26
|
catch (e) {
|
|
26
27
|
// debugLog(`Error creating provider for ${name} with RPCs: ${rpcList.join(', ')}`)
|
|
@@ -70,8 +71,8 @@ function createProvider(name, rpcString, chainId) {
|
|
|
70
71
|
*/
|
|
71
72
|
// const batchMaxSize = 10 * (1024 * 1024) // 10Mb
|
|
72
73
|
// some rpcs throw error if batchMaxCount is set higher than 100
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const batchMaxCount = (0, env_1.getBatchMaxCount)(chain);
|
|
75
|
+
const jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42, batchMaxCount, };
|
|
75
76
|
if (url.startsWith('wss://')) {
|
|
76
77
|
delete jsonRpcApiProviderOptions.batchMaxCount;
|
|
77
78
|
return new ethers_1.ethers.WebSocketProvider(url, networkish, jsonRpcApiProviderOptions);
|
|
@@ -80,28 +81,26 @@ function createProvider(name, rpcString, chainId) {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
exports.providers = {};
|
|
83
|
-
|
|
84
|
-
function getProvider(chain, getArchivalNode) {
|
|
84
|
+
const archivalProviders = {};
|
|
85
|
+
function getProvider(chain = "ethereum", getArchivalNode = false) {
|
|
85
86
|
var _a, _b, _c;
|
|
86
|
-
if (chain === void 0) { chain = "ethereum"; }
|
|
87
|
-
if (getArchivalNode === void 0) { getArchivalNode = false; }
|
|
88
87
|
if (getArchivalNode) {
|
|
89
88
|
if (archivalProviders[chain])
|
|
90
89
|
return archivalProviders[chain]._provider;
|
|
91
|
-
|
|
92
|
-
if (
|
|
90
|
+
let rpcList = (0, env_1.getArchivalRPCs)(chain);
|
|
91
|
+
if (rpcList.length) {
|
|
93
92
|
// shuffle rpcList
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
archivalProviders[chain] = { rpcList:
|
|
93
|
+
rpcList = rpcList.sort(() => Math.random() - 0.5);
|
|
94
|
+
const provider = createProvider(chain, rpcList.join(','), (_a = providers_json_1.default[chain]) === null || _a === void 0 ? void 0 : _a.chainId);
|
|
95
|
+
if (rpcList.length === 1)
|
|
96
|
+
archivalProviders[chain] = { rpcList: rpcList[0], _provider: provider };
|
|
98
97
|
return provider;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
if (exports.providers[chain] && !getArchivalNode)
|
|
102
101
|
return exports.providers[chain]._provider;
|
|
103
102
|
// use RPC from env variable if set else use RPC from providers.json
|
|
104
|
-
|
|
103
|
+
let rpcList = (0, env_1.getChainRPCs)(chain, (_b = providers_json_1.default[chain]) === null || _b === void 0 ? void 0 : _b.rpc);
|
|
105
104
|
if (!rpcList) {
|
|
106
105
|
// in case provider was set using `setProvider` function
|
|
107
106
|
if (exports.providers[chain])
|
|
@@ -111,7 +110,7 @@ function getProvider(chain, getArchivalNode) {
|
|
|
111
110
|
}
|
|
112
111
|
if (!exports.providers[chain] || exports.providers[chain].rpcList !== rpcList) {
|
|
113
112
|
exports.providers[chain] = {
|
|
114
|
-
rpcList
|
|
113
|
+
rpcList,
|
|
115
114
|
_provider: createProvider(chain, rpcList, (_c = providers_json_1.default[chain]) === null || _c === void 0 ? void 0 : _c.chainId)
|
|
116
115
|
};
|
|
117
116
|
}
|
|
@@ -126,7 +125,7 @@ function handleDecimals(num, decimals) {
|
|
|
126
125
|
return num.toString();
|
|
127
126
|
}
|
|
128
127
|
else {
|
|
129
|
-
return Number(num / (
|
|
128
|
+
return Number(num / (10 ** decimals)).toString();
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
exports.handleDecimals = handleDecimals;
|
package/build/generalUtil.js
CHANGED
|
@@ -22,52 +22,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
26
|
exports.formError = exports.formErrorString = exports.getProviderUrl = exports.getUniqueAddresses = exports.humanizeNumber = exports.blocks = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = exports.convertToBigInt = void 0;
|
|
63
|
-
|
|
27
|
+
const blocks = __importStar(require("./computeTVL/blocks"));
|
|
64
28
|
exports.blocks = blocks;
|
|
65
|
-
|
|
29
|
+
const humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
|
|
66
30
|
exports.humanizeNumber = humanizeNumber;
|
|
67
|
-
|
|
31
|
+
const ethers = __importStar(require("ethers"));
|
|
68
32
|
// We ignore `sum` as it's never used (only in some SDK wrapper code)
|
|
69
33
|
function convertToBigInt(value) {
|
|
70
|
-
|
|
34
|
+
const balance = value;
|
|
71
35
|
if (!value)
|
|
72
36
|
return BigInt(0);
|
|
73
37
|
if (typeof value === 'bigint')
|
|
@@ -76,10 +40,10 @@ function convertToBigInt(value) {
|
|
|
76
40
|
value = value.toString();
|
|
77
41
|
if (typeof value === 'string') {
|
|
78
42
|
if (!value.startsWith('0x') && value.includes('e')) { // Convert scientific notation to standard notation
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
43
|
+
let [base, e] = value.split('e');
|
|
44
|
+
const [lead, decimal] = base.split('.');
|
|
45
|
+
let final;
|
|
46
|
+
let exponent = +e;
|
|
83
47
|
if (exponent >= 0) {
|
|
84
48
|
final = lead + (decimal || '') + '0'.repeat(exponent - (decimal || '').length);
|
|
85
49
|
}
|
|
@@ -94,17 +58,15 @@ function convertToBigInt(value) {
|
|
|
94
58
|
}
|
|
95
59
|
if (typeof value === 'string')
|
|
96
60
|
return BigInt(value);
|
|
97
|
-
throw new Error(
|
|
61
|
+
throw new Error(`Invalid balance: ${balance}`);
|
|
98
62
|
}
|
|
99
63
|
exports.convertToBigInt = convertToBigInt;
|
|
100
|
-
function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transformAddress) {
|
|
101
|
-
|
|
102
|
-
if (transformAddress === void 0) { transformAddress = function (addr) { return addr; }; }
|
|
103
|
-
results.output.map(function (result) {
|
|
64
|
+
function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful = true, transformAddress = (addr) => addr) {
|
|
65
|
+
results.output.map((result) => {
|
|
104
66
|
var _a;
|
|
105
67
|
if (result.success) {
|
|
106
|
-
|
|
107
|
-
|
|
68
|
+
const address = transformAddress(result.input.target);
|
|
69
|
+
const balance = result.output;
|
|
108
70
|
if (BigInt(balance) <= 0) {
|
|
109
71
|
return;
|
|
110
72
|
}
|
|
@@ -112,7 +74,7 @@ function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transfor
|
|
|
112
74
|
}
|
|
113
75
|
else if (allCallsMustBeSuccessful) {
|
|
114
76
|
console.error(result);
|
|
115
|
-
throw new Error(
|
|
77
|
+
throw new Error(`balanceOf multicall failed`);
|
|
116
78
|
}
|
|
117
79
|
});
|
|
118
80
|
}
|
|
@@ -124,7 +86,7 @@ function sumSingleBalance(balances, token, balance, chain) {
|
|
|
124
86
|
if (+balance === 0)
|
|
125
87
|
return;
|
|
126
88
|
if (chain)
|
|
127
|
-
token =
|
|
89
|
+
token = `${chain}:${token}`;
|
|
128
90
|
if (typeof balance === 'object') {
|
|
129
91
|
if (typeof balance.toString === 'function')
|
|
130
92
|
balance = balance.toString();
|
|
@@ -132,16 +94,16 @@ function sumSingleBalance(balances, token, balance, chain) {
|
|
|
132
94
|
throw new Error('Invalid balance value:' + balance);
|
|
133
95
|
}
|
|
134
96
|
if (typeof balance === 'number' || (balances[token] && typeof balances[token] === 'number')) {
|
|
135
|
-
|
|
97
|
+
const prevBalance = +(balances.hasOwnProperty(token) ? balances[token] : 0);
|
|
136
98
|
if (typeof prevBalance !== 'number' || isNaN(prevBalance))
|
|
137
|
-
throw new Error(
|
|
138
|
-
|
|
99
|
+
throw new Error(`Trying to merge token balance and coingecko amount for ${token} current balance: ${balance} previous balance: ${balances[token]}`);
|
|
100
|
+
const value = prevBalance + +balance;
|
|
139
101
|
isValidNumber(value);
|
|
140
102
|
balances[token] = value;
|
|
141
103
|
}
|
|
142
104
|
else {
|
|
143
|
-
|
|
144
|
-
|
|
105
|
+
const prevBalance = convertToBigInt(balances[token]);
|
|
106
|
+
const value = (prevBalance + convertToBigInt(balance));
|
|
145
107
|
isValidNumber(Number(value));
|
|
146
108
|
balances[token] = Number(value).toString();
|
|
147
109
|
}
|
|
@@ -149,22 +111,21 @@ function sumSingleBalance(balances, token, balance, chain) {
|
|
|
149
111
|
if (typeof value === 'bigint')
|
|
150
112
|
return;
|
|
151
113
|
if ([null, undefined].includes(value) || isNaN(+value))
|
|
152
|
-
throw new Error(
|
|
114
|
+
throw new Error(`Invalid balance: ${balance}`);
|
|
153
115
|
}
|
|
154
116
|
}
|
|
155
117
|
exports.sumSingleBalance = sumSingleBalance;
|
|
156
118
|
function mergeBalances(balances, balancesToMerge) {
|
|
157
119
|
if (balances === balancesToMerge)
|
|
158
120
|
return;
|
|
159
|
-
Object.entries(balancesToMerge).forEach(
|
|
121
|
+
Object.entries(balancesToMerge).forEach((balance) => {
|
|
160
122
|
sumSingleBalance(balances, balance[0], balance[1]);
|
|
161
123
|
});
|
|
162
124
|
}
|
|
163
125
|
exports.mergeBalances = mergeBalances;
|
|
164
|
-
function removeTokenBalance(balances, token, isCaseSensitive) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
Object.keys(balances).forEach(function (key) {
|
|
126
|
+
function removeTokenBalance(balances, token, isCaseSensitive = false) {
|
|
127
|
+
const re = new RegExp(token, isCaseSensitive ? undefined : 'i');
|
|
128
|
+
Object.keys(balances).forEach(key => {
|
|
168
129
|
if (re.test(key))
|
|
169
130
|
delete balances[key];
|
|
170
131
|
});
|
|
@@ -172,41 +133,23 @@ function removeTokenBalance(balances, token, isCaseSensitive) {
|
|
|
172
133
|
}
|
|
173
134
|
exports.removeTokenBalance = removeTokenBalance;
|
|
174
135
|
function sumChainTvls(chainTvls) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return [4 /*yield*/, Promise.all(chainTvls.map(function (chainTvl) { return __awaiter(_this, void 0, void 0, function () {
|
|
184
|
-
var chainBalances;
|
|
185
|
-
return __generator(this, function (_a) {
|
|
186
|
-
switch (_a.label) {
|
|
187
|
-
case 0: return [4 /*yield*/, chainTvl(timestamp, ethBlock, chainBlocks, params)];
|
|
188
|
-
case 1:
|
|
189
|
-
chainBalances = _a.sent();
|
|
190
|
-
api.addBalances(chainBalances);
|
|
191
|
-
return [2 /*return*/];
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}); }))];
|
|
195
|
-
case 1:
|
|
196
|
-
_a.sent();
|
|
197
|
-
return [2 /*return*/, api.getBalances()];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}); };
|
|
136
|
+
return async (timestamp, ethBlock, chainBlocks, params) => {
|
|
137
|
+
const api = params.api;
|
|
138
|
+
await Promise.all(chainTvls.map(async (chainTvl) => {
|
|
139
|
+
const chainBalances = await chainTvl(timestamp, ethBlock, chainBlocks, params);
|
|
140
|
+
api.addBalances(chainBalances);
|
|
141
|
+
}));
|
|
142
|
+
return api.getBalances();
|
|
143
|
+
};
|
|
201
144
|
}
|
|
202
145
|
exports.sumChainTvls = sumChainTvls;
|
|
203
146
|
function getUniqueAddresses(addresses, chain) {
|
|
204
147
|
if (!addresses.length)
|
|
205
148
|
return [];
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
addresses.forEach(
|
|
149
|
+
const isTronAddress = chain === 'tron' && addresses[0].startsWith('T');
|
|
150
|
+
const toLowerCase = !isTronAddress;
|
|
151
|
+
const set = {};
|
|
152
|
+
addresses.forEach(i => set[toLowerCase ? i.toLowerCase() : i] = true);
|
|
210
153
|
return Object.keys(set);
|
|
211
154
|
}
|
|
212
155
|
exports.getUniqueAddresses = getUniqueAddresses;
|
|
@@ -218,39 +161,39 @@ function getProviderUrl(provider) {
|
|
|
218
161
|
return '';
|
|
219
162
|
}
|
|
220
163
|
exports.getProviderUrl = getProviderUrl;
|
|
221
|
-
function formErrorString(e, errorParams) {
|
|
222
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
223
|
-
if (errorParams === void 0) { errorParams = {}; }
|
|
164
|
+
function formErrorString(e, errorParams = {}) {
|
|
165
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
224
166
|
if (!e) {
|
|
225
167
|
if (errorParams.promisePoolErrors) {
|
|
226
|
-
|
|
227
|
-
return
|
|
168
|
+
const errors = errorParams.promisePoolErrors.map((i) => formErrorString(i));
|
|
169
|
+
return `Promise pool failed! \n ${errors.join('\n')}`;
|
|
228
170
|
}
|
|
229
171
|
if (errorParams.isMultiCallError) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
(_c = errorParams.failedQueries) === null || _c === void 0 ? void 0 : _c.forEach(
|
|
172
|
+
const targetStr = errorParams.target ? `[target: ${errorParams.target}]` : '';
|
|
173
|
+
let errorString = `Multicall failed! \n [chain: ${(_a = errorParams.chain) !== null && _a !== void 0 ? _a : "ethereum"}] [fail count: ${(_b = errorParams.failedQueries) === null || _b === void 0 ? void 0 : _b.length}] [abi: ${errorParams.abi}] ${targetStr} `;
|
|
174
|
+
(_c = errorParams.failedQueries) === null || _c === void 0 ? void 0 : _c.forEach((i) => {
|
|
233
175
|
i = i.input;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
176
|
+
let target = !targetStr ? ` target: ${i.target}` : '';
|
|
177
|
+
let params = i.params && i.params.length ? `params: ${i.params.length === 1 ? i.params[0] : i.params.join(', ')}]` : '';
|
|
178
|
+
errorString += `\n ${target} ${params}`;
|
|
237
179
|
});
|
|
238
180
|
// truncate error string to 310 chars
|
|
239
|
-
return
|
|
181
|
+
return errorString.length > 310 ? errorString.slice(0, 310).concat('...') : errorString;
|
|
240
182
|
}
|
|
241
183
|
return '';
|
|
242
184
|
}
|
|
243
|
-
|
|
185
|
+
let errorString = e.toString();
|
|
244
186
|
if (typeof e !== 'object')
|
|
245
187
|
return errorString;
|
|
246
188
|
if (((e.reason || e.method || e.shortMessage) && e.code) || errorParams.result === '0x') { // ethers.js error
|
|
247
|
-
|
|
189
|
+
const errorMessage = (_k = (_j = (_h = (_g = (_f = (_e = (_d = e.info) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : e.message) !== null && _g !== void 0 ? _g : e.shortMessage) !== null && _h !== void 0 ? _h : e.errorName) !== null && _j !== void 0 ? _j : e.reason) !== null && _k !== void 0 ? _k : '';
|
|
190
|
+
let method = (_p = (_l = e.method) !== null && _l !== void 0 ? _l : (_o = (_m = e.info) === null || _m === void 0 ? void 0 : _m.request) === null || _o === void 0 ? void 0 : _o.method) !== null && _p !== void 0 ? _p : errorParams.abi;
|
|
248
191
|
if (e.body) {
|
|
249
192
|
try {
|
|
250
193
|
e.body = JSON.parse(e.body);
|
|
251
194
|
}
|
|
252
195
|
catch (e) { }
|
|
253
|
-
if ((
|
|
196
|
+
if ((_r = (_q = e.body) === null || _q === void 0 ? void 0 : _q.error) === null || _r === void 0 ? void 0 : _r.message)
|
|
254
197
|
return e.body.error.message;
|
|
255
198
|
}
|
|
256
199
|
if (!method && e.requestBody) {
|
|
@@ -258,55 +201,54 @@ function formErrorString(e, errorParams) {
|
|
|
258
201
|
e.requestBody = JSON.parse(e.requestBody);
|
|
259
202
|
}
|
|
260
203
|
catch (e) { }
|
|
261
|
-
method = (
|
|
204
|
+
method = (_s = e.requestBody) === null || _s === void 0 ? void 0 : _s.method;
|
|
262
205
|
}
|
|
263
206
|
else if (!e.provider && errorParams.provider)
|
|
264
207
|
e.provider = errorParams.provider;
|
|
265
|
-
|
|
208
|
+
let providerUrl = getProviderUrl((_t = e.provider) !== null && _t !== void 0 ? _t : errorParams.provider);
|
|
266
209
|
if (e.serverError)
|
|
267
|
-
return
|
|
210
|
+
return `host: ${providerUrl} ${e.serverError.toString()}`;
|
|
268
211
|
if (e.results) {
|
|
269
|
-
|
|
212
|
+
let errors = e.results.filter((i) => i.error).map((i) => i.error);
|
|
270
213
|
if (errors.length) {
|
|
271
|
-
|
|
272
|
-
return
|
|
214
|
+
const eStrings = errors.map((i) => formError(i));
|
|
215
|
+
return `Failed to call method: ${method} provider: ${providerUrl}
|
|
216
|
+
${eStrings.join('\n')}`;
|
|
273
217
|
}
|
|
274
218
|
}
|
|
275
219
|
else if (e.code === 'CALL_EXCEPTION' || errorParams.isCallError) {
|
|
276
|
-
|
|
220
|
+
let extraInfo = 'target: ' + errorParams.target;
|
|
277
221
|
if (errorParams.params && Array.isArray(errorParams.params) && errorParams.params.length)
|
|
278
222
|
extraInfo += shortenString(' params: ' + errorParams.params.join(', '));
|
|
279
|
-
return
|
|
223
|
+
return `Failed to call: ${method} ${extraInfo} on chain: [${errorParams.chain}] rpc: ${providerUrl} call reverted, reason: ${errorMessage} ${(_u = e.errorArgs) !== null && _u !== void 0 ? _u : ''}`;
|
|
280
224
|
}
|
|
281
225
|
else if (e.code === 'BAD_DATA') {
|
|
282
226
|
if (!method)
|
|
283
|
-
method = (
|
|
284
|
-
|
|
285
|
-
return
|
|
227
|
+
method = (_w = (_v = e === null || e === void 0 ? void 0 : e.info) === null || _v === void 0 ? void 0 : _v.payload) === null || _w === void 0 ? void 0 : _w.method;
|
|
228
|
+
let extraInfo = 'target: ' + errorParams.target;
|
|
229
|
+
return `Failed method: ${method} ${shortenString(extraInfo)} on chain: [${errorParams.chain}] rpc: ${providerUrl} reason: ${errorMessage} ${(_x = e.errorArgs) !== null && _x !== void 0 ? _x : ''}`;
|
|
286
230
|
}
|
|
287
231
|
if (method === 'eth_blockNumber')
|
|
288
|
-
return
|
|
232
|
+
return `host: ${providerUrl} reason: ${e.reason} code: ${e.code}`;
|
|
289
233
|
if (method === 'getBlockNumber')
|
|
290
|
-
return
|
|
291
|
-
return
|
|
234
|
+
return `Failed to call ${method} ${providerUrl} reason: ${e.reason} code: ${e.code}`;
|
|
235
|
+
return `Failed to call ${method} on ${providerUrl} reason: ${e.reason} code: ${e.code}`;
|
|
292
236
|
}
|
|
293
237
|
return errorString;
|
|
294
238
|
}
|
|
295
239
|
exports.formErrorString = formErrorString;
|
|
296
|
-
function shortenString(str, length) {
|
|
297
|
-
if (length === void 0) { length = 150; }
|
|
240
|
+
function shortenString(str, length = 150) {
|
|
298
241
|
return str.length > length ? str.slice(0, length).concat('...') : str;
|
|
299
242
|
}
|
|
300
|
-
function formError(e, errorParams) {
|
|
243
|
+
function formError(e, errorParams = {}) {
|
|
301
244
|
var _a;
|
|
302
|
-
|
|
303
|
-
var errorParamsSet = Object.keys(errorParams).length;
|
|
245
|
+
const errorParamsSet = Object.keys(errorParams).length;
|
|
304
246
|
if ((e === null || e === void 0 ? void 0 : e._isCustomError) || (!errorParamsSet && typeof e === 'object' && !Object.keys(e).length))
|
|
305
247
|
return e; // already formatted or vannila error
|
|
306
|
-
|
|
248
|
+
const error = new Error(formErrorString(e, errorParams));
|
|
307
249
|
try {
|
|
308
250
|
if (errorParams.isMultiCallError)
|
|
309
|
-
error._underlyingErrors = (_a = errorParams === null || errorParams === void 0 ? void 0 : errorParams.failedQueries) === null || _a === void 0 ? void 0 : _a.map(
|
|
251
|
+
error._underlyingErrors = (_a = errorParams === null || errorParams === void 0 ? void 0 : errorParams.failedQueries) === null || _a === void 0 ? void 0 : _a.map((i) => shortenString(i.error.toString()));
|
|
310
252
|
else
|
|
311
253
|
error._underlyingError = shortenString(e.toString());
|
|
312
254
|
}
|
package/build/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.humanizeNumber = exports.logTable = exports.log = exports.blocks = exports.api2 = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
|
|
27
|
-
|
|
27
|
+
const debugLog_1 = require("./util/debugLog");
|
|
28
28
|
var ChainApi_1 = require("./ChainApi");
|
|
29
29
|
Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
|
|
30
30
|
var Balances_1 = require("./Balances");
|
|
@@ -40,7 +40,7 @@ exports.sdkCache = __importStar(require("./util/internal-cache"));
|
|
|
40
40
|
exports.api = __importStar(require("./api"));
|
|
41
41
|
exports.api2 = __importStar(require("./api2"));
|
|
42
42
|
exports.blocks = __importStar(require("./computeTVL/blocks"));
|
|
43
|
-
|
|
43
|
+
const humanN = __importStar(require("./computeTVL/humanizeNumber"));
|
|
44
44
|
exports.log = debugLog_1.debugLog;
|
|
45
45
|
exports.logTable = debugLog_1.debugTable;
|
|
46
46
|
exports.humanizeNumber = humanN.humanizeNumber;
|