Skip to content

Commit

Permalink
Add: avalon finance cedefi market ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmin-avalon committed Aug 14, 2024
1 parent e3f4d73 commit 41b65b8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
12 changes: 12 additions & 0 deletions projects/avalon-finance-cedefi/addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const avalonCeDefi = {
ethereum: "0x02feDCff97942fe28e8936Cdc3D7A480fdD248f0"
};

const lfbtc = {
ethereum: "0x3119a1AD5B63A000aB9CA3F2470611eB997B93B9"
}

module.exports = {
avalonCeDefi,
lfbtc,
}
42 changes: 42 additions & 0 deletions projects/avalon-finance-cedefi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Defillama Adapter for Avalon Finance CeDeFi Market
const { fetchMarketData } = require('./markets');
const { avalonCeDefi, lfbtc } = require("./addresses");
const coreAssets = 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;

api.add(lfbtcAddress, balanceOfCollateral);
if (borrowed) {
api.add(usdtAddress, balanceOfDebt);
}
} catch (error) {
console.error("Error in getMetrics:", error);
throw error;
}
};

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);
}
};

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
15 changes: 15 additions & 0 deletions projects/avalon-finance-cedefi/markets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
}
6 changes: 6 additions & 0 deletions projects/helper/abis/avalon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"avalonCeDefi": {
"getPoolManagerReserveInformation": "function getPoolManagerReserveInformation() view returns (tuple(uint256 userAmount, uint256 collateral, uint256 debt, uint256 claimableUSDT, uint256 claimableBTC) poolManagerReserveInfor)"
}
}

0 comments on commit 41b65b8

Please sign in to comment.