@pear-protocol/hyperliquid-sdk 0.0.60-beta → 0.0.60-beta-usdh-1
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/useAuth.d.ts +4 -4
- package/dist/hooks/useMarketData.d.ts +9 -7
- package/dist/hooks/useWebData.d.ts +21 -3
- package/dist/index.d.ts +126 -45
- package/dist/index.js +709 -260
- package/dist/provider.d.ts +1 -1
- package/dist/store/historicalPriceDataStore.d.ts +1 -12
- package/dist/store/hyperliquidDataStore.d.ts +1 -25
- package/dist/store/marketDataStore.d.ts +1 -10
- package/dist/store/tokenSelectionMetadataStore.d.ts +2 -2
- package/dist/store/userDataStore.d.ts +1 -28
- package/dist/store/userSelection.d.ts +1 -1
- package/dist/types.d.ts +38 -3
- package/dist/utils/symbol-translator.d.ts +32 -3
- package/dist/utils/token-metadata-extractor.d.ts +9 -5
- package/package.json +2 -3
package/dist/provider.d.ts
CHANGED
|
@@ -10,16 +10,5 @@ interface TokenHistoricalPriceData {
|
|
|
10
10
|
oldestTime: number | null;
|
|
11
11
|
latestTime: number | null;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|
|
15
|
-
loadingTokens: Set<string>;
|
|
16
|
-
addHistoricalPriceData: (symbol: string, interval: CandleInterval, candles: CandleData[], range: HistoricalRange) => void;
|
|
17
|
-
hasHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => boolean;
|
|
18
|
-
getHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => CandleData[];
|
|
19
|
-
setTokenLoading: (symbol: string, loading: boolean) => void;
|
|
20
|
-
isTokenLoading: (symbol: string) => boolean;
|
|
21
|
-
removeTokenPriceData: (symbol: string, interval: CandleInterval) => void;
|
|
22
|
-
clearData: () => void;
|
|
23
|
-
}
|
|
24
|
-
export declare const useHistoricalPriceDataStore: import("zustand").UseBoundStore<import("zustand").StoreApi<HistoricalPriceDataState>>;
|
|
13
|
+
export declare const useHistoricalPriceDataStore: any;
|
|
25
14
|
export type { HistoricalRange, TokenHistoricalPriceData };
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
interface HyperliquidDataState {
|
|
3
|
-
allMids: WsAllMidsData | null;
|
|
4
|
-
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
5
|
-
candleData: CandleChartData | null;
|
|
6
|
-
finalAssetContexts: WebData3AssetCtx[] | null;
|
|
7
|
-
finalAtOICaps: string[] | null;
|
|
8
|
-
aggregatedClearingHouseState: ClearinghouseState | null;
|
|
9
|
-
perpMetaAssets: UniverseAsset[] | null;
|
|
10
|
-
hip3DisplayToFull: Map<string, string>;
|
|
11
|
-
setAllMids: (value: WsAllMidsData | null) => void;
|
|
12
|
-
setActiveAssetData: (value: Record<string, ActiveAssetData> | null | ((prev: Record<string, ActiveAssetData> | null) => Record<string, ActiveAssetData> | null)) => void;
|
|
13
|
-
deleteActiveAssetData: (key: string) => void;
|
|
14
|
-
addCandleData: (symbol: string, candle: CandleData) => void;
|
|
15
|
-
deleteCandleSymbol: (symbol: string) => void;
|
|
16
|
-
setCandleData: (value: CandleChartData | null) => void;
|
|
17
|
-
upsertActiveAssetData: (key: string, value: ActiveAssetData) => void;
|
|
18
|
-
setFinalAssetContexts: (value: WebData3AssetCtx[] | null) => void;
|
|
19
|
-
setFinalAtOICaps: (value: string[] | null) => void;
|
|
20
|
-
setAggregatedClearingHouseState: (value: ClearinghouseState | null) => void;
|
|
21
|
-
setPerpMetaAssets: (value: UniverseAsset[] | null) => void;
|
|
22
|
-
setHip3DisplayToFull: (value: Map<string, string>) => void;
|
|
23
|
-
}
|
|
24
|
-
export declare const useHyperliquidData: import("zustand").UseBoundStore<import("zustand").StoreApi<HyperliquidDataState>>;
|
|
25
|
-
export {};
|
|
1
|
+
export declare const useHyperliquidData: any;
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
interface MarketDataState {
|
|
3
|
-
marketData: ActiveAssetsResponse | null;
|
|
4
|
-
marketDataAll: ActiveAssetsAllResponse | null;
|
|
5
|
-
setMarketData: (value: ActiveAssetsResponse | null) => void;
|
|
6
|
-
setMarketDataAll: (value: ActiveAssetsAllResponse | null) => void;
|
|
7
|
-
clean: () => void;
|
|
8
|
-
}
|
|
9
|
-
export declare const useMarketData: import("zustand").UseBoundStore<import("zustand").StoreApi<MarketDataState>>;
|
|
10
|
-
export {};
|
|
1
|
+
export declare const useMarketData: any;
|
|
@@ -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;
|
|
@@ -24,4 +24,4 @@ export interface TokenSelectionMetadataState {
|
|
|
24
24
|
shortTokens: TokenSelection[];
|
|
25
25
|
}) => void;
|
|
26
26
|
}
|
|
27
|
-
export declare const useTokenSelectionMetadataStore:
|
|
27
|
+
export declare const useTokenSelectionMetadataStore: any;
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
interface UserDataState {
|
|
3
|
-
accessToken: string | null;
|
|
4
|
-
refreshToken: string | null;
|
|
5
|
-
isAuthenticated: boolean;
|
|
6
|
-
address: string | null;
|
|
7
|
-
tradeHistories: TradeHistoryDataDto[] | null;
|
|
8
|
-
rawOpenPositions: RawPositionDto[] | null;
|
|
9
|
-
openOrders: OpenLimitOrderDto[] | null;
|
|
10
|
-
accountSummary: PlatformAccountSummaryResponseDto | null;
|
|
11
|
-
twapDetails: TwapMonitoringDto[] | null;
|
|
12
|
-
notifications: NotificationDto[] | null;
|
|
13
|
-
userExtraAgents: ExtraAgent[] | null;
|
|
14
|
-
setAccessToken: (token: string | null) => void;
|
|
15
|
-
setRefreshToken: (token: string | null) => void;
|
|
16
|
-
setIsAuthenticated: (value: boolean) => void;
|
|
17
|
-
setAddress: (address: string | null) => void;
|
|
18
|
-
setTradeHistories: (value: TradeHistoryDataDto[] | null) => void;
|
|
19
|
-
setRawOpenPositions: (value: RawPositionDto[] | null) => void;
|
|
20
|
-
setOpenOrders: (value: OpenLimitOrderDto[] | null) => void;
|
|
21
|
-
setAccountSummary: (value: PlatformAccountSummaryResponseDto | null) => void;
|
|
22
|
-
setUserExtraAgents: (value: ExtraAgent[] | null) => void;
|
|
23
|
-
setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
|
|
24
|
-
setNotifications: (value: NotificationDto[] | null) => void;
|
|
25
|
-
clean: () => void;
|
|
26
|
-
}
|
|
27
|
-
export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
|
|
28
|
-
export {};
|
|
1
|
+
export declare const useUserData: any;
|
|
@@ -22,5 +22,5 @@ interface UserSelectionState {
|
|
|
22
22
|
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
23
23
|
resetToDefaults: () => void;
|
|
24
24
|
}
|
|
25
|
-
export declare const useUserSelection:
|
|
25
|
+
export declare const useUserSelection: any;
|
|
26
26
|
export type { UserSelectionState };
|
package/dist/types.d.ts
CHANGED
|
@@ -162,6 +162,8 @@ export interface TradeHistoryAssetDataDto {
|
|
|
162
162
|
externalFeePaid: number;
|
|
163
163
|
builderFeePaid: number;
|
|
164
164
|
realizedPnl: number;
|
|
165
|
+
marketPrefix?: string | null;
|
|
166
|
+
collateralToken?: CollateralToken;
|
|
165
167
|
}
|
|
166
168
|
/**
|
|
167
169
|
* Trade history data structure
|
|
@@ -210,6 +212,8 @@ export interface PositionAssetDetailDto {
|
|
|
210
212
|
liquidationPrice: number;
|
|
211
213
|
initialWeight: number;
|
|
212
214
|
fundingPaid?: number;
|
|
215
|
+
marketPrefix?: string | null;
|
|
216
|
+
collateralToken?: CollateralToken;
|
|
213
217
|
}
|
|
214
218
|
export interface TpSlThreshold {
|
|
215
219
|
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
@@ -427,7 +431,7 @@ export interface AgentWalletState {
|
|
|
427
431
|
* WebSocket message from HyperLiquid native API
|
|
428
432
|
*/
|
|
429
433
|
export interface WebSocketMessage {
|
|
430
|
-
method:
|
|
434
|
+
method: 'subscribe' | 'unsubscribe';
|
|
431
435
|
subscription: {
|
|
432
436
|
type: string;
|
|
433
437
|
dex?: string;
|
|
@@ -501,6 +505,12 @@ export interface AssetCtx {
|
|
|
501
505
|
impactPxs?: string[];
|
|
502
506
|
oraclePx: string;
|
|
503
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Collateral token type
|
|
510
|
+
* 0 = USDC
|
|
511
|
+
* 360 = USDH
|
|
512
|
+
*/
|
|
513
|
+
export type CollateralToken = 'USDC' | 'USDH';
|
|
504
514
|
/**
|
|
505
515
|
* Universe asset metadata
|
|
506
516
|
*/
|
|
@@ -510,6 +520,8 @@ export interface UniverseAsset {
|
|
|
510
520
|
maxLeverage: number;
|
|
511
521
|
onlyIsolated?: boolean;
|
|
512
522
|
isDelisted?: boolean;
|
|
523
|
+
marketPrefix?: string;
|
|
524
|
+
collateralToken?: CollateralToken;
|
|
513
525
|
}
|
|
514
526
|
export interface PerpMetaAsset extends UniverseAsset {
|
|
515
527
|
marginTableId: number;
|
|
@@ -645,6 +657,7 @@ export interface TokenMetadata {
|
|
|
645
657
|
leverage?: LeverageInfo;
|
|
646
658
|
maxTradeSzs?: [string, string];
|
|
647
659
|
availableToTrade?: [string, string];
|
|
660
|
+
collateralToken?: CollateralToken;
|
|
648
661
|
}
|
|
649
662
|
/**
|
|
650
663
|
* Enhanced token selection with weight and metadata for basket trading
|
|
@@ -665,9 +678,30 @@ export interface AssetMarketData {
|
|
|
665
678
|
asset: WebData3AssetCtx | AssetCtx;
|
|
666
679
|
universe: UniverseAsset;
|
|
667
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Nested market data structure for multi-market assets.
|
|
683
|
+
* Each symbol maps to its market variants (keyed by prefix).
|
|
684
|
+
* For non-HIP3 assets, use "default" as the key.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```ts
|
|
688
|
+
* {
|
|
689
|
+
* "TSLA": {
|
|
690
|
+
* "xyz": { asset: {...}, universe: { collateralToken: "USDC", ... } },
|
|
691
|
+
* "flx": { asset: {...}, universe: { collateralToken: "USDH", ... } }
|
|
692
|
+
* },
|
|
693
|
+
* "BTC": {
|
|
694
|
+
* "default": { asset: {...}, universe: {...} }
|
|
695
|
+
* }
|
|
696
|
+
* }
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
export type MarketDataBySymbol = Record<string, Record<string, AssetMarketData>>;
|
|
668
700
|
export interface PairAssetDto {
|
|
669
701
|
asset: string;
|
|
670
702
|
weight: number;
|
|
703
|
+
collateralToken: CollateralToken;
|
|
704
|
+
marketPrefix: string | null;
|
|
671
705
|
}
|
|
672
706
|
export interface ActiveAssetGroupItem {
|
|
673
707
|
longAssets: PairAssetDto[];
|
|
@@ -681,6 +715,7 @@ export interface ActiveAssetGroupItem {
|
|
|
681
715
|
weightedRatio?: string;
|
|
682
716
|
weightedPrevRatio?: string;
|
|
683
717
|
weightedChange24h?: string;
|
|
718
|
+
collateralType: 'USDC' | 'USDH' | 'MIXED';
|
|
684
719
|
}
|
|
685
720
|
export interface ActiveAssetsResponse {
|
|
686
721
|
active: ActiveAssetGroupItem[];
|
|
@@ -698,7 +733,7 @@ export interface ActiveAssetsAllResponse {
|
|
|
698
733
|
/**
|
|
699
734
|
* Candle interval options
|
|
700
735
|
*/
|
|
701
|
-
export type CandleInterval =
|
|
736
|
+
export type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
702
737
|
/**
|
|
703
738
|
* Candle data structure from WebSocket
|
|
704
739
|
*/
|
|
@@ -726,7 +761,7 @@ export interface CandleSnapshotRequest {
|
|
|
726
761
|
endTime: number;
|
|
727
762
|
interval: CandleInterval;
|
|
728
763
|
};
|
|
729
|
-
type:
|
|
764
|
+
type: 'candleSnapshot';
|
|
730
765
|
}
|
|
731
766
|
export interface TokenSelectorConfig {
|
|
732
767
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.0.60-beta",
|
|
3
|
+
"version": "0.0.60-beta-usdh-1",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"clean": "rimraf dist"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.6.0"
|
|
28
|
-
"zustand": "^5.0.8"
|
|
27
|
+
"axios": "^1.6.0"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
30
|
"react": "^18.0.0",
|