Skip to content

Commit b904fca

Browse files
authored
bump some contracts support for spark finance (DefiLlama#12944)
2 parents 1d272ef + 0097339 commit b904fca

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

projects/spark/index.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
const { sumTokens } = require("../helper/chain/fuel")
1+
const { sumTokens } = require("../helper/chain/fuel");
22

33
async function tvl(api) {
4-
const contractId = '0xfe2c524ad8e088f33d232a45dbea43e792861640b71aa1814b30506bf8430ee5'
5-
return sumTokens({ api, owner: contractId, })
4+
const contractIds = [
5+
'0xfe2c524ad8e088f33d232a45dbea43e792861640b71aa1814b30506bf8430ee5',
6+
'0xdafe498b31f24ea5577055e86bf77e96bcba2c39a7ae47abaa819c303a45a352',
7+
'0x81e83f73530c262b0dbf5414649a875c48a48144de3c08ff68cb9d54b36f2eaa',
8+
];
9+
10+
const balancesList = await Promise.all(
11+
contractIds.map(async (contractId) => {
12+
const balances = await sumTokens({ api, owner: contractId });
13+
console.log(`Balances from contract ${contractId}:`, balances);
14+
return balances;
15+
})
16+
);
17+
18+
const combinedBalances = balancesList.reduce((acc, balances) => {
19+
Object.entries(balances).forEach(([key, value]) => {
20+
const numericValue = BigInt(value || 0);
21+
acc[key] = acc[key] ? BigInt(Math.max(Number(acc[key]), Number(numericValue))) : numericValue;
22+
});
23+
return acc;
24+
}, {});
25+
26+
console.log("Final combined balances:", combinedBalances);
27+
28+
const totalTvl = Object.values(combinedBalances).reduce((sum, value) => {
29+
return sum + Number(value);
30+
}, 0);
31+
32+
const formattedBalances = Object.fromEntries(
33+
Object.entries(combinedBalances).map(([key, value]) => [key, value.toString()])
34+
);
35+
36+
console.log("Formatted Balances for TVL:", formattedBalances);
37+
38+
return formattedBalances;
639
}
740

841
module.exports = {
9-
fuel: { tvl },
10-
timetravel: false,
11-
}
42+
fuel: { tvl },
43+
timetravel: false,
44+
};

0 commit comments

Comments
 (0)