Skip to content

[add] halfmoon - add perpetuals volume adapter#8069

Open
GameLife75 wants to merge 2 commits into
DefiLlama:masterfrom
GameLife75:add-halfmoon-perps
Open

[add] halfmoon - add perpetuals volume adapter#8069
GameLife75 wants to merge 2 commits into
DefiLlama:masterfrom
GameLife75:add-halfmoon-perps

Conversation

@GameLife75

@GameLife75 GameLife75 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a standalone dexs/halfmoon adapter to track HalfMoon perpetual futures volume.
  • Data source: https://api-market.halfmoondex.com/md/volume/builder/daily_stats?broker_id=halfmoon
  • Volume metric: daily taker volume only.
  • Chain attribution: Avalanche (primary deployment chain).

Test plan

  • npm test dexs halfmoon
  • npm test dexs halfmoon 2026-07-10
  • Verified adapter returns expected daily volume (~5.86k on 2026-07-10)

Name (to be shown on DefiLlama):

HalfMoon

Twitter Link:

https://x.com/HalfMoon_Dex

List of audit links if any:
Website Link:

https://halfmoondex.com/

Logo (High resolution, will be shown with rounded borders):

https://halfmoondex.com/images/navbar/logo.svg

Current TVL:
Treasury Addresses (if the protocol has treasury):
Chain:

Avalanche (primary). Also supports Arbitrum for deposits/trading.

Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed):
Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed):
Short Description (to be shown on DefiLlama):

HalfMoon is a perpetual futures trading platform.

