Skip to content

fix: Handle panics when metadata references indices beyond array length#37

Open
0xikalgo wants to merge 1 commit intoinfinitefield:mainfrom
0xikalgo:fix/spot-panic
Open

fix: Handle panics when metadata references indices beyond array length#37
0xikalgo wants to merge 1 commit intoinfinitefield:mainfrom
0xikalgo:fix/spot-panic

Conversation

@0xikalgo
Copy link

@0xikalgo 0xikalgo commented Mar 17, 2026

Summary

The testnet API returns market metadata referencing token indices that exceed the token array bounds:

$ curl -s -X POST https://api.hyperliquid-testnet.xyz/info
   \                                                        
      -H 'Content-Type: application/json' \                 
      -d '{"type": "spotMeta"}' | jq '.tokens | length'     
1580   
                                                  
$ curl -s -X POST https://api.hyperliquid-testnet.xyz/info
   \                                                        
      -H 'Content-Type: application/json' \                 
      -d '{"type": "spotMeta"}' | jq '[.universe[].tokens[]]
   | max'                                                   
1827     

Markets like @1455 reference token index 1583, which doesn't exist in the 1580-element token array.

  • Replace expect() with context() in spot_markets() when looking up base/quote tokens
  • Replace direct array indexing with .get().context() in perp_markets() for collateral token lookup

@0xikalgo 0xikalgo marked this pull request as draft March 17, 2026 02:30
@0xikalgo 0xikalgo marked this pull request as ready for review March 17, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant