-
Notifications
You must be signed in to change notification settings - Fork 0
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
prototype for defillama IST tvl calculation v0.0.1 🚀 #1
base: main
Are you sure you want to change the base?
Conversation
…alue in vaults w.r.t the asset locked...
Updated calculation:
|
TLDR; (added to readme too) - Deprecated approach, see recent comments for for for for for |
…rs and finalize calculation
Rethought the approach, and instead decided to go with graphql, much better approach. Thanks @toliaqat @ivanlei for the resources on the indexer, got this working. Here is an updated calculation, which is wrong, but its using the new approach. Now we can just iterate on the calc to get it finalized to become more accurate, bulk of work is done 🚀
|
For example here is the get total collateral: const fetchTotalCollateral = async () => {
const query = `
query {
vaultManagerMetrics {
nodes {
totalCollateral
liquidatingCollateralBrand
}
}
oraclePrices {
nodes {
priceFeedName
typeOutAmount
typeInAmount
}
}
boardAuxes {
nodes {
allegedName
decimalPlaces
}
}
}`;
const data = await fetchSubqueryData(query);
let totalCollateral = 0;
const collateralPrices = {};
const collateralDecimals = {};
const collateralSet = new Set();
data.vaultManagerMetrics.nodes.forEach(vault => {
totalCollateral += parseFloat(vault.totalCollateral);
collateralSet.add(vault.liquidatingCollateralBrand);
});
data.oraclePrices.nodes.forEach(price => {
collateralPrices[price.priceFeedName] = parseFloat(price.typeOutAmount) / parseFloat(price.typeInAmount);
});
data.boardAuxes.nodes.forEach(aux => {
collateralDecimals[aux.allegedName.toLowerCase()] = Math.pow(10, aux.decimalPlaces);
});
let totalCollateralUSD = 0;
collateralSet.forEach(collateral => {
const collatKey = `${collateral}-USD`;
const price = collateralPrices[collatKey];
const decimals = collateralDecimals[collateral.toLowerCase()] || 1;
if (price) {
totalCollateralUSD += (totalCollateral / decimals) * price;
} else {
console.error(`Price not found for collateral: ${collateral}`);
}
});
return totalCollateralUSD / getCoinDecimals('uist');
}; Also saw in our notes, we are no longer using coingecko, so decided to do the same, and just use our price oracle data from the indexer. Finalizing the decimals part now, to ensure decimals are being used right: |
Updated calculation, seems right-er:
its not exactly what I'm seeing on dashboard though: Total Collateral Value Locked |
The dashboard showing Total Collateral Value Locked that only uses Vaults metrics. Here is the query that gives ~$4.19M
In code above, you are adding up all collateral values which might be the cause of the problem. I think we need to multiple vault.totalCollateral to collateralPrices[collatKey] before adding final dollar amounts.
|
Wanted to run these two approaches by you guys to calc tvl for ist for defi llama...
will fill out below when ready:
NOTE
Please enable "Allow edits by maintainers" while putting up the PR.
package-lock.json
file as part of your changes, we use lockfileVersion 2, and most use v1 and using that messes up our CIName (to be shown on DefiLlama):
Twitter Link:
List of audit links if any:
Website Link:
Logo (High resolution, will be shown with rounded borders):
Current TVL:
Treasury Addresses (if the protocol has treasury)
Chain:
Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed): (https://api.coingecko.com/api/v3/coins/list)
Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed): (https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active,inactive,untracked&start=1&limit=10000)
Short Description (to be shown on DefiLlama):
Token address and ticker if any:
Category (full list at https://defillama.com/categories) *Please choose only one:
Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
Implementation Details: Briefly describe how the oracle is integrated into your project:
Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:
forkedFrom (Does your project originate from another project):
methodology (what is being counted as tvl, how is tvl being calculated):
Github org/user (Optional, if your code is open source, we can track activity):