@defillama/sdk 5.0.4 → 5.0.6
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/ChainApi.d.ts +1 -1
- package/build/abi/index.js +8 -2
- package/build/general.js +3 -3
- package/build/generalUtil.d.ts +1 -0
- package/build/generalUtil.js +43 -36
- package/build/providers.json +1 -1
- package/build/util/cache.js +4 -1
- package/build/util/index.d.ts +2 -1
- package/build/util/index.js +13 -7
- package/build/util/logs.d.ts +5 -4
- package/build/util/logs.js +65 -31
- package/package.json +1 -1
package/build/ChainApi.d.ts
CHANGED
|
@@ -56,6 +56,6 @@ export declare class ChainApi {
|
|
|
56
56
|
usdTokenBalances: BalancesV1;
|
|
57
57
|
rawTokenBalances: BalancesV1;
|
|
58
58
|
}>;
|
|
59
|
-
getLogs(params: GetLogsOptions): Promise<any[] | import("ethers").EventLog[]>;
|
|
59
|
+
getLogs(params: GetLogsOptions): Promise<any[] | import("ethers").EventLog[] | import("ethers").EventLog[][]>;
|
|
60
60
|
}
|
|
61
61
|
export default ChainApi;
|
package/build/abi/index.js
CHANGED
|
@@ -101,7 +101,13 @@ var knownTypes = [
|
|
|
101
101
|
'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
|
102
102
|
];
|
|
103
103
|
(__spreadArray([], knownTypes, true)).forEach(function (i) { return knownTypes.push(i + '[]'); }); // support array type for all known types
|
|
104
|
-
|
|
104
|
+
function getDefaultChunkSize(chain) {
|
|
105
|
+
if (process.env['SDK_MULTICALL_CHUNK_SIZE_' + (chain === null || chain === void 0 ? void 0 : chain.toUpperCase())])
|
|
106
|
+
return +process.env['SDK_MULTICALL_CHUNK_SIZE_' + (chain === null || chain === void 0 ? void 0 : chain.toUpperCase())];
|
|
107
|
+
if (chain === 'cronos')
|
|
108
|
+
return 200;
|
|
109
|
+
return process.env.SDK_MULTICALL_CHUNK_SIZE ? +process.env.SDK_MULTICALL_CHUNK_SIZE : 300;
|
|
110
|
+
}
|
|
105
111
|
function resolveABI(providedAbi) {
|
|
106
112
|
if (!providedAbi)
|
|
107
113
|
throw new Error('Missing ABI parameter!');
|
|
@@ -265,7 +271,7 @@ function multiCall(params) {
|
|
|
265
271
|
chunkSize = params.chunkSize;
|
|
266
272
|
if (!params.chunkSize) {
|
|
267
273
|
// Only a max of around 500 calls are supported by multicall, we have to split bigger batches
|
|
268
|
-
chunkSize =
|
|
274
|
+
chunkSize = getDefaultChunkSize(chain);
|
|
269
275
|
}
|
|
270
276
|
if (!params.target && !params.permitFailure) {
|
|
271
277
|
// check if target adddress is missing for one of the calls
|
package/build/general.js
CHANGED
|
@@ -20,7 +20,7 @@ function createProvider(name, rpcString, chainId) {
|
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
try {
|
|
23
|
-
return new ethers_1.ethers.FallbackProvider(rpcList.map(function (url, i) { return ({ provider: getProviderObject(url), priority: i, chainId: chainId, }); }), networkish, { cacheTimeout: 5 * 1000, quorum: 1,
|
|
23
|
+
return new ethers_1.ethers.FallbackProvider(rpcList.map(function (url, i) { return ({ provider: getProviderObject(url), priority: i, chainId: chainId, }); }), networkish, { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, });
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
// debugLog(`Error creating provider for ${name} with RPCs: ${rpcList.join(', ')}`)
|
|
@@ -68,9 +68,9 @@ function createProvider(name, rpcString, chainId) {
|
|
|
68
68
|
* disable, ``0`` will only buffer within the same event loop and
|
|
69
69
|
* any other value is in ms. (default: ``250``)
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
// const batchMaxSize = 10 * (1024 * 1024) // 10Mb
|
|
72
72
|
// some rpcs throw error if batchMaxCount is set higher than 100
|
|
73
|
-
var jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42,
|
|
73
|
+
var jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42, batchMaxCount: 99, cacheTimeout: 5 * 1000 };
|
|
74
74
|
if (url.startsWith('wss://')) {
|
|
75
75
|
delete jsonRpcApiProviderOptions.batchMaxCount;
|
|
76
76
|
return new ethers_1.ethers.WebSocketProvider(url, networkish, jsonRpcApiProviderOptions);
|
package/build/generalUtil.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as blocks from "./computeTVL/blocks";
|
|
2
2
|
import * as humanizeNumber from "./computeTVL/humanizeNumber";
|
|
3
3
|
import type { Balances, StringNumber, Address } from "./types";
|
|
4
|
+
export declare function convertToBigInt(value: any): bigint;
|
|
4
5
|
export declare function sumMultiBalanceOf(balances: Balances, results: {
|
|
5
6
|
ethCallCount?: number;
|
|
6
7
|
output: {
|
package/build/generalUtil.js
CHANGED
|
@@ -59,13 +59,44 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.formError = exports.formErrorString = exports.getProviderUrl = exports.getUniqueAddresses = exports.humanizeNumber = exports.blocks = exports.sumChainTvls = exports.removeTokenBalance = exports.mergeBalances = exports.sumSingleBalance = exports.sumMultiBalanceOf = void 0;
|
|
62
|
+
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
63
|
var blocks = __importStar(require("./computeTVL/blocks"));
|
|
64
64
|
exports.blocks = blocks;
|
|
65
65
|
var humanizeNumber = __importStar(require("./computeTVL/humanizeNumber"));
|
|
66
66
|
exports.humanizeNumber = humanizeNumber;
|
|
67
67
|
var ethers = __importStar(require("ethers"));
|
|
68
68
|
// We ignore `sum` as it's never used (only in some SDK wrapper code)
|
|
69
|
+
function convertToBigInt(value) {
|
|
70
|
+
var balance = value;
|
|
71
|
+
if (!value)
|
|
72
|
+
return BigInt(0);
|
|
73
|
+
if (typeof value === 'bigint')
|
|
74
|
+
return value;
|
|
75
|
+
if (typeof value === 'number')
|
|
76
|
+
value = value.toString();
|
|
77
|
+
if (typeof value === 'string') {
|
|
78
|
+
if (!value.startsWith('0x') && value.includes('e')) { // Convert scientific notation to standard notation
|
|
79
|
+
var _a = value.split('e'), base = _a[0], e = _a[1];
|
|
80
|
+
var _b = base.split('.'), lead = _b[0], decimal = _b[1];
|
|
81
|
+
var final = void 0;
|
|
82
|
+
var exponent = +e;
|
|
83
|
+
if (exponent >= 0) {
|
|
84
|
+
final = lead + (decimal || '') + '0'.repeat(exponent - (decimal || '').length);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// NOTE: unforutenately BigInt doesn't support negative exponents, so this ends up being 0
|
|
88
|
+
exponent = exponent * -1;
|
|
89
|
+
final = BigInt(lead) / BigInt('1' + Array(exponent).fill(0).join(''));
|
|
90
|
+
}
|
|
91
|
+
return BigInt(final);
|
|
92
|
+
}
|
|
93
|
+
return BigInt(value);
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'string')
|
|
96
|
+
return BigInt(value);
|
|
97
|
+
throw new Error("Invalid balance: ".concat(balance));
|
|
98
|
+
}
|
|
99
|
+
exports.convertToBigInt = convertToBigInt;
|
|
69
100
|
function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transformAddress) {
|
|
70
101
|
if (allCallsMustBeSuccessful === void 0) { allCallsMustBeSuccessful = true; }
|
|
71
102
|
if (transformAddress === void 0) { transformAddress = function (addr) { return addr; }; }
|
|
@@ -109,41 +140,11 @@ function sumSingleBalance(balances, token, balance, chain) {
|
|
|
109
140
|
balances[token] = value;
|
|
110
141
|
}
|
|
111
142
|
else {
|
|
112
|
-
var prevBalance =
|
|
113
|
-
var value = (prevBalance +
|
|
143
|
+
var prevBalance = convertToBigInt(balances[token]);
|
|
144
|
+
var value = (prevBalance + convertToBigInt(balance));
|
|
114
145
|
isValidNumber(Number(value));
|
|
115
146
|
balances[token] = Number(value).toString();
|
|
116
147
|
}
|
|
117
|
-
function getBigInt(value) {
|
|
118
|
-
var balance = value;
|
|
119
|
-
if (!value)
|
|
120
|
-
return BigInt(0);
|
|
121
|
-
if (typeof value === 'bigint')
|
|
122
|
-
return value;
|
|
123
|
-
if (typeof value === 'number')
|
|
124
|
-
value = value.toString();
|
|
125
|
-
if (typeof value === 'string') {
|
|
126
|
-
if (value.includes('e')) { // Convert scientific notation to standard notation
|
|
127
|
-
var _a = value.split('e'), base = _a[0], e = _a[1];
|
|
128
|
-
var _b = base.split('.'), lead = _b[0], decimal = _b[1];
|
|
129
|
-
var final = void 0;
|
|
130
|
-
var exponent = +e;
|
|
131
|
-
if (exponent >= 0) {
|
|
132
|
-
final = lead + (decimal || '') + '0'.repeat(exponent - (decimal || '').length);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
// NOTE: unforutenately BigInt doesn't support negative exponents, so this ends up being 0
|
|
136
|
-
exponent = exponent * -1;
|
|
137
|
-
final = BigInt(lead) / BigInt('1' + Array(exponent).fill(0).join(''));
|
|
138
|
-
}
|
|
139
|
-
return BigInt(final);
|
|
140
|
-
}
|
|
141
|
-
return BigInt(value);
|
|
142
|
-
}
|
|
143
|
-
if (typeof value === 'string')
|
|
144
|
-
return BigInt(value);
|
|
145
|
-
throw new Error("Invalid balance: ".concat(balance));
|
|
146
|
-
}
|
|
147
148
|
function isValidNumber(value) {
|
|
148
149
|
if (typeof value === 'bigint')
|
|
149
150
|
return;
|
|
@@ -218,7 +219,7 @@ function getProviderUrl(provider) {
|
|
|
218
219
|
}
|
|
219
220
|
exports.getProviderUrl = getProviderUrl;
|
|
220
221
|
function formErrorString(e, errorParams) {
|
|
221
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
222
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
222
223
|
if (errorParams === void 0) { errorParams = {}; }
|
|
223
224
|
if (!e) {
|
|
224
225
|
if (errorParams.promisePoolErrors) {
|
|
@@ -273,10 +274,16 @@ function formErrorString(e, errorParams) {
|
|
|
273
274
|
}
|
|
274
275
|
else if (e.code === 'CALL_EXCEPTION' || errorParams.isCallError) {
|
|
275
276
|
var extraInfo = 'target: ' + errorParams.target;
|
|
276
|
-
if (errorParams.params && errorParams.params.length)
|
|
277
|
+
if (errorParams.params && Array.isArray(errorParams.params) && errorParams.params.length)
|
|
277
278
|
extraInfo += shortenString(' params: ' + errorParams.params.join(', '));
|
|
278
279
|
return "Failed to call: ".concat(method, " ").concat(extraInfo, " on chain: [").concat(errorParams.chain, "] rpc: ").concat(providerUrl, " call reverted, reason: ").concat((_o = (_m = e.errorName) !== null && _m !== void 0 ? _m : e.shortMessage) !== null && _o !== void 0 ? _o : '', " ").concat((_p = e.errorArgs) !== null && _p !== void 0 ? _p : '');
|
|
279
280
|
}
|
|
281
|
+
else if (e.code === 'BAD_DATA') {
|
|
282
|
+
if (!method)
|
|
283
|
+
method = (_r = (_q = e === null || e === void 0 ? void 0 : e.info) === null || _q === void 0 ? void 0 : _q.payload) === null || _r === void 0 ? void 0 : _r.method;
|
|
284
|
+
var extraInfo = 'target: ' + errorParams.target;
|
|
285
|
+
return "Failed method: ".concat(method, " ").concat(shortenString(extraInfo), " on chain: [").concat(errorParams.chain, "] rpc: ").concat(providerUrl, " reason: ").concat((_u = (_t = (_s = e.errorName) !== null && _s !== void 0 ? _s : e.shortMessage) !== null && _t !== void 0 ? _t : e.message) !== null && _u !== void 0 ? _u : '', " ").concat((_v = e.errorArgs) !== null && _v !== void 0 ? _v : '');
|
|
286
|
+
}
|
|
280
287
|
if (method === 'eth_blockNumber')
|
|
281
288
|
return "host: ".concat(providerUrl, " reason: ").concat(e.reason, " code: ").concat(e.code);
|
|
282
289
|
if (method === 'getBlockNumber')
|
|
@@ -305,7 +312,7 @@ function formError(e, errorParams) {
|
|
|
305
312
|
}
|
|
306
313
|
catch (e) { }
|
|
307
314
|
error._isCustomError = true;
|
|
308
|
-
error.message = shortenString(error.message,
|
|
315
|
+
error.message = shortenString(error.message, 999);
|
|
309
316
|
error.stack = '';
|
|
310
317
|
return error;
|
|
311
318
|
}
|