@pear-protocol/hyperliquid-sdk 0.1.3 → 0.1.5

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.
package/dist/index.d.ts CHANGED
@@ -1068,6 +1068,7 @@ interface TokenHistoricalPriceData {
1068
1068
  candles: CandleData[];
1069
1069
  oldestTime: number | null;
1070
1070
  latestTime: number | null;
1071
+ requestedRanges: HistoricalRange[];
1071
1072
  }
1072
1073
  interface HistoricalPriceDataState {
1073
1074
  historicalPriceData: Record<string, TokenHistoricalPriceData>;
package/dist/index.js CHANGED
@@ -1453,8 +1453,9 @@ const getAssetByName = (tokenMetadata, symbol) => {
1453
1453
  * Hook to access webData
1454
1454
  */
1455
1455
  const useMarket = () => {
1456
+ const supportedMarkets = ['USDT', 'USDT0', 'USDC', 'USDH'];
1456
1457
  const tokenMetadata = useHyperliquidData((state) => state.tokenMetadata);
1457
- const allTokenMetadata = useMemo(() => Object.values(tokenMetadata).filter((metadata) => Boolean(metadata)), [tokenMetadata]);
1458
+ const allTokenMetadata = useMemo(() => Object.values(tokenMetadata).filter((metadata) => Boolean(metadata)).filter((token) => { var _a; return supportedMarkets.includes((_a = token.collateralToken) !== null && _a !== void 0 ? _a : ''); }), [tokenMetadata]);
1458
1459
  const getAssetByName$1 = useCallback((symbol) => getAssetByName(tokenMetadata, symbol), [tokenMetadata]);
1459
1460
  return { allTokenMetadata, getAssetByName: getAssetByName$1 };
1460
1461
  };
@@ -1818,6 +1819,22 @@ const getIntervalSeconds = (interval) => {
1818
1819
  default: return 60;
1819
1820
  }
1820
1821
  };
1822
+ /**
1823
+ * Merges overlapping or adjacent ranges to prevent unbounded growth
1824
+ */
1825
+ const mergeRanges = (ranges, newRange) => {
1826
+ const all = [...ranges, newRange].sort((a, b) => a.start - b.start);
1827
+ const merged = [];
1828
+ for (const r of all) {
1829
+ if (merged.length === 0 || r.start > merged[merged.length - 1].end) {
1830
+ merged.push({ start: r.start, end: r.end });
1831
+ }
1832
+ else {
1833
+ merged[merged.length - 1].end = Math.max(merged[merged.length - 1].end, r.end);
1834
+ }
1835
+ }
1836
+ return merged;
1837
+ };
1821
1838
  const useHistoricalPriceDataStore = create((set, get) => ({
1822
1839
  historicalPriceData: {},
1823
1840
  loadingTokens: new Set(),
@@ -1836,7 +1853,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
1836
1853
  interval,
1837
1854
  candles: sortedCandles,
1838
1855
  oldestTime: sortedCandles.length > 0 ? sortedCandles[0].t : null,
1839
- latestTime: sortedCandles.length > 0 ? sortedCandles[sortedCandles.length - 1].t : null
1856
+ latestTime: sortedCandles.length > 0 ? sortedCandles[sortedCandles.length - 1].t : null,
1857
+ requestedRanges: [range]
1840
1858
  }
1841
1859
  }
1842
1860
  };
@@ -1848,6 +1866,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
1848
1866
  // Update time pointers
1849
1867
  const oldestTime = mergedCandles.length > 0 ? mergedCandles[0].t : null;
1850
1868
  const latestTime = mergedCandles.length > 0 ? mergedCandles[mergedCandles.length - 1].t : null;
1869
+ // Merge requested ranges
1870
+ const mergedRanges = mergeRanges(existing.requestedRanges || [], range);
1851
1871
  return {
1852
1872
  historicalPriceData: {
1853
1873
  ...state.historicalPriceData,
@@ -1855,7 +1875,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
1855
1875
  ...existing,
1856
1876
  candles: mergedCandles,
1857
1877
  oldestTime,
1858
- latestTime
1878
+ latestTime,
1879
+ requestedRanges: mergedRanges
1859
1880
  }
1860
1881
  }
1861
1882
  };
@@ -1865,7 +1886,17 @@ const useHistoricalPriceDataStore = create((set, get) => ({
1865
1886
  const { historicalPriceData } = get();
1866
1887
  const key = createKey(symbol, interval);
1867
1888
  const tokenData = historicalPriceData[key];
1868
- if (!tokenData || tokenData.oldestTime === null || tokenData.latestTime === null)
1889
+ if (!tokenData)
1890
+ return false;
1891
+ // Check if we've already attempted to fetch this range (prevents infinite loops for tokens with no data)
1892
+ const requestedRanges = tokenData.requestedRanges || [];
1893
+ for (const range of requestedRanges) {
1894
+ if (range.start <= startTime && range.end >= endTime) {
1895
+ return true; // Already attempted this fetch
1896
+ }
1897
+ }
1898
+ // Fallback: check actual data coverage
1899
+ if (tokenData.oldestTime === null || tokenData.latestTime === null)
1869
1900
  return false;
1870
1901
  const intervalMilisecond = getIntervalSeconds(interval) * 1000;
1871
1902
  const hasStartCoverage = tokenData.oldestTime <= startTime;
@@ -9,6 +9,7 @@ interface TokenHistoricalPriceData {
9
9
  candles: CandleData[];
10
10
  oldestTime: number | null;
11
11
  latestTime: number | null;
12
+ requestedRanges: HistoricalRange[];
12
13
  }
13
14
  interface HistoricalPriceDataState {
14
15
  historicalPriceData: Record<string, TokenHistoricalPriceData>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",