Skip to content

Commit

Permalink
remove try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulZhemanov committed Jan 2, 2025
1 parent 4fa14d0 commit 0097339
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions projects/spark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,35 @@ async function tvl(api) {
'0x81e83f73530c262b0dbf5414649a875c48a48144de3c08ff68cb9d54b36f2eaa',
];

try {
const balancesList = await Promise.all(
contractIds.map(async (contractId) => {
try {
const balances = await sumTokens({ api, owner: contractId });
console.log(`Balances from contract ${contractId}:`, balances);
return balances;
} catch (err) {
console.error(`Error fetching balance for contract ${contractId}:`, err.message);
return {};
}
})
);

const combinedBalances = balancesList.reduce((acc, balances) => {
Object.entries(balances).forEach(([key, value]) => {
const numericValue = BigInt(value || 0);
acc[key] = acc[key] ? BigInt(Math.max(Number(acc[key]), Number(numericValue))) : numericValue;
});
return acc;
}, {});

console.log("Final combined balances:", combinedBalances);

const totalTvl = Object.values(combinedBalances).reduce((sum, value) => {
return sum + Number(value);
}, 0);

const formattedBalances = Object.fromEntries(
Object.entries(combinedBalances).map(([key, value]) => [key, value.toString()])
);

console.log("Formatted Balances for TVL:", formattedBalances);

return formattedBalances;
} catch (err) {
console.error("Unexpected error during TVL calculation:", err.message);
return {};
}
const balancesList = await Promise.all(
contractIds.map(async (contractId) => {
const balances = await sumTokens({ api, owner: contractId });
console.log(`Balances from contract ${contractId}:`, balances);
return balances;
})
);

const combinedBalances = balancesList.reduce((acc, balances) => {
Object.entries(balances).forEach(([key, value]) => {
const numericValue = BigInt(value || 0);
acc[key] = acc[key] ? BigInt(Math.max(Number(acc[key]), Number(numericValue))) : numericValue;
});
return acc;
}, {});

console.log("Final combined balances:", combinedBalances);

const totalTvl = Object.values(combinedBalances).reduce((sum, value) => {
return sum + Number(value);
}, 0);

const formattedBalances = Object.fromEntries(
Object.entries(combinedBalances).map(([key, value]) => [key, value.toString()])
);

console.log("Formatted Balances for TVL:", formattedBalances);

return formattedBalances;
}

module.exports = {
Expand Down

0 comments on commit 0097339

Please sign in to comment.