From f15feadc119b8e509cab14c8ba7f66d0f75add98 Mon Sep 17 00:00:00 2001 From: seunbayo Date: Tue, 29 Apr 2025 21:19:39 +0100 Subject: [PATCH] added adapter for eden finance --- projects/Eden-finance/index.js | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 projects/Eden-finance/index.js diff --git a/projects/Eden-finance/index.js b/projects/Eden-finance/index.js new file mode 100644 index 0000000000..484de85b98 --- /dev/null +++ b/projects/Eden-finance/index.js @@ -0,0 +1,41 @@ +const abi = { + getReserveTokensAddresses: "function getReserveTokensAddresses(address asset) view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress)", + getAllReservesTokens: "function getAllReservesTokens() view returns ((string symbol, address tokenAddress)[])", + getReserveData: "function getReserveData(address asset) view returns (uint256 unbacked, uint256 accruedToTreasuryScaled, uint256 totalAToken, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp)", + }; + + const CONFIG = { + assetchain: ['0x1d0c5587b05D2FBE944c118d581C3102E06D1726'] + }; + + const fetchReserveData = async (api, poolDatas, isBorrowed) => { + const reserveTokens = await api.multiCall({ calls: poolDatas, abi: abi.getAllReservesTokens }); + const calls = [] + + poolDatas.map((pool, i) => { + reserveTokens[i].forEach(({ tokenAddress }) => calls.push({ target: pool, params: tokenAddress })); + }); + const reserveData = await api.multiCall({ abi: isBorrowed ? abi.getReserveData : abi.getReserveTokensAddresses, calls, }) + const tokensAndOwners = [] + reserveData.forEach((data, i) => { + const token = calls[i].params + if (isBorrowed) { + api.add(token, data.totalVariableDebt) + api.add(token, data.totalStableDebt) + } else + tokensAndOwners.push([token, data.aTokenAddress]) + }) + + if (isBorrowed) return api.getBalances() + return api.sumTokens({ tokensAndOwners }) + } + + module.exports.methodology = "Counts the tokens locked in the contracts to be used as collateral to borrow or to earn yield. Borrowed coins are not counted towards the TVL, so only the coins actually locked in the contracts are counted. There's multiple reasons behind this but one of the main ones is to avoid inflating the TVL through cycled lending." + + Object.keys(CONFIG).forEach((chain) => { + const poolDatas = CONFIG[chain]; + module.exports[chain] = { + tvl: (api) => fetchReserveData(api, poolDatas), + borrowed: (api) => fetchReserveData(api, poolDatas, true), + }; + }); \ No newline at end of file