Skip to content

chore(runway): cherry-pick fix(perps): add spotMeta caching to reduce API calls on HIP-3 markets#25511

Merged
joaoloureirop merged 3 commits intorelease/7.63.0from
cherry-pick-7-63-0-b5c386c
Feb 2, 2026
Merged

chore(runway): cherry-pick fix(perps): add spotMeta caching to reduce API calls on HIP-3 markets#25511
joaoloureirop merged 3 commits intorelease/7.63.0from
cherry-pick-7-63-0-b5c386c

Conversation

@runway-github
Copy link
Copy Markdown
Contributor

@runway-github runway-github bot commented Feb 2, 2026

Description

fix(perps): add spotMeta caching to reduce API calls on HIP-3
markets

This PR adds session-based caching for HyperLiquid's global spotMeta
endpoint to avoid redundant API calls during HIP-3 operations.

Context

Following a rate limiting incident where excessive API calls triggered
HyperLiquid's rate limits (2000 msg/min), this is a defensive
improvement to reduce unnecessary network requests.

Problem

The spotMeta API (which returns token metadata like USDC/USDH indices)
was being called multiple times per trading session:

  • getUsdcTokenId() - called during transfers
  • isUsdhCollateralDex() - called to check collateral type
  • swapUsdcToUsdh() - called during HIP-3 USDH swaps

Each call was making a fresh API request, even though the data (token
indices) doesn't change during a session.

Solution

  • Added cachedSpotMeta property for session-based caching (no TTL -
    token indices are stable)
  • Added getCachedSpotMeta() method that returns cached data or fetches
    once
  • Pre-fetch spotMeta in ensureReadyForTrading() when HIP-3 is enabled
    (non-blocking)
  • Cache invalidated on disconnect() to ensure fresh state on
    reconnect/account switch

Design Decisions

  • Global cache (not per-DEX): spotMeta is a global endpoint
    returning all tokens
  • Session-based (no TTL): Token indices don't change during a
    session
  • Graceful fallback: If pre-fetch fails, methods fetch on-demand
  • Follows existing patterns: getCachedMeta(), getCachedPerpDexs()

Changelog

CHANGELOG entry: Fixed excessive API calls on HIP-3 markets by caching
spot metadata

Related issues

Fixes: N/A (Defensive improvement following rate limiting incident)

Manual testing steps

Feature: SpotMeta caching for HIP-3 operations

  Scenario: User places order on HIP-3 DEX (SILVER)
    Given user has connected wallet with USDC balance
    And user is on a HIP-3 enabled DEX (e.g., SILVER)

    When user places an order
    Then order should succeed
    And spotMeta API should only be called once per session (check debug logs)

  Scenario: User disconnects and reconnects
    Given user has placed orders (spotMeta is cached)

    When user disconnects wallet
    And user reconnects wallet
    Then spotMeta cache should be cleared
    And next HIP-3 operation should fetch fresh spotMeta

Screenshots/Recordings

N/A - Internal optimization, no UI changes

Before

Multiple spotMeta API calls per session (one per HIP-3 operation)

After

Single spotMeta API call per session, cached for subsequent operations

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 core Perps trading/connectivity paths (HIP-3 collateral checks, transfers, connection lifecycle), so caching or error-wrapping regressions could impact order placement or diagnostics despite being largely additive and well-tested.

Overview
Reduces redundant HyperLiquid API calls by adding a session-scoped spotMeta cache in HyperLiquidProvider and routing HIP-3 collateral checks/USDC↔USDH flows through it, with cache cleared on disconnect.

Standardizes error handling by expanding ensureError (better undefined/null handling + optional context) and updating Perps connection/provider/stream logging and Sentry capture to use it.

Introduces a global singleton signing readiness cache (TradingReadinessCache/PerpsSigningCache) with in-flight locks to prevent repeated signing prompts, plus comprehensive unit tests and updated HyperLiquid provider test mocks/types (SpotMetaResponse).

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

b5c386c

This commit manually ports the changes from commit b5c386c to reduce
API calls during HIP-3 operations by caching spotMeta responses.

Changes:
- Added session-based `cachedSpotMeta` cache in HyperLiquidProvider
- Added `getCachedSpotMeta()` method for centralized cache access
- Updated `getUsdcTokenId()`, `isUsdhCollateralDex()`, `swapUsdcToUsdh()`
  to use cached spotMeta instead of making fresh API calls
- Cache invalidated on `disconnect()` to ensure fresh state on reconnect
- Extended `ensureError()` to handle undefined/null with optional context
- Standardized error handling across perps providers to use ensureError
- Added SpotMetaResponse type to hyperliquid-types.ts
- Added TradingReadinessCache service for future signing state management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@runway-github runway-github bot requested a review from a team as a code owner February 2, 2026 11:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2026

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-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Feb 2, 2026
@joaoloureirop joaoloureirop added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Feb 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2026

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - base branch is not main (base: release/7.63.0)

All E2E tests pre-selected.

View GitHub Actions results

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Feb 2, 2026

@joaoloureirop joaoloureirop merged commit e2ca72f into release/7.63.0 Feb 2, 2026
90 of 91 checks passed
@joaoloureirop joaoloureirop deleted the cherry-pick-7-63-0-b5c386c branch February 2, 2026 14:47
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2026
@metamaskbot metamaskbot added the release-7.63.0 Issue or pull request that will be included in release 7.63.0 label Feb 6, 2026
@metamaskbot
Copy link
Copy Markdown
Collaborator

No release label on PR. Adding release label release-7.63.0 on PR, as PR was cherry-picked in branch 7.63.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.63.0 Issue or pull request that will be included in release 7.63.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants