add aave v3 helper

This commit is contained in:
g1nt0ki
2025-10-15 21:42:26 +02:00
parent 23d772069d
commit 130c4a1cf8
13 changed files with 119 additions and 479 deletions

View File

@@ -1,41 +1,7 @@
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),
};
});
const CONFIG = {
assetchain: ['0x1d0c5587b05D2FBE944c118d581C3102E06D1726']
};
const { aaveV3Export } = require("../helper/aave");
module.exports = aaveV3Export(CONFIG)

View File

@@ -1,8 +1,4 @@
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 { aaveV3Export } = require("../helper/aave");
// https://aave.com/docs/resources/addresses
const CONFIG = {
@@ -26,37 +22,7 @@ const CONFIG = {
plasma: ['0xf2D6E38B407e31E7E7e4a16E6769728b76c7419F'],
};
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),
};
});
module.exports = aaveV3Export(CONFIG)
module.exports.hallmarks = [
[1659630089, "Start OP Rewards"],

View File

@@ -1,44 +1,6 @@
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 = {
bsc: ['0xDc33eAA50B8707f791478Cec324e451E20FDa7ed']
};
const { aaveV3Export } = require("../helper/aave");
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),
};
});
module.exports.hallmarks = [
]
module.exports = aaveV3Export(CONFIG)

View File

@@ -4,7 +4,7 @@ const sdk = require('@defillama/sdk');
const { default: BigNumber } = require('bignumber.js');
const abi = require('./abis/aave.json');
const { getChainTransform, getFixBalancesSync, } = require('../helper/portedTokens')
const { sumTokens2 } = require('../helper/unwrapLPs');
const { sumTokens2, } = require('../helper/unwrapLPs');
const methodologies = require('./methodologies');
async function getV2Reserves(block, addressesProviderRegistry, chain, dataHelperAddress, abis = {}) {
@@ -142,6 +142,7 @@ module.exports = {
aaveExports,
getBorrowed,
aaveV2Export,
aaveV3Export,
}
const cachedData = {}
@@ -204,7 +205,7 @@ function aaveV2Export(registry, { useOracle = false, baseCurrency, baseCurrencyU
return sumTokens2({ tokensAndOwners, api, blacklistedTokens })
const balances = {}
const res = await api.multiCall({ abi: 'erc20:balanceOf', calls: tokensAndOwners.map(i => ({ target: i[0], params: i[1] })) })
res.forEach((v, i) => {
sdk.util.sumSingleBalance(balances, data[i].currency, v * data[i].price, api.chain)
})
@@ -253,7 +254,7 @@ function aaveV2Export(registry, { useOracle = false, baseCurrency, baseCurrencyU
const currencyDecimal = 18
const prices = await api.call({ abi: abiv2.getAssetsPrices, target: oracle, params: [tokens] })
prices.forEach((v, i) => {
data[i].price = (v / unit )/ (10 ** (decimals[i] - currencyDecimal))
data[i].price = (v / unit) / (10 ** (decimals[i] - currencyDecimal))
data[i].currency = currency
})
}
@@ -283,4 +284,67 @@ function aaveV2Export(registry, { useOracle = false, baseCurrency, baseCurrencyU
}
return { tvl, borrowed, }
}
}
function aaveV3Export(config) {
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 exports = {
methodology: methodologies.lendingMarket,
}
Object.keys(config).forEach(chain => {
let chainConfig = config[chain]
let poolDatas
let abis
if (typeof chainConfig === 'object') {
poolDatas = chainConfig.poolDatas
abis = chainConfig.abis || {}
Object.entries(abis).forEach(([k, v]) => abi[k] = v)
}
if (Array.isArray(chainConfig)) poolDatas = chainConfig
if (typeof chainConfig === 'string') poolDatas = [chainConfig]
if (!poolDatas) throw new Error(`No poolDatas for ${chain} in aaveV3Export`)
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, })
let 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) tokensAndOwners = [] // we still do sumTokens to transform the response
return sumTokens2({ api, tokensAndOwners })
}
exports[chain] = {
tvl: (api) => fetchReserveData(api, poolDatas),
borrowed: (api) => fetchReserveData(api, poolDatas, true),
}
})
return exports
}

View File

@@ -105,6 +105,9 @@ const fixBalancesTokens = {
},
somnia: {
'0x936ab8c674bcb567cd5deb85d8a216494704e9d8': { coingeckoId: 'ethereum', decimals: 18 }
},
ink: {
'0xfc421ad3c883bf9e7c4f42de845c4e4405799e73': { coingeckoId: 'gho', decimals: 18 }
}
}

View File

