UNPKG

@dahlia-labs/use-ethers

Version:
23 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchCalls = exports.fetchMulticalls = exports.getMulticall = void 0; const tslib_1 = require("tslib"); const chunk_1 = tslib_1.__importDefault(require("lodash/chunk")); const multicall2_json_1 = tslib_1.__importDefault(require("./abis/multicall2.json")); const constants_1 = require("./constants"); const contracts_1 = require("./contracts"); const getMulticall = (provider, chain) => (0, contracts_1.getContract)(constants_1.MulticallAddress[chain], multicall2_json_1.default, provider); exports.getMulticall = getMulticall; async function fetchMulticalls(multicalls, multicallContract, maxChunk = 100) { const data = await (0, exports.fetchCalls)(multicalls.map((m) => m.call), multicallContract, maxChunk); return data.map((v, i) => { return multicalls[i].parseReturn(v); }); } exports.fetchMulticalls = fetchMulticalls; const fetchCalls = async (calls, multicallContract, maxChunk = 100) => { const callChunks = (0, chunk_1.default)(calls, maxChunk); return (await Promise.all(callChunks.map((c) => multicallContract === null || multicallContract === void 0 ? void 0 : multicallContract.callStatic.aggregate(c)))).flatMap((c) => c === null || c === void 0 ? void 0 : c.returnData); }; exports.fetchCalls = fetchCalls; //# sourceMappingURL=multicall.js.map