fix: include hip3 dexes when building position map on init cp-7.61.6#24293
fix: include hip3 dexes when building position map on init cp-7.61.6#24293
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe changes are isolated to the HyperLiquidSubscriptionService within the Perps (Perpetuals trading) module. The modifications add DEX discovery synchronization for HIP-3 support, ensuring that subscriptions wait for DEX discovery before creating per-DEX subscriptions, and that all DEXs send initial data before notifying subscribers. Key observations:
This is a well-scoped change to the Perpetuals trading feature that should only require SmokePerps tests to validate. |
| this.dexAccountCache.set(cacheKey, accountState); | ||
|
|
||
| // Mark this DEX as initialized (has sent first data) | ||
| this.initializedDexs.add(cacheKey); |
There was a problem hiding this comment.
Initial positions may briefly lack TP/SL data
Low Severity
Both clearinghouseState and openOrders callbacks add the same DEX to initializedDexs, but only one callback needs to fire for a DEX to be considered "initialized." If clearinghouseState fires before openOrders, the synchronization check passes and subscribers receive positions without TP/SL data (since orders haven't been cached yet at line 1269). A subsequent openOrders callback will update the data, causing a brief flicker where positions appear without their take-profit/stop-loss values on initial load.
Additional Locations (1)
There was a problem hiding this comment.
I think this is acceptable, I haven't been able to reproduce this, and we don't show TP/SL data on the main PerpsHome page anyway. We can circle back on this after if it becomes an issue but I don't think it should block this hotifx
There was a problem hiding this comment.
The edge cases are there likely due to the complexity of this service. It may be worth splitting it into multiple services or simplifying it sometime later
|



Description
After the HIP-3 refactor that replaced webData3 with individual clearinghouseState/openOrders subscriptions, HIP-3 market positions were not showing up on initial load. Additionally, when they did appear (e.g., after switching accounts), there was a ~1 second delay between crypto perps and HIP-3 positions appearing.
Root Cause
A race condition between subscription creation and DEX discovery:
enabledDexssubscribeToPositions() creates subscriptions using empty
enabledDexs(main DEX only)buildAssetMapping()updateFeatureFlags()is called with discovered DEXs, but subscriptions already exist for main DEX onlyWhy switching accounts worked: Account switching triggers
reconnectWithNewContext()which performs a full reinitialization. During reconnection,buildAssetMapping()(DEX discovery) completes beforecreateUserDataSubscription()is called, soenabledDexsis already populated and HIP-3 subscriptions are correctly created.Solution
Added
dexDiscoveryPromiseanddexDiscoveryResolverfieldscreateUserDataSubscription()waits for DEX discovery when HIP-3 is enabled butenabledDexsis emptyupdateFeatureFlags()resolves the promise when DEXs are discovered5-second timeout prevents indefinite waiting
Added
expectedDexsandinitializedDexstracking setsaggregateAndNotifySubscribers()waits for ALL expected DEXs to send initial data before notifyingEnsures crypto and HIP-3 positions appear simultaneously
Modified aggregation to always show main DEX (crypto perps) first, then HIP-3 positions
Error handling:
expectedDexsso they don't block notifications for other DEXsensureClearinghouseStateSubscriptionandensureOpenOrdersSubscriptionmark DEXs as initializeChanges to
HyperLiquidSubscriptionService.ts:Changelog
CHANGELOG entry: Fixes bug where hip3 positions were not loaded on initial PerpsContext load
Related issues
Fixes:
Manual testing steps
Verified crypto and HIP-3 positions appear simultaneously on initial load
Verified position ordering (crypto first, HIP-3 second)
Verified account switching still works correctly
Verified that TP/SL still works as intended
Screenshots/Recordings
Screen.Recording.2026-01-07.at.11.26.25.AM.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Improves HIP-3 multi-DEX handling and subscription lifecycle to deliver consistent, aggregated user data.
waitForDexDiscovery) and resolves pending waits inupdateFeatureFlagsexpectedDexs/initializedDexsto delay notifications until all DEXs send initial data; orders aggregation preserves main DEX firstclearinghouseStateandopenOrderssubscriptions upon feature-flag updates if user-data subscribers existsubscribeTo...waits for DEX discovery before creating HIP-3 subscriptions; error paths avoid blocking other DEX updatesclearAllresets DEX trackingWritten by Cursor Bugbot for commit 67f8a9a. This will update automatically on new commits. Configure here.