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 17 commits into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
|
The close order's slippage price was computed from the mid price fetched at script start (step 1), but the close happens at step 6 after leverage setup, order placement, and optional TP/SL — potentially minutes later. Stale price could cause the IOC close to miss and leave the position open.
…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
|
…feat/perps-e2e-validation # Conflicts: # packages/perps-controller/e2e/trading-lifecycle.ts
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 8215682. Configure here.
The e2e limit-order script could continue into cancellation and final removal verification after failing to extract a resting order id. The final removal check then compared open orders against null, which made the cleanup verification look successful even though the script did not have a concrete exchange order to cancel or verify.\n\nThe script now records an explicit failure when no resting order id is extracted and exits with the accumulated runner result before any cancellation/removal checks run.\n\nConstraint: Review feedback targeted the e2e script behavior only; keep the production controller surface unchanged.\nRejected: Leave the final null comparison in place | it preserves the misleading cleanup signal reported by Bugbot.\nConfidence: high\nScope-risk: narrow\nTested: yarn workspace @metamask/perps-controller test --bail --no-coverage\nTested: yarn exec eslint packages/perps-controller/e2e/limit-orders.ts\nNot-tested: Live trading scenario execution; HL_E2E_PRIVATE_KEY is not configured in this slot.

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 additive test/validation tooling and dev dependencies; trading scripts only run with explicit testnet keys and do not alter production controller runtime behavior.
Overview
Adds a new
packages/perps-controller/e2esuite of standalonetsxscripts that hit live HyperLiquid APIs (no mocks), with sharedE2ERunnerJSON pass/fail output ande2e/README.mdusage docs.Read-only scenarios validate mainnet info endpoints and a raw
allMidsWebSocket subscription (market-data,account-state,order-validation,subscription-stream,error-codes). Trading scenarios useHL_E2E_PRIVATE_KEY, default testnet viaHL_TESTNET,viemsigning, and parameterized CLI flags fortrading-lifecycle(open → optional TP/SL → close) andlimit-orders(resting → cancel).Package wiring adds
viemas a devDependency, includes./e2eintsconfig.json, and updatesyarn.lock(viem/ox/ws resolution bumps).Reviewed by Cursor Bugbot for commit 7aaee55. Bugbot is set up for automated code reviews on this repo. Configure here.