@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/abi/index.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,90 +22,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
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;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
74
|
-
if (ar || !(i in from)) {
|
|
75
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
76
|
-
ar[i] = from[i];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
80
|
-
};
|
|
81
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
82
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
83
27
|
};
|
|
84
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85
29
|
exports.multiCall = exports.bytecodeCall = exports.call = void 0;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
30
|
+
const cachedABIs_1 = __importDefault(require("./cachedABIs"));
|
|
31
|
+
const ethers_1 = require("ethers");
|
|
32
|
+
const general_1 = require("../general");
|
|
33
|
+
const multicall3_1 = __importDefault(require("./multicall3"));
|
|
34
|
+
const convertResults_1 = __importDefault(require("./convertResults"));
|
|
35
|
+
const debugLog_1 = require("../util/debugLog");
|
|
36
|
+
const internal_cache_1 = require("../util/internal-cache");
|
|
37
|
+
const util_1 = require("../util");
|
|
38
|
+
const Tron = __importStar(require("./tron"));
|
|
39
|
+
const generalUtil_1 = require("../generalUtil");
|
|
40
|
+
const env_1 = require("../util/env");
|
|
41
|
+
const nullAddress = '0x0000000000000000000000000000000000000000';
|
|
98
42
|
// https://docs.soliditylang.org/en/latest/abi-spec.html
|
|
99
|
-
|
|
43
|
+
const knownTypes = [
|
|
100
44
|
'string', 'address', 'bool',
|
|
101
45
|
'int', 'int8', 'int16', 'int32', 'int64', 'int128', 'int256',
|
|
102
46
|
'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
|
103
47
|
];
|
|
104
|
-
(
|
|
48
|
+
([...knownTypes]).forEach(i => knownTypes.push(i + '[]')); // support array type for all known types
|
|
105
49
|
function resolveABI(providedAbi) {
|
|
106
50
|
if (!providedAbi)
|
|
107
51
|
throw new Error('Missing ABI parameter!');
|
|
108
|
-
|
|
52
|
+
let abi = providedAbi;
|
|
109
53
|
if (typeof abi === "string") {
|
|
110
|
-
|
|
111
|
-
if (!knownTypes.includes(outputType) || !
|
|
112
|
-
|
|
113
|
-
|
|
54
|
+
const [outputType, name] = providedAbi.split(':');
|
|
55
|
+
if (!knownTypes.includes(outputType) || !name) {
|
|
56
|
+
const contractInterface = new ethers_1.ethers.Interface([providedAbi]);
|
|
57
|
+
const jsonAbi = contractInterface.formatJson();
|
|
114
58
|
return JSON.parse(jsonAbi)[0];
|
|
115
59
|
}
|
|
116
60
|
abi = {
|
|
117
61
|
constant: true,
|
|
118
62
|
inputs: [],
|
|
119
|
-
name
|
|
63
|
+
name,
|
|
120
64
|
outputs: [
|
|
121
65
|
{
|
|
122
66
|
internalType: outputType,
|
|
@@ -130,7 +74,10 @@ function resolveABI(providedAbi) {
|
|
|
130
74
|
};
|
|
131
75
|
}
|
|
132
76
|
// If type is omitted DP's sdk processes it fine but we don't, so we need to add it
|
|
133
|
-
return
|
|
77
|
+
return {
|
|
78
|
+
type: "function",
|
|
79
|
+
...abi,
|
|
80
|
+
};
|
|
134
81
|
}
|
|
135
82
|
function normalizeParams(params) {
|
|
136
83
|
if (params === undefined) {
|
|
@@ -144,7 +91,7 @@ function normalizeParams(params) {
|
|
|
144
91
|
}
|
|
145
92
|
}
|
|
146
93
|
function fixBlockTag(params) {
|
|
147
|
-
|
|
94
|
+
let { block } = params;
|
|
148
95
|
if (typeof block !== 'string' || block === 'latest')
|
|
149
96
|
return;
|
|
150
97
|
block = +block;
|
|
@@ -159,269 +106,216 @@ function isValidTarget(target, chain) {
|
|
|
159
106
|
return true;
|
|
160
107
|
return target.startsWith('0x') && target !== nullAddress;
|
|
161
108
|
}
|
|
162
|
-
function call(params) {
|
|
109
|
+
async function call(params) {
|
|
163
110
|
var _a;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
callData = contractInterface.encodeFunctionData(functionABI, callParams);
|
|
188
|
-
provider = (0, general_1.getProvider)(chain);
|
|
189
|
-
errorParams.provider = provider;
|
|
190
|
-
return [4 /*yield*/, provider.call({
|
|
191
|
-
to: params.target,
|
|
192
|
-
data: callData,
|
|
193
|
-
blockTag: params.block,
|
|
194
|
-
})];
|
|
195
|
-
case 2:
|
|
196
|
-
result = _b.sent();
|
|
197
|
-
errorParams.result = result;
|
|
198
|
-
decodedResult = contractInterface.decodeFunctionResult(abi, result);
|
|
199
|
-
output = (0, convertResults_1.default)(decodedResult, functionABI);
|
|
200
|
-
if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
|
|
201
|
-
params.logArray.push({
|
|
202
|
-
chain: chain,
|
|
203
|
-
token: params.target,
|
|
204
|
-
holder: Array.isArray(params.params) ? params.params[0] : params.params,
|
|
205
|
-
amount: output
|
|
206
|
-
});
|
|
207
|
-
return [2 /*return*/, {
|
|
208
|
-
output: output,
|
|
209
|
-
}];
|
|
210
|
-
case 3:
|
|
211
|
-
e_1 = _b.sent();
|
|
212
|
-
errorParams.isCallError = true;
|
|
213
|
-
throw (0, generalUtil_1.formError)(e_1, errorParams);
|
|
214
|
-
case 4: return [2 /*return*/];
|
|
215
|
-
}
|
|
111
|
+
if (!isValidTarget(params.target, params.chain))
|
|
112
|
+
throw new Error('Invalid target: ' + params.target);
|
|
113
|
+
fixBlockTag(params);
|
|
114
|
+
const chain = (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum";
|
|
115
|
+
if (cachedABIs_1.default[params.abi])
|
|
116
|
+
params.abi = cachedABIs_1.default[params.abi];
|
|
117
|
+
let errorParams = { ...params };
|
|
118
|
+
try {
|
|
119
|
+
if (!params.skipCache)
|
|
120
|
+
return cachedCall(params);
|
|
121
|
+
const abi = resolveABI(params.abi);
|
|
122
|
+
const callParams = normalizeParams(params.params);
|
|
123
|
+
if (chain === 'tron')
|
|
124
|
+
return Tron.call({ ...params, abi, params: callParams });
|
|
125
|
+
const contractInterface = new ethers_1.ethers.Interface([abi]);
|
|
126
|
+
const functionABI = ethers_1.ethers.FunctionFragment.from(abi);
|
|
127
|
+
const callData = contractInterface.encodeFunctionData(functionABI, callParams);
|
|
128
|
+
const provider = (0, general_1.getProvider)(chain);
|
|
129
|
+
errorParams.provider = provider;
|
|
130
|
+
const result = await provider.call({
|
|
131
|
+
to: params.target,
|
|
132
|
+
data: callData,
|
|
133
|
+
blockTag: params.block,
|
|
216
134
|
});
|
|
217
|
-
|
|
135
|
+
errorParams.result = result;
|
|
136
|
+
const decodedResult = contractInterface.decodeFunctionResult(abi, result);
|
|
137
|
+
const output = (0, convertResults_1.default)(decodedResult, functionABI);
|
|
138
|
+
if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
|
|
139
|
+
params.logArray.push({
|
|
140
|
+
chain,
|
|
141
|
+
token: params.target,
|
|
142
|
+
holder: Array.isArray(params.params) ? params.params[0] : params.params,
|
|
143
|
+
amount: output
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
output,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
errorParams.isCallError = true;
|
|
151
|
+
throw (0, generalUtil_1.formError)(e, errorParams);
|
|
152
|
+
}
|
|
218
153
|
}
|
|
219
154
|
exports.call = call;
|
|
220
|
-
function bytecodeCall(params) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return [4 /*yield*/, (0, general_1.getProvider)(chain).call({ data: callData, blockTag: block })];
|
|
235
|
-
case 1:
|
|
236
|
-
result = _a.sent();
|
|
237
|
-
decodedResult = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(outputTypes, result);
|
|
238
|
-
return [2 /*return*/, {
|
|
239
|
-
output: (0, convertResults_1.default)(decodedResult),
|
|
240
|
-
}];
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
});
|
|
155
|
+
async function bytecodeCall(params) {
|
|
156
|
+
fixBlockTag(params);
|
|
157
|
+
const { block, bytecode, inputTypes, inputs, outputTypes, chain } = params;
|
|
158
|
+
if (!bytecode)
|
|
159
|
+
throw new Error('Missing bytecode parameter!');
|
|
160
|
+
if (chain === 'tron')
|
|
161
|
+
throw new Error('Bytecode call is not supported on Tron');
|
|
162
|
+
const inputData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(inputTypes, inputs);
|
|
163
|
+
const callData = '0x' + bytecode.concat(inputData.slice(2));
|
|
164
|
+
const result = await (0, general_1.getProvider)(chain).call({ data: callData, blockTag: block });
|
|
165
|
+
const decodedResult = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(outputTypes, result);
|
|
166
|
+
return {
|
|
167
|
+
output: (0, convertResults_1.default)(decodedResult),
|
|
168
|
+
};
|
|
244
169
|
}
|
|
245
170
|
exports.bytecodeCall = bytecodeCall;
|
|
246
|
-
function multiCall(params) {
|
|
171
|
+
async function multiCall(params) {
|
|
247
172
|
var _a;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
var _a;
|
|
287
|
-
var callParams = normalizeParams(call.params);
|
|
288
|
-
return {
|
|
289
|
-
params: callParams,
|
|
290
|
-
contract: (_a = call.target) !== null && _a !== void 0 ? _a : params.target,
|
|
291
|
-
};
|
|
292
|
-
});
|
|
293
|
-
params.contractCalls = contractCalls;
|
|
294
|
-
}
|
|
295
|
-
if (!params.skipCache)
|
|
296
|
-
return [2 /*return*/, cachedMultiCall(params)];
|
|
297
|
-
abi = resolveABI(params.abi);
|
|
298
|
-
return [4 /*yield*/, (0, util_1.runInPromisePool)({
|
|
299
|
-
items: (0, util_1.sliceIntoChunks)(contractCalls, chunkSize),
|
|
300
|
-
concurrency: 10,
|
|
301
|
-
processor: function (calls) { return (0, multicall3_1.default)(abi, calls, chain, params.block); }
|
|
302
|
-
})];
|
|
303
|
-
case 1:
|
|
304
|
-
results = _c.sent();
|
|
305
|
-
flatResults = [].concat.apply([], results);
|
|
306
|
-
failedQueries = flatResults.filter(function (r) { return !r.success; });
|
|
307
|
-
if (failedQueries.length) {
|
|
308
|
-
// debugLog(`[chain: ${params.chain ?? "ethereum"}] [abi: ${params.abi}] Failed multicalls:`, failedQueries.map(r => r.input))
|
|
309
|
-
if (!params.permitFailure) {
|
|
310
|
-
params.failedQueries = failedQueries;
|
|
311
|
-
params.isMultiCallError = true;
|
|
312
|
-
throw (0, generalUtil_1.formError)(null, params);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
|
|
316
|
-
(_b = params.logArray).push.apply(_b, contractCalls.map(function (c, i) { return ({
|
|
317
|
-
chain: chain,
|
|
318
|
-
holder: c.params.length ? c.params[0] : c.params,
|
|
319
|
-
token: c.contract,
|
|
320
|
-
amount: flatResults[i].output
|
|
321
|
-
}); }));
|
|
322
|
-
return [2 /*return*/, {
|
|
323
|
-
output: flatResults, // flatten array
|
|
324
|
-
}];
|
|
325
|
-
}
|
|
173
|
+
fixBlockTag(params);
|
|
174
|
+
if (cachedABIs_1.default[params.abi])
|
|
175
|
+
params.abi = cachedABIs_1.default[params.abi];
|
|
176
|
+
const chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
|
|
177
|
+
if (!params.calls)
|
|
178
|
+
throw new Error('Missing calls parameter');
|
|
179
|
+
if (params.target && !isValidTarget(params.target, chain))
|
|
180
|
+
throw new Error('Invalid target: ' + params.target);
|
|
181
|
+
if (!params.calls.length) {
|
|
182
|
+
return { output: [] };
|
|
183
|
+
}
|
|
184
|
+
let chunkSize = params.chunkSize;
|
|
185
|
+
if (!params.chunkSize) {
|
|
186
|
+
// Only a max of around 500 calls are supported by multicall, we have to split bigger batches
|
|
187
|
+
chunkSize = (0, env_1.getDefaultChunkSize)(chain);
|
|
188
|
+
}
|
|
189
|
+
if (!params.target && !params.permitFailure) {
|
|
190
|
+
// check if target adddress is missing for one of the calls
|
|
191
|
+
if (params.calls.some((i) => {
|
|
192
|
+
if (typeof i === 'string' && i.startsWith('0x'))
|
|
193
|
+
return !isValidTarget(i, params.chain);
|
|
194
|
+
if (typeof i === 'object')
|
|
195
|
+
return !isValidTarget(i.target, params.chain);
|
|
196
|
+
return true;
|
|
197
|
+
})) {
|
|
198
|
+
(0, debugLog_1.debugLog)('Multicall is missing target', JSON.stringify(params, null, 2));
|
|
199
|
+
throw new Error('Multicall is missing a target');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let contractCalls = params.contractCalls;
|
|
203
|
+
if (!contractCalls) {
|
|
204
|
+
contractCalls = (params.calls).map((call) => {
|
|
205
|
+
var _a;
|
|
206
|
+
const callParams = normalizeParams(call.params);
|
|
207
|
+
return {
|
|
208
|
+
params: callParams,
|
|
209
|
+
contract: (_a = call.target) !== null && _a !== void 0 ? _a : params.target,
|
|
210
|
+
};
|
|
326
211
|
});
|
|
212
|
+
params.contractCalls = contractCalls;
|
|
213
|
+
}
|
|
214
|
+
if (!params.skipCache)
|
|
215
|
+
return cachedMultiCall(params);
|
|
216
|
+
const abi = resolveABI(params.abi);
|
|
217
|
+
const results = await (0, util_1.runInPromisePool)({
|
|
218
|
+
items: (0, util_1.sliceIntoChunks)(contractCalls, chunkSize),
|
|
219
|
+
concurrency: 10,
|
|
220
|
+
processor: (calls) => (0, multicall3_1.default)(abi, calls, chain, params.block)
|
|
327
221
|
});
|
|
222
|
+
const flatResults = [].concat.apply([], results);
|
|
223
|
+
const failedQueries = flatResults.filter(r => !r.success);
|
|
224
|
+
if (failedQueries.length) {
|
|
225
|
+
// debugLog(`[chain: ${params.chain ?? "ethereum"}] [abi: ${params.abi}] Failed multicalls:`, failedQueries.map(r => r.input))
|
|
226
|
+
if (!params.permitFailure) {
|
|
227
|
+
params.failedQueries = failedQueries;
|
|
228
|
+
params.isMultiCallError = true;
|
|
229
|
+
throw (0, generalUtil_1.formError)(null, params);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
|
|
233
|
+
params.logArray.push(...contractCalls.map((c, i) => ({
|
|
234
|
+
chain,
|
|
235
|
+
holder: c.params.length ? c.params[0] : c.params,
|
|
236
|
+
token: c.contract,
|
|
237
|
+
amount: flatResults[i].output
|
|
238
|
+
})));
|
|
239
|
+
return {
|
|
240
|
+
output: flatResults, // flatten array
|
|
241
|
+
};
|
|
328
242
|
}
|
|
329
243
|
exports.multiCall = multiCall;
|
|
330
|
-
function cachedCall(params) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
case 1:
|
|
351
|
-
value = _a.sent();
|
|
352
|
-
if (value) {
|
|
353
|
-
cacheObject.value = value.output;
|
|
354
|
-
(0, internal_cache_1.setCache)(cacheObject);
|
|
355
|
-
}
|
|
356
|
-
return [2 /*return*/, value];
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
244
|
+
async function cachedCall(params) {
|
|
245
|
+
params.skipCache = true;
|
|
246
|
+
if (!isCachableAbi(params.abi))
|
|
247
|
+
return call(params);
|
|
248
|
+
const cacheObject = {
|
|
249
|
+
abi: params.abi,
|
|
250
|
+
chain: params.chain,
|
|
251
|
+
address: params.target,
|
|
252
|
+
};
|
|
253
|
+
const cachedValue = (0, internal_cache_1.getCache)(cacheObject);
|
|
254
|
+
if (cachedValue)
|
|
255
|
+
return {
|
|
256
|
+
output: cachedValue
|
|
257
|
+
};
|
|
258
|
+
const value = await call(params);
|
|
259
|
+
if (value) {
|
|
260
|
+
cacheObject.value = value.output;
|
|
261
|
+
(0, internal_cache_1.setCache)(cacheObject);
|
|
262
|
+
}
|
|
263
|
+
return value;
|
|
360
264
|
}
|
|
361
|
-
function cachedMultiCall(params) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
input: { target: value.contract, params: value.params, },
|
|
392
|
-
output: cachedValue,
|
|
393
|
-
success: true,
|
|
394
|
-
};
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
missing.push(value);
|
|
399
|
-
missingIndices.push(i);
|
|
400
|
-
});
|
|
401
|
-
if (!missing.length)
|
|
402
|
-
return [2 /*return*/, { output: response }];
|
|
403
|
-
params.contractCalls = missing;
|
|
404
|
-
return [4 /*yield*/, multiCall(params)];
|
|
405
|
-
case 1:
|
|
406
|
-
response_ = _a.sent();
|
|
407
|
-
response_.output.forEach(function (value, i) {
|
|
408
|
-
if (isCacheable) {
|
|
409
|
-
var cacheObject = {
|
|
410
|
-
abi: params.abi,
|
|
411
|
-
chain: params.chain,
|
|
412
|
-
address: value.input.target,
|
|
413
|
-
value: value.output
|
|
414
|
-
};
|
|
415
|
-
(0, internal_cache_1.setCache)(cacheObject);
|
|
416
|
-
}
|
|
417
|
-
response[missingIndices[i]] = value;
|
|
418
|
-
});
|
|
419
|
-
return [2 /*return*/, { output: response }];
|
|
265
|
+
async function cachedMultiCall(params) {
|
|
266
|
+
params.skipCache = true;
|
|
267
|
+
const isCacheable = isCachableAbi(params.abi);
|
|
268
|
+
const response = [];
|
|
269
|
+
const missing = [];
|
|
270
|
+
const missingIndices = [];
|
|
271
|
+
params.contractCalls.forEach((value, i) => {
|
|
272
|
+
if (!isValidTarget(value.contract, params.chain)) {
|
|
273
|
+
response[i] = {
|
|
274
|
+
input: { target: value.contract, params: value.params, },
|
|
275
|
+
output: null,
|
|
276
|
+
success: false,
|
|
277
|
+
};
|
|
278
|
+
(0, debugLog_1.debugLog)(params.abi, 'Bad target passed:', value.contract, 'skipping call and returning null output for this');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (isCacheable) {
|
|
282
|
+
const cacheObject = {
|
|
283
|
+
abi: params.abi,
|
|
284
|
+
chain: params.chain,
|
|
285
|
+
address: value.contract,
|
|
286
|
+
};
|
|
287
|
+
const cachedValue = (0, internal_cache_1.getCache)(cacheObject);
|
|
288
|
+
if (cachedValue) {
|
|
289
|
+
response[i] = {
|
|
290
|
+
input: { target: value.contract, params: value.params, },
|
|
291
|
+
output: cachedValue,
|
|
292
|
+
success: true,
|
|
293
|
+
};
|
|
294
|
+
return;
|
|
420
295
|
}
|
|
421
|
-
}
|
|
296
|
+
}
|
|
297
|
+
missing.push(value);
|
|
298
|
+
missingIndices.push(i);
|
|
299
|
+
});
|
|
300
|
+
if (!missing.length)
|
|
301
|
+
return { output: response };
|
|
302
|
+
params.contractCalls = missing;
|
|
303
|
+
const response_ = await multiCall(params);
|
|
304
|
+
response_.output.forEach((value, i) => {
|
|
305
|
+
if (isCacheable) {
|
|
306
|
+
const cacheObject = {
|
|
307
|
+
abi: params.abi,
|
|
308
|
+
chain: params.chain,
|
|
309
|
+
address: value.input.target,
|
|
310
|
+
value: value.output
|
|
311
|
+
};
|
|
312
|
+
(0, internal_cache_1.setCache)(cacheObject);
|
|
313
|
+
}
|
|
314
|
+
response[missingIndices[i]] = value;
|
|
422
315
|
});
|
|
316
|
+
return { output: response };
|
|
423
317
|
}
|
|
424
|
-
|
|
318
|
+
const cachableAbiSet = new Set([
|
|
425
319
|
'uint8:decimals',
|
|
426
320
|
]);
|
|
427
321
|
function isCachableAbi(abi) {
|