|
| 1 | +const axios = require('axios'); |
| 2 | +const utils = require('../utils'); |
| 3 | + |
| 4 | +const VAULT_ADDRESS = '0x0e008684ae576f280c5426a89d3f5e1da1fc7398'; |
| 5 | +const HL_INFO_URL = 'https://api.hyperliquid.xyz/info'; |
| 6 | +const PRODUCTION_LIVE_MS = new Date('2026-04-15T00:00:00Z').getTime(); |
| 7 | + |
| 8 | +const apy = async () => { |
| 9 | + const { data } = await axios.post(HL_INFO_URL, { |
| 10 | + type: 'vaultDetails', |
| 11 | + vaultAddress: VAULT_ADDRESS, |
| 12 | + }); |
| 13 | + |
| 14 | + // TVL = sum of all follower vault equity |
| 15 | + const tvlUsd = (data.followers ?? []).reduce( |
| 16 | + (sum, f) => sum + Number(f.vaultEquity ?? 0), |
| 17 | + 0, |
| 18 | + ); |
| 19 | + |
| 20 | + // APY from Hyperliquid's reported APR (already annualized) |
| 21 | + const apr = Number(data.apr); |
| 22 | + |
| 23 | + // Compute base APY from PnL history since production live date |
| 24 | + const historyEntry = (data.portfolio ?? []).find(([k]) => k === 'allTime'); |
| 25 | + const rawPnl = historyEntry?.[1]?.pnlHistory ?? []; |
| 26 | + const rawAV = historyEntry?.[1]?.accountValueHistory ?? []; |
| 27 | + |
| 28 | + let apyBase = null; |
| 29 | + |
| 30 | + if (rawPnl.length > 0 && rawAV.length > 0) { |
| 31 | + // Find PnL and account value at live cutoff |
| 32 | + const pnlSorted = rawPnl |
| 33 | + .map(([t, v]) => [t, Number(v)]) |
| 34 | + .sort(([a], [b]) => a - b); |
| 35 | + const avSorted = rawAV |
| 36 | + .map(([t, v]) => [t, Number(v)]) |
| 37 | + .sort(([a], [b]) => a - b); |
| 38 | + |
| 39 | + let liveStartPnl = 0; |
| 40 | + let closestPnlDist = Infinity; |
| 41 | + for (const [t, v] of pnlSorted) { |
| 42 | + const dist = Math.abs(t - PRODUCTION_LIVE_MS); |
| 43 | + if (dist < closestPnlDist) { |
| 44 | + closestPnlDist = dist; |
| 45 | + liveStartPnl = v; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + let liveStartValue = 0; |
| 50 | + let closestAVDist = Infinity; |
| 51 | + for (const [t, v] of avSorted) { |
| 52 | + if (v > 0) { |
| 53 | + const dist = Math.abs(t - PRODUCTION_LIVE_MS); |
| 54 | + if (dist < closestAVDist) { |
| 55 | + closestAVDist = dist; |
| 56 | + liveStartValue = v; |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + if (liveStartValue > 0 && pnlSorted.length > 0) { |
| 62 | + const currentPnl = pnlSorted[pnlSorted.length - 1][1]; |
| 63 | + const livePnlDelta = currentPnl - liveStartPnl; |
| 64 | + const cumulativeReturn = livePnlDelta / liveStartValue; |
| 65 | + |
| 66 | + // Annualize based on elapsed days |
| 67 | + const liveDays = |
| 68 | + (pnlSorted[pnlSorted.length - 1][0] - PRODUCTION_LIVE_MS) / 86_400_000; |
| 69 | + if (liveDays > 0) { |
| 70 | + apyBase = (cumulativeReturn / liveDays) * 365 * 100; // as percentage |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + // Fallback to Hyperliquid-reported APR if calculation fails |
| 76 | + if (apyBase === null || !isFinite(apyBase)) { |
| 77 | + apyBase = isFinite(apr) ? apr * 100 : null; |
| 78 | + } |
| 79 | + |
| 80 | + return [ |
| 81 | + { |
| 82 | + pool: `${VAULT_ADDRESS}-hyperliquid`.toLowerCase(), |
| 83 | + chain: utils.formatChain('Hyperliquid'), |
| 84 | + project: 'akka', |
| 85 | + symbol: 'USDC', |
| 86 | + tvlUsd, |
| 87 | + apyBase, |
| 88 | + poolMeta: 'AI Quant Vault', |
| 89 | + url: 'https://app.akka.finance/vault', |
| 90 | + }, |
| 91 | + ].filter((p) => utils.keepFinite(p)); |
| 92 | +}; |
| 93 | + |
| 94 | +module.exports = { |
| 95 | + timetravel: false, |
| 96 | + apy, |
| 97 | + url: 'https://app.akka.finance/vault', |
| 98 | +}; |
0 commit comments