@pear-protocol/hyperliquid-sdk 0.0.78 → 0.1.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.
@@ -1,4 +1,5 @@
1
- import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from '../types';
1
+ import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, TokenMetadata, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from '../types';
2
+ type TokenMetadataBySymbol = Record<string, TokenMetadata | null>;
2
3
  interface HyperliquidDataState {
3
4
  allMids: WsAllMidsData | null;
4
5
  activeAssetData: Record<string, ActiveAssetData> | null;
@@ -8,9 +9,7 @@ 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;
14
13
  setAllMids: (value: WsAllMidsData | null) => void;
15
14
  setActiveAssetData: (value: Record<string, ActiveAssetData> | null | ((prev: Record<string, ActiveAssetData> | null) => Record<string, ActiveAssetData> | null)) => void;
16
15
  deleteActiveAssetData: (key: string) => void;
@@ -23,9 +22,6 @@ interface HyperliquidDataState {
23
22
  setAggregatedClearingHouseState: (value: ClearinghouseState | null) => void;
24
23
  setRawClearinghouseStates: (value: [string, ClearinghouseState][] | null) => void;
25
24
  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;
29
25
  }
30
26
  export declare const useHyperliquidData: import("zustand").UseBoundStore<import("zustand").StoreApi<HyperliquidDataState>>;
31
27
  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
@@ -642,8 +639,7 @@ export interface UniverseAsset {
642
639
  maxLeverage: number;
643
640
  onlyIsolated?: boolean;
644
641
  isDelisted?: boolean;
645
- marketPrefix?: string;
646
- collateralToken?: CollateralToken;
642
+ collateralToken: CollateralToken;
647
643
  }
648
644
  export interface PerpMetaAsset extends UniverseAsset {
649
645
  marginTableId: number;
@@ -732,8 +728,6 @@ export interface RawAssetDto {
732
728
  size: number;
733
729
  side: string;
734
730
  fundingPaid?: number;
735
- marketPrefix?: string | null;
736
- collateralToken?: CollateralToken;
737
731
  leverage: number;
738
732
  }
739
733
  /**
@@ -769,6 +763,10 @@ export interface ActiveAssetData {
769
763
  markPx: string;
770
764
  }
771
765
  export interface TokenMetadata {
766
+ assetName: string;
767
+ symbolName: string;
768
+ marketName: string;
769
+ isAtOiCaps: boolean;
772
770
  currentPrice: number;
773
771
  prevDayPrice: number;
774
772
  priceChange24h: number;
@@ -803,30 +801,9 @@ export interface AssetMarketData {
803
801
  asset: WebData3AssetCtx | AssetCtx;
804
802
  universe: UniverseAsset;
805
803
  }
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
804
  export interface PairAssetDto {
826
805
  asset: string;
827
806
  weight: number;
828
- collateralToken: CollateralToken;
829
- marketPrefix: string | null;
830
807
  }
831
808
  export interface ActiveAssetGroupItem {
832
809
  longAssets: PairAssetDto[];
@@ -903,3 +880,7 @@ export interface SpotState {
903
880
  user: string;
904
881
  balances: SpotBalance[];
905
882
  }
883
+ export interface TokenEntry {
884
+ symbol: string;
885
+ data: AssetMarketData;
886
+ }
@@ -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[];
@@ -5,28 +5,24 @@ import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebD
5
5
  export declare class TokenMetadataExtractor {
6
6
  /**
7
7
  * Extracts comprehensive token metadata
8
- * @param symbol - Token symbol (base symbol without prefix, e.g., "TSLA")
8
+ * @param symbol - Token symbol (e.g., "BTC", "TSLA")
9
9
  * @param perpMetaAssets - Aggregated universe assets (flattened across dexes)
10
10
  * @param finalAssetContexts - Aggregated asset contexts (flattened across dexes)
11
11
  * @param allMids - AllMids data containing current prices
12
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
13
  * @returns TokenMetadata or null if token not found
15
14
  */
16
- static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, marketPrefix?: string | null): TokenMetadata | null;
15
+ static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): TokenMetadata | null;
17
16
  /**
18
17
  * Extracts metadata for multiple tokens
19
- * @param tokens - Array of token objects with symbol and optional marketPrefix
18
+ * @param tokens - Array of token strings (e.g., "BTC", "TSLA")
20
19
  * @param perpMetaAssets - Aggregated universe assets
21
20
  * @param finalAssetContexts - Aggregated asset contexts
22
21
  * @param allMids - AllMids data
23
22
  * @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
23
+ * @returns Record of token string to TokenMetadata (keys match input tokens exactly)
25
24
  */
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>;
25
+ static extractMultipleTokensMetadata(tokens: string[], perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): Record<string, TokenMetadata | null>;
30
26
  /**
31
27
  * Checks if token data is available in aggregated universe assets
32
28
  * @param symbol - Token symbol
@@ -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.78",
3
+ "version": "0.1.0",
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;