Skip to content
Open
Changes from 3 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
55 changes: 49 additions & 6 deletions projects/volo-vsui/index.js
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(
Expand All @@ -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`);
Copy link
Collaborator

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

Copy link
Author

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🙏


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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please no try catch

Copy link
Author

Choose a reason for hiding this comment

The 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,
}

Loading