Skip to content

Conversation

NotRithik
Copy link

@NotRithik NotRithik commented Aug 21, 2025

Addressing the issue "Find source to refill hyperliquid derivatives volume and revenue(especially holder revenue)" #3793.

@llamabutler
Copy link

The hyperliquid-perp adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts dexs hyperliquid-perp

🦙 Running HYPERLIQUID-PERP adapter 🦙
---------------------------------------------------
Start Date:	Tue, 19 Aug 2025 21:59:25 GMT
End Date:	Wed, 20 Aug 2025 21:59:25 GMT
---------------------------------------------------

Error: Hyperliquid fee data is stale. Latest available date from API is 2025-07-12, but you requested 2025-08-21.
    at fetch (/home/runner/work/dimension-adapters/dimension-adapters/dexs/hyperliquid-perp/index.ts:59:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getChainResult (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:206:18)
    at async Promise.all (index 0)
    at async _runAdapter (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:159:20)
    at async /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:69:24 {
  chain: 'hyperliquid'
}

@NotRithik
Copy link
Author

This adapter fetches daily volume and fee data for the Hyperliquid perpetuals exchange.

It works in three main steps:

  1. Fetches Data from the Official Stats API: It uses the backend API that powers stats.hyperliquid.xyz. This source provides accurate, pre-calculated historical data for a full UTC day.

  2. Calculates Metrics:

    • Daily Volume: It calls the /total_volume endpoint and sums the volume for all markets for the requested day.
    • Daily Fees & Revenue: It calls the /user_pnl endpoint. The protocol's revenue is the inverse of the net profit/loss of all traders (-1 * total_user_pnl), as user_pnl + hlp_pnl + liquidator_pnl = 0 for any trade. Fees paid by users are the same but are floored at zero (Since users can't pay a negative fee, which would be a profit. We are not measuring profit here).
  3. Handles API Quirks:

    • Timestamp Correction: It adds two days to the requested date to correct for compounding off-by-one-day errors found in both the DefiLlama test runner and the Hyperliquid API, ensuring the data aligns with the official frontend.
    • Stale Data: The API's data source is known to lag by several weeks. To avoid showing incorrect $0 data for recent dates, the code intentionally throws an error if the requested date is recent but the API has no data for it.

@NotRithik NotRithik marked this pull request as ready for review August 21, 2025 00:46
@noateden
Copy link
Contributor

hi @NotRithik, thanks for the PR. Look like this API data is stale from 2025-07-12

@noateden noateden closed this Aug 21, 2025
@noateden noateden reopened this Aug 21, 2025
@llamabutler
Copy link

The hyperliquid-perp adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts dexs hyperliquid-perp

🦙 Running HYPERLIQUID-PERP adapter 🦙
---------------------------------------------------
Start Date:	Wed, 20 Aug 2025 01:06:33 GMT
End Date:	Thu, 21 Aug 2025 01:06:33 GMT
---------------------------------------------------

Error: Hyperliquid fee data is stale. Latest available date from API is 2025-07-12, but you requested 2025-08-22.
    at fetch (/home/runner/work/dimension-adapters/dimension-adapters/dexs/hyperliquid-perp/index.ts:59:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getChainResult (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:206:18)
    at async Promise.all (index 0)
    at async _runAdapter (/home/runner/work/dimension-adapters/dimension-adapters/adapters/utils/runAdapter.ts:159:20)
    at async /home/runner/work/dimension-adapters/dimension-adapters/cli/testAdapter.ts:69:24 {
  chain: 'hyperliquid'
}

@NotRithik
Copy link
Author

NotRithik commented Aug 21, 2025

Hi @noateden Yes, unfortunately this method of getting the data, can fetch updated info only when the hyperliquid team processes and updates its archive, which happens about once a month. I'd ideally want to go with a blockchain-first approach, but it's not super feasible through an adapter with hyperliquid because of the sheer volume of trades on it each day. It is possible to get the latest trading volume figures and open interest, but not fee data. I didn't want to return half-complete data, which is why I designed this adapter to throw an error if any of the data points isn't available.

Please feel free to provide any pointers on how I can improve this adapter. Do you think going returning just OI, trading volume would be a good approach for now, until we can come up with a better approach for fetching fees? These endpoints are regularly updated and don't go stale for weeks unlike the fee data.

@noateden noateden marked this pull request as draft August 21, 2025 04:49
@treeoflife2
Copy link
Member

@NotRithik we can use allium query, as they have hyperliquid core trades data, https://docs.allium.so/historical-data/supported-blockchains/hyperliquid/dex/trades

@treeoflife2
Copy link
Member

treeoflife2 commented Aug 25, 2025

@NotRithik we can use allium query, as they have hyperliquid core trades data, https://docs.allium.so/historical-data/supported-blockchains/hyperliquid/dex/trades

ignore this as we don't have access to allium hyperliquid data anymore

@NotRithik
Copy link
Author

NotRithik commented Aug 26, 2025

If I can get a cloud instance with the required resources, I will run a hyperliquid node and access trade info in this format: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/nodes/l1-data-schemas.

The reason behind running a new blockchain node is that order history data is stored on the node's disk, and is not exposed with an endpoint that we can just ping an existing node provider for.

I will then create an open-source public endpoint that indexes Hyperliquid order info by the hour:
image

Then, I'll create an API endpoint that uses this order info to effectively create a new source for derivatives volume and revenue. This hyperliquid node can also serve as a data source for other deeper custom DefiLlama dashboards.

Would DefiLlama be open to this approach and funding the setup?

EDIT: Added reasoning behind running a new blockchain node.

@NotRithik
Copy link
Author

@0xngmi @realdealshaman thoughts?

@treeoflife2
Copy link
Member

treeoflife2 commented Aug 26, 2025

@0xngmi @realdealshaman thoughts?

thanks but no, we don't want to go this route. don't worry about this, we will find some solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants