Skip to content

Commit 95ee409

Browse files
committed
Add support for Multipart2 contract
1 parent e8b860a commit 95ee409

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
pragma solidity >=0.5.0;
3+
4+
contract Multicall2 {
5+
struct Call {
6+
address target;
7+
bytes callData;
8+
}
9+
struct Result {
10+
bool success;
11+
bytes returnData;
12+
}
13+
14+
function aggregate(Call[] memory calls) public virtual returns (uint256 blockNumber, bytes[] memory returnData) {}
15+
16+
function tryBlockAndAggregate(bool requireSuccess, Call[] memory calls) public returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {}
17+
}

packages/sdk/src/clients/multicall/client.e2e.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ import { ethers } from "ethers";
55
import { emp } from "..";
66

77
// multicall contract deployed to mainnet
8-
const address = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
8+
const multicallV1Address = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
9+
const multicallV2Address = "0x5ba1e12693dc8f9c48aad8770482f4739beed696";
910
const empAddress = "0xd81028a6fbAAaf604316F330b20D24bFbFd14478";
1011
// these require integration testing, skip for ci
1112
describe("multicall", function () {
12-
let client: Client.Instance;
13+
let clientV1: Client.Instance;
14+
let clientV2: Client.Instance;
1315
let empClient: emp.Instance;
1416
test("inits", function () {
1517
const provider = ethers.providers.getDefaultProvider(process.env.CUSTOM_NODE_URL);
16-
client = Client.connect(address, provider);
18+
clientV1 = Client.connect(multicallV1Address, provider);
19+
clientV2 = Client.connect(multicallV2Address, provider);
1720
empClient = emp.connect(empAddress, provider);
18-
assert.ok(client);
21+
assert.ok(clientV1);
22+
assert.ok(clientV2);
1923
assert.ok(empClient);
2024
});
25+
2126
test("multicall on emp", async function () {
2227
const calls = ["priceIdentifier", "tokenCurrency", "collateralCurrency"];
2328
const multicalls = calls.map((call: any) => {
@@ -26,11 +31,27 @@ describe("multicall", function () {
2631
callData: empClient.interface.encodeFunctionData(call),
2732
};
2833
});
29-
const response = await client.callStatic.aggregate(multicalls);
34+
const response = await clientV1.callStatic.aggregate(multicalls);
3035
const decoded = calls.map((call: any, i: number) => {
3136
const result = response.returnData[i];
3237
return empClient.interface.decodeFunctionResult(call, result);
3338
});
3439
assert.equal(decoded.length, calls.length);
3540
});
41+
42+
test("multicall2 on emp", async function () {
43+
const calls = ["priceIdentifier", "tokenCurrency", "collateralCurrency"];
44+
const multicalls = calls.map((call: any) => {
45+
return {
46+
target: empAddress,
47+
callData: empClient.interface.encodeFunctionData(call),
48+
};
49+
});
50+
const response = await clientV2.callStatic.tryBlockAndAggregate(false, multicalls);
51+
const decoded = calls.map((call: any, i: number) => {
52+
const result = response.returnData[i];
53+
return empClient.interface.decodeFunctionResult(call, result[1]);
54+
});
55+
assert.equal(decoded.length, calls.length);
56+
});
3657
});

packages/sdk/src/clients/multicall/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EthersContracts } from "@uma/core";
22
import type { SignerOrProvider } from "../..";
33

4-
export type Instance = EthersContracts.Multicall;
5-
const Factory = EthersContracts.Multicall__factory;
4+
export type Instance = EthersContracts.Multicall2;
5+
const Factory = EthersContracts.Multicall2__factory;
66

77
export function connect(address: string, provider: SignerOrProvider): Instance {
88
return Factory.connect(address, provider);

0 commit comments

Comments
 (0)