-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Replace old API endpoint with NAVI Open API for vault TVL data #16122
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
Open
MarkChen1213866
wants to merge
5
commits into
DefiLlama:main
Choose a base branch
from
MarkChen1213866:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1d414e
Update index.js
MarkChen1213866 21607e2
Merge pull request #1 from MarkChen1213866/volo-vsui-tvl-update
MarkChen1213866 4369e54
Update index.js
MarkChen1213866 411a7f9
Merge branch 'DefiLlama:main' into main
MarkChen1213866 aba5f6e
Remove try-catch
MarkChen1213866 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const sui = require('../helper/chain/sui') | ||
const axios = require("axios"); | ||
|
||
async function tvl() { | ||
const naviApiURL = 'https://open-api.naviprotocol.io'; | ||
|
||
async function liquidStakingTVL() { | ||
const nativePoolObj = await sui.getObject('0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf'); | ||
|
||
const totalStakedValue = +(await sui.getDynamicFieldObject( | ||
|
@@ -15,14 +18,54 @@ async function tvl() { | |
|
||
const totalStakedSui = totalStakedValue + totalPendingRewards - unstakeTicketsSupply; | ||
|
||
return { | ||
sui: totalStakedSui / 1e9, | ||
return totalStakedSui / 1e9; | ||
} | ||
|
||
async function getVaultTVL() { | ||
try { | ||
const response = await axios.get(`${naviApiURL}/api/volo/volo-vaults?type=tvl`); | ||
|
||
if (response.data && response.data.code === 0 && response.data.data) { | ||
return response.data.data; | ||
} else { | ||
console.error('Invalid response format from NAVI API:', response.data); | ||
return {}; | ||
} | ||
} catch (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please no try catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
console.error('Error fetching vault TVL from NAVI API:', error.message); | ||
return {}; | ||
} | ||
} | ||
|
||
async function tvl(api) { | ||
const lstTVL = await liquidStakingTVL(); | ||
api.add('0x2::sui::SUI', lstTVL); | ||
|
||
const vaultData = await getVaultTVL(); | ||
|
||
for (const [vaultAddress, tvlValue] of Object.entries(vaultData)) { | ||
if (tvlValue && tvlValue > 0) { | ||
const coinType = extractCoinType(vaultAddress); | ||
if (coinType) { | ||
api.add(coinType, tvlValue); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function extractCoinType(vaultAddress) { | ||
const parts = vaultAddress.split('::'); | ||
if (parts.length >= 3) { | ||
return vaultAddress; | ||
} | ||
return null; | ||
} | ||
|
||
module.exports = { | ||
methodology: "Calculates the amount of SUI staked in Volo liquid staking contracts.", | ||
methodology: "Calculates the amount of SUI staked in Volo liquid staking contracts and tokens in Volo vaults. TVL includes LST (Liquid Staking) and all vault types combined.", | ||
sui: { | ||
tvl, | ||
} | ||
tvl: tvl, | ||
}, | ||
tvl: tvl, | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use on chain data and our sui helper functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of our protocol’s design, we cannot compute TVL by reading objects directly, it must be derived from event emissions. This PR follows the same approach as Haedal vaults by fetching vault metadata from API and helper to aggregate balances. Please understand this is the only feasible way to calculate TVL on our protocol, and future changes can simply adjust the packageId or API endpoint without modifying on-chain logic. Thank you for understanding🙏