@@ -6,7 +6,7 @@ async function sumLPBalances(api, gauges, sickles, lpTokens) {
6
6
lpTokens . forEach ( ( lpToken , index ) => lpTokens [ index ] = lpToken . toLowerCase ( ) )
7
7
let minLPValue = 4e3
8
8
if ( lpTokens . length > 200 ) minLPValue = 15e3
9
- if ( lpTokens . length > 400 ) minLPValue = 25e3
9
+ if ( lpTokens . length > 400 ) minLPValue = 40e3
10
10
11
11
const filteredLPSet = new Set ( await filteredLPTokens ( { api, lpTokens, minLPValue, } ) )
12
12
@@ -24,7 +24,7 @@ async function sumLPBalances(api, gauges, sickles, lpTokens) {
24
24
token = token . toLowerCase ( )
25
25
return `${ api . chain } :${ gaugeTokenMapping [ token ] ?? token } `
26
26
}
27
- await sumTokens2 ( { api, transformAddress, tokens, owners : sickles } )
27
+ await sumTokens2 ( { api, transformAddress, tokens, owners : sickles , sumChunkSize : 10000 , } )
28
28
}
29
29
30
30
// we are going to filter out tokens that we dont have price in the server and LP tokens with less than 1k value in it
@@ -67,6 +67,35 @@ async function filteredLPTokens({ api, lpTokens, minLPValue = 10e3 }) {
67
67
}
68
68
69
69
70
+ // we are going to filter out tokens that we dont have price in the server and LP tokens with less than 1k value in it
71
+ async function filteredV3LPTokens ( { api, lpTokens, minLPValue = 10e3 } ) {
72
+ const token0s = await api . multiCall ( { abi : 'address:token0' , calls : lpTokens , permitFailure : true , } )
73
+ const token1s = await api . multiCall ( { abi : 'address:token1' , calls : lpTokens , permitFailure : true , } )
74
+ const tok1n0Bals = await api . multiCall ( { abi : 'erc20:balanceOf' , calls : lpTokens . map ( ( i , idx ) => ( { target : token0s [ idx ] , params : i } ) ) , permitFailure : true , } )
75
+ const tok1n1Bals = await api . multiCall ( { abi : 'erc20:balanceOf' , calls : lpTokens . map ( ( i , idx ) => ( { target : token1s [ idx ] , params : i } ) ) , permitFailure : true , } )
76
+ const allTokens = [ token0s , token1s , ] . flat ( ) . filter ( i => i ) . map ( i => i . toLowerCase ( ) )
77
+ const dummyBals = { }
78
+ allTokens . forEach ( i => dummyBals [ api . chain + ':' + i ] = 1e20 ) // hack to cache token prices to memory
79
+ await Balances . getUSDValue ( dummyBals )
80
+
81
+ const filteredLPTokens = [ ]
82
+ for ( let i = 0 ; i < lpTokens . length ; i ++ ) {
83
+ const lpBalance = new Balances ( { chain : api . chain , } )
84
+ lpBalance . add ( token0s [ i ] , tok1n0Bals [ i ] ?? 0 )
85
+ lpBalance . add ( token1s [ i ] , tok1n1Bals [ i ] ?? 0 )
86
+ const lpValue = await lpBalance . getUSDValue ( )
87
+ if ( lpValue < minLPValue ) { // LP has less than 2k value, we ignore it
88
+ continue ;
89
+ }
90
+ filteredLPTokens . push ( lpTokens [ i ] )
91
+ }
92
+
93
+ api . log ( api . chain , 'filteredLPTokens' , filteredLPTokens . length , 'out of' , lpTokens . length , 'LP tokens are filtered out.' )
94
+ return filteredLPTokens
95
+ }
96
+
97
+
70
98
module . exports = {
71
99
sumLPBalances,
100
+ filteredV3LPTokens,
72
101
}
0 commit comments