@pear-protocol/hyperliquid-sdk 0.0.72 → 0.0.73-beta.2
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/hooks/useAuth.d.ts +5 -3
- package/dist/index.d.ts +26 -5
- package/dist/index.js +115 -54
- package/dist/store/historicalPriceDataStore.d.ts +12 -1
- package/dist/store/hyperliquidDataStore.d.ts +25 -1
- package/dist/store/marketDataStore.d.ts +10 -1
- package/dist/store/tokenSelectionMetadataStore.d.ts +1 -1
- package/dist/store/userDataStore.d.ts +30 -1
- package/dist/store/userSelection.d.ts +1 -1
- package/package.json +3 -2
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { GetEIP712MessageResponse } from "../types";
|
|
2
2
|
export declare function useAuth(): {
|
|
3
3
|
readonly isReady: boolean;
|
|
4
|
-
readonly isAuthenticated:
|
|
5
|
-
readonly accessToken:
|
|
6
|
-
readonly refreshToken:
|
|
4
|
+
readonly isAuthenticated: boolean;
|
|
5
|
+
readonly accessToken: string | null;
|
|
6
|
+
readonly refreshToken: string | null;
|
|
7
7
|
readonly getEip712: (address: string) => Promise<GetEIP712MessageResponse>;
|
|
8
8
|
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
9
9
|
readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
|
|
10
10
|
readonly refreshTokens: () => Promise<import("../types").RefreshTokenResponse>;
|
|
11
11
|
readonly logout: () => Promise<void>;
|
|
12
|
+
readonly setAddress: (address: string | null) => void;
|
|
13
|
+
readonly address: string | null;
|
|
12
14
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
import * as zustand from 'zustand';
|
|
2
3
|
|
|
3
4
|
interface PearHyperliquidContextType {
|
|
4
5
|
clientId: string;
|
|
@@ -781,7 +782,18 @@ interface TokenHistoricalPriceData {
|
|
|
781
782
|
oldestTime: number | null;
|
|
782
783
|
latestTime: number | null;
|
|
783
784
|
}
|
|
784
|
-
|
|
785
|
+
interface HistoricalPriceDataState {
|
|
786
|
+
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|
|
787
|
+
loadingTokens: Set<string>;
|
|
788
|
+
addHistoricalPriceData: (symbol: string, interval: CandleInterval, candles: CandleData[], range: HistoricalRange) => void;
|
|
789
|
+
hasHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => boolean;
|
|
790
|
+
getHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => CandleData[];
|
|
791
|
+
setTokenLoading: (symbol: string, loading: boolean) => void;
|
|
792
|
+
isTokenLoading: (symbol: string) => boolean;
|
|
793
|
+
removeTokenPriceData: (symbol: string, interval: CandleInterval) => void;
|
|
794
|
+
clearData: () => void;
|
|
795
|
+
}
|
|
796
|
+
declare const useHistoricalPriceDataStore: zustand.UseBoundStore<zustand.StoreApi<HistoricalPriceDataState>>;
|
|
785
797
|
|
|
786
798
|
interface UseHistoricalPriceDataReturn {
|
|
787
799
|
fetchHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
|
|
@@ -1127,14 +1139,16 @@ declare function usePortfolio(): UsePortfolioResult;
|
|
|
1127
1139
|
|
|
1128
1140
|
declare function useAuth(): {
|
|
1129
1141
|
readonly isReady: boolean;
|
|
1130
|
-
readonly isAuthenticated:
|
|
1131
|
-
readonly accessToken:
|
|
1132
|
-
readonly refreshToken:
|
|
1142
|
+
readonly isAuthenticated: boolean;
|
|
1143
|
+
readonly accessToken: string | null;
|
|
1144
|
+
readonly refreshToken: string | null;
|
|
1133
1145
|
readonly getEip712: (address: string) => Promise<GetEIP712MessageResponse>;
|
|
1134
1146
|
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
1135
1147
|
readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
|
|
1136
1148
|
readonly refreshTokens: () => Promise<RefreshTokenResponse>;
|
|
1137
1149
|
readonly logout: () => Promise<void>;
|
|
1150
|
+
readonly setAddress: (address: string | null) => void;
|
|
1151
|
+
readonly address: string | null;
|
|
1138
1152
|
};
|
|
1139
1153
|
|
|
1140
1154
|
interface UseHyperliquidWebSocketProps {
|
|
@@ -1331,7 +1345,14 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
|
|
|
1331
1345
|
minimumRequired?: number;
|
|
1332
1346
|
};
|
|
1333
1347
|
|
|
1334
|
-
|
|
1348
|
+
interface MarketDataState {
|
|
1349
|
+
marketData: ActiveAssetsResponse | null;
|
|
1350
|
+
marketDataAll: ActiveAssetsAllResponse | null;
|
|
1351
|
+
setMarketData: (value: ActiveAssetsResponse | null) => void;
|
|
1352
|
+
setMarketDataAll: (value: ActiveAssetsAllResponse | null) => void;
|
|
1353
|
+
clean: () => void;
|
|
1354
|
+
}
|
|
1355
|
+
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1335
1356
|
|
|
1336
1357
|
export { AccountSummaryCalculator, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, getPortfolio, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1337
1358
|
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateLeverageRequestInput, UpdateLeverageResponseDto, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useRef, useCallback, useEffect, useMemo, useContext, createContext } from 'react';
|
|
3
|
-
import { create } from 'zustand';
|
|
2
|
+
import React, { useState, useRef, useCallback, useEffect, useMemo, useContext, createContext } from 'react';
|
|
4
3
|
|
|
5
4
|
// Browser-compatible WebSocket ready state enum (mirrors native values)
|
|
6
5
|
var ReadyState;
|
|
@@ -11,10 +10,52 @@ var ReadyState;
|
|
|
11
10
|
ReadyState[ReadyState["CLOSED"] = 3] = "CLOSED";
|
|
12
11
|
})(ReadyState || (ReadyState = {}));
|
|
13
12
|
|
|
13
|
+
const createStoreImpl = (createState) => {
|
|
14
|
+
let state;
|
|
15
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
16
|
+
const setState = (partial, replace) => {
|
|
17
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
18
|
+
if (!Object.is(nextState, state)) {
|
|
19
|
+
const previousState = state;
|
|
20
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
21
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const getState = () => state;
|
|
25
|
+
const getInitialState = () => initialState;
|
|
26
|
+
const subscribe = (listener) => {
|
|
27
|
+
listeners.add(listener);
|
|
28
|
+
return () => listeners.delete(listener);
|
|
29
|
+
};
|
|
30
|
+
const api = { setState, getState, getInitialState, subscribe };
|
|
31
|
+
const initialState = state = createState(setState, getState, api);
|
|
32
|
+
return api;
|
|
33
|
+
};
|
|
34
|
+
const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
35
|
+
|
|
36
|
+
const identity = (arg) => arg;
|
|
37
|
+
function useStore(api, selector = identity) {
|
|
38
|
+
const slice = React.useSyncExternalStore(
|
|
39
|
+
api.subscribe,
|
|
40
|
+
React.useCallback(() => selector(api.getState()), [api, selector]),
|
|
41
|
+
React.useCallback(() => selector(api.getInitialState()), [api, selector])
|
|
42
|
+
);
|
|
43
|
+
React.useDebugValue(slice);
|
|
44
|
+
return slice;
|
|
45
|
+
}
|
|
46
|
+
const createImpl = (createState) => {
|
|
47
|
+
const api = createStore(createState);
|
|
48
|
+
const useBoundStore = (selector) => useStore(api, selector);
|
|
49
|
+
Object.assign(useBoundStore, api);
|
|
50
|
+
return useBoundStore;
|
|
51
|
+
};
|
|
52
|
+
const create = ((createState) => createState ? createImpl(createState) : createImpl);
|
|
53
|
+
|
|
14
54
|
const useUserData = create((set) => ({
|
|
15
55
|
accessToken: null,
|
|
16
56
|
refreshToken: null,
|
|
17
57
|
isAuthenticated: false,
|
|
58
|
+
isReady: false,
|
|
18
59
|
address: null,
|
|
19
60
|
tradeHistories: null,
|
|
20
61
|
rawOpenPositions: null,
|
|
@@ -26,17 +67,17 @@ const useUserData = create((set) => ({
|
|
|
26
67
|
setAccessToken: (token) => set({ accessToken: token }),
|
|
27
68
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
28
69
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
70
|
+
setIsReady: (value) => set({ isReady: value }),
|
|
71
|
+
setAddress: (address) => {
|
|
72
|
+
// if (typeof window !== "undefined") {
|
|
73
|
+
// if (address) {
|
|
74
|
+
// window.localStorage.setItem("address", address);
|
|
75
|
+
// } else {
|
|
76
|
+
// window.localStorage.removeItem("address");
|
|
77
|
+
// }
|
|
78
|
+
// }
|
|
79
|
+
set({ address });
|
|
80
|
+
},
|
|
40
81
|
setTradeHistories: (value) => set({ tradeHistories: value }),
|
|
41
82
|
setRawOpenPositions: (value) => set({ rawOpenPositions: value }),
|
|
42
83
|
setOpenOrders: (value) => set({ openOrders: value }),
|
|
@@ -44,10 +85,11 @@ const useUserData = create((set) => ({
|
|
|
44
85
|
setTwapDetails: (value) => set({ twapDetails: value }),
|
|
45
86
|
setNotifications: (value) => set({ notifications: value }),
|
|
46
87
|
clean: () => set({
|
|
47
|
-
accessToken: null,
|
|
48
|
-
refreshToken: null,
|
|
49
|
-
isAuthenticated: false,
|
|
50
|
-
|
|
88
|
+
// accessToken: null,
|
|
89
|
+
// refreshToken: null,
|
|
90
|
+
// isAuthenticated: false,
|
|
91
|
+
// isReady: false,
|
|
92
|
+
// address: null,
|
|
51
93
|
tradeHistories: null,
|
|
52
94
|
rawOpenPositions: null,
|
|
53
95
|
openOrders: null,
|
|
@@ -7164,38 +7206,50 @@ async function logout(baseUrl, refreshTokenVal) {
|
|
|
7164
7206
|
function useAuth() {
|
|
7165
7207
|
const context = useContext(PearHyperliquidContext);
|
|
7166
7208
|
if (!context) {
|
|
7167
|
-
throw new Error("
|
|
7209
|
+
throw new Error("useAuth must be used within a PearHyperliquidProvider");
|
|
7168
7210
|
}
|
|
7169
7211
|
const { apiBaseUrl, clientId } = context;
|
|
7170
|
-
const [isReady, setIsReady] = useState(false);
|
|
7171
7212
|
const accessToken = useUserData((s) => s.accessToken);
|
|
7172
7213
|
const refreshToken$1 = useUserData((s) => s.refreshToken);
|
|
7214
|
+
const isReady = useUserData((s) => s.isReady);
|
|
7215
|
+
const isAuthenticated = useUserData((s) => s.isAuthenticated);
|
|
7216
|
+
const address = useUserData((s) => s.address);
|
|
7173
7217
|
const setAccessToken = useUserData((s) => s.setAccessToken);
|
|
7174
7218
|
const setRefreshToken = useUserData((s) => s.setRefreshToken);
|
|
7175
|
-
const
|
|
7219
|
+
const setIsReady = useUserData((s) => s.setIsReady);
|
|
7176
7220
|
const setIsAuthenticated = useUserData((s) => s.setIsAuthenticated);
|
|
7177
7221
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7178
7222
|
useEffect(() => {
|
|
7179
7223
|
if (typeof window == "undefined") {
|
|
7180
7224
|
return;
|
|
7181
7225
|
}
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7226
|
+
if (address) {
|
|
7227
|
+
// If we already have an address in state, use it to load the session
|
|
7228
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7229
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7230
|
+
const storedAccessToken = localStorage.getItem(accessTokenKey);
|
|
7231
|
+
const storedRefreshToken = localStorage.getItem(refreshTokenKey);
|
|
7232
|
+
if (storedAccessToken && storedRefreshToken) {
|
|
7233
|
+
setAccessToken(storedAccessToken);
|
|
7234
|
+
setRefreshToken(storedRefreshToken);
|
|
7235
|
+
setIsAuthenticated(true);
|
|
7236
|
+
}
|
|
7237
|
+
else {
|
|
7238
|
+
setAccessToken(null);
|
|
7239
|
+
setRefreshToken(null);
|
|
7240
|
+
setIsAuthenticated(false);
|
|
7241
|
+
}
|
|
7242
|
+
}
|
|
7190
7243
|
setIsReady(true);
|
|
7191
|
-
}, [
|
|
7244
|
+
}, [address]);
|
|
7192
7245
|
useEffect(() => {
|
|
7193
7246
|
const cleanup = addAuthInterceptors({
|
|
7194
7247
|
apiBaseUrl,
|
|
7195
7248
|
getAccessToken: () => {
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7249
|
+
if (typeof window === "undefined")
|
|
7250
|
+
return null;
|
|
7251
|
+
// Read from Zustand state as single source of truth
|
|
7252
|
+
return useUserData.getState().accessToken;
|
|
7199
7253
|
},
|
|
7200
7254
|
refreshTokens: async () => {
|
|
7201
7255
|
const data = await refreshTokens();
|
|
@@ -7221,12 +7275,12 @@ function useAuth() {
|
|
|
7221
7275
|
clientId,
|
|
7222
7276
|
details: { signature, timestamp },
|
|
7223
7277
|
});
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
window.localStorage.setItem(
|
|
7278
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7279
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7280
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7281
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7227
7282
|
setAccessToken(data.accessToken);
|
|
7228
7283
|
setRefreshToken(data.refreshToken);
|
|
7229
|
-
setAddress(address);
|
|
7230
7284
|
setIsAuthenticated(true);
|
|
7231
7285
|
}
|
|
7232
7286
|
catch (e) {
|
|
@@ -7241,12 +7295,12 @@ function useAuth() {
|
|
|
7241
7295
|
appId,
|
|
7242
7296
|
accessToken: privyAccessToken,
|
|
7243
7297
|
});
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
window.localStorage.setItem(
|
|
7298
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7299
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7300
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7301
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7247
7302
|
setAccessToken(data.accessToken);
|
|
7248
7303
|
setRefreshToken(data.refreshToken);
|
|
7249
|
-
setAddress(address);
|
|
7250
7304
|
setIsAuthenticated(true);
|
|
7251
7305
|
}
|
|
7252
7306
|
catch (e) {
|
|
@@ -7254,30 +7308,38 @@ function useAuth() {
|
|
|
7254
7308
|
}
|
|
7255
7309
|
}
|
|
7256
7310
|
async function refreshTokens() {
|
|
7257
|
-
const
|
|
7258
|
-
|
|
7311
|
+
const currentAddress = address;
|
|
7312
|
+
const currentRefresh = refreshToken$1;
|
|
7313
|
+
if (!currentRefresh || !currentAddress)
|
|
7259
7314
|
throw new Error("No refresh token");
|
|
7260
|
-
const { data } = await refreshToken(apiBaseUrl,
|
|
7261
|
-
|
|
7262
|
-
|
|
7315
|
+
const { data } = await refreshToken(apiBaseUrl, currentRefresh);
|
|
7316
|
+
// Update tokens in localStorage
|
|
7317
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7318
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7319
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7320
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7263
7321
|
setAccessToken(data.accessToken);
|
|
7264
7322
|
setRefreshToken(data.refreshToken);
|
|
7265
7323
|
setIsAuthenticated(true);
|
|
7266
7324
|
return data;
|
|
7267
7325
|
}
|
|
7268
7326
|
async function logout$1() {
|
|
7269
|
-
const
|
|
7270
|
-
|
|
7327
|
+
const currentAddress = address;
|
|
7328
|
+
const currentRefresh = refreshToken$1;
|
|
7329
|
+
if (currentRefresh) {
|
|
7271
7330
|
try {
|
|
7272
|
-
await logout(apiBaseUrl,
|
|
7331
|
+
await logout(apiBaseUrl, currentRefresh);
|
|
7273
7332
|
}
|
|
7274
7333
|
catch (_a) {
|
|
7275
7334
|
/* ignore */
|
|
7276
7335
|
}
|
|
7277
7336
|
}
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7337
|
+
if (currentAddress) {
|
|
7338
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7339
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7340
|
+
window.localStorage.removeItem(accessTokenKey);
|
|
7341
|
+
window.localStorage.removeItem(refreshTokenKey);
|
|
7342
|
+
}
|
|
7281
7343
|
setAccessToken(null);
|
|
7282
7344
|
setRefreshToken(null);
|
|
7283
7345
|
setAddress(null);
|
|
@@ -7293,6 +7355,8 @@ function useAuth() {
|
|
|
7293
7355
|
loginWithPrivyToken,
|
|
7294
7356
|
refreshTokens,
|
|
7295
7357
|
logout: logout$1,
|
|
7358
|
+
setAddress,
|
|
7359
|
+
address,
|
|
7296
7360
|
};
|
|
7297
7361
|
}
|
|
7298
7362
|
|
|
@@ -7302,7 +7366,6 @@ const PearHyperliquidContext = createContext(undefined);
|
|
|
7302
7366
|
*/
|
|
7303
7367
|
const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-ui.pearprotocol.io", clientId = "PEARPROTOCOLUI", wsUrl = "wss://hl-ui.pearprotocol.io/ws", }) => {
|
|
7304
7368
|
const address = useUserData((s) => s.address);
|
|
7305
|
-
const setAddress = useUserData((s) => s.setAddress);
|
|
7306
7369
|
const perpsMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
7307
7370
|
const setPerpMetaAssets = useHyperliquidData((state) => state.setPerpMetaAssets);
|
|
7308
7371
|
const setHip3DisplayToFull = useHyperliquidData((state) => state.setHip3DisplayToFull);
|
|
@@ -7367,8 +7430,6 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-ui.pearpro
|
|
|
7367
7430
|
}), [
|
|
7368
7431
|
apiBaseUrl,
|
|
7369
7432
|
wsUrl,
|
|
7370
|
-
address,
|
|
7371
|
-
setAddress,
|
|
7372
7433
|
isConnected,
|
|
7373
7434
|
lastError,
|
|
7374
7435
|
nativeIsConnected,
|
|
@@ -10,5 +10,16 @@ interface TokenHistoricalPriceData {
|
|
|
10
10
|
oldestTime: number | null;
|
|
11
11
|
latestTime: number | null;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
interface HistoricalPriceDataState {
|
|
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>>;
|
|
14
25
|
export type { HistoricalRange, TokenHistoricalPriceData };
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from "../types";
|
|
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 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ActiveAssetsAllResponse, ActiveAssetsResponse } from '../types';
|
|
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 {};
|
|
@@ -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: import("zustand").UseBoundStore<import("zustand").StoreApi<TokenSelectionMetadataState>>;
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent } from "../types";
|
|
2
|
+
interface UserDataState {
|
|
3
|
+
accessToken: string | null;
|
|
4
|
+
refreshToken: string | null;
|
|
5
|
+
isAuthenticated: boolean;
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
address: string | null;
|
|
8
|
+
tradeHistories: TradeHistoryDataDto[] | null;
|
|
9
|
+
rawOpenPositions: RawPositionDto[] | null;
|
|
10
|
+
openOrders: OpenLimitOrderDto[] | null;
|
|
11
|
+
accountSummary: PlatformAccountSummaryResponseDto | null;
|
|
12
|
+
twapDetails: TwapMonitoringDto[] | null;
|
|
13
|
+
notifications: NotificationDto[] | null;
|
|
14
|
+
userExtraAgents: ExtraAgent[] | null;
|
|
15
|
+
setAccessToken: (token: string | null) => void;
|
|
16
|
+
setRefreshToken: (token: string | null) => void;
|
|
17
|
+
setIsAuthenticated: (value: boolean) => void;
|
|
18
|
+
setIsReady: (value: boolean) => void;
|
|
19
|
+
setAddress: (address: string | null) => void;
|
|
20
|
+
setTradeHistories: (value: TradeHistoryDataDto[] | null) => void;
|
|
21
|
+
setRawOpenPositions: (value: RawPositionDto[] | null) => void;
|
|
22
|
+
setOpenOrders: (value: OpenLimitOrderDto[] | null) => void;
|
|
23
|
+
setAccountSummary: (value: PlatformAccountSummaryResponseDto | null) => void;
|
|
24
|
+
setUserExtraAgents: (value: ExtraAgent[] | null) => void;
|
|
25
|
+
setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
|
|
26
|
+
setNotifications: (value: NotificationDto[] | null) => void;
|
|
27
|
+
clean: () => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
|
|
30
|
+
export {};
|
|
@@ -23,5 +23,5 @@ interface UserSelectionState {
|
|
|
23
23
|
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
24
24
|
resetToDefaults: () => void;
|
|
25
25
|
}
|
|
26
|
-
export declare const useUserSelection:
|
|
26
|
+
export declare const useUserSelection: import("zustand").UseBoundStore<import("zustand").StoreApi<UserSelectionState>>;
|
|
27
27
|
export type { UserSelectionState };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73-beta.2",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"clean": "rimraf dist"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.6.0"
|
|
27
|
+
"axios": "^1.6.0",
|
|
28
|
+
"zustand": "^5.0.8"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"react": "^18.0.0",
|