@pear-protocol/hyperliquid-sdk 0.0.49 → 0.0.50
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 +81 -96
- package/dist/index.js +399 -307
- package/dist/provider.d.ts +0 -20
- package/dist/store/tokenSelectionMetadataStore.d.ts +3 -2
- package/dist/types.d.ts +66 -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
|
*/
|
|
@@ -301,15 +301,22 @@ export interface BalanceSummaryDto {
|
|
|
301
301
|
* Agent wallet information
|
|
302
302
|
*/
|
|
303
303
|
export interface AgentWalletDto {
|
|
304
|
-
address
|
|
304
|
+
address?: string;
|
|
305
305
|
status: string;
|
|
306
306
|
}
|
|
307
|
+
export interface PlatformAccountSummaryResponseDto {
|
|
308
|
+
agentWalletAddress: string | null;
|
|
309
|
+
totalClosedTrades: number;
|
|
310
|
+
totalLimitOrderUsdValue?: number;
|
|
311
|
+
totalTwapChunkUsdValue?: number;
|
|
312
|
+
lastSyncedAt?: number;
|
|
313
|
+
}
|
|
307
314
|
/**
|
|
308
315
|
* Account balance response (renamed to AccountSummaryResponseDto for consistency)
|
|
309
316
|
*/
|
|
310
317
|
export interface AccountSummaryResponseDto {
|
|
311
318
|
balanceSummary: BalanceSummaryDto;
|
|
312
|
-
agentWallet
|
|
319
|
+
agentWallet?: AgentWalletDto;
|
|
313
320
|
}
|
|
314
321
|
/**
|
|
315
322
|
* Address management state
|
|
@@ -400,8 +407,10 @@ export interface CreateAgentWalletResponseDto {
|
|
|
400
407
|
agentWalletAddress: string;
|
|
401
408
|
message: string;
|
|
402
409
|
}
|
|
403
|
-
export interface
|
|
404
|
-
|
|
410
|
+
export interface ExtraAgent {
|
|
411
|
+
name: string;
|
|
412
|
+
address: string;
|
|
413
|
+
validUntil: number;
|
|
405
414
|
}
|
|
406
415
|
export interface AgentWalletState {
|
|
407
416
|
address: string | null;
|
|
@@ -416,6 +425,7 @@ export interface WebSocketMessage {
|
|
|
416
425
|
method: "subscribe" | "unsubscribe";
|
|
417
426
|
subscription: {
|
|
418
427
|
type: string;
|
|
428
|
+
dex?: string;
|
|
419
429
|
coin?: string;
|
|
420
430
|
interval?: string;
|
|
421
431
|
user?: string;
|
|
@@ -425,13 +435,44 @@ export interface WebSocketMessage {
|
|
|
425
435
|
/**
|
|
426
436
|
* WebSocket response from HyperLiquid native API
|
|
427
437
|
*/
|
|
428
|
-
export type HLChannel = '
|
|
438
|
+
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle';
|
|
429
439
|
export interface HLChannelDataMap {
|
|
430
|
-
|
|
440
|
+
webData3: WebData3Response;
|
|
431
441
|
allMids: WsAllMidsData;
|
|
432
442
|
activeAssetData: ActiveAssetData;
|
|
433
443
|
candle: CandleData;
|
|
434
444
|
}
|
|
445
|
+
export interface WebData3UserState {
|
|
446
|
+
agentAddress?: string;
|
|
447
|
+
agentValidUntil?: number;
|
|
448
|
+
cumLedger: string;
|
|
449
|
+
serverTime: number;
|
|
450
|
+
isVault: boolean;
|
|
451
|
+
user: string;
|
|
452
|
+
dexAbstractionEnabled?: boolean;
|
|
453
|
+
}
|
|
454
|
+
export interface WebData3AssetCtx {
|
|
455
|
+
funding: string;
|
|
456
|
+
openInterest: string;
|
|
457
|
+
prevDayPx: string;
|
|
458
|
+
dayNtlVlm: string;
|
|
459
|
+
premium: string | null;
|
|
460
|
+
oraclePx: string;
|
|
461
|
+
markPx: string;
|
|
462
|
+
midPx: string | null;
|
|
463
|
+
impactPxs: string[] | null;
|
|
464
|
+
dayBaseVlm: string;
|
|
465
|
+
}
|
|
466
|
+
export interface WebData3PerpDexState {
|
|
467
|
+
clearinghouseState: ClearinghouseState;
|
|
468
|
+
totalVaultEquity: string;
|
|
469
|
+
assetCtxs: WebData3AssetCtx[];
|
|
470
|
+
perpsAtOpenInterestCap: string[];
|
|
471
|
+
}
|
|
472
|
+
export interface WebData3Response {
|
|
473
|
+
userState: WebData3UserState;
|
|
474
|
+
perpDexStates: WebData3PerpDexState[];
|
|
475
|
+
}
|
|
435
476
|
export interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
|
|
436
477
|
channel: T;
|
|
437
478
|
data: HLChannelDataMap[T];
|
|
@@ -465,17 +506,24 @@ export interface UniverseAsset {
|
|
|
465
506
|
onlyIsolated?: boolean;
|
|
466
507
|
isDelisted?: boolean;
|
|
467
508
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
export interface
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
509
|
+
export interface PerpMetaAsset extends UniverseAsset {
|
|
510
|
+
marginTableId: number;
|
|
511
|
+
}
|
|
512
|
+
export interface MarginTier {
|
|
513
|
+
lowerBound: string;
|
|
514
|
+
maxLeverage: number;
|
|
515
|
+
}
|
|
516
|
+
export interface MarginTableDef {
|
|
517
|
+
description: string;
|
|
518
|
+
marginTiers: MarginTier[];
|
|
478
519
|
}
|
|
520
|
+
export type MarginTablesEntry = [number, MarginTableDef];
|
|
521
|
+
export interface AllPerpMetasItem {
|
|
522
|
+
universe: PerpMetaAsset[];
|
|
523
|
+
marginTables: MarginTablesEntry[];
|
|
524
|
+
collateralToken: number;
|
|
525
|
+
}
|
|
526
|
+
export type AllPerpMetasResponse = AllPerpMetasItem[];
|
|
479
527
|
export interface ClearinghouseState {
|
|
480
528
|
assetPositions: AssetPosition[];
|
|
481
529
|
crossMaintenanceMarginUsed: string;
|
|
@@ -577,9 +625,6 @@ export interface ActiveAssetData {
|
|
|
577
625
|
availableToTrade: [string, string];
|
|
578
626
|
markPx: string;
|
|
579
627
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Token metadata from WebData2 and AllMids
|
|
582
|
-
*/
|
|
583
628
|
export interface TokenMetadata {
|
|
584
629
|
currentPrice: number;
|
|
585
630
|
prevDayPrice: number;
|
|
@@ -611,7 +656,7 @@ export interface TokenConflict {
|
|
|
611
656
|
conflictMessage: string;
|
|
612
657
|
}
|
|
613
658
|
export interface AssetMarketData {
|
|
614
|
-
asset: AssetCtx;
|
|
659
|
+
asset: WebData3AssetCtx | AssetCtx;
|
|
615
660
|
universe: UniverseAsset;
|
|
616
661
|
}
|
|
617
662
|
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
|
};
|