@pear-protocol/symmio-client 0.2.47 → 0.3.0

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.
@@ -707,6 +707,17 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
707
707
  // src/react/query-keys.ts
708
708
  var symmKeys = {
709
709
  all: ["symm"],
710
+ balancesRoot: ["symm", "balances"],
711
+ accountSummaryRoot: ["symm", "accountSummary"],
712
+ accountDataRoot: ["symm", "accountData"],
713
+ approvalRoot: ["symm", "approval"],
714
+ positionsRoot: ["symm", "positions"],
715
+ openOrdersRoot: ["symm", "openOrders"],
716
+ tradeHistoryRoot: ["symm", "tradeHistory"],
717
+ portfolioRoot: ["symm", "portfolio"],
718
+ tpslOrdersRoot: ["symm", "tpslOrders"],
719
+ twapOrdersRoot: ["symm", "twapOrders"],
720
+ triggerOrdersRoot: ["symm", "triggerOrders"],
710
721
  accounts: (address, chainId) => ["symm", "accounts", address, chainId],
711
722
  accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
712
723
  accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
@@ -714,7 +725,7 @@ var symmKeys = {
714
725
  accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
715
726
  accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
716
727
  signature: (address, chainId) => ["symm", "signature", address, chainId],
717
- auth: (accountAddress, chainId) => ["symm", "auth", accountAddress, chainId],
728
+ auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
718
729
  approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
719
730
  balances: (address, chainId) => ["symm", "balances", address, chainId],
720
731
  positions: (params) => ["symm", "positions", params],
@@ -734,8 +745,8 @@ var symmKeys = {
734
745
  fundingPayments: (params) => ["symm", "fundingPayments", params],
735
746
  fundingHistory: (params) => ["symm", "fundingHistory", params],
736
747
  portfolio: (params) => ["symm", "portfolio", params],
737
- notifications: (address, chainId) => ["symm", "notifications", address, chainId],
738
- unreadCount: (address, chainId) => ["symm", "unreadCount", address, chainId],
748
+ notifications: (params) => ["symm", "notifications", params],
749
+ unreadCount: (params) => ["symm", "unreadCount", params],
739
750
  availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
740
751
  pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
741
752
  pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
@@ -745,23 +756,25 @@ var symmKeys = {
745
756
  };
746
757
 
747
758
  // src/react/auth-cache.ts
748
- function getAuthQueryData(queryClient, accountAddress, chainId) {
749
- return queryClient.getQueryData(symmKeys.auth(accountAddress, chainId)) ?? null;
759
+ function getAuthQueryData(queryClient, accountAddress, chainId, signerAddress) {
760
+ return queryClient.getQueryData(
761
+ symmKeys.auth(accountAddress, chainId, signerAddress)
762
+ ) ?? null;
750
763
  }
751
- function setAuthQueryData(queryClient, accountAddress, chainId, entry) {
752
- queryClient.setQueryData(symmKeys.auth(accountAddress, chainId), entry);
764
+ function setAuthQueryData(queryClient, accountAddress, chainId, signerAddress, entry) {
765
+ queryClient.setQueryData(symmKeys.auth(accountAddress, chainId, signerAddress), entry);
753
766
  }
754
- function clearAuthQueryData(queryClient, accountAddress, chainId) {
767
+ function clearAuthQueryData(queryClient, accountAddress, chainId, signerAddress) {
755
768
  queryClient.removeQueries({
756
- queryKey: symmKeys.auth(accountAddress, chainId),
769
+ queryKey: symmKeys.auth(accountAddress, chainId, signerAddress),
757
770
  exact: true
758
771
  });
759
772
  }
760
773
  function clearPersistedAuthState(accountAddress, chainId) {
761
774
  clearCachedToken(accountAddress, chainId);
762
775
  }
763
- function getAuthTokenFromRuntimeCache(queryClient, accountAddress, chainId) {
764
- const inQuery = getAuthQueryData(queryClient, accountAddress, chainId);
776
+ function getAuthTokenFromRuntimeCache(queryClient, accountAddress, chainId, signerAddress) {
777
+ const inQuery = getAuthQueryData(queryClient, accountAddress, chainId, signerAddress) ?? getAuthQueryData(queryClient, accountAddress, chainId);
765
778
  if (inQuery && inQuery.expiresAt > Date.now()) {
766
779
  return inQuery.token;
767
780
  }
@@ -769,7 +782,7 @@ function getAuthTokenFromRuntimeCache(queryClient, accountAddress, chainId) {
769
782
  if (!persisted) {
770
783
  return null;
771
784
  }
772
- setAuthQueryData(queryClient, accountAddress, chainId, persisted);
785
+ setAuthQueryData(queryClient, accountAddress, chainId, signerAddress, persisted);
773
786
  return persisted.token;
774
787
  }
775
788
  async function resolveAuthTokenEntry({
@@ -785,13 +798,13 @@ async function resolveAuthTokenEntry({
785
798
  return null;
786
799
  }
787
800
  if (!force) {
788
- const inQuery = getAuthQueryData(queryClient, accountAddress, chainId);
801
+ const inQuery = getAuthQueryData(queryClient, accountAddress, chainId, signerAddress);
789
802
  if (inQuery && inQuery.expiresAt > Date.now()) {
790
803
  return inQuery;
791
804
  }
792
805
  const persisted = getCachedTokenEntry(accountAddress, chainId);
793
806
  if (persisted) {
794
- setAuthQueryData(queryClient, accountAddress, chainId, persisted);
807
+ setAuthQueryData(queryClient, accountAddress, chainId, signerAddress, persisted);
795
808
  return persisted;
796
809
  }
797
810
  }
@@ -802,12 +815,12 @@ async function resolveAuthTokenEntry({
802
815
  chainId,
803
816
  siweDomain
804
817
  );
805
- setAuthQueryData(queryClient, accountAddress, chainId, fresh);
818
+ setAuthQueryData(queryClient, accountAddress, chainId, signerAddress, fresh);
806
819
  return fresh;
807
820
  }
808
- function clearAuthState(queryClient, accountAddress, chainId) {
821
+ function clearAuthState(queryClient, accountAddress, chainId, signerAddress) {
809
822
  clearPersistedAuthState(accountAddress, chainId);
810
- clearAuthQueryData(queryClient, accountAddress, chainId);
823
+ clearAuthQueryData(queryClient, accountAddress, chainId, signerAddress);
811
824
  }
812
825
 
813
826
  // src/react/hooks/use-symm-auth.ts
@@ -881,7 +894,7 @@ function useSymmAuth(params) {
881
894
  ]
882
895
  );
883
896
  const authQuery = reactQuery.useQuery({
884
- queryKey: symmKeys.auth(activeAccountAddress, chainId),
897
+ queryKey: symmKeys.auth(activeAccountAddress, chainId, address),
885
898
  queryFn: async () => {
886
899
  const tokenEntry = await resolveAuthTokenEntry({
887
900
  queryClient,
@@ -903,9 +916,9 @@ function useSymmAuth(params) {
903
916
  });
904
917
  const clearAuth = react.useCallback(() => {
905
918
  if (activeAccountAddress) {
906
- clearAuthState(queryClient, activeAccountAddress, chainId);
919
+ clearAuthState(queryClient, activeAccountAddress, chainId, address);
907
920
  }
908
- }, [activeAccountAddress, chainId, queryClient]);
921
+ }, [activeAccountAddress, address, chainId, queryClient]);
909
922
  const token = authQuery.data?.token ?? null;
910
923
  return {
911
924
  accessToken: token,
@@ -1670,22 +1683,22 @@ function useSymmRevokeDelegationMutation(params = {}, options) {
1670
1683
 
1671
1684
  // src/react/cache.ts
1672
1685
  function invalidateBalances(qc) {
1673
- qc.invalidateQueries({ queryKey: ["symm", "balances"] });
1674
- qc.invalidateQueries({ queryKey: ["symm", "accountSummary"] });
1675
- qc.invalidateQueries({ queryKey: ["symm", "accountData"] });
1676
- qc.invalidateQueries({ queryKey: ["symm", "portfolio"] });
1686
+ qc.invalidateQueries({ queryKey: symmKeys.balancesRoot });
1687
+ qc.invalidateQueries({ queryKey: symmKeys.accountSummaryRoot });
1688
+ qc.invalidateQueries({ queryKey: symmKeys.accountDataRoot });
1689
+ qc.invalidateQueries({ queryKey: symmKeys.portfolioRoot });
1677
1690
  }
1678
1691
  function invalidatePositions(qc) {
1679
- qc.invalidateQueries({ queryKey: ["symm", "positions"] });
1680
- qc.invalidateQueries({ queryKey: ["symm", "openOrders"] });
1681
- qc.invalidateQueries({ queryKey: ["symm", "tradeHistory"] });
1682
- qc.invalidateQueries({ queryKey: ["symm", "portfolio"] });
1692
+ qc.invalidateQueries({ queryKey: symmKeys.positionsRoot });
1693
+ qc.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
1694
+ qc.invalidateQueries({ queryKey: symmKeys.tradeHistoryRoot });
1695
+ qc.invalidateQueries({ queryKey: symmKeys.portfolioRoot });
1683
1696
  }
1684
1697
  function invalidateOrders(qc) {
1685
- qc.invalidateQueries({ queryKey: ["symm", "openOrders"] });
1686
- qc.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
1687
- qc.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
1688
- qc.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
1698
+ qc.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
1699
+ qc.invalidateQueries({ queryKey: symmKeys.tpslOrdersRoot });
1700
+ qc.invalidateQueries({ queryKey: symmKeys.twapOrdersRoot });
1701
+ qc.invalidateQueries({ queryKey: symmKeys.triggerOrdersRoot });
1689
1702
  }
1690
1703
 
1691
1704
  // src/react/hooks/use-symm-instant-trade.ts
@@ -1702,12 +1715,13 @@ function useInstantTradeDeps(params) {
1702
1715
  defaultTarget,
1703
1716
  multiAccount,
1704
1717
  publicClient: params.publicClient,
1718
+ signerAddress: address,
1705
1719
  symmCoreClient,
1706
1720
  walletClient: params.walletClient
1707
1721
  };
1708
1722
  }
1709
1723
  async function ensureInstantTradeReady(deps, queryClient, request) {
1710
- const { chainId, defaultAccountAddress, defaultSelectors, defaultTarget, multiAccount, publicClient, walletClient } = deps;
1724
+ const { chainId, defaultAccountAddress, defaultSelectors, defaultTarget, multiAccount, publicClient, signerAddress, walletClient } = deps;
1711
1725
  if (!publicClient || !walletClient) throw new Error("Clients not available");
1712
1726
  const accountAddress = request?.accountAddress ?? defaultAccountAddress;
1713
1727
  const target = request?.target ?? defaultTarget;
@@ -1717,7 +1731,12 @@ async function ensureInstantTradeReady(deps, queryClient, request) {
1717
1731
  if (selectors.length === 0) {
1718
1732
  throw new Error("at least one delegation selector is required");
1719
1733
  }
1720
- const accessToken = getAuthTokenFromRuntimeCache(queryClient, accountAddress, chainId);
1734
+ const accessToken = getAuthTokenFromRuntimeCache(
1735
+ queryClient,
1736
+ accountAddress,
1737
+ chainId,
1738
+ signerAddress
1739
+ );
1721
1740
  if (!accessToken) {
1722
1741
  throw new Error("auth token is required for instant trading");
1723
1742
  }
@@ -2130,7 +2149,12 @@ function useSymmCancelClose(options) {
2130
2149
  }
2131
2150
  const resolvedAccountAddress = accountAddress ?? address;
2132
2151
  const resolvedChainId = overrideChainId ?? chainId;
2133
- const resolvedAuthToken = authToken ?? (resolvedAccountAddress ? getAuthTokenFromRuntimeCache(queryClient, resolvedAccountAddress, resolvedChainId) : null);
2152
+ const resolvedAuthToken = authToken ?? (resolvedAccountAddress ? getAuthTokenFromRuntimeCache(
2153
+ queryClient,
2154
+ resolvedAccountAddress,
2155
+ resolvedChainId,
2156
+ address
2157
+ ) : null);
2134
2158
  if (!resolvedAuthToken) {
2135
2159
  throw new Error("auth token is required to cancel a pending close");
2136
2160
  }
@@ -2161,7 +2185,12 @@ function useSymmCloseOrder(options) {
2161
2185
  return symmCoreClient.orders.close(request.id, {
2162
2186
  kind: request.kind,
2163
2187
  type: request.type,
2164
- authToken: request.authToken ?? (resolvedAccountAddress ? getAuthTokenFromRuntimeCache(queryClient, resolvedAccountAddress, chainId) ?? void 0 : void 0)
2188
+ authToken: request.authToken ?? (resolvedAccountAddress ? getAuthTokenFromRuntimeCache(
2189
+ queryClient,
2190
+ resolvedAccountAddress,
2191
+ chainId,
2192
+ address
2193
+ ) ?? void 0 : void 0)
2165
2194
  });
2166
2195
  }
2167
2196
  });
@@ -2234,7 +2263,7 @@ function useSymmDepositMutation(params = {}, options) {
2234
2263
  ...withSymmMutationConfig(options?.mutation, {
2235
2264
  onSuccess: () => {
2236
2265
  invalidateBalances(queryClient);
2237
- queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
2266
+ queryClient.invalidateQueries({ queryKey: symmKeys.approvalRoot });
2238
2267
  }
2239
2268
  }),
2240
2269
  mutationFn: async ({
@@ -2253,7 +2282,7 @@ function useSymmDepositAndAllocateMutation(params = {}, options) {
2253
2282
  ...withSymmMutationConfig(options?.mutation, {
2254
2283
  onSuccess: () => {
2255
2284
  invalidateBalances(queryClient);
2256
- queryClient.invalidateQueries({ queryKey: ["symm", "approval"] });
2285
+ queryClient.invalidateQueries({ queryKey: symmKeys.approvalRoot });
2257
2286
  }
2258
2287
  }),
2259
2288
  mutationFn: async ({
@@ -25310,7 +25339,8 @@ function useResolveTradeAuthToken(params = {}) {
25310
25339
  const inMemoryToken = getAuthTokenFromRuntimeCache(
25311
25340
  queryClient,
25312
25341
  resolvedAccountAddress,
25313
- chainId
25342
+ chainId,
25343
+ address
25314
25344
  );
25315
25345
  if (inMemoryToken) {
25316
25346
  logTradeAuth("resolve-auth:store-hit", {
@@ -25446,13 +25476,14 @@ function useSymmUpdatePositionMutation(paramsOrOptions, maybeOptions) {
25446
25476
  typedRequest.authToken,
25447
25477
  typedRequest.accountAddress
25448
25478
  );
25449
- if (!authToken) {
25450
- throw new Error("auth token is required to update a position");
25451
- }
25452
- return symmCoreClient.positions.update(positionId, {
25479
+ const requestWithOptionalAuth = authToken ? {
25453
25480
  ...request,
25454
25481
  authToken
25455
- });
25482
+ } : request;
25483
+ return symmCoreClient.positions.update(
25484
+ positionId,
25485
+ requestWithOptionalAuth
25486
+ );
25456
25487
  }
25457
25488
  });
25458
25489
  }
@@ -25828,9 +25859,10 @@ async function fetch24hrTickers() {
25828
25859
  }
25829
25860
 
25830
25861
  // src/react/hooks/use-symm-token-selection-markets.ts
25862
+ var EMPTY_MARKETS = [];
25831
25863
  function useSymmTokenSelectionMarkets(params) {
25832
25864
  const query = useSymmHedgerMarkets(params);
25833
- const baseMarkets = query.data?.filteredMarkets ?? query.data?.markets ?? [];
25865
+ const baseMarkets = query.data?.filteredMarkets ?? query.data?.markets ?? EMPTY_MARKETS;
25834
25866
  const marketSymbols = react.useMemo(
25835
25867
  () => Array.from(
25836
25868
  new Set(
@@ -26009,61 +26041,81 @@ function useSymmPortfolio(params) {
26009
26041
  function useResolvedNotificationsParams(params) {
26010
26042
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26011
26043
  const chainId = params.chainId ?? ctxChainId;
26044
+ const accountAddress = params.accountAddress;
26045
+ const address = accountAddress ? void 0 : params.address;
26012
26046
  return {
26013
26047
  symmCoreClient,
26014
26048
  chainId,
26015
- userAddress: params.userAddress,
26049
+ accountAddress,
26050
+ address,
26016
26051
  query: params.query
26017
26052
  };
26018
26053
  }
26019
26054
  function useSymmNotificationsQuery(params) {
26020
- const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
26021
- const internalEnabled = !!symmCoreClient && !!userAddress;
26055
+ const { symmCoreClient, chainId, accountAddress, address, query } = useResolvedNotificationsParams(params);
26056
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || address);
26057
+ const queryParams = {
26058
+ accountAddress,
26059
+ address,
26060
+ chainId
26061
+ };
26022
26062
  return reactQuery.useQuery({
26023
26063
  ...query,
26024
- queryKey: symmKeys.notifications(userAddress, chainId),
26064
+ queryKey: symmKeys.notifications(queryParams),
26025
26065
  queryFn: () => symmCoreClient.notifications.list({
26026
- userAddress,
26066
+ accountAddress,
26067
+ address,
26027
26068
  chainId
26028
26069
  }),
26029
26070
  enabled: internalEnabled && (query?.enabled ?? true)
26030
26071
  });
26031
26072
  }
26032
26073
  function useSymmUnreadCountQuery(params) {
26033
- const { symmCoreClient, chainId, userAddress, query } = useResolvedNotificationsParams(params);
26034
- const internalEnabled = !!symmCoreClient && !!userAddress;
26074
+ const { symmCoreClient, chainId, accountAddress, address, query } = useResolvedNotificationsParams(params);
26075
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || address);
26076
+ const queryParams = {
26077
+ accountAddress,
26078
+ address,
26079
+ chainId
26080
+ };
26035
26081
  return reactQuery.useQuery({
26036
26082
  ...query,
26037
- queryKey: symmKeys.unreadCount(userAddress, chainId),
26083
+ queryKey: symmKeys.unreadCount(queryParams),
26038
26084
  queryFn: () => symmCoreClient.notifications.getUnreadCount({
26039
- userAddress,
26085
+ accountAddress,
26086
+ address,
26040
26087
  chainId
26041
26088
  }),
26042
26089
  enabled: internalEnabled && (query?.enabled ?? true)
26043
26090
  });
26044
26091
  }
26045
26092
  function useSymmMarkReadNotificationMutation(params, options) {
26046
- const { symmCoreClient, chainId, userAddress } = useResolvedNotificationsParams(params);
26093
+ const { symmCoreClient, chainId, accountAddress, address } = useResolvedNotificationsParams(params);
26047
26094
  const queryClient = reactQuery.useQueryClient();
26095
+ const queryParams = {
26096
+ accountAddress,
26097
+ address,
26098
+ chainId
26099
+ };
26048
26100
  return reactQuery.useMutation({
26049
26101
  ...withSymmMutationConfig(options?.mutation, {
26050
26102
  onSuccess: () => {
26051
26103
  queryClient.invalidateQueries({
26052
- queryKey: symmKeys.notifications(userAddress, chainId)
26104
+ queryKey: symmKeys.notifications(queryParams)
26053
26105
  });
26054
26106
  queryClient.invalidateQueries({
26055
- queryKey: symmKeys.unreadCount(userAddress, chainId)
26107
+ queryKey: symmKeys.unreadCount(queryParams)
26056
26108
  });
26057
26109
  }
26058
26110
  }),
26059
26111
  mutationFn: async ({ id, timestamp }) => {
26060
- if (!symmCoreClient || !userAddress) {
26112
+ if (!symmCoreClient || !accountAddress) {
26061
26113
  throw new Error("symm-core client not available");
26062
26114
  }
26063
26115
  return symmCoreClient.notifications.markRead({
26064
26116
  id,
26065
26117
  timestamp,
26066
- userAddress,
26118
+ accountAddress,
26067
26119
  chainId
26068
26120
  });
26069
26121
  }
@@ -26087,7 +26139,8 @@ function useSymmPendingIds(params) {
26087
26139
  function useSymmPendingInstantOpens(params) {
26088
26140
  const {
26089
26141
  symmCoreClient,
26090
- chainId: ctxChainId
26142
+ chainId: ctxChainId,
26143
+ address
26091
26144
  } = useSymmContext();
26092
26145
  const queryClient = reactQuery.useQueryClient();
26093
26146
  const { accountAddress, authToken: providedAuthToken } = params;
@@ -26097,7 +26150,12 @@ function useSymmPendingInstantOpens(params) {
26097
26150
  ...params.query,
26098
26151
  queryKey: symmKeys.pendingInstantOpens(accountAddress, chainId),
26099
26152
  queryFn: async () => {
26100
- const authToken = providedAuthToken ?? getAuthTokenFromRuntimeCache(queryClient, accountAddress, chainId);
26153
+ const authToken = providedAuthToken ?? getAuthTokenFromRuntimeCache(
26154
+ queryClient,
26155
+ accountAddress,
26156
+ chainId,
26157
+ address
26158
+ );
26101
26159
  if (!authToken) {
26102
26160
  throw new Error("failed to acquire auth token for pending instant opens");
26103
26161
  }
@@ -26121,122 +26179,6 @@ function useSymmTwapOrder(params) {
26121
26179
  enabled: internalEnabled && (params.query?.enabled ?? true)
26122
26180
  });
26123
26181
  }
26124
- var useSymmWsStore = zustand.create((set) => ({
26125
- isConnected: false,
26126
- setConnected: (isConnected) => set({ isConnected })
26127
- }));
26128
-
26129
- // src/react/hooks/use-symm-ws.ts
26130
- function asUnsubscribeFn(value) {
26131
- return typeof value === "function" ? value : null;
26132
- }
26133
- function useSymmWs(params = {}) {
26134
- const {
26135
- symmCoreClient: ctxClient,
26136
- address: ctxAddress,
26137
- chainId: ctxChainId
26138
- } = useSymmContext();
26139
- const queryClient = reactQuery.useQueryClient();
26140
- const isConnected = useSymmWsStore((state) => state.isConnected);
26141
- const setConnected = useSymmWsStore((state) => state.setConnected);
26142
- const symmCoreClient = params.symmCoreClient ?? ctxClient;
26143
- const accountAddress = params.accountAddress ?? ctxAddress;
26144
- const chainId = params.chainId ?? ctxChainId;
26145
- react.useEffect(() => {
26146
- if (!symmCoreClient || !accountAddress) {
26147
- setConnected(false);
26148
- return;
26149
- }
26150
- const ws = symmCoreClient.ws;
26151
- const addr = accountAddress;
26152
- const unsubscribers = [];
26153
- const removeOnConnect = ws.onConnect(() => setConnected(true));
26154
- const removeOnDisconnect = ws.onDisconnect(() => setConnected(false));
26155
- unsubscribers.push(removeOnConnect, removeOnDisconnect);
26156
- const positionsUnsub = asUnsubscribeFn(
26157
- ws.subscribeToPositions(addr, chainId, () => {
26158
- queryClient.invalidateQueries({
26159
- queryKey: ["symm", "positions"]
26160
- });
26161
- })
26162
- );
26163
- if (positionsUnsub) unsubscribers.push(positionsUnsub);
26164
- const openOrdersUnsub = asUnsubscribeFn(
26165
- ws.subscribeToOpenOrders(addr, chainId, () => {
26166
- queryClient.invalidateQueries({
26167
- queryKey: ["symm", "openOrders"]
26168
- });
26169
- })
26170
- );
26171
- if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
26172
- const tradesUnsub = asUnsubscribeFn(
26173
- ws.subscribeToTrades(addr, chainId, () => {
26174
- queryClient.invalidateQueries({
26175
- queryKey: ["symm", "tradeHistory"]
26176
- });
26177
- })
26178
- );
26179
- if (tradesUnsub) unsubscribers.push(tradesUnsub);
26180
- const accountSummaryUnsub = asUnsubscribeFn(
26181
- ws.subscribeToAccountSummary(addr, chainId, () => {
26182
- queryClient.invalidateQueries({
26183
- queryKey: symmKeys.balances(accountAddress, chainId)
26184
- });
26185
- queryClient.invalidateQueries({
26186
- queryKey: symmKeys.accountSummary(accountAddress, chainId)
26187
- });
26188
- })
26189
- );
26190
- if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
26191
- const notificationsUnsub = asUnsubscribeFn(
26192
- ws.subscribeToNotifications(addr, chainId, () => {
26193
- queryClient.invalidateQueries({
26194
- queryKey: symmKeys.notifications(accountAddress, chainId)
26195
- });
26196
- queryClient.invalidateQueries({
26197
- queryKey: symmKeys.unreadCount(accountAddress, chainId)
26198
- });
26199
- })
26200
- );
26201
- if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
26202
- const tpslUnsub = asUnsubscribeFn(
26203
- ws.subscribeToTpsl(addr, chainId, () => {
26204
- queryClient.invalidateQueries({ queryKey: ["symm", "tpslOrders"] });
26205
- queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
26206
- })
26207
- );
26208
- if (tpslUnsub) unsubscribers.push(tpslUnsub);
26209
- const twapUnsub = asUnsubscribeFn(
26210
- ws.subscribeToTwapOrders(addr, chainId, () => {
26211
- queryClient.invalidateQueries({ queryKey: ["symm", "twapOrders"] });
26212
- queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
26213
- })
26214
- );
26215
- if (twapUnsub) unsubscribers.push(twapUnsub);
26216
- const triggerOrdersUnsub = asUnsubscribeFn(
26217
- ws.subscribeToTriggerOrders(addr, chainId, () => {
26218
- queryClient.invalidateQueries({ queryKey: ["symm", "triggerOrders"] });
26219
- queryClient.invalidateQueries({ queryKey: ["symm", "openOrders"] });
26220
- })
26221
- );
26222
- if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
26223
- const executionsUnsub = asUnsubscribeFn(
26224
- ws.subscribeToExecutions(addr, chainId, () => {
26225
- queryClient.invalidateQueries({
26226
- queryKey: ["symm", "positions"]
26227
- });
26228
- queryClient.invalidateQueries({
26229
- queryKey: ["symm", "portfolio"]
26230
- });
26231
- })
26232
- );
26233
- if (executionsUnsub) unsubscribers.push(executionsUnsub);
26234
- return () => {
26235
- unsubscribers.forEach((unsubscribe) => unsubscribe());
26236
- };
26237
- }, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
26238
- return { isConnected };
26239
- }
26240
26182
  var STABLE_SYMBOLS = /* @__PURE__ */ new Set(["USDC", "USD", "USDT", "USDE", "USDH", "USDT0"]);
26241
26183
  function useSymmChartSelection(input) {
26242
26184
  const {
@@ -26466,7 +26408,10 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
26466
26408
  );
26467
26409
  const isUnsupported = unsupportedSymbols.length > 0;
26468
26410
  const unavailableReason = isUnsupported ? `Binance market data is unavailable for ${unsupportedSymbols.join(", ")}.` : null;
26469
- const symbolsKey = [...selectedSymbols].sort().join(",");
26411
+ const symbolsKey = react.useMemo(
26412
+ () => [...selectedSymbols].sort().join(","),
26413
+ [selectedSymbols]
26414
+ );
26470
26415
  const liveMarkPrices = useBinanceMarkPriceStore((state) => state.markPrices);
26471
26416
  const liveFundingRates = useBinanceMarkPriceStore(
26472
26417
  (state) => state.fundingRates
@@ -26563,7 +26508,6 @@ function useSymmTokenSelectionMetadata(selection, options = {}) {
26563
26508
  }, [
26564
26509
  isUnsupported,
26565
26510
  longTokens,
26566
- query,
26567
26511
  query.data,
26568
26512
  query.isLoading,
26569
26513
  shortTokens,
@@ -26977,6 +26921,10 @@ function getSymmErrorMessage(error) {
26977
26921
  if (error instanceof Error) return error.message;
26978
26922
  return "An unexpected error occurred.";
26979
26923
  }
26924
+ var useSymmWsStore = zustand.create((set) => ({
26925
+ isConnected: false,
26926
+ setConnected: (isConnected) => set({ isConnected })
26927
+ }));
26980
26928
 
26981
26929
  exports.SymmProvider = SymmProvider;
26982
26930
  exports.getSymmErrorMessage = getSymmErrorMessage;
@@ -27051,7 +26999,6 @@ exports.useSymmTwapOrdersQuery = useSymmTwapOrdersQuery;
27051
26999
  exports.useSymmUnreadCountQuery = useSymmUnreadCountQuery;
27052
27000
  exports.useSymmUpdatePositionMutation = useSymmUpdatePositionMutation;
27053
27001
  exports.useSymmWithdraw = useSymmWithdraw;
27054
- exports.useSymmWs = useSymmWs;
27055
27002
  exports.useSymmWsStore = useSymmWsStore;
27056
27003
  //# sourceMappingURL=index.js.map
27057
27004
  //# sourceMappingURL=index.js.map