@pear-protocol/hyperliquid-sdk 0.0.59 → 0.0.60-beta-usdh
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/clients/hyperliquid.d.ts +1 -1
- package/dist/clients/positions.d.ts +2 -2
- package/dist/clients/watchlist.d.ts +1 -1
- package/dist/hooks/useMarketData.d.ts +9 -7
- package/dist/hooks/useWebData.d.ts +21 -3
- package/dist/index.d.ts +119 -21
- package/dist/index.js +626 -145
- package/dist/store/tokenSelectionMetadataStore.d.ts +1 -1
- package/dist/types.d.ts +36 -3
- package/dist/utils/symbol-translator.d.ts +32 -3
- package/dist/utils/token-metadata-extractor.d.ts +9 -5
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActiveAssetData, TokenSelection, TokenMetadata, WsAllMidsData, ActiveAssetsResponse, UniverseAsset, WebData3AssetCtx } from
|
|
1
|
+
import type { ActiveAssetData, TokenSelection, TokenMetadata, WsAllMidsData, ActiveAssetsResponse, UniverseAsset, WebData3AssetCtx } from '../types';
|
|
2
2
|
export interface TokenSelectionMetadataState {
|
|
3
3
|
isPriceDataReady: boolean;
|
|
4
4
|
isLoading: boolean;
|
package/dist/types.d.ts
CHANGED
|
@@ -210,6 +210,8 @@ export interface PositionAssetDetailDto {
|
|
|
210
210
|
liquidationPrice: number;
|
|
211
211
|
initialWeight: number;
|
|
212
212
|
fundingPaid?: number;
|
|
213
|
+
marketPrefix?: string | null;
|
|
214
|
+
collateralToken?: CollateralToken;
|
|
213
215
|
}
|
|
214
216
|
export interface TpSlThreshold {
|
|
215
217
|
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
@@ -427,7 +429,7 @@ export interface AgentWalletState {
|
|
|
427
429
|
* WebSocket message from HyperLiquid native API
|
|
428
430
|
*/
|
|
429
431
|
export interface WebSocketMessage {
|
|
430
|
-
method:
|
|
432
|
+
method: 'subscribe' | 'unsubscribe';
|
|
431
433
|
subscription: {
|
|
432
434
|
type: string;
|
|
433
435
|
dex?: string;
|
|
@@ -501,6 +503,12 @@ export interface AssetCtx {
|
|
|
501
503
|
impactPxs?: string[];
|
|
502
504
|
oraclePx: string;
|
|
503
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Collateral token type
|
|
508
|
+
* 0 = USDC
|
|
509
|
+
* 360 = USDH
|
|
510
|
+
*/
|
|
511
|
+
export type CollateralToken = 'USDC' | 'USDH';
|
|
504
512
|
/**
|
|
505
513
|
* Universe asset metadata
|
|
506
514
|
*/
|
|
@@ -510,6 +518,8 @@ export interface UniverseAsset {
|
|
|
510
518
|
maxLeverage: number;
|
|
511
519
|
onlyIsolated?: boolean;
|
|
512
520
|
isDelisted?: boolean;
|
|
521
|
+
marketPrefix?: string;
|
|
522
|
+
collateralToken?: CollateralToken;
|
|
513
523
|
}
|
|
514
524
|
export interface PerpMetaAsset extends UniverseAsset {
|
|
515
525
|
marginTableId: number;
|
|
@@ -645,6 +655,7 @@ export interface TokenMetadata {
|
|
|
645
655
|
leverage?: LeverageInfo;
|
|
646
656
|
maxTradeSzs?: [string, string];
|
|
647
657
|
availableToTrade?: [string, string];
|
|
658
|
+
collateralToken?: CollateralToken;
|
|
648
659
|
}
|
|
649
660
|
/**
|
|
650
661
|
* Enhanced token selection with weight and metadata for basket trading
|
|
@@ -665,9 +676,30 @@ export interface AssetMarketData {
|
|
|
665
676
|
asset: WebData3AssetCtx | AssetCtx;
|
|
666
677
|
universe: UniverseAsset;
|
|
667
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* Nested market data structure for multi-market assets.
|
|
681
|
+
* Each symbol maps to its market variants (keyed by prefix).
|
|
682
|
+
* For non-HIP3 assets, use "default" as the key.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* {
|
|
687
|
+
* "TSLA": {
|
|
688
|
+
* "xyz": { asset: {...}, universe: { collateralToken: "USDC", ... } },
|
|
689
|
+
* "flx": { asset: {...}, universe: { collateralToken: "USDH", ... } }
|
|
690
|
+
* },
|
|
691
|
+
* "BTC": {
|
|
692
|
+
* "default": { asset: {...}, universe: {...} }
|
|
693
|
+
* }
|
|
694
|
+
* }
|
|
695
|
+
* ```
|
|
696
|
+
*/
|
|
697
|
+
export type MarketDataBySymbol = Record<string, Record<string, AssetMarketData>>;
|
|
668
698
|
export interface PairAssetDto {
|
|
669
699
|
asset: string;
|
|
670
700
|
weight: number;
|
|
701
|
+
collateralToken: CollateralToken;
|
|
702
|
+
marketPrefix: string | null;
|
|
671
703
|
}
|
|
672
704
|
export interface ActiveAssetGroupItem {
|
|
673
705
|
longAssets: PairAssetDto[];
|
|
@@ -681,6 +713,7 @@ export interface ActiveAssetGroupItem {
|
|
|
681
713
|
weightedRatio?: string;
|
|
682
714
|
weightedPrevRatio?: string;
|
|
683
715
|
weightedChange24h?: string;
|
|
716
|
+
collateralType: 'USDC' | 'USDH' | 'MIXED';
|
|
684
717
|
}
|
|
685
718
|
export interface ActiveAssetsResponse {
|
|
686
719
|
active: ActiveAssetGroupItem[];
|
|
@@ -698,7 +731,7 @@ export interface ActiveAssetsAllResponse {
|
|
|
698
731
|
/**
|
|
699
732
|
* Candle interval options
|
|
700
733
|
*/
|
|
701
|
-
export type CandleInterval =
|
|
734
|
+
export type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
702
735
|
/**
|
|
703
736
|
* Candle data structure from WebSocket
|
|
704
737
|
*/
|
|
@@ -726,7 +759,7 @@ export interface CandleSnapshotRequest {
|
|
|
726
759
|
endTime: number;
|
|
727
760
|
interval: CandleInterval;
|
|
728
761
|
};
|
|
729
|
-
type:
|
|
762
|
+
type: 'candleSnapshot';
|
|
730
763
|
}
|
|
731
764
|
export interface TokenSelectorConfig {
|
|
732
765
|
isLong: boolean;
|
|
@@ -5,7 +5,36 @@ export declare function toDisplaySymbol(symbol: string): string;
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert a display symbol back to backend form using a provided map.
|
|
7
7
|
* If mapping is missing, returns the original symbol.
|
|
8
|
-
*
|
|
9
|
-
* @param
|
|
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"])
|
|
10
11
|
*/
|
|
11
|
-
export declare function toBackendSymbol(displaySymbol: string,
|
|
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;
|
|
@@ -5,24 +5,28 @@ 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
|
|
8
|
+
* @param symbol - Token symbol (base symbol without prefix, e.g., "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
|
|
13
14
|
* @returns TokenMetadata or null if token not found
|
|
14
15
|
*/
|
|
15
|
-
static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): TokenMetadata | null;
|
|
16
|
+
static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, marketPrefix?: string | null): TokenMetadata | null;
|
|
16
17
|
/**
|
|
17
18
|
* Extracts metadata for multiple tokens
|
|
18
|
-
* @param
|
|
19
|
+
* @param tokens - Array of token objects with symbol and optional marketPrefix
|
|
19
20
|
* @param perpMetaAssets - Aggregated universe assets
|
|
20
21
|
* @param finalAssetContexts - Aggregated asset contexts
|
|
21
22
|
* @param allMids - AllMids data
|
|
22
23
|
* @param activeAssetData - Optional active asset data containing leverage information
|
|
23
|
-
* @returns Record of
|
|
24
|
+
* @returns Record of unique key to TokenMetadata. Key is "{prefix}:{symbol}" for HIP3 assets, or just "{symbol}" otherwise
|
|
24
25
|
*/
|
|
25
|
-
static extractMultipleTokensMetadata(
|
|
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>;
|
|
26
30
|
/**
|
|
27
31
|
* Checks if token data is available in aggregated universe assets
|
|
28
32
|
* @param symbol - Token symbol
|