diff --git a/projects/visor/index.js b/projects/visor/index.js index e18edc2971f..4dcda274d65 100644 --- a/projects/visor/index.js +++ b/projects/visor/index.js @@ -1,62 +1,89 @@ -const { getLogs } = require('../helper/cache/getLogs') -const hypervisorAbi = require("./abis/hypervisor.json"); +const axios = require('axios') + +// Mapping deployment suffixes to chains (adjust as needed) +const CHAIN_SUFFIXES = { + ethereum: ['mainnet'], + arbitrum: ['arbitrum'], + polygon: ['polygon'], + optimism: ['optimism'], + bsc: ['bsc'], + base: ['base'], + moonbeam: ['moonbeam'], + celo: ['celo'], + avax: ['avalanche'], + fantom: ['fantom'], + mantle: ['mantle'], + rollux: ['rollux'], + linea: ['linea'], + kava: ['kava'], + op_bnb: ['op_bnb'], + manta: ['manta'], + metis: ['metis'], + xdai: ['gnosis', 'xdai'], + imx: ['immutable', 'imx'], + scroll: ['scroll'], + blast: ['blast'], + xlayer: ['xlayer'], + mode: ['mode'], + taiko: ['taiko'], + rsk: ['rootstock', 'rsk'], + iotaevm: ['iota'], + core: ['core'], + zircuit: ['zircuit'], + wc: ['worldchain', 'wc'], + apechain: ['apechain'], + sonic: ['sonic'], + bob: ['bob'], + hemi: ['hemi'], + nibiru: ['nibiru'], + sei: ['sei'], + berachain: ['berachain'], + unichain: ['unichain'], +}; + +// Optional: staking patch for Ethereum const { staking } = require("../helper/staking"); -const getTotalAmounts = - "function getTotalAmounts() view returns (uint256 total0, uint256 total1)"; -const { getUniqueAddresses } = require("../helper/utils"); -const config = require("./config"); -const { sumTokens2 } = require('../helper/unwrapLPs') -module.exports = { +let cachedDeployments = null; +let lastFetch = 0; +const CACHE_TIME = 60 * 1000; // 1 minute cache + +async function getDeployments() { + if (!cachedDeployments || (Date.now() - lastFetch) > CACHE_TIME) { + const { data } = await axios.get('https://api.gamma.xyz/allDeployments/hypervisors/aggregateStats?dexDesign=all'); + cachedDeployments = data.deployments; + lastFetch = Date.now(); + } + return cachedDeployments; +} + +async function getChainTVL(chain) { + const deployments = await getDeployments(); + const suffixes = CHAIN_SUFFIXES[chain]; + let tvl = 0; + Object.entries(deployments).forEach(([deployment, data]) => { + if (suffixes.some(suffix => deployment.endsWith('-' + suffix))) { + tvl += Number(data.totalValueLockedUSD || 0); + } + }); + return { usd: tvl }; +} + +const adapter = { doublecounted: true, - start: '2021-03-25', // (Mar-25-2021 01:42:42 PM +UTC) + start: '2021-03-25', }; -Object.keys(config).forEach(chain => { - let { blacklistedHypes = [], registries, LIQUIDITY_MINING_POOLS } = config[chain] - module.exports[chain] = { - tvl: async (api) => { - - if (LIQUIDITY_MINING_POOLS) { - const bals = await api.multiCall({ abi: hypervisorAbi.getHyperVisorData, calls: LIQUIDITY_MINING_POOLS, }); - bals.forEach(({ stakingToken, totalStake }) => api.add(stakingToken, totalStake)); - } - - let hypervisors = [] - for (const { factory, fromBlock } of registries) { - const logs = await getLogs({ - api, - target: factory, - eventAbi: 'event HypeAdded(address hype, uint256 index)', - onlyArgs: true, - fromBlock, - }) - hypervisors.push(...logs.map(i => i.hype)) - } - hypervisors = getUniqueAddresses(hypervisors); - if (blacklistedHypes.length) { - const blacklistSet = new Set(blacklistedHypes.map((i) => i.toLowerCase())); - hypervisors = hypervisors.filter((i) => !blacklistSet.has(i.toLowerCase())); - } - const supplies = await api.multiCall({ - abi: "erc20:totalSupply", - calls: hypervisors, - permitFailure: true, - }); - hypervisors = hypervisors.filter((_, i) => +supplies[i] > 0); - - const [token0s, token1s, bals] = await Promise.all([ - api.multiCall({ calls: hypervisors, abi: "address:token0" }), - api.multiCall({ calls: hypervisors, abi: "address:token1" }), - api.multiCall({ calls: hypervisors, abi: getTotalAmounts }), - ]); - bals.forEach(({ total0, total1 }, i) => { - api.add(token0s[i], total0); - api.add(token1s[i], total1); - }); - return sumTokens2({ api }) - } +Object.keys(CHAIN_SUFFIXES).forEach(chain => { + adapter[chain] = { + tvl: async () => getChainTVL(chain), } }) -module.exports.ethereum.staking = staking("0x26805021988f1a45dc708b5fb75fc75f21747d8c", "0x6bea7cfef803d1e3d5f7c0103f7ded065644e197",) +// Ethereum staking export (optional) +adapter.ethereum.staking = staking( + "0x26805021988f1a45dc708b5fb75fc75f21747d8c", + "0x6bea7cfef803d1e3d5f7c0103f7ded065644e197" +); + +module.exports = adapter; \ No newline at end of file