Skip to content

Commit 52e0db0

Browse files
g1nt0kilifeofjer
andauthored
* Ready for PR * Refactor * Refactor * Refactor * code refactor * Update index.js --------- Co-authored-by: Jeremy Crane <[email protected]>
1 parent fa7271b commit 52e0db0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

projects/alta-finance/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
methodology: "Sums the amount of funded real-world assets on ALTA Finance as borrowed. Tokens left in the countract are counted towards tvl",
3+
}
4+
5+
const config = {
6+
polygon: { investments: ['0xcf152E9f60E197A44FAdce961c6B822Dcb6c9dcc'], debts: ['0xE92F580C930dd24aACB38Ab0EA18F6c1dEf31369'], token: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' },
7+
}
8+
9+
Object.keys(config).forEach(chain => {
10+
const { investments, debts, token } = config[chain]
11+
module.exports[chain] = {
12+
tvl: async (_, _b, _cb, { api, }) => {
13+
return api.sumTokens({ owners: investments.concat(debts), tokens: [token] })
14+
},
15+
borrowed: async (_, _b, _cb, { api, }) => {
16+
const nftCount = (await api.multiCall({ abi: 'uint256:_tokenIdCounter', calls: investments, permitFailure: true })).map(i => i ?? 0)
17+
const amount = (await api.multiCall({ abi: 'uint256:amountPerNft', calls: investments, permitFailure: true })).map(i => i ?? 0)
18+
api.add(token, nftCount.map((v, i) => v * amount[i]))
19+
20+
const bals = (await api.multiCall({ abi: 'uint256:amount', calls: debts, permitFailure: true })).map(i => i ?? 0)
21+
api.add(token, bals)
22+
return api.getBalances()
23+
},
24+
}
25+
})

0 commit comments

Comments
 (0)