Skip to content

Commit fb62555

Browse files
committed
tune vfat
1 parent 2301925 commit fb62555

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

projects/vfat/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { getLogs } = require('../helper/cache/getLogs');
22
const { sumTokens2, addUniV3LikePosition } = require('../helper/unwrapLPs');
33

44
const config = require('./config');
5-
const { sumLPBalances } = require('./utils');
5+
const { sumLPBalances, filteredV3LPTokens } = require('./utils');
66

77
// Helper function to fetch sickles
88
async function fetchSickles(api, factory, fromBlockSickle) {
@@ -175,9 +175,11 @@ async function tvlBaseOptimism(api) {
175175
await sumLPBalances(api, deployedAeroGauges.lp, sickles, stakingTokens);
176176

177177
const pools = await api.multiCall({ abi: 'address:pool', calls: deployedAeroGauges.nft });
178+
const whitelistedPoolList = new Set(await filteredV3LPTokens({ api, lpTokens: pools, minLPValue: 50e3 }));
178179
const slot0s = await api.multiCall({ abi: 'function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, bool unlocked)', calls: pools });
179180

180181
await Promise.all(deployedAeroGauges.nft.map(async (gauge, i) => {
182+
if (!whitelistedPoolList.has(pools[i])) return;
181183
const tick = slot0s[i].tick;
182184
const nftIds = (await api.multiCall({ abi: 'function stakedValues(address depositor) view returns (uint256[])', calls: sickles, target: gauge })).flat();
183185
const positions = await api.multiCall({ abi: 'function positions(uint256 tokenId) view returns (uint96 nonce, address operator, address token0, address token1, int24 tickSpacing, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1)', calls: nftIds, target: NonfungiblePositionManager, permitFailure: true, });
@@ -322,4 +324,4 @@ Object.keys(config).forEach(chain => {
322324
module.exports[chain] = { tvl }
323325
})
324326

325-
module.exports.isHeavyProtocol = true
327+
module.exports.isHeavyProtocol = true

projects/vfat/utils.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function sumLPBalances(api, gauges, sickles, lpTokens) {
66
lpTokens.forEach((lpToken, index) => lpTokens[index] = lpToken.toLowerCase())
77
let minLPValue = 4e3
88
if (lpTokens.length > 200) minLPValue = 15e3
9-
if (lpTokens.length > 400) minLPValue = 25e3
9+
if (lpTokens.length > 400) minLPValue = 40e3
1010

1111
const filteredLPSet = new Set(await filteredLPTokens({ api, lpTokens, minLPValue, }))
1212

@@ -24,7 +24,7 @@ async function sumLPBalances(api, gauges, sickles, lpTokens) {
2424
token = token.toLowerCase()
2525
return `${api.chain}:${gaugeTokenMapping[token] ?? token}`
2626
}
27-
await sumTokens2({ api, transformAddress, tokens, owners: sickles })
27+
await sumTokens2({ api, transformAddress, tokens, owners: sickles, sumChunkSize: 10000, })
2828
}
2929

3030
// 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 }) {
6767
}
6868

6969

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+
7098
module.exports = {
7199
sumLPBalances,
100+
filteredV3LPTokens,
72101
}

0 commit comments

Comments
 (0)