@agg-build/hooks 2.1.0 → 2.1.2

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.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  useRampQuotes,
3
3
  useRampSession
4
- } from "./chunk-QKVR32KC.mjs";
4
+ } from "./chunk-5VDUIUJB.mjs";
5
5
  import {
6
6
  useWithdrawEstimate,
7
7
  useWithdrawFlow,
8
8
  useWithdrawPreview,
9
9
  useWithdrawalLifecycle
10
- } from "./chunk-DK4YDVPH.mjs";
10
+ } from "./chunk-FBYQBFFR.mjs";
11
11
  import {
12
12
  AggAuthContext,
13
13
  AggBalanceProvider,
@@ -95,7 +95,7 @@ import {
95
95
  useSyncBalances,
96
96
  useWithdrawManaged,
97
97
  userActivityQueryKeys
98
- } from "./chunk-V7VCT62L.mjs";
98
+ } from "./chunk-7UDYSDKQ.mjs";
99
99
 
100
100
  // src/index.ts
101
101
  import { QueryClient as QueryClient4, QueryClientProvider, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
@@ -1003,6 +1003,7 @@ function findLivePriceById(livePrices, id) {
1003
1003
  import { useMemo as useMemo7, useRef as useRef3 } from "react";
1004
1004
  import { useQueries as useQueries4 } from "@tanstack/react-query";
1005
1005
  var EMPTY = /* @__PURE__ */ new Map();
1006
+ var EMPTY_CANDIDATES = /* @__PURE__ */ new Map();
1006
1007
  var extractOutcomeBestPrices = (state) => {
1007
1008
  var _a, _b;
1008
1009
  const ob = state == null ? void 0 : state.orderbook;
@@ -1120,6 +1121,175 @@ function mergeBestPricesPreferringLive(rest, live) {
1120
1121
  }
1121
1122
  return merged;
1122
1123
  }
1124
+ var pickSideVenue = (venues, level, side) => {
1125
+ if (venues) {
1126
+ let bestVenue;
1127
+ let bestValue;
1128
+ for (const [venue, info] of Object.entries(venues)) {
1129
+ const value = side === "bid" ? info.bestBid : info.bestAsk;
1130
+ if (value == null) continue;
1131
+ const wins = bestValue == null || (side === "bid" ? value > bestValue : value < bestValue);
1132
+ if (wins) {
1133
+ bestValue = value;
1134
+ bestVenue = venue;
1135
+ }
1136
+ }
1137
+ if (bestVenue != null) return bestVenue;
1138
+ }
1139
+ if (level == null ? void 0 : level.venues) {
1140
+ let bestVenue;
1141
+ let bestSize = -Infinity;
1142
+ for (const [venue, size] of Object.entries(level.venues)) {
1143
+ if (size > bestSize) {
1144
+ bestSize = size;
1145
+ bestVenue = venue;
1146
+ }
1147
+ }
1148
+ if (bestVenue != null) return bestVenue;
1149
+ }
1150
+ return void 0;
1151
+ };
1152
+ var extractOutcomeBestCandidate = (state) => {
1153
+ var _a;
1154
+ const ob = state == null ? void 0 : state.orderbook;
1155
+ if (!ob) return {};
1156
+ const candidate = {};
1157
+ const bidLevel = ob.bids[0];
1158
+ const askLevel = ob.asks[0];
1159
+ if ((bidLevel == null ? void 0 : bidLevel.price) != null) {
1160
+ candidate.bestBid = bidLevel.price;
1161
+ const venue = pickSideVenue(ob.venues, bidLevel, "bid");
1162
+ if (venue) candidate.bestBidVenue = venue;
1163
+ }
1164
+ if ((askLevel == null ? void 0 : askLevel.price) != null) {
1165
+ candidate.bestAsk = askLevel.price;
1166
+ const venue = pickSideVenue(ob.venues, askLevel, "ask");
1167
+ if (venue) candidate.bestAskVenue = venue;
1168
+ }
1169
+ if (ob.midpoint != null) {
1170
+ candidate.midpoint = ob.midpoint;
1171
+ const midVenue = (_a = candidate.bestAskVenue) != null ? _a : candidate.bestBidVenue;
1172
+ if (midVenue) candidate.midpointVenue = midVenue;
1173
+ }
1174
+ if (ob.timestamp != null) candidate.updatedAt = ob.timestamp;
1175
+ return candidate;
1176
+ };
1177
+ function buildLiveBestPriceCandidates(outcomeIds, states, venueMarkets) {
1178
+ var _a, _b, _c;
1179
+ const perOutcome = /* @__PURE__ */ new Map();
1180
+ for (let i = 0; i < outcomeIds.length; i++) {
1181
+ const candidate = extractOutcomeBestCandidate(states[i]);
1182
+ if (candidate.bestBid != null || candidate.bestAsk != null || candidate.midpoint != null) {
1183
+ perOutcome.set(outcomeIds[i], candidate);
1184
+ }
1185
+ }
1186
+ if (perOutcome.size === 0 || !(venueMarkets == null ? void 0 : venueMarkets.length)) {
1187
+ return perOutcome;
1188
+ }
1189
+ const result = new Map(perOutcome);
1190
+ for (const vm of venueMarkets) {
1191
+ for (const outcome of (_a = vm.venueMarketOutcomes) != null ? _a : []) {
1192
+ const refs = (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : [];
1193
+ if (!refs.length) continue;
1194
+ const group = [outcome.id, ...refs.map((ref) => ref.venueMarketOutcomeId)];
1195
+ let groupBestAsk;
1196
+ let groupBestAskVenue;
1197
+ let groupBestBid;
1198
+ let groupBestBidVenue;
1199
+ let groupUpdatedAt;
1200
+ for (const id of group) {
1201
+ const entry = perOutcome.get(id);
1202
+ if (!entry) continue;
1203
+ if (entry.bestAsk != null && (groupBestAsk == null || entry.bestAsk < groupBestAsk)) {
1204
+ groupBestAsk = entry.bestAsk;
1205
+ groupBestAskVenue = entry.bestAskVenue;
1206
+ }
1207
+ if (entry.bestBid != null && (groupBestBid == null || entry.bestBid > groupBestBid)) {
1208
+ groupBestBid = entry.bestBid;
1209
+ groupBestBidVenue = entry.bestBidVenue;
1210
+ }
1211
+ if (entry.updatedAt != null && (groupUpdatedAt == null || entry.updatedAt > groupUpdatedAt)) {
1212
+ groupUpdatedAt = entry.updatedAt;
1213
+ }
1214
+ }
1215
+ if (groupBestAsk == null && groupBestBid == null) continue;
1216
+ for (const id of group) {
1217
+ const prev = (_c = result.get(id)) != null ? _c : {};
1218
+ const next = __spreadValues({}, prev);
1219
+ if (groupBestBid != null) {
1220
+ next.bestBid = groupBestBid;
1221
+ if (groupBestBidVenue) next.bestBidVenue = groupBestBidVenue;
1222
+ }
1223
+ if (groupBestAsk != null) {
1224
+ next.bestAsk = groupBestAsk;
1225
+ if (groupBestAskVenue) next.bestAskVenue = groupBestAskVenue;
1226
+ }
1227
+ if (groupUpdatedAt != null) next.updatedAt = groupUpdatedAt;
1228
+ result.set(id, next);
1229
+ }
1230
+ }
1231
+ }
1232
+ return result;
1233
+ }
1234
+ var buildCandidateFingerprint = (outcomeIds, queries) => {
1235
+ var _a, _b, _c, _d;
1236
+ const parts = [];
1237
+ for (let i = 0; i < outcomeIds.length; i++) {
1238
+ const ob = (_b = (_a = queries[i]) == null ? void 0 : _a.data) == null ? void 0 : _b.orderbook;
1239
+ const bid = (_c = ob == null ? void 0 : ob.bids[0]) == null ? void 0 : _c.price;
1240
+ const ask = (_d = ob == null ? void 0 : ob.asks[0]) == null ? void 0 : _d.price;
1241
+ const mid = ob == null ? void 0 : ob.midpoint;
1242
+ const ts = ob == null ? void 0 : ob.timestamp;
1243
+ const venues = (ob == null ? void 0 : ob.venues) ? Object.keys(ob.venues).sort().join(",") : "";
1244
+ parts.push(`${outcomeIds[i]}:${bid != null ? bid : "_"}:${ask != null ? ask : "_"}:${mid != null ? mid : "_"}:${ts != null ? ts : "_"}:${venues}`);
1245
+ }
1246
+ return parts.join("|");
1247
+ };
1248
+ function useLiveBestPriceCandidates(venueMarkets) {
1249
+ const {
1250
+ features: { enableLiveUpdates }
1251
+ } = useAggUiConfig();
1252
+ const outcomeIds = useMemo7(() => {
1253
+ var _a, _b;
1254
+ if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
1255
+ const ids = /* @__PURE__ */ new Set();
1256
+ for (const vm of venueMarkets) {
1257
+ for (const outcome of (_a = vm.venueMarketOutcomes) != null ? _a : []) {
1258
+ if (outcome.id) ids.add(outcome.id);
1259
+ for (const ref of (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : []) {
1260
+ if (ref.venueMarketOutcomeId) ids.add(ref.venueMarketOutcomeId);
1261
+ }
1262
+ }
1263
+ }
1264
+ return [...ids].sort();
1265
+ }, [venueMarkets]);
1266
+ const queries = useQueries4({
1267
+ queries: outcomeIds.map((id) => ({
1268
+ queryKey: marketDataKeys.live(id),
1269
+ queryFn: () => createMarketLiveState(id),
1270
+ enabled: false,
1271
+ staleTime: Infinity,
1272
+ gcTime: 5 * 6e4,
1273
+ initialData: () => createMarketLiveState(id)
1274
+ }))
1275
+ });
1276
+ const fingerprint = buildCandidateFingerprint(outcomeIds, queries);
1277
+ const prevRef = useRef3({
1278
+ fingerprint: "",
1279
+ result: EMPTY_CANDIDATES
1280
+ });
1281
+ return useMemo7(() => {
1282
+ if (!(venueMarkets == null ? void 0 : venueMarkets.length) || !enableLiveUpdates) return EMPTY_CANDIDATES;
1283
+ if (fingerprint === prevRef.current.fingerprint) return prevRef.current.result;
1284
+ const states = outcomeIds.map((_, i) => {
1285
+ var _a;
1286
+ return (_a = queries[i]) == null ? void 0 : _a.data;
1287
+ });
1288
+ const result = buildLiveBestPriceCandidates(outcomeIds, states, venueMarkets);
1289
+ prevRef.current = { fingerprint, result };
1290
+ return result;
1291
+ }, [venueMarkets, enableLiveUpdates, fingerprint, outcomeIds, queries]);
1292
+ }
1123
1293
 
1124
1294
  // src/use-live-trades.ts
1125
1295
  function useLiveTrades(canonicalMarketId) {
@@ -2667,11 +2837,13 @@ export {
2667
2837
  TradeSide,
2668
2838
  TurnstileChallengeError,
2669
2839
  Venue,
2840
+ buildLiveBestPriceCandidates,
2670
2841
  computeClosedPositionTotals,
2671
2842
  computePriceGaps,
2672
2843
  defaultAggUiConfig,
2673
2844
  defaultAggUiConfig as defaultSdkUiConfig,
2674
2845
  executionKeys,
2846
+ extractOutcomeBestCandidate,
2675
2847
  findLivePriceById,
2676
2848
  getBuilder,
2677
2849
  getDepositAddress,
@@ -2733,6 +2905,7 @@ export {
2733
2905
  useGeoBlock,
2734
2906
  useLabels,
2735
2907
  useLinkAccount,
2908
+ useLiveBestPriceCandidates,
2736
2909
  useLiveBestPrices,
2737
2910
  useLiveCandleOverlay,
2738
2911
  useLiveCandles,
package/dist/withdraw.js CHANGED
@@ -330,6 +330,13 @@ var enUsLabels = {
330
330
  categoryTabsAria: "Home page category tabs"
331
331
  },
332
332
  userProfile: {
333
+ balance: {
334
+ availableBalance: "Available Balance",
335
+ balanceByNetwork: "Balance by network",
336
+ paperModeNetwork: "Paper",
337
+ paperModeWarning: "Paper mode is enabled. These are simulated funds for paper trading.",
338
+ networkTooltipDescription: "Funds are stored across networks. We handle routing automatically, but keeping funds on the right network enables faster trades and lower fees. When depositing, you can choose your preferred network."
339
+ },
333
340
  activity: {
334
341
  depositType: "Deposit",
335
342
  redeemType: "Claim",
@@ -695,6 +702,7 @@ var enUsLabels = {
695
702
  orderSkip: "Skip",
696
703
  orderRetryRemaining: "Retry remaining",
697
704
  resolvedEarningsTitle: "Your Earnings",
705
+ resolvedResolutionDateLabel: "Resolution date",
698
706
  resolvedSharesLabel: "Shares",
699
707
  resolvedTotalPayoutLabel: "Total payout",
700
708
  claimWinnings: "Claim Winnings",
@@ -994,7 +1002,10 @@ var defaultAggUiConfig = {
994
1002
  }
995
1003
  },
996
1004
  formatting: defaultFormatters,
997
- search: defaultAggUiSearchConfig
1005
+ search: defaultAggUiSearchConfig,
1006
+ trading: {
1007
+ executionMode: "live"
1008
+ }
998
1009
  };
999
1010
 
1000
1011
  // src/core/providers/contexts.ts
@@ -1028,7 +1039,7 @@ var balanceQueryKeys = {
1028
1039
  execution: () => executionKeys.balances(),
1029
1040
  // Kept as an alias for backward compatibility with existing callers.
1030
1041
  // The balance provider now uses the same canonical execution balances key.
1031
- provider: () => executionKeys.balances(),
1042
+ provider: (mode) => executionKeys.balances(mode),
1032
1043
  venue: (venuesKey) => ["venue-balances", venuesKey],
1033
1044
  venuePrefix: () => ["venue-balances"]
1034
1045
  };
package/dist/withdraw.mjs CHANGED
@@ -3,12 +3,12 @@ import {
3
3
  useWithdrawFlow,
4
4
  useWithdrawPreview,
5
5
  useWithdrawalLifecycle
6
- } from "./chunk-DK4YDVPH.mjs";
6
+ } from "./chunk-FBYQBFFR.mjs";
7
7
  import {
8
8
  useDepositAddresses,
9
9
  useManagedBalances,
10
10
  useWithdrawManaged
11
- } from "./chunk-V7VCT62L.mjs";
11
+ } from "./chunk-7UDYSDKQ.mjs";
12
12
  export {
13
13
  useDepositAddresses,
14
14
  useManagedBalances,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agg-build/hooks",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "React hooks and providers for the AGG prediction market aggregator. Wraps @agg-build/sdk with TanStack Query, shared session state, and live WebSocket data.",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -83,7 +83,7 @@
83
83
  "react": "^18.0.0 || ^19.0.0",
84
84
  "viem": "^2.0.0",
85
85
  "wagmi": "^3.0.0 || ^2.0.0",
86
- "@agg-build/sdk": "^2.1.0"
86
+ "@agg-build/sdk": "^2.1.2"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@solana/wallet-adapter-react": {