Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions projects/clober-liquidity-vault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ const abi = {
}

const config = {
base: {
rebalancer: '0xeA0E19fbca0D9D707f3dA10Ef846cC255B0aAdf3',
bookManager: '0x382CCccbD3b142D7DA063bF68cd0c89634767F76',
blacklistedTokens: ['0x000000000000bb1b11e5ac8099e92e366b64c133'],
fromBlock: 21715410,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd rather keep this for historical accuracy

monad: {
rebalancer: '0xB09684f5486d1af80699BbC27f14dd5A905da873',
bookManager: '0x6657d192273731C3cAc646cc82D5F28D0CBE8CCC',
Expand All @@ -33,5 +27,4 @@ async function tvl(api) {
module.exports = {
methodology: "TVL includes all assets deposited into the Clober Liquidity Vault contract, specifically allocated for liquidity provision and market-making within the Clober ecosystem",
monad: { tvl },
base: { tvl },
}
35 changes: 0 additions & 35 deletions projects/clober-v2/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions projects/clober/abi.json

This file was deleted.

67 changes: 22 additions & 45 deletions projects/clober/index.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,33 @@
const abi = require("./abi.json");
const { ethers } = require("ethers");
const { getLogs2 } = require('../helper/cache/getLogs')
const { sumTokens2 } = require('../helper/unwrapLPs')
const { getUniqueAddresses } = require('../helper/utils')

const contractV1DeployedChainIds = [1, 137, 42161]
const contractV1_1DeployedChainIds = [137, 1101, 42161]

function calculateSalt(chainId, nonce) {
return ethers.solidityPackedKeccak256(['uint256', 'uint256'], [chainId, nonce])
const abi = {
openEvent: 'event Open(uint192 indexed id, address indexed base, address indexed quote, uint64 unitSize, uint24 makerPolicy, uint24 takerPolicy, address hooks)',
}

async function fetchTokenAddressesV1_0(api, chainId){
if(!contractV1DeployedChainIds.includes(chainId)){
return []
}
return await api.fetchList({
lengthAbi: abi.nonce,
itemAbi: "function computeTokenAddress(uint256) view returns (address)",
target: "0x93A43391978BFC0bc708d5f55b0Abe7A9ede1B91"
})
const config = {
monad: { factory: '0x6657d192273731C3cAc646cc82D5F28D0CBE8CCC', fromBlock: 31662843, },
}

async function fetchTokenAddressesV1_1(api, chainId){
if (!contractV1_1DeployedChainIds.includes(chainId)) {
return []
}
const maxNonce = await api.call({ abi: abi.nonce, target: "0x24aC0938C010Fb520F1068e96d78E0458855111D" })
return await api.multiCall({
abi: "function computeTokenAddress(bytes32) view returns (address)",
calls: Array.from({length: maxNonce}, (_, i) => i ).map((i, v) => ({ target: "0x58ed1f4913e652baF17C154551bd8E9dbc73fC56", params: calculateSalt(chainId, v) })),
})
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 chainId = await api.getChainId()
let tokenAddresses = [...await fetchTokenAddressesV1_0(api, chainId), ...await fetchTokenAddressesV1_1(api, chainId)]
tokenAddresses = tokenAddresses.flat()
const markets = await api.multiCall({ abi: abi.market, calls: tokenAddresses })
const base = await api.multiCall({ abi: abi.baseToken, calls: markets})
const quote = await api.multiCall({ abi: abi.quoteToken, calls: markets})
const tokens = [base, quote].flat()
const symbols = await api.multiCall({ abi: 'erc20:symbol', calls: tokens})
const putTokens = tokens.filter((_, i) => symbols[i].includes('$') && symbols[i].endsWith('PUT'))
const ownerTokens = markets.map((v, i) => ([[base[i], quote[i]], v]))
const putQutes = await api.multiCall({ abi: abi.quoteToken, calls: putTokens})
const putUnderlying = await api.multiCall({ abi: 'address:underlyingToken', calls: putTokens})
putTokens.forEach((v, i) => ownerTokens.push([[putQutes[i], putUnderlying[i]], v]))
return sumTokens2({ api, ownerTokens, blacklistedTokens: putTokens, })
const { factory, fromBlock } = config[api.chain]
const tokens = await getLogs2({ api, factory, eventAbi: abi.openEvent, fromBlock, extraKey: 'open-address', customCacheFunction,})
return sumTokens2({ api, owner: factory, tokens, permitFailure: true })
}

module.exports = {
methodology: "TVL consists of assets deposited into market contracts",
ethereum: { tvl },
polygon: { tvl },
arbitrum: { tvl },
polygon_zkevm: { tvl }
}
methodology: "TVL consists of assets deposited into the Clober Book Manager contract",
};

Object.keys(config).forEach(chain => {
module.exports[chain] = { tvl }
})
Loading