@@ -5,19 +5,24 @@ import { ethers } from "ethers";
5
5
import { emp } from ".." ;
6
6
7
7
// multicall contract deployed to mainnet
8
- const address = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441" ;
8
+ const multicallV1Address = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441" ;
9
+ const multicallV2Address = "0x5ba1e12693dc8f9c48aad8770482f4739beed696" ;
9
10
const empAddress = "0xd81028a6fbAAaf604316F330b20D24bFbFd14478" ;
10
11
// these require integration testing, skip for ci
11
12
describe ( "multicall" , function ( ) {
12
- let client : Client . Instance ;
13
+ let clientV1 : Client . Instance ;
14
+ let clientV2 : Client . Instance ;
13
15
let empClient : emp . Instance ;
14
16
test ( "inits" , function ( ) {
15
17
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 ) ;
17
20
empClient = emp . connect ( empAddress , provider ) ;
18
- assert . ok ( client ) ;
21
+ assert . ok ( clientV1 ) ;
22
+ assert . ok ( clientV2 ) ;
19
23
assert . ok ( empClient ) ;
20
24
} ) ;
25
+
21
26
test ( "multicall on emp" , async function ( ) {
22
27
const calls = [ "priceIdentifier" , "tokenCurrency" , "collateralCurrency" ] ;
23
28
const multicalls = calls . map ( ( call : any ) => {
@@ -26,11 +31,27 @@ describe("multicall", function () {
26
31
callData : empClient . interface . encodeFunctionData ( call ) ,
27
32
} ;
28
33
} ) ;
29
- const response = await client . callStatic . aggregate ( multicalls ) ;
34
+ const response = await clientV1 . callStatic . aggregate ( multicalls ) ;
30
35
const decoded = calls . map ( ( call : any , i : number ) => {
31
36
const result = response . returnData [ i ] ;
32
37
return empClient . interface . decodeFunctionResult ( call , result ) ;
33
38
} ) ;
34
39
assert . equal ( decoded . length , calls . length ) ;
35
40
} ) ;
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
+ } ) ;
36
57
} ) ;
0 commit comments