@pear-protocol/hyperliquid-sdk 0.0.66-usdh-1 → 0.0.66-usdh-3
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 -1
- package/dist/hooks/useAllUserBalances.d.ts +9 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +157 -40
- package/package.json +1 -1
- package/dist/hooks/useSpotBalances.d.ts +0 -7
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface AllUserBalances {
|
|
2
|
+
spotUsdcBalance: number | undefined;
|
|
3
|
+
availableToTradeUsdc: number | undefined;
|
|
4
|
+
spotUsdhBalance: number | undefined;
|
|
5
|
+
availableToTradeUsdh: number | undefined;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useAllUserBalances: () => AllUserBalances;
|
|
9
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1252,12 +1252,14 @@ declare function useAuth(): {
|
|
|
1252
1252
|
readonly logout: () => Promise<void>;
|
|
1253
1253
|
};
|
|
1254
1254
|
|
|
1255
|
-
interface
|
|
1256
|
-
usdhBalance: number | undefined;
|
|
1255
|
+
interface AllUserBalances {
|
|
1257
1256
|
spotUsdcBalance: number | undefined;
|
|
1257
|
+
availableToTradeUsdc: number | undefined;
|
|
1258
|
+
spotUsdhBalance: number | undefined;
|
|
1259
|
+
availableToTradeUsdh: number | undefined;
|
|
1258
1260
|
isLoading: boolean;
|
|
1259
1261
|
}
|
|
1260
|
-
declare const
|
|
1262
|
+
declare const useAllUserBalances: () => AllUserBalances;
|
|
1261
1263
|
|
|
1262
1264
|
interface UseHyperliquidWebSocketProps {
|
|
1263
1265
|
wsUrl: string;
|
|
@@ -1500,5 +1502,5 @@ declare function isHip3Market(symbol: string): boolean;
|
|
|
1500
1502
|
|
|
1501
1503
|
declare const useMarketData: any;
|
|
1502
1504
|
|
|
1503
|
-
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, 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,
|
|
1505
|
+
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, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, 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, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1504
1506
|
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
|
@@ -422,6 +422,7 @@ const useHyperliquidData = create((set, get) => ({
|
|
|
422
422
|
finalAssetContexts: null,
|
|
423
423
|
finalAtOICaps: null,
|
|
424
424
|
aggregatedClearingHouseState: null,
|
|
425
|
+
rawClearinghouseStates: null,
|
|
425
426
|
perpMetaAssets: null,
|
|
426
427
|
allPerpMetaAssets: null,
|
|
427
428
|
hip3Assets: new Map(),
|
|
@@ -468,6 +469,7 @@ const useHyperliquidData = create((set, get) => ({
|
|
|
468
469
|
setFinalAssetContexts: (value) => set({ finalAssetContexts: value }),
|
|
469
470
|
setFinalAtOICaps: (value) => set({ finalAtOICaps: value }),
|
|
470
471
|
setAggregatedClearingHouseState: (value) => set({ aggregatedClearingHouseState: value }),
|
|
472
|
+
setRawClearinghouseStates: (value) => set({ rawClearinghouseStates: value }),
|
|
471
473
|
setPerpMetaAssets: (value) => set({ perpMetaAssets: value }),
|
|
472
474
|
setAllPerpMetaAssets: (value) => set({ allPerpMetaAssets: value }),
|
|
473
475
|
setHip3Assets: (value) => set({ hip3Assets: value }),
|
|
@@ -734,7 +736,7 @@ const useUserSelection$1 = create((set, get) => ({
|
|
|
734
736
|
}));
|
|
735
737
|
|
|
736
738
|
const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
737
|
-
const { setAllMids, setActiveAssetData, upsertActiveAssetData, setCandleData, deleteCandleSymbol, deleteActiveAssetData, addCandleData, setFinalAssetContexts, setFinalAtOICaps, setAggregatedClearingHouseState, } = useHyperliquidData();
|
|
739
|
+
const { setAllMids, setActiveAssetData, upsertActiveAssetData, setCandleData, deleteCandleSymbol, deleteActiveAssetData, addCandleData, setFinalAssetContexts, setFinalAtOICaps, setAggregatedClearingHouseState, setRawClearinghouseStates, } = useHyperliquidData();
|
|
738
740
|
const { setSpotState } = useUserData();
|
|
739
741
|
const { candleInterval } = useUserSelection$1();
|
|
740
742
|
const longTokens = useUserSelection$1((s) => s.longTokens);
|
|
@@ -777,7 +779,21 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
777
779
|
case 'allDexsAssetCtxs':
|
|
778
780
|
{
|
|
779
781
|
const data = response.data;
|
|
780
|
-
|
|
782
|
+
// Filter out vntl and hyna to match perpMetaAssets filtering
|
|
783
|
+
const FILTERED_DEX_PREFIXES = ['vntl', 'hyna'];
|
|
784
|
+
const filtered = (data.ctxs || [])
|
|
785
|
+
.filter(([prefix]) => !FILTERED_DEX_PREFIXES.includes((prefix || '').toLowerCase()))
|
|
786
|
+
.sort((a, b) => {
|
|
787
|
+
// Sort to match perpMetaAssets order: default market first, then alphabetically
|
|
788
|
+
const prefixA = a[0] || '';
|
|
789
|
+
const prefixB = b[0] || '';
|
|
790
|
+
if (prefixA === '' && prefixB !== '')
|
|
791
|
+
return -1;
|
|
792
|
+
if (prefixA !== '' && prefixB === '')
|
|
793
|
+
return 1;
|
|
794
|
+
return prefixA.localeCompare(prefixB);
|
|
795
|
+
});
|
|
796
|
+
const finalAssetContexts = filtered.flatMap(([, ctxs]) => ctxs || []);
|
|
781
797
|
setFinalAssetContexts(finalAssetContexts);
|
|
782
798
|
}
|
|
783
799
|
break;
|
|
@@ -814,6 +830,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
814
830
|
withdrawable,
|
|
815
831
|
};
|
|
816
832
|
setAggregatedClearingHouseState(aggregatedClearingHouseState);
|
|
833
|
+
setRawClearinghouseStates(data.clearinghouseStates || null);
|
|
817
834
|
}
|
|
818
835
|
break;
|
|
819
836
|
case 'allMids':
|
|
@@ -891,6 +908,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
891
908
|
setFinalAssetContexts,
|
|
892
909
|
setFinalAtOICaps,
|
|
893
910
|
setAggregatedClearingHouseState,
|
|
911
|
+
setRawClearinghouseStates,
|
|
894
912
|
setSpotState,
|
|
895
913
|
]);
|
|
896
914
|
const connect = useCallback(() => {
|
|
@@ -1061,6 +1079,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1061
1079
|
if (subscribedAddress && subscribedAddress !== userAddress) {
|
|
1062
1080
|
// clear aggregatedClearingHouseState
|
|
1063
1081
|
setAggregatedClearingHouseState(null);
|
|
1082
|
+
setRawClearinghouseStates(null);
|
|
1064
1083
|
// clear spotState
|
|
1065
1084
|
setSpotState(null);
|
|
1066
1085
|
}
|
|
@@ -1070,6 +1089,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1070
1089
|
subscribedAddress,
|
|
1071
1090
|
sendJsonMessage,
|
|
1072
1091
|
setAggregatedClearingHouseState,
|
|
1092
|
+
setRawClearinghouseStates,
|
|
1073
1093
|
setSpotState,
|
|
1074
1094
|
]);
|
|
1075
1095
|
// Handle token subscriptions for activeAssetData
|
|
@@ -1484,19 +1504,11 @@ class TokenMetadataExtractor {
|
|
|
1484
1504
|
// No prefix specified - match non-HIP3 asset (no marketPrefix) or first matching asset
|
|
1485
1505
|
return !asset.marketPrefix;
|
|
1486
1506
|
});
|
|
1487
|
-
|
|
1488
|
-
const finalIndex = universeIndex === -1 && marketPrefix
|
|
1489
|
-
? perpMetaAssets.findIndex((asset) => asset.name === symbol && asset.marketPrefix === marketPrefix)
|
|
1490
|
-
: universeIndex;
|
|
1491
|
-
// Fallback: if still not found and no prefix, find first matching by name (for backward compatibility)
|
|
1492
|
-
const resolvedIndex = finalIndex === -1
|
|
1493
|
-
? perpMetaAssets.findIndex((asset) => asset.name === symbol)
|
|
1494
|
-
: finalIndex;
|
|
1495
|
-
if (resolvedIndex === -1) {
|
|
1507
|
+
if (universeIndex === -1) {
|
|
1496
1508
|
return null;
|
|
1497
1509
|
}
|
|
1498
|
-
const universeAsset = perpMetaAssets[
|
|
1499
|
-
const assetCtx = finalAssetContexts[
|
|
1510
|
+
const universeAsset = perpMetaAssets[universeIndex];
|
|
1511
|
+
const assetCtx = finalAssetContexts[universeIndex];
|
|
1500
1512
|
if (!assetCtx) {
|
|
1501
1513
|
return null;
|
|
1502
1514
|
}
|
|
@@ -8133,34 +8145,97 @@ function useAuth() {
|
|
|
8133
8145
|
};
|
|
8134
8146
|
}
|
|
8135
8147
|
|
|
8136
|
-
const
|
|
8148
|
+
const useAllUserBalances = () => {
|
|
8137
8149
|
const spotState = useUserData((state) => state.spotState);
|
|
8150
|
+
const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
|
|
8151
|
+
const rawClearinghouseStates = useHyperliquidData((state) => state.rawClearinghouseStates);
|
|
8152
|
+
const activeAssetData = useHyperliquidData((state) => state.activeAssetData);
|
|
8153
|
+
const { longTokensMetadata, shortTokensMetadata } = useTokenSelectionMetadata();
|
|
8138
8154
|
return useMemo(() => {
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8155
|
+
const isLoading = !spotState || !aggregatedClearingHouseState;
|
|
8156
|
+
// Helper function to truncate to 2 decimal places without rounding
|
|
8157
|
+
const truncateToTwoDecimals = (value) => {
|
|
8158
|
+
return Math.floor(value * 100) / 100;
|
|
8159
|
+
};
|
|
8160
|
+
// Get spot balances from spotState
|
|
8161
|
+
let spotUsdcBal = undefined;
|
|
8162
|
+
let spotUsdhBal = undefined;
|
|
8163
|
+
if (spotState) {
|
|
8164
|
+
const balances = spotState.balances || [];
|
|
8165
|
+
for (const balance of balances) {
|
|
8166
|
+
const total = parseFloat(balance.total || '0');
|
|
8167
|
+
if (balance.coin === 'USDC') {
|
|
8168
|
+
spotUsdcBal = truncateToTwoDecimals(total);
|
|
8169
|
+
}
|
|
8170
|
+
if (balance.coin === 'USDH') {
|
|
8171
|
+
spotUsdhBal = truncateToTwoDecimals(total);
|
|
8172
|
+
}
|
|
8153
8173
|
}
|
|
8154
|
-
|
|
8155
|
-
|
|
8174
|
+
}
|
|
8175
|
+
let availableToTradeUsdhFromAsset = 0;
|
|
8176
|
+
// This activeAssetData only contains data for SELECTED tokens (user's long and short Tokens)
|
|
8177
|
+
// It does NOT contain data for all tokens, so we cannot reliably use it for available to trade as used on hl trade page
|
|
8178
|
+
// so intead, we rely on rawClearinghouseStates which provides market-specific data
|
|
8179
|
+
// if (activeAssetData) {
|
|
8180
|
+
// Object.values(activeAssetData).forEach((assetData) => {
|
|
8181
|
+
// if (!assetData.availableToTrade) return;
|
|
8182
|
+
// const coinSymbol = assetData.coin;
|
|
8183
|
+
// const availableValue = truncateToTwoDecimals(
|
|
8184
|
+
// parseFloat(assetData.availableToTrade[0] || '0'),
|
|
8185
|
+
// );
|
|
8186
|
+
// // Determine collateral type based on market prefix
|
|
8187
|
+
// // HIP3 markets have prefix: "xyz:SYMBOL", "flx:SYMBOL", "vntl:SYMBOL", etc.
|
|
8188
|
+
// if (coinSymbol.includes(':')) {
|
|
8189
|
+
// const prefix = coinSymbol.split(':')[0];
|
|
8190
|
+
// if (prefix === 'xyz') {
|
|
8191
|
+
// // xyz markets use USDC
|
|
8192
|
+
// availableToTradeUsdcFromAsset = availableValue;
|
|
8193
|
+
// } else {
|
|
8194
|
+
// // flx, vntl, hyna and other markets use USDH
|
|
8195
|
+
// availableToTradeUsdhFromAsset = availableValue;
|
|
8196
|
+
// }
|
|
8197
|
+
// } else {
|
|
8198
|
+
// // Regular markets without prefix are automatically USDC
|
|
8199
|
+
// availableToTradeUsdcFromAsset = availableValue;
|
|
8200
|
+
// }
|
|
8201
|
+
// });
|
|
8202
|
+
// }
|
|
8203
|
+
// Calculate USDC available to trade
|
|
8204
|
+
// Priority 1: Use value from activeAssetData if available (> 0)
|
|
8205
|
+
// Priority 2: Calculate from USDC-specific clearinghouseState (empty prefix)
|
|
8206
|
+
let availableToTradeUsdcValue = undefined;
|
|
8207
|
+
if (rawClearinghouseStates) {
|
|
8208
|
+
// Find USDC market (empty prefix)
|
|
8209
|
+
const usdcMarket = rawClearinghouseStates.find(([prefix]) => prefix === '');
|
|
8210
|
+
const usdcState = usdcMarket === null || usdcMarket === void 0 ? void 0 : usdcMarket[1];
|
|
8211
|
+
if (usdcState === null || usdcState === void 0 ? void 0 : usdcState.marginSummary) {
|
|
8212
|
+
const accountValue = parseFloat(usdcState.marginSummary.accountValue || '0');
|
|
8213
|
+
const totalMarginUsed = parseFloat(usdcState.marginSummary.totalMarginUsed || '0');
|
|
8214
|
+
const calculatedValue = Math.max(0, accountValue - totalMarginUsed);
|
|
8215
|
+
availableToTradeUsdcValue = truncateToTwoDecimals(calculatedValue);
|
|
8156
8216
|
}
|
|
8157
8217
|
}
|
|
8218
|
+
// Calculate USDH available to trade
|
|
8219
|
+
// Priority 1: Use value from activeAssetData if available (> 0)
|
|
8220
|
+
// Priority 2: Use spot USDH balance
|
|
8221
|
+
const availableToTradeUsdhValue = availableToTradeUsdhFromAsset > 0
|
|
8222
|
+
? availableToTradeUsdhFromAsset
|
|
8223
|
+
: spotUsdhBal;
|
|
8158
8224
|
return {
|
|
8159
|
-
usdhBalance: usdhBal,
|
|
8160
8225
|
spotUsdcBalance: spotUsdcBal,
|
|
8161
|
-
|
|
8226
|
+
availableToTradeUsdc: availableToTradeUsdcValue,
|
|
8227
|
+
spotUsdhBalance: spotUsdhBal,
|
|
8228
|
+
availableToTradeUsdh: availableToTradeUsdhValue,
|
|
8229
|
+
isLoading,
|
|
8162
8230
|
};
|
|
8163
|
-
}, [
|
|
8231
|
+
}, [
|
|
8232
|
+
spotState,
|
|
8233
|
+
aggregatedClearingHouseState,
|
|
8234
|
+
rawClearinghouseStates,
|
|
8235
|
+
activeAssetData,
|
|
8236
|
+
longTokensMetadata,
|
|
8237
|
+
shortTokensMetadata,
|
|
8238
|
+
]);
|
|
8164
8239
|
};
|
|
8165
8240
|
|
|
8166
8241
|
const PearHyperliquidContext = createContext(undefined);
|
|
@@ -8191,15 +8266,18 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-ui.pearpro
|
|
|
8191
8266
|
.then((res) => {
|
|
8192
8267
|
const assetToMarkets = new Map();
|
|
8193
8268
|
const marketPrefixes = new Map();
|
|
8194
|
-
const cleanedPerpMetas = [];
|
|
8195
|
-
const allPerpMetas = [];
|
|
8196
8269
|
const FILTERED_PREFIXES = ['vntl', 'hyna'];
|
|
8270
|
+
// Group assets by market prefix to match WebSocket flattening order
|
|
8271
|
+
// WebSocket sends in order: "", "flx", "hyna", "vntl", "xyz"
|
|
8272
|
+
const assetsByPrefix = new Map();
|
|
8273
|
+
const allAssetsByPrefix = new Map();
|
|
8197
8274
|
res.data.forEach((item) => {
|
|
8198
8275
|
const collateralToken = item.collateralToken === 360 ? 'USDH' : 'USDC';
|
|
8199
8276
|
item.universe.forEach((asset) => {
|
|
8200
8277
|
var _a;
|
|
8201
8278
|
const [maybePrefix, maybeMarket] = asset.name.split(':');
|
|
8202
8279
|
if (maybeMarket) {
|
|
8280
|
+
// HIP3 asset with market prefix
|
|
8203
8281
|
const prefix = maybePrefix.toLowerCase();
|
|
8204
8282
|
const displayName = maybeMarket;
|
|
8205
8283
|
const fullName = `${prefix}:${displayName}`;
|
|
@@ -8219,21 +8297,60 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-ui.pearpro
|
|
|
8219
8297
|
marketPrefix: prefix,
|
|
8220
8298
|
collateralToken,
|
|
8221
8299
|
};
|
|
8222
|
-
|
|
8300
|
+
// Group by market prefix
|
|
8301
|
+
const allList = allAssetsByPrefix.get(prefix) || [];
|
|
8302
|
+
allList.push(assetWithMeta);
|
|
8303
|
+
allAssetsByPrefix.set(prefix, allList);
|
|
8223
8304
|
if (!FILTERED_PREFIXES.includes(prefix)) {
|
|
8224
|
-
|
|
8305
|
+
const cleanedList = assetsByPrefix.get(prefix) || [];
|
|
8306
|
+
cleanedList.push(assetWithMeta);
|
|
8307
|
+
assetsByPrefix.set(prefix, cleanedList);
|
|
8225
8308
|
}
|
|
8226
8309
|
}
|
|
8227
8310
|
else {
|
|
8311
|
+
// Default market asset (no prefix)
|
|
8228
8312
|
const assetWithMeta = {
|
|
8229
8313
|
...asset,
|
|
8230
8314
|
collateralToken,
|
|
8231
8315
|
};
|
|
8232
|
-
|
|
8233
|
-
|
|
8316
|
+
// Add to default market group ("")
|
|
8317
|
+
const defaultList = assetsByPrefix.get('') || [];
|
|
8318
|
+
defaultList.push(assetWithMeta);
|
|
8319
|
+
assetsByPrefix.set('', defaultList);
|
|
8320
|
+
const allDefaultList = allAssetsByPrefix.get('') || [];
|
|
8321
|
+
allDefaultList.push(assetWithMeta);
|
|
8322
|
+
allAssetsByPrefix.set('', allDefaultList);
|
|
8234
8323
|
}
|
|
8235
8324
|
});
|
|
8236
8325
|
});
|
|
8326
|
+
// Flatten in consistent order: default market first, then HIP3 markets alphabetically
|
|
8327
|
+
// This ensures both REST API and WebSocket data align properly
|
|
8328
|
+
const cleanedPrefixes = Array.from(assetsByPrefix.keys()).sort((a, b) => {
|
|
8329
|
+
// Empty prefix (default market) always comes first
|
|
8330
|
+
if (a === '' && b !== '')
|
|
8331
|
+
return -1;
|
|
8332
|
+
if (a !== '' && b === '')
|
|
8333
|
+
return 1;
|
|
8334
|
+
// HIP3 markets sorted alphabetically
|
|
8335
|
+
return a.localeCompare(b);
|
|
8336
|
+
});
|
|
8337
|
+
const allPrefixes = Array.from(allAssetsByPrefix.keys()).sort((a, b) => {
|
|
8338
|
+
if (a === '' && b !== '')
|
|
8339
|
+
return -1;
|
|
8340
|
+
if (a !== '' && b === '')
|
|
8341
|
+
return 1;
|
|
8342
|
+
return a.localeCompare(b);
|
|
8343
|
+
});
|
|
8344
|
+
const cleanedPerpMetas = [];
|
|
8345
|
+
const allPerpMetas = [];
|
|
8346
|
+
cleanedPrefixes.forEach((prefix) => {
|
|
8347
|
+
const assets = assetsByPrefix.get(prefix) || [];
|
|
8348
|
+
cleanedPerpMetas.push(...assets);
|
|
8349
|
+
});
|
|
8350
|
+
allPrefixes.forEach((prefix) => {
|
|
8351
|
+
const assets = allAssetsByPrefix.get(prefix) || [];
|
|
8352
|
+
allPerpMetas.push(...assets);
|
|
8353
|
+
});
|
|
8237
8354
|
setHip3Assets(assetToMarkets);
|
|
8238
8355
|
setHip3MarketPrefixes(marketPrefixes);
|
|
8239
8356
|
setPerpMetaAssets(cleanedPerpMetas);
|
|
@@ -8376,4 +8493,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8376
8493
|
}
|
|
8377
8494
|
}
|
|
8378
8495
|
|
|
8379
|
-
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, 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,
|
|
8496
|
+
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, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, 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, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
package/package.json
CHANGED