@pear-protocol/hyperliquid-sdk 0.1.0 → 0.1.1-9.2-pnl

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,4 +1,4 @@
1
- import React, { ReactNode } from 'react';
1
+ import React, { ReactNode } from "react";
2
2
  export interface PearHyperliquidContextType {
3
3
  clientId: string;
4
4
  apiBaseUrl: string;
@@ -9,6 +9,8 @@ interface TokenHistoricalPriceData {
9
9
  candles: CandleData[];
10
10
  oldestTime: number | null;
11
11
  latestTime: number | null;
12
+ requestedRanges: HistoricalRange[];
13
+ noDataBefore: number | null;
12
14
  }
13
15
  interface HistoricalPriceDataState {
14
16
  historicalPriceData: Record<string, TokenHistoricalPriceData>;
@@ -16,6 +18,7 @@ interface HistoricalPriceDataState {
16
18
  addHistoricalPriceData: (symbol: string, interval: CandleInterval, candles: CandleData[], range: HistoricalRange) => void;
17
19
  hasHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => boolean;
18
20
  getHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => CandleData[];
21
+ getEffectiveDataBoundary: (symbols: string[], interval: CandleInterval) => number | null;
19
22
  setTokenLoading: (symbol: string, loading: boolean) => void;
20
23
  isTokenLoading: (symbol: string) => boolean;
21
24
  removeTokenPriceData: (symbol: string, interval: CandleInterval) => void;
@@ -1,5 +1,5 @@
1
- import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, TokenMetadata, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from '../types';
2
- type TokenMetadataBySymbol = Record<string, TokenMetadata | null>;
1
+ import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData, PerpDexsResponse } from "../types";
2
+ import { TokenMetadataBySymbol } from "../utils/token-metadata-extractor";
3
3
  interface HyperliquidDataState {
4
4
  allMids: WsAllMidsData | null;
5
5
  activeAssetData: Record<string, ActiveAssetData> | null;
@@ -10,6 +10,9 @@ interface HyperliquidDataState {
10
10
  rawClearinghouseStates: [string, ClearinghouseState][] | null;
11
11
  perpMetaAssets: UniverseAsset[] | null;
12
12
  tokenMetadata: TokenMetadataBySymbol;
13
+ perpDexs: PerpDexsResponse | null;
14
+ perpMetasByDex: Map<string, UniverseAsset[]> | null;
15
+ assetContextsByDex: Map<string, WebData3AssetCtx[]> | null;
13
16
  setAllMids: (value: WsAllMidsData | null) => void;
14
17
  setActiveAssetData: (value: Record<string, ActiveAssetData> | null | ((prev: Record<string, ActiveAssetData> | null) => Record<string, ActiveAssetData> | null)) => void;
15
18
  deleteActiveAssetData: (key: string) => void;
@@ -22,6 +25,10 @@ interface HyperliquidDataState {
22
25
  setAggregatedClearingHouseState: (value: ClearinghouseState | null) => void;
23
26
  setRawClearinghouseStates: (value: [string, ClearinghouseState][] | null) => void;
24
27
  setPerpMetaAssets: (value: UniverseAsset[] | null) => void;
28
+ setPerpDexs: (value: PerpDexsResponse | null) => void;
29
+ setPerpMetasByDex: (value: Map<string, UniverseAsset[]> | null) => void;
30
+ setAssetContextsByDex: (value: Map<string, WebData3AssetCtx[]> | null) => void;
31
+ clearUserData: () => void;
25
32
  }
26
33
  export declare const useHyperliquidData: import("zustand").UseBoundStore<import("zustand").StoreApi<HyperliquidDataState>>;
27
34
  export {};
@@ -1,4 +1,4 @@
1
- import type { TokenSelection, TokenMetadata, ActiveAssetsResponse, UniverseAsset } from "../types";
1
+ import type { TokenSelection, TokenMetadata, ActiveAssetsResponse } from "../types";
2
2
  export interface TokenSelectionMetadataState {
3
3
  isPriceDataReady: boolean;
4
4
  isLoading: boolean;
@@ -12,10 +12,9 @@ export interface TokenSelectionMetadataState {
12
12
  volume: string;
13
13
  sumNetFunding: number;
14
14
  maxLeverage: number;
15
- minMargin: number;
15
+ minSize: Record<string, number>;
16
16
  leverageMatched: boolean;
17
17
  recompute: (args: {
18
- perpMetaAssets: UniverseAsset[] | null;
19
18
  tokenMetadata: Record<string, TokenMetadata | null>;
20
19
  marketData: ActiveAssetsResponse | null;
21
20
  longTokens: TokenSelection[];
@@ -1,8 +1,9 @@
1
- import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent, SpotState } from "../types";
1
+ import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent, SpotState, UserAbstraction } from "../types";
2
2
  interface UserDataState {
3
3
  accessToken: string | null;
4
4
  refreshToken: string | null;
5
5
  isAuthenticated: boolean;
6
+ isReady: boolean;
6
7
  address: string | null;
7
8
  tradeHistories: TradeHistoryDataDto[] | null;
8
9
  rawOpenPositions: RawPositionDto[] | null;
@@ -12,6 +13,7 @@ interface UserDataState {
12
13
  notifications: NotificationDto[] | null;
13
14
  userExtraAgents: ExtraAgent[] | null;
14
15
  spotState: SpotState | null;
16
+ userAbstractionMode: UserAbstraction | null;
15
17
  setAccessToken: (token: string | null) => void;
16
18
  setRefreshToken: (token: string | null) => void;
17
19
  setIsAuthenticated: (value: boolean) => void;
@@ -24,6 +26,8 @@ interface UserDataState {
24
26
  setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
25
27
  setNotifications: (value: NotificationDto[] | null) => void;
26
28
  setSpotState: (value: SpotState | null) => void;
29
+ setUserAbstractionMode: (value: UserAbstraction | null) => void;
30
+ setIsReady: (value: boolean) => void;
27
31
  clean: () => void;
28
32
  }
29
33
  export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
package/dist/types.d.ts CHANGED
@@ -200,6 +200,7 @@ export interface TwapMonitoringDto {
200
200
  export interface TradeHistoryAssetDataDto {
201
201
  coin: string;
202
202
  entryWeight: number;
203
+ closeWeight: number;
203
204
  entryPrice: number;
204
205
  limitPrice: number;
205
206
  leverage: number;
@@ -255,7 +256,9 @@ export interface PositionAssetDetailDto {
255
256
  unrealizedPnl: number;
256
257
  liquidationPrice: number;
257
258
  initialWeight: number;
259
+ currentWeight: number;
258
260
  fundingPaid?: number;
261
+ targetWeight?: number;
259
262
  metadata?: TokenMetadata | null;
260
263
  }
261
264
  export interface TpSlThreshold {
@@ -563,6 +566,7 @@ export interface HLChannelDataMap {
563
566
  allDexsAssetCtxs: AllDexsAssetCtxsData;
564
567
  userFills: any;
565
568
  }
569
+ export type UserAbstraction = 'dexAbstraction' | 'disabled' | 'unifiedAccount' | 'portfolioMargin';
566
570
  export interface WebData3UserState {
567
571
  agentAddress?: string;
568
572
  agentValidUntil?: number;
@@ -571,6 +575,7 @@ export interface WebData3UserState {
571
575
  isVault: boolean;
572
576
  user: string;
573
577
  dexAbstractionEnabled?: boolean;
578
+ abstraction: UserAbstraction;
574
579
  }
575
580
  export interface WebData3AssetCtx {
576
581
  funding: string;
@@ -628,8 +633,10 @@ export interface AssetCtx {
628
633
  * Collateral token type
629
634
  * 0 = USDC
630
635
  * 360 = USDH
636
+ * 235 = USDE
637
+ * 268 = USDT0
631
638
  */
632
- export type CollateralToken = 'USDC' | 'USDH';
639
+ export type CollateralToken = 'USDC' | 'USDH' | 'USDE' | 'USDT0';
633
640
  /**
634
641
  * Universe asset metadata
635
642
  */
@@ -729,6 +736,7 @@ export interface RawAssetDto {
729
736
  side: string;
730
737
  fundingPaid?: number;
731
738
  leverage: number;
739
+ targetWeight?: number;
732
740
  }
733
741
  /**
734
742
  * Raw position data from open-positions channel
@@ -804,6 +812,7 @@ export interface AssetMarketData {
804
812
  export interface PairAssetDto {
805
813
  asset: string;
806
814
  weight: number;
815
+ metadata?: TokenMetadata | null;
807
816
  }
808
817
  export interface ActiveAssetGroupItem {
809
818
  longAssets: PairAssetDto[];
@@ -817,7 +826,6 @@ export interface ActiveAssetGroupItem {
817
826
  weightedRatio?: string;
818
827
  weightedPrevRatio?: string;
819
828
  weightedChange24h?: string;
820
- collateralType: 'USDC' | 'USDH' | 'MIXED';
821
829
  }
822
830
  export interface ActiveAssetsResponse {
823
831
  active: ActiveAssetGroupItem[];
@@ -884,3 +892,64 @@ export interface TokenEntry {
884
892
  symbol: string;
885
893
  data: AssetMarketData;
886
894
  }
895
+ export interface PerpDex {
896
+ name: string;
897
+ fullName: string;
898
+ deployer: string;
899
+ oracleUpdater: string | null;
900
+ feeRecipient: string | null;
901
+ deployerFeeScale: string;
902
+ assetToStreamingOiCap: [string, string][];
903
+ assetToFundingMultiplier: [string, string][];
904
+ subDeployers: [string, string[]][];
905
+ lastDeployerFeeScaleChangeTime: string;
906
+ }
907
+ export type PerpDexsResponse = (PerpDex | null)[];
908
+ export interface SpotBalances {
909
+ [coin: string]: number;
910
+ }
911
+ export interface AvailableToTrades {
912
+ [collateralCoin: string]: number;
913
+ }
914
+ export type ExecutionType = "MARKET" | "TRIGGER" | "TWAP" | "LADDER" | "TP" | "SL" | "SPOT_MARKET" | "SPOT_LIMIT" | "SPOT_TWAP";
915
+ export type TpSlThresholdType = "PERCENTAGE" | "DOLLAR" | "POSITION_VALUE" | "PRICE" | "PRICE_RATIO" | "WEIGHTED_RATIO";
916
+ export interface PairAssetInput {
917
+ asset: string;
918
+ weight?: number;
919
+ }
920
+ export interface TpSlThresholdInput {
921
+ type: TpSlThresholdType;
922
+ value?: number;
923
+ isTrailing?: boolean;
924
+ trailingDeltaValue?: number;
925
+ trailingActivationValue?: number;
926
+ }
927
+ export interface LadderConfigInput {
928
+ ratioStart: number;
929
+ ratioEnd: number;
930
+ numberOfLevels: number;
931
+ }
932
+ export interface CreatePositionRequestInput {
933
+ slippage: number;
934
+ executionType: ExecutionType;
935
+ leverage: number;
936
+ usdValue: number;
937
+ longAssets?: PairAssetInput[];
938
+ shortAssets?: PairAssetInput[];
939
+ triggerValue?: string | number;
940
+ triggerType?: TriggerType;
941
+ direction?: "MORE_THAN" | "LESS_THAN";
942
+ assetName?: string;
943
+ marketCode?: string;
944
+ twapDuration?: number;
945
+ twapIntervalSeconds?: number;
946
+ randomizeExecution?: boolean;
947
+ referralCode?: string;
948
+ ladderConfig?: LadderConfigInput;
949
+ takeProfit?: TpSlThresholdInput | null;
950
+ stopLoss?: TpSlThresholdInput | null;
951
+ }
952
+ export interface CreatePositionResponseDto {
953
+ orderId: string;
954
+ fills?: ExternalFillDto[];
955
+ }
@@ -1,5 +1,5 @@
1
- import type { AxiosInstance } from 'axios';
2
- import { ApiErrorResponse } from '../types';
1
+ import type { AxiosInstance } from "axios";
2
+ import { ApiErrorResponse } from "../types";
3
3
  export declare function toApiError(error: unknown): ApiErrorResponse;
4
4
  export declare function joinUrl(baseUrl: string, path: string): string;
5
5
  /**
@@ -1,4 +1,4 @@
1
- import type { PairAssetInput } from "../clients/positions";
1
+ import { PairAssetInput } from "../types";
2
2
  /**
3
3
  * Minimum USD value required per asset when creating a position
4
4
  */
@@ -3,26 +3,6 @@ import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebD
3
3
  * Extracts token metadata from aggregated WebData3 contexts and AllMids data
4
4
  */
5
5
  export declare class TokenMetadataExtractor {
6
- /**
7
- * Extracts comprehensive token metadata
8
- * @param symbol - Token symbol (e.g., "BTC", "TSLA")
9
- * @param perpMetaAssets - Aggregated universe assets (flattened across dexes)
10
- * @param finalAssetContexts - Aggregated asset contexts (flattened across dexes)
11
- * @param allMids - AllMids data containing current prices
12
- * @param activeAssetData - Optional active asset data containing leverage information
13
- * @returns TokenMetadata or null if token not found
14
- */
15
- static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): TokenMetadata | null;
16
- /**
17
- * Extracts metadata for multiple tokens
18
- * @param tokens - Array of token strings (e.g., "BTC", "TSLA")
19
- * @param perpMetaAssets - Aggregated universe assets
20
- * @param finalAssetContexts - Aggregated asset contexts
21
- * @param allMids - AllMids data
22
- * @param activeAssetData - Optional active asset data containing leverage information
23
- * @returns Record of token string to TokenMetadata (keys match input tokens exactly)
24
- */
25
- static extractMultipleTokensMetadata(tokens: string[], perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): Record<string, TokenMetadata | null>;
26
6
  /**
27
7
  * Checks if token data is available in aggregated universe assets
28
8
  * @param symbol - Token symbol
@@ -30,4 +10,39 @@ export declare class TokenMetadataExtractor {
30
10
  * @returns boolean indicating if token exists in universe
31
11
  */
32
12
  static isTokenAvailable(symbol: string, perpMetaAssets: UniverseAsset[] | null): boolean;
13
+ /**
14
+ * Extracts token metadata using DEX-aware lookup (correctly matches perpMetas to assetContexts)
15
+ * @param symbol - Token symbol (e.g., "BTC", "TSLA")
16
+ * @param perpMetasByDex - Map of DEX name to UniverseAsset[]
17
+ * @param assetContextsByDex - Map of DEX name to WebData3AssetCtx[]
18
+ * @param allMids - AllMids data containing current prices
19
+ * @param activeAssetData - Optional active asset data containing leverage information
20
+ * @param finalAtOICaps - Optional array of symbols at OI caps
21
+ * @returns TokenMetadata or null if token not found
22
+ */
23
+ static extractTokenMetadataByDex(symbol: string, perpMetasByDex: Map<string, UniverseAsset[]>, assetContextsByDex: Map<string, WebData3AssetCtx[]>, allMids: WsAllMidsData, activeAssetData?: Record<string, ActiveAssetData> | null, finalAtOICaps?: string[] | null): TokenMetadata | null;
33
24
  }
25
+ export type TokenMetadataBySymbol = Record<string, TokenMetadata | null>;
26
+ export type TokenMetadataInputs = {
27
+ perpMetaAssets: UniverseAsset[] | null;
28
+ finalAssetContexts: WebData3AssetCtx[] | null;
29
+ allMids: WsAllMidsData | null;
30
+ activeAssetData: Record<string, ActiveAssetData> | null;
31
+ finalAtOICaps: string[] | null;
32
+ perpMetasByDex?: Map<string, UniverseAsset[]> | null;
33
+ assetContextsByDex?: Map<string, WebData3AssetCtx[]> | null;
34
+ };
35
+ export type RefreshTokenMetadataOptions = {
36
+ symbols?: string[];
37
+ oiCapsOnly?: boolean;
38
+ };
39
+ export declare const refreshTokenMetadata: (state: {
40
+ perpMetaAssets: UniverseAsset[] | null;
41
+ finalAssetContexts: WebData3AssetCtx[] | null;
42
+ allMids: WsAllMidsData | null;
43
+ activeAssetData: Record<string, ActiveAssetData> | null;
44
+ finalAtOICaps: string[] | null;
45
+ tokenMetadata: TokenMetadataBySymbol;
46
+ perpMetasByDex?: Map<string, UniverseAsset[]> | null;
47
+ assetContextsByDex?: Map<string, WebData3AssetCtx[]> | null;
48
+ }, overrides: Partial<TokenMetadataInputs>, options?: RefreshTokenMetadataOptions) => TokenMetadataBySymbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.19.2-pnl",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",