@pear-protocol/hyperliquid-sdk 0.0.71 → 0.0.73-beta.1
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 -58
- 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,
|
|
@@ -1389,20 +1431,20 @@ const useTokenSelectionMetadataStore = create((set) => ({
|
|
|
1389
1431
|
});
|
|
1390
1432
|
return totalFunding;
|
|
1391
1433
|
})();
|
|
1392
|
-
// Max leverage (
|
|
1434
|
+
// Max leverage (maximum across all tokens)
|
|
1393
1435
|
const maxLeverage = (() => {
|
|
1394
1436
|
if (!perpMetaAssets)
|
|
1395
1437
|
return 0;
|
|
1396
1438
|
const allTokenSymbols = [...longTokens, ...shortTokens].map((t) => t.symbol);
|
|
1397
1439
|
if (allTokenSymbols.length === 0)
|
|
1398
1440
|
return 0;
|
|
1399
|
-
let
|
|
1441
|
+
let maxLev = 0;
|
|
1400
1442
|
allTokenSymbols.forEach((symbol) => {
|
|
1401
1443
|
const tokenUniverse = perpMetaAssets.find((u) => u.name === symbol);
|
|
1402
1444
|
if (tokenUniverse === null || tokenUniverse === void 0 ? void 0 : tokenUniverse.maxLeverage)
|
|
1403
|
-
|
|
1445
|
+
maxLev = Math.max(maxLev, tokenUniverse.maxLeverage);
|
|
1404
1446
|
});
|
|
1405
|
-
return
|
|
1447
|
+
return maxLev;
|
|
1406
1448
|
})();
|
|
1407
1449
|
// Min margin (10 * total number of tokens)
|
|
1408
1450
|
const minMargin = (() => {
|
|
@@ -7164,38 +7206,46 @@ 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
|
+
console.log({ storedAccessToken, storedRefreshToken });
|
|
7233
|
+
if (storedAccessToken && storedRefreshToken) {
|
|
7234
|
+
setAccessToken(storedAccessToken);
|
|
7235
|
+
setRefreshToken(storedRefreshToken);
|
|
7236
|
+
setIsAuthenticated(true);
|
|
7237
|
+
}
|
|
7238
|
+
}
|
|
7190
7239
|
setIsReady(true);
|
|
7191
|
-
}, [
|
|
7240
|
+
}, [address]);
|
|
7192
7241
|
useEffect(() => {
|
|
7193
7242
|
const cleanup = addAuthInterceptors({
|
|
7194
7243
|
apiBaseUrl,
|
|
7195
7244
|
getAccessToken: () => {
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7245
|
+
if (typeof window === "undefined")
|
|
7246
|
+
return null;
|
|
7247
|
+
// Read from Zustand state as single source of truth
|
|
7248
|
+
return useUserData.getState().accessToken;
|
|
7199
7249
|
},
|
|
7200
7250
|
refreshTokens: async () => {
|
|
7201
7251
|
const data = await refreshTokens();
|
|
@@ -7221,12 +7271,12 @@ function useAuth() {
|
|
|
7221
7271
|
clientId,
|
|
7222
7272
|
details: { signature, timestamp },
|
|
7223
7273
|
});
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
window.localStorage.setItem(
|
|
7274
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7275
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7276
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7277
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7227
7278
|
setAccessToken(data.accessToken);
|
|
7228
7279
|
setRefreshToken(data.refreshToken);
|
|
7229
|
-
setAddress(address);
|
|
7230
7280
|
setIsAuthenticated(true);
|
|
7231
7281
|
}
|
|
7232
7282
|
catch (e) {
|
|
@@ -7241,12 +7291,12 @@ function useAuth() {
|
|
|
7241
7291
|
appId,
|
|
7242
7292
|
accessToken: privyAccessToken,
|
|
7243
7293
|
});
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
window.localStorage.setItem(
|
|
7294
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7295
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7296
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7297
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7247
7298
|
setAccessToken(data.accessToken);
|
|
7248
7299
|
setRefreshToken(data.refreshToken);
|
|
7249
|
-
setAddress(address);
|
|
7250
7300
|
setIsAuthenticated(true);
|
|
7251
7301
|
}
|
|
7252
7302
|
catch (e) {
|
|
@@ -7254,30 +7304,38 @@ function useAuth() {
|
|
|
7254
7304
|
}
|
|
7255
7305
|
}
|
|
7256
7306
|
async function refreshTokens() {
|
|
7257
|
-
const
|
|
7258
|
-
|
|
7307
|
+
const currentAddress = address;
|
|
7308
|
+
const currentRefresh = refreshToken$1;
|
|
7309
|
+
if (!currentRefresh || !currentAddress)
|
|
7259
7310
|
throw new Error("No refresh token");
|
|
7260
|
-
const { data } = await refreshToken(apiBaseUrl,
|
|
7261
|
-
|
|
7262
|
-
|
|
7311
|
+
const { data } = await refreshToken(apiBaseUrl, currentRefresh);
|
|
7312
|
+
// Update tokens in localStorage
|
|
7313
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7314
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7315
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7316
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7263
7317
|
setAccessToken(data.accessToken);
|
|
7264
7318
|
setRefreshToken(data.refreshToken);
|
|
7265
7319
|
setIsAuthenticated(true);
|
|
7266
7320
|
return data;
|
|
7267
7321
|
}
|
|
7268
7322
|
async function logout$1() {
|
|
7269
|
-
const
|
|
7270
|
-
|
|
7323
|
+
const currentAddress = address;
|
|
7324
|
+
const currentRefresh = refreshToken$1;
|
|
7325
|
+
if (currentRefresh) {
|
|
7271
7326
|
try {
|
|
7272
|
-
await logout(apiBaseUrl,
|
|
7327
|
+
await logout(apiBaseUrl, currentRefresh);
|
|
7273
7328
|
}
|
|
7274
7329
|
catch (_a) {
|
|
7275
7330
|
/* ignore */
|
|
7276
7331
|
}
|
|
7277
7332
|
}
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7333
|
+
if (currentAddress) {
|
|
7334
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7335
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7336
|
+
window.localStorage.removeItem(accessTokenKey);
|
|
7337
|
+
window.localStorage.removeItem(refreshTokenKey);
|
|
7338
|
+
}
|
|
7281
7339
|
setAccessToken(null);
|
|
7282
7340
|
setRefreshToken(null);
|
|
7283
7341
|
setAddress(null);
|
|
@@ -7293,6 +7351,8 @@ function useAuth() {
|
|
|
7293
7351
|
loginWithPrivyToken,
|
|
7294
7352
|
refreshTokens,
|
|
7295
7353
|
logout: logout$1,
|
|
7354
|
+
setAddress,
|
|
7355
|
+
address,
|
|
7296
7356
|
};
|
|
7297
7357
|
}
|
|
7298
7358
|
|
|
@@ -7302,7 +7362,6 @@ const PearHyperliquidContext = createContext(undefined);
|
|
|
7302
7362
|
*/
|
|
7303
7363
|
const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-ui.pearprotocol.io", clientId = "PEARPROTOCOLUI", wsUrl = "wss://hl-ui.pearprotocol.io/ws", }) => {
|
|
7304
7364
|
const address = useUserData((s) => s.address);
|
|
7305
|
-
const setAddress = useUserData((s) => s.setAddress);
|
|
7306
7365
|
const perpsMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
7307
7366
|
const setPerpMetaAssets = useHyperliquidData((state) => state.setPerpMetaAssets);
|
|
7308
7367
|
const setHip3DisplayToFull = useHyperliquidData((state) => state.setHip3DisplayToFull);
|
|
@@ -7367,8 +7426,6 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-ui.pearpro
|
|
|
7367
7426
|
}), [
|
|
7368
7427
|
apiBaseUrl,
|
|
7369
7428
|
wsUrl,
|
|
7370
|
-
address,
|
|
7371
|
-
setAddress,
|
|
7372
7429
|
isConnected,
|
|
7373
7430
|
lastError,
|
|
7374
7431
|
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.1",
|
|
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",
|