Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ export async function multicall(
);
const itf = new Interface(abi);
try {
const [, res] = await multi.aggregate(
calls.map((call) => [
call[0].toLowerCase(),
itf.encodeFunctionData(call[1], call[2])
]),
options || {}
const max = options.limit || 1000;
const pages = Math.ceil(calls.length / max);
const promises: any = [];
Array.from(Array(pages)).forEach((x, i) => {
const callsInPage = calls.slice(max * i, max * (i + 1));
promises.push(
multi.aggregate(
callsInPage.map((call) => [
call[0].toLowerCase(),
itf.encodeFunctionData(call[1], call[2])
]),
options || {}
)
);
});
let results: any = await Promise.all(promises);
results = results.reduce((prev: any, [, res]: any) => prev.concat(res), []);
return results.map((call, i) =>
itf.decodeFunctionResult(calls[i][1], call)
);
return res.map((call, i) => itf.decodeFunctionResult(calls[i][1], call));
} catch (e) {
return Promise.reject(e);
}
Expand Down