@@ -19,74 +19,10 @@ const DATA_PROVIDERS_CONTRACTS = [
"0x40025ad3f5438aC971e61Ba97F9Ab1B8b818900d"
];
const abi = {
getAllReservesTokens: "function getAllReservesTokens() view returns (tuple(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 { aaveV3Export } = require("../helper/aave");
async function tvl(api) {
const allReservesTokens = await api.multiCall({
abi: abi.getAllReservesTokens,
calls: DATA_PROVIDERS_CONTRACTS
});
module.exports = aaveV3Export({
mantle: DATA_PROVIDERS_CONTRACTS
})
const collateralAddresses = allReservesTokens.map(i => i[0].tokenAddress);
const debtAddresses = allReservesTokens.map(i => i[1].tokenAddress);
const debtReserveDatas = await api.multiCall({
abi: abi.getReserveData,
calls: DATA_PROVIDERS_CONTRACTS.map((target, i) => ({ target, params: debtAddresses[i] })),
});
const collateralReserveDatas = await api.multiCall({
abi: abi.getReserveData,
calls: DATA_PROVIDERS_CONTRACTS.map((target, i) => ({ target, params: collateralAddresses[i] })),
});
api.add(collateralAddresses, collateralReserveDatas.map(i => i.totalAToken));
api.add(debtAddresses, debtReserveDatas.map(i => i.totalAToken));
debtReserveDatas.forEach((debtReserveData, i) => {
const totalStableDebt = +debtReserveData.totalStableDebt || 0;
const totalVariableDebt = +debtReserveData.totalVariableDebt || 0;
const totalBorrowed = totalStableDebt + totalVariableDebt;
api.add(debtAddresses[i], -totalBorrowed);
});
return api.getBalances();
}
async function borrowed(api) {
const allReservesTokens = await api.multiCall({
abi: abi.getAllReservesTokens,
calls: DATA_PROVIDERS_CONTRACTS
});
const debtAddresses = allReservesTokens.map(i => i[1].tokenAddress);
// Get reserve data for this configurator (the configurator address is the reserve)
const debtReserveDatas = await api.multiCall({
abi: abi.getReserveData,
calls: DATA_PROVIDERS_CONTRACTS.map((target, i) => ({ target, params: debtAddresses[i] })),
});
debtReserveDatas.forEach((debtReserveData, i) => {
const totalStableDebt = +debtReserveData.totalStableDebt || 0;
const totalVariableDebt = +debtReserveData.totalVariableDebt || 0;
const totalBorrowed = totalStableDebt + totalVariableDebt;
api.add(debtAddresses[i], totalBorrowed);
});
return api.getBalances();
}
module.exports = {
methodology: 'TVL accounts for all assets deposited into the Vaults. Borrowed amounts are calculated as the total amount of tokens borrowed from the lending pools.',
mantle: {
tvl,
borrowed,
staking: staking(StakingContract, TokenContract)
},
};
module.exports.mantle.staking = staking(StakingContract, TokenContract)

View File

@@ -1,6 +1,7 @@
const { function_view } = require("../helper/chain/aptos");
const { compoundExports2 } = require("../helper/compound")
const { mergeExports } = require("../helper/utils")
const { aaveV3Export } = require("../helper/aave");
/* LayerBank V2 */
const v2Config = {
@@ -30,9 +31,9 @@ Object.keys(v2Config).forEach(chain => {
module.exports[chain] = compoundExports2({ comptroller, abis, })
})
module.exports = mergeExports([module.exports, {
const compoundExports = {
linea: compoundExports2({ comptroller: '0x43Eac5BFEa14531B8DE0B334E123eA98325de866', abis, }),
}])
}
/* LayerBank Move */
@@ -79,12 +80,6 @@ module.exports.move = {
/* LayerBank V3 */
const v3Abi = {
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 v3Config = {
plume_mainnet: [`0xF9642C3B35Cd4Ccd55D22Fb2B35fcc31c5E0B62E`],
hemi: [`0x8D45801736F3504BEfA35ABEf8bc7a1C4d610651`],
@@ -93,36 +88,4 @@ const v3Config = {
rsk: ['0x47C1ef207d49cfC519F48b8251857CA6BE6c2caf'],
};
const fetchReserveData = async (api, poolDatas, isBorrowed) => {
const reserveTokens = await api.multiCall({ calls: poolDatas, abi: v3Abi.getAllReservesTokens });
const calls = []
poolDatas.map((pool, i) => {
reserveTokens[i].forEach(({ tokenAddress }) => calls.push({ target: pool, params: tokenAddress }));
});
const reserveData = await api.multiCall({ abi: isBorrowed ? v3Abi.getReserveData : v3Abi.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 })
}
const v3Exports = {};
Object.keys(v3Config).forEach((chain) => {
const poolDatas = v3Config[chain];
v3Exports[chain] = {
tvl: (api) => fetchReserveData(api, poolDatas),
borrowed: (api) => fetchReserveData(api, poolDatas, true),
};
});
module.exports = mergeExports([module.exports, v3Exports]);
module.exports = mergeExports([module.exports, compoundExports, aaveV3Export(v3Config)]);

View File

@@ -1,47 +1,17 @@
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 = {
sonic: ['0x82c7B4aBB462dE2f7bFDE40c05d1fAa3913DbBB3'],
hyperliquid: ['0x0F0E6905B0199393b9102be42f28f71c22e30151'],
};
const fetchReserveData = async (api, poolDatas, isBorrowed) => {
const reserveTokens = await api.multiCall({ calls: poolDatas, abi: abi.getAllReservesTokens });
const calls = []
const { aaveV3Export } = require("../helper/aave");
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."
module.exports = aaveV3Export({
sonic: ['0x82c7B4aBB462dE2f7bFDE40c05d1fAa3913DbBB3'],
hyperliquid: ['0x0F0E6905B0199393b9102be42f28f71c22e30151'],
})
Object.keys(CONFIG).forEach((chain) => {
const poolDatas = CONFIG[chain];
module.exports[chain] = {
tvl: (api) => fetchReserveData(api, poolDatas),
// borrowed: (api) => fetchReserveData(api, poolDatas, true),
borrowed: () => ({}),
};
});
if (module.exports[chain].borrowed) module.exports[chain].borrowed = () => ({})
})
// module.exports.hallmarks = [
// ['2025-05-10', 'Protocol was hacked'],
// ]
module.exports.deadFrom = '2025-05-10'

View File

@@ -1,9 +1,3 @@
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)",
};
// Ploutos - Aave v3 fork
// AaveProtocolDataProviders
// https://docs.ploutos.money/contracts-addresses
@@ -13,40 +7,11 @@ const CONFIG = {
polygon: ['0x6A9b632010226F9bBbf2B6cb8B6990bE3F90cb0e'],
katana: ['0x4DC446e349bDA9516033E11D63f1851d6B5Fd492'],
plasma: ['0x9C48A6D3e859ab124A8873D73b2678354D0B4c0A'],
};
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."
const { aaveV3Export } = require("../helper/aave");
Object.keys(CONFIG).forEach((chain) => {
const poolDatas = CONFIG[chain];
module.exports[chain] = {
tvl: (api) => fetchReserveData(api, poolDatas),
borrowed: (api) => fetchReserveData(api, poolDatas, true),
};
});
module.exports = aaveV3Export(CONFIG)
module.exports.hallmarks = [
[1659630089, "Start OP Rewards"],

View File

@@ -1,43 +1,5 @@
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 = {
soneium: ['0x2BECa16DAa6Decf9C6F85eBA8F0B35696A3200b3','0x3b5FDb25672A0ea560E66905B97d0c818a00f5eb']
};
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),
};
});
const { aaveV3Export } = require("../helper/aave");
module.exports = aaveV3Export({
soneium: ['0x2BECa16DAa6Decf9C6F85eBA8F0B35696A3200b3', '0x3b5FDb25672A0ea560E66905B97d0c818a00f5eb']
})

