Skip to content

Commit ce73da8

Browse files
committed
stability adapter
1 parent d2fe61a commit ce73da8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

projects/stability/abi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"vaultAddresses": "function vaultAddresses() view returns (address[] memory vaultAddress)",
3+
"strategy": "address:strategy",
4+
"assetsAmounts": "function assetsAmounts() view returns (address[] memory assets_, uint[] memory amounts_)"
5+
}

projects/stability/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const abi = require('./abi.json')
2+
3+
const config = {
4+
polygon: {
5+
vaultManager: '0x6008b366058B42792A2497972A3312274DC5e1A8',
6+
},
7+
}
8+
9+
module.exports = {}
10+
11+
Object.keys(config).forEach(chain => {
12+
module.exports[chain] = {
13+
tvl: async function (_, _1, _2, { api }) {
14+
// Stability Platform Vaults
15+
// Get all vaults
16+
const vaults = await api.call({
17+
abi: abi.vaultAddresses,
18+
target: config[chain].vaultManager
19+
});
20+
21+
// Get strategy addresses
22+
const strategies = await api.multiCall({ abi: abi.strategy, calls: vaults, })
23+
24+
// Get all assets amounts managed by strategies
25+
const assetsAmountsAll = await api.multiCall({ abi: abi.assetsAmounts, calls: strategies, })
26+
27+
// Get summary balances
28+
const balances = {}
29+
for (const assetsAmounts of assetsAmountsAll) {
30+
for (let i = 0; i < assetsAmounts[0].length; i++) {
31+
const asset = assetsAmounts[0][i]
32+
if (balances[asset] === undefined) {
33+
balances[asset] = 0
34+
}
35+
balances[asset] += +assetsAmounts[1][i]
36+
}
37+
}
38+
39+
// Add data
40+
api.addTokens(Object.keys(balances), Object.keys(balances).map(asset => balances[asset]))
41+
},
42+
}
43+
})

0 commit comments

Comments
 (0)