From 6b9739e79d150006096c465f98d2316a2c03ef86 Mon Sep 17 00:00:00 2001 From: qiuchenghui <243852877@qq.com> Date: Mon, 15 Sep 2025 13:10:06 +0800 Subject: [PATCH] feat: update ring dex and remove ring few --- projects/ring-dex/index.js | 49 +++++++++++++++++++++++++++++--------- projects/ring-few/index.js | 25 ------------------- 2 files changed, 38 insertions(+), 36 deletions(-) delete mode 100644 projects/ring-few/index.js diff --git a/projects/ring-dex/index.js b/projects/ring-dex/index.js index cad23889d1..cf87290d10 100644 --- a/projects/ring-dex/index.js +++ b/projects/ring-dex/index.js @@ -1,4 +1,8 @@ + const { sumTokens2 } = require('../helper/unwrapLPs') +const uniswapAbi = require("../helper/abis/uniswap") +const { getUniqueAddresses, } = require("../helper/utils") +const sdk = require('@defillama/sdk') const fewFactoryConfig = { ethereum: { factory: '0x7D86394139bf1122E82FDF45Bb4e3b038A4464DD' }, @@ -21,18 +25,41 @@ const factoryConfig = { Object.keys(fewFactoryConfig).forEach(chain => { module.exports[chain] = { tvl: async (api) => { + const balances = {} const fewTokens = await api.fetchList({ lengthAbi: 'allWrappedTokensLength', itemAbi: 'allWrappedTokens', target: fewFactoryConfig[chain].factory }) - const pairs = await api.fetchList({ lengthAbi: 'allPairsLength', itemAbi: 'allPairs', target: factoryConfig[chain].factory }) - const token0s = await api.multiCall({ abi: 'address:token0', calls: pairs }) - const token1s = await api.multiCall({ abi: 'address:token1', calls: pairs }) - const allTokens = token0s.concat(token1s) - const names = await api.multiCall({ abi: 'string:name', calls: allTokens, permitFailure: true }) - names.forEach((name, i) => { - if (!name) return; - if (name.startsWith('Few Wrapped')) fewTokens.push(allTokens[i]) + const originTokens = await api.multiCall({ abi: 'address:token', calls: fewTokens }) + const calls = await api.fetchList({ lengthAbi: 'allPairsLength', itemAbi: 'allPairs', target: factoryConfig[chain].factory }) + const token0s = await api.multiCall({ abi: uniswapAbi.token0, calls }) + const token1s = await api.multiCall({ abi: uniswapAbi.token1, calls }) + const reserves = await api.multiCall({ abi: uniswapAbi.getReserves, calls }) + const token0symbols = await api.multiCall({ abi: 'string:symbol', calls: token0s, permitFailure: true }) + const token1symbols = await api.multiCall({ abi: 'string:symbol', calls: token1s, permitFailure: true }) + const fewSymbols = await api.multiCall({ abi: 'string:symbol', calls: fewTokens, permitFailure: true }) + + reserves.forEach(({ _reserve0, _reserve1 }, i) => { + const index0 = fewTokens.findIndex(token => token === token0s[i]) + const index1 = fewTokens.findIndex(token => token === token1s[i]) + if (token0symbols[i] && !(token0symbols[i].includes('RING') || token0symbols[i].includes('RNG'))) { + if (fewSymbols[index0]) { + sdk.util.sumSingleBalance(balances, originTokens[index0], _reserve0, chain) + } else { + sdk.util.sumSingleBalance(balances, token0s[i], _reserve0, chain) + } + } + if (token1symbols[i] && !(token1symbols[i].includes('RING') || token1symbols[i].includes('RNG'))) { + if (fewSymbols[index1]) { + sdk.util.sumSingleBalance(balances, originTokens[index1], _reserve1, chain) + } else { + sdk.util.sumSingleBalance(balances, token1s[i], _reserve1, chain) + } + } + }) + + const tokens = new Set([...token0s, ...token1s, ...originTokens]) + + return sumTokens2({ + chain, owner: factoryConfig[chain].factory, tokens: getUniqueAddresses(tokens), balances, }) - const ownerTokens = pairs.map(((pair, i) => [[token0s[i], token1s[i]], pair])) - return sumTokens2({ api, ownerTokens, blacklistedTokens: fewTokens, }) } } -}); +}); \ No newline at end of file diff --git a/projects/ring-few/index.js b/projects/ring-few/index.js deleted file mode 100644 index 20f0234971..0000000000 --- a/projects/ring-few/index.js +++ /dev/null @@ -1,25 +0,0 @@ - -const config = { - ethereum: { factory: '0x7D86394139bf1122E82FDF45Bb4e3b038A4464DD' }, - blast: { factory: '0x455b20131D59f01d082df1225154fDA813E8CeE9' }, - bsc: { factory: '0xEeE400Eabfba8F60f4e6B351D8577394BeB972CD' }, - base: { factory: '0xb3Ad7754f363af676dC1C5be40423FE538a47920' }, - arbitrum: { factory: '0x974Cc3F3468cd9C12731108148C4DABFB5eE556F' }, - hyperliquid: { factory: '0x6B65ed7315274eB9EF06A48132EB04D808700b86' } -} - -module.exports = { - doublecounted: true, -}; - -Object.keys(config).forEach(chain => { - module.exports[chain] = { - tvl: async (api) => { - const fewTokens = await api.fetchList({ lengthAbi: 'allWrappedTokensLength', itemAbi: 'allWrappedTokens', target: config[chain].factory }) - const tokens = await api.multiCall({ abi: 'address:token', calls: fewTokens }) - const symbols = await api.multiCall({ abi: 'string:symbol', calls: tokens, permitFailure: true }) - const blacklistedTokens = tokens.filter((token, i) => symbols[i] && (symbols[i].includes('RING') || symbols[i].includes('RNG') || symbols[i] === 'USDR' || symbols[i].startsWith('fw'))) - return api.sumTokens({ tokensAndOwners2: [tokens, fewTokens], blacklistedTokens, }) - } - } -}) \ No newline at end of file