Skip to content

[new-plugin] hyperliquid-aigrid v1.2.6#360

Closed
dddd86971-cloud wants to merge 11 commits into
okx:mainfrom
dddd86971-cloud:submit/hyperliquid-aigrid
Closed

[new-plugin] hyperliquid-aigrid v1.2.6#360
dddd86971-cloud wants to merge 11 commits into
okx:mainfrom
dddd86971-cloud:submit/hyperliquid-aigrid

Conversation

@dddd86971-cloud
Copy link
Copy Markdown

[new-plugin] hyperliquid-aigrid v1.2.0

Season 1 Developer Challenge submission — strategy plugin for Hyperliquid perps.

This PR replaces #344 (which was titled liqgrid — renamed for clearer brand association with Hyperliquid).

Summary

hyperliquid-aigrid turns a trader's one-sentence Hyperliquid view into a deterministic, risk-capped grid strategy:

User: "BTC 90k-95k range, $300 at 2x"
   ↓
hyperliquid-aigrid Skill (natural-language parsing)
   ├─► hyperliquid-plugin            → mark price + 1h candles
   ├─► api.hyperliquid.xyz/info      → live funding rate (read-only)
   └─► hyperliquid-aigrid binary     → deterministic plan
   ↓
Dry-run plan + 7-day backtest preview:
   • 23 tick-aligned rungs, concentrated near mark
   • funding-tilted ±20% (collects funding as alpha)
   • stop-loss + max-loss bound, hard caps enforced
   ↓
User: "go live"
   ↓
hyperliquid-plugin order ... --strategy-id hyperliquid-aigrid
hyperliquid-plugin tpsl  ... --strategy-id hyperliquid-aigrid
   ↓
Agentic Wallet TEE signing → on-chain fills

What makes it different (vs other Hyperliquid grid Skills)

  1. Deterministic binary, not LLM math — grid prices, stop-loss, sizing run in compiled TypeScript engine. Same inputs → byte-identical outputs. Stable planHash SHA-256 fingerprint.
  2. Funding rate as alpha — when |annualized funding| ≥ 10%, per-rung notional tilts up to ±20% toward the side that collects funding. Hyperliquid-specific.
  3. Concentrated-liquidity rung sizing — Gaussian fill-probability weighting. Mark-near rungs get more capital, edge rungs less. Same total notional, higher expected fill density.
  4. 75-combo parameter optimizer (hyperliquid-aigrid optimize) — sweeps 5 widths × 5 leverages × 3 profiles, Calmar-ranked.
  5. Built-in backtest (hyperliquid-aigrid backtest) — deterministic candle-by-candle simulation. Realized PnL / max DD / Sharpe before live trading.
  6. Zero-friction quickstart (hyperliquid-aigrid quickstart) — given coin + notional + candles, binary picks (rangeLow, rangeHigh, leverage, profile) from recent vol regime.

Safety posture (advanced risk)

  • Dry-run by default on every session
  • Max $5,000 notional / 10× leverage / 50 rungs (hard-coded in src/types.ts:CAPS)
  • Stop-loss bounded to ≤ 30% of notional (warning + explicit user accept above threshold)
  • First-session training wheels (capped $200 / 2× regardless of user request)
  • No private key handling — all signing via Agentic Wallet TEE through hyperliquid-plugin
  • All write ops carry --strategy-id hyperliquid-aigrid for leaderboard attribution

Source

  • Repo: dddd86971-cloud/hyperliquid-aigrid
  • Pinned commit: aed9868e8950ecb6b49c852bc75e92fd150ecd6d
  • Language: TypeScript (compiled to JS, distributed via bun install -g)
  • Self-tests: 30 invariants — determinism, cap enforcement, tick alignment, risk-profile monotonicity, input validation, funding bias, concentrated-liquidity sizing, backtest determinism, quickstart, optimize ranking
  • License: MIT

