Skip to content

Commit

Permalink
wildcat: fix borrowed tvl
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Dec 28, 2023
1 parent 649de2d commit 5c9dff5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions projects/wildcat-fi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
})

0 comments on commit 5c9dff5

Please sign in to comment.