@pear-protocol/hyperliquid-sdk 0.0.79 → 0.1.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.
@@ -1,4 +1,5 @@
1
- import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from '../types';
1
+ import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData, PerpDexsResponse } from '../types';
2
+ import { TokenMetadataBySymbol } from '../utils/token-metadata-extractor';
2
3
  interface HyperliquidDataState {
3
4
  allMids: WsAllMidsData | null;
4
5
  activeAssetData: Record<string, ActiveAssetData> | null;
@@ -8,9 +9,10 @@ interface HyperliquidDataState {
8
9
  aggregatedClearingHouseState: ClearinghouseState | null;
9
10
  rawClearinghouseStates: [string, ClearinghouseState][] | null;
10
11
  perpMetaAssets: UniverseAsset[] | null;
11
- allPerpMetaAssets: UniverseAsset[] | null;
12
- hip3Assets: Map<string, string[]>;
13
- hip3MarketPrefixes: Map<string, string>;
12
+ tokenMetadata: TokenMetadataBySymbol;
13
+ perpDexs: PerpDexsResponse | null;
14
+ perpMetasByDex: Map<string, UniverseAsset[]> | null;
15
+ assetContextsByDex: Map<string, WebData3AssetCtx[]> | null;
14
16
  setAllMids: (value: WsAllMidsData | null) => void;
15
17
  setActiveAssetData: (value: Record<string, ActiveAssetData> | null | ((prev: Record<string, ActiveAssetData> | null) => Record<string, ActiveAssetData> | null)) => void;
16
18
  deleteActiveAssetData: (key: string) => void;
@@ -23,9 +25,9 @@ interface HyperliquidDataState {
23
25
  setAggregatedClearingHouseState: (value: ClearinghouseState | null) => void;
24
26
  setRawClearinghouseStates: (value: [string, ClearinghouseState][] | null) => void;
25
27
  setPerpMetaAssets: (value: UniverseAsset[] | null) => void;
26
- setAllPerpMetaAssets: (value: UniverseAsset[] | null) => void;
27
- setHip3Assets: (value: Map<string, string[]>) => void;
28
- setHip3MarketPrefixes: (value: Map<string, string>) => void;
28
+ setPerpDexs: (value: PerpDexsResponse | null) => void;
29
+ setPerpMetasByDex: (value: Map<string, UniverseAsset[]> | null) => void;
30
+ setAssetContextsByDex: (value: Map<string, WebData3AssetCtx[]> | null) => void;
29
31
  }
30
32
  export declare const useHyperliquidData: import("zustand").UseBoundStore<import("zustand").StoreApi<HyperliquidDataState>>;
31
33
  export {};
@@ -1,9 +1,7 @@
1
- import type { ActiveAssetsAllResponse, ActiveAssetsResponse } from '../types';
1
+ import type { ActiveAssetsResponse } from '../types';
2
2
  interface MarketDataState {
3
3
  marketData: ActiveAssetsResponse | null;
4
- marketDataAll: ActiveAssetsAllResponse | null;
5
4
  setMarketData: (value: ActiveAssetsResponse | null) => void;
6
- setMarketDataAll: (value: ActiveAssetsAllResponse | null) => void;
7
5
  clean: () => void;
8
6
  }
9
7
  export declare const useMarketData: import("zustand").UseBoundStore<import("zustand").StoreApi<MarketDataState>>;
@@ -1,4 +1,4 @@
1
- import type { ActiveAssetData, TokenSelection, TokenMetadata, WsAllMidsData, ActiveAssetsResponse, UniverseAsset, WebData3AssetCtx } from "../types";
1
+ import type { TokenSelection, TokenMetadata, ActiveAssetsResponse, UniverseAsset } from "../types";
2
2
  export interface TokenSelectionMetadataState {
3
3
  isPriceDataReady: boolean;
4
4
  isLoading: boolean;
@@ -16,9 +16,7 @@ export interface TokenSelectionMetadataState {
16
16
  leverageMatched: boolean;
17
17
  recompute: (args: {
18
18
  perpMetaAssets: UniverseAsset[] | null;
19
- finalAssetContexts: WebData3AssetCtx[] | null;
20
- allMids: WsAllMidsData | null;
21
- activeAssetData: Record<string, ActiveAssetData> | null;
19
+ tokenMetadata: Record<string, TokenMetadata | null>;
22
20
  marketData: ActiveAssetsResponse | null;
23
21
  longTokens: TokenSelection[];
24
22
  shortTokens: TokenSelection[];
package/dist/types.d.ts CHANGED
@@ -207,8 +207,7 @@ export interface TradeHistoryAssetDataDto {
207
207
  externalFeePaid: number;
208
208
  builderFeePaid: number;
209
209
  realizedPnl: number;
210
- marketPrefix?: string | null;
211
- collateralToken?: CollateralToken;
210
+ metadata?: TokenMetadata | null;
212
211
  }
213
212
  /**
214
213
  * Trade history data structure
@@ -257,8 +256,7 @@ export interface PositionAssetDetailDto {
257
256
  liquidationPrice: number;
258
257
  initialWeight: number;
259
258
  fundingPaid?: number;
260
- marketPrefix?: string | null;
261
- collateralToken?: CollateralToken;
259
+ metadata?: TokenMetadata | null;
262
260
  }
263
261
  export interface TpSlThreshold {
264
262
  type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO';
@@ -295,8 +293,7 @@ export interface OpenPositionDto {
295
293
  export interface OrderAssetDto {
296
294
  asset: string;
297
295
  weight: number;
298
- marketPrefix?: string | null;
299
- collateralToken?: CollateralToken;
296
+ metadata?: TokenMetadata | null;
300
297
  }
301
298
  /**
302
299
  * Order status
@@ -631,8 +628,10 @@ export interface AssetCtx {
631
628
  * Collateral token type
632
629
  * 0 = USDC
633
630
  * 360 = USDH
631
+ * 235 = USDE
632
+ * 268 = USDT
634
633
  */
635
- export type CollateralToken = 'USDC' | 'USDH';
634
+ export type CollateralToken = 'USDC' | 'USDH' | 'USDE' | 'USDT';
636
635
  /**
637
636
  * Universe asset metadata
638
637
  */
@@ -642,8 +641,7 @@ export interface UniverseAsset {
642
641
  maxLeverage: number;
643
642
  onlyIsolated?: boolean;
644
643
  isDelisted?: boolean;
645
- marketPrefix?: string;
646
- collateralToken?: CollateralToken;
644
+ collateralToken: CollateralToken;
647
645
  }
648
646
  export interface PerpMetaAsset extends UniverseAsset {
649
647
  marginTableId: number;
@@ -732,8 +730,6 @@ export interface RawAssetDto {
732
730
  size: number;
733
731
  side: string;
734
732
  fundingPaid?: number;
735
- marketPrefix?: string | null;
736
- collateralToken?: CollateralToken;
737
733
  leverage: number;
738
734
  }
739
735
  /**
@@ -769,6 +765,10 @@ export interface ActiveAssetData {
769
765
  markPx: string;
770
766
  }
771
767
  export interface TokenMetadata {
768
+ assetName: string;
769
+ symbolName: string;
770
+ marketName: string;
771
+ isAtOiCaps: boolean;
772
772
  currentPrice: number;
773
773
  prevDayPrice: number;
774
774
  priceChange24h: number;
@@ -803,30 +803,9 @@ export interface AssetMarketData {
803
803
  asset: WebData3AssetCtx | AssetCtx;
804
804
  universe: UniverseAsset;
805
805
  }
806
- /**
807
- * Nested market data structure for multi-market assets.
808
- * Each symbol maps to its market variants (keyed by prefix).
809
- * For non-HIP3 assets, use "default" as the key.
810
- *
811
- * @example
812
- * ```ts
813
- * {
814
- * "TSLA": {
815
- * "xyz": { asset: {...}, universe: { collateralToken: "USDC", ... } },
816
- * "flx": { asset: {...}, universe: { collateralToken: "USDH", ... } }
817
- * },
818
- * "BTC": {
819
- * "default": { asset: {...}, universe: {...} }
820
- * }
821
- * }
822
- * ```
823
- */
824
- export type MarketDataBySymbol = Record<string, Record<string, AssetMarketData>>;
825
806
  export interface PairAssetDto {
826
807
  asset: string;
827
808
  weight: number;
828
- collateralToken: CollateralToken;
829
- marketPrefix: string | null;
830
809
  }
831
810
  export interface ActiveAssetGroupItem {
832
811
  longAssets: PairAssetDto[];
@@ -903,3 +882,20 @@ export interface SpotState {
903
882
  user: string;
904
883
  balances: SpotBalance[];
905
884
  }
885
+ export interface TokenEntry {
886
+ symbol: string;
887
+ data: AssetMarketData;
888
+ }
889
+ export interface PerpDex {
890
+ name: string;
891
+ fullName: string;
892
+ deployer: string;
893
+ oracleUpdater: string | null;
894
+ feeRecipient: string | null;
895
+ deployerFeeScale: string;
896
+ assetToStreamingOiCap: [string, string][];
897
+ assetToFundingMultiplier: [string, string][];
898
+ subDeployers: [string, string[]][];
899
+ lastDeployerFeeScaleChangeTime: string;
900
+ }
901
+ export type PerpDexsResponse = (PerpDex | null)[];
@@ -0,0 +1,5 @@
1
+ export type MarketInfo = {
2
+ symbolName: string;
3
+ marketName: string;
4
+ };
5
+ export declare const getMarketInfoFromSymbol: (symbol: string) => MarketInfo;
@@ -1,2 +1,2 @@
1
- import { OpenPositionDto, RawPositionDto, ClearinghouseState, WsAllMidsData } from "../types";
2
- export declare const buildPositionValue: (rawPositions: RawPositionDto[], clearinghouseState: ClearinghouseState, allMids: WsAllMidsData) => OpenPositionDto[];
1
+ import { OpenPositionDto, RawPositionDto, ClearinghouseState, TokenMetadata } from "../types";
2
+ export declare const buildPositionValue: (rawPositions: RawPositionDto[], clearinghouseState: ClearinghouseState, getAssetByName: (symbol: string) => TokenMetadata | null) => OpenPositionDto[];
@@ -3,30 +3,6 @@ import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebD
3
3
  * Extracts token metadata from aggregated WebData3 contexts and AllMids data
4
4
  */
5
5
  export declare class TokenMetadataExtractor {
6
- /**
7
- * Extracts comprehensive token metadata
8
- * @param symbol - Token symbol (base symbol without prefix, e.g., "TSLA")
9
- * @param perpMetaAssets - Aggregated universe assets (flattened across dexes)
10
- * @param finalAssetContexts - Aggregated asset contexts (flattened across dexes)
11
- * @param allMids - AllMids data containing current prices
12
- * @param activeAssetData - Optional active asset data containing leverage information
13
- * @param marketPrefix - Optional market prefix (e.g., "xyz", "flx") for HIP3 multi-market assets
14
- * @returns TokenMetadata or null if token not found
15
- */
16
- static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, marketPrefix?: string | null): TokenMetadata | null;
17
- /**
18
- * Extracts metadata for multiple tokens
19
- * @param tokens - Array of token objects with symbol and optional marketPrefix
20
- * @param perpMetaAssets - Aggregated universe assets
21
- * @param finalAssetContexts - Aggregated asset contexts
22
- * @param allMids - AllMids data
23
- * @param activeAssetData - Optional active asset data containing leverage information
24
- * @returns Record of unique key to TokenMetadata. Key is "{prefix}:{symbol}" for HIP3 assets, or just "{symbol}" otherwise
25
- */
26
- static extractMultipleTokensMetadata(tokens: Array<{
27
- symbol: string;
28
- marketPrefix?: string | null;
29
- }>, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): Record<string, TokenMetadata | null>;
30
6
  /**
31
7
  * Checks if token data is available in aggregated universe assets
32
8
  * @param symbol - Token symbol
@@ -34,4 +10,39 @@ export declare class TokenMetadataExtractor {
34
10
  * @returns boolean indicating if token exists in universe
35
11
  */
36
12
  static isTokenAvailable(symbol: string, perpMetaAssets: UniverseAsset[] | null): boolean;
13
+ /**
14
+ * Extracts token metadata using DEX-aware lookup (correctly matches perpMetas to assetContexts)
15
+ * @param symbol - Token symbol (e.g., "BTC", "TSLA")
16
+ * @param perpMetasByDex - Map of DEX name to UniverseAsset[]
17
+ * @param assetContextsByDex - Map of DEX name to WebData3AssetCtx[]
18
+ * @param allMids - AllMids data containing current prices
19
+ * @param activeAssetData - Optional active asset data containing leverage information
20
+ * @param finalAtOICaps - Optional array of symbols at OI caps
21
+ * @returns TokenMetadata or null if token not found
22
+ */
23
+ static extractTokenMetadataByDex(symbol: string, perpMetasByDex: Map<string, UniverseAsset[]>, assetContextsByDex: Map<string, WebData3AssetCtx[]>, allMids: WsAllMidsData, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): TokenMetadata | null;
37
24
  }
25
+ export type TokenMetadataBySymbol = Record<string, TokenMetadata | null>;
26
+ export type TokenMetadataInputs = {
27
+ perpMetaAssets: UniverseAsset[] | null;
28
+ finalAssetContexts: WebData3AssetCtx[] | null;
29
+ allMids: WsAllMidsData | null;
30
+ activeAssetData: Record<string, ActiveAssetData> | null;
31
+ finalAtOICaps: string[] | null;
32
+ perpMetasByDex?: Map<string, UniverseAsset[]> | null;
33
+ assetContextsByDex?: Map<string, WebData3AssetCtx[]> | null;
34
+ };
35
+ export type RefreshTokenMetadataOptions = {
36
+ symbols?: string[];
37
+ oiCapsOnly?: boolean;
38
+ };
39
+ export declare const refreshTokenMetadata: (state: {
40
+ perpMetaAssets: UniverseAsset[] | null;
41
+ finalAssetContexts: WebData3AssetCtx[] | null;
42
+ allMids: WsAllMidsData | null;
43
+ activeAssetData: Record<string, ActiveAssetData> | null;
44
+ finalAtOICaps: string[] | null;
45
+ tokenMetadata: TokenMetadataBySymbol;
46
+ perpMetasByDex?: Map<string, UniverseAsset[]> | null;
47
+ assetContextsByDex?: Map<string, WebData3AssetCtx[]> | null;
48
+ }, overrides: Partial<TokenMetadataInputs>, options?: RefreshTokenMetadataOptions) => TokenMetadataBySymbol;
@@ -0,0 +1,4 @@
1
+ import type { TokenMetadata } from '../types';
2
+ export type TokenMetadataBySymbol = Record<string, TokenMetadata | null>;
3
+ export declare const selectTokenMetadataBySymbols: (tokenMetadata: TokenMetadataBySymbol, symbols: string[]) => TokenMetadataBySymbol;
4
+ export declare const getAssetByName: (tokenMetadata: TokenMetadataBySymbol, symbol: string) => TokenMetadata | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.79",
3
+ "version": "0.1.2",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,30 +0,0 @@
1
- import type { ClearinghouseState, MarketDataBySymbol } from '../types';
2
- /**
3
- * Hook to access webData and native WebSocket state
4
- */
5
- export declare const useWebData: () => {
6
- clearinghouseState: ClearinghouseState | null;
7
- perpsAtOpenInterestCap: string[] | null;
8
- /**
9
- * Market data keyed by symbol, with nested market variants.
10
- * Each symbol maps to its market variants (keyed by prefix).
11
- * For non-HIP3 assets, use "default" as the key.
12
- *
13
- * @example
14
- * ```ts
15
- * // HIP-3 asset with multiple markets
16
- * marketDataBySymbol["TSLA"]["xyz"] // { asset, universe: { collateralToken: "USDC" } }
17
- * marketDataBySymbol["TSLA"]["flx"] // { asset, universe: { collateralToken: "USDH" } }
18
- *
19
- * // Regular asset
20
- * marketDataBySymbol["BTC"]["default"] // { asset, universe }
21
- * ```
22
- */
23
- marketDataBySymbol: MarketDataBySymbol;
24
- /** Map of display name -> all full market names (e.g., "TSLA" -> ["xyz:TSLA", "flx:TSLA"]) */
25
- hip3Assets: Map<string, string[]>;
26
- /** Map of full market name -> prefix (e.g., "xyz:TSLA" -> "xyz") */
27
- hip3MarketPrefixes: Map<string, string>;
28
- isConnected: boolean;
29
- error: string | null;
30
- };
@@ -1,40 +0,0 @@
1
- /**
2
- * Convert a full/prefixed symbol (e.g., "xyz:XYZ100") to a display symbol (e.g., "XYZ100").
3
- */
4
- export declare function toDisplaySymbol(symbol: string): string;
5
- /**
6
- * Convert a display symbol back to backend form using a provided map.
7
- * If mapping is missing, returns the original symbol.
8
- * For multi-market assets, returns the first available market.
9
- * @param displaySymbol e.g., "TSLA"
10
- * @param hip3Assets map of display -> all full market names (e.g., "TSLA" -> ["xyz:TSLA", "flx:TSLA"])
11
- */
12
- export declare function toBackendSymbol(displaySymbol: string, hip3Assets: Map<string, string[]>): string;
13
- /**
14
- * Convert a display symbol to backend form for a specific market prefix.
15
- * This is useful when an asset is available on multiple markets (e.g., xyz:TSLA and flx:TSLA).
16
- * @param displaySymbol e.g., "TSLA"
17
- * @param marketPrefix e.g., "xyz" or "flx"
18
- * @param hip3Assets map of display -> all full market names
19
- * @returns Full market name if found, null if prefix not specified for multi-market asset, otherwise displaySymbol with prefix
20
- */
21
- export declare function toBackendSymbolWithMarket(displaySymbol: string, marketPrefix: string | undefined, hip3Assets: Map<string, string[]>): string | null;
22
- /**
23
- * Get all available markets for a display symbol.
24
- * @param displaySymbol e.g., "TSLA"
25
- * @param hip3Assets map of display -> all full market names
26
- * @returns Array of full market names, e.g., ["xyz:TSLA", "flx:TSLA"]
27
- */
28
- export declare function getAvailableMarkets(displaySymbol: string, hip3Assets: Map<string, string[]>): string[];
29
- /**
30
- * Extract the market prefix from a full market name.
31
- * @param fullSymbol e.g., "xyz:TSLA"
32
- * @returns The prefix (e.g., "xyz") or undefined if no prefix
33
- */
34
- export declare function getMarketPrefix(fullSymbol: string): string | undefined;
35
- /**
36
- * Check if a symbol is a HIP-3 market (has a prefix).
37
- * @param symbol e.g., "xyz:TSLA" or "TSLA"
38
- * @returns true if the symbol has a market prefix
39
- */
40
- export declare function isHip3Market(symbol: string): boolean;