@pear-protocol/hyperliquid-sdk 0.0.60-beta-usdh-2 → 0.0.60-beta-usdh-4
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/index.d.ts +1 -0
- package/dist/hooks/useAuth.d.ts +1 -1
- package/dist/hooks/useSpotBalances.d.ts +7 -0
- package/dist/index.d.ts +26 -3
- package/dist/index.js +134 -42
- package/dist/provider.d.ts +1 -1
- package/dist/types.d.ts +17 -1
- package/dist/utils/account-summary-calculator.d.ts +1 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/useAuth.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -347,6 +347,7 @@ interface PlatformAccountSummaryResponseDto {
|
|
|
347
347
|
*/
|
|
348
348
|
interface AccountSummaryResponseDto {
|
|
349
349
|
balanceSummary: BalanceSummaryDto;
|
|
350
|
+
platformAccountSummary: PlatformAccountSummaryResponseDto | null;
|
|
350
351
|
agentWallet?: AgentWalletDto;
|
|
351
352
|
}
|
|
352
353
|
interface UseAuthOptions {
|
|
@@ -414,12 +415,16 @@ interface WebSocketMessage {
|
|
|
414
415
|
/**
|
|
415
416
|
* WebSocket response from HyperLiquid native API
|
|
416
417
|
*/
|
|
417
|
-
type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle';
|
|
418
|
+
type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState';
|
|
418
419
|
interface HLChannelDataMap {
|
|
419
420
|
webData3: WebData3Response;
|
|
420
421
|
allMids: WsAllMidsData;
|
|
421
422
|
activeAssetData: ActiveAssetData;
|
|
422
423
|
candle: CandleData;
|
|
424
|
+
spotState: {
|
|
425
|
+
user: string;
|
|
426
|
+
spotState: SpotState;
|
|
427
|
+
};
|
|
423
428
|
}
|
|
424
429
|
interface WebData3UserState {
|
|
425
430
|
agentAddress?: string;
|
|
@@ -719,6 +724,17 @@ interface TokenSelectorConfig {
|
|
|
719
724
|
isLong: boolean;
|
|
720
725
|
index: number;
|
|
721
726
|
}
|
|
727
|
+
interface SpotBalance {
|
|
728
|
+
coin: string;
|
|
729
|
+
token: number;
|
|
730
|
+
total: string;
|
|
731
|
+
hold: string;
|
|
732
|
+
entryNtl: string;
|
|
733
|
+
}
|
|
734
|
+
interface SpotState {
|
|
735
|
+
user: string;
|
|
736
|
+
balances: SpotBalance[];
|
|
737
|
+
}
|
|
722
738
|
|
|
723
739
|
declare const useAccountSummary: () => {
|
|
724
740
|
data: AccountSummaryResponseDto | null;
|
|
@@ -1224,6 +1240,13 @@ declare function useAuth(): {
|
|
|
1224
1240
|
readonly logout: () => Promise<void>;
|
|
1225
1241
|
};
|
|
1226
1242
|
|
|
1243
|
+
interface SpotBalances {
|
|
1244
|
+
usdhBalance: number | undefined;
|
|
1245
|
+
spotUsdcBalance: number | undefined;
|
|
1246
|
+
isLoading: boolean;
|
|
1247
|
+
}
|
|
1248
|
+
declare const useSpotBalances: () => SpotBalances;
|
|
1249
|
+
|
|
1227
1250
|
interface UseHyperliquidWebSocketProps {
|
|
1228
1251
|
wsUrl: string;
|
|
1229
1252
|
address: string | null;
|
|
@@ -1445,5 +1468,5 @@ declare function isHip3Market(symbol: string): boolean;
|
|
|
1445
1468
|
|
|
1446
1469
|
declare const useMarketData: any;
|
|
1447
1470
|
|
|
1448
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1449
|
-
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, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1471
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotBalances, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1472
|
+
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, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotBalance, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const useUserData = create((set) => ({
|
|
|
23
23
|
twapDetails: null,
|
|
24
24
|
notifications: null,
|
|
25
25
|
userExtraAgents: null,
|
|
26
|
+
spotState: null,
|
|
26
27
|
setAccessToken: (token) => set({ accessToken: token }),
|
|
27
28
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
28
29
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
@@ -43,6 +44,7 @@ const useUserData = create((set) => ({
|
|
|
43
44
|
setAccountSummary: (value) => set({ accountSummary: value }),
|
|
44
45
|
setTwapDetails: (value) => set({ twapDetails: value }),
|
|
45
46
|
setNotifications: (value) => set({ notifications: value }),
|
|
47
|
+
setSpotState: (value) => set({ spotState: value }),
|
|
46
48
|
clean: () => set({
|
|
47
49
|
accessToken: null,
|
|
48
50
|
refreshToken: null,
|
|
@@ -54,6 +56,7 @@ const useUserData = create((set) => ({
|
|
|
54
56
|
accountSummary: null,
|
|
55
57
|
twapDetails: null,
|
|
56
58
|
notifications: null,
|
|
59
|
+
spotState: null,
|
|
57
60
|
}),
|
|
58
61
|
setUserExtraAgents: (value) => set({ userExtraAgents: value }),
|
|
59
62
|
}));
|
|
@@ -559,6 +562,7 @@ const useUserSelection$1 = create((set, get) => ({
|
|
|
559
562
|
|
|
560
563
|
const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
561
564
|
const { setAllMids, setActiveAssetData, upsertActiveAssetData, setCandleData, deleteCandleSymbol, deleteActiveAssetData, addCandleData, setFinalAssetContexts, setFinalAtOICaps, setAggregatedClearingHouseState, } = useHyperliquidData();
|
|
565
|
+
const { setSpotState } = useUserData();
|
|
562
566
|
const { candleInterval } = useUserSelection$1();
|
|
563
567
|
const longTokens = useUserSelection$1((s) => s.longTokens);
|
|
564
568
|
const shortTokens = useUserSelection$1((s) => s.shortTokens);
|
|
@@ -680,6 +684,14 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
680
684
|
addCandleData(symbol, normalized);
|
|
681
685
|
}
|
|
682
686
|
break;
|
|
687
|
+
case 'spotState':
|
|
688
|
+
{
|
|
689
|
+
const spotStateData = response.data;
|
|
690
|
+
if (spotStateData === null || spotStateData === void 0 ? void 0 : spotStateData.spotState) {
|
|
691
|
+
setSpotState(spotStateData.spotState);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
break;
|
|
683
695
|
default:
|
|
684
696
|
console.warn(`[HyperLiquid WS] Unknown channel: ${response.channel}`);
|
|
685
697
|
}
|
|
@@ -697,6 +709,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
697
709
|
setFinalAssetContexts,
|
|
698
710
|
setFinalAtOICaps,
|
|
699
711
|
setAggregatedClearingHouseState,
|
|
712
|
+
setSpotState,
|
|
700
713
|
]);
|
|
701
714
|
const connect = useCallback(() => {
|
|
702
715
|
if (!enabled)
|
|
@@ -795,6 +808,17 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
795
808
|
},
|
|
796
809
|
};
|
|
797
810
|
sendJsonMessage(unsubscribeMessage);
|
|
811
|
+
// Unsubscribe from spotState for previous address
|
|
812
|
+
if (subscribedAddress !== DEFAULT_ADDRESS) {
|
|
813
|
+
const unsubscribeSpotState = {
|
|
814
|
+
method: 'unsubscribe',
|
|
815
|
+
subscription: {
|
|
816
|
+
type: 'spotState',
|
|
817
|
+
user: subscribedAddress,
|
|
818
|
+
},
|
|
819
|
+
};
|
|
820
|
+
sendJsonMessage(unsubscribeSpotState);
|
|
821
|
+
}
|
|
798
822
|
}
|
|
799
823
|
// Subscribe to webData3 with new address
|
|
800
824
|
const subscribeWebData3 = {
|
|
@@ -814,11 +838,25 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
814
838
|
};
|
|
815
839
|
sendJsonMessage(subscribeWebData3);
|
|
816
840
|
sendJsonMessage(subscribeAllMids);
|
|
841
|
+
// Subscribe to spotState for real-time spot balances (USDH, USDC, etc.)
|
|
842
|
+
// Only subscribe if we have a real user address (not the default)
|
|
843
|
+
if (userAddress !== DEFAULT_ADDRESS) {
|
|
844
|
+
const subscribeSpotState = {
|
|
845
|
+
method: 'subscribe',
|
|
846
|
+
subscription: {
|
|
847
|
+
type: 'spotState',
|
|
848
|
+
user: userAddress,
|
|
849
|
+
},
|
|
850
|
+
};
|
|
851
|
+
sendJsonMessage(subscribeSpotState);
|
|
852
|
+
}
|
|
817
853
|
setSubscribedAddress(userAddress);
|
|
818
854
|
// Clear previous data when address changes
|
|
819
855
|
if (subscribedAddress && subscribedAddress !== userAddress) {
|
|
820
856
|
// clear aggregatedClearingHouseState
|
|
821
857
|
setAggregatedClearingHouseState(null);
|
|
858
|
+
// clear spotState
|
|
859
|
+
setSpotState(null);
|
|
822
860
|
}
|
|
823
861
|
}, [
|
|
824
862
|
isConnected,
|
|
@@ -826,6 +864,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
826
864
|
subscribedAddress,
|
|
827
865
|
sendJsonMessage,
|
|
828
866
|
setAggregatedClearingHouseState,
|
|
867
|
+
setSpotState,
|
|
829
868
|
]);
|
|
830
869
|
// Handle token subscriptions for activeAssetData
|
|
831
870
|
useEffect(() => {
|
|
@@ -956,31 +995,40 @@ class AccountSummaryCalculator {
|
|
|
956
995
|
return null;
|
|
957
996
|
}
|
|
958
997
|
const clearinghouseState = this.clearinghouseState;
|
|
959
|
-
const withdrawableAmount = parseFloat(clearinghouseState.withdrawable ||
|
|
960
|
-
const adjustedWithdrawable = Math.max(0, withdrawableAmount -
|
|
998
|
+
const withdrawableAmount = parseFloat(clearinghouseState.withdrawable || "0");
|
|
999
|
+
const adjustedWithdrawable = Math.max(0, withdrawableAmount -
|
|
1000
|
+
((_a = platformAccountSummary === null || platformAccountSummary === void 0 ? void 0 : platformAccountSummary.totalTwapChunkUsdValue) !== null && _a !== void 0 ? _a : 0) -
|
|
1001
|
+
((_b = platformAccountSummary === null || platformAccountSummary === void 0 ? void 0 : platformAccountSummary.totalLimitOrderUsdValue) !== null && _b !== void 0 ? _b : 0));
|
|
961
1002
|
const accountSummary = {
|
|
962
1003
|
balanceSummary: {
|
|
963
|
-
crossMaintenanceMarginUsed: clearinghouseState.crossMaintenanceMarginUsed ||
|
|
1004
|
+
crossMaintenanceMarginUsed: clearinghouseState.crossMaintenanceMarginUsed || "0",
|
|
964
1005
|
crossMarginSummary: {
|
|
965
|
-
accountValue: ((_c = clearinghouseState.crossMarginSummary) === null || _c === void 0 ? void 0 : _c.accountValue) ||
|
|
966
|
-
totalMarginUsed: ((_d = clearinghouseState.crossMarginSummary) === null || _d === void 0 ? void 0 : _d.totalMarginUsed) ||
|
|
967
|
-
totalNtlPos: ((_e = clearinghouseState.crossMarginSummary) === null || _e === void 0 ? void 0 : _e.totalNtlPos) ||
|
|
968
|
-
totalRawUsd: ((_f = clearinghouseState.crossMarginSummary) === null || _f === void 0 ? void 0 : _f.totalRawUsd) ||
|
|
1006
|
+
accountValue: ((_c = clearinghouseState.crossMarginSummary) === null || _c === void 0 ? void 0 : _c.accountValue) || "0",
|
|
1007
|
+
totalMarginUsed: ((_d = clearinghouseState.crossMarginSummary) === null || _d === void 0 ? void 0 : _d.totalMarginUsed) || "0",
|
|
1008
|
+
totalNtlPos: ((_e = clearinghouseState.crossMarginSummary) === null || _e === void 0 ? void 0 : _e.totalNtlPos) || "0",
|
|
1009
|
+
totalRawUsd: ((_f = clearinghouseState.crossMarginSummary) === null || _f === void 0 ? void 0 : _f.totalRawUsd) || "0",
|
|
969
1010
|
},
|
|
970
1011
|
marginSummary: {
|
|
971
|
-
accountValue: ((_g = clearinghouseState.marginSummary) === null || _g === void 0 ? void 0 : _g.accountValue) ||
|
|
972
|
-
totalMarginUsed: ((_h = clearinghouseState.marginSummary) === null || _h === void 0 ? void 0 : _h.totalMarginUsed) ||
|
|
973
|
-
totalNtlPos: ((_j = clearinghouseState.marginSummary) === null || _j === void 0 ? void 0 : _j.totalNtlPos) ||
|
|
974
|
-
totalRawUsd: ((_k = clearinghouseState.marginSummary) === null || _k === void 0 ? void 0 : _k.totalRawUsd) ||
|
|
1012
|
+
accountValue: ((_g = clearinghouseState.marginSummary) === null || _g === void 0 ? void 0 : _g.accountValue) || "0",
|
|
1013
|
+
totalMarginUsed: ((_h = clearinghouseState.marginSummary) === null || _h === void 0 ? void 0 : _h.totalMarginUsed) || "0",
|
|
1014
|
+
totalNtlPos: ((_j = clearinghouseState.marginSummary) === null || _j === void 0 ? void 0 : _j.totalNtlPos) || "0",
|
|
1015
|
+
totalRawUsd: ((_k = clearinghouseState.marginSummary) === null || _k === void 0 ? void 0 : _k.totalRawUsd) || "0",
|
|
975
1016
|
},
|
|
976
1017
|
time: clearinghouseState.time || Date.now(),
|
|
977
|
-
withdrawable: adjustedWithdrawable.toString()
|
|
978
|
-
}
|
|
1018
|
+
withdrawable: adjustedWithdrawable.toString(),
|
|
1019
|
+
},
|
|
1020
|
+
platformAccountSummary,
|
|
979
1021
|
};
|
|
980
1022
|
if (platformAccountSummary === null || platformAccountSummary === void 0 ? void 0 : platformAccountSummary.agentWalletAddress) {
|
|
981
1023
|
accountSummary.agentWallet = {
|
|
982
1024
|
address: platformAccountSummary.agentWalletAddress,
|
|
983
|
-
status: registeredAgentWallets.find((agent) => {
|
|
1025
|
+
status: registeredAgentWallets.find((agent) => {
|
|
1026
|
+
var _a;
|
|
1027
|
+
return agent.address.toLowerCase() ===
|
|
1028
|
+
((_a = platformAccountSummary.agentWalletAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
1029
|
+
})
|
|
1030
|
+
? "ACTIVE"
|
|
1031
|
+
: "EXPIRED",
|
|
984
1032
|
};
|
|
985
1033
|
}
|
|
986
1034
|
return accountSummary;
|
|
@@ -7560,7 +7608,7 @@ async function logout(baseUrl, refreshTokenVal) {
|
|
|
7560
7608
|
function useAuth() {
|
|
7561
7609
|
const context = useContext(PearHyperliquidContext);
|
|
7562
7610
|
if (!context) {
|
|
7563
|
-
throw new Error(
|
|
7611
|
+
throw new Error("usePortfolio must be used within a PearHyperliquidProvider");
|
|
7564
7612
|
}
|
|
7565
7613
|
const { apiBaseUrl, clientId } = context;
|
|
7566
7614
|
const [isReady, setIsReady] = useState(false);
|
|
@@ -7572,12 +7620,12 @@ function useAuth() {
|
|
|
7572
7620
|
const setIsAuthenticated = useUserData((s) => s.setIsAuthenticated);
|
|
7573
7621
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7574
7622
|
useEffect(() => {
|
|
7575
|
-
if (typeof window ==
|
|
7623
|
+
if (typeof window == "undefined") {
|
|
7576
7624
|
return;
|
|
7577
7625
|
}
|
|
7578
|
-
const access = localStorage.getItem(
|
|
7579
|
-
const refresh = localStorage.getItem(
|
|
7580
|
-
const addr = localStorage.getItem(
|
|
7626
|
+
const access = localStorage.getItem("accessToken");
|
|
7627
|
+
const refresh = localStorage.getItem("refreshToken");
|
|
7628
|
+
const addr = localStorage.getItem("address");
|
|
7581
7629
|
setAccessToken(access);
|
|
7582
7630
|
setRefreshToken(refresh);
|
|
7583
7631
|
setAddress(addr);
|
|
@@ -7589,7 +7637,9 @@ function useAuth() {
|
|
|
7589
7637
|
const cleanup = addAuthInterceptors({
|
|
7590
7638
|
apiBaseUrl,
|
|
7591
7639
|
getAccessToken: () => {
|
|
7592
|
-
return typeof window !==
|
|
7640
|
+
return typeof window !== "undefined"
|
|
7641
|
+
? window.localStorage.getItem("accessToken")
|
|
7642
|
+
: null;
|
|
7593
7643
|
},
|
|
7594
7644
|
refreshTokens: async () => {
|
|
7595
7645
|
const data = await refreshTokens();
|
|
@@ -7610,14 +7660,14 @@ function useAuth() {
|
|
|
7610
7660
|
async function loginWithSignedMessage(address, signature, timestamp) {
|
|
7611
7661
|
try {
|
|
7612
7662
|
const { data } = await authenticate(apiBaseUrl, {
|
|
7613
|
-
method:
|
|
7663
|
+
method: "eip712",
|
|
7614
7664
|
address,
|
|
7615
7665
|
clientId,
|
|
7616
7666
|
details: { signature, timestamp },
|
|
7617
7667
|
});
|
|
7618
|
-
window.localStorage.setItem(
|
|
7619
|
-
window.localStorage.setItem(
|
|
7620
|
-
window.localStorage.setItem(
|
|
7668
|
+
window.localStorage.setItem("accessToken", data.accessToken);
|
|
7669
|
+
window.localStorage.setItem("refreshToken", data.refreshToken);
|
|
7670
|
+
window.localStorage.setItem("address", address);
|
|
7621
7671
|
setAccessToken(data.accessToken);
|
|
7622
7672
|
setRefreshToken(data.refreshToken);
|
|
7623
7673
|
setAddress(address);
|
|
@@ -7629,10 +7679,15 @@ function useAuth() {
|
|
|
7629
7679
|
}
|
|
7630
7680
|
async function loginWithPrivyToken(address, appId, privyAccessToken) {
|
|
7631
7681
|
try {
|
|
7632
|
-
const { data } = await authenticateWithPrivy(apiBaseUrl, {
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7682
|
+
const { data } = await authenticateWithPrivy(apiBaseUrl, {
|
|
7683
|
+
address,
|
|
7684
|
+
clientId,
|
|
7685
|
+
appId,
|
|
7686
|
+
accessToken: privyAccessToken,
|
|
7687
|
+
});
|
|
7688
|
+
window.localStorage.setItem("accessToken", data.accessToken);
|
|
7689
|
+
window.localStorage.setItem("refreshToken", data.refreshToken);
|
|
7690
|
+
window.localStorage.setItem("address", address);
|
|
7636
7691
|
setAccessToken(data.accessToken);
|
|
7637
7692
|
setRefreshToken(data.refreshToken);
|
|
7638
7693
|
setAddress(address);
|
|
@@ -7643,28 +7698,30 @@ function useAuth() {
|
|
|
7643
7698
|
}
|
|
7644
7699
|
}
|
|
7645
7700
|
async function refreshTokens() {
|
|
7646
|
-
const refresh = window.localStorage.getItem(
|
|
7701
|
+
const refresh = window.localStorage.getItem("refreshToken");
|
|
7647
7702
|
if (!refresh)
|
|
7648
|
-
throw new Error(
|
|
7703
|
+
throw new Error("No refresh token");
|
|
7649
7704
|
const { data } = await refreshToken(apiBaseUrl, refresh);
|
|
7650
|
-
window.localStorage.setItem(
|
|
7651
|
-
window.localStorage.setItem(
|
|
7705
|
+
window.localStorage.setItem("accessToken", data.accessToken);
|
|
7706
|
+
window.localStorage.setItem("refreshToken", data.refreshToken);
|
|
7652
7707
|
setAccessToken(data.accessToken);
|
|
7653
7708
|
setRefreshToken(data.refreshToken);
|
|
7654
7709
|
setIsAuthenticated(true);
|
|
7655
7710
|
return data;
|
|
7656
7711
|
}
|
|
7657
7712
|
async function logout$1() {
|
|
7658
|
-
const refresh = window.localStorage.getItem(
|
|
7713
|
+
const refresh = window.localStorage.getItem("refreshToken");
|
|
7659
7714
|
if (refresh) {
|
|
7660
7715
|
try {
|
|
7661
7716
|
await logout(apiBaseUrl, refresh);
|
|
7662
7717
|
}
|
|
7663
|
-
catch (
|
|
7718
|
+
catch (_a) {
|
|
7719
|
+
/* ignore */
|
|
7720
|
+
}
|
|
7664
7721
|
}
|
|
7665
|
-
window.localStorage.removeItem(
|
|
7666
|
-
window.localStorage.removeItem(
|
|
7667
|
-
window.localStorage.removeItem(
|
|
7722
|
+
window.localStorage.removeItem("accessToken");
|
|
7723
|
+
window.localStorage.removeItem("refreshToken");
|
|
7724
|
+
window.localStorage.removeItem("address");
|
|
7668
7725
|
setAccessToken(null);
|
|
7669
7726
|
setRefreshToken(null);
|
|
7670
7727
|
setAddress(null);
|
|
@@ -7683,11 +7740,40 @@ function useAuth() {
|
|
|
7683
7740
|
};
|
|
7684
7741
|
}
|
|
7685
7742
|
|
|
7743
|
+
const useSpotBalances = () => {
|
|
7744
|
+
const spotState = useUserData((state) => state.spotState);
|
|
7745
|
+
return useMemo(() => {
|
|
7746
|
+
if (!spotState) {
|
|
7747
|
+
return {
|
|
7748
|
+
usdhBalance: undefined,
|
|
7749
|
+
spotUsdcBalance: undefined,
|
|
7750
|
+
isLoading: true,
|
|
7751
|
+
};
|
|
7752
|
+
}
|
|
7753
|
+
const balances = spotState.balances || [];
|
|
7754
|
+
let usdhBal = 0;
|
|
7755
|
+
let spotUsdcBal = 0;
|
|
7756
|
+
for (const balance of balances) {
|
|
7757
|
+
if (balance.coin === 'USDH') {
|
|
7758
|
+
usdhBal = parseFloat(balance.hold || '0') + parseFloat(balance.total || '0');
|
|
7759
|
+
}
|
|
7760
|
+
if (balance.coin === 'USDC') {
|
|
7761
|
+
spotUsdcBal = parseFloat(balance.hold || '0') + parseFloat(balance.total || '0');
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
return {
|
|
7765
|
+
usdhBalance: usdhBal,
|
|
7766
|
+
spotUsdcBalance: spotUsdcBal,
|
|
7767
|
+
isLoading: false,
|
|
7768
|
+
};
|
|
7769
|
+
}, [spotState]);
|
|
7770
|
+
};
|
|
7771
|
+
|
|
7686
7772
|
const PearHyperliquidContext = createContext(undefined);
|
|
7687
7773
|
/**
|
|
7688
7774
|
* React Provider for PearHyperliquidClient
|
|
7689
7775
|
*/
|
|
7690
|
-
const PearHyperliquidProvider = ({ children, apiBaseUrl =
|
|
7776
|
+
const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-v2.pearprotocol.io", clientId = "PEARPROTOCOLUI", wsUrl = "wss://hl-v2.pearprotocol.io/ws", }) => {
|
|
7691
7777
|
const address = useUserData((s) => s.address);
|
|
7692
7778
|
const setAddress = useUserData((s) => s.setAddress);
|
|
7693
7779
|
const perpsMetaAssets = useHyperliquidData((state) => state.perpMetaAssets);
|
|
@@ -7713,15 +7799,21 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7713
7799
|
const marketPrefixes = new Map(); // "xyz:TSLA" -> "xyz"
|
|
7714
7800
|
const cleanedPerpMetas = [];
|
|
7715
7801
|
// Process each market group (different collateral tokens)
|
|
7802
|
+
// Filter out vntl HIP-3 assets from being sent to frontend
|
|
7803
|
+
const FILTERED_PREFIXES = ['vntl'];
|
|
7716
7804
|
res.data.forEach((item) => {
|
|
7717
7805
|
// Convert numeric collateral token to human-readable name
|
|
7718
|
-
const collateralToken = item.collateralToken === 360 ?
|
|
7806
|
+
const collateralToken = item.collateralToken === 360 ? "USDH" : "USDC";
|
|
7719
7807
|
item.universe.forEach((asset) => {
|
|
7720
7808
|
var _a;
|
|
7721
|
-
const [maybePrefix, maybeMarket] = asset.name.split(
|
|
7809
|
+
const [maybePrefix, maybeMarket] = asset.name.split(":");
|
|
7722
7810
|
if (maybeMarket) {
|
|
7723
7811
|
// HIP-3 market with prefix (e.g., "xyz:TSLA")
|
|
7724
7812
|
const prefix = maybePrefix.toLowerCase();
|
|
7813
|
+
// Skip filtered prefixes (e.g., vntl)
|
|
7814
|
+
if (FILTERED_PREFIXES.includes(prefix)) {
|
|
7815
|
+
return;
|
|
7816
|
+
}
|
|
7725
7817
|
const displayName = maybeMarket;
|
|
7726
7818
|
const fullName = `${prefix}:${displayName}`;
|
|
7727
7819
|
// Store full market name with prefix
|
|
@@ -7802,7 +7894,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
7802
7894
|
function usePearHyperliquid() {
|
|
7803
7895
|
const ctx = useContext(PearHyperliquidContext);
|
|
7804
7896
|
if (!ctx)
|
|
7805
|
-
throw new Error(
|
|
7897
|
+
throw new Error("usePearHyperliquid must be used within a PearHyperliquidProvider");
|
|
7806
7898
|
return ctx;
|
|
7807
7899
|
}
|
|
7808
7900
|
|
|
@@ -7893,4 +7985,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
7893
7985
|
}
|
|
7894
7986
|
}
|
|
7895
7987
|
|
|
7896
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
7988
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotBalances, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
package/dist/provider.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -331,6 +331,7 @@ export interface PlatformAccountSummaryResponseDto {
|
|
|
331
331
|
*/
|
|
332
332
|
export interface AccountSummaryResponseDto {
|
|
333
333
|
balanceSummary: BalanceSummaryDto;
|
|
334
|
+
platformAccountSummary: PlatformAccountSummaryResponseDto | null;
|
|
334
335
|
agentWallet?: AgentWalletDto;
|
|
335
336
|
}
|
|
336
337
|
/**
|
|
@@ -444,12 +445,16 @@ export interface WebSocketMessage {
|
|
|
444
445
|
/**
|
|
445
446
|
* WebSocket response from HyperLiquid native API
|
|
446
447
|
*/
|
|
447
|
-
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle';
|
|
448
|
+
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState';
|
|
448
449
|
export interface HLChannelDataMap {
|
|
449
450
|
webData3: WebData3Response;
|
|
450
451
|
allMids: WsAllMidsData;
|
|
451
452
|
activeAssetData: ActiveAssetData;
|
|
452
453
|
candle: CandleData;
|
|
454
|
+
spotState: {
|
|
455
|
+
user: string;
|
|
456
|
+
spotState: SpotState;
|
|
457
|
+
};
|
|
453
458
|
}
|
|
454
459
|
export interface WebData3UserState {
|
|
455
460
|
agentAddress?: string;
|
|
@@ -767,3 +772,14 @@ export interface TokenSelectorConfig {
|
|
|
767
772
|
isLong: boolean;
|
|
768
773
|
index: number;
|
|
769
774
|
}
|
|
775
|
+
export interface SpotBalance {
|
|
776
|
+
coin: string;
|
|
777
|
+
token: number;
|
|
778
|
+
total: string;
|
|
779
|
+
hold: string;
|
|
780
|
+
entryNtl: string;
|
|
781
|
+
}
|
|
782
|
+
export interface SpotState {
|
|
783
|
+
user: string;
|
|
784
|
+
balances: SpotBalance[];
|
|
785
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountSummaryResponseDto, ClearinghouseState, ExtraAgent, PlatformAccountSummaryResponseDto } from
|
|
1
|
+
import type { AccountSummaryResponseDto, ClearinghouseState, ExtraAgent, PlatformAccountSummaryResponseDto } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* Account summary calculation utility class
|
|
4
4
|
*/
|