Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Aurum #13059

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions projects/aurum/index.js
Original file line number Diff line number Diff line change
@@ -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 = {
sonic: ['0x2ce2f663f8C8A011df0ACb1744b45108F61B9005'],
};

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