Skip to content

fix(perps): fix HIP-3 asset ID lookup failure from dual-cache desync cp-7.70.1#27854

Merged
abretonc7s merged 1 commit into
mainfrom
fix/perps/cachepoisoning-perps-tab
Mar 24, 2026
Merged

fix(perps): fix HIP-3 asset ID lookup failure from dual-cache desync cp-7.70.1#27854
abretonc7s merged 1 commit into
mainfrom
fix/perps/cachepoisoning-perps-tab

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fix HIP-3 asset ID lookup failure ("Asset ID not found for xyz:BRENTOIL") that blocked trading on HIP-3 markets when navigating via the old Perps tab layout.

Root cause: Dual-cache desync between #cachedValidatedDexs (string DEX names) and #cachedAllPerpDexs (raw API objects for perpDexIndex computation). The standalone preload path (#getStandaloneValidatedDexs) populated one cache but not the other. When #buildAssetMapping later ran, it found "xyz" in dexsToMap but couldn't compute its perpDexIndex because #cachedAllPerpDexs was null.

Why old Perps tab vs new Homepage Sections: Both layouts sit inside Wallet/index.tsx, which calls startMarketDataPreload() on mount. This fires standalone HTTP calls that populate #cachedValidatedDexs but not #cachedAllPerpDexs.

  • New homepage sections: PerpsSectionWithProvider mounts immediately. Stream hooks fire ensureReady() before or concurrently with the standalone preload. Since #cachedValidatedDexs is often still null, fetchValidatedDexsInternal runs fresh and sets both caches correctly.
  • Old tab layout: The Perps tab doesn't mount until the user taps it. By that time, startMarketDataPreload() has already completed → #cachedValidatedDexs is populated by standalone. When the tab mounts → getValidatedDexs()cache hitfetchValidatedDexsInternal is never called → #cachedAllPerpDexs stays null → buildAssetMapping can't find "xyz".

Changes (1 file, 3 sites):

  1. Root cause fix: #getStandaloneValidatedDexs now sets this.#cachedAllPerpDexs = allDexs after a successful perpDexs() call, keeping both caches in sync.
  2. Cache poisoning fix: Removed this.#cachedAllPerpDexs = this.#cachedAllPerpDexs ?? [null] from the catch block in #buildAssetMapping.
  3. Cache poisoning fix: Replaced persistent if (!cache) { cache = [null] } with local const allPerpDexs = cache ?? [null] — consumers read the cache, only the owner writes it.

Changelog

CHANGELOG entry: Fixed a bug where closing positions on HIP-3 markets (e.g., xyz:BRENTOIL) failed with "Asset ID not found" when navigating via the Perps tab

Related issues

Fixes: HIP-3 asset ID lookup failure on old Perps tab layout

Manual testing steps

Feature: HIP-3 position management via Perps tab

  Scenario: user closes a HIP-3 position from the old Perps tab
    Given user has an open position on a HIP-3 market (e.g., xyz:BRENTOIL)
    And user is using the old tab layout (homepage redesign v1 disabled)

    When user navigates to the Perps tab
    And user taps close on the xyz:BRENTOIL position
    Then the position closes successfully without "Asset ID not found" error

  Scenario: user opens a HIP-3 position from the old Perps tab
    Given user is on the Perps tab (old layout)

    When user navigates to xyz:BRENTOIL market and places a market order
    Then the order executes successfully with correct asset ID routing

Screenshots/Recordings

Before

Metro logs show the desync:

getValidatedDexs CACHE HIT {"cachedAllNull": true, "dexs": [null, "xyz"]}
buildAssetMapping state  {"allPerpDexsLen": 1, "cachedAllNull": true}
Could not find perpDexIndex for DEX xyz
Asset ID not found for xyz:BRENTOIL

After

Metro logs show both caches in sync:

