@pear-protocol/hyperliquid-sdk 0.0.49 → 0.0.51
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 +14 -2
- package/dist/clients/positions.d.ts +1 -1
- package/dist/clients/sync.d.ts +1 -1
- package/dist/clients/watchlist.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useAccountSummary.d.ts +5 -0
- package/dist/hooks/useAgentWallet.d.ts +4 -9
- package/dist/hooks/usePortfolio.d.ts +1 -1
- package/dist/hooks/useTrading.d.ts +1 -8
- package/dist/hooks/useWebData.d.ts +3 -2
- package/dist/hyperliquid-websocket.d.ts +2 -1
- package/dist/index.d.ts +84 -96
- package/dist/index.js +400 -310
- package/dist/provider.d.ts +0 -20
- package/dist/store/tokenSelectionMetadataStore.d.ts +3 -2
- package/dist/types.d.ts +69 -21
- package/dist/utils/account-summary-calculator.d.ts +6 -13
- package/dist/utils/position-processor.d.ts +2 -2
- package/dist/utils/symbol-translator.d.ts +11 -0
- package/dist/utils/token-metadata-extractor.d.ts +11 -9
- package/dist/websocket.d.ts +2 -1
- package/package.json +1 -1
- package/README.md +0 -735
- package/dist/hooks/useAddress.d.ts +0 -9
package/dist/provider.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import type { UserProfile } from './types';
|
|
3
3
|
import { AuthStatus } from './types';
|
|
4
|
-
import type { AgentWalletState } from './types';
|
|
5
4
|
export interface PearHyperliquidContextType {
|
|
6
5
|
apiBaseUrl: string;
|
|
7
6
|
wsUrl: string;
|
|
@@ -21,13 +20,6 @@ export interface PearHyperliquidContextType {
|
|
|
21
20
|
loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
22
21
|
refreshTokens: () => Promise<any>;
|
|
23
22
|
logout: () => Promise<void>;
|
|
24
|
-
agentWallet: AgentWalletState;
|
|
25
|
-
isAgentWalletReady: boolean;
|
|
26
|
-
agentWalletError: string | null;
|
|
27
|
-
agentWalletLoading: boolean;
|
|
28
|
-
refreshAgentWalletStatus: () => Promise<any>;
|
|
29
|
-
createAgentWallet: () => Promise<any>;
|
|
30
|
-
notifyAgentWalletApproved: () => Promise<any>;
|
|
31
23
|
}
|
|
32
24
|
export declare const PearHyperliquidContext: React.Context<PearHyperliquidContextType | undefined>;
|
|
33
25
|
interface PearHyperliquidProviderProps {
|
|
@@ -60,16 +52,4 @@ export declare function usePearAuth(): {
|
|
|
60
52
|
readonly refreshTokens: () => Promise<any>;
|
|
61
53
|
readonly logout: () => Promise<void>;
|
|
62
54
|
};
|
|
63
|
-
/**
|
|
64
|
-
* Provider-aware Agent Wallet hook. Uses agent wallet state/actions provided by PearHyperliquidProvider.
|
|
65
|
-
*/
|
|
66
|
-
export declare function usePearAgentWallet(): {
|
|
67
|
-
readonly agentWallet: AgentWalletState;
|
|
68
|
-
readonly isReady: boolean;
|
|
69
|
-
readonly loading: boolean;
|
|
70
|
-
readonly error: string | null;
|
|
71
|
-
readonly refreshAgentWalletStatus: () => Promise<any>;
|
|
72
|
-
readonly createAgentWallet: () => Promise<any>;
|
|
73
|
-
readonly notifyAgentWalletApproved: () => Promise<any>;
|
|
74
|
-
};
|
|
75
55
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActiveAssetData, TokenSelection, TokenMetadata,
|
|
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;
|
|
@@ -15,7 +15,8 @@ export interface TokenSelectionMetadataState {
|
|
|
15
15
|
minMargin: number;
|
|
16
16
|
leverageMatched: boolean;
|
|
17
17
|
recompute: (args: {
|
|
18
|
-
|
|
18
|
+
perpMetaAssets: UniverseAsset[] | null;
|
|
19
|
+
finalAssetContexts: WebData3AssetCtx[] | null;
|
|
19
20
|
allMids: WsAllMidsData | null;
|
|
20
21
|
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
21
22
|
marketData: ActiveAssetsResponse | null;
|
package/dist/types.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare enum ReadyState {
|
|
|
57
57
|
/**
|
|
58
58
|
* WebSocket channels
|
|
59
59
|
*/
|
|
60
|
-
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'market-data-all' | '
|
|
60
|
+
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'market-data-all' | 'webData3' | 'allMids' | 'activeAssetData';
|
|
61
61
|
/**
|
|
62
62
|
* WebSocket subscription message
|
|
63
63
|
*/
|
|
@@ -152,6 +152,7 @@ export interface TradeHistoryAssetDataDto {
|
|
|
152
152
|
entryWeight: number;
|
|
153
153
|
entryPrice: number;
|
|
154
154
|
limitPrice: number;
|
|
155
|
+
leverage: number;
|
|
155
156
|
size: number;
|
|
156
157
|
externalFeePaid: number;
|
|
157
158
|
builderFeePaid: number;
|
|
@@ -167,6 +168,7 @@ export interface TradeHistoryDataDto {
|
|
|
167
168
|
externalFeePaid: number;
|
|
168
169
|
builderFeePaid: number;
|
|
169
170
|
realizedPnl: number;
|
|
171
|
+
realizedPnlPercentage: number;
|
|
170
172
|
totalEntryValue: number;
|
|
171
173
|
totalValue: number;
|
|
172
174
|
entryRatio: number;
|
|
@@ -221,6 +223,7 @@ export interface OpenPositionDto {
|
|
|
221
223
|
positionValue: number;
|
|
222
224
|
marginUsed: number;
|
|
223
225
|
unrealizedPnl: number;
|
|
226
|
+
unrealizedPnlPercentage: number;
|
|
224
227
|
longAssets: PositionAssetDetailDto[];
|
|
225
228
|
shortAssets: PositionAssetDetailDto[];
|
|
226
229
|
createdAt: string;
|
|
@@ -301,15 +304,22 @@ export interface BalanceSummaryDto {
|
|
|
301
304
|
* Agent wallet information
|
|
302
305
|
*/
|
|
303
306
|
export interface AgentWalletDto {
|
|
304
|
-
address
|
|
307
|
+
address?: string;
|
|
305
308
|
status: string;
|
|
306
309
|
}
|
|
310
|
+
export interface PlatformAccountSummaryResponseDto {
|
|
311
|
+
agentWalletAddress: string | null;
|
|
312
|
+
totalClosedTrades: number;
|
|
313
|
+
totalLimitOrderUsdValue?: number;
|
|
314
|
+
totalTwapChunkUsdValue?: number;
|
|
315
|
+
lastSyncedAt?: number;
|
|
316
|
+
}
|
|
307
317
|
/**
|
|
308
318
|
* Account balance response (renamed to AccountSummaryResponseDto for consistency)
|
|
309
319
|
*/
|
|
310
320
|
export interface AccountSummaryResponseDto {
|
|
311
321
|
balanceSummary: BalanceSummaryDto;
|
|
312
|
-
agentWallet
|
|
322
|
+
agentWallet?: AgentWalletDto;
|
|
313
323
|
}
|
|
314
324
|
/**
|
|
315
325
|
* Address management state
|
|
@@ -400,8 +410,10 @@ export interface CreateAgentWalletResponseDto {
|
|
|
400
410
|
agentWalletAddress: string;
|
|
401
411
|
message: string;
|
|
402
412
|
}
|
|
403
|
-
export interface
|
|
404
|
-
|
|
413
|
+
export interface ExtraAgent {
|
|
414
|
+
name: string;
|
|
415
|
+
address: string;
|
|
416
|
+
validUntil: number;
|
|
405
417
|
}
|
|
406
418
|
export interface AgentWalletState {
|
|
407
419
|
address: string | null;
|
|
@@ -416,6 +428,7 @@ export interface WebSocketMessage {
|
|
|
416
428
|
method: "subscribe" | "unsubscribe";
|
|
417
429
|
subscription: {
|
|
418
430
|
type: string;
|
|
431
|
+
dex?: string;
|
|
419
432
|
coin?: string;
|
|
420
433
|
interval?: string;
|
|
421
434
|
user?: string;
|
|
@@ -425,13 +438,44 @@ export interface WebSocketMessage {
|
|
|
425
438
|
/**
|
|
426
439
|
* WebSocket response from HyperLiquid native API
|
|
427
440
|
*/
|
|
428
|
-
export type HLChannel = '
|
|
441
|
+
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle';
|
|
429
442
|
export interface HLChannelDataMap {
|
|
430
|
-
|
|
443
|
+
webData3: WebData3Response;
|
|
431
444
|
allMids: WsAllMidsData;
|
|
432
445
|
activeAssetData: ActiveAssetData;
|
|
433
446
|
candle: CandleData;
|
|
434
447
|
}
|
|
448
|
+
export interface WebData3UserState {
|
|
449
|
+
agentAddress?: string;
|
|
450
|
+
agentValidUntil?: number;
|
|
451
|
+
cumLedger: string;
|
|
452
|
+
serverTime: number;
|
|
453
|
+
isVault: boolean;
|
|
454
|
+
user: string;
|
|
455
|
+
dexAbstractionEnabled?: boolean;
|
|
456
|
+
}
|
|
457
|
+
export interface WebData3AssetCtx {
|
|
458
|
+
funding: string;
|
|
459
|
+
openInterest: string;
|
|
460
|
+
prevDayPx: string;
|
|
461
|
+
dayNtlVlm: string;
|
|
462
|
+
premium: string | null;
|
|
463
|
+
oraclePx: string;
|
|
464
|
+
markPx: string;
|
|
465
|
+
midPx: string | null;
|
|
466
|
+
impactPxs: string[] | null;
|
|
467
|
+
dayBaseVlm: string;
|
|
468
|
+
}
|
|
469
|
+
export interface WebData3PerpDexState {
|
|
470
|
+
clearinghouseState: ClearinghouseState;
|
|
471
|
+
totalVaultEquity: string;
|
|
472
|
+
assetCtxs: WebData3AssetCtx[];
|
|
473
|
+
perpsAtOpenInterestCap: string[];
|
|
474
|
+
}
|
|
475
|
+
export interface WebData3Response {
|
|
476
|
+
userState: WebData3UserState;
|
|
477
|
+
perpDexStates: WebData3PerpDexState[];
|
|
478
|
+
}
|
|
435
479
|
export interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
|
|
436
480
|
channel: T;
|
|
437
481
|
data: HLChannelDataMap[T];
|
|
@@ -465,17 +509,24 @@ export interface UniverseAsset {
|
|
|
465
509
|
onlyIsolated?: boolean;
|
|
466
510
|
isDelisted?: boolean;
|
|
467
511
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
export interface
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
512
|
+
export interface PerpMetaAsset extends UniverseAsset {
|
|
513
|
+
marginTableId: number;
|
|
514
|
+
}
|
|
515
|
+
export interface MarginTier {
|
|
516
|
+
lowerBound: string;
|
|
517
|
+
maxLeverage: number;
|
|
518
|
+
}
|
|
519
|
+
export interface MarginTableDef {
|
|
520
|
+
description: string;
|
|
521
|
+
marginTiers: MarginTier[];
|
|
478
522
|
}
|
|
523
|
+
export type MarginTablesEntry = [number, MarginTableDef];
|
|
524
|
+
export interface AllPerpMetasItem {
|
|
525
|
+
universe: PerpMetaAsset[];
|
|
526
|
+
marginTables: MarginTablesEntry[];
|
|
527
|
+
collateralToken: number;
|
|
528
|
+
}
|
|
529
|
+
export type AllPerpMetasResponse = AllPerpMetasItem[];
|
|
479
530
|
export interface ClearinghouseState {
|
|
480
531
|
assetPositions: AssetPosition[];
|
|
481
532
|
crossMaintenanceMarginUsed: string;
|
|
@@ -577,9 +628,6 @@ export interface ActiveAssetData {
|
|
|
577
628
|
availableToTrade: [string, string];
|
|
578
629
|
markPx: string;
|
|
579
630
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Token metadata from WebData2 and AllMids
|
|
582
|
-
*/
|
|
583
631
|
export interface TokenMetadata {
|
|
584
632
|
currentPrice: number;
|
|
585
633
|
prevDayPrice: number;
|
|
@@ -611,7 +659,7 @@ export interface TokenConflict {
|
|
|
611
659
|
conflictMessage: string;
|
|
612
660
|
}
|
|
613
661
|
export interface AssetMarketData {
|
|
614
|
-
asset: AssetCtx;
|
|
662
|
+
asset: WebData3AssetCtx | AssetCtx;
|
|
615
663
|
universe: UniverseAsset;
|
|
616
664
|
}
|
|
617
665
|
export interface PairAssetDto {
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import type { AccountSummaryResponseDto,
|
|
1
|
+
import type { AccountSummaryResponseDto, ClearinghouseState, ExtraAgent, PlatformAccountSummaryResponseDto } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Account summary calculation utility class
|
|
4
4
|
*/
|
|
5
5
|
export declare class AccountSummaryCalculator {
|
|
6
|
-
private
|
|
7
|
-
constructor(
|
|
6
|
+
private clearinghouseState;
|
|
7
|
+
constructor(clearinghouseState: ClearinghouseState | null);
|
|
8
8
|
/**
|
|
9
|
-
* Calculate account summary from
|
|
9
|
+
* Calculate account summary from real-time clearinghouse state and platform orders
|
|
10
10
|
*/
|
|
11
|
-
calculateAccountSummary(platformAccountSummary:
|
|
12
|
-
|
|
13
|
-
* Calculate total USD value of open limit orders
|
|
14
|
-
*/
|
|
15
|
-
private calculateTotalLimitOrderValue;
|
|
16
|
-
/**
|
|
17
|
-
* Get real-time clearinghouse state from webData2
|
|
18
|
-
*/
|
|
19
|
-
getClearinghouseState(): import("../types").ClearinghouseState | null;
|
|
11
|
+
calculateAccountSummary(platformAccountSummary: PlatformAccountSummaryResponseDto | null, registeredAgentWallets: ExtraAgent[]): AccountSummaryResponseDto | null;
|
|
12
|
+
getClearinghouseState(): ClearinghouseState | null;
|
|
20
13
|
/**
|
|
21
14
|
* Check if real-time data is available
|
|
22
15
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { OpenPositionDto, RawPositionDto,
|
|
2
|
-
export declare const buildPositionValue: (rawPositions: RawPositionDto[],
|
|
1
|
+
import { OpenPositionDto, RawPositionDto, ClearinghouseState, WsAllMidsData } from "../types";
|
|
2
|
+
export declare const buildPositionValue: (rawPositions: RawPositionDto[], clearinghouseState: ClearinghouseState, allMids: WsAllMidsData) => OpenPositionDto[];
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
* @param displaySymbol e.g., "XYZ100"
|
|
9
|
+
* @param displayToFull map of display -> full (e.g., "XYZ100" -> "xyz:XYZ100")
|
|
10
|
+
*/
|
|
11
|
+
export declare function toBackendSymbol(displaySymbol: string, displayToFull: Map<string, string>): string;
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebData3AssetCtx } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Extracts token metadata from
|
|
3
|
+
* Extracts token metadata from aggregated WebData3 contexts and AllMids data
|
|
4
4
|
*/
|
|
5
5
|
export declare class TokenMetadataExtractor {
|
|
6
6
|
/**
|
|
7
7
|
* Extracts comprehensive token metadata
|
|
8
8
|
* @param symbol - Token symbol
|
|
9
|
-
* @param
|
|
9
|
+
* @param perpMetaAssets - Aggregated universe assets (flattened across dexes)
|
|
10
|
+
* @param finalAssetContexts - Aggregated asset contexts (flattened across dexes)
|
|
10
11
|
* @param allMids - AllMids data containing current prices
|
|
11
12
|
* @param activeAssetData - Optional active asset data containing leverage information
|
|
12
13
|
* @returns TokenMetadata or null if token not found
|
|
13
14
|
*/
|
|
14
|
-
static extractTokenMetadata(symbol: string,
|
|
15
|
+
static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): TokenMetadata | null;
|
|
15
16
|
/**
|
|
16
17
|
* Extracts metadata for multiple tokens
|
|
17
18
|
* @param symbols - Array of token symbols
|
|
18
|
-
* @param
|
|
19
|
+
* @param perpMetaAssets - Aggregated universe assets
|
|
20
|
+
* @param finalAssetContexts - Aggregated asset contexts
|
|
19
21
|
* @param allMids - AllMids data
|
|
20
22
|
* @param activeAssetData - Optional active asset data containing leverage information
|
|
21
23
|
* @returns Record of symbol to TokenMetadata
|
|
22
24
|
*/
|
|
23
|
-
static extractMultipleTokensMetadata(symbols: string[],
|
|
25
|
+
static extractMultipleTokensMetadata(symbols: string[], perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): Record<string, TokenMetadata | null>;
|
|
24
26
|
/**
|
|
25
|
-
* Checks if token data is available in
|
|
27
|
+
* Checks if token data is available in aggregated universe assets
|
|
26
28
|
* @param symbol - Token symbol
|
|
27
|
-
* @param
|
|
29
|
+
* @param perpMetaAssets - Aggregated universe assets
|
|
28
30
|
* @returns boolean indicating if token exists in universe
|
|
29
31
|
*/
|
|
30
|
-
static isTokenAvailable(symbol: string,
|
|
32
|
+
static isTokenAvailable(symbol: string, perpMetaAssets: UniverseAsset[] | null): boolean;
|
|
31
33
|
}
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export interface UseHyperliquidWebSocketProps {
|
|
2
2
|
wsUrl: string;
|
|
3
3
|
address: string | null;
|
|
4
|
+
enabled?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => {
|
|
6
|
+
export declare const useHyperliquidWebSocket: ({ wsUrl, address, enabled, }: UseHyperliquidWebSocketProps) => {
|
|
6
7
|
isConnected: boolean;
|
|
7
8
|
lastError: string | null;
|
|
8
9
|
};
|