File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -47,14 +47,26 @@ export async function multicall(
47
47
) ;
48
48
const itf = new Interface ( abi ) ;
49
49
try {
50
- const [ , res ] = await multi . aggregate (
51
- calls . map ( ( call ) => [
52
- call [ 0 ] . toLowerCase ( ) ,
53
- itf . encodeFunctionData ( call [ 1 ] , call [ 2 ] )
54
- ] ) ,
55
- options || { }
50
+ const max = options . limit || 1000 ;
51
+ const pages = Math . ceil ( calls . length / max ) ;
52
+ const promises : any = [ ] ;
53
+ Array . from ( Array ( pages ) ) . forEach ( ( x , i ) => {
54
+ const callsInPage = calls . slice ( max * i , max * ( i + 1 ) ) ;
55
+ promises . push (
56
+ multi . aggregate (
57
+ callsInPage . map ( ( call ) => [
58
+ call [ 0 ] . toLowerCase ( ) ,
59
+ itf . encodeFunctionData ( call [ 1 ] , call [ 2 ] )
60
+ ] ) ,
61
+ options || { }
62
+ )
63
+ ) ;
64
+ } ) ;
65
+ let results : any = await Promise . all ( promises ) ;
66
+ results = results . reduce ( ( prev : any , [ , res ] : any ) => prev . concat ( res ) , [ ] ) ;
67
+ return results . map ( ( call , i ) =>
68
+ itf . decodeFunctionResult ( calls [ i ] [ 1 ] , call )
56
69
) ;
57
- return res . map ( ( call , i ) => itf . decodeFunctionResult ( calls [ i ] [ 1 ] , call ) ) ;
58
70
} catch ( e ) {
59
71
return Promise . reject ( e ) ;
60
72
}
You can’t perform that action at this time.
0 commit comments