Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Aug 15, 2024
1 parent 41b65b8 commit 9293403
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 70 deletions.
12 changes: 0 additions & 12 deletions projects/avalon-finance-cedefi/addresses.js

This file was deleted.

63 changes: 26 additions & 37 deletions projects/avalon-finance-cedefi/index.js
Original file line number Diff line number Diff line change
@@ -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),
}
}
15 changes: 0 additions & 15 deletions projects/avalon-finance-cedefi/markets.js

This file was deleted.

6 changes: 0 additions & 6 deletions projects/helper/abis/avalon.json

This file was deleted.

0 comments on commit 9293403

Please sign in to comment.