@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/multicall.js
CHANGED
|
@@ -22,55 +22,19 @@ 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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
27
|
};
|
|
64
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
29
|
exports.networkSupportsMulticall = exports.multicallAddressOrThrow = exports.AGGREGATE_SELECTOR = exports.MULTICALL_ADDRESS_OPTIMISM = exports.MULTICALL_ADDRESS_AURORA = exports.MULTICALL_ADDRESS_MOONRIVER = exports.MULTICALL_ADDRESS_AVAX = exports.MULTICALL_ADDRESS_ARBITRUM = exports.MULTICALL_ADDRESS_HARMONY = exports.MULTICALL_ADDRESS_HECO = exports.MULTICALL_ADDRESS_XDAI = exports.MULTICALL_ADDRESS_FANTOM = exports.MULTICALL_ADDRESS_BSC = exports.MULTICALL_ADDRESS_POLYGON = exports.MULTICALL_ADDRESS_GOERLI = exports.MULTICALL_ADDRESS_RINKEBY = exports.MULTICALL_ADDRESS_KOVAN = exports.MULTICALL_ADDRESS_MAINNET = void 0;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
30
|
+
const ethers_1 = require("ethers");
|
|
31
|
+
const general_1 = require("../general");
|
|
32
|
+
const convertResults_1 = __importDefault(require("./convertResults"));
|
|
33
|
+
const rpcCall_1 = require("./rpcCall");
|
|
34
|
+
const debugLog_1 = require("../util/debugLog");
|
|
35
|
+
const util_1 = require("../util");
|
|
36
|
+
const Tron = __importStar(require("./tron"));
|
|
37
|
+
const env_1 = require("../util/env");
|
|
74
38
|
exports.MULTICALL_ADDRESS_MAINNET = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
|
|
75
39
|
exports.MULTICALL_ADDRESS_KOVAN = "0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a";
|
|
76
40
|
exports.MULTICALL_ADDRESS_RINKEBY = "0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821";
|
|
@@ -87,188 +51,122 @@ exports.MULTICALL_ADDRESS_MOONRIVER = "0xe05349d6fE12602F6084550995B247a5C80C0E2
|
|
|
87
51
|
exports.MULTICALL_ADDRESS_AURORA = "0xe0e3887b158F7F9c80c835a61ED809389BC08d1b";
|
|
88
52
|
exports.MULTICALL_ADDRESS_OPTIMISM = "0xD0E99f15B24F265074747B2A1444eB02b9E30422";
|
|
89
53
|
exports.AGGREGATE_SELECTOR = "0x252dba42";
|
|
90
|
-
function makeMultiCall(functionABI, calls, chain, block) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
success: output !== null,
|
|
126
|
-
output: output,
|
|
127
|
-
};
|
|
128
|
-
if (error)
|
|
129
|
-
res.error = error;
|
|
130
|
-
return res;
|
|
131
|
-
})];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
54
|
+
async function makeMultiCall(functionABI, calls, chain, block) {
|
|
55
|
+
if (chain === 'tron')
|
|
56
|
+
return Tron.multiCall(functionABI, calls);
|
|
57
|
+
const contractInterface = new ethers_1.ethers.Interface([functionABI]);
|
|
58
|
+
let fd = contractInterface.fragments[0];
|
|
59
|
+
const contractCalls = calls.map((call) => {
|
|
60
|
+
const data = contractInterface.encodeFunctionData(fd, call.params);
|
|
61
|
+
return {
|
|
62
|
+
to: call.contract,
|
|
63
|
+
data,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
const returnValues = await executeCalls(contractCalls, chain, block);
|
|
67
|
+
return returnValues.map((values, index) => {
|
|
68
|
+
let output;
|
|
69
|
+
let error = undefined;
|
|
70
|
+
try {
|
|
71
|
+
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
output = null;
|
|
75
|
+
error = e;
|
|
76
|
+
}
|
|
77
|
+
const res = {
|
|
78
|
+
input: {
|
|
79
|
+
params: calls[index].params,
|
|
80
|
+
target: calls[index].contract,
|
|
81
|
+
},
|
|
82
|
+
success: output !== null,
|
|
83
|
+
output,
|
|
84
|
+
};
|
|
85
|
+
if (error)
|
|
86
|
+
res.error = error;
|
|
87
|
+
return res;
|
|
134
88
|
});
|
|
135
89
|
}
|
|
136
90
|
exports.default = makeMultiCall;
|
|
137
|
-
function executeCalls(contractCalls, chain, block) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
_a = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(["uint256", "bytes[]"], returnData), blockNumber = _a[0], returnValues = _a[1];
|
|
172
|
-
return [2 /*return*/, returnValues];
|
|
173
|
-
case 5:
|
|
174
|
-
e_1 = _d.sent();
|
|
175
|
-
if (!(contractCalls.length > 10)) return [3 /*break*/, 7];
|
|
176
|
-
chunkSize = Math.ceil(contractCalls.length / 5);
|
|
177
|
-
chunks = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
|
|
178
|
-
(0, debugLog_1.debugLog)("Multicall failed, call size: ".concat(contractCalls.length, ", splitting into smaller chunks and trying again, new call size: ").concat(chunks[0].length));
|
|
179
|
-
return [4 /*yield*/, (0, util_1.runInPromisePool)({
|
|
180
|
-
items: chunks,
|
|
181
|
-
concurrency: 2,
|
|
182
|
-
processor: function (calls) { return executeCalls(calls, chain, block); }
|
|
183
|
-
})];
|
|
184
|
-
case 6:
|
|
185
|
-
response = _d.sent();
|
|
186
|
-
return [2 /*return*/, response.flat()];
|
|
187
|
-
case 7:
|
|
188
|
-
(0, debugLog_1.debugLog)("Multicall failed, defaulting to single transactions...");
|
|
189
|
-
return [3 /*break*/, 8];
|
|
190
|
-
case 8:
|
|
191
|
-
_b = util_1.runInPromisePool;
|
|
192
|
-
_c = {
|
|
193
|
-
items: contractCalls
|
|
194
|
-
};
|
|
195
|
-
return [4 /*yield*/, networkSupportsMulticall(chain)];
|
|
196
|
-
case 9: return [2 /*return*/, _b.apply(void 0, [(_c.concurrency = (_d.sent()) ? 2 : 10,
|
|
197
|
-
_c.processor = function (_a) {
|
|
198
|
-
var to = _a.to, data = _a.data;
|
|
199
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
200
|
-
var result, e_2;
|
|
201
|
-
return __generator(this, function (_b) {
|
|
202
|
-
switch (_b.label) {
|
|
203
|
-
case 0:
|
|
204
|
-
result = null;
|
|
205
|
-
_b.label = 1;
|
|
206
|
-
case 1:
|
|
207
|
-
_b.trys.push([1, 3, , 4]);
|
|
208
|
-
return [4 /*yield*/, (0, rpcCall_1.call)((0, general_1.getProvider)(chain), { to: to, data: data }, block, chain)];
|
|
209
|
-
case 2:
|
|
210
|
-
result = _b.sent();
|
|
211
|
-
return [3 /*break*/, 4];
|
|
212
|
-
case 3:
|
|
213
|
-
e_2 = _b.sent();
|
|
214
|
-
(0, debugLog_1.debugLog)(e_2);
|
|
215
|
-
return [3 /*break*/, 4];
|
|
216
|
-
case 4: return [2 /*return*/, result];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
_c)])];
|
|
91
|
+
async function executeCalls(contractCalls, chain, block) {
|
|
92
|
+
if (await networkSupportsMulticall(chain)) {
|
|
93
|
+
try {
|
|
94
|
+
const multicallData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode([
|
|
95
|
+
ethers_1.ethers.ParamType.from({
|
|
96
|
+
components: [
|
|
97
|
+
{ name: "target", type: "address" },
|
|
98
|
+
{ name: "callData", type: "bytes" },
|
|
99
|
+
],
|
|
100
|
+
name: "data",
|
|
101
|
+
type: "tuple[]",
|
|
102
|
+
}),
|
|
103
|
+
], [contractCalls.map((call) => [call.to, call.data])]);
|
|
104
|
+
const address = await multicallAddressOrThrow(chain);
|
|
105
|
+
const callData = exports.AGGREGATE_SELECTOR + multicallData.substr(2);
|
|
106
|
+
const tx = {
|
|
107
|
+
to: address,
|
|
108
|
+
data: callData,
|
|
109
|
+
};
|
|
110
|
+
const returnData = await (0, rpcCall_1.call)((0, general_1.getProvider)(chain), tx, block, chain);
|
|
111
|
+
const [blockNumber, returnValues] = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(["uint256", "bytes[]"], returnData);
|
|
112
|
+
return returnValues;
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
if (contractCalls.length > 10) {
|
|
116
|
+
const chunkSize = Math.ceil(contractCalls.length / 5);
|
|
117
|
+
const chunks = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
|
|
118
|
+
(0, debugLog_1.debugLog)(`Multicall failed, call size: ${contractCalls.length}, splitting into smaller chunks and trying again, new call size: ${chunks[0].length}`);
|
|
119
|
+
const response = await (0, util_1.runInPromisePool)({
|
|
120
|
+
items: chunks,
|
|
121
|
+
concurrency: 2,
|
|
122
|
+
processor: (calls) => executeCalls(calls, chain, block)
|
|
123
|
+
});
|
|
124
|
+
return response.flat();
|
|
222
125
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (multicallEnv)
|
|
234
|
-
return [2 /*return*/, multicallEnv];
|
|
235
|
-
return [4 /*yield*/, (0, general_1.getProvider)(chain).getNetwork()];
|
|
236
|
-
case 1:
|
|
237
|
-
network = _a.sent();
|
|
238
|
-
address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
239
|
-
if (address === null) {
|
|
240
|
-
msg = "multicall is not available on the network ".concat(network.chainId);
|
|
241
|
-
console.error(msg);
|
|
242
|
-
throw new Error(msg);
|
|
243
|
-
}
|
|
244
|
-
return [2 /*return*/, address];
|
|
126
|
+
(0, debugLog_1.debugLog)("Multicall failed, defaulting to single transactions...");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return (0, util_1.runInPromisePool)({
|
|
130
|
+
items: contractCalls,
|
|
131
|
+
concurrency: await networkSupportsMulticall(chain) ? 2 : 10,
|
|
132
|
+
processor: async ({ to, data }) => {
|
|
133
|
+
let result = null;
|
|
134
|
+
try {
|
|
135
|
+
result = await (0, rpcCall_1.call)((0, general_1.getProvider)(chain), { to, data }, block, chain);
|
|
245
136
|
}
|
|
246
|
-
|
|
137
|
+
catch (e) {
|
|
138
|
+
(0, debugLog_1.debugLog)(e);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
247
142
|
});
|
|
248
143
|
}
|
|
144
|
+
async function multicallAddressOrThrow(chain) {
|
|
145
|
+
const multicallEnv = (0, env_1.getEnvMulticallAddress)(chain);
|
|
146
|
+
if (multicallEnv)
|
|
147
|
+
return multicallEnv;
|
|
148
|
+
const network = await (0, general_1.getProvider)(chain).getNetwork();
|
|
149
|
+
const address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
150
|
+
if (address === null) {
|
|
151
|
+
const msg = `multicall is not available on the network ${network.chainId}`;
|
|
152
|
+
console.error(msg);
|
|
153
|
+
throw new Error(msg);
|
|
154
|
+
}
|
|
155
|
+
return address;
|
|
156
|
+
}
|
|
249
157
|
exports.multicallAddressOrThrow = multicallAddressOrThrow;
|
|
250
|
-
|
|
251
|
-
function networkSupportsMulticall(chain) {
|
|
158
|
+
const networkMulticallCache = {};
|
|
159
|
+
async function networkSupportsMulticall(chain) {
|
|
252
160
|
var _a;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return [4 /*yield*/, ((_a = (0, general_1.getProvider)(chain)) === null || _a === void 0 ? void 0 : _a.getNetwork())];
|
|
263
|
-
case 1:
|
|
264
|
-
network = _b.sent();
|
|
265
|
-
address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
266
|
-
networkMulticallCache[chain] = address !== null;
|
|
267
|
-
_b.label = 2;
|
|
268
|
-
case 2: return [2 /*return*/, networkMulticallCache[chain]];
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
});
|
|
161
|
+
const multicallEnv = (0, env_1.getEnvMulticallAddress)(chain);
|
|
162
|
+
if (multicallEnv)
|
|
163
|
+
networkMulticallCache[chain] = true;
|
|
164
|
+
if (!networkMulticallCache.hasOwnProperty(chain)) {
|
|
165
|
+
const network = await ((_a = (0, general_1.getProvider)(chain)) === null || _a === void 0 ? void 0 : _a.getNetwork());
|
|
166
|
+
const address = multicallAddress(network === null || network === void 0 ? void 0 : network.chainId);
|
|
167
|
+
networkMulticallCache[chain] = address !== null;
|
|
168
|
+
}
|
|
169
|
+
return networkMulticallCache[chain];
|
|
272
170
|
}
|
|
273
171
|
exports.networkSupportsMulticall = networkSupportsMulticall;
|
|
274
172
|
function multicallAddress(chainId) {
|
package/build/abi/multicall3.js
CHANGED
|
@@ -22,56 +22,20 @@ 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
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
27
|
};
|
|
64
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
29
|
exports.getMulticallAddress = exports.isMulticallV3Supported = void 0;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
30
|
+
const ethers_1 = require("ethers");
|
|
31
|
+
const convertResults_1 = __importDefault(require("./convertResults"));
|
|
32
|
+
const multicall_1 = __importDefault(require("./multicall"));
|
|
33
|
+
const Tron = __importStar(require("./tron"));
|
|
34
|
+
const index_1 = require("./index");
|
|
71
35
|
// https://github.com/mds1/multicall
|
|
72
36
|
// https://www.multicall3.com/deployments
|
|
73
|
-
|
|
74
|
-
|
|
37
|
+
const MULTICALL_V3_ADDRESS = '0xca11bde05977b3631167028862be2a173976ca11';
|
|
38
|
+
const DEPLOYMENT_BLOCK = {
|
|
75
39
|
ethereum: 14353601,
|
|
76
40
|
ethf: 14353601,
|
|
77
41
|
arbitrum: 7654707,
|
|
@@ -148,90 +112,62 @@ var DEPLOYMENT_BLOCK = {
|
|
|
148
112
|
callisto: 13811517,
|
|
149
113
|
bittorrent: 31078552,
|
|
150
114
|
};
|
|
151
|
-
function makeMultiCall(functionABI, calls, chain, block) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
115
|
+
async function makeMultiCall(functionABI, calls, chain, block) {
|
|
116
|
+
if (chain === 'tron')
|
|
117
|
+
return Tron.multiCall(functionABI, calls);
|
|
118
|
+
if (!functionABI)
|
|
119
|
+
throw new Error('Missing ABI parameter');
|
|
120
|
+
if (calls.some(i => !i.contract))
|
|
121
|
+
throw new Error('Missing target, abi:' + functionABI);
|
|
122
|
+
if (!isMulticallV3Supported(chain, block))
|
|
123
|
+
return (0, multicall_1.default)(functionABI, calls, chain, block);
|
|
124
|
+
const contractInterface = new ethers_1.ethers.Interface([functionABI]);
|
|
125
|
+
let fd = contractInterface.fragments[0];
|
|
126
|
+
const contractCalls = calls.map((call) => {
|
|
127
|
+
const data = contractInterface.encodeFunctionData(fd, call.params);
|
|
128
|
+
return {
|
|
129
|
+
to: call.contract,
|
|
130
|
+
data,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
let returnValues;
|
|
134
|
+
try {
|
|
135
|
+
await _call();
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
// debugLog(chain, 'Multicall failed, retrying call...')
|
|
139
|
+
await _call();
|
|
140
|
+
}
|
|
141
|
+
return returnValues.map(([success, values], index) => {
|
|
142
|
+
let output = null;
|
|
143
|
+
let error = null;
|
|
144
|
+
try {
|
|
145
|
+
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
|
|
168
146
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
contractCalls = calls.map(function (call) {
|
|
184
|
-
var data = contractInterface.encodeFunctionData(fd, call.params);
|
|
185
|
-
return {
|
|
186
|
-
to: call.contract,
|
|
187
|
-
data: data,
|
|
188
|
-
};
|
|
189
|
-
});
|
|
190
|
-
_a.label = 1;
|
|
191
|
-
case 1:
|
|
192
|
-
_a.trys.push([1, 3, , 5]);
|
|
193
|
-
return [4 /*yield*/, _call()];
|
|
194
|
-
case 2:
|
|
195
|
-
_a.sent();
|
|
196
|
-
return [3 /*break*/, 5];
|
|
197
|
-
case 3:
|
|
198
|
-
e_1 = _a.sent();
|
|
199
|
-
// debugLog(chain, 'Multicall failed, retrying call...')
|
|
200
|
-
return [4 /*yield*/, _call()];
|
|
201
|
-
case 4:
|
|
202
|
-
// debugLog(chain, 'Multicall failed, retrying call...')
|
|
203
|
-
_a.sent();
|
|
204
|
-
return [3 /*break*/, 5];
|
|
205
|
-
case 5: return [2 /*return*/, returnValues.map(function (_a, index) {
|
|
206
|
-
var success = _a[0], values = _a[1];
|
|
207
|
-
var output = null;
|
|
208
|
-
var error = null;
|
|
209
|
-
try {
|
|
210
|
-
output = (0, convertResults_1.default)(contractInterface.decodeFunctionResult(fd, values), fd);
|
|
211
|
-
}
|
|
212
|
-
catch (e) {
|
|
213
|
-
error = e;
|
|
214
|
-
success = false;
|
|
215
|
-
}
|
|
216
|
-
var res = {
|
|
217
|
-
input: {
|
|
218
|
-
params: calls[index].params,
|
|
219
|
-
target: calls[index].contract,
|
|
220
|
-
},
|
|
221
|
-
success: success,
|
|
222
|
-
output: output,
|
|
223
|
-
};
|
|
224
|
-
if (error)
|
|
225
|
-
res.error = error;
|
|
226
|
-
return res;
|
|
227
|
-
})];
|
|
228
|
-
}
|
|
229
|
-
});
|
|
147
|
+
catch (e) {
|
|
148
|
+
error = e;
|
|
149
|
+
success = false;
|
|
150
|
+
}
|
|
151
|
+
const res = {
|
|
152
|
+
input: {
|
|
153
|
+
params: calls[index].params,
|
|
154
|
+
target: calls[index].contract,
|
|
155
|
+
},
|
|
156
|
+
success, output,
|
|
157
|
+
};
|
|
158
|
+
if (error)
|
|
159
|
+
res.error = error;
|
|
160
|
+
return res;
|
|
230
161
|
});
|
|
162
|
+
async function _call() {
|
|
163
|
+
const multicallAddress = getMulticallAddress(chain, block);
|
|
164
|
+
const { output: returnData } = await (0, index_1.call)({ chain, block, target: multicallAddress, abi: 'function tryAggregate(bool requireSuccess, tuple(address target, bytes callData)[] calls) payable returns (tuple(bool success, bytes returnData)[] returnData)', params: [false, contractCalls.map((call) => [call.to, call.data])] });
|
|
165
|
+
returnValues = returnData;
|
|
166
|
+
}
|
|
231
167
|
}
|
|
232
168
|
exports.default = makeMultiCall;
|
|
233
169
|
function isMulticallV3Supported(chain, block) {
|
|
234
|
-
|
|
170
|
+
const startBlock = DEPLOYMENT_BLOCK[chain];
|
|
235
171
|
if (!startBlock)
|
|
236
172
|
return false;
|
|
237
173
|
if (!block)
|
|
@@ -244,7 +180,7 @@ exports.isMulticallV3Supported = isMulticallV3Supported;
|
|
|
244
180
|
function getMulticallAddress(chain, block) {
|
|
245
181
|
if (!isMulticallV3Supported(chain, block))
|
|
246
182
|
return null;
|
|
247
|
-
|
|
183
|
+
let multicallAddress = MULTICALL_V3_ADDRESS;
|
|
248
184
|
switch (chain) {
|
|
249
185
|
case 'onus':
|
|
250
186
|
multicallAddress = '0x748c384f759cc596f0d9fa96dcabe8a11e443b30';
|