diff --git a/projects/clober-v2/index.js b/projects/clober-v2/index.js index d704c67ef2ff..65c6b40aa124 100644 --- a/projects/clober-v2/index.js +++ b/projects/clober-v2/index.js @@ -1,4 +1,6 @@ const { getLogs2 } = require('../helper/cache/getLogs') +const { sumTokens2 } = require('../helper/unwrapLPs') +const { getUniqueAddresses } = require('../helper/utils') const abi = { openEvent: 'event Open(uint192 indexed id, address indexed base, address indexed quote, uint64 unitSize, uint24 makerPolicy, uint24 takerPolicy, address hooks)', @@ -9,11 +11,18 @@ const config = { era: { factory: '0xAaA0e933e1EcC812fc075A81c116Aa0a82A5bbb8', fromBlock: 34448160, }, } +function customCacheFunction({ cache, logs }) { + if (!cache.logs) cache.logs = [] + const tokens = logs.map(({ base, quote }) => [base, quote]).flat() + cache.logs.push(...tokens) + cache.logs = getUniqueAddresses(cache.logs) + return cache +} + async function tvl(api) { const { factory, fromBlock } = config[api.chain] - const logs = await getLogs2({ api, factory, eventAbi: abi.openEvent, fromBlock, extraKey: 'open-address', }) - const tokens = logs.map(({ base, quote }) => [base, quote]).flat() - return api.sumTokens({ owner: factory, tokens, }) + const tokens = await getLogs2({ api, factory, eventAbi: abi.openEvent, fromBlock, extraKey: 'open-address', customCacheFunction, skipCacheRead: true }) + return sumTokens2({ api, owner: factory, tokens, permitFailure: true }) } module.exports = { diff --git a/projects/sonic-market-amm/index.js b/projects/sonic-market-amm/index.js index 64be85982c68..aaef76582be4 100644 --- a/projects/sonic-market-amm/index.js +++ b/projects/sonic-market-amm/index.js @@ -1,11 +1,4 @@ -const { getUniTVL } = require("../helper/unknownTokens"); - -module.exports = { - methodology: "TVL consists of assets deposited into the Sonic Market AMM contract", - sonic: { - tvl: getUniTVL({ - factory: "0x01D6747dD2d65dDD90FAEC2C84727c2706ee28E2", - useDefaultCoreAssets: true, - }), - } -}; +const { uniTvlExports } = require('../helper/unknownTokens') +module.exports = uniTvlExports({ + 'sonic': '0x01D6747dD2d65dDD90FAEC2C84727c2706ee28E2' +}) \ No newline at end of file diff --git a/projects/sonic-market/index.js b/projects/sonic-market-orderbook/index.js similarity index 57% rename from projects/sonic-market/index.js rename to projects/sonic-market-orderbook/index.js index ab8a8798e2f3..aba82ce753f7 100644 --- a/projects/sonic-market/index.js +++ b/projects/sonic-market-orderbook/index.js @@ -1,4 +1,6 @@ const { getLogs2 } = require('../helper/cache/getLogs') +const { sumTokens2 } = require('../helper/unwrapLPs') +const { getUniqueAddresses } = require('../helper/utils') const abi = { openEvent: 'event Open(uint192 indexed id, address indexed base, address indexed quote, uint64 unitSize, uint24 makerPolicy, uint24 takerPolicy, address hooks)', @@ -8,11 +10,18 @@ const config = { sonic: { factory: '0xD4aD5Ed9E1436904624b6dB8B1BE31f36317C636', fromBlock: 297198, }, } +function customCacheFunction({ cache, logs }) { + if (!cache.logs) cache.logs = [] + const tokens = logs.map(({ base, quote }) => [base, quote]).flat() + cache.logs.push(...tokens) + cache.logs = getUniqueAddresses(cache.logs) + return cache +} + async function tvl(api) { const { factory, fromBlock } = config[api.chain] - const logs = await getLogs2({ api, factory, eventAbi: abi.openEvent, fromBlock, extraKey: 'open-address', }) - const tokens = logs.map(({ base, quote }) => [base, quote]).flat() - return api.sumTokens({ owner: factory, tokens, }) + const tokens = await getLogs2({ api, factory, eventAbi: abi.openEvent, fromBlock, extraKey: 'open-address', customCacheFunction, skipCacheRead: true }) + return sumTokens2({ api, owner: factory, tokens, permitFailure: true }) } module.exports = {