fix(perps-controller): repair CommonJS build and add close leverage + order latency#9471
Open
abretonc7s wants to merge 7 commits into
Open
fix(perps-controller): repair CommonJS build and add close leverage + order latency#9471abretonc7s wants to merge 7 commits into
abretonc7s wants to merge 7 commits into
Conversation
… order latency
The published 9.2.1 CJS build emits require("file:///home/runner/.../mod.ts")
because @nktkas/hyperliquid ships .d.ts with an amd-module directive carrying an
absolute CI path; ts-bridge uses it as the CJS require target, so any CJS consumer
throws Cannot find module. Fixed via a yarn patch on the SDK applied through the
root monorepo resolutions (build-time only); perps-controller's dependency range
stays ^0.33.1. Upstream: nktkas/hyperliquid#165
Also:
- TAT-3147: close events emit computed effective leverage (abs(positionValue)/marginUsed,
1 dp), incl. TP/SL closes.
- TAT-3084: add optional TrackingData.orderExecutionLatencyMs, emitted as
order_execution_latency_ms on the trade terminal event only.
Bumps perps-controller to 9.2.2.
…rnal ticket refs Move the pending analytics and CommonJS-fix entries from a premature [9.2.2] section to [Unreleased] and revert the package version to 9.2.1 so the release check passes (package versions are bumped at release-cut, not in feature PRs). Remove internal ticket references from the changelog, code comments, and test names, and apply oxfmt formatting.
The check-changelog action requires user-facing Unreleased entries to link to the current pull request. Add the PR reference to the added, changed, and fixed entries.
Mirror the close path on the open-trade path in #trackOrderResult: when a successful order fills for less than the requested size, emit an additional PERPS_TRADE_TRANSACTION event with status=partially_filled plus amount_filled and remaining_amount. Full fills are unchanged. Previously partial fills only emitted status=executed, hiding the fill's partiality.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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 82545e5. Configure here.
…ing failures
updateMargin only emitted the failed Perp Risk Management analytics event on
the thrown-error path, so a non-throwing { success: false } provider result
silently lost the terminal event. Emit the failed event on that branch too,
with the error message from the result, keeping exactly-once semantics per
operation (success emits executed, non-throwing failure emits failed, thrown
errors emit failed in the catch).
Add flip_long_to_short and flip_short_to_long to the TradeAction union alongside create_position and increase_exposure. The runtime already forwards these values verbatim, so consumers no longer need casts when deriving flip actions.
…mmary The closePositions batch summary event carried only status, completion_duration and bulk_action_id, silently dropping the closed count after clients removed their own close-all summary emission. Add a NUMBER_POSITIONS_CLOSED event property and emit the successful-close count on the batch summary event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Explanation
perps-controller@9.2.1 (#9311) has a broken CommonJS build: dist/services/HyperLiquidClientService.cjs and dist/utils/standaloneInfoClient.cjs emit require("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts") — an absolute build-machine path — so any CJS/bundler/Jest consumer throws Cannot find module. Root cause is upstream: @nktkas/hyperliquid (0.33.0+) ships .d.ts with a /// directive (a Deno->npm dnt build artifact); ts-bridge uses that amd-module name as the CJS require() target, leaking the absolute path. The ESM build is unaffected.
This PR:
All changes are additive and recorded under
## [Unreleased]in the CHANGELOG (version stays 9.2.1 in this PR per release-cut convention; the next perps-controller release picks them up).References
Checklist
Note
Medium Risk
The yarn patch changes how a critical HyperLiquid SDK resolves in CJS builds (high impact if wrong), but the change is build-time only and narrowly strips bad
.d.tsdirectives; runtime trading/analytics edits are mostly additive with targeted test coverage.Overview
Fixes perps-controller CommonJS consumers that broke on
9.2.1becausets-bridgeinlinedrequire("file:///home/runner/.../mod.ts")from@nktkas/hyperliquid’s.d.tsamd-moduledirectives. A root monorepo yarn patch (viaresolutions) strips those directives so emitted.cjsfiles userequire("@nktkas/hyperliquid"); the package dependency range stays^0.33.1.Analytics and types in
TradingService/TrackingData: optionalorderExecutionLatencyMson the terminal trade event; an extrapartially_filledtrade event when an open fill is smaller than requested; close events report effective leverage (|positionValue| / marginUsed, 1 dp) including TP/SL; batchclosePositionssummary addsnumber_positions_closed;updateMarginemits a failed Risk Management event when the provider returns{ success: false }without throwing;TradeActionadds flip direction literals.Reviewed by Cursor Bugbot for commit 30ea9ed. Bugbot is set up for automated code reviews on this repo. Configure here.