forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bump some contracts support for spark finance (DefiLlama#12944)
- Loading branch information
Showing
1 changed file
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |