diff --git a/projects/wildcat-fi/index.js b/projects/wildcat-fi/index.js index d5546088e7..400f16678a 100644 --- a/projects/wildcat-fi/index.js +++ b/projects/wildcat-fi/index.js @@ -8,20 +8,25 @@ Object.keys(config).forEach(chain => { const { archController } = config[chain] module.exports[chain] = { tvl: async (_, _b, _cb, { api, }) => { - const { markets, tokens} = await getMarkets(api) - return api.sumTokens({ tokensAndOwners2: [tokens, markets]}) + const { markets, tokens } = await getMarkets(api) + return api.sumTokens({ tokensAndOwners2: [tokens, markets] }) }, borrowed: async (_, _b, _cb, { api, }) => { - const { markets, tokens} = await getMarkets(api) - const debts = await api.multiCall({ abi: 'uint256:delinquentDebt', calls: markets}) - api.addTokens(tokens, debts) + const { markets, tokens } = await getMarkets(api) + const debts = await api.multiCall({ abi: 'uint256:totalDebts', calls: markets }) + const assets = await api.multiCall({ abi: 'uint256:totalAssets', calls: markets }) + tokens.forEach((token, i) => { + const bal = debts[i] - assets[i] + if (bal > 0) + api.add(token, bal) + }) return api.getBalances() } } async function getMarkets(api) { - const markets = await api.call({ abi: 'address[]:getRegisteredMarkets', target: archController}) - const tokens = await api.multiCall({ abi: 'address:asset', calls: markets}) + const markets = await api.call({ abi: 'address[]:getRegisteredMarkets', target: archController }) + const tokens = await api.multiCall({ abi: 'address:asset', calls: markets }) return { markets, tokens } } }) \ No newline at end of file