@agg-build/hooks 2.7.2 → 3.0.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.
package/dist/index.js CHANGED
@@ -84,8 +84,8 @@ __export(src_exports, {
84
84
  MarketStatus: () => MarketStatus,
85
85
  MatchStatus: () => MatchStatus,
86
86
  MatchType: () => MatchType,
87
- QueryClient: () => import_react_query43.QueryClient,
88
- QueryClientProvider: () => import_react_query43.QueryClientProvider,
87
+ QueryClient: () => import_react_query45.QueryClient,
88
+ QueryClientProvider: () => import_react_query45.QueryClientProvider,
89
89
  RedeemRejectedError: () => RedeemRejectedError,
90
90
  TradeSide: () => TradeSide,
91
91
  TurnstileChallengeError: () => import_sdk4.TurnstileChallengeError,
@@ -141,6 +141,7 @@ __export(src_exports, {
141
141
  useAggWebSocket: () => useAggWebSocket,
142
142
  useAppConfig: () => useAppConfig,
143
143
  useArbFeed: () => useArbFeed,
144
+ useBalanceRefillPolicies: () => useBalanceRefillPolicies,
144
145
  useCachedAppConfig: () => useCachedAppConfig,
145
146
  useCancelManagedOrder: () => useCancelManagedOrder,
146
147
  useCategories: () => useCategories,
@@ -158,6 +159,7 @@ __export(src_exports, {
158
159
  useExternalId: () => useExternalId,
159
160
  useGeoBlock: () => useGeoBlock,
160
161
  useLabels: () => useLabels,
162
+ useLimitOrderVenueQuotes: () => useLimitOrderVenueQuotes,
161
163
  useLinkAccount: () => useLinkAccount,
162
164
  useLiveBestPriceCandidates: () => useLiveBestPriceCandidates,
163
165
  useLiveBestPrices: () => useLiveBestPrices,
@@ -184,7 +186,7 @@ __export(src_exports, {
184
186
  useOrders: () => useOrders,
185
187
  usePlaceLimitOrder: () => usePlaceLimitOrder,
186
188
  usePositions: () => usePositions,
187
- useQueryClient: () => import_react_query43.useQueryClient,
189
+ useQueryClient: () => import_react_query45.useQueryClient,
188
190
  useQuoteManaged: () => useQuoteManaged,
189
191
  useRampQuotes: () => useRampQuotes,
190
192
  useRampSession: () => useRampSession,
@@ -352,7 +354,7 @@ var getVenueOrder = (venue) => {
352
354
  var sortVenues = (venues) => [...venues].sort((a, b) => getVenueOrder(a) - getVenueOrder(b));
353
355
 
354
356
  // src/index.ts
355
- var import_react_query43 = require("@tanstack/react-query");
357
+ var import_react_query45 = require("@tanstack/react-query");
356
358
 
357
359
  // src/candle-store.ts
358
360
  var import_sdk = require("@agg-build/sdk");
@@ -617,6 +619,56 @@ var enUsLabels = {
617
619
  claimableWinningsTooltip: (count) => `${count} position${count === 1 ? "" : "s"} ready to claim`,
618
620
  walletMenuFor: (profileLabel) => `Profile menu for ${profileLabel}`
619
621
  },
622
+ balanceRefill: {
623
+ tabLabel: "Balance management",
624
+ title: "Automatic balance refill",
625
+ description: "Keep a minimum USDC balance on one network by moving funds from another managed network.",
626
+ networkLabel: "Network to maintain",
627
+ minimumLabel: "Minimum balance",
628
+ refillAmountLabel: "Refill by at least",
629
+ dailyCapLabel: "Maximum per day",
630
+ maximumFeeLabel: "Maximum fee per refill",
631
+ activeLabel: "Automatic refill is active",
632
+ pausedLabel: "Automatic refill is paused",
633
+ enableAction: "Enable automatic refill",
634
+ saveAction: "Save refill settings",
635
+ pauseAction: "Pause automatic refill",
636
+ resumeAction: "Resume automatic refill",
637
+ loading: "Loading refill settings...",
638
+ loadError: "Refill settings could not be loaded.",
639
+ saveError: "Refill settings could not be saved.",
640
+ saved: "Refill settings saved.",
641
+ consent: "By enabling, you authorize AGG to move USDC between your managed wallets within these limits.",
642
+ lastRefill: "Latest refill",
643
+ manageTitle: "Manage balances",
644
+ manageDescription: "Set a minimum balance and refill target for each venue. When a venue falls below your minimum, funds are automatically transferred from your balances on other venues to restore it to your refill target.",
645
+ noAutoRefill: "No auto-refill",
646
+ autoRefill: "Auto-refill",
647
+ minimumShortLabel: "Min",
648
+ refillToLabel: "Refill to",
649
+ unitLabel: "USDC",
650
+ resetAction: "Reset",
651
+ cancelAction: "Cancel",
652
+ saveChangesAction: "Save changes",
653
+ modalLoading: "Loading balances...",
654
+ modalEmptyTitle: "No supported networks",
655
+ modalEmptyDescription: "There are no supported networks to manage yet.",
656
+ modalLoadError: "Balances could not be loaded.",
657
+ requiredError: "Enter an amount.",
658
+ positiveError: "Enter an amount greater than 0.",
659
+ precisionError: "Use no more than 6 decimal places.",
660
+ relationshipError: "Refill to must be greater than or equal to Min.",
661
+ maximumError: (maximum) => `Enter an amount no greater than ${maximum} USDC.`,
662
+ createUnavailableError: "Auto-refill cannot be enabled for this network until refill limits are supported by the API.",
663
+ expandNetwork: (network) => `Expand ${network} balance settings`,
664
+ collapseNetwork: (network) => `Collapse ${network} balance settings`,
665
+ statuses: {
666
+ reserved: "Funds reserved",
667
+ executing: "Refill in progress",
668
+ completed: "Refill completed",
669
+ failed: "Refill failed"
670
+ }
671
+ },
620
672
  deposit: {
621
673
  title: "Deposit",
622
674
  back: "Go back",
@@ -820,7 +872,8 @@ var enUsLabels = {
820
872
  activity: "Activity"
821
873
  },
822
874
  balance: {
823
- availableBalance: "Available Balance",
875
+ availableBalance: "Withdrawable Balance",
876
+ manage: "Manage",
824
877
  reservedForOpenOrders: (amount) => `${amount} reserved for open orders`,
825
878
  positionsValue: "Positions Value",
826
879
  kalshiBalance: "Kalshi Balance",
@@ -1192,6 +1245,7 @@ var enUsLabels = {
1192
1245
  tradingAccessAddKalshiAccount: "Add Kalshi Account",
1193
1246
  outcome: (label) => `Outcome: ${label}`,
1194
1247
  smartRouting: "Smart Routing",
1248
+ limitRoutingCurrentPrice: (priceLabel, feeLabel) => feeLabel ? `Current ${priceLabel} \xB7 Fee ${feeLabel}` : `Current ${priceLabel}`,
1195
1249
  orderTypeMarket: "Market",
1196
1250
  orderTypeLimit: "Limit",
1197
1251
  orderTypeAria: "Order type",
@@ -1217,6 +1271,10 @@ var enUsLabels = {
1217
1271
  limitOrderPlacedDescription: "Your limit order has been submitted.",
1218
1272
  orderSplitting: "Order Splitting",
1219
1273
  splitOrderDescription: "We split your order for the best price:",
1274
+ maximizePayout: "Maximize payout",
1275
+ maximizePayoutDescription: "We\u2019ll route your shares for the highest payout:",
1276
+ venueInventory: (sharesLabel, priceLabel) => `${sharesLabel} \xB7 ${priceLabel}`,
1277
+ insufficientVenueInventory: (sharesLabel, priceLabel) => `Only ${sharesLabel} \xB7 ${priceLabel}`,
1220
1278
  viewAllRoutes: (count) => `View all (${count})`,
1221
1279
  venueUnavailableInRegion: "Unavailable in your region",
1222
1280
  verified: "Verified",
@@ -1665,7 +1723,7 @@ var mergeAggUiSearchConfig = (config) => {
1665
1723
  };
1666
1724
  };
1667
1725
  var mergeAggUiConfig = (persisted, config) => {
1668
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$;
1726
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa;
1669
1727
  const locale = (_d = (_c = (_a = config == null ? void 0 : config.general) == null ? void 0 : _a.locale) != null ? _c : (_b = persisted.general) == null ? void 0 : _b.locale) != null ? _d : DEFAULT_LOCALE;
1670
1728
  const theme = (_h = (_g = (_e = config == null ? void 0 : config.general) == null ? void 0 : _e.theme) != null ? _g : (_f = persisted.general) == null ? void 0 : _f.theme) != null ? _h : defaultAggUiConfig.general.theme;
1671
1729
  const formatters = createFormatters(locale);
@@ -1703,13 +1761,16 @@ var mergeAggUiConfig = (persisted, config) => {
1703
1761
  formatting: {
1704
1762
  formatNumber: (_R = (_Q = config == null ? void 0 : config.formatting) == null ? void 0 : _Q.formatNumber) != null ? _R : formatters.formatNumber,
1705
1763
  formatPercent: (_T = (_S = config == null ? void 0 : config.formatting) == null ? void 0 : _S.formatPercent) != null ? _T : formatters.formatPercent,
1706
- formatCurrency: (_V = (_U = config == null ? void 0 : config.formatting) == null ? void 0 : _U.formatCurrency) != null ? _V : formatters.formatCurrency,
1707
- formatCompactCurrency: (_X = (_W = config == null ? void 0 : config.formatting) == null ? void 0 : _W.formatCompactCurrency) != null ? _X : formatters.formatCompactCurrency,
1708
- formatDate: (_Z = (_Y = config == null ? void 0 : config.formatting) == null ? void 0 : _Y.formatDate) != null ? _Z : formatters.formatDate
1764
+ // ponytail: no default here — each cents surface keeps its own rendering
1765
+ // when unset, so adding this knob changes nothing for existing partners.
1766
+ formatPrice: (_U = config == null ? void 0 : config.formatting) == null ? void 0 : _U.formatPrice,
1767
+ formatCurrency: (_W = (_V = config == null ? void 0 : config.formatting) == null ? void 0 : _V.formatCurrency) != null ? _W : formatters.formatCurrency,
1768
+ formatCompactCurrency: (_Y = (_X = config == null ? void 0 : config.formatting) == null ? void 0 : _X.formatCompactCurrency) != null ? _Y : formatters.formatCompactCurrency,
1769
+ formatDate: (__ = (_Z = config == null ? void 0 : config.formatting) == null ? void 0 : _Z.formatDate) != null ? __ : formatters.formatDate
1709
1770
  },
1710
1771
  search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
1711
1772
  trading: {
1712
- executionMode: (_$ = (__ = config == null ? void 0 : config.trading) == null ? void 0 : __.executionMode) != null ? _$ : defaultAggUiConfig.trading.executionMode
1773
+ executionMode: (_aa = (_$ = config == null ? void 0 : config.trading) == null ? void 0 : _$.executionMode) != null ? _aa : defaultAggUiConfig.trading.executionMode
1713
1774
  },
1714
1775
  walletActions: config == null ? void 0 : config.walletActions,
1715
1776
  solanaRpcUrl: config == null ? void 0 : config.solanaRpcUrl
@@ -1985,7 +2046,8 @@ var executionKeys = {
1985
2046
  claimableClosedPositionsCount: () => ["execution", "positions", "claimable-count"],
1986
2047
  orders: (status, cursor, limit) => ["execution", "orders", status != null ? status : null, cursor != null ? cursor : null, limit != null ? limit : null],
1987
2048
  ordersPrefix: () => ["execution", "orders"],
1988
- depositAddresses: () => ["execution", "deposit-addresses"]
2049
+ depositAddresses: () => ["execution", "deposit-addresses"],
2050
+ balanceRefillPolicies: () => ["execution", "balance-refill-policies"]
1989
2051
  };
1990
2052
 
1991
2053
  // src/execution/balance-invalidation.ts
@@ -2133,7 +2195,7 @@ function AggBalanceProvider({ children }) {
2133
2195
  (a, b) => a.localeCompare(b)
2134
2196
  );
2135
2197
  }, [managedBalances.positions]);
2136
- const balancesError = balancesQuery.error;
2198
+ const balancesError = managedBalancesData === void 0 ? balancesQuery.error : null;
2137
2199
  const isBalancesLoading = balancesQuery.isLoading;
2138
2200
  const refetchBalances = balancesQuery.refetch;
2139
2201
  const totalBalance = (0, import_react3.useMemo)(() => {
@@ -2219,11 +2281,12 @@ function AggBalanceProvider({ children }) {
2219
2281
  }, [buildBalanceBreakdown]);
2220
2282
  const positionsBalanceTotal = (0, import_react3.useMemo)(() => {
2221
2283
  const positions = managedBalances.positions;
2222
- return positions.reduce(
2284
+ const actualPositionsBalance = positions.reduce(
2223
2285
  (sum, position) => sum + (Number.isFinite(position.balance) ? position.balance : 0),
2224
2286
  0
2225
2287
  );
2226
- }, [managedBalances]);
2288
+ return actualPositionsBalance + reservedBalance;
2289
+ }, [managedBalances.positions, reservedBalance]);
2227
2290
  const kalshiVenueCash = (_a = managedBalances.venueCash) == null ? void 0 : _a.find((item) => item.venue === "kalshi");
2228
2291
  const kalshiBalance = kalshiVenueCash ? kalshiVenueCash.balanceCents / 100 : null;
2229
2292
  const kalshiPortfolioValue = (kalshiVenueCash == null ? void 0 : kalshiVenueCash.portfolioValueCents) == null ? null : kalshiVenueCash.portfolioValueCents / 100;
@@ -4800,6 +4863,53 @@ function useExecutionProgress({
4800
4863
  return { phase, submittedOrders, latestBalance, dagProgress, terminalOrderEvents };
4801
4864
  }
4802
4865
 
4866
+ // src/execution/use-balance-refill-policies.ts
4867
+ var import_react_query16 = require("@tanstack/react-query");
4868
+ function useBalanceRefillPolicies(options) {
4869
+ var _a, _b;
4870
+ const client = useAggClient();
4871
+ const queryClient = (0, import_react_query16.useQueryClient)();
4872
+ const queryKey = executionKeys.balanceRefillPolicies();
4873
+ const query = (0, import_react_query16.useQuery)({
4874
+ queryKey,
4875
+ queryFn: () => client.getBalanceRefillPolicies(),
4876
+ enabled: (_a = options == null ? void 0 : options.enabled) != null ? _a : true,
4877
+ staleTime: 15e3,
4878
+ refetchInterval: (state) => {
4879
+ var _a2;
4880
+ return ((_a2 = state.state.data) == null ? void 0 : _a2.some(
4881
+ (policy) => {
4882
+ var _a3, _b2;
4883
+ return ["reserved", "executing"].includes((_b2 = (_a3 = policy.latestAttempt) == null ? void 0 : _a3.status) != null ? _b2 : "");
4884
+ }
4885
+ )) ? 5e3 : false;
4886
+ }
4887
+ });
4888
+ const createPolicy = (0, import_react_query16.useMutation)({
4889
+ mutationFn: (params) => client.createBalanceRefillPolicy(params),
4890
+ onSuccess: (policy) => {
4891
+ queryClient.setQueryData(queryKey, [policy]);
4892
+ }
4893
+ });
4894
+ const updatePolicy = (0, import_react_query16.useMutation)({
4895
+ mutationFn: ({
4896
+ policyId,
4897
+ params
4898
+ }) => client.updateBalanceRefillPolicy(policyId, params),
4899
+ onSuccess: (updated) => {
4900
+ queryClient.setQueryData(
4901
+ queryKey,
4902
+ (current) => (current != null ? current : []).map((policy) => policy.id === updated.id ? updated : policy)
4903
+ );
4904
+ }
4905
+ });
4906
+ return __spreadProps(__spreadValues({}, query), {
4907
+ policies: (_b = query.data) != null ? _b : [],
4908
+ createPolicy,
4909
+ updatePolicy
4910
+ });
4911
+ }
4912
+
4803
4913
  // src/execution/compute-closed-position-totals.ts
4804
4914
  var computeClosedPositionTotals = (group) => {
4805
4915
  const outcomes = group.venueMarket.venueMarketOutcomes;
@@ -4839,7 +4949,7 @@ var computeClosedPositionTotals = (group) => {
4839
4949
  };
4840
4950
 
4841
4951
  // src/execution/use-redeem.ts
4842
- var import_react_query16 = require("@tanstack/react-query");
4952
+ var import_react_query17 = require("@tanstack/react-query");
4843
4953
  var RedeemRejectedError = class extends Error {
4844
4954
  constructor(message, response) {
4845
4955
  super(message);
@@ -4850,8 +4960,8 @@ var RedeemRejectedError = class extends Error {
4850
4960
  var isLegRejected = (status) => status === "ineligible" || status === "rejected";
4851
4961
  var useRedeem = () => {
4852
4962
  const client = useAggClient();
4853
- const queryClient = (0, import_react_query16.useQueryClient)();
4854
- return (0, import_react_query16.useMutation)({
4963
+ const queryClient = (0, import_react_query17.useQueryClient)();
4964
+ return (0, import_react_query17.useMutation)({
4855
4965
  mutationFn: (body) => __async(null, null, function* () {
4856
4966
  const response = yield client.redeem(body);
4857
4967
  if (response.results.length > 0 && response.results.every((r) => isLegRejected(r.status))) {
@@ -4873,7 +4983,7 @@ var useOnRedeemEvent2 = (listener) => {
4873
4983
  };
4874
4984
 
4875
4985
  // src/execution/use-redeem-eligible-count.ts
4876
- var import_react_query17 = require("@tanstack/react-query");
4986
+ var import_react_query18 = require("@tanstack/react-query");
4877
4987
  var CLAIMABLE_COUNT_PAGE_LIMIT = 100;
4878
4988
  var getClaimablePositionsCount = (client) => __async(null, null, function* () {
4879
4989
  var _a;
@@ -4898,7 +5008,7 @@ var useRedeemEligibleCount = () => {
4898
5008
  var _a;
4899
5009
  const client = useAggClient();
4900
5010
  const { isAuthenticated } = useAggAuthState();
4901
- const query = (0, import_react_query17.useQuery)({
5011
+ const query = (0, import_react_query18.useQuery)({
4902
5012
  queryKey: executionKeys.claimablePositionsCount(),
4903
5013
  queryFn: () => getClaimablePositionsCount(client),
4904
5014
  enabled: isAuthenticated,
@@ -5374,7 +5484,7 @@ function useWithdrawEstimate({
5374
5484
 
5375
5485
  // src/withdraw/use-withdrawal-lifecycle.ts
5376
5486
  var import_react15 = require("react");
5377
- var import_react_query18 = require("@tanstack/react-query");
5487
+ var import_react_query19 = require("@tanstack/react-query");
5378
5488
  var INITIAL_STATE2 = {
5379
5489
  pending: true,
5380
5490
  status: null,
@@ -5431,7 +5541,7 @@ var restToLifecycleState = (response) => {
5431
5541
  function useWithdrawalLifecycle(withdrawalId) {
5432
5542
  const client = useAggClient();
5433
5543
  const wsConnected = useAggWebSocketConnectionState();
5434
- const queryClient = (0, import_react_query18.useQueryClient)();
5544
+ const queryClient = (0, import_react_query19.useQueryClient)();
5435
5545
  const [state, setState] = (0, import_react15.useState)(INITIAL_STATE2);
5436
5546
  const stateRef = (0, import_react15.useRef)(state);
5437
5547
  stateRef.current = state;
@@ -5500,7 +5610,7 @@ function useWithdrawalLifecycle(withdrawalId) {
5500
5610
  }
5501
5611
 
5502
5612
  // src/withdraw/use-withdraw-preview.ts
5503
- var import_react_query19 = require("@tanstack/react-query");
5613
+ var import_react_query20 = require("@tanstack/react-query");
5504
5614
  function useWithdrawPreview({
5505
5615
  amountRaw,
5506
5616
  tokenSymbol,
@@ -5510,7 +5620,7 @@ function useWithdrawPreview({
5510
5620
  }) {
5511
5621
  const client = useAggClient();
5512
5622
  const enabled = !!amountRaw && BigInt(amountRaw || "0") > BigInt(0) && !!tokenSymbol && !!destinationChainId && !!destinationAddress;
5513
- return (0, import_react_query19.useQuery)({
5623
+ return (0, import_react_query20.useQuery)({
5514
5624
  queryKey: [
5515
5625
  "withdraw-preview",
5516
5626
  tokenSymbol,
@@ -5582,14 +5692,14 @@ var getVenueAvailabilityState = ({
5582
5692
  };
5583
5693
 
5584
5694
  // src/use-venue-key-status.ts
5585
- var import_react_query20 = require("@tanstack/react-query");
5695
+ var import_react_query21 = require("@tanstack/react-query");
5586
5696
  var venueKeyQueryKeys = {
5587
5697
  all: ["agg", "venue-keys"],
5588
5698
  status: (venue) => [...venueKeyQueryKeys.all, venue, "status"]
5589
5699
  };
5590
5700
  var useVenueKeyStatus = (venue, enabled = true) => {
5591
5701
  const client = useAggClient();
5592
- return (0, import_react_query20.useQuery)({
5702
+ return (0, import_react_query21.useQuery)({
5593
5703
  queryKey: venueKeyQueryKeys.status(venue),
5594
5704
  queryFn: () => client.getVenueKeyStatus(venue),
5595
5705
  enabled
@@ -5664,7 +5774,7 @@ var requestAggAuthChooserOpen = () => {
5664
5774
  };
5665
5775
 
5666
5776
  // src/use-categories.ts
5667
- var import_react_query21 = require("@tanstack/react-query");
5777
+ var import_react_query22 = require("@tanstack/react-query");
5668
5778
  function useCategories(options) {
5669
5779
  var _a, _b, _c, _d, _e, _f;
5670
5780
  const client = useAggClient();
@@ -5672,7 +5782,7 @@ function useCategories(options) {
5672
5782
  const parentId = (_b = options == null ? void 0 : options.parentId) != null ? _b : null;
5673
5783
  const enabled = (_c = options == null ? void 0 : options.enabled) != null ? _c : true;
5674
5784
  const limit = (_d = options == null ? void 0 : options.limit) != null ? _d : 20;
5675
- const query = (0, import_react_query21.useInfiniteQuery)({
5785
+ const query = (0, import_react_query22.useInfiniteQuery)({
5676
5786
  queryKey: [queryKeyScope, "parent", parentId != null ? parentId : "__root__", limit],
5677
5787
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
5678
5788
  const res = yield client.getCategories(__spreadValues({
@@ -5704,7 +5814,7 @@ function useCategoryChildren(options) {
5704
5814
  const parentIds = Array.from(
5705
5815
  new Set(((_d = options == null ? void 0 : options.parentIds) != null ? _d : []).filter((parentId) => Boolean(parentId)))
5706
5816
  );
5707
- const queries = (0, import_react_query21.useQueries)({
5817
+ const queries = (0, import_react_query22.useQueries)({
5708
5818
  queries: parentIds.map((parentId) => ({
5709
5819
  queryKey: [queryKeyScope, "parent", parentId, limit],
5710
5820
  queryFn: () => __async(null, null, function* () {
@@ -5747,7 +5857,7 @@ function useDebouncedValue(value, delay) {
5747
5857
  }
5748
5858
 
5749
5859
  // src/use-execution-orders.ts
5750
- var import_react_query22 = require("@tanstack/react-query");
5860
+ var import_react_query23 = require("@tanstack/react-query");
5751
5861
  function useExecutionOrders(options = {}) {
5752
5862
  var _a, _b;
5753
5863
  const client = useAggClient();
@@ -5760,7 +5870,7 @@ function useExecutionOrders(options = {}) {
5760
5870
  enabled = true,
5761
5871
  refetchIntervalMs = false
5762
5872
  } = options;
5763
- const query = (0, import_react_query22.useInfiniteQuery)({
5873
+ const query = (0, import_react_query23.useInfiniteQuery)({
5764
5874
  // quoteId + orderId are part of the cache key — different filters
5765
5875
  // produce different result sets, so they have to vary the key.
5766
5876
  queryKey: [
@@ -5796,7 +5906,7 @@ function useExecutionOrders(options = {}) {
5796
5906
  }
5797
5907
 
5798
5908
  // src/use-user-activity.ts
5799
- var import_react_query23 = require("@tanstack/react-query");
5909
+ var import_react_query24 = require("@tanstack/react-query");
5800
5910
  var DEFAULT_PENDING_REFETCH_INTERVAL_MS = 15e3;
5801
5911
  var PENDING_ACTIVITY_STATUSES = /* @__PURE__ */ new Set([
5802
5912
  "pending",
@@ -5830,7 +5940,7 @@ function useUserActivity(options = {}) {
5830
5940
  enabled = true,
5831
5941
  pendingRefetchIntervalMs = DEFAULT_PENDING_REFETCH_INTERVAL_MS
5832
5942
  } = options;
5833
- const query = (0, import_react_query23.useInfiniteQuery)({
5943
+ const query = (0, import_react_query24.useInfiniteQuery)({
5834
5944
  queryKey: userActivityQueryKeys.feed(type, limit),
5835
5945
  queryFn: ({ pageParam }) => client.getUserActivity({
5836
5946
  type,
@@ -5847,7 +5957,7 @@ function useUserActivity(options = {}) {
5847
5957
  // flight (typically after a deposit / withdraw cache invalidation).
5848
5958
  // Without this the feed flashes to the skeleton mid-session, which
5849
5959
  // is worse UX than briefly showing slightly-stale rows.
5850
- placeholderData: import_react_query23.keepPreviousData,
5960
+ placeholderData: import_react_query24.keepPreviousData,
5851
5961
  refetchInterval: (q) => {
5852
5962
  if (pendingRefetchIntervalMs === false) return false;
5853
5963
  const data = q.state.data;
@@ -5892,12 +6002,12 @@ function useExternalId(options = {}) {
5892
6002
  }
5893
6003
 
5894
6004
  // src/use-execution-positions.ts
5895
- var import_react_query24 = require("@tanstack/react-query");
6005
+ var import_react_query25 = require("@tanstack/react-query");
5896
6006
  function useExecutionPositions(options = {}) {
5897
6007
  var _a, _b;
5898
6008
  const client = useAggClient();
5899
6009
  const { limit = 50, status, mode, enabled = true } = options;
5900
- const query = (0, import_react_query24.useInfiniteQuery)({
6010
+ const query = (0, import_react_query25.useInfiniteQuery)({
5901
6011
  queryKey: executionKeys.positions(null, limit, status != null ? status : null, mode != null ? mode : null),
5902
6012
  queryFn: ({ pageParam }) => client.getExecutionPositions(__spreadProps(__spreadValues({
5903
6013
  limit,
@@ -5928,7 +6038,7 @@ var import_react23 = require("react");
5928
6038
  var import_sdk3 = require("@agg-build/sdk");
5929
6039
 
5930
6040
  // src/use-market-chart.ts
5931
- var import_react_query25 = require("@tanstack/react-query");
6041
+ var import_react_query26 = require("@tanstack/react-query");
5932
6042
 
5933
6043
  // src/market-data/subscription.ts
5934
6044
  var import_react21 = require("react");
@@ -6013,7 +6123,7 @@ function useMarketChart(options) {
6013
6123
  orderbook: true,
6014
6124
  trades: true
6015
6125
  });
6016
- const queries = (0, import_react_query25.useQueries)({
6126
+ const queries = (0, import_react_query26.useQueries)({
6017
6127
  queries: outcomeIds.map((outcomeId) => ({
6018
6128
  // Cache key is intentionally time-free. The rolling window's
6019
6129
  // startTs/endTs advance on every bucket but the user expects the same
@@ -6048,7 +6158,7 @@ function useMarketChart(options) {
6048
6158
  gcTime: 60 * 6e4,
6049
6159
  refetchOnWindowFocus: false,
6050
6160
  retry: 1,
6051
- placeholderData: import_react_query25.keepPreviousData,
6161
+ placeholderData: import_react_query26.keepPreviousData,
6052
6162
  refetchInterval: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : false,
6053
6163
  refetchIntervalInBackground: false
6054
6164
  }))
@@ -6291,7 +6401,7 @@ function useEventOrderbookData(venueMarkets, selectedMarketId) {
6291
6401
  }
6292
6402
 
6293
6403
  // src/use-live-market.ts
6294
- var import_react_query26 = require("@tanstack/react-query");
6404
+ var import_react_query27 = require("@tanstack/react-query");
6295
6405
  function outcomeOrderbookToState(response, marketId) {
6296
6406
  var _a, _b, _c, _d;
6297
6407
  const { venue, orderbook, midpoint, spread, seq, checksum, timestamp, venueMarketOutcomeId } = response;
@@ -6341,7 +6451,7 @@ function useLiveMarket(canonicalMarketId) {
6341
6451
  enabled: isLiveSubscriptionEnabled,
6342
6452
  orderbook: true
6343
6453
  });
6344
- const query = (0, import_react_query26.useQuery)({
6454
+ const query = (0, import_react_query27.useQuery)({
6345
6455
  queryKey: marketDataKeys.live(canonicalMarketId != null ? canonicalMarketId : "__disabled__"),
6346
6456
  queryFn: () => __async(null, null, function* () {
6347
6457
  return createMarketLiveState(canonicalMarketId != null ? canonicalMarketId : "__disabled__");
@@ -6353,7 +6463,7 @@ function useLiveMarket(canonicalMarketId) {
6353
6463
  isConnected: Boolean(isLiveSubscriptionEnabled && isConnected)
6354
6464
  })
6355
6465
  });
6356
- const seedQuery = (0, import_react_query26.useQuery)({
6466
+ const seedQuery = (0, import_react_query27.useQuery)({
6357
6467
  queryKey: ["live-market-seed", canonicalMarketId],
6358
6468
  queryFn: ({ signal }) => canonicalMarketId ? client.getOutcomeOrderbook(canonicalMarketId, { signal }) : Promise.resolve(null),
6359
6469
  enabled: Boolean(canonicalMarketId),
@@ -6374,7 +6484,7 @@ function useLiveMarket(canonicalMarketId) {
6374
6484
 
6375
6485
  // src/use-live-outcome-prices.ts
6376
6486
  var import_react26 = require("react");
6377
- var import_react_query27 = require("@tanstack/react-query");
6487
+ var import_react_query28 = require("@tanstack/react-query");
6378
6488
  var EMPTY_PRICES = /* @__PURE__ */ new Map();
6379
6489
  var buildMidpointFingerprint = (outcomeIds, queries) => {
6380
6490
  var _a, _b, _c;
@@ -6390,17 +6500,20 @@ function useLiveOutcomePrices(venueMarkets) {
6390
6500
  features: { enableLiveUpdates }
6391
6501
  } = useAggUiConfig();
6392
6502
  const outcomeIds = (0, import_react26.useMemo)(() => {
6393
- var _a;
6503
+ var _a, _b;
6394
6504
  if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
6395
6505
  const ids = /* @__PURE__ */ new Set();
6396
6506
  for (const vm of venueMarkets) {
6397
6507
  for (const outcome of (_a = vm.venueMarketOutcomes) != null ? _a : []) {
6398
6508
  if (outcome.id) ids.add(outcome.id);
6509
+ for (const ref of (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : []) {
6510
+ if (ref.venueMarketOutcomeId) ids.add(ref.venueMarketOutcomeId);
6511
+ }
6399
6512
  }
6400
6513
  }
6401
6514
  return [...ids].sort();
6402
6515
  }, [venueMarkets]);
6403
- const queries = (0, import_react_query27.useQueries)({
6516
+ const queries = (0, import_react_query28.useQueries)({
6404
6517
  queries: outcomeIds.map((id) => ({
6405
6518
  queryKey: marketDataKeys.live(id),
6406
6519
  queryFn: () => createMarketLiveState(id),
@@ -6416,7 +6529,7 @@ function useLiveOutcomePrices(venueMarkets) {
6416
6529
  prices: EMPTY_PRICES
6417
6530
  });
6418
6531
  const data = (0, import_react26.useMemo)(() => {
6419
- var _a, _b, _c, _d;
6532
+ var _a, _b, _c;
6420
6533
  if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return EMPTY_PRICES;
6421
6534
  if (fingerprint === prevRef.current.fingerprint) {
6422
6535
  return prevRef.current.prices;
@@ -6427,16 +6540,10 @@ function useLiveOutcomePrices(venueMarkets) {
6427
6540
  const state = (_a = queries[i]) == null ? void 0 : _a.data;
6428
6541
  liveByOutcomeId.set(outcomeIds[i], (_c = (_b = state == null ? void 0 : state.orderbook) == null ? void 0 : _b.midpoint) != null ? _c : null);
6429
6542
  }
6430
- for (const vm of venueMarkets) {
6431
- for (const outcome of (_d = vm.venueMarketOutcomes) != null ? _d : []) {
6432
- if (!enableLiveUpdates) {
6433
- continue;
6434
- }
6435
- const liveMidpoint = liveByOutcomeId.get(outcome.id);
6436
- if (liveMidpoint != null) {
6437
- prices.set(outcome.id, liveMidpoint);
6438
- }
6439
- }
6543
+ if (!enableLiveUpdates) return prices;
6544
+ for (const outcomeId of outcomeIds) {
6545
+ const liveMidpoint = liveByOutcomeId.get(outcomeId);
6546
+ if (liveMidpoint != null) prices.set(outcomeId, liveMidpoint);
6440
6547
  }
6441
6548
  prevRef.current = { fingerprint, prices };
6442
6549
  return prices;
@@ -6449,7 +6556,7 @@ function findLivePriceById(livePrices, id) {
6449
6556
 
6450
6557
  // src/use-live-best-prices.ts
6451
6558
  var import_react27 = require("react");
6452
- var import_react_query28 = require("@tanstack/react-query");
6559
+ var import_react_query29 = require("@tanstack/react-query");
6453
6560
  var EMPTY = /* @__PURE__ */ new Map();
6454
6561
  var EMPTY_CANDIDATES = /* @__PURE__ */ new Map();
6455
6562
  var extractOutcomeBestPrices = (state) => {
@@ -6492,7 +6599,7 @@ function useLiveBestPrices(venueMarkets) {
6492
6599
  }
6493
6600
  return [...ids].sort();
6494
6601
  }, [venueMarkets]);
6495
- const queries = (0, import_react_query28.useQueries)({
6602
+ const queries = (0, import_react_query29.useQueries)({
6496
6603
  queries: outcomeIds.map((id) => ({
6497
6604
  queryKey: marketDataKeys.live(id),
6498
6605
  queryFn: () => createMarketLiveState(id),
@@ -6711,7 +6818,7 @@ function useLiveBestPriceCandidates(venueMarkets) {
6711
6818
  }
6712
6819
  return [...ids].sort();
6713
6820
  }, [venueMarkets]);
6714
- const queries = (0, import_react_query28.useQueries)({
6821
+ const queries = (0, import_react_query29.useQueries)({
6715
6822
  queries: outcomeIds.map((id) => ({
6716
6823
  queryKey: marketDataKeys.live(id),
6717
6824
  queryFn: () => createMarketLiveState(id),
@@ -6755,7 +6862,7 @@ function useLiveTrades(canonicalMarketId) {
6755
6862
  }
6756
6863
 
6757
6864
  // src/use-midpoints.ts
6758
- var import_react_query29 = require("@tanstack/react-query");
6865
+ var import_react_query30 = require("@tanstack/react-query");
6759
6866
  var import_react28 = require("react");
6760
6867
  var normalizeVenueMarketIds = (venueMarkets) => {
6761
6868
  var _a;
@@ -6934,7 +7041,7 @@ function useMidpoints(venueMarkets, options) {
6934
7041
  () => resolveBestMidpointCandidateOutcomeIds(venueMarkets),
6935
7042
  [venueMarkets]
6936
7043
  );
6937
- const { data, isLoading } = (0, import_react_query29.useQuery)({
7044
+ const { data, isLoading } = (0, import_react_query30.useQuery)({
6938
7045
  queryKey: ["midpoints", ids, maxMidpointIdsPerRequest],
6939
7046
  queryFn: () => client.getMidpoints(ids, { bestPrice: true, maxMidpointIdsPerRequest }),
6940
7047
  enabled: ids.length > 0,
@@ -6947,8 +7054,9 @@ function useMidpoints(venueMarkets, options) {
6947
7054
  const result = (0, import_react28.useMemo)(() => {
6948
7055
  var _a2, _b, _c, _d, _e, _f;
6949
7056
  const map = /* @__PURE__ */ new Map();
7057
+ const currentMap = /* @__PURE__ */ new Map();
6950
7058
  const venueMap = /* @__PURE__ */ new Map();
6951
- if (!(data == null ? void 0 : data.data) || !venueMarkets) return { map, venueMap };
7059
+ if (!(data == null ? void 0 : data.data) || !venueMarkets) return { map, currentMap, venueMap };
6952
7060
  const itemByMarketId = new Map(data.data.map((item) => [item.venueMarketId, item]));
6953
7061
  const marketById = new Map(venueMarkets.map((market) => [market.id, market]));
6954
7062
  for (const item of data.data) {
@@ -6956,6 +7064,7 @@ function useMidpoints(venueMarkets, options) {
6956
7064
  for (const o of item.outcomes) {
6957
7065
  if (o.midpoint == null) continue;
6958
7066
  map.set(o.venueMarketOutcomeId, o.midpoint);
7067
+ currentMap.set(o.venueMarketOutcomeId, o.midpoint);
6959
7068
  if (item.venue) venueMap.set(o.venueMarketOutcomeId, item.venue);
6960
7069
  }
6961
7070
  }
@@ -6970,6 +7079,7 @@ function useMidpoints(venueMarkets, options) {
6970
7079
  for (const ref of refs) {
6971
7080
  const sib = resolveSiblingOutcomeMidpoint(item.matched, ref);
6972
7081
  if (sib == null) continue;
7082
+ currentMap.set(ref.venueMarketOutcomeId, sib.midpoint);
6973
7083
  if (best == null || sib.midpoint < best) {
6974
7084
  best = sib.midpoint;
6975
7085
  bestVenue = (_e = sib.venue) != null ? _e : bestVenue;
@@ -6992,7 +7102,7 @@ function useMidpoints(venueMarkets, options) {
6992
7102
  }
6993
7103
  }
6994
7104
  }
6995
- return { map, venueMap };
7105
+ return { map, currentMap, venueMap };
6996
7106
  }, [data, venueMarkets]);
6997
7107
  const { bestMidpoint, bestMidpointVenue } = (0, import_react28.useMemo)(() => {
6998
7108
  let value;
@@ -7022,6 +7132,7 @@ function useMidpoints(venueMarkets, options) {
7022
7132
  return {
7023
7133
  prices: result.map,
7024
7134
  bestMidpointsByOutcomeId: result.map,
7135
+ currentMidpointsByOutcomeId: result.currentMap,
7025
7136
  venueByOutcomeId: result.venueMap,
7026
7137
  bestPrices,
7027
7138
  bestPriceVenuesByOutcomeId,
@@ -7079,10 +7190,10 @@ var useRollingChartWindow = (options) => {
7079
7190
  };
7080
7191
 
7081
7192
  // src/use-market-orderbook.ts
7082
- var import_react_query30 = require("@tanstack/react-query");
7193
+ var import_react_query31 = require("@tanstack/react-query");
7083
7194
  function useMarketOrderbook(options) {
7084
7195
  var _a, _b, _c, _d, _e, _f, _g, _h;
7085
- const queryClient = (0, import_react_query30.useQueryClient)();
7196
+ const queryClient = (0, import_react_query31.useQueryClient)();
7086
7197
  const ws = useAggWebSocket();
7087
7198
  const isConnected = useAggWebSocketConnectionState();
7088
7199
  const {
@@ -7100,7 +7211,7 @@ function useMarketOrderbook(options) {
7100
7211
  enabled: enabled && !!selectedOutcomeId,
7101
7212
  orderbook: true
7102
7213
  });
7103
- const liveQueries = (0, import_react_query30.useQueries)({
7214
+ const liveQueries = (0, import_react_query31.useQueries)({
7104
7215
  queries: subscriptionIds.map((subscriptionId) => ({
7105
7216
  queryKey: marketDataKeys.live(subscriptionId),
7106
7217
  queryFn: () => createMarketLiveState(subscriptionId),
@@ -7224,7 +7335,7 @@ function useArbFeed() {
7224
7335
  }
7225
7336
 
7226
7337
  // src/use-order-book.ts
7227
- var import_react_query31 = require("@tanstack/react-query");
7338
+ var import_react_query32 = require("@tanstack/react-query");
7228
7339
  function useOrderBook(options) {
7229
7340
  const client = useAggClient();
7230
7341
  const { orderbooks, enabled = true, canonicalMarketId } = options;
@@ -7237,7 +7348,7 @@ function useOrderBook(options) {
7237
7348
  venueMarketOutcomeId: outcome.id
7238
7349
  })) : void 0
7239
7350
  });
7240
- const batchedResult = (0, import_react_query31.useQuery)({
7351
+ const batchedResult = (0, import_react_query32.useQuery)({
7241
7352
  queryKey: requestedVenueMarketIds.length ? ["orderbooks", requestedVenueMarketIds, null] : ["orderbooks", "__disabled__", null],
7242
7353
  queryFn: ({ signal }) => client.getOrderbooks(
7243
7354
  {
@@ -7250,7 +7361,7 @@ function useOrderBook(options) {
7250
7361
  gcTime: 5 * 6e4,
7251
7362
  refetchOnWindowFocus: false,
7252
7363
  retry: 1,
7253
- placeholderData: import_react_query31.keepPreviousData
7364
+ placeholderData: import_react_query32.keepPreviousData
7254
7365
  });
7255
7366
  const data = (() => {
7256
7367
  var _a, _b;
@@ -7305,7 +7416,7 @@ function useOrderBook(options) {
7305
7416
  }
7306
7417
 
7307
7418
  // src/use-orderbook-quote.ts
7308
- var import_react_query32 = require("@tanstack/react-query");
7419
+ var import_react_query33 = require("@tanstack/react-query");
7309
7420
  var QUOTE_DEBOUNCE_MS = 300;
7310
7421
  var createUnavailableOrderbookError = (message, code, retryable) => {
7311
7422
  const error = new Error(message);
@@ -7367,7 +7478,7 @@ function useOrderbookQuote(options) {
7367
7478
  const { marketId, side, size, enabled = true } = options;
7368
7479
  const debouncedSize = useDebouncedValue(size, QUOTE_DEBOUNCE_MS);
7369
7480
  const shouldFetch = enabled && !!marketId && debouncedSize > 0;
7370
- const query = (0, import_react_query32.useQuery)({
7481
+ const query = (0, import_react_query33.useQuery)({
7371
7482
  queryKey: marketId ? marketDataKeys.orderbookQuote(marketId, side, debouncedSize) : ["market-data", "orderbook-quote", "__disabled__"],
7372
7483
  queryFn: () => __async(null, null, function* () {
7373
7484
  var _a2, _b, _c, _d;
@@ -7398,7 +7509,7 @@ function useOrderbookQuote(options) {
7398
7509
  staleTime: 1e4,
7399
7510
  gcTime: 5 * 6e4,
7400
7511
  retry: 1,
7401
- placeholderData: import_react_query32.keepPreviousData
7512
+ placeholderData: import_react_query33.keepPreviousData
7402
7513
  });
7403
7514
  return {
7404
7515
  data: (_a = query.data) != null ? _a : null,
@@ -7409,12 +7520,12 @@ function useOrderbookQuote(options) {
7409
7520
  }
7410
7521
 
7411
7522
  // src/use-orders.ts
7412
- var import_react_query33 = require("@tanstack/react-query");
7523
+ var import_react_query34 = require("@tanstack/react-query");
7413
7524
  function useOrders(options = {}) {
7414
7525
  var _a, _b, _c, _d;
7415
7526
  const client = useAggClient();
7416
7527
  const { userId, status, limit = 50, offset = 0, enabled = true } = options;
7417
- const query = (0, import_react_query33.useQuery)({
7528
+ const query = (0, import_react_query34.useQuery)({
7418
7529
  queryKey: ["orders", userId != null ? userId : "me", status != null ? status : "all", limit, offset],
7419
7530
  queryFn: () => client.getOrders({
7420
7531
  userId,
@@ -7431,13 +7542,13 @@ function useOrders(options = {}) {
7431
7542
  }
7432
7543
 
7433
7544
  // src/use-search.ts
7434
- var import_react_query34 = require("@tanstack/react-query");
7545
+ var import_react_query35 = require("@tanstack/react-query");
7435
7546
  var import_react31 = require("react");
7436
7547
  function useSearch(options) {
7437
7548
  var _a, _b, _c, _d;
7438
7549
  const client = (0, import_react31.useContext)(AggClientContext);
7439
- const queryClient = (0, import_react31.useContext)(import_react_query34.QueryClientContext);
7440
- const [fallbackQueryClient] = (0, import_react31.useState)(() => new import_react_query34.QueryClient());
7550
+ const queryClient = (0, import_react31.useContext)(import_react_query35.QueryClientContext);
7551
+ const [fallbackQueryClient] = (0, import_react31.useState)(() => new import_react_query35.QueryClient());
7441
7552
  const { q, type, categoryIds, status, limit = 20, enabled = true, deep = false } = options;
7442
7553
  const isEnabled = enabled && q.length > 0;
7443
7554
  (0, import_react31.useEffect)(() => {
@@ -7450,7 +7561,7 @@ function useSearch(options) {
7450
7561
  if (isEnabled && !client) {
7451
7562
  throw new Error("useSearch must be used within an <AggProvider>");
7452
7563
  }
7453
- const query = (0, import_react_query34.useInfiniteQuery)(
7564
+ const query = (0, import_react_query35.useInfiniteQuery)(
7454
7565
  {
7455
7566
  // deep is part of the key — TanStack treats deep vs light as
7456
7567
  // independent queries so users can have both modes cached side-by-side.
@@ -7484,7 +7595,7 @@ function useSearch(options) {
7484
7595
  if (!lastPage.hasMore) return void 0;
7485
7596
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
7486
7597
  },
7487
- placeholderData: import_react_query34.keepPreviousData,
7598
+ placeholderData: import_react_query35.keepPreviousData,
7488
7599
  enabled: isEnabled && !!client
7489
7600
  },
7490
7601
  queryClient != null ? queryClient : fallbackQueryClient
@@ -7592,7 +7703,7 @@ function useMarketSearch(options) {
7592
7703
  }
7593
7704
 
7594
7705
  // src/use-smart-route.ts
7595
- var import_react_query35 = require("@tanstack/react-query");
7706
+ var import_react_query36 = require("@tanstack/react-query");
7596
7707
 
7597
7708
  // src/smart-route-refresh-policy.ts
7598
7709
  var THIN_SMART_ROUTE_REFETCH_INTERVAL_MS = 5e3;
@@ -7741,7 +7852,7 @@ function useSmartRoute(options) {
7741
7852
  const resolvedVenueMarketOutcomeId = (_a = venueMarketOutcomeId != null ? venueMarketOutcomeId : venueMarketId) != null ? _a : outcomeId;
7742
7853
  const hasValidInput = (maxSpend != null ? maxSpend : 0) > 0 || (sellShares != null ? sellShares : 0) > 0;
7743
7854
  const queryEnabled = enabled && !!resolvedVenueMarketOutcomeId && hasValidInput;
7744
- const query = (0, import_react_query35.useQuery)({
7855
+ const query = (0, import_react_query36.useQuery)({
7745
7856
  queryKey: [
7746
7857
  "smart-route",
7747
7858
  resolvedVenueMarketOutcomeId,
@@ -7778,7 +7889,9 @@ function useSmartRoute(options) {
7778
7889
  refetchInterval: (queryState) => {
7779
7890
  var _a2, _b2, _c2, _d2;
7780
7891
  return resolveSmartRouteRefetchInterval({
7781
- data: queryState.state.data,
7892
+ // SELL already fans out into one quote per venue. Keep that group on a
7893
+ // stable cadence instead of multiplying the adaptive 5s/refreshAt poll.
7894
+ data: tradeSide === "sell" ? void 0 : queryState.state.data,
7782
7895
  defaultIntervalMs: staleTimeMs,
7783
7896
  isDocumentVisible: getIsDocumentVisible(),
7784
7897
  isEditing: (_a2 = refreshContext == null ? void 0 : refreshContext.isEditing) != null ? _a2 : false,
@@ -7797,7 +7910,7 @@ function useSmartRoute(options) {
7797
7910
  // a different amount or position snapshot. Never expose it under a new
7798
7911
  // sell key while the replacement request is in flight. BUY retains the
7799
7912
  // existing no-flicker behavior.
7800
- placeholderData: tradeSide === "sell" ? void 0 : import_react_query35.keepPreviousData
7913
+ placeholderData: tradeSide === "sell" ? void 0 : import_react_query36.keepPreviousData
7801
7914
  });
7802
7915
  const error = query.error;
7803
7916
  let loadingReason = null;
@@ -7818,13 +7931,123 @@ function useSmartRoute(options) {
7818
7931
  };
7819
7932
  }
7820
7933
 
7821
- // src/use-venue-sell-quotes.ts
7822
- var import_react_query36 = require("@tanstack/react-query");
7934
+ // src/use-limit-order-venue-quotes.ts
7935
+ var import_react_query37 = require("@tanstack/react-query");
7823
7936
  var getIsDocumentVisible2 = () => {
7824
7937
  if (typeof document === "undefined") return true;
7825
7938
  return document.visibilityState !== "hidden";
7826
7939
  };
7827
7940
  var getUniqueVenueRequests = (requests) => {
7941
+ const requestsByVenue = /* @__PURE__ */ new Map();
7942
+ for (const request of requests) {
7943
+ if (!request.venueMarketOutcomeId || requestsByVenue.has(request.venue)) continue;
7944
+ requestsByVenue.set(request.venue, request);
7945
+ }
7946
+ return [...requestsByVenue.values()].sort((left, right) => left.venue.localeCompare(right.venue));
7947
+ };
7948
+ var useLimitOrderVenueQuotes = (options) => {
7949
+ var _a, _b;
7950
+ const client = useAggClient();
7951
+ const {
7952
+ requests,
7953
+ tradeSide,
7954
+ amount,
7955
+ marketId,
7956
+ accountId,
7957
+ chainBalances,
7958
+ mode,
7959
+ slipCapBps,
7960
+ enabled = true,
7961
+ staleTimeMs = SMART_ROUTE_STALE_TIME_MS,
7962
+ refreshContext
7963
+ } = options;
7964
+ const uniqueRequests = getUniqueVenueRequests(requests);
7965
+ const hasValidInput = typeof amount === "number" && Number.isFinite(amount) && amount > 0;
7966
+ const hasRequiredAccount = tradeSide === "buy" || Boolean(accountId);
7967
+ const queryEnabled = enabled && hasValidInput && hasRequiredAccount;
7968
+ const serializedChainBalances = chainBalances ? JSON.stringify(chainBalances) : null;
7969
+ const queries = (0, import_react_query37.useQueries)({
7970
+ queries: uniqueRequests.map((request) => ({
7971
+ queryKey: [
7972
+ "smart-route",
7973
+ request.venueMarketOutcomeId,
7974
+ "limit-order-venue-info",
7975
+ {
7976
+ venue: request.venue,
7977
+ tradeSide,
7978
+ amount: amount != null ? amount : null,
7979
+ // The quote endpoint does not use limit price, so it must not be
7980
+ // part of this key or trigger a new informational quote.
7981
+ marketId: marketId != null ? marketId : null,
7982
+ accountId: accountId != null ? accountId : null,
7983
+ chainBalances: serializedChainBalances,
7984
+ mode: mode != null ? mode : null,
7985
+ slipCapBps: slipCapBps != null ? slipCapBps : null
7986
+ }
7987
+ ],
7988
+ queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
7989
+ return client.getSmartRoute(
7990
+ __spreadProps(__spreadValues(__spreadValues(__spreadValues({
7991
+ venueMarketOutcomeId: request.venueMarketOutcomeId,
7992
+ tradeSide
7993
+ }, tradeSide === "buy" ? { maxSpend: amount } : { sellShares: amount }), chainBalances ? { chainBalances } : {}), mode ? { mode } : {}), {
7994
+ slipCapBps,
7995
+ allowedVenues: [request.venue]
7996
+ }),
7997
+ { signal }
7998
+ );
7999
+ }),
8000
+ enabled: queryEnabled,
8001
+ placeholderData: import_react_query37.keepPreviousData,
8002
+ staleTime: staleTimeMs,
8003
+ refetchInterval: (queryState) => {
8004
+ var _a2, _b2, _c, _d;
8005
+ return resolveSmartRouteRefetchInterval({
8006
+ data: queryState.state.data,
8007
+ defaultIntervalMs: staleTimeMs,
8008
+ isDocumentVisible: getIsDocumentVisible2(),
8009
+ isEditing: (_a2 = refreshContext == null ? void 0 : refreshContext.isEditing) != null ? _a2 : false,
8010
+ isInputValid: hasValidInput,
8011
+ isMarketOpen: (_b2 = refreshContext == null ? void 0 : refreshContext.isMarketOpen) != null ? _b2 : true,
8012
+ isPanelActive: (_c = refreshContext == null ? void 0 : refreshContext.isPanelActive) != null ? _c : true,
8013
+ isSubmitting: (_d = refreshContext == null ? void 0 : refreshContext.isSubmitting) != null ? _d : false,
8014
+ queryEnabled
8015
+ });
8016
+ },
8017
+ gcTime: 6e4,
8018
+ refetchOnWindowFocus: false,
8019
+ refetchIntervalInBackground: false,
8020
+ retry: 1
8021
+ }))
8022
+ });
8023
+ const quotes = queries.map((query, index) => {
8024
+ var _a2;
8025
+ const queryError = query.error;
8026
+ return {
8027
+ request: uniqueRequests[index],
8028
+ data: (_a2 = query.data) != null ? _a2 : null,
8029
+ isLoading: query.isLoading,
8030
+ isFetching: query.isFetching,
8031
+ error: queryError instanceof Error ? queryError : queryError ? new Error(String(queryError)) : null,
8032
+ refetch: query.refetch
8033
+ };
8034
+ });
8035
+ return {
8036
+ quotes,
8037
+ isLoading: quotes.some((quote) => quote.isLoading),
8038
+ isFetching: quotes.some((quote) => quote.isFetching),
8039
+ error: (_b = (_a = quotes.find((quote) => quote.error)) == null ? void 0 : _a.error) != null ? _b : null,
8040
+ refetch: () => Promise.all(quotes.map((quote) => quote.refetch()))
8041
+ };
8042
+ };
8043
+
8044
+ // src/use-venue-sell-quotes.ts
8045
+ var import_react_query38 = require("@tanstack/react-query");
8046
+ var getIsDocumentVisible3 = () => {
8047
+ if (typeof document === "undefined") return true;
8048
+ return document.visibilityState !== "hidden";
8049
+ };
8050
+ var getUniqueVenueRequests2 = (requests) => {
7828
8051
  const requestsByVenue = /* @__PURE__ */ new Map();
7829
8052
  for (const request of requests) {
7830
8053
  if (request.requestedSellShares <= 0 || request.sellShares <= 0 || request.availableShares <= 0) {
@@ -7849,8 +8072,8 @@ var useVenueSellQuotes = (options) => {
7849
8072
  staleTimeMs = SMART_ROUTE_STALE_TIME_MS,
7850
8073
  refreshContext
7851
8074
  } = options;
7852
- const uniqueRequests = getUniqueVenueRequests(requests);
7853
- const queries = (0, import_react_query36.useQueries)({
8075
+ const uniqueRequests = getUniqueVenueRequests2(requests);
8076
+ const queries = (0, import_react_query38.useQueries)({
7854
8077
  queries: uniqueRequests.map((request) => {
7855
8078
  const hasValidInput = request.requestedSellShares > 0 && request.sellShares > 0 && request.availableShares > 0;
7856
8079
  const queryEnabled = enabled && !!venueMarketOutcomeId && !!accountId && hasValidInput;
@@ -7887,12 +8110,15 @@ var useVenueSellQuotes = (options) => {
7887
8110
  }),
7888
8111
  enabled: queryEnabled,
7889
8112
  staleTime: staleTimeMs,
7890
- refetchInterval: (queryState) => {
8113
+ refetchInterval: (_queryState) => {
7891
8114
  var _a2, _b2, _c, _d;
7892
8115
  return resolveSmartRouteRefetchInterval({
7893
- data: queryState.state.data,
8116
+ // Venue quotes are display companions to the aggregate SELL quote.
8117
+ // Poll them at the normal cadence rather than independently
8118
+ // accelerating every venue to the thin-liquidity interval.
8119
+ data: void 0,
7894
8120
  defaultIntervalMs: staleTimeMs,
7895
- isDocumentVisible: getIsDocumentVisible2(),
8121
+ isDocumentVisible: getIsDocumentVisible3(),
7896
8122
  isEditing: (_a2 = refreshContext == null ? void 0 : refreshContext.isEditing) != null ? _a2 : false,
7897
8123
  isInputValid: hasValidInput,
7898
8124
  isMarketOpen: (_b2 = refreshContext == null ? void 0 : refreshContext.isMarketOpen) != null ? _b2 : true,
@@ -7930,12 +8156,12 @@ var useVenueSellQuotes = (options) => {
7930
8156
  };
7931
8157
 
7932
8158
  // src/use-user-holdings.ts
7933
- var import_react_query37 = require("@tanstack/react-query");
8159
+ var import_react_query39 = require("@tanstack/react-query");
7934
8160
  function useUserHoldings(options) {
7935
8161
  var _a, _b;
7936
8162
  const client = useAggClient();
7937
8163
  const { venue, venueMarketId, venueEventId, enabled = true } = options;
7938
- const query = (0, import_react_query37.useInfiniteQuery)({
8164
+ const query = (0, import_react_query39.useInfiniteQuery)({
7939
8165
  queryKey: ["user-holdings", venue, venueMarketId, venueEventId],
7940
8166
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
7941
8167
  return client.getUserHoldings({
@@ -7964,7 +8190,7 @@ function useUserHoldings(options) {
7964
8190
  var import_react34 = require("react");
7965
8191
 
7966
8192
  // src/use-venue-event.ts
7967
- var import_react_query38 = require("@tanstack/react-query");
8193
+ var import_react_query40 = require("@tanstack/react-query");
7968
8194
  var RESOLUTION_POLL_MS = 15e3;
7969
8195
  var RESOLUTION_POLL_MAX_PAST_END_MS = 60 * 6e4;
7970
8196
  function resolutionPollInterval(event) {
@@ -7982,7 +8208,7 @@ function useVenueEvent(options) {
7982
8208
  var _a;
7983
8209
  const client = useAggClient();
7984
8210
  const { eventId, enabled = true } = options;
7985
- const query = (0, import_react_query38.useQuery)({
8211
+ const query = (0, import_react_query40.useQuery)({
7986
8212
  queryKey: ["venue-event", eventId],
7987
8213
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
7988
8214
  return client.getVenueEventById(eventId, { signal });
@@ -8002,13 +8228,13 @@ function useVenueEvent(options) {
8002
8228
  }
8003
8229
 
8004
8230
  // src/use-venue-markets.ts
8005
- var import_react_query39 = require("@tanstack/react-query");
8231
+ var import_react_query41 = require("@tanstack/react-query");
8006
8232
  var import_react33 = require("react");
8007
8233
  function useVenueMarkets(options) {
8008
8234
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
8009
8235
  const client = (0, import_react33.useContext)(AggClientContext);
8010
- const queryClient = (0, import_react33.useContext)(import_react_query39.QueryClientContext);
8011
- const [fallbackQueryClient] = (0, import_react33.useState)(() => new import_react_query39.QueryClient());
8236
+ const queryClient = (0, import_react33.useContext)(import_react_query41.QueryClientContext);
8237
+ const [fallbackQueryClient] = (0, import_react33.useState)(() => new import_react_query41.QueryClient());
8012
8238
  const venue = options == null ? void 0 : options.venue;
8013
8239
  const venueEventId = options == null ? void 0 : options.venueEventId;
8014
8240
  const search = options == null ? void 0 : options.search;
@@ -8035,7 +8261,7 @@ function useVenueMarkets(options) {
8035
8261
  if (enabled && !client) {
8036
8262
  throw new Error("useVenueMarkets must be used within an <AggProvider>");
8037
8263
  }
8038
- const query = (0, import_react_query39.useInfiniteQuery)(
8264
+ const query = (0, import_react_query41.useInfiniteQuery)(
8039
8265
  {
8040
8266
  queryKey: [
8041
8267
  "venue-markets",
@@ -8156,13 +8382,13 @@ function useEnrichedVenueEvent(options) {
8156
8382
  }
8157
8383
 
8158
8384
  // src/use-venue-events.ts
8159
- var import_react_query40 = require("@tanstack/react-query");
8385
+ var import_react_query42 = require("@tanstack/react-query");
8160
8386
  var import_react35 = require("react");
8161
8387
  function useVenueEvents(options) {
8162
8388
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
8163
8389
  const client = (0, import_react35.useContext)(AggClientContext);
8164
- const queryClient = (0, import_react35.useContext)(import_react_query40.QueryClientContext);
8165
- const [fallbackQueryClient] = (0, import_react35.useState)(() => new import_react_query40.QueryClient());
8390
+ const queryClient = (0, import_react35.useContext)(import_react_query42.QueryClientContext);
8391
+ const [fallbackQueryClient] = (0, import_react35.useState)(() => new import_react_query42.QueryClient());
8166
8392
  const venues = options == null ? void 0 : options.venues;
8167
8393
  const search = options == null ? void 0 : options.search;
8168
8394
  const categoryIds = options == null ? void 0 : options.categoryIds;
@@ -8189,7 +8415,7 @@ function useVenueEvents(options) {
8189
8415
  if (enabled && !client) {
8190
8416
  throw new Error("useVenueEvents must be used within an <AggProvider>");
8191
8417
  }
8192
- const query = (0, import_react_query40.useInfiniteQuery)(
8418
+ const query = (0, import_react_query42.useInfiniteQuery)(
8193
8419
  {
8194
8420
  queryKey: [
8195
8421
  queryKeyScope,
@@ -8236,7 +8462,7 @@ function useVenueEvents(options) {
8236
8462
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
8237
8463
  },
8238
8464
  // TODO: RMIK - Comment out to show skeletons on category switch
8239
- placeholderData: import_react_query40.keepPreviousData,
8465
+ placeholderData: import_react_query42.keepPreviousData,
8240
8466
  enabled: enabled && !!client
8241
8467
  },
8242
8468
  queryClient != null ? queryClient : fallbackQueryClient
@@ -8278,7 +8504,7 @@ function useVenueEvents(options) {
8278
8504
  }
8279
8505
 
8280
8506
  // src/use-venue-market-midpoints.ts
8281
- var import_react_query41 = require("@tanstack/react-query");
8507
+ var import_react_query43 = require("@tanstack/react-query");
8282
8508
  var normalizeVenueMarketIds2 = (venueMarketIds) => {
8283
8509
  return [
8284
8510
  ...new Set(venueMarketIds.map((venueMarketId) => venueMarketId.trim()).filter(Boolean))
@@ -8317,7 +8543,7 @@ function useVenueMarketMidpoints(options) {
8317
8543
  const enabled = (_a = options.enabled) != null ? _a : true;
8318
8544
  const requestedVenueMarketIds = normalizeVenueMarketIds2(options.venueMarketIds);
8319
8545
  const maxMidpointIdsPerRequest = (_b = options.maxMidpointIdsPerRequest) != null ? _b : configuredMaxMidpointIdsPerRequest;
8320
- const query = (0, import_react_query41.useQuery)({
8546
+ const query = (0, import_react_query43.useQuery)({
8321
8547
  queryKey: requestedVenueMarketIds.length ? ["venue-market-midpoints", requestedVenueMarketIds, maxMidpointIdsPerRequest] : ["venue-market-midpoints", "__disabled__"],
8322
8548
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
8323
8549
  if (requestedVenueMarketIds.length === 0) {
@@ -8333,7 +8559,7 @@ function useVenueMarketMidpoints(options) {
8333
8559
  gcTime: 5 * 6e4,
8334
8560
  refetchOnWindowFocus: false,
8335
8561
  retry: 1,
8336
- placeholderData: import_react_query41.keepPreviousData
8562
+ placeholderData: import_react_query43.keepPreviousData
8337
8563
  });
8338
8564
  const midpointRows = (_d = (_c = query.data) == null ? void 0 : _c.data) != null ? _d : [];
8339
8565
  const midpointsByVenueMarketId = mapMidpointsByVenueMarketId(midpointRows);
@@ -8584,12 +8810,12 @@ function useVisibleIds(options = {}) {
8584
8810
  }
8585
8811
 
8586
8812
  // src/use-app-config.ts
8587
- var import_react_query42 = require("@tanstack/react-query");
8813
+ var import_react_query44 = require("@tanstack/react-query");
8588
8814
  var FIVE_MINUTES = 5 * 60 * 1e3;
8589
8815
  var APP_CONFIG_QUERY_KEY = ["agg", "app-config"];
8590
8816
  function useAppConfig() {
8591
8817
  const client = useAggClient();
8592
- const query = (0, import_react_query42.useQuery)({
8818
+ const query = (0, import_react_query44.useQuery)({
8593
8819
  queryKey: APP_CONFIG_QUERY_KEY,
8594
8820
  queryFn: () => client.getAppConfig(),
8595
8821
  staleTime: FIVE_MINUTES
@@ -8601,8 +8827,8 @@ function useAppConfig() {
8601
8827
  });
8602
8828
  }
8603
8829
  function useCachedAppConfig() {
8604
- const queryClient = (0, import_react_query42.useQueryClient)();
8605
- const query = (0, import_react_query42.useQuery)({
8830
+ const queryClient = (0, import_react_query44.useQueryClient)();
8831
+ const query = (0, import_react_query44.useQuery)({
8606
8832
  queryKey: APP_CONFIG_QUERY_KEY,
8607
8833
  enabled: false,
8608
8834
  initialData: () => queryClient.getQueryData(APP_CONFIG_QUERY_KEY),
@@ -8698,6 +8924,7 @@ var toAppConfigResult = (query) => {
8698
8924
  useAggWebSocket,
8699
8925
  useAppConfig,
8700
8926
  useArbFeed,
8927
+ useBalanceRefillPolicies,
8701
8928
  useCachedAppConfig,
8702
8929
  useCancelManagedOrder,
8703
8930
  useCategories,
@@ -8715,6 +8942,7 @@ var toAppConfigResult = (query) => {
8715
8942
  useExternalId,
8716
8943
  useGeoBlock,
8717
8944
  useLabels,
8945
+ useLimitOrderVenueQuotes,
8718
8946
  useLinkAccount,
8719
8947
  useLiveBestPriceCandidates,
8720
8948
  useLiveBestPrices,