diff --git a/projects/btcfi-cdp/index.js b/projects/btcfi-cdp/index.js index 6390a554531e..feb54d33ea65 100644 --- a/projects/btcfi-cdp/index.js +++ b/projects/btcfi-cdp/index.js @@ -1,5 +1,7 @@ const ADDRESSES = require('../helper/coreAssets.json') const { sumTokensExport, } = require('../helper/unwrapLPs') +const { sumTokens } = require("../helper/chain/bitcoin"); +const { ethers } = require("ethers"); const chainPools = { bfc: { @@ -8,10 +10,33 @@ const chainPools = { }, } +const targetContract = "0x0000000000000000000000000000000000000100"; +const rpc = "https://public-01.mainnet.bifrostnetwork.com/rpc"; + +async function fetchVaultAddresses() { + const vaultContract = new ethers.Contract( + targetContract, + ["function vault_addresses(uint32 pool_round) view returns (string[])"], + new ethers.JsonRpcProvider(rpc) + ); + + const vaultAddresses = await vaultContract.vault_addresses(0); + + return vaultAddresses +} + +async function bitcoinTvl() { + return sumTokens({ owners: await fetchVaultAddresses() }) +} + Object.keys(chainPools).forEach(chain => { const pools = chainPools[chain] const tokensAndOwners = Object.values(pools).map(({ pool, token }) => ([token, pool,])) module.exports[chain] = { tvl: sumTokensExport({ tokensAndOwners }) } -}) \ No newline at end of file +}) + +module.exports["bitcoin"] = { + tvl: bitcoinTvl, +} \ No newline at end of file