View File

@@ -1,42 +1,6 @@
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)",
};
// https://docs.tydro.com/resources/addresses
const CONFIG = {
ink: ['0x96086C25d13943C80Ff9a19791a40Df6aFC08328'],
};
const { aaveV3Export } = require("../helper/aave");
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),
};
});
module.exports = aaveV3Export({
ink: '0x96086C25d13943C80Ff9a19791a40Df6aFC08328',
})

View File

@@ -1,51 +1,5 @@
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 = {
unit0: ['0x99118c1Ca7D0DC824719E740d4b4721009a267d6'], // Unilend on Unit Zero
};
const fetchReserveData = async (api, poolDatas, isBorrowed) => {
const reserveTokens = await api.multiCall({ calls: poolDatas, abi: abi.getAllReservesTokens });
const calls = [];
poolDatas.forEach((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.";
Object.keys(CONFIG).forEach((chain) => {
const poolDatas = CONFIG[chain];
module.exports[chain] = {
tvl: (api) => fetchReserveData(api, poolDatas),
borrowed: (api) => fetchReserveData(api, poolDatas, true),
};
});
const { aaveV3Export } = require("../helper/aave");
module.exports = aaveV3Export({
unit0: ['0x99118c1Ca7D0DC824719E740d4b4721009a267d6'], // Unilend on Unit Zero
})

View File

@@ -1,41 +1,6 @@
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 { aaveV3Export } = require("../helper/aave");
const CONFIG = {
module.exports = aaveV3Export({
fuse: ['0x87cB512CFB0f18F4Dd9652a186922cf6A4e63213'],
};
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),
};
});
})