|
1 | 1 | const sdk = require('@defillama/sdk') |
2 | 2 |
|
3 | | -async function computeMarketCap(api, asset) { |
4 | | - const abi = 'function latestRoundData() view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)' |
5 | | - const { answer: price } = await api.call({ abi, target: asset.priceFeed }) |
6 | | - const totalSupply = await api.call({ abi: 'erc20:totalSupply', target: asset.assetId }) |
7 | | - const marketCap = (Number(totalSupply) / 10 ** 18) * (Number(price) / 10 ** 8) |
8 | | - sdk.util.sumSingleBalance(api.getBalances(), 'coingecko:usd-coin', marketCap) |
| 3 | +async function computeMarketCap(api, assets, token) { |
| 4 | + const priceFeedAbi = 'function latestRoundData() view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)' |
| 5 | + const assetList = Array.isArray(assets) ? assets : [assets] |
| 6 | + |
| 7 | + await Promise.all(assetList.map(async (asset) => { |
| 8 | + const { answer: price } = await api.call({ abi: priceFeedAbi, target: asset.priceFeed }) |
| 9 | + const totalSupply = await api.call({ abi: 'erc20:totalSupply', target: asset.assetId }) |
| 10 | + const assetDecimals = asset.decimals ?? 18 |
| 11 | + const priceDecimals = asset.priceDecimals ?? 8 |
| 12 | + const marketCap = (Number(totalSupply) / 10 ** assetDecimals) * (Number(price) / 10 ** priceDecimals) |
| 13 | + sdk.util.sumSingleBalance(api.getBalances(), token, marketCap) |
| 14 | + })) |
| 15 | + |
9 | 16 | return api.getBalances() |
10 | 17 | } |
11 | 18 |
|
12 | 19 | module.exports = { |
13 | 20 | base: { |
14 | | - tvl: async (api) => computeMarketCap(api, { |
| 21 | + tvl: async (api) => computeMarketCap(api, [{ |
15 | 22 | assetId: '0xcCa6848034d327fAc4D60126Ac6ee26708BDfe9d', // KOODOG Token |
16 | 23 | priceFeed: '0x7B4dc9df689afbf5dDe58d474C229c3d2fb4cd85', |
17 | | - }) |
| 24 | + }, { |
| 25 | + assetId: '0x25a0e808A7Ed833EA9e9C0B643Eb8B6832af3749', // MURFLO Token |
| 26 | + priceFeed: '0x6913A66f54DAe935fD489f34728D20aeEB43A6bB', |
| 27 | + }], 'coingecko:usd-coin'), |
18 | 28 | }, |
19 | 29 | bsc: { |
20 | | - tvl: async (api) => computeMarketCap(api, { |
| 30 | + tvl: async (api) => computeMarketCap(api, [{ |
21 | 31 | assetId: '0x8c3b6Bf5078bE53B7462353218853129B642943C', // HOCPOOL Token |
22 | 32 | priceFeed: '0x8eB682CdC4E7F913414274a54db1ca35bcC0c4bC', |
23 | | - }) |
| 33 | + }, { |
| 34 | + assetId: '0x2024739806E4DEb480481150C45340fB800cB8fe', // MURFLO Token |
| 35 | + priceFeed: '0x102a2a121F6d54cCc137978642c6294a73c971d7', |
| 36 | + }], 'coingecko:tether') |
| 37 | + }, |
| 38 | + berachain: { |
| 39 | + tvl: async (api) => computeMarketCap(api, [{ |
| 40 | + assetId: '0x25a0e808A7Ed833EA9e9C0B643Eb8B6832af3749', // MURFLO Token |
| 41 | + priceFeed: '0x0C0ccB0d5de18E0a208225585f0de4288D8dD2ff', |
| 42 | + }], 'coingecko:tether') |
24 | 43 | }, |
25 | 44 | }; |
0 commit comments