From df339b24fb26d1eb6d47faad1816849535a929f0 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:27:15 +0200 Subject: [PATCH] minor refactor --- projects/jones-dao/index.js | 46 ++++++++----------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/projects/jones-dao/index.js b/projects/jones-dao/index.js index 88011f79fe24..fa378a17fef1 100644 --- a/projects/jones-dao/index.js +++ b/projects/jones-dao/index.js @@ -43,47 +43,19 @@ async function tvl(api) { api.addTokens(metavaultTokens, metavaultBalances); api.addTokens(optionVaultTokens, optionVaultBalances); api.addTokens(addresses.tokens.usdc, jusdcTvl.output); + const getLPManagerContractsABI = "function getLPManagerContracts(uint256 _nonce) view returns (address lp,address viewer,address swapper,address receiver,address priceHelper,address lpManager,address doubleTracker,address singleTrackerZero,address singleTrackerOne,address compounder,address router)" - for (const factoryAddress of addresses.smartLpArbFactories) { - const nonce = await api.call({ - target: factoryAddress, - abi: "uint256:nonce", - }); - - const contracts = await api.multiCall({ - abi: "function getLPManagerContracts(uint256 _nonce) view returns (address lp,address viewer,address swapper,address receiver,address priceHelper,address lpManager,address doubleTracker,address singleTrackerZero,address singleTrackerOne,address compounder,address router)", - calls: Array.from({ length: nonce }, (_n, i) => i + 1).map((i) => ({ - target: factoryAddress, - params: [i], - })), - }); - const lpManagers = contracts.map((c) => c.lpManager); - - const [token0s, token1s, aums] = await Promise.all([ - api.multiCall({ - abi: "address:token0", - calls: lpManagers, - }), - api.multiCall({ - abi: "address:token1", - calls: lpManagers, - }), - api.multiCall({ - abi: "function aum() returns (uint256 amount0, uint256 amount1)", - calls: lpManagers, - }), - ]); - const balancesMap = aums.reduce((acc, { amount0, amount1 }, i) => { - acc[token0s[i]] = (acc[token0s[i]] ?? BigInt(0)) + BigInt(amount0); - acc[token1s[i]] = (acc[token1s[i]] ?? BigInt(0)) + BigInt(amount1); - return acc; - }, {}); + for (const factoryAddress of addresses.smartLpArbFactories) { + const contracts = await api.fetchList({ lengthAbi: 'nonce', itemAbi: getLPManagerContractsABI, target: factoryAddress, startFromOne: true }) + const lpManagers = contracts.map(c => c.lpManager) - const tokens = Object.keys(balancesMap); - const balances = Object.values(balancesMap); + const token0s = await api.multiCall({ abi: "address:token0", calls: lpManagers }) + const token1s = await api.multiCall({ abi: "address:token1", calls: lpManagers }) + const aums = await api.multiCall({ abi: "function aum() returns (uint256 amount0, uint256 amount1)", calls: lpManagers }) - api.addTokens(tokens, balances); + api.add(token0s, aums.map(a => a.amount0)) + api.add(token1s, aums.map(a => a.amount1)) } const tokensAndOwners = [