fix(perps): add spotMeta caching to reduce API calls on HIP-3 markets cp-7.63.0 cp-7.64.0#25493
fix(perps): add spotMeta caching to reduce API calls on HIP-3 markets cp-7.63.0 cp-7.64.0#25493abretonc7s merged 3 commits intomainfrom
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. |
QA Testing Performed ✅Environment
Test 1: SpotMeta Caching - Single API Call Per Session ✅Steps:
Test 2: Cache Invalidation on Disconnect ✅Steps:
Test 3: Account Switch - Cache Cleared ✅Steps:
Test 4: Graceful Fallback - Pre-fetch Failure ✅Steps:
Test 5: Rate Limit Protection ✅Steps:
Expected: No rate limit errors, spotMeta cached Network Request Comparison
Edge Cases Tested
Code Review Notes
ConclusionAll test scenarios passed. The caching implementation correctly reduces API calls while maintaining data freshness on reconnection/account switch. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Only Performance Test Selection: |
|


Description
fix(perps): add spotMeta caching to reduce API calls on HIP-3 markets
This PR adds session-based caching for HyperLiquid's global
spotMetaendpoint 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
spotMetaAPI (which returns token metadata like USDC/USDH indices) was being called multiple times per trading session:getUsdcTokenId()- called during transfersisUsdhCollateralDex()- called to check collateral typeswapUsdcToUsdh()- called during HIP-3 USDH swapsEach call was making a fresh API request, even though the data (token indices) doesn't change during a session.
Solution
cachedSpotMetaproperty for session-based caching (no TTL - token indices are stable)getCachedSpotMeta()method that returns cached data or fetches onceensureReadyForTrading()when HIP-3 is enabled (non-blocking)disconnect()to ensure fresh state on reconnect/account switchDesign Decisions
spotMetais a global endpoint returning all tokensgetCachedMeta(),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
Screenshots/Recordings
N/A - Internal optimization, no UI changes
Before
Multiple
spotMetaAPI calls per session (one per HIP-3 operation)After
Single
spotMetaAPI call per session, cached for subsequent operationsPre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches perps trading setup and HIP-3 collateral/token resolution by introducing session-cached
spotMeta; incorrect caching or cache invalidation could affect order/transfer flows, though it falls back to on-demand fetch and clears on disconnect.Overview
Reduces HyperLiquid rate-limit pressure on HIP-3 flows by adding a session-level
spotMetacache inHyperLiquidProvider, prefetching it duringensureReadyForTrading(), reusing it in USDC/USDH collateral checks and swaps, and clearing it on disconnect.Standardizes error handling across perps controllers/providers by extending
ensureErrorwith optional context (including better messages fornull/undefined) and replacing ad-hocinstanceof Errorchecks in connection, streaming, deposit/testnet toggle, and provider operations; updates related tests and types (SpotMetaResponse).Written by Cursor Bugbot for commit 3ee4cb2. This will update automatically on new commits. Configure here.