@pear-protocol/hyperliquid-sdk 0.0.73 → 0.0.74

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 +27 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1514,6 +1514,20 @@ const useWebData = () => {
1514
1514
  };
1515
1515
  };
1516
1516
 
1517
+ /**
1518
+ * Check if two symbols match, handling kPEPE/KPEPE variations
1519
+ * Returns true if symbols match (case-insensitive for k-prefix tokens)
1520
+ */
1521
+ function symbolsMatch(assetName, searchSymbol) {
1522
+ // Exact match
1523
+ if (assetName === searchSymbol)
1524
+ return true;
1525
+ // Try case-insensitive match for k-prefix tokens (kPEPE vs KPEPE)
1526
+ if (assetName.toUpperCase() === searchSymbol.toUpperCase()) {
1527
+ return true;
1528
+ }
1529
+ return false;
1530
+ }
1517
1531
  /**
1518
1532
  * Extracts token metadata from aggregated WebData3 contexts and AllMids data
1519
1533
  */
@@ -1534,8 +1548,9 @@ class TokenMetadataExtractor {
1534
1548
  }
1535
1549
  // Find token index in aggregated universe
1536
1550
  // For HIP3 assets, match both name AND marketPrefix
1551
+ // Uses symbolsMatch to handle kPEPE/KPEPE case variations
1537
1552
  const universeIndex = perpMetaAssets.findIndex((asset) => {
1538
- if (asset.name !== symbol)
1553
+ if (!symbolsMatch(asset.name, symbol))
1539
1554
  return false;
1540
1555
  // If marketPrefix is specified, match it; otherwise match assets without prefix
1541
1556
  if (marketPrefix) {
@@ -1554,15 +1569,20 @@ class TokenMetadataExtractor {
1554
1569
  }
1555
1570
  // Get current price - prefer assetCtx.midPx as it's already index-matched,
1556
1571
  // fall back to allMids lookup if midPx is null
1557
- const prefixedKeyColon = marketPrefix ? `${marketPrefix}:${symbol}` : null;
1572
+ const actualSymbol = universeAsset.name; // Use actual symbol from universe (handles kPEPE vs KPEPE)
1573
+ const prefixedKeyColon = marketPrefix
1574
+ ? `${marketPrefix}:${actualSymbol}`
1575
+ : null;
1558
1576
  let currentPrice = 0;
1559
1577
  // Primary source: assetCtx.midPx (already properly indexed)
1560
1578
  if (assetCtx.midPx) {
1561
1579
  currentPrice = parseFloat(assetCtx.midPx);
1562
1580
  }
1563
1581
  // Fallback: allMids lookup with multiple key formats for HIP3 markets
1582
+ // Try actual symbol from universe first, then input symbol
1564
1583
  if (!currentPrice || isNaN(currentPrice)) {
1565
1584
  const currentPriceStr = (prefixedKeyColon && allMids.mids[prefixedKeyColon]) ||
1585
+ allMids.mids[actualSymbol] ||
1566
1586
  allMids.mids[symbol];
1567
1587
  currentPrice = currentPriceStr ? parseFloat(currentPriceStr) : 0;
1568
1588
  }
@@ -1576,10 +1596,12 @@ class TokenMetadataExtractor {
1576
1596
  const markPrice = parseFloat(assetCtx.markPx);
1577
1597
  const oraclePrice = parseFloat(assetCtx.oraclePx);
1578
1598
  // Extract leverage info from activeAssetData if available
1579
- // Try prefixed key first (e.g., "xyz:TSLA"), then fall back to plain symbol
1599
+ // Try prefixed key first (e.g., "xyz:TSLA"), then actual symbol, then input symbol
1580
1600
  const activeDataKey = prefixedKeyColon && (activeAssetData === null || activeAssetData === void 0 ? void 0 : activeAssetData[prefixedKeyColon])
1581
1601
  ? prefixedKeyColon
1582
- : symbol;
1602
+ : (activeAssetData === null || activeAssetData === void 0 ? void 0 : activeAssetData[actualSymbol])
1603
+ ? actualSymbol
1604
+ : symbol;
1583
1605
  const tokenActiveData = activeAssetData === null || activeAssetData === void 0 ? void 0 : activeAssetData[activeDataKey];
1584
1606
  const leverage = tokenActiveData === null || tokenActiveData === void 0 ? void 0 : tokenActiveData.leverage;
1585
1607
  const maxTradeSzs = tokenActiveData === null || tokenActiveData === void 0 ? void 0 : tokenActiveData.maxTradeSzs;
@@ -1631,7 +1653,7 @@ class TokenMetadataExtractor {
1631
1653
  static isTokenAvailable(symbol, perpMetaAssets) {
1632
1654
  if (!perpMetaAssets)
1633
1655
  return false;
1634
- return perpMetaAssets.some((asset) => asset.name === symbol);
1656
+ return perpMetaAssets.some((asset) => symbolsMatch(asset.name, symbol));
1635
1657
  }
1636
1658
  }
1637
1659
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.73",
3
+ "version": "0.0.74",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",