Skip to content

Commit

Permalink
feat(multicall): Enable a before hook for use in production (Zapper-f…
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Aug 8, 2022
1 parent 087d540 commit 73e6f78
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/multicall/multicall.ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ export const isMulticallUnderlyingError = (err: Error) => err.message.includes('
export class EthersMulticall implements IMulticallWrapper {
private multicall: Multicall;
private dataLoader: DataLoader<ContractCall, any>;
private beforeCallHook?: () => void;

constructor(
multicall: Multicall,
dataLoaderOptions: DataLoader.Options<ContractCall, any> = { cache: false, maxBatchSize: 250 },
beforeCallHook?: () => void,
) {
this.multicall = multicall;
this.dataLoader = new DataLoader(this.doCalls.bind(this), dataLoaderOptions);
this.beforeCallHook = beforeCallHook;
}

get contract() {
Expand All @@ -40,6 +43,7 @@ export class EthersMulticall implements IMulticallWrapper {
callData: new Interface([]).encodeFunctionData(call.fragment, call.params),
}));

if (this.beforeCallHook) this.beforeCallHook();
const response = await this.multicall.callStatic.aggregate(callRequests, false);

const result = calls.map((call, i) => {
Expand Down

0 comments on commit 73e6f78

Please sign in to comment.