@@ -30,103 +30,24 @@ async function tvl(api) {
30
30
await vaultBalance ( api , graphData ) ;
31
31
await otherDeposit ( api , address ) ;
32
32
await ceffuBalance ( api , address , graphData ) ;
33
-
34
- return api . getBalances ( ) ;
35
33
}
36
34
37
- async function borrowed ( api ) {
38
- const network = api . chain ;
39
-
40
- const graphData = await getGraphData ( api . timestamp , network , api ) ;
41
- if ( graphData . pools . length > 0 ) {
42
- const poolLists = graphData . pools ;
43
-
44
- let address = ( await getConfig ( 'solv-protocol/funds' , addressUrl ) ) ;
45
- const depositAddress = filterDepositAddress ( network , address ) ;
46
-
47
- let fofFundPoolId = [ ] ;
48
- if ( address [ network ] && address [ network ] [ "fofFund" ] ) {
49
- fofFundPoolId = address [ network ] [ "fofFund" ] ;
50
- }
51
-
52
- let pools = [ ] ;
53
- for ( const pool of poolLists ) {
54
- if ( depositAddress . length == 0 && depositAddress . indexOf ( pool . vault ) == - 1 && fofFundPoolId . indexOf ( pool . poolId ) == - 1 ) {
55
- pools . push ( pool ) ;
56
- }
57
- }
58
-
59
- const poolConcretes = await concrete ( pools , api ) ;
60
- const nav = await api . multiCall ( {
61
- abi : abi . getSubscribeNav ,
62
- calls : pools . map ( ( index ) => ( {
63
- target : index . navOracle ,
64
- params : [ index . poolId , api . timestamp * 1000 ]
65
- } ) ) ,
66
- } )
67
-
68
- const poolTotalValues = await api . multiCall ( {
69
- abi : abi . slotTotalValue ,
70
- calls : pools . map ( ( index ) => ( {
71
- target : poolConcretes [ index . contractAddress ] ,
72
- params : [ index . openFundShareSlot ]
73
- } ) ) ,
74
- } )
75
-
76
- const poolBaseInfos = await api . multiCall ( {
77
- abi : abi . slotBaseInfo ,
78
- calls : pools . map ( ( index ) => ( {
79
- target : poolConcretes [ index . contractAddress ] ,
80
- params : [ index . openFundShareSlot ]
81
- } ) ) ,
82
- } )
83
-
84
- const poolDecimalList = await api . multiCall ( {
85
- abi : abi . decimals ,
86
- calls : poolBaseInfos . map ( i => i [ 1 ] ) ,
87
- } )
88
-
89
- let vaults = { } ;
90
- for ( const key in pools ) {
91
- if ( poolBaseInfos [ key ] [ 1 ] && pools [ key ] [ "vault" ] ) {
92
- vaults [ `${ pools [ key ] [ "vault" ] . toLowerCase ( ) } -${ poolBaseInfos [ key ] [ 1 ] . toLowerCase ( ) } ` ] = [ poolBaseInfos [ key ] [ 1 ] , pools [ key ] [ "vault" ] ]
93
- }
94
- }
95
-
96
- const symbols = await api . multiCall ( {
97
- abi : abi . symbol ,
98
- calls : poolBaseInfos . map ( ( index ) => ( {
99
- target : index [ 1 ]
100
- } ) ) ,
101
- } )
102
-
103
- const balances = await api . multiCall ( {
104
- abi : abi . balanceOf ,
105
- calls : Object . values ( vaults ) . map ( ( index ) => ( {
106
- target : index [ 0 ] ,
107
- params : [ index [ 1 ] ]
108
- } ) ) ,
109
- } )
35
+ const solvbtcListUrl = 'https://raw.githubusercontent.com/solv-finance-dev/slov-protocol-defillama/main/solvbtc.json' ;
36
+ async function getSolvBTCVAddresses ( api ) {
37
+ let solvbtc = ( await getConfig ( 'solv-protocol/solvbtc' , solvbtcListUrl ) ) ;
110
38
111
- let vaultbalances = { } ;
112
- for ( let i = 0 ; i < Object . keys ( vaults ) . length ; i ++ ) {
113
- vaultbalances [ Object . keys ( vaults ) [ i ] ] = balances [ i ] ;
114
- }
115
- for ( let i = 0 ; i < poolTotalValues . length ; i ++ ) {
116
- const decimals = poolDecimalList [ i ] ;
117
- let balance = BigNumber ( poolTotalValues [ i ] ) . div ( BigNumber ( 10 ) . pow ( 18 - decimals ) ) . times ( BigNumber ( nav [ i ] . nav_ ) . div ( BigNumber ( 10 ) . pow ( decimals ) ) ) . toNumber ( ) ;
118
- if ( pools [ i ] [ 'vault' ] && poolBaseInfos [ i ] [ 1 ] && vaultbalances [ `${ pools [ i ] [ 'vault' ] . toLowerCase ( ) } -${ poolBaseInfos [ i ] [ 1 ] . toLowerCase ( ) } ` ] ) {
119
- balance = BigNumber ( balance ) . minus ( vaultbalances [ `${ pools [ i ] [ 'vault' ] . toLowerCase ( ) } -${ poolBaseInfos [ i ] [ 1 ] . toLowerCase ( ) } ` ] ) . toNumber ( ) ;
120
- vaultbalances [ `${ pools [ i ] [ 'vault' ] . toLowerCase ( ) } -${ poolBaseInfos [ i ] [ 1 ] . toLowerCase ( ) } ` ] = undefined
121
- }
122
- if ( balance > 0 ) {
123
- if ( symbols [ i ] !== "SolvBTC" ) {
124
- api . add ( poolBaseInfos [ i ] [ 1 ] , balance )
125
- }
126
- }
39
+ const blacklisted = { }
40
+ if ( ! solvbtc [ api . chain ] || ! solvbtc [ api . chain ] [ "otherDeposit" ] ) {
41
+ return blacklisted
42
+ }
43
+ let otherDeposit = solvbtc [ api . chain ] [ "otherDeposit" ] ;
44
+ for ( const deposit of otherDeposit [ "depositAddress" ] ) {
45
+ for ( const tokenAddress of otherDeposit [ "tokens" ] ) {
46
+ const key = `${ tokenAddress } -${ deposit } ` . toLowerCase ( )
47
+ blacklisted [ key ] = true
127
48
}
128
49
}
129
- return api . getBalances ( )
50
+ return blacklisted
130
51
}
131
52
132
53
async function otherDeposit ( api , address ) {
@@ -328,27 +249,17 @@ async function vaultBalance(api, graphData) {
328
249
vaults [ `${ poolBaseInfos [ key ] [ 1 ] . toLowerCase ( ) } -${ poolLists [ key ] [ "vault" ] . toLowerCase ( ) } ` ] = [ poolBaseInfos [ key ] [ 1 ] , poolLists [ key ] [ "vault" ] ]
329
250
}
330
251
}
331
-
332
- const symbols = await api . multiCall ( {
333
- abi : abi . symbol ,
334
- calls : Object . values ( vaults ) . map ( ( index ) => ( {
335
- target : index [ 0 ]
336
- } ) ) ,
252
+ const tokens = Object . values ( vaults ) . map ( ( [ token ] ) => token )
253
+
254
+ const symbols = await api . multiCall ( { abi : abi . symbol , calls : tokens , } )
255
+ const blacklisted = await getSolvBTCVAddresses ( api )
256
+ const blacklistedTokens = tokens . filter ( ( token , i ) => symbols [ i ] . toLowerCase ( ) . includes ( 'solvbtc' ) )
257
+ const tokensAndOwners = Object . values ( vaults ) . filter ( ( [ token , owner ] ) => {
258
+ const key = `${ token } -${ owner } ` . toLowerCase ( )
259
+ return ! blacklisted [ key ] && ! blacklistedTokens . includes ( token )
337
260
} )
338
-
339
- const balances = await api . multiCall ( {
340
- abi : abi . balanceOf ,
341
- calls : Object . values ( vaults ) . map ( ( index ) => ( {
342
- target : index [ 0 ] ,
343
- params : [ index [ 1 ] ]
344
- } ) ) ,
345
- } )
346
-
347
- for ( const key in balances ) {
348
- if ( symbols [ key ] !== "SolvBTC" ) {
349
- api . add ( Object . values ( vaults ) [ key ] [ 0 ] , balances [ key ] )
350
- }
351
- }
261
+
262
+ return api . sumTokens ( { tokensAndOwners, blacklistedTokens, } )
352
263
}
353
264
}
354
265
@@ -357,7 +268,7 @@ async function ceffuBalance(api, address, graphData) {
357
268
return ;
358
269
}
359
270
let ceffuData = address [ api . chain ] [ "ceffu" ] ;
360
-
271
+
361
272
let pools = [ ] ;
362
273
for ( const graph of graphData . pools ) {
363
274
if ( graph [ 'openFundShareSlot' ] == ceffuData [ 'slot' ] ) {
@@ -479,40 +390,10 @@ async function getGraphData(timestamp, chain, api) {
479
390
} ;
480
391
}
481
392
482
- function filterDepositAddress ( network , address ) {
483
- let depositAddresses = [ ] ;
484
- if ( address [ network ] ) {
485
- if ( address [ network ] [ "gm" ] ) {
486
- for ( let depositAddress of address [ network ] [ "gm" ] [ "depositAddress" ] ) {
487
- depositAddresses . push ( depositAddress . toLowerCase ( ) )
488
- }
489
- }
490
- if ( address [ network ] [ "mux" ] ) {
491
- depositAddresses . push ( address [ network ] [ "mux" ] [ "account" ] . toLowerCase ( ) )
492
- }
493
- if ( address [ network ] [ "klp" ] ) {
494
- for ( let poolAddress of address [ network ] [ "klp" ] [ "klpPool" ] ) {
495
- depositAddresses . push ( poolAddress . toLowerCase ( ) )
496
- }
497
- }
498
- if ( address [ network ] [ "iziswap" ] ) {
499
- for ( let owner of address [ network ] [ "iziswap" ] [ "owner" ] ) {
500
- depositAddresses . push ( owner . toLowerCase ( ) )
501
- }
502
- }
503
- if ( address [ network ] [ "lendle" ] ) {
504
- depositAddresses . push ( address [ network ] [ "lendle" ] [ "account" ] [ "user" ] . toLowerCase ( ) )
505
- }
506
- }
507
-
508
- return depositAddresses ;
509
- }
510
-
511
393
512
394
// node test.js projects/solv-protocol-funds
513
395
[ 'ethereum' , 'bsc' , 'polygon' , 'arbitrum' , 'mantle' , 'merlin' ] . forEach ( chain => {
514
396
module . exports [ chain ] = {
515
- tvl,
516
- borrowed
397
+ tvl
517
398
}
518
399
} )
0 commit comments