@pear-protocol/hyperliquid-sdk 0.0.59 → 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 +134 -49
- 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 };
|
|
@@ -6989,7 +7029,7 @@ async function logout(baseUrl, refreshTokenVal) {
|
|
|
6989
7029
|
function useAuth() {
|
|
6990
7030
|
const context = useContext(PearHyperliquidContext);
|
|
6991
7031
|
if (!context) {
|
|
6992
|
-
throw new Error(
|
|
7032
|
+
throw new Error("usePortfolio must be used within a PearHyperliquidProvider");
|
|
6993
7033
|
}
|
|
6994
7034
|
const { apiBaseUrl, clientId } = context;
|
|
6995
7035
|
const [isReady, setIsReady] = useState(false);
|
|
@@ -6999,26 +7039,46 @@ function useAuth() {
|
|
|
6999
7039
|
const setRefreshToken = useUserData((s) => s.setRefreshToken);
|
|
7000
7040
|
const isAuthenticated = useUserData((s) => s.isAuthenticated);
|
|
7001
7041
|
const setIsAuthenticated = useUserData((s) => s.setIsAuthenticated);
|
|
7042
|
+
const address = useUserData((s) => s.address);
|
|
7002
7043
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7003
7044
|
useEffect(() => {
|
|
7004
|
-
if (typeof window ==
|
|
7045
|
+
if (typeof window == "undefined") {
|
|
7005
7046
|
return;
|
|
7006
7047
|
}
|
|
7007
|
-
|
|
7008
|
-
const
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
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
|
+
]);
|
|
7017
7071
|
useEffect(() => {
|
|
7018
7072
|
const cleanup = addAuthInterceptors({
|
|
7019
7073
|
apiBaseUrl,
|
|
7020
7074
|
getAccessToken: () => {
|
|
7021
|
-
|
|
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);
|
|
7022
7082
|
},
|
|
7023
7083
|
refreshTokens: async () => {
|
|
7024
7084
|
const data = await refreshTokens();
|
|
@@ -7039,14 +7099,15 @@ function useAuth() {
|
|
|
7039
7099
|
async function loginWithSignedMessage(address, signature, timestamp) {
|
|
7040
7100
|
try {
|
|
7041
7101
|
const { data } = await authenticate(apiBaseUrl, {
|
|
7042
|
-
method:
|
|
7102
|
+
method: "eip712",
|
|
7043
7103
|
address,
|
|
7044
7104
|
clientId,
|
|
7045
7105
|
details: { signature, timestamp },
|
|
7046
7106
|
});
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
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);
|
|
7050
7111
|
setAccessToken(data.accessToken);
|
|
7051
7112
|
setRefreshToken(data.refreshToken);
|
|
7052
7113
|
setAddress(address);
|
|
@@ -7058,10 +7119,16 @@ function useAuth() {
|
|
|
7058
7119
|
}
|
|
7059
7120
|
async function loginWithPrivyToken(address, appId, privyAccessToken) {
|
|
7060
7121
|
try {
|
|
7061
|
-
const { data } = await authenticateWithPrivy(apiBaseUrl, {
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
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);
|
|
7065
7132
|
setAccessToken(data.accessToken);
|
|
7066
7133
|
setRefreshToken(data.refreshToken);
|
|
7067
7134
|
setAddress(address);
|
|
@@ -7072,28 +7139,38 @@ function useAuth() {
|
|
|
7072
7139
|
}
|
|
7073
7140
|
}
|
|
7074
7141
|
async function refreshTokens() {
|
|
7075
|
-
const
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
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);
|
|
7081
7152
|
setAccessToken(data.accessToken);
|
|
7082
7153
|
setRefreshToken(data.refreshToken);
|
|
7083
7154
|
setIsAuthenticated(true);
|
|
7084
7155
|
return data;
|
|
7085
7156
|
}
|
|
7086
7157
|
async function logout$1() {
|
|
7087
|
-
const
|
|
7088
|
-
|
|
7158
|
+
const currentAddress = address;
|
|
7159
|
+
const currentRefresh = refreshToken$1;
|
|
7160
|
+
if (currentRefresh) {
|
|
7089
7161
|
try {
|
|
7090
|
-
await logout(apiBaseUrl,
|
|
7162
|
+
await logout(apiBaseUrl, currentRefresh);
|
|
7091
7163
|
}
|
|
7092
|
-
catch (
|
|
7164
|
+
catch (_a) {
|
|
7165
|
+
/* ignore */
|
|
7166
|
+
}
|
|
7167
|
+
}
|
|
7168
|
+
if (currentAddress) {
|
|
7169
|
+
const accessTokenKey = `${currentAddress}_accessToken`;
|
|
7170
|
+
const refreshTokenKey = `${currentAddress}_refreshToken`;
|
|
7171
|
+
window.localStorage.removeItem(accessTokenKey);
|
|
7172
|
+
window.localStorage.removeItem(refreshTokenKey);
|
|
7093
7173
|
}
|
|
7094
|
-
window.localStorage.removeItem('accessToken');
|
|
7095
|
-
window.localStorage.removeItem('refreshToken');
|
|
7096
|
-
window.localStorage.removeItem('address');
|
|
7097
7174
|
setAccessToken(null);
|
|
7098
7175
|
setRefreshToken(null);
|
|
7099
7176
|
setAddress(null);
|
|
@@ -7116,7 +7193,7 @@ const PearHyperliquidContext = createContext(undefined);
|
|
|
7116
7193
|
/**
|
|
7117
7194
|
* React Provider for PearHyperliquidClient
|
|
7118
7195
|
*/
|
|
7119
|
-
const PearHyperliquidProvider = ({ children, apiBaseUrl =
|
|
7196
|
+
const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-v2.pearprotocol.io", clientId = "PEARPROTOCOLUI", wsUrl = "wss://hl-v2.pearprotocol.io/ws", }) => {
|
|
7120
7197
|
const address = useUserData((s) => s.address);
|
|
7121
7198
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7122
7199
|
const perpsMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
@@ -7134,9 +7211,9 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7134
7211
|
});
|
|
7135
7212
|
useEffect(() => {
|
|
7136
7213
|
if (perpsMetaAssets === null) {
|
|
7137
|
-
fetchAllPerpMetas()
|
|
7138
|
-
|
|
7139
|
-
const aggregatedPerpMetas = res.data.
|
|
7214
|
+
fetchAllPerpMetas()
|
|
7215
|
+
.then((res) => {
|
|
7216
|
+
const aggregatedPerpMetas = res.data.flatMap((item) => item.universe);
|
|
7140
7217
|
const hip3Map = new Map();
|
|
7141
7218
|
const displayToFull = new Map();
|
|
7142
7219
|
const cleanedPerpMetas = aggregatedPerpMetas.map((asset) => {
|
|
@@ -7154,7 +7231,8 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7154
7231
|
});
|
|
7155
7232
|
setHip3DisplayToFull(displayToFull);
|
|
7156
7233
|
setPerpMetaAssets(cleanedPerpMetas);
|
|
7157
|
-
})
|
|
7234
|
+
})
|
|
7235
|
+
.catch(() => { });
|
|
7158
7236
|
}
|
|
7159
7237
|
}, [perpsMetaAssets, setPerpMetaAssets, setHip3DisplayToFull]);
|
|
7160
7238
|
// Auth methods now sourced from useAuth hook
|
|
@@ -7176,11 +7254,18 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7176
7254
|
// HyperLiquid native WebSocket state
|
|
7177
7255
|
nativeIsConnected,
|
|
7178
7256
|
nativeLastError,
|
|
7257
|
+
// Address utilities
|
|
7258
|
+
address,
|
|
7259
|
+
setAddress,
|
|
7179
7260
|
}), [
|
|
7180
|
-
apiBaseUrl,
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7261
|
+
apiBaseUrl,
|
|
7262
|
+
wsUrl,
|
|
7263
|
+
address,
|
|
7264
|
+
setAddress,
|
|
7265
|
+
isConnected,
|
|
7266
|
+
lastError,
|
|
7267
|
+
nativeIsConnected,
|
|
7268
|
+
nativeLastError,
|
|
7184
7269
|
]);
|
|
7185
7270
|
return (jsx(PearHyperliquidContext.Provider, { value: contextValue, children: children }));
|
|
7186
7271
|
};
|
|
@@ -7191,7 +7276,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7191
7276
|
function usePearHyperliquid() {
|
|
7192
7277
|
const ctx = useContext(PearHyperliquidContext);
|
|
7193
7278
|
if (!ctx)
|
|
7194
|
-
throw new Error(
|
|
7279
|
+
throw new Error("usePearHyperliquid must be used within a PearHyperliquidProvider");
|
|
7195
7280
|
return ctx;
|
|
7196
7281
|
}
|
|
7197
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",
|