Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Destiner committed Mar 18, 2024
1 parent d0f0aee commit 8731192
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
36 changes: 27 additions & 9 deletions src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ async function all<T>(
callData,
};
});
const response = contract
const response = contract && contract.aggregate
? await contract.aggregate(callRequests, overrides || {})
: await callDeployless(provider, callRequests, overrides?.blockTag);
const callCount = calls.length;
const callResult: T[] = [];
for (let i = 0; i < callCount; i++) {
const name = calls[i].name;
const outputs = calls[i].outputs;
const call = calls[i];
if (!call) {
throw new Error("Unable to access the call");
}
const name = call.name;
const outputs = call.outputs;
const returnData = response.returnData[i];
const params = Abi.decode(name, outputs, returnData);
const result = outputs.length === 1 ? params[0] : params;
Expand All @@ -94,15 +98,22 @@ async function tryAll<T>(
callData,
};
});
const response: CallResult[] = contract
const response: CallResult[] = contract && contract.tryAggregate
? await contract.tryAggregate(false, callRequests, overrides || {})
: await callDeployless2(provider, callRequests, overrides?.blockTag);
const callCount = calls.length;
const callResult: (T | null)[] = [];
for (let i = 0; i < callCount; i++) {
const name = calls[i].name;
const outputs = calls[i].outputs;
const call = calls[i];
if (!call) {
throw new Error("Unable to access the call");
}
const name = call.name;
const outputs = call.outputs;
const result = response[i];
if (!result) {
throw new Error("Unable to access the result");
}
if (!result.success) {
callResult.push(null);
} else {
Expand Down Expand Up @@ -136,15 +147,22 @@ async function tryEach<T>(
callData,
};
});
const response: CallResult[] = contract
const response: CallResult[] = contract && contract.aggregate3
? await contract.aggregate3(callRequests, overrides || {})
: await callDeployless3(provider, callRequests, overrides?.blockTag);
const callCount = calls.length;
const callResult: (T | null)[] = [];
for (let i = 0; i < callCount; i++) {
const name = calls[i].name;
const outputs = calls[i].outputs;
const call = calls[i];
if (!call) {
throw new Error("Unable to access the call");
}
const name = call.name;
const outputs = call.outputs;
const result = response[i];
if (!result) {
throw new Error("Unable to access the result");
}
if (!result.success) {
callResult.push(null);
} else {
Expand Down
20 changes: 16 additions & 4 deletions src/multicall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface Multicall {
}

function getMulticall(chainId: number): Multicall | null {
const addressMap: Record<number, Multicall | null> = {
const addressMap: Record<number, Multicall> = {
1: {
address: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
block: 7929876,
Expand Down Expand Up @@ -135,7 +135,11 @@ function getMulticall(chainId: number): Multicall | null {
block: 14080409,
},
};
return addressMap[chainId];
const chainAddressMap = addressMap[chainId];
if (!chainAddressMap) {
return null;
}
return chainAddressMap;
}

function getMulticall2(chainId: number): Multicall | null {
Expand Down Expand Up @@ -225,7 +229,11 @@ function getMulticall2(chainId: number): Multicall | null {
block: 14080778,
},
};
return addressMap[chainId];
const chainAddressMap = addressMap[chainId];
if (!chainAddressMap) {
return null;
}
return chainAddressMap;
}

function getMulticall3(chainId: number): Multicall | null {
Expand Down Expand Up @@ -364,7 +372,11 @@ function getMulticall3(chainId: number): Multicall | null {
block: 14080843,
},
};
return addressMap[chainId];
const chainAddressMap = addressMap[chainId];
if (!chainAddressMap) {
return null;
}
return chainAddressMap;
}

const deploylessMulticallBytecode =
Expand Down
6 changes: 5 additions & 1 deletion src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ class Provider {
const multicall = this.#getContract('TRY_EACH', overrides?.blockTag);
const provider = this.#provider;
const failableCalls = calls.map((call, index) => {
const callCanFail = canFail[index];
if (callCanFail === undefined) {
throw new Error("Unable to access the canFail value");
}
return {
...call,
canFail: canFail[index],
canFail: callCanFail,
};
});
return await callTryEach<T>(provider, multicall, failableCalls, overrides);
Expand Down

0 comments on commit 8731192

Please sign in to comment.