Skip to content

Commit

Permalink
bump some contracts support for spark finance (DefiLlama#12944)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x authored Jan 3, 2025
2 parents 1d272ef + 0097339 commit b904fca
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions projects/spark/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
const { sumTokens } = require("../helper/chain/fuel")
const { sumTokens } = require("../helper/chain/fuel");

async function tvl(api) {
const contractId = '0xfe2c524ad8e088f33d232a45dbea43e792861640b71aa1814b30506bf8430ee5'
return sumTokens({ api, owner: contractId, })
const contractIds = [
'0xfe2c524ad8e088f33d232a45dbea43e792861640b71aa1814b30506bf8430ee5',
'0xdafe498b31f24ea5577055e86bf77e96bcba2c39a7ae47abaa819c303a45a352',
'0x81e83f73530c262b0dbf5414649a875c48a48144de3c08ff68cb9d54b36f2eaa',
];

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 = {
fuel: { tvl },
timetravel: false,
}
fuel: { tvl },
timetravel: false,
};

0 comments on commit b904fca

Please sign in to comment.