@hyperix/hooks 0.1.25 → 0.2.0

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 (55) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/lib/symbol-converter.d.ts +1 -1
  4. package/dist/lib/symbol-converter.js +14 -10
  5. package/dist/use-active-asset-data.d.ts +1 -1
  6. package/dist/use-all-dexs-asset-ctxs.d.ts +1 -1
  7. package/dist/use-all-dexs-clearing-house-state.d.ts +1 -1
  8. package/dist/use-all-mids.d.ts +1 -1
  9. package/dist/use-all-perp-metas.d.ts +4 -2
  10. package/dist/use-all-perp-metas.js +1 -1
  11. package/dist/use-historical-orders.d.ts +1 -1
  12. package/dist/use-historical-orders.js +2 -1
  13. package/dist/use-l2-book.js +1 -1
  14. package/dist/use-max-builder-fee.d.ts +1 -1
  15. package/dist/use-max-builder-fee.js +1 -1
  16. package/dist/use-mid.js +16 -2
  17. package/dist/use-open-orders.d.ts +1 -1
  18. package/dist/use-open-orders.js +1 -1
  19. package/dist/use-order-history.js +1 -1
  20. package/dist/use-perp-market.js +1 -1
  21. package/dist/use-perp-markets.js +15 -4
  22. package/dist/use-portfolio.d.ts +5 -2
  23. package/dist/use-portfolio.js +1 -1
  24. package/dist/use-positions.js +4 -1
  25. package/dist/use-spot-asset-ctxs.d.ts +1 -1
  26. package/dist/use-spot-markets.js +3 -1
  27. package/dist/use-spot-meta-and-asset-ctxs.d.ts +4 -2
  28. package/dist/use-spot-meta-and-asset-ctxs.js +1 -1
  29. package/dist/use-spot-meta.d.ts +1 -1
  30. package/dist/use-spot-meta.js +1 -1
  31. package/dist/use-spot-state.d.ts +1 -1
  32. package/dist/use-spot-state.js +3 -1
  33. package/dist/use-subscribe-status.d.ts +2 -0
  34. package/dist/use-subscribe-status.js +21 -0
  35. package/dist/use-symbol-converter.js +1 -1
  36. package/dist/use-trade-history.d.ts +1 -1
  37. package/dist/use-trade-history.js +7 -3
  38. package/dist/use-trades.d.ts +1 -1
  39. package/dist/use-twap-states.d.ts +1 -1
  40. package/dist/use-twap-states.js +3 -1
  41. package/dist/use-user-account-activity.js +11 -5
  42. package/dist/use-user-delegator-summary.d.ts +1 -1
  43. package/dist/use-user-delegator-summary.js +1 -1
  44. package/dist/use-user-fills.d.ts +1 -1
  45. package/dist/use-user-fills.js +4 -2
  46. package/dist/use-user-fundings.d.ts +1 -1
  47. package/dist/use-user-fundings.js +3 -1
  48. package/dist/use-user-non-funding-ledger-updates.d.ts +1 -1
  49. package/dist/use-user-twap-history.d.ts +1 -1
  50. package/dist/use-user-twap-history.js +1 -1
  51. package/dist/use-user-twap-slice-fills.d.ts +1 -1
  52. package/dist/use-user-twap-slice-fills.js +1 -1
  53. package/dist/use-user-vault-equities.d.ts +5 -2
  54. package/dist/use-user-vault-equities.js +1 -1
  55. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from "./use-spot-markets.js";
21
21
  export * from "./use-spot-meta-and-asset-ctxs.js";
22
22
  export * from "./use-spot-meta.js";
23
23
  export * from "./use-spot-state.js";
24
+ export * from "./use-subscribe-status.js";
24
25
  export * from "./lib/symbol-converter.js";
25
26
  export * from "./use-symbol-converter.js";
26
27
  export * from "./use-twap-states.js";
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ export * from "./use-spot-markets.js";
21
21
  export * from "./use-spot-meta-and-asset-ctxs.js";
22
22
  export * from "./use-spot-meta.js";
23
23
  export * from "./use-spot-state.js";
24
+ export * from "./use-subscribe-status.js";
24
25
  export * from "./lib/symbol-converter.js";
25
26
  export * from "./use-symbol-converter.js";
26
27
  export * from "./use-twap-states.js";