buildAssetMapping state {"allPerpDexsLen": 8, "cachedAllNull": false, "dexsToMap": [null, "xyz"]}
Asset map state at order time {"assetExistsInMap": true, "hip3AssetsCount": 54, "totalAssetsInMap": 283}
Resolved DEX-specific asset ID {"assetId": 110049, "coin": "xyz:BRENTOIL"}
usePerpsClosePosition: Close result {"success": true, "orderId": "359617825254"}

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches HIP-3 market routing/asset-ID mapping in HyperLiquidProvider, so a mistake could break trading on some perps markets; scope is small and localized to cache population/fallback behavior.

Overview
Fixes a HIP-3 asset mapping failure where #cachedValidatedDexs could be populated via the standalone preload path while #cachedAllPerpDexs stayed null, leading to missing perpDexIndex during #buildAssetMapping.

#getStandaloneValidatedDexs() now also populates #cachedAllPerpDexs after a successful perpDexs() call, and #buildAssetMapping() no longer “poisons” the shared cache with a persistent [null] fallback (it uses a local fallback instead).

Written by Cursor Bugbot for commit c925609. This will update automatically on new commits. Configure here.

The standalone preload path (#getStandaloneValidatedDexs) populated
#cachedValidatedDexs but not #cachedAllPerpDexs. When the full init
later hit the cache, buildAssetMapping couldn't compute perpDexIndex
for HIP-3 DEXs, causing "Asset ID not found for xyz:BRENTOIL".

- Populate #cachedAllPerpDexs in standalone path
- Remove cache poisoning writes from #buildAssetMapping
- Use local fallback instead of persistent [null] write
@abretonc7s abretonc7s requested a review from a team as a code owner March 24, 2026 11:07
@github-actions

Copy link
Copy Markdown
Contributor

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.

@metamaskbot metamaskbot added the team-perps Perps team label Mar 24, 2026
@abretonc7s abretonc7s enabled auto-merge March 24, 2026 11:08
@abretonc7s abretonc7s disabled auto-merge March 24, 2026 11:08
@github-actions github-actions Bot added size-S risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The change is a targeted bug fix in HyperLiquidProvider.ts affecting DEX caching logic:

  1. Bug fix in buildAssetMapping: Removes incorrect writes of [null] into #cachedAllPerpDexs during error fallback paths. Previously, writing [null] into the cache would prevent subsequent callers from retrying perpDexs(). Now uses a local-only fallback const allPerpDexs = this.#cachedAllPerpDexs ?? [null] without polluting the cache.

  2. Bug fix in #fetchValidatedDexsInternal: Adds this.#cachedAllPerpDexs = allDexs to properly populate the cache. Without this, buildAssetMapping couldn't compute perpDexIndex for HIP-3 DEXes, causing "Could not find perpDexIndex for DEX xyz" failures.

This directly impacts the Perps Add Funds flow and DEX asset mapping. The fix is isolated to the HyperLiquidProvider and doesn't touch shared infrastructure.

Tags selected:

  • SmokePerps: Primary tag — directly tests perps Add Funds flow and balance verification which rely on the DEX mapping logic being fixed
  • SmokeWalletPlatform: Required per SmokePerps description — Perps is a section inside the Trending tab
  • SmokeConfirmations: Required per SmokePerps description — Add Funds deposits are on-chain transactions requiring confirmations

Performance Test Selection:
The bug fix changes DEX caching behavior in HyperLiquidProvider — specifically how #cachedAllPerpDexs is populated and used. This cache is used during asset mapping rebuilds which could affect the performance of perps market loading and the Add Funds flow. Running @PerformancePreps ensures the fix doesn't introduce any performance regression in the perps flow.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@aganglada aganglada changed the title fix(perps): fix HIP-3 asset ID lookup failure from dual-cache desync fix(perps): fix HIP-3 asset ID lookup failure from dual-cache desync cp-7.70.1 Mar 24, 2026

@aganglada aganglada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated

@abretonc7s abretonc7s added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 2898ec8 Mar 24, 2026
123 checks passed
@abretonc7s abretonc7s deleted the fix/perps/cachepoisoning-perps-tab branch March 24, 2026 12:11
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-S team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants