Skip to content

Commit 0097339

Browse files
committed
remove try catch
1 parent 4fa14d0 commit 0097339

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

projects/spark/index.js

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,35 @@ async function tvl(api) {
77
'0x81e83f73530c262b0dbf5414649a875c48a48144de3c08ff68cb9d54b36f2eaa',
88
];
99

10-
try {
11-
const balancesList = await Promise.all(
12-
contractIds.map(async (contractId) => {
13-
try {
14-
const balances = await sumTokens({ api, owner: contractId });
15-
console.log(`Balances from contract ${contractId}:`, balances);
16-
return balances;
17-
} catch (err) {
18-
console.error(`Error fetching balance for contract ${contractId}:`, err.message);
19-
return {};
20-
}
21-
})
22-
);
23-
24-
const combinedBalances = balancesList.reduce((acc, balances) => {
25-
Object.entries(balances).forEach(([key, value]) => {
26-
const numericValue = BigInt(value || 0);
27-
acc[key] = acc[key] ? BigInt(Math.max(Number(acc[key]), Number(numericValue))) : numericValue;
28-
});
29-
return acc;
30-
}, {});
31-
32-
console.log("Final combined balances:", combinedBalances);
33-
34-
const totalTvl = Object.values(combinedBalances).reduce((sum, value) => {
35-
return sum + Number(value);
36-
}, 0);
37-
38-
const formattedBalances = Object.fromEntries(
39-
Object.entries(combinedBalances).map(([key, value]) => [key, value.toString()])
40-
);
41-
42-
console.log("Formatted Balances for TVL:", formattedBalances);
43-
44-
return formattedBalances;
45-
} catch (err) {
46-
console.error("Unexpected error during TVL calculation:", err.message);
47-
return {};
48-
}
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;
4939
}
5040

5141
module.exports = {

0 commit comments

Comments
 (0)