Skip to content

Commit 6f07553

Browse files
authored
Remove API Endpoint Dependency (#16999)
1 parent 370d845 commit 6f07553

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

projects/looped-hype/index.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
const { getConfig } = require("../helper/cache")
2-
31
const LHYPE_VAULT = '0x5748ae796AE46A4F1348a1693de4b50560485562'
4-
const CHAIN_ID_STR = '999'
5-
const HYPE_TOKEN = '0x5555555555555555555555555555555555555555'
62

7-
const tvl = async (api) => {
8-
const data = await getConfig(
9-
'lhype-tokens',
10-
`https://backend.nucleusearn.io/v1/vaults/underlying_strategies?vault_address=${LHYPE_VAULT}&chain_id=${CHAIN_ID_STR}`
11-
)
3+
const LHYPE_ACCOUNTANT = '0xcE621a3CA6F72706678cFF0572ae8d15e5F001c3'
4+
5+
const WHYPE = '0x5555555555555555555555555555555555555555'
126

13-
const strat = data?.[CHAIN_ID_STR]
14-
if (!strat) return
7+
const totalSupplyAbi = 'function totalSupply() view returns (uint256)'
8+
const exchangeRateAbi = 'function getRate() view returns (uint256)'
9+
10+
const tvl = async (api) => {
11+
const [lhypeTotalSupply, lhypeExchangeRate,] = await Promise.all([
12+
api.call({ target: LHYPE_VAULT, abi: totalSupplyAbi }),
13+
api.call({ target: LHYPE_ACCOUNTANT, abi: exchangeRateAbi, }),
14+
])
1515

16-
let totalHype = 0
17-
for (const pos of Object.values(strat)) {
18-
totalHype += Number(pos.valueInBase || 0)
19-
}
16+
const lhypeTotalValueInHype = lhypeTotalSupply * lhypeExchangeRate / 1e18
2017

21-
const hypeAmount = BigInt(Math.round(totalHype * 1e18))
22-
api.add(HYPE_TOKEN, hypeAmount)
18+
api.add(WHYPE, lhypeTotalValueInHype)
2319
}
2420

2521
module.exports = {
2622
hyperliquid: { tvl },
27-
methodology: 'The total value of assets deployed across all LHYPE strategies.',
23+
methodology: 'The total value of assets deployed across all LHYPE and WHLP strategies.',
2824
misrepresentedTokens: true,
2925
}

projects/wrapped-hlp/index.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
const { getConfig } = require("../helper/cache")
2-
31
const WHLP_VAULT = '0x1359b05241cA5076c9F59605214f4F84114c0dE8'
4-
const CHAIN_ID_STR = '999'
2+
const WHLP_ACCOUNTANT = '0x470bd109A24f608590d85fc1f5a4B6e625E8bDfF'
3+
const USDT0 = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
4+
5+
const totalSupplyAbi = 'function totalSupply() view returns (uint256)'
6+
const exchangeRateAbi = 'function getRate() view returns (uint256)'
7+
58

69
const tvl = async (api) => {
7-
const data = await getConfig(
8-
'whlp-tokens',
9-
`https://backend.nucleusearn.io/v1/vaults/underlying_strategies?vault_address=${WHLP_VAULT}&chain_id=${CHAIN_ID_STR}`
10-
)
11-
const strat = data?.[CHAIN_ID_STR]
12-
if (!strat) return
10+
const [whlpTotalSupply, whlpExchangeRate,] = await Promise.all([
11+
api.call({ target: WHLP_VAULT, abi: totalSupplyAbi }),
12+
api.call({ target: WHLP_ACCOUNTANT, abi: exchangeRateAbi, }),
13+
])
1314

14-
let totalUsd = 0
15-
for (const pos of Object.values(strat)) totalUsd += Number(pos.valueInBase || 0)
15+
const whlpTotalValueInUsdt0 = whlpTotalSupply * whlpExchangeRate / 1e6
1616

17-
const priceData = await fetch(`https://coins.llama.fi/prices/current/hyperliquid:${WHLP_VAULT}`).then(r => r.json())
18-
const whlpPrice = priceData?.coins?.[`hyperliquid:${WHLP_VAULT}`]?.price
19-
if (!whlpPrice || whlpPrice <= 0) return
17+
api.add(USDT0, whlpTotalValueInUsdt0)
2018

21-
const whlpAmount = BigInt(Math.round((totalUsd / whlpPrice) * 1e6))
22-
api.add(WHLP_VAULT, whlpAmount)
2319
}
2420

2521
module.exports = {

0 commit comments

Comments
 (0)