@@ -7,45 +7,35 @@ async function tvl(api) {
7
7
'0x81e83f73530c262b0dbf5414649a875c48a48144de3c08ff68cb9d54b36f2eaa' ,
8
8
] ;
9
9
10
- try {
11
- const balancesList = await Promise . all (
12
- contractIds . map ( async ( contractId ) => {
13
- try {
14
- const balances = await sumTokens ( { api, owner : contractId } ) ;
15
- console . log ( `Balances from contract ${ contractId } :` , balances ) ;
16
- return balances ;
17
- } catch ( err ) {
18
- console . error ( `Error fetching balance for contract ${ contractId } :` , err . message ) ;
19
- return { } ;
20
- }
21
- } )
22
- ) ;
23
-
24
- const combinedBalances = balancesList . reduce ( ( acc , balances ) => {
25
- Object . entries ( balances ) . forEach ( ( [ key , value ] ) => {
26
- const numericValue = BigInt ( value || 0 ) ;
27
- acc [ key ] = acc [ key ] ? BigInt ( Math . max ( Number ( acc [ key ] ) , Number ( numericValue ) ) ) : numericValue ;
28
- } ) ;
29
- return acc ;
30
- } , { } ) ;
31
-
32
- console . log ( "Final combined balances:" , combinedBalances ) ;
33
-
34
- const totalTvl = Object . values ( combinedBalances ) . reduce ( ( sum , value ) => {
35
- return sum + Number ( value ) ;
36
- } , 0 ) ;
37
-
38
- const formattedBalances = Object . fromEntries (
39
- Object . entries ( combinedBalances ) . map ( ( [ key , value ] ) => [ key , value . toString ( ) ] )
40
- ) ;
41
-
42
- console . log ( "Formatted Balances for TVL:" , formattedBalances ) ;
43
-
44
- return formattedBalances ;
45
- } catch ( err ) {
46
- console . error ( "Unexpected error during TVL calculation:" , err . message ) ;
47
- return { } ;
48
- }
10
+ const balancesList = await Promise . all (
11
+ contractIds . map ( async ( contractId ) => {
12
+ const balances = await sumTokens ( { api, owner : contractId } ) ;
13
+ console . log ( `Balances from contract ${ contractId } :` , balances ) ;
14
+ return balances ;
15
+ } )
16
+ ) ;
17
+
18
+ const combinedBalances = balancesList . reduce ( ( acc , balances ) => {
19
+ Object . entries ( balances ) . forEach ( ( [ key , value ] ) => {
20
+ const numericValue = BigInt ( value || 0 ) ;
21
+ acc [ key ] = acc [ key ] ? BigInt ( Math . max ( Number ( acc [ key ] ) , Number ( numericValue ) ) ) : numericValue ;
22
+ } ) ;
23
+ return acc ;
24
+ } , { } ) ;
25
+
26
+ console . log ( "Final combined balances:" , combinedBalances ) ;
27
+
28
+ const totalTvl = Object . values ( combinedBalances ) . reduce ( ( sum , value ) => {
29
+ return sum + Number ( value ) ;
30
+ } , 0 ) ;
31
+
32
+ const formattedBalances = Object . fromEntries (
33
+ Object . entries ( combinedBalances ) . map ( ( [ key , value ] ) => [ key , value . toString ( ) ] )
34
+ ) ;
35
+
36
+ console . log ( "Formatted Balances for TVL:" , formattedBalances ) ;
37
+
38
+ return formattedBalances ;
49
39
}
50
40
51
41
module . exports = {
0 commit comments