From 5c9dff560b6a553127f181fd2bd641bb7d193998 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Thu, 28 Dec 2023 14:36:25 +0100 Subject: [PATCH] wildcat: fix borrowed tvl --- projects/wildcat-fi/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/projects/wildcat-fi/index.js b/projects/wildcat-fi/index.js index d5546088e7b..400f16678a8 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