@@ -1,4 +1,4 @@
1
- import { IRequestTransport } from "@nktkas/hyperliquid";
1
+ import type { IRequestTransport } from "@nktkas/hyperliquid";
2
2
  /** Options for creating a {@link SymbolConverter} instance. */
3
3
  export interface SymbolConverterOptions {
4
4
  /** Transport instance to use for API requests. */
@@ -72,11 +72,12 @@ export class SymbolConverter {
72
72
  */
73
73
  async reload() {
74
74
  const config = { transport: this.#transport };
75
- const needDexs = this.#dexOption === true || (Array.isArray(this.#dexOption) && this.#dexOption.length > 0);
75
+ const needDexs = this.#dexOption === true ||
76
+ (Array.isArray(this.#dexOption) && this.#dexOption.length > 0);
76
77
  const [perpMetaData, spotMetaData, perpDexsData] = await Promise.all([
77
78
  meta(config),
78
79
  spotMeta(config),
79
- needDexs ? perpDexs(config) : undefined
80
+ needDexs ? perpDexs(config) : undefined,
80
81
  ]);
81
82
  if (!perpMetaData?.universe?.length) {
82
83
  throw new Error("Invalid perpetual metadata response");
@@ -106,7 +107,7 @@ export class SymbolConverter {
106
107
  const builderDexs = perpDexsData
107
108
  .map((dex, index) => ({ dex, index }))
108
109
  .filter((item) => {
109
- return item.index > 0 && item.dex !== null && item.dex.name.length > 0;
110
+ return (item.index > 0 && item.dex !== null && item.dex.name.length > 0);
110
111
  });
111
112
  if (builderDexs.length === 0)
112
113
  return;
@@ -134,23 +135,26 @@ export class SymbolConverter {
134
135
  }
135
136
  #processSpotAssets(spotMetaData) {
136
137
  const tokenMap = new Map();
137
- spotMetaData.tokens.forEach((token) => {
138
- tokenMap.set(token.index, { name: token.name, szDecimals: token.szDecimals });
139
- });
140
- spotMetaData.universe.forEach((market) => {
138
+ for (const token of spotMetaData.tokens) {
139
+ tokenMap.set(token.index, {
140
+ name: token.name,
141
+ szDecimals: token.szDecimals,
142
+ });
143
+ }
144
+ for (const market of spotMetaData.universe) {
141
145
  if (market.tokens.length < 2)
142
- return;
146
+ continue;
143
147
  const baseToken = tokenMap.get(market.tokens[0]);
144
148
  const quoteToken = tokenMap.get(market.tokens[1]);
145
149
  if (!baseToken || !quoteToken)
146
- return;
150
+ continue;
147
151
  const assetId = 10000 + market.index;
148
152
  const baseQuoteKey = `${baseToken.name}/${quoteToken.name}`;
149
153
  this.#nameToAssetId.set(baseQuoteKey, assetId);
150
154
  this.#nameToSzDecimals.set(baseQuoteKey, baseToken.szDecimals);
151
155
  this.#nameToSpotPairId.set(baseQuoteKey, market.name);
152
156
  this.#SpotPairIdToName.set(market.name, baseQuoteKey);
153
- });
157
+ }
154
158
  }
155
159
  /**
156
160
  * Get asset ID for a coin.
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { ActiveAssetDataEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type ActiveAssetData = ActiveAssetDataEvent;
4
4
  export type UseActiveAssetDataOptions = {
5
5
  enabled?: boolean;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { AllDexsAssetCtxsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type AllDexsAssetCtxsData = AllDexsAssetCtxsEvent;
4
4
  export type UseAllDexsAssetCtxsOptions = {
5
5
  enabled?: boolean;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { AllDexsClearinghouseStateEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type AllDexsClearingHouseStateData = AllDexsClearinghouseStateEvent;
4
4
  export type UseAllDexsClearingHouseStateOptions = {
5
5
  enabled?: boolean;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { AllMidsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type AllMidsData = AllMidsEvent;
4
4
  export type UseAllMidsOptions = {
5
5
  enabled?: boolean;
@@ -1,5 +1,7 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { AllPerpMetasResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type AllPerpMetasData = AllPerpMetasResponse;
4
- export type UseAllPerpMetasOptions = Omit<UseQueryOptions<AllPerpMetasData, Error, AllPerpMetasData, ["all-perp-metas"]>, "queryKey" | "queryFn">;
4
+ export type UseAllPerpMetasOptions = Omit<UseQueryOptions<AllPerpMetasData, Error, AllPerpMetasData, [
5
+ "all-perp-metas"
6
+ ]>, "queryKey" | "queryFn">;
5
7
  export declare function useAllPerpMetas(options?: UseAllPerpMetasOptions): UseQueryResult<AllPerpMetasData, Error>;
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useAllPerpMetas(options = {}) {
4
4
  return useQuery({
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserHistoricalOrdersEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type HistoricalOrder = UserHistoricalOrdersEvent["orderHistory"][number];
4
4
  export type HistoricalOrdersData = {
5
5
  user: `0x${string}`;
@@ -12,7 +12,8 @@ function sortHistoricalOrders(orderHistory) {
12
12
  if (a.statusTimestamp !== b.statusTimestamp) {
13
13
  return b.statusTimestamp - a.statusTimestamp;
14
14
  }
15
- const statusRankDelta = getHistoricalOrderStatusRank(a.status) - getHistoricalOrderStatusRank(b.status);
15
+ const statusRankDelta = getHistoricalOrderStatusRank(a.status) -
16
+ getHistoricalOrderStatusRank(b.status);
16
17
  if (statusRankDelta !== 0) {
17
18
  return statusRankDelta;
18
19
  }
@@ -1,5 +1,5 @@
1
- import Decimal from "decimal.js";
2
1
  import { useSubscribe } from "@outofgas/react-stream";
2
+ import Decimal from "decimal.js";
3
3
  import { wsClient } from "./config/hl.js";
4
4
  export const EMPTY_L2_BOOK = {
5
5
  bids: [],
@@ -1,5 +1,5 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { MaxBuilderFeeResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type MaxBuilderFeeData = MaxBuilderFeeResponse;
4
4
  export type UseMaxBuilderFeeOptions = Omit<UseQueryOptions<MaxBuilderFeeData, Error, MaxBuilderFeeData, [
5
5
  "max-builder-fee",
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useMaxBuilderFee(user, builder, options = {}) {
4
4
  const enabled = options.enabled ?? Boolean(user && builder);
package/dist/use-mid.js CHANGED
@@ -22,7 +22,9 @@ export function useMid(coin) {
22
22
  const symbolConverter = useSymbolConverter();
23
23
  const spot = isSpotCoin(coin);
24
24
  const midsState = useAllMids({ enabled: spot && Boolean(coin) });
25
- const assetCtxsState = useAllDexsAssetCtxs({ enabled: !spot && Boolean(coin) });
25
+ const assetCtxsState = useAllDexsAssetCtxs({
26
+ enabled: !spot && Boolean(coin),
27
+ });
26
28
  return useMemo(() => {
27
29
  if (!coin) {
28
30
  return {
@@ -60,5 +62,17 @@ export function useMid(coin) {
60
62
  error: assetCtxsState.error,
61
63
  source: "all-dexs-asset-ctxs",
62
64
  };
63
- }, [coin, spot, symbolConverter, midsState.data, midsState.loading, midsState.ready, midsState.error, assetCtxsState.data, assetCtxsState.loading, assetCtxsState.ready, assetCtxsState.error]);
65
+ }, [
66
+ coin,
67
+ spot,
68
+ symbolConverter,
69
+ midsState.data,
70
+ midsState.loading,
71
+ midsState.ready,
72
+ midsState.error,
73
+ assetCtxsState.data,
74
+ assetCtxsState.loading,
75
+ assetCtxsState.ready,
76
+ assetCtxsState.error,
77
+ ]);
64
78
  }
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { OpenOrdersEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  type RawOpenOrder = OpenOrdersEvent["orders"][number];
4
4
  export type OpenOrderDirection = "Buy" | "Sell" | "Long" | "Short" | "Close Long" | "Close Short";
5
5
  export type OpenOrder = RawOpenOrder & {
@@ -1,5 +1,5 @@
1
- import { useMemo } from "react";
2
1
  import { useSubscribe } from "@outofgas/react-stream";
2
+ import { useMemo } from "react";
3
3
  import { wsClient } from "./config/hl.js";
4
4
  import { useSymbolConverter } from "./use-symbol-converter.js";
5
5
  const DEFAULT_DEX = "ALL_DEXS";
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from "react";
2
- import { useSymbolConverter } from "./use-symbol-converter.js";
3
2
  import { useHistoricalOrders, } from "./use-historical-orders.js";
3
+ import { useSymbolConverter } from "./use-symbol-converter.js";
4
4
  function formatOrderDirection(order, isSpot) {
5
5
  if (order.reduceOnly) {
6
6
  return order.side === "A" ? "Close Long" : "Close Short";
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from "react";
2
- import { usePerpMarkets } from "./use-perp-markets.js";
2
+ import { usePerpMarkets, } from "./use-perp-markets.js";
3
3
  export function usePerpMarket(coin, options = {}) {
4
4
  const marketsState = usePerpMarkets(options);
5
5
  const data = useMemo(() => {
@@ -64,11 +64,22 @@ export function usePerpMarkets(options = {}) {
64
64
  });
65
65
  })
66
66
  .filter((market) => includeDelisted || !market.isDelisted);
67
- }, [allPerpMetasState.data, spotMetaState.data, assetCtxsState.data, includeDelisted]);
67
+ }, [
68
+ allPerpMetasState.data,
69
+ spotMetaState.data,
70
+ assetCtxsState.data,
71
+ includeDelisted,
72
+ ]);
68
73
  return {
69
74
  data: markets,
70
- loading: allPerpMetasState.isLoading || spotMetaState.isLoading || assetCtxsState.loading,
71
- ready: allPerpMetasState.isSuccess && spotMetaState.isSuccess && assetCtxsState.ready,
72
- error: allPerpMetasState.error?.message ?? spotMetaState.error?.message ?? assetCtxsState.error,
75
+ loading: allPerpMetasState.isLoading ||
76
+ spotMetaState.isLoading ||
77
+ assetCtxsState.loading,
78
+ ready: allPerpMetasState.isSuccess &&
79
+ spotMetaState.isSuccess &&
80
+ assetCtxsState.ready,
81
+ error: allPerpMetasState.error?.message ??
82
+ spotMetaState.error?.message ??
83
+ assetCtxsState.error,
73
84
  };
74
85
  }
@@ -1,5 +1,8 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { PortfolioResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type PortfolioData = PortfolioResponse;
4
- export type UsePortfolioOptions = Omit<UseQueryOptions<PortfolioData, Error, PortfolioData, ["portfolio", `0x${string}`]>, "queryKey" | "queryFn">;
4
+ export type UsePortfolioOptions = Omit<UseQueryOptions<PortfolioData, Error, PortfolioData, [
5
+ "portfolio",
6
+ `0x${string}`
7
+ ]>, "queryKey" | "queryFn">;
5
8
  export declare function usePortfolio(user: `0x${string}`, options?: UsePortfolioOptions): UseQueryResult<PortfolioData, Error>;
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function usePortfolio(user, options = {}) {
4
4
  const enabled = options.enabled ?? Boolean(user);
@@ -5,7 +5,10 @@ export function usePositions(user, options = {}) {
5
5
  const data = useMemo(() => {
6
6
  return positionsState.data?.clearinghouseStates
7
7
  .flatMap(([, state]) => state.assetPositions)
8
- .sort((left, right) => Number(left.position.positionValue) < Number(right.position.positionValue) ? 1 : -1);
8
+ .sort((left, right) => Number(left.position.positionValue) <
9
+ Number(right.position.positionValue)
10
+ ? 1
11
+ : -1);
9
12
  }, [positionsState.data]);
10
13
  return {
11
14
  ...positionsState,
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { SpotAssetCtxsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type SpotAssetCtxsData = SpotAssetCtxsEvent;
4
4
  export type UseSpotAssetCtxsOptions = {
5
5
  enabled?: boolean;
@@ -31,7 +31,9 @@ export function useSpotMarkets(options = {}) {
31
31
  const quoteToken = tokenByIndex.get(market.tokens[1]);
32
32
  const ctx = assetCtxsByPairId.get(market.name);
33
33
  return {
34
- symbol: baseToken && quoteToken ? `${baseToken.name}/${quoteToken.name}` : market.name,
34
+ symbol: baseToken && quoteToken
35
+ ? `${baseToken.name}/${quoteToken.name}`
36
+ : market.name,
35
37
  pairId: market.name,
36
38
  baseToken: baseToken?.name ?? "",
37
39
  quoteToken: quoteToken?.name ?? "",
@@ -1,5 +1,7 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { SpotMetaAndAssetCtxsResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type SpotMetaAndAssetCtxsData = SpotMetaAndAssetCtxsResponse;
4
- export type UseSpotMetaAndAssetCtxsOptions = Omit<UseQueryOptions<SpotMetaAndAssetCtxsData, Error, SpotMetaAndAssetCtxsData, ["spot-meta-and-asset-ctxs"]>, "queryKey" | "queryFn">;
4
+ export type UseSpotMetaAndAssetCtxsOptions = Omit<UseQueryOptions<SpotMetaAndAssetCtxsData, Error, SpotMetaAndAssetCtxsData, [
5
+ "spot-meta-and-asset-ctxs"
6
+ ]>, "queryKey" | "queryFn">;
5
7
  export declare function useSpotMetaAndAssetCtxs(options?: UseSpotMetaAndAssetCtxsOptions): UseQueryResult<SpotMetaAndAssetCtxsData, Error>;
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useSpotMetaAndAssetCtxs(options = {}) {
4
4
  return useQuery({
@@ -1,5 +1,5 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { SpotMetaResponse } from "@nktkas/hyperliquid";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type SpotMetaData = SpotMetaResponse;
4
4
  export type UseSpotMetaOptions = Omit<UseQueryOptions<SpotMetaData, Error, SpotMetaData, ["spot-meta"]>, "queryKey" | "queryFn">;
5
5
  export declare function useSpotMeta(options?: UseSpotMetaOptions): UseQueryResult<SpotMetaData, Error>;
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useSpotMeta(options = {}) {
4
4
  return useQuery({
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { SpotStateEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type SpotBalance = SpotStateEvent["spotState"]["balances"][number];
4
4
  export type SpotEscrow = NonNullable<SpotStateEvent["spotState"]["evmEscrows"]>[number];
5
5
  export type SpotStateData = SpotStateEvent["spotState"] & {
@@ -16,7 +16,9 @@ export function useSpotState(user, options = {}) {
16
16
  });
17
17
  }
18
18
  catch (error) {
19
- onError(error instanceof Error ? error : new Error("Failed to process spot state event"));
19
+ onError(error instanceof Error
20
+ ? error
21
+ : new Error("Failed to process spot state event"));
20
22
  }
21
23
  });
22
24
  return {
@@ -0,0 +1,2 @@
1
+ export type ConnectionStatus = "online" | "offline";
2
+ export declare function useSubscribeStatus(): ConnectionStatus;
@@ -0,0 +1,21 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { wsTransport } from "./config/hl.js";
3
+ function getStatus() {
4
+ return wsTransport.socket.readyState === wsTransport.socket.OPEN
5
+ ? "online"
6
+ : "offline";
7
+ }
8
+ function subscribe(onStoreChange) {
9
+ const socket = wsTransport.socket;
10
+ socket.addEventListener("open", onStoreChange);
11
+ socket.addEventListener("close", onStoreChange);
12
+ socket.addEventListener("error", onStoreChange);
13
+ return () => {
14
+ socket.removeEventListener("open", onStoreChange);
15
+ socket.removeEventListener("close", onStoreChange);
16
+ socket.removeEventListener("error", onStoreChange);
17
+ };
18
+ }
19
+ export function useSubscribeStatus() {
20
+ return useSyncExternalStore(subscribe, getStatus, () => "offline");
21
+ }
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
- import { SymbolConverter } from "./lib/symbol-converter.js";
3
2
  import { transport } from "./config/hl.js";
3
+ import { SymbolConverter } from "./lib/symbol-converter.js";
4
4
  let converterPromise = null;
5
5
  export function getSymbolConverter() {
6
6
  if (!converterPromise) {
@@ -1,4 +1,4 @@
1
- import { type UserFill, type UseUserFillsOptions } from "./use-user-fills.js";
1
+ import { type UseUserFillsOptions, type UserFill } from "./use-user-fills.js";
2
2
  export type TradeHistory = UserFill & {
3
3
  displayCoin: string;
4
4
  quoteCoin: string;
@@ -1,11 +1,13 @@
1
1
  import Decimal from "decimal.js";
2
2
  import { useMemo } from "react";
3
3
  import { useSymbolConverter } from "./use-symbol-converter.js";
4
- import { useUserFills } from "./use-user-fills.js";
4
+ import { useUserFills, } from "./use-user-fills.js";
5
5
  function formatTradeHistoryFill(fill, spotPair) {
6
6
  const price = new Decimal(fill.px);
7
7
  if (!spotPair) {
8
- const netPnlInQuote = new Decimal(fill.closedPnl).minus(fill.fee).toString();
8
+ const netPnlInQuote = new Decimal(fill.closedPnl)
9
+ .minus(fill.fee)
10
+ .toString();
9
11
  return {
10
12
  ...fill,
11
13
  baseCoin: fill.coin,
@@ -19,7 +21,9 @@ function formatTradeHistoryFill(fill, spotPair) {
19
21
  }
20
22
  const [baseCoin = fill.coin, quoteCoin = fill.feeToken] = spotPair.split("/");
21
23
  const closedPnlInQuote = new Decimal(fill.closedPnl).mul(price);
22
- const feeInQuote = fill.feeToken === baseCoin ? new Decimal(fill.fee).mul(price) : new Decimal(fill.fee);
24
+ const feeInQuote = fill.feeToken === baseCoin
25
+ ? new Decimal(fill.fee).mul(price)
26
+ : new Decimal(fill.fee);
23
27
  const netPnlInQuote = closedPnlInQuote.minus(feeInQuote);
24
28
  return {
25
29
  ...fill,
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { TradesEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type Trade = TradesEvent[number];
4
4
  export type UseTradesOptions = {
5
5
  limit?: number;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { TwapStatesEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type TwapStatesData = TwapStatesEvent;
4
4
  export type UseTwapStatesOptions = {
5
5
  dex?: string;
@@ -14,7 +14,9 @@ export function useTwapStates(user, options = {}) {
14
14
  onData(event);
15
15
  }
16
16
  catch (error) {
17
- onError(error instanceof Error ? error : new Error("Failed to process twap states event"));
17
+ onError(error instanceof Error
18
+ ? error
19
+ : new Error("Failed to process twap states event"));
18
20
  }
19
21
  });
20
22
  return {
@@ -42,17 +42,21 @@ function getAction(entry) {
42
42
  case "internalTransfer":
43
43
  return "Send";
44
44
  case "spotTransfer":
45
- return isSystemAddress(entry.delta.destination) || isSystemAddress(entry.delta.user)
45
+ return isSystemAddress(entry.delta.destination) ||
46
+ isSystemAddress(entry.delta.user)
46
47
  ? "Transfer"
47
48
  : "Send";
48
49
  case "send":
49
- if (isSystemAddress(entry.delta.destination) || isSystemAddress(entry.delta.user)) {
50
+ if (isSystemAddress(entry.delta.destination) ||
51
+ isSystemAddress(entry.delta.user)) {
50
52
  return "Transfer";
51
53
  }
52
- if (entry.delta.sourceDex === "spot" && entry.delta.destinationDex === "spot") {
54
+ if (entry.delta.sourceDex === "spot" &&
55
+ entry.delta.destinationDex === "spot") {
53
56
  return "Send";
54
57
  }
55
- if (entry.delta.sourceDex === "spot" || entry.delta.destinationDex === "spot") {
58
+ if (entry.delta.sourceDex === "spot" ||
59
+ entry.delta.destinationDex === "spot") {
56
60
  return "Transfer";
57
61
  }
58
62
  return "Send";
@@ -150,7 +154,9 @@ function getDestination(entry) {
150
154
  case "subAccountTransfer":
151
155
  return "Perps";
152
156
  case "send":
153
- return isSystemAddress(entry.delta.destination) ? "HyperEVM" : formatDexLabel(entry.delta.destinationDex);
157
+ return isSystemAddress(entry.delta.destination)
158
+ ? "HyperEVM"
159
+ : formatDexLabel(entry.delta.destinationDex);
154
160
  case "internalTransfer":
155
161
  return "Perps";
156
162
  case "cStakingTransfer":
@@ -1,5 +1,5 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { DelegatorSummaryResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type UserDelegatorSummaryData = DelegatorSummaryResponse;
4
4
  export type UseUserDelegatorSummaryOptions = Omit<UseQueryOptions<UserDelegatorSummaryData, Error, UserDelegatorSummaryData, [
5
5
  "userDelegatorSummary",
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useUserDelegatorSummary(user, options = {}) {
4
4
  const enabled = options.enabled ?? Boolean(user);
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserFillsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type UserFill = UserFillsEvent["fills"][number];
4
4
  export type UserFillsData = {
5
5
  user: `0x${string}`;
@@ -13,7 +13,7 @@ function mergeUserFills(previousData, incomingEvent) {
13
13
  };
14
14
  }
15
15
  export function useUserFills(user, options = {}) {
16
- const { aggregateByTime = true, enabled: enabledOverride, onUpdate } = options;
16
+ const { aggregateByTime = true, enabled: enabledOverride, onUpdate, } = options;
17
17
  const enabled = enabledOverride ?? Boolean(user);
18
18
  return useSubscribe({
19
19
  key: ["user-fills", user, aggregateByTime],
@@ -29,7 +29,9 @@ export function useUserFills(user, options = {}) {
29
29
  onData(data);
30
30
  }
31
31
  catch (error) {
32
- onError(error instanceof Error ? error : new Error("Failed to process user fills event"));
32
+ onError(error instanceof Error
33
+ ? error
34
+ : new Error("Failed to process user fills event"));
33
35
  }
34
36
  });
35
37
  return {
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserFundingsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type UserFunding = UserFundingsEvent["fundings"][number];
4
4
  export type UserFundingsData = {
5
5
  user: `0x${string}`;
@@ -32,7 +32,9 @@ export function useUserFundings(user, options = {}) {
32
32
  onData(data);
33
33
  }
34
34
  catch (error) {
35
- onError(error instanceof Error ? error : new Error("Failed to process user fundings event"));
35
+ onError(error instanceof Error
36
+ ? error
37
+ : new Error("Failed to process user fundings event"));
36
38
  }
37
39
  });
38
40
  return {
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserNonFundingLedgerUpdatesEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type UserNonFundingLedgerUpdate = UserNonFundingLedgerUpdatesEvent["nonFundingLedgerUpdates"][number];
4
4
  export type UserNonFundingLedgerUpdatesData = {
5
5
  user: `0x${string}`;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserTwapHistoryEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type UserTwapHistoryData = {
4
4
  user: `0x${string}`;
5
5
  history: UserTwapHistoryEvent["history"];
@@ -1,5 +1,5 @@
1
- import { useEffect, useMemo, useState } from "react";
2
1
  import { useSubscribe } from "@outofgas/react-stream";
2
+ import { useEffect, useMemo, useState } from "react";
3
3
  import { wsClient } from "./config/hl.js";
4
4
  export function useUserTwapHistory(user, options = {}) {
5
5
  const { enabled: enabledOverride, onUpdate } = options;
@@ -1,5 +1,5 @@
1
- import { type UseSubscribeState } from "@outofgas/react-stream";
2
1
  import type { UserTwapSliceFillsEvent } from "@nktkas/hyperliquid/api/subscription";
2
+ import { type UseSubscribeState } from "@outofgas/react-stream";
3
3
  export type UserTwapSliceFillsData = {
4
4
  user: `0x${string}`;
5
5
  twapSliceFills: UserTwapSliceFillsEvent["twapSliceFills"];
@@ -1,5 +1,5 @@
1
- import { useEffect, useMemo, useState } from "react";
2
1
  import { useSubscribe } from "@outofgas/react-stream";
2
+ import { useEffect, useMemo, useState } from "react";
3
3
  import { wsClient } from "./config/hl.js";
4
4
  export function useUserTwapSliceFills(user, options = {}) {
5
5
  const { enabled: enabledOverride, onUpdate } = options;
@@ -1,6 +1,9 @@
1
- import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
2
1
  import type { UserVaultEquitiesResponse } from "@nktkas/hyperliquid/api/info";
2
+ import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
3
3
  export type UserVaultEquity = UserVaultEquitiesResponse[number];
4
4
  export type UserVaultEquitiesData = UserVaultEquitiesResponse;
5
- export type UseUserVaultEquitiesOptions = Omit<UseQueryOptions<UserVaultEquitiesData, Error, UserVaultEquitiesData, ["userVaultEquities", `0x${string}`]>, "queryKey" | "queryFn">;
5
+ export type UseUserVaultEquitiesOptions = Omit<UseQueryOptions<UserVaultEquitiesData, Error, UserVaultEquitiesData, [
6
+ "userVaultEquities",
7
+ `0x${string}`
8
+ ]>, "queryKey" | "queryFn">;
6
9
  export declare function useUserVaultEquities(user: `0x${string}`, options?: UseUserVaultEquitiesOptions): UseQueryResult<UserVaultEquitiesData, Error>;
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useQuery, } from "@tanstack/react-query";
2
2
  import { infoClient } from "./config/hl.js";
3
3
  export function useUserVaultEquities(user, options = {}) {
4
4
  const enabled = options.enabled ?? Boolean(user);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperix/hooks",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",