Pre-submission checklist

  • plugin.yaml, .claude-plugin/plugin.json, SKILL.md, SUMMARY.md, LICENSE all present
  • name = hyperliquid-aigrid (lowercase, 18 chars, within 2-40)
  • version = 1.2.0 consistent across all three files
  • author.github = dddd86971-cloud matches PR author
  • license = MIT (valid SPDX)
  • category = strategy (per the strategy-plugin spec)
  • dependent_plugin = [hyperliquid-plugin@^0.3.9]
  • risk_level = advanced, supported_venues = [hyperliquid]
  • description = 195 chars (within 200)
  • api_calls = ["https://api.hyperliquid.xyz"] (read-only info endpoint for funding + candles)
  • All write ops carry --strategy-id hyperliquid-aigrid
  • SKILL.md sections: Overview / Pre-flight / Commands / Error Handling / Security Notices
  • No hardcoded credentials / private keys / mnemonics
  • No pre-compiled binaries committed (CI compiles TS)
  • PR only modifies files in skills/hyperliquid-aigrid/
  • Source repo binary builds locally (TypeScript → JS, #!/usr/bin/env node shebang on dist/index.js)
  • 30/30 self-tests pass

🤖 Generated with Claude Code

Strategy plugin for Hyperliquid perps. Renamed from liqgrid for clearer
brand association with Hyperliquid.

Pipeline:
  user → natural-language parse → hyperliquid-plugin (mark/candles)
       + api.hyperliquid.xyz (funding) + hyperliquid-aigrid binary
       → dry-run plan + 7-day backtest preview → user confirm
       → hyperliquid-plugin order/tpsl --strategy-id hyperliquid-aigrid
       → Agentic Wallet TEE signing → on-chain fills

Key features (deterministic binary):
- Funding-aware ±20% notional tilt to collect funding as alpha
- Concentrated-liquidity sizing (Gaussian fill-prob in log-price)
- 75-combination parameter optimizer (Calmar-ranked)
- 30-day backtest with realized PnL / max DD / Sharpe
- Zero-friction quickstart (range/leverage/profile auto-pick)
- Hard caps in source: $5k notional / 10x lev / 50 rungs / 30% loss

Source: dddd86971-cloud/hyperliquid-aigrid@aed9868
30/30 self-tests pass. SUMMARY.md / SKILL.md / README.md / LICENSE all
present. category=strategy + dependent_plugin: hyperliquid-plugin@^0.3.9
+ risk_level: advanced + supported_venues: [hyperliquid].

This PR replaces okx#344 (which was titled liqgrid). okx#344 will be closed
with a link to this PR.
@dddd86971-cloud dddd86971-cloud mentioned this pull request Apr 25, 2026
24 tasks
mac added 3 commits April 25, 2026 20:42
Round 1 (P1 + P2):
- SKILL.md: lg-<planHash[:5]> → ha-<planHash[:6]> (line 498 stale tag form)
- SKILL.md: drop 'v1.0.0' from Example 3 ceiling text
- SKILL.md: jq funding-rate fetch example now copy-paste-able with --arg
  coin substitution + explicit "mainnet only" rationale
- README.md: 26 invariants → 30
- plugin.yaml: + type: community-developer + github_link
- plugin.json: + homepage + repository

Round 2 (caught after first verification pass):
- SKILL.md: grid-resume filter rule lg- prefix → 'hyperliquid-aigrid' or
  ha-{planHash[:6]} per Attribution Rule (line 561 was stale)
- source_commit pin bumped to 2a8d6cc (incl. types.ts comment fix +
  README v1.2 section + 30-test count)

No code changes. Same 30/30 self-tests pass.
Source: dddd86971-cloud/hyperliquid-aigrid@66bd3f5

Adds post-buildLevels guard for small-notional accounts ($50-200 range):
when concentrated-liquidity sizing leaves edge rungs below
marketMeta.minOrderSizeUsd, iteratively reduce gridCount toward
MIN_GRID_COUNT, then fall back to uniform sizing if even that fails.

Solves the production issue where v1.2.0 plans for $50 accounts produced
edge rungs around $0.05 each — well below HL's $10 min order — leading
to silent rejection on placement. Now small-account users get viable
4-rung uniform grids with clear warnings explaining how to restore
concentrated geometry.

Self-tests: 30 → 33. Existing large-account behavior (≥ $300 × 1×) is
byte-identical to v1.2.0.

SKILL.md adds 'Small-account guidance' table covering:
- ≥ $300 × 1× → full concentrated
- $100-$300 × 1× → reduced count, still concentrated
- $50-$100 × 1× → uniform fallback
- < $50 × 1× → recommend 2× leverage
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.0 [new-plugin] hyperliquid-aigrid v1.2.1 Apr 26, 2026
mac added 3 commits April 26, 2026 10:57
…ills/day<1 warning

PR-side updates only — bump plugin.yaml version + source_commit pin, plus
document the new fields + REFUSE-abort rule in SKILL.md.

Three new GridPlan output fields make the funding-bias tilt and grid
geometry directly readable without summing levels[]:

  - buySideNotionalUsd / sellSideNotionalUsd  : per-side aggregates
  - rangeWidthPct                              : (rangeHigh - rangeLow) / mark

New "expected fills/day < 1" warning: when realized vol is too low for
the configured range, the grid sits idle and pays funding for nothing —
the warning suggests a tighter range (~±2σ daily of mark) or waiting.

Pre-execution check okx#3 in SKILL.md formalizes the existing "REFUSE:
prefix → abort" guard for stale-range / mark-out-of-range plans.

planHash unchanged for the same input bytes — purely additive output
extension. Source SHA pinned at b0fdd4230f, self-tests 33 → 37 (all
green).
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.1 [new-plugin] hyperliquid-aigrid v1.2.2 Apr 26, 2026
@dddd86971-cloud
Copy link
Copy Markdown
Author

v1.2.2 update — purely additive output extension

Source SHA 66bd3f57b0fdd423. plugin.yaml version and source_commit bumped accordingly.

What's new:

  • 3 new GridPlan output fields (buySideNotionalUsd, sellSideNotionalUsd, rangeWidthPct) — direct visibility of funding-bias tilt and grid geometry without walking levels[].
  • expected fills/day < 1 warning — flags grids that would sit idle at current vol; suggests tightening range to ±2σ daily of mark.
  • SKILL.md formalizes the REFUSE-prefix abort rule as pre-execution check [new-plugin] test-rust-cli v1.0.0 — E2E verification #3.
  • Self-tests: 33 → 37 (4 new cases covering the additions).

planHash is unchanged for the same input bytes — the new fields are derived from existing inputs (levels[], rangeLow, rangeHigh, markPrice) and not part of the hashable spec. Cached planHash references in user UIs / audit logs remain valid.

Same shape as before (no breaking changes), no algorithm shifts, no new caps. Rebased cleanly on origin/main.

PR-side updates only — bump plugin.yaml version + source_commit pin,
plus document the new range algorithm in SKILL.md.

quickstart() now derives the recommended range from BOTH the placeable
rung count AND realized vol, instead of a fixed vol-only formula. For
small accounts (where rungs are forced down to MIN_GRID_COUNT=4 by the
HL $10 min order), this means the range tightens to (rungs-1) × σ_hourly
instead of always being ±4-7% — so the grid actually trades on hourly
wiggles rather than waiting hours for outlier moves.

Real-world impact at σ_d=1.35% on BTC:

  $24   account → ±0.41% (was ±4.4%)
  $100  account → ±2.61% (was ±4.4%)
  $5000 account → ±4.36% (unchanged — vol envelope kept as upper bound)

plan() semantics unchanged. Only quickstart() output range differs.
Plans built from explicit (rangeLow, rangeHigh) have byte-identical
output to v1.2.2.

Source SHA pinned at dd30dec42e. Self-tests 37 → 41 (all green).
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.2 [new-plugin] hyperliquid-aigrid v1.2.3 Apr 26, 2026
@dddd86971-cloud
Copy link
Copy Markdown
Author

v1.2.3 update — notional-aware quickstart range

Source SHA b0fdd423dd30dec42. plugin.yaml bumped accordingly.

This fixes a real product gap discovered during live testing: a $24 small-account user calling quickstart got the same ±4-7% range as a $5000 user, which spread their forced 4 rungs across ~1% gaps when hourly vol was only ~0.3%. Result: grid sat inactive for hours waiting for outlier moves.

v1.2.3 picks the tighter of two derivations:

  • (a) natural geometry: (rungs - 1) × σ_hourly × profileGap where rungs = clamp(floor(notional × lev / minOrder), 4, 50). Each gap ≈ one hourly σ.
  • (b) vol envelope: k × σ_daily × √7 × profileWidth (the old formula, now used only as an upper bound).

Real-world impact at σ_d=1.35% (BTC calm day):

Account Pre-1.2.3 Post-1.2.3 Source
$24 ±4.4% ±0.41% natural — 4 rungs
$100 ±4.4% ±2.61% natural — 20 rungs
$5000 ±4.4% ±4.36% vol envelope (unchanged)

Plus a tiny notional warning when notional × leverage < MIN_GRID_COUNT × minOrder, with the exact bump amount to restore full coverage.

plan() semantics unchanged — only quickstart() was touched. Plans built from explicit (rangeLow, rangeHigh) have byte-identical output to v1.2.2. Self-tests 37 → 41 (all green).

PR-side updates only — bump plugin.yaml version + source_commit pin,
plus document the new fee-aware fields in SKILL.md.

Discovered during live $24-account testing on this PR that maker fills
on Hyperliquid tier-0 carry a 1.5 bps fee even with `crossed: false`
(observed: 0.00016 BTC × $77,822 fill paid $0.001867 USDC). v1.2.4
makes this visible in plan output:

  - avgRungGapPct
  - expectedFeePerRoundtripUsd
  - breakEvenGapPct (= 2 × feeRateMaker)
  - feeAwareNetEdgePerRoundtripUsd

Plus optional MarketMeta.feeRateMaker / feeRateTaker (defaults to HL
tier-0: 1.5 / 4.5 bps), and a fee-erosion warning when avgRungGapPct
falls within 2× breakEven.

Source SHA pinned at 098a21aa. Self-tests 41 → 45 (all green).
plan() / quickstart() semantics, planHash, and levels[] byte-identical
to v1.2.3.
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.3 [new-plugin] hyperliquid-aigrid v1.2.4 Apr 26, 2026
@dddd86971-cloud
Copy link
Copy Markdown
Author

v1.2.4 update — fee-aware plan output, driven by live testing on this PR

Source SHA dd30dec42098a21aa. plugin.yaml bumped accordingly.

Discovered during live $24-account 4-rung grid testing on this PR that maker fills on Hyperliquid tier-0 carry a 1.5 bps fee even when crossed: false (observed: a 0.00016 BTC × $77,822 maker buy paid $0.001867 USDC = 1.5 bps of $12.45 notional).

v1.2.4 makes the fee economics visible in plan output instead of leaving users to guess whether their grid is profitable in absolute USD:

  • avgRungGapPct — gap between adjacent same-side rungs
  • expectedFeePerRoundtripUsd2 × rungNotional × leverage × feeRateMaker
  • breakEvenGapPct2 × feeRateMaker; below this gap fees > gross
  • feeAwareNetEdgePerRoundtripUsd — gross excursion − round-trip fee

Plus optional MarketMeta.feeRateMaker / feeRateTaker (defaults match HL tier-0: 1.5 / 4.5 bps) and a fee-erosion warning when avgRungGapPct < 2 × breakEvenGapPct.

Real example from the live $24 grid (gap 0.275%, default maker 1.5 bps):

  • gross/RT = $0.034
  • fee/RT = $0.0036 (10.6% of gross)
  • net/RT = $0.0294
  • breakEven = 0.030% (gap is 9× breakEven — comfortable)

plan() / quickstart() semantics, planHash, and levels[] byte-identical to v1.2.3. Self-tests 41 → 45 (all green).

PR-side updates only — bump plugin.yaml version + source_commit pin,
plus document two new user-facing commands in SKILL.md.

These commands respond to natural-language asks the user already makes
("撤掉最下面那个 buy", "网格往上挪", "cancel the $77,608 rung", "tighten
the grid", "follow the price"). Pre-v1.2.5 the user had to manually
orchestrate grid-close → grid-plan → grid-open through three separate
confirmations — error-prone (e.g. cancelling but failing to place new)
and clunky.

  - grid-cancel-rung : surgical single-oid cancel via natural-language
                       reference (lowest / highest / closest-to-mid /
                       by-price), with disambiguation rules and
                       explicit ASK when ambiguous. Other rungs stay
                       intact.

  - grid-roll        : atomic re-center around current mark. One
                       confirmation, internally cancels old rungs +
                       runs grid-quickstart with current price + places
                       new rungs. Safety rules:
                         - refuse if existing position would be
                           liquidated by new range
                         - refuse if any old rungs fail to cancel
                         - "roll + flatten" option to also close the
                           current position before re-deploying

Skill orchestration only — binary unchanged. Source SHA pinned at
41ca8f93. Self-tests 45 (unchanged from v1.2.4). plan() / quickstart()
semantics and planHash byte-identical to v1.2.4 for the same input.
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.4 [new-plugin] hyperliquid-aigrid v1.2.5 Apr 26, 2026
@dddd86971-cloud
Copy link
Copy Markdown
Author

v1.2.5 update — grid-cancel-rung + grid-roll user commands

Source SHA 098a21aa41ca8f93. plugin.yaml bumped accordingly.

This is a Skill-orchestration release — no binary changes. plan() / quickstart() semantics, planHash, and dist/ output are byte-identical to v1.2.4. Only SKILL.md adds two new user-facing commands.

Why these matter: users naturally say things like "撤掉最下面那个 buy", "cancel the $77,608 rung", "网格往上挪", "tighten the grid", "follow the price". Pre-v1.2.5 the Skill had no documented flow for these — the user had to manually orchestrate grid-closegrid-plangrid-open (three commands, three confirmations, error-prone if any step fails).

  • grid-cancel-rung — cancel ONE rung via natural-language reference. Documented disambiguation table maps "lowest" / "highest" / "closest to mid" / "the buy at $X" to a specific oid. If ambiguous, the Skill enumerates candidates and asks instead of guessing. The other rungs stay intact.

  • grid-roll — atomically re-center the active grid around current mark. One confirmation; internally:

    1. Runs grid-quickstart with current markPrice + fresh candles + same totalNotional / riskProfile (so v1.2.3's notional-aware geometry still applies)
    2. Surfaces side-by-side old vs. new rungs + planHash for user confirmation
    3. Cancels old rungs (or roll + flatten to also close the existing position first)
    4. Places new rungs

    Safety rules: refuses if the existing position would be liquidated by the new range; refuses if any old rungs fail to cancel before placing new ones; never lets state become inconsistent.

Self-tests: 45 (unchanged). The decision to keep these as orchestration-only docs (not binary subcommands) is deliberate — the binary stays pure compute, and the agent layer handles user-intent disambiguation where it belongs. This also keeps planHash byte-stable across v1.2.4 → v1.2.5.

…ptimize fee-aware

PR-side updates only — bump plugin.yaml version + source_commit pin,
plus document the new fee-aware behavior in SKILL.md.

Fixes a real visibility gap discovered during PR-okx#360 testing: the
v1.2.2 / v1.2.4 fields (buySide/sellSide notional, fee economics)
were computed by the binary but never shown by `explain` — users
had to read raw JSON. v1.2.6 makes `explain` render them in human
form (Notional split + Fee economics sections).

Also makes runBacktest/runOptimize fee-aware:
  - BacktestResult adds feesPaidUsd + realizedPnlNetUsd
  - Each simulated fill is charged maker fee (default 1.5 bps HL
    tier-0, overridable via marketMeta.feeRateMaker)
  - Optimize.score now uses NET PnL, not gross — prevents tight
    fee-eroding grids from gaming the ranking

Backwards compat preserved: realizedPnlUsd unchanged (gross), score
formula change is transparent to callers reading realizedPnlNetUsd.
plan() / quickstart() / planHash byte-identical to v1.2.5.

Source SHA pinned at c45a8ef3. Self-tests 45 → 49.
@dddd86971-cloud dddd86971-cloud changed the title [new-plugin] hyperliquid-aigrid v1.2.5 [new-plugin] hyperliquid-aigrid v1.2.6 Apr 26, 2026
@dddd86971-cloud
Copy link
Copy Markdown
Author

v1.2.6 update — explain surfaces fee fields; backtest + optimize fee-aware

Source SHA 41ca8f93c45a8ef3. plugin.yaml bumped accordingly.

Fixes a visibility gap discovered while monitoring the live $24-account grid on this PR: the v1.2.2 buy/sell aggregates and v1.2.4 fee-economics fields were computed by the binary but explain never rendered them — users had to jq raw JSON. v1.2.6 adds two new sections to explain:

Notional split:
  buy-side:        $12.00
  sell-side:       $12.00  (ratio buy/sell 1.000 — neutral)

Fee economics (per completed roundtrip):
  rung gap:        0.263%  (break-even 0.030% — 8.8× margin)
  expected fee:    $0.0036  (maker × 2 legs)
  net edge / RT:   $0.0280
  est. daily net:  $0.1820  (6.5 RT/day × $0.0280)

runBacktest and runOptimize are now fee-aware:

  • BacktestResult adds feesPaidUsd + realizedPnlNetUsd. Every simulated fill incurs price × sizeCoin × feeRateMaker (default 1.5 bps HL tier-0, overridable via marketMeta.feeRateMaker).
  • OptimizeCandidate exposes the same breakdown. score is now realizedPnlNetUsd / max(maxDD, 1) instead of gross — prevents tight fee-eroding grids from topping the ranking.

Real impact on a 75-combo BTC sweep:

gross fees net score
Top candidate $2.062 $0.172 (8.3%) $1.89 1.89

Backwards compat preserved: realizedPnlUsd unchanged (still gross). Old callers continue to work; new callers prefer realizedPnlNetUsd. computeGridPlan() and quickstart() semantics, planHash, and levels[] byte-identical to v1.2.5. Self-tests 45 → 49.

@Noah3595
Copy link
Copy Markdown
Collaborator

Plugin Store DApp Popularity Contest

  • 💰 Prize Pool: 17,700 USDC
  • 📅 Period: Apr 23 – May 7, 23:59 (UTC+8)
  • 🧩 Featured Basic Skills: Polymarket Plugin | Hyperliquid Plugin

About the Contest

Plugin Store is the decentralized agent plugin marketplace on Onchain OS.

This contest focuses on two trading-related Basic Skills in Plugin Store — the Polymarket Plugin and the Hyperliquid Plugin — and encourages developers to build more high-quality strategy Skills around them.

Contest Rules

  • Strategy Skills must be built on top of the Polymarket Plugin or the Hyperliquid Plugin.
  • Each strategy Skill is ranked across three independent dimensions: trading volume, number of trades, and number of unique trading addresses.

Scoring Rules

  • Stats are aggregated per Skill. If you submit multiple Skills, each one is scored and competes independently.
  • Only trades initiated through Onchain OS and executed via the Polymarket Plugin or Hyperliquid Plugin are counted. Trades that bypass the Basic Skill are excluded.
  • Leaderboards are synced daily in the official community. Final standings are locked at May 7, 23:59 (UTC+8).

Four Steps to Participate

  1. Open Plugin Store and install the Polymarket Plugin or the Hyperliquid Plugin.
  2. Build your own strategy on top of the Plugin.
  3. Use your strategy — the three metrics will be tracked automatically.
  4. Submit the entry form: https://forms.gle/gFCef1Y4qCv49L2z7

Three Leaderboards · 5,900 USDC each · 17,700 USDC in total

Trading Volume | Number of Trades | Unique Trading Addresses

  • Top 1 — 1,300 USDC
  • Top 2 — 800 USDC
  • Top 3–5 — 600 USDC × 3
  • Top 6–10 — 400 USDC × 5

A single Skill can win on multiple leaderboards. All prizes are paid in USDC.

⚠️ Red Lines

Sybil attacks · Plagiarism · Malicious code

The contest follows fair-play principles. Any confirmed violation will result in immediate removal from the leaderboards.


⚠️ Skills/Plugins not officially listed on OKX Plugin Store have not been reviewed by OKX. Please be aware of the risks when installing or running third-party Skills.

@Noah3595 Noah3595 closed this Apr 27, 2026
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.

2 participants