@pear-protocol/hyperliquid-sdk 0.0.66-usdh-1 → 0.0.66-usdh-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +66 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -777,7 +777,21 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
777
777
  case 'allDexsAssetCtxs':
778
778
  {
779
779
  const data = response.data;
780
- const finalAssetContexts = (data.ctxs || []).flatMap(([, ctxs]) => ctxs || []);
780
+ // Filter out vntl and hyna to match perpMetaAssets filtering
781
+ const FILTERED_DEX_PREFIXES = ['vntl', 'hyna'];
782
+ const filtered = (data.ctxs || [])
783
+ .filter(([prefix]) => !FILTERED_DEX_PREFIXES.includes((prefix || '').toLowerCase()))
784
+ .sort((a, b) => {
785
+ // Sort to match perpMetaAssets order: default market first, then alphabetically
786
+ const prefixA = a[0] || '';
787
+ const prefixB = b[0] || '';
788
+ if (prefixA === '' && prefixB !== '')
789
+ return -1;
790
+ if (prefixA !== '' && prefixB === '')
791
+ return 1;
792
+ return prefixA.localeCompare(prefixB);
793
+ });
794
+ const finalAssetContexts = filtered.flatMap(([, ctxs]) => ctxs || []);
781
795
  setFinalAssetContexts(finalAssetContexts);
782
796
  }
783
797
  break;
@@ -1484,19 +1498,11 @@ class TokenMetadataExtractor {
1484
1498
  // No prefix specified - match non-HIP3 asset (no marketPrefix) or first matching asset
1485
1499
  return !asset.marketPrefix;
1486
1500
  });
1487
- // If no exact match found and prefix was specified, try finding the specific market variant
1488
- const finalIndex = universeIndex === -1 && marketPrefix
1489
- ? perpMetaAssets.findIndex((asset) => asset.name === symbol && asset.marketPrefix === marketPrefix)
1490
- : universeIndex;
1491
- // Fallback: if still not found and no prefix, find first matching by name (for backward compatibility)
1492
- const resolvedIndex = finalIndex === -1
1493
- ? perpMetaAssets.findIndex((asset) => asset.name === symbol)
1494
- : finalIndex;
1495
- if (resolvedIndex === -1) {
1501
+ if (universeIndex === -1) {
1496
1502
  return null;
1497
1503
  }
1498
- const universeAsset = perpMetaAssets[resolvedIndex];
1499
- const assetCtx = finalAssetContexts[resolvedIndex];
1504
+ const universeAsset = perpMetaAssets[universeIndex];
1505
+ const assetCtx = finalAssetContexts[universeIndex];
1500
1506
  if (!assetCtx) {
1501
1507
  return null;
1502
1508
  }
@@ -8191,15 +8197,18 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-ui.pearpro
8191
8197
  .then((res) => {
8192
8198
  const assetToMarkets = new Map();
8193
8199
  const marketPrefixes = new Map();
8194
- const cleanedPerpMetas = [];
8195
- const allPerpMetas = [];
8196
8200
  const FILTERED_PREFIXES = ['vntl', 'hyna'];
8201
+ // Group assets by market prefix to match WebSocket flattening order
8202
+ // WebSocket sends in order: "", "flx", "hyna", "vntl", "xyz"
8203
+ const assetsByPrefix = new Map();
8204
+ const allAssetsByPrefix = new Map();
8197
8205
  res.data.forEach((item) => {
8198
8206
  const collateralToken = item.collateralToken === 360 ? 'USDH' : 'USDC';
8199
8207
  item.universe.forEach((asset) => {
8200
8208
  var _a;
8201
8209
  const [maybePrefix, maybeMarket] = asset.name.split(':');
8202
8210
  if (maybeMarket) {
8211
+ // HIP3 asset with market prefix
8203
8212
  const prefix = maybePrefix.toLowerCase();
8204
8213
  const displayName = maybeMarket;
8205
8214
  const fullName = `${prefix}:${displayName}`;
@@ -8219,21 +8228,60 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-ui.pearpro
8219
8228
  marketPrefix: prefix,
8220
8229
  collateralToken,
8221
8230
  };
8222
- allPerpMetas.push(assetWithMeta);
8231
+ // Group by market prefix
8232
+ const allList = allAssetsByPrefix.get(prefix) || [];
8233
+ allList.push(assetWithMeta);
8234
+ allAssetsByPrefix.set(prefix, allList);
8223
8235
  if (!FILTERED_PREFIXES.includes(prefix)) {
8224
- cleanedPerpMetas.push(assetWithMeta);
8236
+ const cleanedList = assetsByPrefix.get(prefix) || [];
8237
+ cleanedList.push(assetWithMeta);
8238
+ assetsByPrefix.set(prefix, cleanedList);
8225
8239
  }
8226
8240
  }
8227
8241
  else {
8242
+ // Default market asset (no prefix)
8228
8243
  const assetWithMeta = {
8229
8244
  ...asset,
8230
8245
  collateralToken,
8231
8246
  };
8232
- cleanedPerpMetas.push(assetWithMeta);
8233
- allPerpMetas.push(assetWithMeta);
8247
+ // Add to default market group ("")
8248
+ const defaultList = assetsByPrefix.get('') || [];
8249
+ defaultList.push(assetWithMeta);
8250
+ assetsByPrefix.set('', defaultList);
8251
+ const allDefaultList = allAssetsByPrefix.get('') || [];
8252
+ allDefaultList.push(assetWithMeta);
8253
+ allAssetsByPrefix.set('', allDefaultList);
8234
8254
  }
8235
8255
  });
8236
8256
  });
8257
+ // Flatten in consistent order: default market first, then HIP3 markets alphabetically
8258
+ // This ensures both REST API and WebSocket data align properly
8259
+ const cleanedPrefixes = Array.from(assetsByPrefix.keys()).sort((a, b) => {
8260
+ // Empty prefix (default market) always comes first
8261
+ if (a === '' && b !== '')
8262
+ return -1;
8263
+ if (a !== '' && b === '')
8264
+ return 1;
8265
+ // HIP3 markets sorted alphabetically
8266
+ return a.localeCompare(b);
8267
+ });
8268
+ const allPrefixes = Array.from(allAssetsByPrefix.keys()).sort((a, b) => {
8269
+ if (a === '' && b !== '')
8270
+ return -1;
8271
+ if (a !== '' && b === '')
8272
+ return 1;
8273
+ return a.localeCompare(b);
8274
+ });
8275
+ const cleanedPerpMetas = [];
8276
+ const allPerpMetas = [];
8277
+ cleanedPrefixes.forEach((prefix) => {
8278
+ const assets = assetsByPrefix.get(prefix) || [];
8279
+ cleanedPerpMetas.push(...assets);
8280
+ });
8281
+ allPrefixes.forEach((prefix) => {
8282
+ const assets = allAssetsByPrefix.get(prefix) || [];
8283
+ allPerpMetas.push(...assets);
8284
+ });
8237
8285
  setHip3Assets(assetToMarkets);
8238
8286
  setHip3MarketPrefixes(marketPrefixes);
8239
8287
  setPerpMetaAssets(cleanedPerpMetas);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.66-usdh-1",
3
+ "version": "0.0.66-usdh-2",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",