Token address and ticker if any:
Category (full list at https://defillama.com/categories) *Please choose only one:

Derivatives

Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
Implementation Details: Briefly describe how the oracle is integrated into your project:
Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:

https://halfmoon.gitbook.io/halfmoon-docs

forkedFrom (Does your project originate from another project):
methodology (what is being counted as tvl, how is tvl being calculated):

Perpetual futures taker volume routed through HalfMoon. Daily volume is sourced from broker daily stats and attributed to Avalanche as the primary deployment chain.

Github org/user (Optional, if your code is open source, we can track activity):
Does this project have a referral program?

Yes

Track HalfMoon perp taker volume from the broker daily stats API and attribute it to Avalanche as the primary deployment chain.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a HalfMoon SimpleAdapter for Avalanche that fetches and caches daily taker volume statistics, validates date-specific data, and returns parsed daily volume.

Changes

HalfMoon adapter

Layer / File(s) Summary
Daily volume fetching and adapter configuration
dexs/halfmoon/index.ts
Fetches and caches HalfMoon statistics by date, throws when data is missing or invalid, converts takerVolume to dailyVolume, and configures the Avalanche adapter metadata and methodology.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HalfMoonAdapter
  participant statsByDate
  participant HalfMoonMarketEndpoint
  HalfMoonAdapter->>statsByDate: request daily statistics
  statsByDate->>HalfMoonMarketEndpoint: fetch daily_stats data
  HalfMoonMarketEndpoint-->>statsByDate: return date-indexed statistics
  statsByDate-->>HalfMoonAdapter: return parsed daily volume
Loading

Suggested labels: dexs, new-adapter, methodology

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Breakdown Methodology Check ✅ Passed Not a fees adapter: dexs/halfmoon uses no .add() calls or breakdownMethodology, so the check is not applicable.
Income Statement Compliance ✅ Passed Not a fees adapter; dexs/halfmoon returns only dailyVolume from takerVolume, with no dailyFees/dailyRevenue/dailySupplySideRevenue fields.
Version 2 Required ✅ Passed HalfMoon uses an external daily_stats API that only provides daily aggregates, so version 1 is allowed under the exception.
Pullhourly Required For Version 2 ✅ Passed HalfMoon is declared version: 1, so the v2 pullHourly requirement does not apply.
Dune Adapters Are Version 1 ✅ Passed HalfMoon uses an external API, not Dune; it still exports version: 1 and has no TIME_RANGE/date-filter usage.
Income Statement Balance ✅ Passed HalfMoon only exposes dailyVolume in a volume adapter; no dailyFees/dailyRevenue/supply-side fields exist, so the fee balance check is not applicable.
Fetchoptions Usage ✅ Passed HalfMoon fetch is async ({ dateString }: FetchOptions) and returns only dailyVolume; no old 3-arg signature or timestamp field appears.
Adapter Shape ✅ Passed HalfMoon uses a single SimpleAdapter with chains:[AVAX] and one start date; no per-chain adapter or config maps appear.
Efficiency And Error Handling ✅ Passed PASS: HalfMoon adapter only does an HTTP fetch/cache and rethrows API errors; it uses no getLogs/api.call loops/raw topics/allowNegativeValue patterns.
Methodology Keys ✅ Passed The methodology object uses the display-name key Volume, not a code field like dailyVolume.
Title check ✅ Passed The title follows the required [type] protocol-name - description format and matches the HalfMoon volume adapter change.
Description check ✅ Passed The description includes the main summary, test plan, and most required listing fields for the new protocol.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

The halfmoon adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs halfmoon

🦙 Running HALFMOON adapter 🦙
---------------------------------------------------
Start Date:	Fri, 10 Jul 2026 00:00:00 GMT
End Date:	Sat, 11 Jul 2026 00:00:00 GMT
---------------------------------------------------

AVAX 👇
Backfill start time: 24/12/2025
Daily volume: 2.12 k

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/halfmoon/index.ts`:
- Around line 13-24: Update the statsByDate initialization in fetch so a
rejected httpGet promise clears statsByDate before propagating the error,
allowing subsequent calls to retry. Preserve the existing successful date-map
caching behavior and use the existing fetch and statsByDate symbols.
- Around line 27-31: Update the daily volume handling around the day lookup and
takerVolume conversion: throw when day is missing, and remove the || 0 fallback
so invalid or non-numeric takerVolume values also throw instead of returning
dailyVolume: 0. Preserve the valid numeric return path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1f4dc101-29ce-4aab-924c-b3947fa6714d

📥 Commits

Reviewing files that changed from the base of the PR and between a025615 and 61ae2f4.

📒 Files selected for processing (1)
  • dexs/halfmoon/index.ts

Comment thread dexs/halfmoon/index.ts
Comment thread dexs/halfmoon/index.ts Outdated
Clear the stats cache when the API request fails so retries can succeed, and throw on missing or invalid daily stats instead of recording zero volume.

Co-authored-by: Cursor <cursoragent@cursor.com>
@GameLife75 GameLife75 changed the title Add HalfMoon perpetuals volume adapter [add] halfmoon - add perpetuals volume adapter Jul 11, 2026
@github-actions

Copy link
Copy Markdown

The halfmoon adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs halfmoon

🦙 Running HALFMOON adapter 🦙
---------------------------------------------------
Start Date:	Fri, 10 Jul 2026 00:00:00 GMT
End Date:	Sat, 11 Jul 2026 00:00:00 GMT
---------------------------------------------------

AVAX 👇
Backfill start time: 24/12/2025
Daily volume: 2.12 k

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dexs/halfmoon/index.ts (1)

46-59: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a source comment for STATS_URL
STATS_URL is hardcoded; add a source link or inline comment so the endpoint can be traced later.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dexs/halfmoon/index.ts` around lines 46 - 59, Add a concise source URL
comment next to the hardcoded STATS_URL declaration, identifying where the
endpoint originates. Keep the existing endpoint value and adapter behavior
unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@dexs/halfmoon/index.ts`:
- Around line 46-59: Add a concise source URL comment next to the hardcoded
STATS_URL declaration, identifying where the endpoint originates. Keep the
existing endpoint value and adapter behavior unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5c782a95-f783-4eab-9bef-345f65467def

📥 Commits

Reviewing files that changed from the base of the PR and between 61ae2f4 and a45c469.

📒 Files selected for processing (1)
  • dexs/halfmoon/index.ts

@bheluga bheluga self-assigned this Jul 11, 2026
@bheluga

bheluga commented Jul 11, 2026

Copy link
Copy Markdown
Member

@GameLife75 thanks for the PR
Can you try to track volume using on-chain logs on avalanche?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants