Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Dec 19, 2024
1 parent 3478b70 commit 50bffe6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
15 changes: 12 additions & 3 deletions projects/clober-v2/index.js
Original file line number Diff line number Diff line change
@@ -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)',
Expand All @@ -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 = {
Expand Down
15 changes: 4 additions & 11 deletions projects/sonic-market-amm/index.js
Original file line number Diff line number Diff line change
@@ -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'
})
Original file line number Diff line number Diff line change
@@ -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)',
Expand All @@ -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 = {
Expand Down

0 comments on commit 50bffe6

Please sign in to comment.