feat(perps): add e2e validation scripts for HyperLiquid API testing#8893
feat(perps): add e2e validation scripts for HyperLiquid API testing#8893abretonc7s wants to merge 11 commits into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
|
…efore close - Change TP/SL order grouping from 'na' to 'positionTpsl' so HyperLiquid properly associates trigger orders with the open position. - Re-fetch mid price immediately before computing close order price to avoid stale price from script start causing IOC close to not fill.
Automated pr-complete run — #8893
Worker reportPR #8893 — Comments ReportPR Comments/Checks Addressedcursor[bot] Review Comments (2 issues)1. TP/SL orders use wrong grouping value (Medium Severity)
2. Close order uses stale price from script start (Medium Severity)
Bot Comments (not actionable)
CI Checks
Files Changed
Downstream Compatibility AssessmentNo impact. Changes are limited to Validation Results
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8ceeb88. Configure here.
| runner.assertGt(`${params.coin} mid price > 0`, midPrice, 0); | ||
|
|
||
| const isBuy = params.side === 'long'; | ||
| const limitPrice = midPrice * (1 + params.offsetPct / 100); |
There was a problem hiding this comment.
Default offset causes immediate fill for short orders
Medium Severity
The limitPrice calculation applies offsetPct uniformly regardless of order side: midPrice * (1 + offsetPct / 100). The default offsetPct is -2, which places the price 2% below market. For a buy (long) order this correctly rests on the book, but for a sell (short) order, placing 2% below market causes immediate fill against existing bids. Running --side short without explicitly setting --offset-pct to a positive value produces an order that fills instantly, failing the 'order is resting' assertion in a confusing way.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 8ceeb88. Configure here.


Explanation
The perps controller (migrated in #8871, tests in #8840) currently has 58 unit test files — all mocked. Zero coverage against real HyperLiquid APIs. This PR adds standalone e2e validation scripts that call the live HyperLiquid API.
Read-only scenarios (no wallet needed)
Trading scenarios (testnet wallet, parameterized)
All trading scripts accept CLI params (
--coin,--size,--leverage,--side,--tp-pct,--sl-pct,--offset-pct) so recipes can invoke the same script with different scenarios.Each script uses
createStandaloneInfoClient(read-only) orExchangeClient+ viemprivateKeyToAccount(trading), outputs structured JSON, and exits 0/1.See
e2e/README.mdfor full usage.References
Checklist
Note
Low Risk
Changes are isolated to new e2e scripts, docs, and dev dependencies; production controller code is not modified. Trading scripts only run with an explicit testnet private key env var.
Overview
Adds a new
packages/perps-controller/e2esuite of standalonetsxscripts that hit live HyperLiquid (no mocks), with sharedE2ERunnerJSON pass/fail output ande2e/README.mdusage docs.Read-only scripts use
createStandaloneInfoClientfor market data, account shapes, order-validation constants vs live meta, WebSocketallMids, and error-code/API edge checks. Trading scripts useExchangeClient+ viemprivateKeyToAccountviaHL_E2E_PRIVATE_KEY(testnet by default), with CLI flags fortrading-lifecycle(open → optional TP/SL → close) andlimit-orders(rest → cancel).Build/tooling:
tsconfig.jsonincludes./e2e,viemis added as a devDependency (lockfile bumpsviem/ox/ws).Reviewed by Cursor Bugbot for commit 8ceeb88. Bugbot is set up for automated code reviews on this repo. Configure here.