@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.
@@ -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, WebData2Response, WsAllMidsData, ActiveAssetsResponse } from "../types";
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
- webData2: WebData2Response | null;
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' | 'webData2' | 'allMids' | 'activeAssetData';
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: string;
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: AgentWalletDto;
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 UseAgentWalletOptions {
404
- baseUrl: string;
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 = 'webData2' | 'allMids' | 'activeAssetData' | 'candle';
438
+ export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle';
429
439
  export interface HLChannelDataMap {
430
- webData2: WebData2Response;
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
- * WebData2 response structure
470
- */
471
- export interface WebData2Response {
472
- assetCtxs: AssetCtx[];
473
- meta: {
474
- universe: UniverseAsset[];
475
- };
476
- clearinghouseState: ClearinghouseState;
477
- perpsAtOpenInterestCap?: string[];
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, WebData2Response, OpenLimitOrderDto } from '../types';
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 webData2;
7
- constructor(webData2: WebData2Response | null);
6
+ private clearinghouseState;
7
+ constructor(clearinghouseState: ClearinghouseState | null);
8
8
  /**
9
- * Calculate account summary from webData2 and platform orders
9
+ * Calculate account summary from real-time clearinghouse state and platform orders
10
10
  */
11
- calculateAccountSummary(platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, agentWalletAddress?: string, agentWalletStatus?: string): AccountSummaryResponseDto | null;
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, WebData2Response, WsAllMidsData } from "../types";
2
- export declare const buildPositionValue: (rawPositions: RawPositionDto[], webData2: WebData2Response, allMids: WsAllMidsData) => OpenPositionDto[];
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 { WebData2Response, WsAllMidsData, TokenMetadata, ActiveAssetData } from '../types';
1
+ import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebData3AssetCtx } from '../types';
2
2
  /**
3
- * Extracts token metadata from WebData2 and AllMids data
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 webData2 - WebData2 response containing asset context and universe data
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, webData2: WebData2Response | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): TokenMetadata | null;
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 webData2 - WebData2 response
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[], webData2: WebData2Response | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): Record<string, TokenMetadata | null>;
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 WebData2
27
+ * Checks if token data is available in aggregated universe assets
26
28
  * @param symbol - Token symbol
27
- * @param webData2 - WebData2 response
29
+ * @param perpMetaAssets - Aggregated universe assets
28
30
  * @returns boolean indicating if token exists in universe
29
31
  */
30
- static isTokenAvailable(symbol: string, webData2: WebData2Response | null): boolean;
32
+ static isTokenAvailable(symbol: string, perpMetaAssets: UniverseAsset[] | null): boolean;
31
33
  }
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",