@pear-protocol/hyperliquid-sdk 0.0.58 → 0.0.60-beta
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 +4 -4
- package/dist/index.d.ts +24 -5
- package/dist/index.js +143 -50
- package/dist/provider.d.ts +1 -1
- 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 +28 -1
- package/dist/store/userSelection.d.ts +1 -1
- package/package.json +3 -3
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { GetEIP712MessageResponse } from
|
|
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>;
|
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;
|
|
@@ -769,7 +770,18 @@ interface TokenHistoricalPriceData {
|
|
|
769
770
|
oldestTime: number | null;
|
|
770
771
|
latestTime: number | null;
|
|
771
772
|
}
|
|
772
|
-
|
|
773
|
+
interface HistoricalPriceDataState {
|
|
774
|
+
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|
|
775
|
+
loadingTokens: Set<string>;
|
|
776
|
+
addHistoricalPriceData: (symbol: string, interval: CandleInterval, candles: CandleData[], range: HistoricalRange) => void;
|
|
777
|
+
hasHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => boolean;
|
|
778
|
+
getHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => CandleData[];
|
|
779
|
+
setTokenLoading: (symbol: string, loading: boolean) => void;
|
|
780
|
+
isTokenLoading: (symbol: string) => boolean;
|
|
781
|
+
removeTokenPriceData: (symbol: string, interval: CandleInterval) => void;
|
|
782
|
+
clearData: () => void;
|
|
783
|
+
}
|
|
784
|
+
declare const useHistoricalPriceDataStore: zustand.UseBoundStore<zustand.StoreApi<HistoricalPriceDataState>>;
|
|
773
785
|
|
|
774
786
|
interface UseHistoricalPriceDataReturn {
|
|
775
787
|
fetchHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
|
|
@@ -1106,9 +1118,9 @@ declare function usePortfolio(): UsePortfolioResult;
|
|
|
1106
1118
|
|
|
1107
1119
|
declare function useAuth(): {
|
|
1108
1120
|
readonly isReady: boolean;
|
|
1109
|
-
readonly isAuthenticated:
|
|
1110
|
-
readonly accessToken:
|
|
1111
|
-
readonly refreshToken:
|
|
1121
|
+
readonly isAuthenticated: boolean;
|
|
1122
|
+
readonly accessToken: string | null;
|
|
1123
|
+
readonly refreshToken: string | null;
|
|
1112
1124
|
readonly getEip712: (address: string) => Promise<GetEIP712MessageResponse>;
|
|
1113
1125
|
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
1114
1126
|
readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
|
|
@@ -1290,7 +1302,14 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
|
|
|
1290
1302
|
minimumRequired?: number;
|
|
1291
1303
|
};
|
|
1292
1304
|
|
|
1293
|
-
|
|
1305
|
+
interface MarketDataState {
|
|
1306
|
+
marketData: ActiveAssetsResponse | null;
|
|
1307
|
+
marketDataAll: ActiveAssetsAllResponse | null;
|
|
1308
|
+
setMarketData: (value: ActiveAssetsResponse | null) => void;
|
|
1309
|
+
setMarketDataAll: (value: ActiveAssetsAllResponse | null) => void;
|
|
1310
|
+
clean: () => void;
|
|
1311
|
+
}
|
|
1312
|
+
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1294
1313
|
|
|
1295
1314
|
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, getPortfolio, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, 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, validateMinimumAssetSize, validatePositionSize };
|
|
1296
1315
|
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, 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,6 +10,47 @@ 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,
|
|
@@ -27,12 +67,12 @@ const useUserData = create((set) => ({
|
|
|
27
67
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
28
68
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
29
69
|
setAddress: (address) => set(() => {
|
|
30
|
-
if (typeof window !==
|
|
70
|
+
if (typeof window !== "undefined") {
|
|
31
71
|
if (address) {
|
|
32
|
-
window.localStorage.setItem(
|
|
72
|
+
window.localStorage.setItem("address", address);
|
|
33
73
|
}
|
|
34
74
|
else {
|
|
35
|
-
window.localStorage.removeItem(
|
|
75
|
+
window.localStorage.removeItem("address");
|
|
36
76
|
}
|
|
37
77
|
}
|
|
38
78
|
return { address };
|
|
@@ -6068,6 +6108,7 @@ function useAgentWallet() {
|
|
|
6068
6108
|
const isAuthenticated = useUserData((state) => state.isAuthenticated);
|
|
6069
6109
|
const address = useUserData((state) => state.address);
|
|
6070
6110
|
const setAgentWallets = useUserData((state) => state.setUserExtraAgents);
|
|
6111
|
+
const setAccountSummary = useUserData((state) => state.setAccountSummary);
|
|
6071
6112
|
const refreshAgentWalletStatus = useCallback(async () => {
|
|
6072
6113
|
const hlAgentWallets = await fetchExtraAgents(address);
|
|
6073
6114
|
setAgentWallets((hlAgentWallets === null || hlAgentWallets === void 0 ? void 0 : hlAgentWallets.data) || []);
|
|
@@ -6082,11 +6123,18 @@ function useAgentWallet() {
|
|
|
6082
6123
|
throw new Error('Not authenticated');
|
|
6083
6124
|
}
|
|
6084
6125
|
const response = await createAgentWallet(apiBaseUrl);
|
|
6126
|
+
const accountSummary = useUserData.getState().accountSummary;
|
|
6127
|
+
if (accountSummary) {
|
|
6128
|
+
const updatedSummary = {
|
|
6129
|
+
agentWalletAddress: response.data.agentWalletAddress,
|
|
6130
|
+
};
|
|
6131
|
+
setAccountSummary(updatedSummary);
|
|
6132
|
+
}
|
|
6085
6133
|
return response.data;
|
|
6086
6134
|
}, [apiBaseUrl, isAuthenticated]);
|
|
6087
6135
|
const notifyAgentWalletApproved = useCallback(async () => {
|
|
6088
6136
|
return refreshAgentWalletStatus();
|
|
6089
|
-
}, [refreshAgentWalletStatus]);
|
|
6137
|
+
}, [refreshAgentWalletStatus, setAccountSummary]);
|
|
6090
6138
|
return {
|
|
6091
6139
|
refreshAgentWalletStatus,
|
|
6092
6140
|
createAgentWallet: createAgentWallet$1,
|
|
@@ -6981,7 +7029,7 @@ async function logout(baseUrl, refreshTokenVal) {
|
|
|
6981
7029
|
function useAuth() {
|
|
6982
7030
|
const context = useContext(PearHyperliquidContext);
|
|
6983
7031
|
if (!context) {
|
|
6984
|
-
throw new Error(
|
|
7032
|
+
throw new Error("usePortfolio must be used within a PearHyperliquidProvider");
|
|
6985
7033
|
}
|
|
6986
7034
|
const { apiBaseUrl, clientId } = context;
|
|
6987
7035
|
const [isReady, setIsReady] = useState(false);
|
|
@@ -6991,26 +7039,46 @@ function useAuth() {
|
|
|
6991
7039
|
const setRefreshToken = useUserData((s) => s.setRefreshToken);
|
|
6992
7040
|
const isAuthenticated = useUserData((s) => s.isAuthenticated);
|
|
6993
7041
|
const setIsAuthenticated = useUserData((s) => s.setIsAuthenticated);
|
|
7042
|
+
const address = useUserData((s) => s.address);
|
|
6994
7043
|
const setAddress = useUserData((s) => s.setAddress);
|
|
6995
7044
|
useEffect(() => {
|
|
6996
|
-
if (typeof window ==
|
|
7045
|
+
if (typeof window == "undefined") {
|
|
6997
7046
|
return;
|
|
6998
7047
|
}
|
|
6999
|
-
|
|
7000
|
-
const
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7048
|
+
// Get the current address from state if it exists
|
|
7049
|
+
const currentAddress = address;
|
|
7050
|
+
if (currentAddress) {
|
|
7051
|
+
// If we already have an address in state, use it to load the session
|
|
7052
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7053
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7054
|
+
const storedAccessToken = localStorage.getItem(accessTokenKey);
|
|
7055
|
+
const storedRefreshToken = localStorage.getItem(refreshTokenKey);
|
|
7056
|
+
if (storedAccessToken && storedRefreshToken) {
|
|
7057
|
+
setAccessToken(storedAccessToken);
|
|
7058
|
+
setRefreshToken(storedRefreshToken);
|
|
7059
|
+
setIsAuthenticated(true);
|
|
7060
|
+
setIsReady(true);
|
|
7061
|
+
return;
|
|
7062
|
+
}
|
|
7063
|
+
}
|
|
7064
|
+
}, [
|
|
7065
|
+
setAccessToken,
|
|
7066
|
+
setRefreshToken,
|
|
7067
|
+
setIsAuthenticated,
|
|
7068
|
+
setAddress,
|
|
7069
|
+
address,
|
|
7070
|
+
]);
|
|
7009
7071
|
useEffect(() => {
|
|
7010
7072
|
const cleanup = addAuthInterceptors({
|
|
7011
7073
|
apiBaseUrl,
|
|
7012
7074
|
getAccessToken: () => {
|
|
7013
|
-
|
|
7075
|
+
if (typeof window === "undefined")
|
|
7076
|
+
return null;
|
|
7077
|
+
const currentAddress = useUserData.getState().address;
|
|
7078
|
+
if (!currentAddress)
|
|
7079
|
+
return null;
|
|
7080
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7081
|
+
return localStorage.getItem(accessTokenKey);
|
|
7014
7082
|
},
|
|
7015
7083
|
refreshTokens: async () => {
|
|
7016
7084
|
const data = await refreshTokens();
|
|
@@ -7031,14 +7099,15 @@ function useAuth() {
|
|
|
7031
7099
|
async function loginWithSignedMessage(address, signature, timestamp) {
|
|
7032
7100
|
try {
|
|
7033
7101
|
const { data } = await authenticate(apiBaseUrl, {
|
|
7034
|
-
method:
|
|
7102
|
+
method: "eip712",
|
|
7035
7103
|
address,
|
|
7036
7104
|
clientId,
|
|
7037
7105
|
details: { signature, timestamp },
|
|
7038
7106
|
});
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
window.localStorage.setItem(
|
|
7107
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7108
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7109
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7110
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7042
7111
|
setAccessToken(data.accessToken);
|
|
7043
7112
|
setRefreshToken(data.refreshToken);
|
|
7044
7113
|
setAddress(address);
|
|
@@ -7050,10 +7119,16 @@ function useAuth() {
|
|
|
7050
7119
|
}
|
|
7051
7120
|
async function loginWithPrivyToken(address, appId, privyAccessToken) {
|
|
7052
7121
|
try {
|
|
7053
|
-
const { data } = await authenticateWithPrivy(apiBaseUrl, {
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7122
|
+
const { data } = await authenticateWithPrivy(apiBaseUrl, {
|
|
7123
|
+
address,
|
|
7124
|
+
clientId,
|
|
7125
|
+
appId,
|
|
7126
|
+
accessToken: privyAccessToken,
|
|
7127
|
+
});
|
|
7128
|
+
const accessTokenKey = `${address}_accessToken`;
|
|
7129
|
+
const refreshTokenKey = `${address}_refreshToken`;
|
|
7130
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7131
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7057
7132
|
setAccessToken(data.accessToken);
|
|
7058
7133
|
setRefreshToken(data.refreshToken);
|
|
7059
7134
|
setAddress(address);
|
|
@@ -7064,28 +7139,38 @@ function useAuth() {
|
|
|
7064
7139
|
}
|
|
7065
7140
|
}
|
|
7066
7141
|
async function refreshTokens() {
|
|
7067
|
-
const
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7142
|
+
const currentAddress = address;
|
|
7143
|
+
const currentRefresh = refreshToken$1;
|
|
7144
|
+
if (!currentRefresh || !currentAddress)
|
|
7145
|
+
throw new Error("No refresh token");
|
|
7146
|
+
const { data } = await refreshToken(apiBaseUrl, currentRefresh);
|
|
7147
|
+
// Update tokens in localStorage
|
|
7148
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7149
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7150
|
+
window.localStorage.setItem(accessTokenKey, data.accessToken);
|
|
7151
|
+
window.localStorage.setItem(refreshTokenKey, data.refreshToken);
|
|
7073
7152
|
setAccessToken(data.accessToken);
|
|
7074
7153
|
setRefreshToken(data.refreshToken);
|
|
7075
7154
|
setIsAuthenticated(true);
|
|
7076
7155
|
return data;
|
|
7077
7156
|
}
|
|
7078
7157
|
async function logout$1() {
|
|
7079
|
-
const
|
|
7080
|
-
|
|
7158
|
+
const currentAddress = address;
|
|
7159
|
+
const currentRefresh = refreshToken$1;
|
|
7160
|
+
if (currentRefresh) {
|
|
7081
7161
|
try {
|
|
7082
|
-
await logout(apiBaseUrl,
|
|
7162
|
+
await logout(apiBaseUrl, currentRefresh);
|
|
7163
|
+
}
|
|
7164
|
+
catch (_a) {
|
|
7165
|
+
/* ignore */
|
|
7083
7166
|
}
|
|
7084
|
-
catch ( /* ignore */_a) { /* ignore */ }
|
|
7085
7167
|
}
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7168
|
+
if (currentAddress) {
|
|
7169
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7170
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7171
|
+
window.localStorage.removeItem(accessTokenKey);
|
|
7172
|
+
window.localStorage.removeItem(refreshTokenKey);
|
|
7173
|
+
}
|
|
7089
7174
|
setAccessToken(null);
|
|
7090
7175
|
setRefreshToken(null);
|
|
7091
7176
|
setAddress(null);
|
|
@@ -7108,7 +7193,7 @@ const PearHyperliquidContext = createContext(undefined);
|
|
|
7108
7193
|
/**
|
|
7109
7194
|
* React Provider for PearHyperliquidClient
|
|
7110
7195
|
*/
|
|
7111
|
-
const PearHyperliquidProvider = ({ children, apiBaseUrl =
|
|
7196
|
+
const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-v2.pearprotocol.io", clientId = "PEARPROTOCOLUI", wsUrl = "wss://hl-v2.pearprotocol.io/ws", }) => {
|
|
7112
7197
|
const address = useUserData((s) => s.address);
|
|
7113
7198
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7114
7199
|
const perpsMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
@@ -7126,9 +7211,9 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7126
7211
|
});
|
|
7127
7212
|
useEffect(() => {
|
|
7128
7213
|
if (perpsMetaAssets === null) {
|
|
7129
|
-
fetchAllPerpMetas()
|
|
7130
|
-
|
|
7131
|
-
const aggregatedPerpMetas = res.data.
|
|
7214
|
+
fetchAllPerpMetas()
|
|
7215
|
+
.then((res) => {
|
|
7216
|
+
const aggregatedPerpMetas = res.data.flatMap((item) => item.universe);
|
|
7132
7217
|
const hip3Map = new Map();
|
|
7133
7218
|
const displayToFull = new Map();
|
|
7134
7219
|
const cleanedPerpMetas = aggregatedPerpMetas.map((asset) => {
|
|
@@ -7146,7 +7231,8 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7146
7231
|
});
|
|
7147
7232
|
setHip3DisplayToFull(displayToFull);
|
|
7148
7233
|
setPerpMetaAssets(cleanedPerpMetas);
|
|
7149
|
-
})
|
|
7234
|
+
})
|
|
7235
|
+
.catch(() => { });
|
|
7150
7236
|
}
|
|
7151
7237
|
}, [perpsMetaAssets, setPerpMetaAssets, setHip3DisplayToFull]);
|
|
7152
7238
|
// Auth methods now sourced from useAuth hook
|
|
@@ -7168,11 +7254,18 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7168
7254
|
// HyperLiquid native WebSocket state
|
|
7169
7255
|
nativeIsConnected,
|
|
7170
7256
|
nativeLastError,
|
|
7257
|
+
// Address utilities
|
|
7258
|
+
address,
|
|
7259
|
+
setAddress,
|
|
7171
7260
|
}), [
|
|
7172
|
-
apiBaseUrl,
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7261
|
+
apiBaseUrl,
|
|
7262
|
+
wsUrl,
|
|
7263
|
+
address,
|
|
7264
|
+
setAddress,
|
|
7265
|
+
isConnected,
|
|
7266
|
+
lastError,
|
|
7267
|
+
nativeIsConnected,
|
|
7268
|
+
nativeLastError,
|
|
7176
7269
|
]);
|
|
7177
7270
|
return (jsx(PearHyperliquidContext.Provider, { value: contextValue, children: children }));
|
|
7178
7271
|
};
|
|
@@ -7183,7 +7276,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7183
7276
|
function usePearHyperliquid() {
|
|
7184
7277
|
const ctx = useContext(PearHyperliquidContext);
|
|
7185
7278
|
if (!ctx)
|
|
7186
|
-
throw new Error(
|
|
7279
|
+
throw new Error("usePearHyperliquid must be used within a PearHyperliquidProvider");
|
|
7187
7280
|
return ctx;
|
|
7188
7281
|
}
|
|
7189
7282
|
|
package/dist/provider.d.ts
CHANGED
|
@@ -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,28 @@
|
|
|
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
|
+
address: string | null;
|
|
7
|
+
tradeHistories: TradeHistoryDataDto[] | null;
|
|
8
|
+
rawOpenPositions: RawPositionDto[] | null;
|
|
9
|
+
openOrders: OpenLimitOrderDto[] | null;
|
|
10
|
+
accountSummary: PlatformAccountSummaryResponseDto | null;
|
|
11
|
+
twapDetails: TwapMonitoringDto[] | null;
|
|
12
|
+
notifications: NotificationDto[] | null;
|
|
13
|
+
userExtraAgents: ExtraAgent[] | null;
|
|
14
|
+
setAccessToken: (token: string | null) => void;
|
|
15
|
+
setRefreshToken: (token: string | null) => void;
|
|
16
|
+
setIsAuthenticated: (value: boolean) => void;
|
|
17
|
+
setAddress: (address: string | null) => void;
|
|
18
|
+
setTradeHistories: (value: TradeHistoryDataDto[] | null) => void;
|
|
19
|
+
setRawOpenPositions: (value: RawPositionDto[] | null) => void;
|
|
20
|
+
setOpenOrders: (value: OpenLimitOrderDto[] | null) => void;
|
|
21
|
+
setAccountSummary: (value: PlatformAccountSummaryResponseDto | null) => void;
|
|
22
|
+
setUserExtraAgents: (value: ExtraAgent[] | null) => void;
|
|
23
|
+
setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
|
|
24
|
+
setNotifications: (value: NotificationDto[] | null) => void;
|
|
25
|
+
clean: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
|
|
28
|
+
export {};
|
|
@@ -22,5 +22,5 @@ interface UserSelectionState {
|
|
|
22
22
|
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
23
23
|
resetToDefaults: () => void;
|
|
24
24
|
}
|
|
25
|
-
export declare const useUserSelection:
|
|
25
|
+
export declare const useUserSelection: import("zustand").UseBoundStore<import("zustand").StoreApi<UserSelectionState>>;
|
|
26
26
|
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.60-beta",
|
|
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",
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
"@types/react": "^18.0.0",
|
|
39
40
|
"concurrently": "^9.2.1",
|
|
40
41
|
"esbuild": "^0.25.9",
|
|
41
|
-
|
|
42
42
|
"rimraf": "^5.0.0",
|
|
43
43
|
"rollup": "^3.0.0",
|
|
44
44
|
"rollup-plugin-dts": "^6.0.0",
|