|
| 1 | + |
1 | 2 | async function tvl(api) {
|
2 | 3 | const zooProtocol = '0xc0fA386aE92f18A783476d09121291A1972C30Dc'
|
3 | 4 | const assets = await api.call({ abi: 'address[]:assetTokens', target: zooProtocol })
|
| 5 | + |
| 6 | + // Normally, assets are routed to other vaults like Infrared, Yeet, etc |
4 | 7 | const vaults = (await api.multiCall({ abi: 'function getVaultAddresses(address) view returns (address[])', calls: assets, target: zooProtocol })).flat()
|
5 |
| - const bals = await api.multiCall({ abi: 'uint256:assetBalance', calls: vaults }) |
6 |
| - const tokens = await api.multiCall({ abi: 'address:assetToken', calls: vaults }) |
7 |
| - api.add(tokens, bals) |
| 8 | + const assetBals = await api.multiCall({ abi: 'uint256:assetBalance', calls: vaults }) |
| 9 | + api.add(assets, assetBals) |
| 10 | + |
| 11 | + // On vault close, assets are withdrawn from underlying vaults and held by the vault itself |
| 12 | + const tokensAndOwners = vaults.map((vault, i) => [assets[i], vault]) |
| 13 | + |
| 14 | + |
| 15 | + // On every epoch close, a portion of assets are withdrawn from underlying vaults, and deposited to the redeem pool contract |
| 16 | + const epochInfoAbi = 'function epochInfoById(uint256 epochId) public view returns (uint256 epochId, uint256 startTime, uint256 duration, address redeemPool, address stakingBribesPool, address adhocBribesPool)' |
| 17 | + const epochInfos = await api.fetchList({ lengthAbi: 'epochIdCount', itemAbi: epochInfoAbi, targets: vaults, startFromOne: true, groupedByInput: true }) |
| 18 | + |
| 19 | + epochInfos.forEach((infos, i) => { |
| 20 | + const asset = assets[i] |
| 21 | + infos.forEach(({ redeemPool }) => { |
| 22 | + tokensAndOwners.push([asset, redeemPool]) |
| 23 | + }) |
| 24 | + }) |
| 25 | + |
| 26 | + return api.sumTokens({ tokensAndOwners }) |
8 | 27 | }
|
9 | 28 |
|
10 | 29 | module.exports = {
|
|
0 commit comments