@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.
@@ -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
- var cachedABIs_1 = __importDefault(require("./cachedABIs"));
87
- var ethers_1 = require("ethers");
88
- var general_1 = require("../general");
89
- var multicall3_1 = __importDefault(require("./multicall3"));
90
- var convertResults_1 = __importDefault(require("./convertResults"));
91
- var debugLog_1 = require("../util/debugLog");
92
- var internal_cache_1 = require("../util/internal-cache");
93
- var util_1 = require("../util");
94
- var Tron = __importStar(require("./tron"));
95
- var generalUtil_1 = require("../generalUtil");
96
- var env_1 = require("../util/env");
97
- var nullAddress = '0x0000000000000000000000000000000000000000';
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
- var knownTypes = [
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
- (__spreadArray([], knownTypes, true)).forEach(function (i) { return knownTypes.push(i + '[]'); }); // support array type for all known types
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
- var abi = providedAbi;
52
+ let abi = providedAbi;
109
53
  if (typeof abi === "string") {
110
- var _a = providedAbi.split(':'), outputType = _a[0], name_1 = _a[1];
111
- if (!knownTypes.includes(outputType) || !name_1) {
112
- var contractInterface = new ethers_1.ethers.Interface([providedAbi]);
113
- var jsonAbi = contractInterface.formatJson();
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: name_1,
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 __assign({ type: "function" }, abi);
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
- var block = params.block;
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
- return __awaiter(this, void 0, void 0, function () {
165
- var chain, errorParams, abi, callParams, contractInterface, functionABI, callData, provider, result, decodedResult, output, e_1;
166
- return __generator(this, function (_b) {
167
- switch (_b.label) {
168
- case 0:
169
- if (!isValidTarget(params.target, params.chain))
170
- throw new Error('Invalid target: ' + params.target);
171
- fixBlockTag(params);
172
- chain = (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum";
173
- if (cachedABIs_1.default[params.abi])
174
- params.abi = cachedABIs_1.default[params.abi];
175
- errorParams = __assign({}, params);
176
- _b.label = 1;
177
- case 1:
178
- _b.trys.push([1, 3, , 4]);
179
- if (!params.skipCache)
180
- return [2 /*return*/, cachedCall(params)];
181
- abi = resolveABI(params.abi);
182
- callParams = normalizeParams(params.params);
183
- if (chain === 'tron')
184
- return [2 /*return*/, Tron.call(__assign(__assign({}, params), { abi: abi, params: callParams }))];
185
- contractInterface = new ethers_1.ethers.Interface([abi]);
186
- functionABI = ethers_1.ethers.FunctionFragment.from(abi);
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
- return __awaiter(this, void 0, void 0, function () {
222
- var block, bytecode, inputTypes, inputs, outputTypes, chain, inputData, callData, result, decodedResult;
223
- return __generator(this, function (_a) {
224
- switch (_a.label) {
225
- case 0:
226
- fixBlockTag(params);
227
- block = params.block, bytecode = params.bytecode, inputTypes = params.inputTypes, inputs = params.inputs, outputTypes = params.outputTypes, chain = params.chain;
228
- if (!bytecode)
229
- throw new Error('Missing bytecode parameter!');
230
- if (chain === 'tron')
231
- throw new Error('Bytecode call is not supported on Tron');
232
- inputData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(inputTypes, inputs);
233
- callData = '0x' + bytecode.concat(inputData.slice(2));
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
- return __awaiter(this, void 0, void 0, function () {
249
- var chain, chunkSize, contractCalls, abi, results, flatResults, failedQueries;
250
- var _b;
251
- return __generator(this, function (_c) {
252
- switch (_c.label) {
253
- case 0:
254
- fixBlockTag(params);
255
- if (cachedABIs_1.default[params.abi])
256
- params.abi = cachedABIs_1.default[params.abi];
257
- chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
258
- if (!params.calls)
259
- throw new Error('Missing calls parameter');
260
- if (params.target && !isValidTarget(params.target, chain))
261
- throw new Error('Invalid target: ' + params.target);
262
- if (!params.calls.length) {
263
- return [2 /*return*/, { output: [] }];
264
- }
265
- chunkSize = params.chunkSize;
266
- if (!params.chunkSize) {
267
- // Only a max of around 500 calls are supported by multicall, we have to split bigger batches
268
- chunkSize = (0, env_1.getDefaultChunkSize)(chain);
269
- }
270
- if (!params.target && !params.permitFailure) {
271
- // check if target adddress is missing for one of the calls
272
- if (params.calls.some(function (i) {
273
- if (typeof i === 'string' && i.startsWith('0x'))
274
- return !isValidTarget(i, params.chain);
275
- if (typeof i === 'object')
276
- return !isValidTarget(i.target, params.chain);
277
- return true;
278
- })) {
279
- (0, debugLog_1.debugLog)('Multicall is missing target', JSON.stringify(params, null, 2));
280
- throw new Error('Multicall is missing a target');
281
- }
282
- }
283
- contractCalls = params.contractCalls;
284
- if (!contractCalls) {
285
- contractCalls = (params.calls).map(function (call) {
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
- return __awaiter(this, void 0, void 0, function () {
332
- var cacheObject, cachedValue, value;
333
- return __generator(this, function (_a) {
334
- switch (_a.label) {
335
- case 0:
336
- params.skipCache = true;
337
- if (!isCachableAbi(params.abi))
338
- return [2 /*return*/, call(params)];
339
- cacheObject = {
340
- abi: params.abi,
341
- chain: params.chain,
342
- address: params.target,
343
- };
344
- cachedValue = (0, internal_cache_1.getCache)(cacheObject);
345
- if (cachedValue)
346
- return [2 /*return*/, {
347
- output: cachedValue
348
- }];
349
- return [4 /*yield*/, call(params)];
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
- return __awaiter(this, void 0, void 0, function () {
363
- var isCacheable, response, missing, missingIndices, response_;
364
- return __generator(this, function (_a) {
365
- switch (_a.label) {
366
- case 0:
367
- params.skipCache = true;
368
- isCacheable = isCachableAbi(params.abi);
369
- response = [];
370
- missing = [];
371
- missingIndices = [];
372
- params.contractCalls.forEach(function (value, i) {
373
- if (!isValidTarget(value.contract, params.chain)) {
374
- response[i] = {
375
- input: { target: value.contract, params: value.params, },
376
- output: null,
377
- success: false,
378
- };
379
- (0, debugLog_1.debugLog)(params.abi, 'Bad target passed:', value.contract, 'skipping call and returning null output for this');
380
- return;
381
- }
382
- if (isCacheable) {
383
- var cacheObject = {
384
- abi: params.abi,
385
- chain: params.chain,
386
- address: value.contract,
387
- };
388
- var cachedValue = (0, internal_cache_1.getCache)(cacheObject);
389
- if (cachedValue) {
390
- response[i] = {
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
- var cachableAbiSet = new Set([
318
+ const cachableAbiSet = new Set([
425
319
  'uint8:decimals',
426
320
  ]);
427
321
  function isCachableAbi(abi) {