1
+ const config = {
2
+ ethereum : {
3
+ factory : '0x820FB8127a689327C863de8433278d6181123982' ,
4
+ fromBlock : 20540819 ,
5
+ } ,
6
+ arbitrum : {
7
+ factory : '0x820FB8127a689327C863de8433278d6181123982' ,
8
+ fromBlock : 243467827 ,
9
+ } ,
10
+ base : {
11
+ factory : '0x820FB8127a689327C863de8433278d6181123982' ,
12
+ fromBlock : 18512550 ,
13
+ } ,
14
+ }
15
+
16
+ module . exports = {
17
+ doublecounted : true ,
18
+ } ;
19
+
20
+ Object . keys ( config ) . forEach ( chain => {
21
+ const { factory } = config [ chain ]
22
+ module . exports [ chain ] = {
23
+ tvl : async ( api ) => {
24
+ const numPublicVaults = await api . call ( { abi : 'uint256:numOfPublicVaults' , target : factory } )
25
+ const numPrivateVaults = await api . call ( { abi : 'uint256:numOfPrivateVaults' , target : factory } )
26
+ const publicVaults = numPublicVaults > 0 ? await api . call ( { abi : 'function publicVaults(uint256 startIndex_, uint256 endIndex_) returns (address[] memory)' , target : factory , params : [ 0 , numPublicVaults ] } ) : [ ]
27
+ const privateVaults = numPrivateVaults > 0 ? await api . call ( { abi : 'function privateVaults(uint256 startIndex_, uint256 endIndex_) returns (address[] memory)' , target : factory , params : [ 0 , numPrivateVaults ] } ) : [ ]
28
+ const vaults = [ ...publicVaults , ...privateVaults ]
29
+ const [ token0s , token1s , bals ] = await Promise . all ( [
30
+ api . multiCall ( { abi : 'address:token0' , calls : vaults } ) ,
31
+ api . multiCall ( { abi : 'address:token1' , calls : vaults } ) ,
32
+ api . multiCall ( { abi : 'function totalUnderlying() view returns (uint256, uint256)' , calls : vaults } ) ,
33
+ ] )
34
+
35
+ bals . forEach ( ( [ v0 , v1 ] , i ) => {
36
+ api . add ( token0s [ i ] , v0 )
37
+ api . add ( token1s [ i ] , v1 )
38
+ } )
39
+ }
40
+ }
41
+ } )
0 commit comments