37 lines
2.1 KiB
JavaScript
37 lines
2.1 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.multicall = void 0;
|
|
function multicall(Multicall, calls) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const calldata = calls.map((call) => {
|
|
var _a, _b, _c;
|
|
const target = (((_a = call.contract) === null || _a === void 0 ? void 0 : _a.target) || call.address);
|
|
const callInterface = (((_b = call.contract) === null || _b === void 0 ? void 0 : _b.interface) || call.interface);
|
|
return {
|
|
target,
|
|
callData: callInterface.encodeFunctionData(call.name, call.params),
|
|
allowFailure: (_c = call.allowFailure) !== null && _c !== void 0 ? _c : false,
|
|
};
|
|
});
|
|
const returnData = yield Multicall.aggregate3.staticCall(calldata);
|
|
const res = returnData.map((call, i) => {
|
|
var _a;
|
|
const callInterface = (((_a = calls[i].contract) === null || _a === void 0 ? void 0 : _a.interface) || calls[i].interface);
|
|
const [result, data] = call;
|
|
const decodeResult = result && data && data !== '0x' ? callInterface.decodeFunctionResult(calls[i].name, data) : null;
|
|
return !decodeResult ? null : decodeResult.length === 1 ? decodeResult[0] : decodeResult;
|
|
});
|
|
return res;
|
|
});
|
|
}
|
|
exports.multicall = multicall;
|
|
//# sourceMappingURL=multicall.js.map
|