Skip to content
Closed
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
46 changes: 40 additions & 6 deletions projects/theo-network/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
const { getConfig } = require('../helper/cache')

// thBill token addresses
const THBILL = {
ethereum: "0x5FA487BCa6158c64046B2813623e20755091DA0b",
arbitrum: "0xfdd22ce6d1f66bc0ec89b20bf16ccb6670f55a5a",
base: "0xfdd22ce6d1f66bc0ec89b20bf16ccb6670f55a5a",
hyperliquid: "0xfdd22ce6d1f66bc0ec89b20bf16ccb6670f55a5a"
}

// Chains where your vaults/vaultInfo endpoint applies (skip hyperliquid here)
const CHAINS_WITH_VAULTS = ["ethereum", "arbitrum", "base", "linea"]
const ETH_ADAPTER = "0xfdd22ce6d1f66bc0ec89b20bf16ccb6670f55a5a"

const config = {
ethereum: {},
arbitrum: {},
base: {},
linea: {},
hyperliquid: {}
}

Object.keys(config).forEach(chain => {
module.exports[chain] = {
tvl: async (api) => {
const { [chain]: data } = await getConfig('theo-network', "https://vaults.theo.xyz/vaults/vaultInfo");
// vault balance
if (CHAINS_WITH_VAULTS.includes(chain)) {
const { [chain]: data } = await getConfig('theo-network', "https://vaults.theo.xyz/vaults/vaultInfo");

const calls = Object.values(data).map(i => i.contract)
const tokens = Object.values(data).map(i => i.asset)
const bals = await api.multiCall({ abi: 'uint256:totalBalance', calls })
api.add(tokens, bals)
}

// thBill balance
const addr = THBILL[chain]
if (!addr) return


const calls = Object.values(data).map(i => i.contract)
const tokens = Object.values(data).map(i => i.asset)
const bals = await api.multiCall({ abi: 'uint256:totalBalance', calls })
api.add(tokens, bals)
// for mainnet, subtract balance of adapter to avoid double counting
if (chain === "ethereum") {
const [totalSupply, locked] = await Promise.all([
api.call({ target: addr, abi: 'erc20:totalSupply' }),
api.call({ target: addr, abi: 'erc20:balanceOf', params: [ETH_ADAPTER] }),
])
const effective = totalSupply - locked
if (effective > 0n) api.add(addr, effective)
} else {
const supply = await api.call({ target: addr, abi: 'erc20:totalSupply' })
api.add(addr, supply)
}
}
}
})
})
Loading