@pear-protocol/hyperliquid-sdk 0.0.62 → 0.0.64

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
@@ -411,12 +411,14 @@ interface WebSocketMessage {
411
411
  /**
412
412
  * WebSocket response from HyperLiquid native API
413
413
  */
414
- type HLChannel = "webData3" | "allMids" | "activeAssetData" | "candle";
414
+ type HLChannel = "webData3" | "allMids" | "activeAssetData" | "candle" | "allDexsClearinghouseState" | "allDexsAssetCtxs";
415
415
  interface HLChannelDataMap {
416
416
  webData3: WebData3Response;
417
417
  allMids: WsAllMidsData;
418
418
  activeAssetData: ActiveAssetData;
419
419
  candle: CandleData;
420
+ allDexsClearinghouseState: AllDexsClearinghouseStateData;
421
+ allDexsAssetCtxs: AllDexsAssetCtxsData;
420
422
  }
421
423
  interface WebData3UserState {
422
424
  agentAddress?: string;
@@ -449,6 +451,13 @@ interface WebData3Response {
449
451
  userState: WebData3UserState;
450
452
  perpDexStates: WebData3PerpDexState[];
451
453
  }
454
+ interface AllDexsClearinghouseStateData {
455
+ user: string;
456
+ clearinghouseStates: [string, ClearinghouseState][];
457
+ }
458
+ interface AllDexsAssetCtxsData {
459
+ ctxs: [string, WebData3AssetCtx[]][];
460
+ }
452
461
  interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
453
462
  channel: T;
454
463
  data: HLChannelDataMap[T];
package/dist/index.js CHANGED
@@ -538,11 +538,22 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
538
538
  switch (response.channel) {
539
539
  case 'webData3':
540
540
  const webData3 = response.data;
541
- const finalAssetContexts = webData3.perpDexStates.flatMap((dex) => dex.assetCtxs);
541
+ // finalAssetContexts now sourced from allDexsAssetCtxs channel
542
542
  const finalAtOICaps = webData3.perpDexStates.flatMap((dex) => dex.perpsAtOpenInterestCap);
543
- const aggregatedClearingHouseState = (() => {
544
- const states = webData3.perpDexStates
545
- .map((dex) => dex.clearinghouseState)
543
+ setFinalAtOICaps(finalAtOICaps);
544
+ break;
545
+ case 'allDexsAssetCtxs':
546
+ {
547
+ const data = response.data;
548
+ const finalAssetContexts = (data.ctxs || []).flatMap(([, ctxs]) => ctxs || []);
549
+ setFinalAssetContexts(finalAssetContexts);
550
+ }
551
+ break;
552
+ case 'allDexsClearinghouseState':
553
+ {
554
+ const data = response.data;
555
+ const states = (data.clearinghouseStates || [])
556
+ .map(([, s]) => s)
546
557
  .filter(Boolean);
547
558
  const sum = (values) => values.reduce((acc, v) => acc + (parseFloat(v || '0') || 0), 0);
548
559
  const toStr = (n) => (Number.isFinite(n) ? n.toString() : '0');
@@ -562,7 +573,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
562
573
  };
563
574
  const withdrawable = toStr(sum(states.map((s) => s.withdrawable)));
564
575
  const time = Math.max(0, ...states.map((s) => s.time || 0));
565
- return {
576
+ const aggregatedClearingHouseState = {
566
577
  assetPositions,
567
578
  crossMaintenanceMarginUsed,
568
579
  crossMarginSummary,
@@ -570,10 +581,8 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
570
581
  time,
571
582
  withdrawable,
572
583
  };
573
- })();
574
- setFinalAssetContexts(finalAssetContexts);
575
- setFinalAtOICaps(finalAtOICaps);
576
- setAggregatedClearingHouseState(aggregatedClearingHouseState);
584
+ setAggregatedClearingHouseState(aggregatedClearingHouseState);
585
+ }
577
586
  break;
578
587
  case 'allMids':
579
588
  {
@@ -710,8 +719,15 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
710
719
  },
711
720
  };
712
721
  sendJsonMessage(unsubscribeMessage);
722
+ const unsubscribeAllDexsClearinghouseState = {
723
+ method: 'unsubscribe',
724
+ subscription: {
725
+ type: 'allDexsClearinghouseState',
726
+ user: subscribedAddress,
727
+ },
728
+ };
729
+ sendJsonMessage(unsubscribeAllDexsClearinghouseState);
713
730
  }
714
- // Subscribe to webData3 with new address
715
731
  const subscribeWebData3 = {
716
732
  method: 'subscribe',
717
733
  subscription: {
@@ -719,6 +735,14 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
719
735
  user: userAddress,
720
736
  },
721
737
  };
738
+ // Subscribe to allDexsClearinghouseState with the same payload as webData3
739
+ const subscribeAllDexsClearinghouseState = {
740
+ method: 'subscribe',
741
+ subscription: {
742
+ type: 'allDexsClearinghouseState',
743
+ user: userAddress,
744
+ },
745
+ };
722
746
  // Subscribe to allMids
723
747
  const subscribeAllMids = {
724
748
  method: 'subscribe',
@@ -727,8 +751,17 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
727
751
  dex: 'ALL_DEXS',
728
752
  },
729
753
  };
754
+ // Subscribe to allDexsAssetCtxs (no payload params, global feed)
755
+ const subscribeAllDexsAssetCtxs = {
756
+ method: 'subscribe',
757
+ subscription: {
758
+ type: 'allDexsAssetCtxs',
759
+ },
760
+ };
730
761
  sendJsonMessage(subscribeWebData3);
762
+ sendJsonMessage(subscribeAllDexsClearinghouseState);
731
763
  sendJsonMessage(subscribeAllMids);
764
+ sendJsonMessage(subscribeAllDexsAssetCtxs);
732
765
  setSubscribedAddress(userAddress);
733
766
  // Clear previous data when address changes
734
767
  if (subscribedAddress && subscribedAddress !== userAddress) {
package/dist/types.d.ts CHANGED
@@ -441,12 +441,14 @@ export interface WebSocketMessage {
441
441
  /**
442
442
  * WebSocket response from HyperLiquid native API
443
443
  */
444
- export type HLChannel = "webData3" | "allMids" | "activeAssetData" | "candle";
444
+ export type HLChannel = "webData3" | "allMids" | "activeAssetData" | "candle" | "allDexsClearinghouseState" | "allDexsAssetCtxs";
445
445
  export interface HLChannelDataMap {
446
446
  webData3: WebData3Response;
447
447
  allMids: WsAllMidsData;
448
448
  activeAssetData: ActiveAssetData;
449
449
  candle: CandleData;
450
+ allDexsClearinghouseState: AllDexsClearinghouseStateData;
451
+ allDexsAssetCtxs: AllDexsAssetCtxsData;
450
452
  }
451
453
  export interface WebData3UserState {
452
454
  agentAddress?: string;
@@ -479,6 +481,13 @@ export interface WebData3Response {
479
481
  userState: WebData3UserState;
480
482
  perpDexStates: WebData3PerpDexState[];
481
483
  }
484
+ export interface AllDexsClearinghouseStateData {
485
+ user: string;
486
+ clearinghouseStates: [string, ClearinghouseState][];
487
+ }
488
+ export interface AllDexsAssetCtxsData {
489
+ ctxs: [string, WebData3AssetCtx[]][];
490
+ }
482
491
  export interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
483
492
  channel: T;
484
493
  data: HLChannelDataMap[T];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",