diff --git a/projects/avalon-finance-cedefi/addresses.js b/projects/avalon-finance-cedefi/addresses.js deleted file mode 100644 index 27d531833232..000000000000 --- a/projects/avalon-finance-cedefi/addresses.js +++ /dev/null @@ -1,12 +0,0 @@ -const avalonCeDefi = { - ethereum: "0x02feDCff97942fe28e8936Cdc3D7A480fdD248f0" -}; - -const lfbtc = { - ethereum: "0x3119a1AD5B63A000aB9CA3F2470611eB997B93B9" -} - -module.exports = { - avalonCeDefi, - lfbtc, -} diff --git a/projects/avalon-finance-cedefi/index.js b/projects/avalon-finance-cedefi/index.js index 346d83846c6a..52047ae96edd 100644 --- a/projects/avalon-finance-cedefi/index.js +++ b/projects/avalon-finance-cedefi/index.js @@ -1,42 +1,31 @@ -// Defillama Adapter for Avalon Finance CeDeFi Market -const { fetchMarketData } = require('./markets'); -const { avalonCeDefi, lfbtc } = require("./addresses"); -const coreAssets = require('../helper/coreAssets.json'); +const ADDRESSES = require('../helper/coreAssets.json') -// @dev getMetrics: call to get the collateral and debt of the Avalon CeDefi pool contract. -const getMetrics = async (poolAddress, lfbtcAddress, usdtAddress, api, borrowed) => { - try { - const marketData = await fetchMarketData(poolAddress, api); - const balanceOfCollateral = marketData.collateral; - const balanceOfDebt = marketData.debt; +const abi = { + "getPoolManagerReserveInformation": "function getPoolManagerReserveInformation() view returns (tuple(uint256 userAmount, uint256 collateral, uint256 debt, uint256 claimableUSDT, uint256 claimableBTC) poolManagerReserveInfor)" +} + +const config = { + ethereum: { poolAddress: "0x02feDCff97942fe28e8936Cdc3D7A480fdD248f0", lfbtcAddress: "0x3119a1AD5B63A000aB9CA3F2470611eB997B93B9", usdtAddress: ADDRESSES.ethereum.USDT, }, +} - api.add(lfbtcAddress, balanceOfCollateral); - if (borrowed) { - api.add(usdtAddress, balanceOfDebt); - } - } catch (error) { - console.error("Error in getMetrics:", error); - throw error; - } -}; +// @dev getMetrics: call to get the collateral and debt of the Avalon CeDefi pool contract. +const getMetrics = async (api, borrowed) => { + const { poolAddress, lfbtcAddress, usdtAddress } = config[api.chain] + const marketData = await api.call({ abi: abi.getPoolManagerReserveInformation, target: poolAddress, }); + const balanceOfCollateral = marketData.collateral; + const balanceOfDebt = marketData.debt; -const ethereum = function (borrowed) { - const poolAddress = avalonCeDefi.ethereum - const lfbtcAddress = lfbtc.ethereum - const usdtAddress = coreAssets.ethereum.USDT - return async (api) => { - return getMetrics(poolAddress, lfbtcAddress, usdtAddress, api, borrowed); - } -}; + if (borrowed) + api.add(usdtAddress, balanceOfDebt); + else + api.add(lfbtcAddress, balanceOfCollateral); +} module.exports = { - methodology: `lfbtc collateral and USDT debt of Avalon CeDefi pool contract`, - doublecounted: false, - ethereum: { - tvl: ethereum(false), - borrowed: ethereum(true), - } -}; - -// export LLAMA_DEBUG_MODE="true" -// node test.js projects/avalon-finance-cedefi/index.js + methodology: `lfbtc collateral and USDT debt of Avalon CeDefi pool contract`, + doublecounted: false, + ethereum: { + tvl: (api) => getMetrics(api), + borrowed: (api) => getMetrics(api, true), + } +} \ No newline at end of file diff --git a/projects/avalon-finance-cedefi/markets.js b/projects/avalon-finance-cedefi/markets.js deleted file mode 100644 index 462d327a72e1..000000000000 --- a/projects/avalon-finance-cedefi/markets.js +++ /dev/null @@ -1,15 +0,0 @@ -const abi = require("../helper/abis/avalon.json"); - -// @dev fetchMarketsData: call to get the reserve information for all markets. Call getPoolManagerReserveInformation for one market. -async function fetchMarketData(poolAddress, api) { - const poolReserveInfo = await api.call({ - abi: abi.avalonCeDefi.getPoolManagerReserveInformation, - target: poolAddress, - }); - - return poolReserveInfo; -} - -module.exports = { - fetchMarketData -} diff --git a/projects/helper/abis/avalon.json b/projects/helper/abis/avalon.json deleted file mode 100644 index b1d6a85e6d44..000000000000 --- a/projects/helper/abis/avalon.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "avalonCeDefi": { - "getPoolManagerReserveInformation": "function getPoolManagerReserveInformation() view returns (tuple(uint256 userAmount, uint256 collateral, uint256 debt, uint256 claimableUSDT, uint256 claimableBTC) poolManagerReserveInfor)" - } -} -