@agg-build/hooks 4.0.1 → 4.4.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/README.md +30 -13
- package/dist/{chunk-AZYAQIZB.mjs → chunk-IHMZHA2W.mjs} +1 -1
- package/dist/{chunk-SC6X5TL4.mjs → chunk-LVOL27OZ.mjs} +338 -49
- package/dist/{chunk-BR6NZSXN.mjs → chunk-O4RM4KKO.mjs} +1 -1
- package/dist/deposit.js +54 -5
- package/dist/deposit.mjs +2 -2
- package/dist/index.d.mts +472 -4
- package/dist/index.d.ts +472 -4
- package/dist/index.js +1013 -80
- package/dist/index.mjs +654 -21
- package/dist/withdraw.js +54 -5
- package/dist/withdraw.mjs +2 -2
- package/package.json +2 -2
|
@@ -61,9 +61,11 @@ var Venue = /* @__PURE__ */ ((Venue2) => {
|
|
|
61
61
|
Venue2["probable"] = "probable";
|
|
62
62
|
Venue2["myriad"] = "myriad";
|
|
63
63
|
Venue2["hyperliquid"] = "hyperliquid";
|
|
64
|
+
Venue2["novig"] = "novig";
|
|
64
65
|
return Venue2;
|
|
65
66
|
})(Venue || {});
|
|
66
67
|
var ACTIVE_VENUES = [
|
|
68
|
+
"kalshi" /* kalshi */,
|
|
67
69
|
"polymarket" /* polymarket */,
|
|
68
70
|
"limitless" /* limitless */,
|
|
69
71
|
"opinion" /* opinion */,
|
|
@@ -72,7 +74,7 @@ var ACTIVE_VENUES = [
|
|
|
72
74
|
"myriad" /* myriad */,
|
|
73
75
|
"hyperliquid" /* hyperliquid */
|
|
74
76
|
];
|
|
75
|
-
var INACTIVE_VENUES = ["
|
|
77
|
+
var INACTIVE_VENUES = ["novig" /* novig */];
|
|
76
78
|
var ACTIVE_VENUE_SET = new Set(ACTIVE_VENUES);
|
|
77
79
|
var INACTIVE_VENUE_SET = new Set(INACTIVE_VENUES);
|
|
78
80
|
|
|
@@ -246,7 +248,8 @@ var enUsLabels = {
|
|
|
246
248
|
limitless: "Limitless",
|
|
247
249
|
probable: "Probable",
|
|
248
250
|
myriad: "Myriad",
|
|
249
|
-
hyperliquid: "Hyperliquid"
|
|
251
|
+
hyperliquid: "Hyperliquid",
|
|
252
|
+
novig: "Novig"
|
|
250
253
|
},
|
|
251
254
|
auth: {
|
|
252
255
|
connect: (connectorName) => connectorName ? `Sign in with ${connectorName}` : "Sign in",
|
|
@@ -527,7 +530,7 @@ var enUsLabels = {
|
|
|
527
530
|
userProfile: {
|
|
528
531
|
tabs: {
|
|
529
532
|
positions: "Positions",
|
|
530
|
-
openOrders: "Open orders",
|
|
533
|
+
openOrders: "Open limit orders",
|
|
531
534
|
activity: "Activity"
|
|
532
535
|
},
|
|
533
536
|
balance: {
|
|
@@ -630,6 +633,7 @@ var enUsLabels = {
|
|
|
630
633
|
goodTilCanceled: "Good 'til canceled",
|
|
631
634
|
expired: "Expired",
|
|
632
635
|
cancel: "Cancel",
|
|
636
|
+
pending: "Pending",
|
|
633
637
|
cancelOrderAria: (orderId) => `Cancel order ${orderId}`,
|
|
634
638
|
loading: "Loading open orders",
|
|
635
639
|
loadingMore: "Loading more open orders",
|
|
@@ -708,7 +712,19 @@ var enUsLabels = {
|
|
|
708
712
|
volumeSuffix: "Vol.",
|
|
709
713
|
marketSelectPlaceholder: "Select market",
|
|
710
714
|
marketSelectSearchPlaceholder: "Search markets...",
|
|
711
|
-
marketSelectEmpty: "No markets found"
|
|
715
|
+
marketSelectEmpty: "No markets found",
|
|
716
|
+
moreMarkets: "More",
|
|
717
|
+
liveMarket: "Live"
|
|
718
|
+
},
|
|
719
|
+
sportsLive: {
|
|
720
|
+
scoreAria: (firstName, firstScore, secondName, secondScore, status) => `${firstName} ${firstScore}, ${secondName} ${secondScore}, ${status}`,
|
|
721
|
+
scheduled: "Scheduled",
|
|
722
|
+
live: "Live",
|
|
723
|
+
paused: "Paused",
|
|
724
|
+
finished: "Final",
|
|
725
|
+
cancelled: "Cancelled",
|
|
726
|
+
postponed: "Postponed",
|
|
727
|
+
unknown: "Status unavailable"
|
|
712
728
|
},
|
|
713
729
|
settlementSummary: {
|
|
714
730
|
title: "Settlement differences",
|
|
@@ -755,6 +771,7 @@ var enUsLabels = {
|
|
|
755
771
|
showOutcomeAria: (label) => `Show ${label} outcome`,
|
|
756
772
|
viewResolved: "View resolved",
|
|
757
773
|
hideResolved: "Hide resolved",
|
|
774
|
+
resolvingBadge: "Resolving",
|
|
758
775
|
resolvingTitle: "Resolving market\u2026",
|
|
759
776
|
resolvingDescription: "This market has closed. We're waiting for final settlement data and will update the result once it's confirmed on-chain.",
|
|
760
777
|
volumeUnavailable: "Volume unavailable",
|
|
@@ -835,7 +852,9 @@ var enUsLabels = {
|
|
|
835
852
|
orderDisabledNoOutcome: "Select an outcome to place an order.",
|
|
836
853
|
orderDisabledNoEvent: "No event selected.",
|
|
837
854
|
insufficientBalance: "Insufficient balance",
|
|
838
|
-
|
|
855
|
+
insufficientBalanceDetails: "Insufficient balance details",
|
|
856
|
+
lowLiquidityWarning: "Your avg. price is higher than the market price due to your order size and available market liquidity.",
|
|
857
|
+
lowLiquiditySellWarning: "Your avg. price is lower than the market price due to your order size and available market liquidity.",
|
|
839
858
|
refreshQuote: "Refresh Quote",
|
|
840
859
|
confirmOrder: "Confirm Order",
|
|
841
860
|
withdrawSubmitted: "Withdrawal submitted",
|
|
@@ -911,6 +930,12 @@ var enUsLabels = {
|
|
|
911
930
|
limitPrice: "Limit price",
|
|
912
931
|
limitPriceInputAria: "Limit price in cents",
|
|
913
932
|
limitPriceInvalid: "Limit price must be greater than 0 and less than 100.",
|
|
933
|
+
limitPriceAdjusted: (venueLabels, tickSizeCents, originalPriceLabel, side, adjustedPriceLabel) => {
|
|
934
|
+
const venues = venueLabels.length <= 1 ? venueLabels.join("") : venueLabels.length === 2 ? `${venueLabels[0]} and ${venueLabels[1]}` : `${venueLabels.slice(0, -1).join(", ")} and ${venueLabels[venueLabels.length - 1]}`;
|
|
935
|
+
const increment = tickSizeCents === 1 ? "whole cents" : `${tickSizeCents.toLocaleString("en-US", { maximumFractionDigits: 4 })}\xA2 increments`;
|
|
936
|
+
const direction = side === "buy" ? "down" : "up";
|
|
937
|
+
return `${venues} price in ${increment}, so your ${originalPriceLabel} ${side} rounds ${direction} to ${adjustedPriceLabel}`;
|
|
938
|
+
},
|
|
914
939
|
limitPriceDecreaseAria: "Decrease limit price",
|
|
915
940
|
limitPriceIncreaseAria: "Increase limit price",
|
|
916
941
|
expiration: "Expiration",
|
|
@@ -954,9 +979,23 @@ var enUsLabels = {
|
|
|
954
979
|
updatingRoute: "Updating route\u2026",
|
|
955
980
|
refreshingQuotes: "Refreshing quotes\u2026",
|
|
956
981
|
checkingBalance: "Checking balance",
|
|
982
|
+
executingOrder: "Executing order...",
|
|
957
983
|
submittingOrderProgress: "Submitting order...",
|
|
984
|
+
executionOrderSubmitted: "Order submitted",
|
|
958
985
|
orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
|
|
959
986
|
executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
|
|
987
|
+
venueOrder: (venueLabel) => `${venueLabel} order`,
|
|
988
|
+
settingUpBridge: "Setting up bridging...",
|
|
989
|
+
bridgeSetupComplete: "Bridge setup complete",
|
|
990
|
+
bridgingFundsProgress: "Bridging funds...",
|
|
991
|
+
bridgeComplete: "Bridge complete",
|
|
992
|
+
bridgingFunds: (amount, sourceChain, destinationChain, tokenSymbol = "USDC") => `Bridging ${amount} ${tokenSymbol} from ${sourceChain} to ${destinationChain}...`,
|
|
993
|
+
fundsBridged: (amount, sourceChain, destinationChain, tokenSymbol = "USDC") => `Bridged ${amount} ${tokenSymbol} from ${sourceChain} to ${destinationChain}`,
|
|
994
|
+
depositingFunds: (amount, tokenSymbol, destinationChain) => `Depositing ${amount} ${tokenSymbol} to ${destinationChain}...`,
|
|
995
|
+
fundsDeposited: (amount, tokenSymbol, destinationChain) => `Deposited ${amount} ${tokenSymbol} to ${destinationChain}`,
|
|
996
|
+
fillingOnVenue: (venueLabel) => `Filling on ${venueLabel}...`,
|
|
997
|
+
venueFilledAtPriceWithAmount: (venueLabel, amountLabel, priceLabel) => `${venueLabel} filled ${amountLabel} at ${priceLabel}`,
|
|
998
|
+
executionShares: (value) => `${value} shares`,
|
|
960
999
|
confirmTransactionInWallet: "Confirm the transaction in your wallet",
|
|
961
1000
|
executionConfirmed: "Execution confirmed",
|
|
962
1001
|
orderSuccessTitle: "Order placed",
|
|
@@ -964,7 +1003,7 @@ var enUsLabels = {
|
|
|
964
1003
|
orderFailureTitle: "Order failed",
|
|
965
1004
|
orderFailureDescription: (message) => message || "Something went wrong. Please try again.",
|
|
966
1005
|
orderDone: "Done",
|
|
967
|
-
orderNewTrade: "New
|
|
1006
|
+
orderNewTrade: "New trade",
|
|
968
1007
|
orderShare: "Share",
|
|
969
1008
|
orderRetry: "Try again",
|
|
970
1009
|
orderContinue: "Continue",
|
|
@@ -977,12 +1016,20 @@ var enUsLabels = {
|
|
|
977
1016
|
orderSummaryAvgPrice: "Avg. price",
|
|
978
1017
|
orderSummaryEstCost: "Est. cost",
|
|
979
1018
|
orderSummaryVenue: "Venue",
|
|
1019
|
+
orderAmountFilled: "Amount filled",
|
|
1020
|
+
orderAmountFilledOf: (requestedAmount) => `of ${requestedAmount}`,
|
|
1021
|
+
orderPayout: "Payout",
|
|
1022
|
+
orderFullyFilled: "Order fully filled",
|
|
1023
|
+
orderPartiallyFilled: "Order partially filled",
|
|
1024
|
+
orderAveragePrice: (priceLabel) => `avg. ${priceLabel}`,
|
|
980
1025
|
orderComplete: "Order complete",
|
|
981
1026
|
orderFilledAtPrice: (venueLabel, priceLabel) => `${venueLabel} order filled at ${priceLabel}`,
|
|
982
1027
|
orderFilledAtPriceWithAmount: (venueLabel, priceLabel, amountLabel) => `${venueLabel} order filled at ${priceLabel} (${amountLabel})`,
|
|
983
1028
|
orderPartiallyFilledAtPriceWithAmount: (venueLabel, priceLabel, amountLabel) => `${venueLabel} order partially filled at ${priceLabel} (${amountLabel})`,
|
|
984
1029
|
orderSkip: "Skip",
|
|
985
1030
|
orderRetryRemaining: "Retry remaining",
|
|
1031
|
+
orderTryRemaining: (remainingLabel) => `Try remaining ${remainingLabel}`,
|
|
1032
|
+
orderClose: "Close",
|
|
986
1033
|
resolvedEarningsTitle: "Your Earnings",
|
|
987
1034
|
resolvedResolutionDateLabel: "Resolution date",
|
|
988
1035
|
resolvedSharesLabel: "Shares",
|
|
@@ -991,6 +1038,7 @@ var enUsLabels = {
|
|
|
991
1038
|
boughtOutcomeAtPrice: (label, priceLabel) => `Bought ${label} at ${priceLabel}`,
|
|
992
1039
|
soldOutcomeAtPrice: (label, priceLabel) => `Sold ${label} at ${priceLabel}`,
|
|
993
1040
|
potentialReturnBonus: (value) => `+${value} Better Payout`,
|
|
1041
|
+
potentialReturnBetter: (value) => `+${value} Better`,
|
|
994
1042
|
withSmartRouting: "with Smart Routing",
|
|
995
1043
|
buy: "Buy",
|
|
996
1044
|
sell: "Sell",
|
|
@@ -1135,6 +1183,9 @@ var enUsLabels = {
|
|
|
1135
1183
|
resolvedOutcome: (label) => `Resolved: ${label}`,
|
|
1136
1184
|
marketDetailsAriaByDate: (dateLabel) => `Market details for ${dateLabel}`,
|
|
1137
1185
|
marketDetailsAriaByQuestion: (question) => `Market details for ${question}`,
|
|
1186
|
+
recurringCountdownAria: (countdown) => `Current market ends in ${countdown}`,
|
|
1187
|
+
goToLive: "Go to live",
|
|
1188
|
+
liveMarketUnavailable: "A live market is not available yet",
|
|
1138
1189
|
sports: {
|
|
1139
1190
|
summaryAria: "Sports event summary",
|
|
1140
1191
|
sectionTabsAria: "Sports market sections",
|
|
@@ -1720,6 +1771,7 @@ function AggBalanceProvider({ children }) {
|
|
|
1720
1771
|
if (!isAuthenticated) {
|
|
1721
1772
|
return {
|
|
1722
1773
|
managedBalances,
|
|
1774
|
+
dataUpdatedAt: 0,
|
|
1723
1775
|
totalBalance: 0,
|
|
1724
1776
|
availableBalance: 0,
|
|
1725
1777
|
reservedBalance: 0,
|
|
@@ -1738,6 +1790,7 @@ function AggBalanceProvider({ children }) {
|
|
|
1738
1790
|
const error = balancesError instanceof Error ? balancesError : balancesError ? new Error(String(balancesError)) : null;
|
|
1739
1791
|
return {
|
|
1740
1792
|
managedBalances,
|
|
1793
|
+
dataUpdatedAt: balancesQuery.dataUpdatedAt,
|
|
1741
1794
|
totalBalance,
|
|
1742
1795
|
availableBalance,
|
|
1743
1796
|
reservedBalance,
|
|
@@ -1763,6 +1816,7 @@ function AggBalanceProvider({ children }) {
|
|
|
1763
1816
|
kalshiBalance,
|
|
1764
1817
|
kalshiPortfolioValue,
|
|
1765
1818
|
managedBalances,
|
|
1819
|
+
balancesQuery.dataUpdatedAt,
|
|
1766
1820
|
positionsBalanceTotal,
|
|
1767
1821
|
refetch,
|
|
1768
1822
|
refetchConnectionStatus,
|
|
@@ -3977,7 +4031,7 @@ function useQueryClientCheck() {
|
|
|
3977
4031
|
if (!hasWarnedMissingQueryClient) {
|
|
3978
4032
|
hasWarnedMissingQueryClient = true;
|
|
3979
4033
|
console.error(
|
|
3980
|
-
"[agg] AggProvider requires a QueryClientProvider ancestor.
|
|
4034
|
+
"[agg] AggProvider requires a QueryClientProvider ancestor. Wrap AggProvider in a <QueryClientProvider client={queryClient}>."
|
|
3981
4035
|
);
|
|
3982
4036
|
}
|
|
3983
4037
|
}
|
|
@@ -3986,7 +4040,7 @@ var AggProvider = ({ client, config, children }) => {
|
|
|
3986
4040
|
useQueryClientCheck();
|
|
3987
4041
|
if (!client) {
|
|
3988
4042
|
throw new Error(
|
|
3989
|
-
"AggProvider requires a valid AggClient instance.
|
|
4043
|
+
"AggProvider requires a valid AggClient instance. Create one with createAggClient() and pass it via the 'client' prop."
|
|
3990
4044
|
);
|
|
3991
4045
|
}
|
|
3992
4046
|
return /* @__PURE__ */ jsx8(AggClientProvider, { client, children: /* @__PURE__ */ jsx8(AggUiProvider, { config, children: /* @__PURE__ */ jsx8(EventListStateProvider, { children: /* @__PURE__ */ jsx8(AggWebSocketProvider, { children: /* @__PURE__ */ jsx8(AggAuthProvider, { children: /* @__PURE__ */ jsx8(AggBalanceProvider, { children }) }) }) }) }) });
|
|
@@ -4196,6 +4250,118 @@ function mapOrderStatusToTerminalEvent(status) {
|
|
|
4196
4250
|
if (status === "failed" || status === "cancelled" || status === "expired") return "failed";
|
|
4197
4251
|
return null;
|
|
4198
4252
|
}
|
|
4253
|
+
var mergeTerminalOrderEvents = (currentEvents, incomingEvents) => {
|
|
4254
|
+
const mergedByOrderId = new Map(currentEvents.map((event) => [event.orderId, event]));
|
|
4255
|
+
for (const incomingEvent of incomingEvents) {
|
|
4256
|
+
const currentEvent = mergedByOrderId.get(incomingEvent.orderId);
|
|
4257
|
+
if (!currentEvent) {
|
|
4258
|
+
mergedByOrderId.set(incomingEvent.orderId, incomingEvent);
|
|
4259
|
+
continue;
|
|
4260
|
+
}
|
|
4261
|
+
if (currentEvent.event === "filled") continue;
|
|
4262
|
+
if (incomingEvent.event === "filled" || incomingEvent.timestamp >= currentEvent.timestamp) {
|
|
4263
|
+
mergedByOrderId.set(incomingEvent.orderId, incomingEvent);
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
return [...mergedByOrderId.values()].sort((left, right) => left.timestamp - right.timestamp);
|
|
4267
|
+
};
|
|
4268
|
+
var EXECUTION_STEP_STATUS_RANK = {
|
|
4269
|
+
pending: 0,
|
|
4270
|
+
in_progress: 1,
|
|
4271
|
+
failed: 2,
|
|
4272
|
+
completed: 3,
|
|
4273
|
+
skipped: 3
|
|
4274
|
+
};
|
|
4275
|
+
var getExecutionStepIdentity = (step) => [step.groupId, step.sequence, step.stepType, ...step.orderIds].join(":");
|
|
4276
|
+
var getExecutionGroupAttempt = (steps) => steps.reduce((highestAttempt, step) => Math.max(highestAttempt, step.attempt), 0);
|
|
4277
|
+
var groupExecutionStepsByGroupId = (steps) => {
|
|
4278
|
+
var _a;
|
|
4279
|
+
const groupedSteps = /* @__PURE__ */ new Map();
|
|
4280
|
+
for (const step of steps) {
|
|
4281
|
+
const existingSteps = (_a = groupedSteps.get(step.groupId)) != null ? _a : [];
|
|
4282
|
+
existingSteps.push(step);
|
|
4283
|
+
groupedSteps.set(step.groupId, existingSteps);
|
|
4284
|
+
}
|
|
4285
|
+
return groupedSteps;
|
|
4286
|
+
};
|
|
4287
|
+
var pickExecutionGroupPresentation = (step) => __spreadValues({
|
|
4288
|
+
groupStatus: step.groupStatus,
|
|
4289
|
+
label: step.label
|
|
4290
|
+
}, step.bridge ? { bridge: step.bridge } : {});
|
|
4291
|
+
var mergeExecutionStepProgress = (previous, incoming) => {
|
|
4292
|
+
var _a, _b;
|
|
4293
|
+
const previousByGroupId = groupExecutionStepsByGroupId(previous);
|
|
4294
|
+
const incomingByGroupId = groupExecutionStepsByGroupId(incoming);
|
|
4295
|
+
const mergedByIdentity = new Map(previous.map((step) => [getExecutionStepIdentity(step), step]));
|
|
4296
|
+
for (const step of incoming) {
|
|
4297
|
+
const identity = getExecutionStepIdentity(step);
|
|
4298
|
+
const current = mergedByIdentity.get(identity);
|
|
4299
|
+
if (!current || step.attempt > current.attempt) {
|
|
4300
|
+
mergedByIdentity.set(identity, step);
|
|
4301
|
+
continue;
|
|
4302
|
+
}
|
|
4303
|
+
if (step.attempt < current.attempt) continue;
|
|
4304
|
+
if (EXECUTION_STEP_STATUS_RANK[step.status] < EXECUTION_STEP_STATUS_RANK[current.status]) {
|
|
4305
|
+
continue;
|
|
4306
|
+
}
|
|
4307
|
+
mergedByIdentity.set(identity, step);
|
|
4308
|
+
}
|
|
4309
|
+
const groupPresentation = /* @__PURE__ */ new Map();
|
|
4310
|
+
const groupIds = /* @__PURE__ */ new Set([...previousByGroupId.keys(), ...incomingByGroupId.keys()]);
|
|
4311
|
+
for (const groupId of groupIds) {
|
|
4312
|
+
const previousGroup = (_a = previousByGroupId.get(groupId)) != null ? _a : [];
|
|
4313
|
+
const incomingGroup = (_b = incomingByGroupId.get(groupId)) != null ? _b : [];
|
|
4314
|
+
const previousStep = previousGroup[0];
|
|
4315
|
+
const incomingStep = incomingGroup[0];
|
|
4316
|
+
if (!previousStep && incomingStep) {
|
|
4317
|
+
groupPresentation.set(groupId, pickExecutionGroupPresentation(incomingStep));
|
|
4318
|
+
continue;
|
|
4319
|
+
}
|
|
4320
|
+
if (!incomingStep && previousStep) {
|
|
4321
|
+
groupPresentation.set(groupId, pickExecutionGroupPresentation(previousStep));
|
|
4322
|
+
continue;
|
|
4323
|
+
}
|
|
4324
|
+
if (!previousStep || !incomingStep) continue;
|
|
4325
|
+
const isNewerAttempt = getExecutionGroupAttempt(incomingGroup) > getExecutionGroupAttempt(previousGroup);
|
|
4326
|
+
const shouldUseIncoming = isNewerAttempt || EXECUTION_STEP_STATUS_RANK[incomingStep.groupStatus] >= EXECUTION_STEP_STATUS_RANK[previousStep.groupStatus];
|
|
4327
|
+
groupPresentation.set(
|
|
4328
|
+
groupId,
|
|
4329
|
+
pickExecutionGroupPresentation(shouldUseIncoming ? incomingStep : previousStep)
|
|
4330
|
+
);
|
|
4331
|
+
}
|
|
4332
|
+
return Array.from(mergedByIdentity.values()).map((step) => __spreadValues(__spreadValues({}, step), groupPresentation.get(step.groupId))).sort((left, right) => {
|
|
4333
|
+
if (left.sequence !== right.sequence) return left.sequence - right.sequence;
|
|
4334
|
+
return getExecutionStepIdentity(left).localeCompare(getExecutionStepIdentity(right));
|
|
4335
|
+
});
|
|
4336
|
+
};
|
|
4337
|
+
var mergeRawExecutionStepProgress = (previous, incoming) => {
|
|
4338
|
+
const mergedBySequence = new Map(previous.map((step) => [step.sequence, step]));
|
|
4339
|
+
for (const step of incoming) {
|
|
4340
|
+
const current = mergedBySequence.get(step.sequence);
|
|
4341
|
+
if (!current || step.attempt > current.attempt) {
|
|
4342
|
+
mergedBySequence.set(step.sequence, step);
|
|
4343
|
+
continue;
|
|
4344
|
+
}
|
|
4345
|
+
if (step.attempt < current.attempt) continue;
|
|
4346
|
+
if (EXECUTION_STEP_STATUS_RANK[step.status] < EXECUTION_STEP_STATUS_RANK[current.status]) {
|
|
4347
|
+
continue;
|
|
4348
|
+
}
|
|
4349
|
+
mergedBySequence.set(step.sequence, step);
|
|
4350
|
+
}
|
|
4351
|
+
return Array.from(mergedBySequence.values()).sort(
|
|
4352
|
+
(left, right) => left.sequence - right.sequence
|
|
4353
|
+
);
|
|
4354
|
+
};
|
|
4355
|
+
var mergeExecutionStatusOrders = (previous, incoming) => {
|
|
4356
|
+
const mergedByOrderId = new Map(previous.map((order) => [order.orderId, order]));
|
|
4357
|
+
for (const order of incoming) {
|
|
4358
|
+
const current = mergedByOrderId.get(order.orderId);
|
|
4359
|
+
if (!current || new Date(order.updatedAt).getTime() >= new Date(current.updatedAt).getTime()) {
|
|
4360
|
+
mergedByOrderId.set(order.orderId, order);
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4363
|
+
return Array.from(mergedByOrderId.values());
|
|
4364
|
+
};
|
|
4199
4365
|
function useExecutionProgress({
|
|
4200
4366
|
orderIds,
|
|
4201
4367
|
quoteId,
|
|
@@ -4207,6 +4373,9 @@ function useExecutionProgress({
|
|
|
4207
4373
|
const [latestBalance, setLatestBalance] = useState5(null);
|
|
4208
4374
|
const [dagProgress, setDagProgress] = useState5(null);
|
|
4209
4375
|
const [terminalOrderEvents, setTerminalOrderEvents] = useState5([]);
|
|
4376
|
+
const [executionSteps, setExecutionSteps] = useState5([]);
|
|
4377
|
+
const [rawExecutionSteps, setRawExecutionSteps] = useState5([]);
|
|
4378
|
+
const [executionOrders, setExecutionOrders] = useState5([]);
|
|
4210
4379
|
const orderIdSetRef = useRef5(/* @__PURE__ */ new Set());
|
|
4211
4380
|
const submittedOrderVenueByIdRef = useRef5(/* @__PURE__ */ new Map());
|
|
4212
4381
|
useEffect5(() => {
|
|
@@ -4219,9 +4388,21 @@ function useExecutionProgress({
|
|
|
4219
4388
|
setLatestBalance(null);
|
|
4220
4389
|
setDagProgress(null);
|
|
4221
4390
|
setTerminalOrderEvents([]);
|
|
4391
|
+
setExecutionSteps([]);
|
|
4392
|
+
setRawExecutionSteps([]);
|
|
4393
|
+
setExecutionOrders([]);
|
|
4222
4394
|
submittedOrderVenueByIdRef.current = /* @__PURE__ */ new Map();
|
|
4223
4395
|
} else if (!enabled) {
|
|
4224
4396
|
setPhase("idle");
|
|
4397
|
+
if (!orderIds || orderIds.length === 0) {
|
|
4398
|
+
setSubmittedOrders([]);
|
|
4399
|
+
setLatestBalance(null);
|
|
4400
|
+
setDagProgress(null);
|
|
4401
|
+
setTerminalOrderEvents([]);
|
|
4402
|
+
setExecutionSteps([]);
|
|
4403
|
+
setRawExecutionSteps([]);
|
|
4404
|
+
setExecutionOrders([]);
|
|
4405
|
+
}
|
|
4225
4406
|
submittedOrderVenueByIdRef.current = /* @__PURE__ */ new Map();
|
|
4226
4407
|
}
|
|
4227
4408
|
}, [enabled, orderIds]);
|
|
@@ -4273,13 +4454,7 @@ function useExecutionProgress({
|
|
|
4273
4454
|
errorReason: (_a = msg.errorReason) != null ? _a : fallbackErrorReason,
|
|
4274
4455
|
timestamp: msg.timestamp
|
|
4275
4456
|
};
|
|
4276
|
-
setTerminalOrderEvents((
|
|
4277
|
-
const nextEvents = [
|
|
4278
|
-
...prev.filter((terminalEvent) => terminalEvent.orderId !== msg.orderId),
|
|
4279
|
-
nextTerminalEvent
|
|
4280
|
-
];
|
|
4281
|
-
return nextEvents.sort((left, right) => left.timestamp - right.timestamp);
|
|
4282
|
-
});
|
|
4457
|
+
setTerminalOrderEvents((previous) => mergeTerminalOrderEvents(previous, [nextTerminalEvent]));
|
|
4283
4458
|
return;
|
|
4284
4459
|
}
|
|
4285
4460
|
if (event === "dag_started") {
|
|
@@ -4299,20 +4474,53 @@ function useExecutionProgress({
|
|
|
4299
4474
|
status: "running",
|
|
4300
4475
|
errorReason: null
|
|
4301
4476
|
});
|
|
4477
|
+
setRawExecutionSteps(
|
|
4478
|
+
(previous) => mergeRawExecutionStepProgress(
|
|
4479
|
+
previous,
|
|
4480
|
+
Object.entries(initialStepTypes).map(([sequence, stepType]) => ({
|
|
4481
|
+
sequence: Number(sequence),
|
|
4482
|
+
stepType,
|
|
4483
|
+
status: "pending",
|
|
4484
|
+
attempt: 0,
|
|
4485
|
+
startedAt: null,
|
|
4486
|
+
completedAt: null,
|
|
4487
|
+
errorReason: null
|
|
4488
|
+
}))
|
|
4489
|
+
)
|
|
4490
|
+
);
|
|
4302
4491
|
return;
|
|
4303
4492
|
}
|
|
4304
|
-
if (event === "step_started") {
|
|
4493
|
+
if (event === "step_started" || event === "step_retrying") {
|
|
4305
4494
|
setDagProgress((prev) => {
|
|
4306
4495
|
var _a2, _b2;
|
|
4307
4496
|
if (!prev) return prev;
|
|
4308
4497
|
const seq = (_a2 = msg.sequence) != null ? _a2 : prev.currentSequence;
|
|
4309
|
-
const
|
|
4498
|
+
const stepType2 = (_b2 = msg.stepType) != null ? _b2 : prev.currentStepType;
|
|
4310
4499
|
return __spreadProps(__spreadValues({}, prev), {
|
|
4311
4500
|
currentSequence: seq,
|
|
4312
|
-
currentStepType:
|
|
4313
|
-
stepTypes:
|
|
4501
|
+
currentStepType: stepType2,
|
|
4502
|
+
stepTypes: stepType2 != null ? __spreadProps(__spreadValues({}, prev.stepTypes), { [seq]: stepType2 }) : prev.stepTypes
|
|
4314
4503
|
});
|
|
4315
4504
|
});
|
|
4505
|
+
const { sequence, stepType } = msg;
|
|
4506
|
+
if (sequence != null && stepType) {
|
|
4507
|
+
setRawExecutionSteps(
|
|
4508
|
+
(previous) => {
|
|
4509
|
+
var _a2, _b2, _c2;
|
|
4510
|
+
return mergeRawExecutionStepProgress(previous, [
|
|
4511
|
+
{
|
|
4512
|
+
sequence,
|
|
4513
|
+
stepType,
|
|
4514
|
+
status: "in_progress",
|
|
4515
|
+
attempt: (_c2 = (_b2 = msg.attempt) != null ? _b2 : (_a2 = previous.find((step) => step.sequence === sequence)) == null ? void 0 : _a2.attempt) != null ? _c2 : 0,
|
|
4516
|
+
startedAt: new Date(msg.timestamp).toISOString(),
|
|
4517
|
+
completedAt: null,
|
|
4518
|
+
errorReason: null
|
|
4519
|
+
}
|
|
4520
|
+
]);
|
|
4521
|
+
}
|
|
4522
|
+
);
|
|
4523
|
+
}
|
|
4316
4524
|
return;
|
|
4317
4525
|
}
|
|
4318
4526
|
if (event === "step_waiting") {
|
|
@@ -4320,25 +4528,64 @@ function useExecutionProgress({
|
|
|
4320
4528
|
var _a2, _b2;
|
|
4321
4529
|
if (!prev) return prev;
|
|
4322
4530
|
const seq = (_a2 = msg.sequence) != null ? _a2 : prev.currentSequence;
|
|
4323
|
-
const
|
|
4531
|
+
const stepType2 = (_b2 = msg.stepType) != null ? _b2 : prev.currentStepType;
|
|
4324
4532
|
return __spreadProps(__spreadValues({}, prev), {
|
|
4325
4533
|
currentSequence: seq,
|
|
4326
|
-
currentStepType:
|
|
4327
|
-
stepTypes:
|
|
4534
|
+
currentStepType: stepType2,
|
|
4535
|
+
stepTypes: stepType2 != null ? __spreadProps(__spreadValues({}, prev.stepTypes), { [seq]: stepType2 }) : prev.stepTypes
|
|
4328
4536
|
});
|
|
4329
4537
|
});
|
|
4538
|
+
const { sequence, stepType } = msg;
|
|
4539
|
+
if (sequence != null && stepType) {
|
|
4540
|
+
setRawExecutionSteps(
|
|
4541
|
+
(previous) => {
|
|
4542
|
+
var _a2, _b2, _c2;
|
|
4543
|
+
return mergeRawExecutionStepProgress(previous, [
|
|
4544
|
+
{
|
|
4545
|
+
sequence,
|
|
4546
|
+
stepType,
|
|
4547
|
+
status: "in_progress",
|
|
4548
|
+
attempt: (_c2 = (_b2 = msg.attempt) != null ? _b2 : (_a2 = previous.find((step) => step.sequence === sequence)) == null ? void 0 : _a2.attempt) != null ? _c2 : 0,
|
|
4549
|
+
startedAt: new Date(msg.timestamp).toISOString(),
|
|
4550
|
+
completedAt: null,
|
|
4551
|
+
errorReason: null
|
|
4552
|
+
}
|
|
4553
|
+
]);
|
|
4554
|
+
}
|
|
4555
|
+
);
|
|
4556
|
+
}
|
|
4330
4557
|
return;
|
|
4331
4558
|
}
|
|
4332
4559
|
if (event === "step_completed") {
|
|
4333
4560
|
setDagProgress((prev) => {
|
|
4334
4561
|
if (!prev) return prev;
|
|
4335
4562
|
const seq = msg.sequence;
|
|
4336
|
-
const
|
|
4563
|
+
const stepType2 = msg.stepType;
|
|
4337
4564
|
return __spreadProps(__spreadValues({}, prev), {
|
|
4338
4565
|
completedSequences: seq != null ? [...prev.completedSequences, seq] : prev.completedSequences,
|
|
4339
|
-
stepTypes: seq != null &&
|
|
4566
|
+
stepTypes: seq != null && stepType2 != null ? __spreadProps(__spreadValues({}, prev.stepTypes), { [seq]: stepType2 }) : prev.stepTypes
|
|
4340
4567
|
});
|
|
4341
4568
|
});
|
|
4569
|
+
const { sequence, stepType } = msg;
|
|
4570
|
+
if (sequence != null && stepType) {
|
|
4571
|
+
const completedAt = new Date(msg.timestamp).toISOString();
|
|
4572
|
+
setRawExecutionSteps(
|
|
4573
|
+
(previous) => {
|
|
4574
|
+
var _a2, _b2, _c2;
|
|
4575
|
+
return mergeRawExecutionStepProgress(previous, [
|
|
4576
|
+
{
|
|
4577
|
+
sequence,
|
|
4578
|
+
stepType,
|
|
4579
|
+
status: "completed",
|
|
4580
|
+
attempt: (_c2 = (_b2 = msg.attempt) != null ? _b2 : (_a2 = previous.find((step) => step.sequence === sequence)) == null ? void 0 : _a2.attempt) != null ? _c2 : 0,
|
|
4581
|
+
startedAt: null,
|
|
4582
|
+
completedAt,
|
|
4583
|
+
errorReason: null
|
|
4584
|
+
}
|
|
4585
|
+
]);
|
|
4586
|
+
}
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4342
4589
|
return;
|
|
4343
4590
|
}
|
|
4344
4591
|
if (event === "dag_completed") {
|
|
@@ -4367,6 +4614,25 @@ function useExecutionProgress({
|
|
|
4367
4614
|
};
|
|
4368
4615
|
if (event === "step_failed") {
|
|
4369
4616
|
setDagProgress((prev) => buildFailedProgress(prev));
|
|
4617
|
+
const { sequence, stepType } = msg;
|
|
4618
|
+
if (sequence != null && stepType) {
|
|
4619
|
+
setRawExecutionSteps(
|
|
4620
|
+
(previous) => {
|
|
4621
|
+
var _a2, _b2, _c2, _d;
|
|
4622
|
+
return mergeRawExecutionStepProgress(previous, [
|
|
4623
|
+
{
|
|
4624
|
+
sequence,
|
|
4625
|
+
stepType,
|
|
4626
|
+
status: "failed",
|
|
4627
|
+
attempt: (_c2 = (_b2 = msg.attempt) != null ? _b2 : (_a2 = previous.find((step) => step.sequence === sequence)) == null ? void 0 : _a2.attempt) != null ? _c2 : 0,
|
|
4628
|
+
startedAt: null,
|
|
4629
|
+
completedAt: new Date(msg.timestamp).toISOString(),
|
|
4630
|
+
errorReason: (_d = msg.errorReason) != null ? _d : null
|
|
4631
|
+
}
|
|
4632
|
+
]);
|
|
4633
|
+
}
|
|
4634
|
+
);
|
|
4635
|
+
}
|
|
4370
4636
|
return;
|
|
4371
4637
|
}
|
|
4372
4638
|
if (event === "dag_failed") {
|
|
@@ -4375,7 +4641,7 @@ function useExecutionProgress({
|
|
|
4375
4641
|
}
|
|
4376
4642
|
}, []);
|
|
4377
4643
|
const isStatusPolling = enabled && !!quoteId;
|
|
4378
|
-
const isListening =
|
|
4644
|
+
const isListening = enabled && !!orderIds && orderIds.length > 0;
|
|
4379
4645
|
useOnOrderSubmitted(isListening ? handleOrderSubmitted : null);
|
|
4380
4646
|
useOnBalanceUpdate(isListening ? handleBalanceUpdate : null);
|
|
4381
4647
|
useOnOrderEvent(isListening ? handleOrderEvent : null);
|
|
@@ -4421,19 +4687,25 @@ function useExecutionProgress({
|
|
|
4421
4687
|
timestamp: new Date(order.updatedAt).getTime() || fallbackTimestamp
|
|
4422
4688
|
};
|
|
4423
4689
|
}).filter((order) => order != null);
|
|
4424
|
-
if (!status.terminal
|
|
4690
|
+
if (!status.terminal) {
|
|
4425
4691
|
return terminalEvents;
|
|
4426
4692
|
}
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4693
|
+
const coveredOrderIds = new Set(terminalEvents.map((event) => event.orderId));
|
|
4694
|
+
const fallbackEvent = status.overallState === "filled" ? "filled" : status.overallState === "partially_filled" ? "partial_fill" : ["failed", "cancelled", "expired"].includes(status.overallState) ? "failed" : null;
|
|
4695
|
+
if (!fallbackEvent) return terminalEvents;
|
|
4696
|
+
return [
|
|
4697
|
+
...terminalEvents,
|
|
4698
|
+
...fallbackOrderIds.filter((orderId) => !coveredOrderIds.has(orderId)).map((orderId) => {
|
|
4699
|
+
var _a;
|
|
4700
|
+
return {
|
|
4701
|
+
orderId,
|
|
4702
|
+
venue: "",
|
|
4703
|
+
event: fallbackEvent,
|
|
4704
|
+
errorReason: fallbackEvent === "failed" ? (_a = status.errorReason) != null ? _a : "Execution failed." : void 0,
|
|
4705
|
+
timestamp: fallbackTimestamp
|
|
4706
|
+
};
|
|
4707
|
+
})
|
|
4708
|
+
];
|
|
4437
4709
|
},
|
|
4438
4710
|
[]
|
|
4439
4711
|
);
|
|
@@ -4501,6 +4773,7 @@ function useExecutionProgress({
|
|
|
4501
4773
|
setPhase("order_submitted");
|
|
4502
4774
|
}
|
|
4503
4775
|
setSubmittedOrders(buildSubmittedOrdersFromStatus(status.orders));
|
|
4776
|
+
setExecutionOrders((previous) => mergeExecutionStatusOrders(previous, status.orders));
|
|
4504
4777
|
if (status.dagProgress) {
|
|
4505
4778
|
setDagProgress(__spreadProps(__spreadValues({}, status.dagProgress), {
|
|
4506
4779
|
stepTypes: Object.fromEntries(
|
|
@@ -4525,13 +4798,30 @@ function useExecutionProgress({
|
|
|
4525
4798
|
};
|
|
4526
4799
|
});
|
|
4527
4800
|
}
|
|
4801
|
+
setExecutionSteps((previous) => mergeExecutionStepProgress(previous, status.steps));
|
|
4802
|
+
setRawExecutionSteps(
|
|
4803
|
+
(previous) => mergeRawExecutionStepProgress(
|
|
4804
|
+
previous,
|
|
4805
|
+
status.steps.map((step) => ({
|
|
4806
|
+
sequence: step.sequence,
|
|
4807
|
+
stepType: step.stepType,
|
|
4808
|
+
status: step.status,
|
|
4809
|
+
attempt: step.attempt,
|
|
4810
|
+
startedAt: step.startedAt,
|
|
4811
|
+
completedAt: step.completedAt,
|
|
4812
|
+
errorReason: step.errorReason
|
|
4813
|
+
}))
|
|
4814
|
+
)
|
|
4815
|
+
);
|
|
4528
4816
|
const fallbackTimestamp = Date.now();
|
|
4529
4817
|
const nextTerminalEvents = buildTerminalEventsFromStatus(
|
|
4530
4818
|
status,
|
|
4531
4819
|
resolvedOrderIds,
|
|
4532
4820
|
fallbackTimestamp
|
|
4533
4821
|
);
|
|
4534
|
-
setTerminalOrderEvents(
|
|
4822
|
+
setTerminalOrderEvents(
|
|
4823
|
+
(previous) => mergeTerminalOrderEvents(previous, nextTerminalEvents)
|
|
4824
|
+
);
|
|
4535
4825
|
if (status.terminal) {
|
|
4536
4826
|
stopPolling();
|
|
4537
4827
|
return;
|
|
@@ -4626,17 +4916,7 @@ function useExecutionProgress({
|
|
|
4626
4916
|
});
|
|
4627
4917
|
}
|
|
4628
4918
|
if (terminalEvents.length > 0) {
|
|
4629
|
-
setTerminalOrderEvents((
|
|
4630
|
-
const nextById = /* @__PURE__ */ new Map();
|
|
4631
|
-
for (const ev of prev) nextById.set(ev.orderId, ev);
|
|
4632
|
-
for (const ev of terminalEvents) {
|
|
4633
|
-
const existing = nextById.get(ev.orderId);
|
|
4634
|
-
if (!existing || existing.timestamp < ev.timestamp) {
|
|
4635
|
-
nextById.set(ev.orderId, ev);
|
|
4636
|
-
}
|
|
4637
|
-
}
|
|
4638
|
-
return Array.from(nextById.values()).sort((l, r) => l.timestamp - r.timestamp);
|
|
4639
|
-
});
|
|
4919
|
+
setTerminalOrderEvents((previous) => mergeTerminalOrderEvents(previous, terminalEvents));
|
|
4640
4920
|
}
|
|
4641
4921
|
const covered = /* @__PURE__ */ new Set([
|
|
4642
4922
|
...terminalOrderIdsRef.current,
|
|
@@ -4658,7 +4938,16 @@ function useExecutionProgress({
|
|
|
4658
4938
|
stopPolling();
|
|
4659
4939
|
};
|
|
4660
4940
|
}, [client, isListening, isStatusPolling, mode, orderIds]);
|
|
4661
|
-
return {
|
|
4941
|
+
return {
|
|
4942
|
+
phase,
|
|
4943
|
+
submittedOrders,
|
|
4944
|
+
latestBalance,
|
|
4945
|
+
dagProgress,
|
|
4946
|
+
terminalOrderEvents,
|
|
4947
|
+
executionSteps,
|
|
4948
|
+
rawExecutionSteps,
|
|
4949
|
+
executionOrders
|
|
4950
|
+
};
|
|
4662
4951
|
}
|
|
4663
4952
|
|
|
4664
4953
|
// src/execution/use-balance-refill-policies.ts
|