@miramarket/cli 1.8.0 → 1.9.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.
Files changed (55) hide show
  1. package/README.md +1 -0
  2. package/dist/{chunk-UCB7XSQE.js → chunk-CUQEGUAG.js} +726 -264
  3. package/dist/{chunk-NKZGADKF.js → chunk-GVMZCXYH.js} +2 -2
  4. package/dist/commands/account/accept-policies.js +17 -17
  5. package/dist/commands/account/capital.js +7 -7
  6. package/dist/commands/account/policies.js +7 -7
  7. package/dist/commands/account/setup.js +10 -10
  8. package/dist/commands/account/status.js +5 -5
  9. package/dist/commands/account/withdraw.js +12 -12
  10. package/dist/commands/auth/status.js +7 -7
  11. package/dist/commands/balance.js +8 -8
  12. package/dist/commands/bridge/execute.js +9 -9
  13. package/dist/commands/bridge/quote.js +5 -5
  14. package/dist/commands/bridge/status.js +5 -5
  15. package/dist/commands/edit.js +5 -5
  16. package/dist/commands/init.js +22 -22
  17. package/dist/commands/login.js +7 -7
  18. package/dist/commands/logout.js +4 -4
  19. package/dist/commands/markets/list.js +5 -5
  20. package/dist/commands/markets/orderbook.js +5 -5
  21. package/dist/commands/markets/prices-history.js +6 -6
  22. package/dist/commands/markets/resolve.js +5 -5
  23. package/dist/commands/markets/search.js +5 -5
  24. package/dist/commands/markets/show.js +5 -5
  25. package/dist/commands/order/cancel.js +7 -7
  26. package/dist/commands/order/status.js +9 -9
  27. package/dist/commands/perps/history.js +5 -5
  28. package/dist/commands/perps/list.js +5 -5
  29. package/dist/commands/perps/positions.js +5 -5
  30. package/dist/commands/perps/show.js +5 -5
  31. package/dist/commands/portfolio.js +9 -9
  32. package/dist/commands/post.js +6 -6
  33. package/dist/commands/preview.js +5 -5
  34. package/dist/commands/schema.js +3 -3
  35. package/dist/commands/status.js +6 -6
  36. package/dist/commands/stocks/history.js +5 -5
  37. package/dist/commands/stocks/list.js +5 -5
  38. package/dist/commands/stocks/show.js +5 -5
  39. package/dist/commands/strategies/approval.js +5 -5
  40. package/dist/commands/strategies/cancel.js +6 -6
  41. package/dist/commands/strategies/delete.js +7 -7
  42. package/dist/commands/strategies/exit.js +7 -7
  43. package/dist/commands/strategies/generate.js +13 -13
  44. package/dist/commands/strategies/list.js +6 -6
  45. package/dist/commands/strategies/pull.js +5 -5
  46. package/dist/commands/strategies/rename.js +6 -6
  47. package/dist/commands/strategies/runs.js +7 -7
  48. package/dist/commands/strategies/show.js +22 -13
  49. package/dist/commands/strategies/update.js +7 -7
  50. package/dist/commands/strategies/watch.js +10 -8
  51. package/dist/commands/trade.js +49 -14
  52. package/dist/commands/update.js +8 -8
  53. package/dist/commands/validate.js +7 -7
  54. package/oclif.manifest.json +1 -1
  55. package/package.json +3 -3
@@ -603,7 +603,7 @@ var require_conditionalActionTypes = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
603
603
  "../../packages/shared/dist/strategy/conditionalActionTypes.js"(exports) {
604
604
  "use strict";
605
605
  Object.defineProperty(exports, "__esModule", { value: true });
606
- exports.isHyperliquidVenue = exports.isBaseStocksVenue = exports.STOCK_PRICE_SIGNAL = exports.PRICE_SIGNALS = exports.isUsdPricedVenueKey = exports.isHyperliquidVenueKey = exports.isBaseStocksVenueKey = exports.isConditionWatchableVenue = exports.normalizeVenueKey = exports.CONDITION_UNWATCHABLE_VENUES = void 0;
606
+ exports.LIMIT_PRICE_FROM_VALUES = exports.isHyperliquidVenue = exports.isBaseStocksVenue = exports.STOCK_PRICE_SIGNAL = exports.LIMIT_SIGNAL = exports.PRICE_SIGNALS = exports.isUsdPricedVenueKey = exports.isHyperliquidVenueKey = exports.isBaseStocksVenueKey = exports.isConditionWatchableVenue = exports.normalizeVenueKey = exports.CONDITION_UNWATCHABLE_VENUES = void 0;
607
607
  exports.CONDITION_UNWATCHABLE_VENUES = [];
608
608
  var normalizeVenueKey = (venue) => venue.trim().toUpperCase().replace(/[\s-]+/g, "_");
609
609
  exports.normalizeVenueKey = normalizeVenueKey;
@@ -615,12 +615,14 @@ var require_conditionalActionTypes = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
615
615
  exports.isHyperliquidVenueKey = isHyperliquidVenueKey;
616
616
  var isUsdPricedVenueKey = (venue) => (0, exports.isBaseStocksVenueKey)(venue) || (0, exports.isHyperliquidVenueKey)(venue);
617
617
  exports.isUsdPricedVenueKey = isUsdPricedVenueKey;
618
- exports.PRICE_SIGNALS = ["IMPLIED_PROBABILITY", "PRICE_USD", "ROI_PCT", "PNL_USD"];
618
+ exports.PRICE_SIGNALS = ["IMPLIED_PROBABILITY", "PRICE_USD", "ROI_PCT", "PNL_USD", "LIMIT_PRICE"];
619
+ exports.LIMIT_SIGNAL = "LIMIT_PRICE";
619
620
  exports.STOCK_PRICE_SIGNAL = "PRICE_USD";
620
621
  var isBaseStocksVenue = (venue) => typeof venue === "string" && (0, exports.normalizeVenueKey)(venue) === "BASE_STOCKS";
621
622
  exports.isBaseStocksVenue = isBaseStocksVenue;
622
623
  var isHyperliquidVenue = (venue) => typeof venue === "string" && (0, exports.normalizeVenueKey)(venue) === "HYPERLIQUID";
623
624
  exports.isHyperliquidVenue = isHyperliquidVenue;
625
+ exports.LIMIT_PRICE_FROM_VALUES = ["BEST_BID", "BEST_ASK"];
624
626
  }
625
627
  });
626
628
 
@@ -1068,11 +1070,10 @@ var require_oracle = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
1068
1070
  return { symbol: token.symbol, address: token.address, error: "No price feed mapped for this token" };
1069
1071
  }
1070
1072
  try {
1071
- const [roundData, feedDecimals, multiplierWad, wadPrecision] = await Promise.all([
1073
+ const [roundData, feedDecimals, multiplierWad] = await Promise.all([
1072
1074
  client.readContract({ address: feedAddress, abi: exports.AGGREGATOR_V3_ABI, functionName: "latestRoundData" }),
1073
1075
  client.readContract({ address: feedAddress, abi: exports.AGGREGATOR_V3_ABI, functionName: "decimals" }),
1074
- client.readContract({ address: token.address, abi: exports.B20_ASSET_ABI, functionName: "multiplier" }),
1075
- client.readContract({ address: token.address, abi: exports.B20_ASSET_ABI, functionName: "WAD_PRECISION" })
1076
+ client.readContract({ address: token.address, abi: exports.B20_ASSET_ABI, functionName: "multiplier" })
1076
1077
  ]);
1077
1078
  const answer = roundData[1];
1078
1079
  const updatedAt = Number(roundData[3]);
@@ -1086,8 +1087,9 @@ var require_oracle = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
1086
1087
  error: `Feed reported a non-positive answer (${answer.toString()})`
1087
1088
  };
1088
1089
  }
1089
- const equityPriceUsd = Number(answer) / 10 ** Number(feedDecimals);
1090
- const priceUsd = (0, exports.applyMultiplier)(equityPriceUsd, multiplierWad, wadPrecision);
1090
+ const feedPriceUsd = Number(answer) / 10 ** Number(feedDecimals);
1091
+ const equityPriceUsd = feedPriceUsd;
1092
+ const priceUsd = feedPriceUsd;
1091
1093
  return {
1092
1094
  symbol: token.symbol,
1093
1095
  address: token.address,
@@ -1664,18 +1666,19 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
1664
1666
  "../../packages/shared/dist/strategy/validateConditionalAction.js"(exports) {
1665
1667
  "use strict";
1666
1668
  Object.defineProperty(exports, "__esModule", { value: true });
1667
- exports.validateConditionalActionStrategy = exports.roiPositionBuy = exports.assertConditionalActionShape = exports.conditionVenueUnwatchableMessage = exports.tokenIdOutcomeMessage = exports.isTokenIdOutcome = exports.roiThresholdMessage = exports.roiWatchMismatchMessage = exports.roiNoPositionMessage = exports.perpOutcomeMessage = exports.unknownPerpIdMessage = exports.stockConditionSignalMessage = exports.unknownStockWatchMessage = exports.MAX_PERP_LEVERAGE = exports.MIN_PERP_LEVERAGE = void 0;
1669
+ exports.validateConditionalActionStrategy = exports.MIN_LIMIT_EXPIRY_SECONDS = exports.roiPositionBuy = exports.assertConditionalActionShape = exports.conditionVenueUnwatchableMessage = exports.tokenIdOutcomeMessage = exports.isTokenIdOutcome = exports.roiThresholdMessage = exports.roiWatchMismatchMessage = exports.roiNoPositionMessage = exports.perpOutcomeMessage = exports.unknownPerpIdMessage = exports.stockConditionSignalMessage = exports.unknownStockWatchMessage = exports.MAX_PERP_LEVERAGE = exports.MIN_PERP_LEVERAGE = void 0;
1668
1670
  exports.buildSemanticGraph = buildSemanticGraph;
1669
1671
  exports.validateGraphTopology = validateGraphTopology;
1670
- var serverSupported_1 = require_serverSupported();
1671
1672
  var conditionalActionTypes_1 = require_conditionalActionTypes();
1673
+ var serverSupported_1 = require_serverSupported();
1674
+ var conditionalActionTypes_2 = require_conditionalActionTypes();
1672
1675
  var basestocks_1 = require_basestocks();
1673
1676
  var ids_1 = require_ids();
1674
1677
  exports.MIN_PERP_LEVERAGE = 1;
1675
1678
  exports.MAX_PERP_LEVERAGE = 50;
1676
1679
  var unknownStockWatchMessage = (nodeId, where, tokenId) => `Condition ${nodeId} ${where} watches ${tokenId}, which is not a tokenized stock this app supports. Use a token address from \`miramarket-cli stocks list\`.`;
1677
1680
  exports.unknownStockWatchMessage = unknownStockWatchMessage;
1678
- var stockConditionSignalMessage = (nodeId, where, signal, venue) => (0, conditionalActionTypes_1.isBaseStocksVenueKey)(venue) ? `Condition ${nodeId} ${where} watches a tokenized stock (${venue}) with signal ${signal}, but a stock is priced in dollars per share: use signal PRICE_USD with the threshold in dollars (e.g. 412.5 for $412.50).` : (0, conditionalActionTypes_1.isHyperliquidVenueKey)(venue) ? `Condition ${nodeId} ${where} watches a Hyperliquid perp (${venue}) with signal ${signal}, but a perp is priced in dollars: use signal PRICE_USD with the threshold in dollars (e.g. 82000 for $82,000).` : `Condition ${nodeId} ${where} uses signal PRICE_USD on venue ${venue}, but PRICE_USD is only valid when watching a BASE_STOCKS token or a HYPERLIQUID perp. Use IMPLIED_PROBABILITY (0-1) for a prediction market.`;
1681
+ var stockConditionSignalMessage = (nodeId, where, signal, venue) => (0, conditionalActionTypes_2.isBaseStocksVenueKey)(venue) ? `Condition ${nodeId} ${where} watches a tokenized stock (${venue}) with signal ${signal}, but a stock is priced in dollars per share: use signal PRICE_USD with the threshold in dollars (e.g. 412.5 for $412.50).` : (0, conditionalActionTypes_2.isHyperliquidVenueKey)(venue) ? `Condition ${nodeId} ${where} watches a Hyperliquid perp (${venue}) with signal ${signal}, but a perp is priced in dollars: use signal PRICE_USD with the threshold in dollars (e.g. 82000 for $82,000).` : `Condition ${nodeId} ${where} uses signal PRICE_USD on venue ${venue}, but PRICE_USD is only valid when watching a BASE_STOCKS token or a HYPERLIQUID perp. Use IMPLIED_PROBABILITY (0-1) for a prediction market.`;
1679
1682
  exports.stockConditionSignalMessage = stockConditionSignalMessage;
1680
1683
  var unknownPerpIdMessage = (nodeId, where, id) => `${where} ${nodeId} names ${id}, which is not a Hyperliquid perp id. Use the form hl:<COIN>, e.g. hl:BTC or hl:ETH, or hl:<dex>:<COIN> for a HIP-3 perp, e.g. hl:xyz:NVDA.`;
1681
1684
  exports.unknownPerpIdMessage = unknownPerpIdMessage;
@@ -1838,11 +1841,11 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
1838
1841
  }
1839
1842
  }
1840
1843
  const venue = _optionalChain([conjunct, 'access', _80 => _80.watch, 'optionalAccess', _81 => _81.venue]);
1841
- const isStock = (0, conditionalActionTypes_1.isBaseStocksVenueKey)(venue);
1842
- const isPerp = (0, conditionalActionTypes_1.isHyperliquidVenueKey)(venue);
1844
+ const isStock = (0, conditionalActionTypes_2.isBaseStocksVenueKey)(venue);
1845
+ const isPerp = (0, conditionalActionTypes_2.isHyperliquidVenueKey)(venue);
1843
1846
  const isUsdPriced = isStock || isPerp;
1844
1847
  const isPriceSignal = signal !== "TIME_SINCE_GROUP_SECONDS" && signal !== "TIME_TO_RESOLUTION_SECONDS";
1845
- if (isUsdPriced && isPriceSignal && signal !== "PRICE_USD" && signal !== "ROI_PCT") {
1848
+ if (isUsdPriced && isPriceSignal && signal !== "PRICE_USD" && signal !== "ROI_PCT" && signal !== "LIMIT_PRICE") {
1846
1849
  errors.push((0, exports.stockConditionSignalMessage)(nodeId, label, signal, _nullishCoalesce(venue, () => ( "BASE_STOCKS"))));
1847
1850
  } else if (!isUsdPriced && signal === "PRICE_USD") {
1848
1851
  errors.push((0, exports.stockConditionSignalMessage)(nodeId, label, signal, _nullishCoalesce(venue, () => ( "unknown"))));
@@ -1917,6 +1920,123 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
1917
1920
  errors.push((0, exports.roiWatchMismatchMessage)(node.node_id, buy.node_id));
1918
1921
  }
1919
1922
  };
1923
+ exports.MIN_LIMIT_EXPIRY_SECONDS = 60;
1924
+ var LIMIT_TRADE_ACTIONS = /* @__PURE__ */ new Set(["BUY_MARKET_OUTCOME", "SELL_MARKET_OUTCOME", "MOVE_TO_WALLET"]);
1925
+ var validateLimitCondition = (strategy, node, nodeMap, errors) => {
1926
+ const condition = node.condition;
1927
+ if (_optionalChain([condition, 'optionalAccess', _106 => _106.signal]) !== "LIMIT_PRICE")
1928
+ return;
1929
+ const id = node.node_id;
1930
+ const venue = _optionalChain([condition, 'access', _107 => _107.watch, 'optionalAccess', _108 => _108.venue]);
1931
+ const limitVenue = venue === void 0 ? "POLYMARKET" : normalizeLimitVenue(venue);
1932
+ if (limitVenue !== "POLYMARKET" && limitVenue !== "HYPERLIQUID") {
1933
+ errors.push(`Condition ${id} uses LIMIT_PRICE on venue "${venue}". Limit conditions rest an order on the venue's book and are supported on POLYMARKET and HYPERLIQUID only; use a price condition there instead.`);
1934
+ return;
1935
+ }
1936
+ const isPerpLimit = limitVenue === "HYPERLIQUID";
1937
+ const price = condition.threshold;
1938
+ const priceFrom = _optionalChain([condition, 'access', _109 => _109.limit, 'optionalAccess', _110 => _110.price_from]);
1939
+ if (isPerpLimit) {
1940
+ if (priceFrom !== void 0) {
1941
+ errors.push(`Condition ${id} sets limit.price_from on a Hyperliquid perp. A perp limit needs an explicit price: set threshold to the USD price per coin (e.g. 82000 for $82,000) and drop limit.price_from.`);
1942
+ } else if (!(typeof price === "number" && Number.isFinite(price) && price > 0)) {
1943
+ errors.push(`Condition ${id} LIMIT_PRICE threshold on a Hyperliquid perp must be an explicit positive USD price per coin (e.g. 82000 for $82,000).`);
1944
+ }
1945
+ } else if (priceFrom !== void 0) {
1946
+ if (!conditionalActionTypes_1.LIMIT_PRICE_FROM_VALUES.includes(priceFrom)) {
1947
+ errors.push(`Condition ${id} limit.price_from must be "BEST_BID" or "BEST_ASK"; omit it to place the order at threshold.`);
1948
+ }
1949
+ if (price !== 0) {
1950
+ errors.push(`Condition ${id} sets limit.price_from, which takes the order's price from the book when the order is placed. Set threshold to 0, or drop limit.price_from to place the order at threshold.`);
1951
+ }
1952
+ } else if (!(typeof price === "number" && Number.isFinite(price) && price > 0 && price < 1)) {
1953
+ errors.push(`Condition ${id} LIMIT_PRICE threshold must be the order price as a fraction between 0 and 1 (0.42 is 42c).`);
1954
+ }
1955
+ if ((_nullishCoalesce(condition.conjuncts, () => ( []))).length > 0) {
1956
+ errors.push(`Condition ${id} uses LIMIT_PRICE with AND clauses. A Limit condition is one resting order and takes no other clause.`);
1957
+ }
1958
+ const expiry = _optionalChain([condition, 'access', _111 => _111.limit, 'optionalAccess', _112 => _112.expires_after_seconds]);
1959
+ if (expiry !== void 0 && !(typeof expiry === "number" && Number.isFinite(expiry) && expiry >= exports.MIN_LIMIT_EXPIRY_SECONDS)) {
1960
+ errors.push(`Condition ${id} limit.expires_after_seconds must be at least ${exports.MIN_LIMIT_EXPIRY_SECONDS} seconds; omit it to rest the order until it fills.`);
1961
+ }
1962
+ const dayEnd = _optionalChain([condition, 'access', _113 => _113.limit, 'optionalAccess', _114 => _114.expires_at_day_end]);
1963
+ if (dayEnd !== void 0 && typeof dayEnd !== "boolean") {
1964
+ errors.push(`Condition ${id} limit.expires_at_day_end must be true or false.`);
1965
+ }
1966
+ if (dayEnd === true && expiry !== void 0) {
1967
+ errors.push(`Condition ${id} sets both limit.expires_at_day_end and limit.expires_after_seconds. Use one: the next 12am Pacific Time, or a number of seconds.`);
1968
+ }
1969
+ const group = strategy.decision_groups.find((g) => g.condition_node_id === id);
1970
+ const actionIds = _nullishCoalesce(_optionalChain([group, 'optionalAccess', _115 => _115.action_node_ids]), () => ( []));
1971
+ if (actionIds.length !== 1) {
1972
+ errors.push(`Condition ${id} uses LIMIT_PRICE and must hold exactly one buy or sell action; it has ${actionIds.length}. Use one Limit condition per order.`);
1973
+ return;
1974
+ }
1975
+ const action = nodeMap.get(actionIds[0]);
1976
+ const actionType = _optionalChain([action, 'optionalAccess', _116 => _116.action, 'optionalAccess', _117 => _117.action_type]);
1977
+ if (!action || !actionType || !LIMIT_TRADE_ACTIONS.has(actionType)) {
1978
+ errors.push(`Condition ${id} uses LIMIT_PRICE over ${actionIds[0]} (${_nullishCoalesce(actionType, () => ( "missing"))}). A Limit condition holds a BUY_MARKET_OUTCOME, a SELL_MARKET_OUTCOME or a MOVE_TO_WALLET exit.`);
1979
+ return;
1980
+ }
1981
+ const isEntryBuy = node.level === 0;
1982
+ if (isEntryBuy && !isPerpLimit && actionType === "BUY_MARKET_OUTCOME" && priceFrom === void 0 && price > 0 && price < 1) {
1983
+ const pct = Number(_nullishCoalesce(_optionalChain([action, 'access', _118 => _118.action, 'optionalAccess', _119 => _119.allocation_pct]), () => ( 100)));
1984
+ const budget = (_nullishCoalesce(strategy.initial_principal_usd, () => ( 0))) * (pct / 100);
1985
+ const feeRate = 0.07 * (1 - price) + 1e-3;
1986
+ const shares = Math.floor(budget / (price * (1 + feeRate)) * 100) / 100;
1987
+ if (budget > 0 && shares < 5) {
1988
+ const needed = Math.ceil(5 * price * (1 + feeRate) / (pct / 100) * 100) / 100;
1989
+ errors.push(`Condition ${id} buys with $${budget.toFixed(2)} at ${price}, which is ${shares} shares - below the venue's 5-share minimum. Raise initial_principal_usd to at least $${needed.toFixed(2)}, or place the order at a lower price.`);
1990
+ }
1991
+ }
1992
+ const watched = _optionalChain([condition, 'access', _120 => _120.watch, 'optionalAccess', _121 => _121.token_id]);
1993
+ const position = (0, exports.roiPositionBuy)(strategy, id, nodeMap);
1994
+ const traded = actionType === "BUY_MARKET_OUTCOME" ? action : position;
1995
+ const tradedVenueRaw = _optionalChain([traded, 'optionalAccess', _122 => _122.action, 'optionalAccess', _123 => _123.target, 'optionalAccess', _124 => _124.venue]);
1996
+ const tradedVenue = tradedVenueRaw === void 0 ? "POLYMARKET" : normalizeLimitVenue(tradedVenueRaw);
1997
+ if (traded && tradedVenue !== limitVenue) {
1998
+ errors.push(`Condition ${id} is a Limit order priced on ${limitVenue} for a trade on ${tradedVenue} (${traded.node_id}). Set watch.venue to ${tradedVenue}: the threshold is read on that venue's scale (0-1 on POLYMARKET, USD per coin on HYPERLIQUID).`);
1999
+ }
2000
+ if (actionType === "BUY_MARKET_OUTCOME") {
2001
+ if (condition.trigger !== "CROSS_BELOW") {
2002
+ errors.push(`Condition ${id} is a Limit buy and must use trigger CROSS_BELOW (buy at this price or lower).`);
2003
+ }
2004
+ const bought = _optionalChain([action, 'access', _125 => _125.action, 'optionalAccess', _126 => _126.target, 'optionalAccess', _127 => _127.market, 'optionalAccess', _128 => _128.token_id]);
2005
+ if (watched && bought && !sameId(watched, bought)) {
2006
+ errors.push(`Condition ${id} is a Limit buy but watches a different token than ${action.node_id} buys. Set watch to that action's venue, market_id, outcome_token and token_id.`);
2007
+ }
2008
+ if (position) {
2009
+ errors.push(`Condition ${id} is a Limit buy chained under the position of ${position.node_id}. A resting buy needs cash: put it at the root, under a cash HOLD, or after a sell.`);
2010
+ }
2011
+ } else {
2012
+ if (condition.trigger !== "CROSS_ABOVE") {
2013
+ errors.push(`Condition ${id} is a Limit sell and must use trigger CROSS_ABOVE (sell at this price or higher).`);
2014
+ }
2015
+ if (!position) {
2016
+ errors.push(`Condition ${id} is a Limit sell with no position to sell. Chain it under the BUY_MARKET_OUTCOME whose position it sells (directly, or under a HOLD of that position).`);
2017
+ } else {
2018
+ const held = _optionalChain([position, 'access', _129 => _129.action, 'optionalAccess', _130 => _130.target, 'optionalAccess', _131 => _131.market, 'optionalAccess', _132 => _132.token_id]);
2019
+ if (watched && held && !sameId(watched, held)) {
2020
+ errors.push(`Condition ${id} is a Limit sell but does not watch the position above it (${position.node_id}). Set watch to the same venue, market_id, outcome_token and token_id.`);
2021
+ }
2022
+ const sold = actionType === "SELL_MARKET_OUTCOME" ? _optionalChain([action, 'access', _133 => _133.action, 'optionalAccess', _134 => _134.target, 'optionalAccess', _135 => _135.market, 'optionalAccess', _136 => _136.token_id]) : void 0;
2023
+ if (sold && held && !sameId(sold, held)) {
2024
+ errors.push(`Condition ${id} is a Limit sell but ${action.node_id} sells a different token than the position above it (${position.node_id}).`);
2025
+ }
2026
+ }
2027
+ if (_optionalChain([action, 'access', _137 => _137.action, 'optionalAccess', _138 => _138.whole_position]) === true) {
2028
+ errors.push(`Condition ${id} is a Limit sell over ${action.node_id}, which sets whole_position. A resting sell covers the one lot it is chained under; remove whole_position.`);
2029
+ }
2030
+ }
2031
+ const parentEdge = strategy.edges.find((e) => e.to_node_id === id);
2032
+ if (parentEdge) {
2033
+ const limitSiblings = strategy.edges.filter((e) => e.from_node_id === parentEdge.from_node_id).map((e) => nodeMap.get(e.to_node_id)).filter((n) => _optionalChain([n, 'optionalAccess', _139 => _139.condition, 'optionalAccess', _140 => _140.signal]) === "LIMIT_PRICE");
2034
+ if (limitSiblings.length > 1 && limitSiblings[0].node_id !== id) {
2035
+ errors.push(`Condition ${id} is a second Limit condition under ${parentEdge.from_node_id} (after ${limitSiblings[0].node_id}). Conditions under one action are alternatives and only one order can rest on what it holds; chain the second under the first's action instead.`);
2036
+ }
2037
+ }
2038
+ };
2039
+ var normalizeLimitVenue = (venue) => venue.trim().toUpperCase().replace(/[\s-]+/g, "_");
1920
2040
  var validateDecisionGroup = (group, nodeMap, errors) => {
1921
2041
  const conditionNode = nodeMap.get(group.condition_node_id);
1922
2042
  if (!conditionNode) {
@@ -1947,7 +2067,7 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
1947
2067
  errors.push(`Decision group ${group.group_id} action node ${actionNodeId} has wrong level.`);
1948
2068
  }
1949
2069
  if (group.mode === "SPLIT_100") {
1950
- const allocationPct = _optionalChain([actionNode, 'access', _106 => _106.action, 'optionalAccess', _107 => _107.allocation_pct]);
2070
+ const allocationPct = _optionalChain([actionNode, 'access', _141 => _141.action, 'optionalAccess', _142 => _142.allocation_pct]);
1951
2071
  if (typeof allocationPct !== "number") {
1952
2072
  errors.push(`Decision group ${group.group_id} requires allocation_pct on ${actionNodeId}.`);
1953
2073
  } else {
@@ -1955,7 +2075,7 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
1955
2075
  }
1956
2076
  }
1957
2077
  if (group.mode === "SINGLE" && group.action_node_ids.length === 1) {
1958
- const allocationPct = _optionalChain([actionNode, 'access', _108 => _108.action, 'optionalAccess', _109 => _109.allocation_pct]);
2078
+ const allocationPct = _optionalChain([actionNode, 'access', _143 => _143.action, 'optionalAccess', _144 => _144.allocation_pct]);
1959
2079
  if (typeof allocationPct === "number" && !approxEqual(allocationPct, 100)) {
1960
2080
  errors.push(`Decision group ${group.group_id} is SINGLE mode (winner-takes-all) but ${actionNodeId} has allocation_pct ${allocationPct}, not 100 -- a SINGLE-mode action always receives the full capital handed to it, so anything less strands the remainder with nothing left to watch it.`);
1961
2081
  }
@@ -2029,8 +2149,9 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2029
2149
  if (node.type === "CONDITION" && node.condition) {
2030
2150
  validateSingleConjunct(node.node_id, node.condition, errors, "base condition");
2031
2151
  validateRoiCondition(strategy, node, nodeMap, errors);
2032
- const watchVenue = _optionalChain([node, 'access', _110 => _110.condition, 'access', _111 => _111.watch, 'optionalAccess', _112 => _112.venue]);
2033
- if (watchVenue && !(0, conditionalActionTypes_1.isConditionWatchableVenue)(watchVenue)) {
2152
+ validateLimitCondition(strategy, node, nodeMap, errors);
2153
+ const watchVenue = _optionalChain([node, 'access', _145 => _145.condition, 'access', _146 => _146.watch, 'optionalAccess', _147 => _147.venue]);
2154
+ if (watchVenue && !(0, conditionalActionTypes_2.isConditionWatchableVenue)(watchVenue)) {
2034
2155
  errors.push((0, exports.conditionVenueUnwatchableMessage)(node.node_id, watchVenue, "base condition"));
2035
2156
  } else if (watchVenue && !serverSupported_1.EXECUTABLE_VENUES_SET.has(watchVenue)) {
2036
2157
  errors.push(`Condition ${node.node_id} uses venue "${watchVenue}" which is not supported by the server. Supported: ${[...serverSupported_1.EXECUTABLE_VENUES_SET].join(", ")}.`);
@@ -2039,8 +2160,8 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2039
2160
  const seen = /* @__PURE__ */ new Set([conjunctKey(node.condition)]);
2040
2161
  conjuncts.forEach((conjunct, index) => {
2041
2162
  validateSingleConjunct(node.node_id, conjunct, errors, `AND clause #${index + 1}`);
2042
- const conjunctVenue = _optionalChain([conjunct, 'access', _113 => _113.watch, 'optionalAccess', _114 => _114.venue]);
2043
- if (conjunctVenue && !(0, conditionalActionTypes_1.isConditionWatchableVenue)(conjunctVenue)) {
2163
+ const conjunctVenue = _optionalChain([conjunct, 'access', _148 => _148.watch, 'optionalAccess', _149 => _149.venue]);
2164
+ if (conjunctVenue && !(0, conditionalActionTypes_2.isConditionWatchableVenue)(conjunctVenue)) {
2044
2165
  errors.push((0, exports.conditionVenueUnwatchableMessage)(node.node_id, conjunctVenue, `AND clause #${index + 1}`));
2045
2166
  } else if (conjunctVenue && !serverSupported_1.EXECUTABLE_VENUES_SET.has(conjunctVenue)) {
2046
2167
  errors.push(`Condition ${node.node_id} AND clause #${index + 1} uses venue "${conjunctVenue}" which is not supported by the server. Supported: ${[...serverSupported_1.EXECUTABLE_VENUES_SET].join(", ")}.`);
@@ -2054,22 +2175,22 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2054
2175
  });
2055
2176
  }
2056
2177
  if (isActionNode(node)) {
2057
- const actionType = _optionalChain([node, 'access', _115 => _115.action, 'optionalAccess', _116 => _116.action_type]);
2178
+ const actionType = _optionalChain([node, 'access', _150 => _150.action, 'optionalAccess', _151 => _151.action_type]);
2058
2179
  if (actionType !== void 0 && !serverSupported_1.EXECUTABLE_ACTION_TYPES_SET.has(actionType)) {
2059
2180
  errors.push(`Action ${node.node_id} has unknown action_type "${actionType}" which is not executable on the server. Supported: ${[...serverSupported_1.EXECUTABLE_ACTION_TYPES_SET].join(", ")}.`);
2060
2181
  }
2061
- const targetVenue = _optionalChain([node, 'access', _117 => _117.action, 'optionalAccess', _118 => _118.target, 'optionalAccess', _119 => _119.venue]);
2182
+ const targetVenue = _optionalChain([node, 'access', _152 => _152.action, 'optionalAccess', _153 => _153.target, 'optionalAccess', _154 => _154.venue]);
2062
2183
  if (targetVenue && !serverSupported_1.EXECUTABLE_VENUES_SET.has(targetVenue)) {
2063
2184
  errors.push(`Action ${node.node_id} uses venue "${targetVenue}" which is not supported by the server. Supported: ${[...serverSupported_1.EXECUTABLE_VENUES_SET].join(", ")}.`);
2064
2185
  }
2065
- if (actionType === "BUY_MARKET_OUTCOME" || actionType === "SELL_MARKET_OUTCOME" || actionType === "HOLD" && _optionalChain([node, 'access', _120 => _120.action, 'optionalAccess', _121 => _121.target, 'optionalAccess', _122 => _122.market]) !== void 0) {
2066
- const tokenId = _optionalChain([node, 'access', _123 => _123.action, 'optionalAccess', _124 => _124.target, 'optionalAccess', _125 => _125.market, 'optionalAccess', _126 => _126.token_id]);
2186
+ if (actionType === "BUY_MARKET_OUTCOME" || actionType === "SELL_MARKET_OUTCOME" || actionType === "HOLD" && _optionalChain([node, 'access', _155 => _155.action, 'optionalAccess', _156 => _156.target, 'optionalAccess', _157 => _157.market]) !== void 0) {
2187
+ const tokenId = _optionalChain([node, 'access', _158 => _158.action, 'optionalAccess', _159 => _159.target, 'optionalAccess', _160 => _160.market, 'optionalAccess', _161 => _161.token_id]);
2067
2188
  if (typeof tokenId !== "string" || tokenId.trim().length === 0) {
2068
2189
  errors.push(`Action ${node.node_id} requires target.market.token_id.`);
2069
2190
  }
2070
2191
  }
2071
- const targetIsPerp = (0, conditionalActionTypes_1.isHyperliquidVenueKey)(targetVenue);
2072
- const targetMarket = _optionalChain([node, 'access', _127 => _127.action, 'optionalAccess', _128 => _128.target, 'optionalAccess', _129 => _129.market]);
2192
+ const targetIsPerp = (0, conditionalActionTypes_2.isHyperliquidVenueKey)(targetVenue);
2193
+ const targetMarket = _optionalChain([node, 'access', _162 => _162.action, 'optionalAccess', _163 => _163.target, 'optionalAccess', _164 => _164.market]);
2073
2194
  if (targetIsPerp && targetMarket) {
2074
2195
  const marketId = targetMarket.market_id;
2075
2196
  if (typeof marketId === "string" && marketId !== "" && !(0, ids_1.parsePerpTokenId)(marketId)) {
@@ -2086,7 +2207,7 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2086
2207
  } else if (targetMarket && (0, exports.isTokenIdOutcome)(targetMarket.outcome_token)) {
2087
2208
  errors.push((0, exports.tokenIdOutcomeMessage)(node.node_id, "Action"));
2088
2209
  }
2089
- const leverage = _optionalChain([node, 'access', _130 => _130.action, 'optionalAccess', _131 => _131.target, 'optionalAccess', _132 => _132.leverage]);
2210
+ const leverage = _optionalChain([node, 'access', _165 => _165.action, 'optionalAccess', _166 => _166.target, 'optionalAccess', _167 => _167.leverage]);
2090
2211
  if (leverage !== void 0) {
2091
2212
  if (!targetIsPerp) {
2092
2213
  errors.push(`Action ${node.node_id} sets leverage, which only a HYPERLIQUID target accepts.`);
@@ -2094,11 +2215,11 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2094
2215
  errors.push(`Action ${node.node_id} has leverage ${leverage}; it must be an integer from ${exports.MIN_PERP_LEVERAGE} to ${exports.MAX_PERP_LEVERAGE}.`);
2095
2216
  }
2096
2217
  }
2097
- const wholePosition = _optionalChain([node, 'access', _133 => _133.action, 'optionalAccess', _134 => _134.whole_position]);
2218
+ const wholePosition = _optionalChain([node, 'access', _168 => _168.action, 'optionalAccess', _169 => _169.whole_position]);
2098
2219
  if (wholePosition !== void 0) {
2099
2220
  if (typeof wholePosition !== "boolean") {
2100
2221
  errors.push(`Action ${node.node_id} has whole_position ${JSON.stringify(wholePosition)}; it must be true or false.`);
2101
- } else if (wholePosition && _optionalChain([node, 'access', _135 => _135.action, 'optionalAccess', _136 => _136.action_type]) !== "MOVE_TO_WALLET") {
2222
+ } else if (wholePosition && _optionalChain([node, 'access', _170 => _170.action, 'optionalAccess', _171 => _171.action_type]) !== "MOVE_TO_WALLET") {
2102
2223
  errors.push(`Action ${node.node_id} sets whole_position, which only a MOVE_TO_WALLET exit accepts.`);
2103
2224
  }
2104
2225
  }
@@ -2165,6 +2286,38 @@ var require_validateConditionalAction = _chunkQGM4M3NIjs.__commonJS.call(void 0,
2165
2286
  }
2166
2287
  });
2167
2288
 
2289
+ // ../../packages/shared/dist/strategy/strategyFieldWarnings.js
2290
+ var require_strategyFieldWarnings = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
2291
+ "../../packages/shared/dist/strategy/strategyFieldWarnings.js"(exports) {
2292
+ "use strict";
2293
+ Object.defineProperty(exports, "__esModule", { value: true });
2294
+ exports.strategyFieldWarnings = strategyFieldWarnings;
2295
+ function strategyFieldWarnings(strategy) {
2296
+ const warnings = [];
2297
+ for (const node of _nullishCoalesce(strategy.nodes, () => ( []))) {
2298
+ if (node.type !== "ACTION")
2299
+ continue;
2300
+ const action = node.action;
2301
+ if (!action)
2302
+ continue;
2303
+ const target = action.target;
2304
+ const market = _optionalChain([target, 'optionalAccess', _172 => _172.market]);
2305
+ const venue = String(_nullishCoalesce(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _173 => _173.venue]), () => ( _optionalChain([market, 'optionalAccess', _174 => _174.venue]))), () => ( ""))).trim().toUpperCase();
2306
+ if (action.leverage === void 0)
2307
+ continue;
2308
+ if (venue === "HYPERLIQUID") {
2309
+ if (_optionalChain([target, 'optionalAccess', _175 => _175.leverage]) === void 0 || _optionalChain([target, 'optionalAccess', _176 => _176.leverage]) === null) {
2310
+ warnings.push(`Action ${node.node_id} sets leverage at action.leverage, which is ignored: put it on the action's target (action.target.leverage) or the order is sized at 1x.`);
2311
+ }
2312
+ continue;
2313
+ }
2314
+ warnings.push(`Action ${node.node_id} sets leverage, which is ignored: ` + (venue ? `only a HYPERLIQUID target accepts leverage and this one is ${venue}, so it is not used.` : `this action has no venue target that accepts leverage, so it is not used.`));
2315
+ }
2316
+ return warnings;
2317
+ }
2318
+ }
2319
+ });
2320
+
2168
2321
  // ../../packages/shared/dist/strategy/strategyValidationErrorCode.js
2169
2322
  var require_strategyValidationErrorCode = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
2170
2323
  "../../packages/shared/dist/strategy/strategyValidationErrorCode.js"(exports) {
@@ -2191,6 +2344,17 @@ var require_strategyValidationErrorCode = _chunkQGM4M3NIjs.__commonJS.call(void
2191
2344
  ["not a Hyperliquid perp id", "PERP_TARGET_INVALID"],
2192
2345
  ["on a Hyperliquid perp, but a perp side is", "PERP_TARGET_INVALID"],
2193
2346
  ["leverage", "PERP_TARGET_INVALID"],
2347
+ // A Limit condition (a resting order) off Polymarket, with a price outside
2348
+ // 0-1, over anything but one buy or sell of the market it names, pointing
2349
+ // the wrong way, or beside another Limit condition. Before the "ROI_PCT" and
2350
+ // "PRICE_USD" needles: none of its messages name those, and it stays so.
2351
+ ["LIMIT_PRICE", "LIMIT_CONDITION_INVALID"],
2352
+ ["is a Limit buy", "LIMIT_CONDITION_INVALID"],
2353
+ ["is a Limit sell", "LIMIT_CONDITION_INVALID"],
2354
+ ["second Limit condition", "LIMIT_CONDITION_INVALID"],
2355
+ ["limit.expires_after_seconds", "LIMIT_CONDITION_INVALID"],
2356
+ // A Limit buy whose cash cannot reach the venue's minimum order at its price.
2357
+ ["5-share minimum", "LIMIT_CONDITION_INVALID"],
2194
2358
  // An ROI condition with no position above it, watching another market, or
2195
2359
  // with a percent no price can reach.
2196
2360
  ["ROI_PCT", "ROI_CONDITION_INVALID"],
@@ -2278,7 +2442,7 @@ var require_runGraphLock = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
2278
2442
  return (_nullishCoalesce(run.activeNodeKeys, () => ( []))).some((nodeKey) => {
2279
2443
  if (nodeResults[nodeKey] !== void 0)
2280
2444
  return false;
2281
- const actionType = _optionalChain([nodesByKey, 'access', _137 => _137.get, 'call', _138 => _138(nodeKey), 'optionalAccess', _139 => _139.actionType, 'optionalAccess', _140 => _140.toLowerCase, 'call', _141 => _141()]);
2445
+ const actionType = _optionalChain([nodesByKey, 'access', _177 => _177.get, 'call', _178 => _178(nodeKey), 'optionalAccess', _179 => _179.actionType, 'optionalAccess', _180 => _180.toLowerCase, 'call', _181 => _181()]);
2282
2446
  return actionType === "buy" || actionType === "sell" || actionType === "move_to_wallet";
2283
2447
  });
2284
2448
  }
@@ -2291,13 +2455,15 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2291
2455
  "use strict";
2292
2456
  Object.defineProperty(exports, "__esModule", { value: true });
2293
2457
  exports.conditionalActionFromConvexStrategy = conditionalActionFromConvexStrategy;
2294
- var PRICE_SIGNALS = /* @__PURE__ */ new Set(["IMPLIED_PROBABILITY", "PRICE_USD", "ROI_PCT", "PNL_USD"]);
2458
+ var PRICE_SIGNALS = /* @__PURE__ */ new Set(["IMPLIED_PROBABILITY", "PRICE_USD", "ROI_PCT", "PNL_USD", "LIMIT_PRICE"]);
2295
2459
  var REFERENCE_MODES = /* @__PURE__ */ new Set([
2296
2460
  "SINCE_GROUP_START",
2297
2461
  "SINCE_STRATEGY_START",
2298
2462
  "FIXED_REFERENCE_VALUE"
2299
2463
  ]);
2300
2464
  function priceSignalFromDbNode(dbNode) {
2465
+ if (dbNode.conditionOperator === "limit")
2466
+ return "LIMIT_PRICE";
2301
2467
  if (PRICE_SIGNALS.has(dbNode.signal))
2302
2468
  return dbNode.signal;
2303
2469
  const venue = toSchemaVenue(dbNode.venue);
@@ -2306,6 +2472,11 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2306
2472
  function thresholdFromDbNode(dbNode, signal) {
2307
2473
  if (typeof dbNode.conditionValue !== "number")
2308
2474
  return 0;
2475
+ if (signal === "LIMIT_PRICE") {
2476
+ if (toSchemaVenue(dbNode.venue) === "HYPERLIQUID")
2477
+ return Number((dbNode.conditionValue / 100).toFixed(12));
2478
+ return Math.round(dbNode.conditionValue * 100) / 1e4;
2479
+ }
2309
2480
  return signal === "IMPLIED_PROBABILITY" ? dbNode.conditionValue / 100 : dbNode.conditionValue;
2310
2481
  }
2311
2482
  var toSchemaVenue = (venue) => {
@@ -2340,6 +2511,16 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2340
2511
  return "BUY_MARKET_OUTCOME";
2341
2512
  }
2342
2513
  };
2514
+ function limitOf(dbNode) {
2515
+ const limit = {};
2516
+ if (typeof dbNode.limitExpiresAfterSeconds === "number")
2517
+ limit.expires_after_seconds = dbNode.limitExpiresAfterSeconds;
2518
+ else if (dbNode.limitExpiresAtDayEnd === true)
2519
+ limit.expires_at_day_end = true;
2520
+ if (dbNode.limitPriceFrom)
2521
+ limit.price_from = dbNode.limitPriceFrom;
2522
+ return Object.keys(limit).length > 0 ? { limit } : {};
2523
+ }
2343
2524
  function timingFromDbNode(dbNode) {
2344
2525
  if (dbNode.timingMode === "ABSOLUTE_TIME") {
2345
2526
  return {
@@ -2354,7 +2535,7 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2354
2535
  };
2355
2536
  }
2356
2537
  function conditionalActionFromConvexStrategy(strategyDetails) {
2357
- if (!_optionalChain([strategyDetails, 'optionalAccess', _142 => _142.entryNodeKey]) || !Array.isArray(_optionalChain([strategyDetails, 'optionalAccess', _143 => _143.nodes])))
2538
+ if (!_optionalChain([strategyDetails, 'optionalAccess', _182 => _182.entryNodeKey]) || !Array.isArray(_optionalChain([strategyDetails, 'optionalAccess', _183 => _183.nodes])))
2358
2539
  return null;
2359
2540
  const dbNodesByKey = new Map(strategyDetails.nodes.map((node) => [node.key, node]));
2360
2541
  const nextChildrenByParent = /* @__PURE__ */ new Map();
@@ -2412,7 +2593,7 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2412
2593
  const isResolution = operator === "resolved";
2413
2594
  const priceSignal = priceSignalFromDbNode(dbNode);
2414
2595
  const actionKeys = metActionsByCondition.get(dbNode.key) || [];
2415
- const sameMarketToken = actionKeys.filter((k) => _optionalChain([dbNodesByKey, 'access', _144 => _144.get, 'call', _145 => _145(k), 'optionalAccess', _146 => _146.marketId]) === dbNode.marketId).map((k) => dbActionTokenByKey.get(k)).find(Boolean);
2596
+ const sameMarketToken = actionKeys.filter((k) => _optionalChain([dbNodesByKey, 'access', _184 => _184.get, 'call', _185 => _185(k), 'optionalAccess', _186 => _186.marketId]) === dbNode.marketId).map((k) => dbActionTokenByKey.get(k)).find(Boolean);
2416
2597
  const derivedTokenId = dbNode.tokenId || sameMarketToken || actionKeys.map((k) => dbActionTokenByKey.get(k)).find(Boolean) || "";
2417
2598
  return {
2418
2599
  node_id: dbNode.key,
@@ -2426,12 +2607,15 @@ var require_conditionalActionFromConvexStrategy = _chunkQGM4M3NIjs.__commonJS.ca
2426
2607
  ...derivedTokenId ? { token_id: derivedTokenId } : {}
2427
2608
  },
2428
2609
  signal: isTime ? "TIME_SINCE_GROUP_SECONDS" : isResolution ? "TIME_TO_RESOLUTION_SECONDS" : priceSignal,
2429
- trigger: operator === "lt" ? "CROSS_BELOW" : "CROSS_ABOVE",
2610
+ // A Limit condition stores no direction of its own: a resting buy
2611
+ // is "this price or lower", a resting sell "this price or higher".
2612
+ trigger: (operator === "limit" ? actionKeys.some((k) => String(_nullishCoalesce(_optionalChain([dbNodesByKey, 'access', _187 => _187.get, 'call', _188 => _188(k), 'optionalAccess', _189 => _189.actionType]), () => ( ""))).toLowerCase() === "buy") : operator === "lt") ? "CROSS_BELOW" : "CROSS_ABOVE",
2430
2613
  threshold: isTime || isResolution ? 0 : thresholdFromDbNode(dbNode, priceSignal),
2431
2614
  ...isTime ? {
2432
2615
  timing: timingFromDbNode(dbNode)
2433
2616
  } : {},
2434
- ...!isTime && !isResolution && REFERENCE_MODES.has(dbNode.referenceMode) ? { reference: { mode: dbNode.referenceMode } } : {}
2617
+ ...!isTime && !isResolution && REFERENCE_MODES.has(dbNode.referenceMode) ? { reference: { mode: dbNode.referenceMode } } : {},
2618
+ ...operator === "limit" ? limitOf(dbNode) : {}
2435
2619
  }
2436
2620
  };
2437
2621
  }
@@ -3003,7 +3187,7 @@ var require_strategyTemplateComposition = _chunkQGM4M3NIjs.__commonJS.call(void
3003
3187
  const nsId = namespaceId(node.node_id, prefix);
3004
3188
  nodeIdMapping.set(node.node_id, nsId);
3005
3189
  const nsNode = { ...node, node_id: nsId, condition: node.condition ? { ...node.condition } : void 0, action: node.action ? { ...node.action } : void 0 };
3006
- if (_optionalChain([nsNode, 'access', _147 => _147.condition, 'optionalAccess', _148 => _148.watch])) {
3190
+ if (_optionalChain([nsNode, 'access', _190 => _190.condition, 'optionalAccess', _191 => _191.watch])) {
3007
3191
  const watch = nsNode.condition.watch;
3008
3192
  if (watch.market_id && watch.market_id.startsWith("__SLOT_")) {
3009
3193
  const slotLocalId = watch.market_id.replace("__SLOT_", "").replace("__", "");
@@ -3016,7 +3200,7 @@ var require_strategyTemplateComposition = _chunkQGM4M3NIjs.__commonJS.call(void
3016
3200
  }
3017
3201
  }
3018
3202
  }
3019
- if (_optionalChain([nsNode, 'access', _149 => _149.condition, 'optionalAccess', _150 => _150.conjuncts])) {
3203
+ if (_optionalChain([nsNode, 'access', _192 => _192.condition, 'optionalAccess', _193 => _193.conjuncts])) {
3020
3204
  for (const conj of nsNode.condition.conjuncts) {
3021
3205
  if (conj.watch && conj.watch.market_id && conj.watch.market_id.startsWith("__SLOT_")) {
3022
3206
  const slotLocalId = conj.watch.market_id.replace("__SLOT_", "").replace("__", "");
@@ -3030,7 +3214,7 @@ var require_strategyTemplateComposition = _chunkQGM4M3NIjs.__commonJS.call(void
3030
3214
  }
3031
3215
  }
3032
3216
  }
3033
- if (_optionalChain([nsNode, 'access', _151 => _151.action, 'optionalAccess', _152 => _152.target, 'optionalAccess', _153 => _153.market])) {
3217
+ if (_optionalChain([nsNode, 'access', _194 => _194.action, 'optionalAccess', _195 => _195.target, 'optionalAccess', _196 => _196.market])) {
3034
3218
  const market = nsNode.action.target.market;
3035
3219
  if (market.market_id && market.market_id.startsWith("__SLOT_")) {
3036
3220
  const slotLocalId = market.market_id.replace("__SLOT_", "").replace("__", "");
@@ -3206,7 +3390,7 @@ var require_strategyStats = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3206
3390
  let hasAllAllocations = true;
3207
3391
  for (const actionNodeId of group.action_node_ids) {
3208
3392
  const node = nodes.find((n) => n.node_id === actionNodeId);
3209
- const pct = _optionalChain([node, 'optionalAccess', _154 => _154.action, 'optionalAccess', _155 => _155.allocation_pct]);
3393
+ const pct = _optionalChain([node, 'optionalAccess', _197 => _197.action, 'optionalAccess', _198 => _198.allocation_pct]);
3210
3394
  if (typeof pct !== "number") {
3211
3395
  hasAllAllocations = false;
3212
3396
  } else {
@@ -3296,7 +3480,7 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3296
3480
  if (idx === -1)
3297
3481
  continue;
3298
3482
  const node = strategy.nodes[idx];
3299
- const pct = _optionalChain([node, 'access', _156 => _156.action, 'optionalAccess', _157 => _157.allocation_pct]);
3483
+ const pct = _optionalChain([node, 'access', _199 => _199.action, 'optionalAccess', _200 => _200.allocation_pct]);
3300
3484
  if (typeof pct === "number") {
3301
3485
  splitTotal += pct;
3302
3486
  allocations.push({ node, idx });
@@ -3329,7 +3513,7 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3329
3513
  if (idx === -1)
3330
3514
  continue;
3331
3515
  const node = strategy.nodes[idx];
3332
- const pct = _optionalChain([node, 'access', _158 => _158.action, 'optionalAccess', _159 => _159.allocation_pct]);
3516
+ const pct = _optionalChain([node, 'access', _201 => _201.action, 'optionalAccess', _202 => _202.allocation_pct]);
3333
3517
  if (typeof pct === "number" && !approxEqual(pct, 100)) {
3334
3518
  strategy.nodes[idx] = { ...node, action: { ...node.action, allocation_pct: 100 } };
3335
3519
  changed = true;
@@ -3366,7 +3550,7 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3366
3550
  const action = node.action;
3367
3551
  if (!action)
3368
3552
  continue;
3369
- const market = _optionalChain([action, 'access', _160 => _160.target, 'optionalAccess', _161 => _161.market]);
3553
+ const market = _optionalChain([action, 'access', _203 => _203.target, 'optionalAccess', _204 => _204.market]);
3370
3554
  if (!market)
3371
3555
  continue;
3372
3556
  if (market.token_id && market.token_id.trim().length > 0)
@@ -3378,10 +3562,10 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3378
3562
  if (idx === -1)
3379
3563
  continue;
3380
3564
  for (const other of strategy.nodes) {
3381
- const otherMarket = _optionalChain([other, 'access', _162 => _162.action, 'optionalAccess', _163 => _163.target, 'optionalAccess', _164 => _164.market]);
3565
+ const otherMarket = _optionalChain([other, 'access', _205 => _205.action, 'optionalAccess', _206 => _206.target, 'optionalAccess', _207 => _207.market]);
3382
3566
  if (!otherMarket)
3383
3567
  continue;
3384
- if (otherMarket.market_id === market.market_id && _optionalChain([otherMarket, 'access', _165 => _165.outcome_token, 'optionalAccess', _166 => _166.toUpperCase, 'call', _167 => _167()]) === _optionalChain([market, 'access', _168 => _168.outcome_token, 'optionalAccess', _169 => _169.toUpperCase, 'call', _170 => _170()]) && otherMarket.token_id && otherMarket.token_id.trim().length > 0) {
3568
+ if (otherMarket.market_id === market.market_id && _optionalChain([otherMarket, 'access', _208 => _208.outcome_token, 'optionalAccess', _209 => _209.toUpperCase, 'call', _210 => _210()]) === _optionalChain([market, 'access', _211 => _211.outcome_token, 'optionalAccess', _212 => _212.toUpperCase, 'call', _213 => _213()]) && otherMarket.token_id && otherMarket.token_id.trim().length > 0) {
3385
3569
  strategy.nodes[idx] = {
3386
3570
  ...node,
3387
3571
  action: {
@@ -3410,8 +3594,8 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3410
3594
  continue;
3411
3595
  for (const other of strategy.nodes) {
3412
3596
  const otherAction = other.action;
3413
- const otherMarket = _optionalChain([otherAction, 'optionalAccess', _171 => _171.target, 'optionalAccess', _172 => _172.market]);
3414
- if (otherMarket && otherMarket.market_id === watch.market_id && _optionalChain([otherMarket, 'access', _173 => _173.outcome_token, 'optionalAccess', _174 => _174.toUpperCase, 'call', _175 => _175()]) === _optionalChain([watch, 'access', _176 => _176.outcome_token, 'optionalAccess', _177 => _177.toUpperCase, 'call', _178 => _178()]) && otherMarket.token_id) {
3597
+ const otherMarket = _optionalChain([otherAction, 'optionalAccess', _214 => _214.target, 'optionalAccess', _215 => _215.market]);
3598
+ if (otherMarket && otherMarket.market_id === watch.market_id && _optionalChain([otherMarket, 'access', _216 => _216.outcome_token, 'optionalAccess', _217 => _217.toUpperCase, 'call', _218 => _218()]) === _optionalChain([watch, 'access', _219 => _219.outcome_token, 'optionalAccess', _220 => _220.toUpperCase, 'call', _221 => _221()]) && otherMarket.token_id) {
3415
3599
  strategy.nodes[idx] = {
3416
3600
  ...node,
3417
3601
  condition: {
@@ -3430,8 +3614,8 @@ var require_strategyAutoRepair = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3430
3614
  if (!conjWatch || conjWatch.token_id && conjWatch.token_id.trim().length > 0)
3431
3615
  continue;
3432
3616
  for (const other of strategy.nodes) {
3433
- const otherMarket = _optionalChain([other, 'access', _179 => _179.action, 'optionalAccess', _180 => _180.target, 'optionalAccess', _181 => _181.market]);
3434
- if (otherMarket && otherMarket.market_id === conjWatch.market_id && _optionalChain([otherMarket, 'access', _182 => _182.outcome_token, 'optionalAccess', _183 => _183.toUpperCase, 'call', _184 => _184()]) === _optionalChain([conjWatch, 'access', _185 => _185.outcome_token, 'optionalAccess', _186 => _186.toUpperCase, 'call', _187 => _187()]) && otherMarket.token_id) {
3617
+ const otherMarket = _optionalChain([other, 'access', _222 => _222.action, 'optionalAccess', _223 => _223.target, 'optionalAccess', _224 => _224.market]);
3618
+ if (otherMarket && otherMarket.market_id === conjWatch.market_id && _optionalChain([otherMarket, 'access', _225 => _225.outcome_token, 'optionalAccess', _226 => _226.toUpperCase, 'call', _227 => _227()]) === _optionalChain([conjWatch, 'access', _228 => _228.outcome_token, 'optionalAccess', _229 => _229.toUpperCase, 'call', _230 => _230()]) && otherMarket.token_id) {
3435
3619
  strategy.nodes[idx] = {
3436
3620
  ...strategy.nodes[idx],
3437
3621
  condition: {
@@ -3703,7 +3887,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3703
3887
  if ((0, conditionalActionTypes_1.isHyperliquidVenueKey)(market.venue)) {
3704
3888
  const wantedLabel = wantedSide === "NO" ? "SHORT" : "LONG";
3705
3889
  const perpOutcome = market.outcomes.find((o) => o.label.toUpperCase() === wantedLabel);
3706
- if (!_optionalChain([perpOutcome, 'optionalAccess', _188 => _188.tokenId])) {
3890
+ if (!_optionalChain([perpOutcome, 'optionalAccess', _231 => _231.tokenId])) {
3707
3891
  warnings.push(`${context}: market ${market.marketId} has no ${wantedLabel} outcome with a usable token id.`);
3708
3892
  return null;
3709
3893
  }
@@ -3793,7 +3977,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3793
3977
  if (!ref)
3794
3978
  return void 0;
3795
3979
  const wanted = (0, conditionalActionTypes_1.isHyperliquidVenueKey)(ref.venue) ? (_nullishCoalesce(action.side, () => ( "YES"))) === "NO" ? "SHORT" : "LONG" : _nullishCoalesce(action.side, () => ( "YES"));
3796
- return _optionalChain([(_nullishCoalesce(ref.outcomes.find((o) => o.label.toUpperCase() === wanted), () => ( ref.outcomes[0]))), 'optionalAccess', _189 => _189.currentPrice]);
3980
+ return _optionalChain([(_nullishCoalesce(ref.outcomes.find((o) => o.label.toUpperCase() === wanted), () => ( ref.outcomes[0]))), 'optionalAccess', _232 => _232.currentPrice]);
3797
3981
  }
3798
3982
  function collapseRootUnconditionalChain(stageById, childrenByParent, primaryRootId, markets, planErrors) {
3799
3983
  const root = stageById.get(primaryRootId);
@@ -3824,7 +4008,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3824
4008
  planErrors.push(`Stage ${root.id}: chaining unconditional stages together produced ${flatActions.length} actions, more than the ${exports.MAX_ACTIONS_PER_STAGE} a single decision group supports. Use a real trigger condition to split these into separate stages, or reduce the number of unconditional legs.`);
3825
4009
  }
3826
4010
  const clampedActions = flatActions.slice(0, exports.MAX_ACTIONS_PER_STAGE);
3827
- const venueOf = (a) => a.market !== null ? _optionalChain([markets, 'access', _190 => _190[a.market - 1], 'optionalAccess', _191 => _191.venue]) : void 0;
4011
+ const venueOf = (a) => a.market !== null ? _optionalChain([markets, 'access', _233 => _233[a.market - 1], 'optionalAccess', _234 => _234.venue]) : void 0;
3828
4012
  const isWatchable = (a) => a.market !== null && (0, conditionalActionTypes_1.isConditionWatchableVenue)(venueOf(a));
3829
4013
  const gateAction = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(clampedActions.find((a) => isWatchable(a) && !(0, conditionalActionTypes_1.isBaseStocksVenueKey)(venueOf(a))), () => ( clampedActions.find(isWatchable))), () => ( clampedActions.find((a) => a.market !== null))), () => ( clampedActions[0]));
3830
4014
  const gateVenue = venueOf(gateAction);
@@ -3937,7 +4121,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
3937
4121
  stageById.set(stage.id, stage);
3938
4122
  }
3939
4123
  const roots = [...stageById.values()].filter((s) => s.after === null);
3940
- const primaryRootId = _optionalChain([roots, 'access', _192 => _192[0], 'optionalAccess', _193 => _193.id]);
4124
+ const primaryRootId = _optionalChain([roots, 'access', _235 => _235[0], 'optionalAccess', _236 => _236.id]);
3941
4125
  if (roots.length > 1) {
3942
4126
  warnings.push(`Plan declared ${roots.length} root stages; only stage ${primaryRootId} is used as the root, the rest are attached to it.`);
3943
4127
  for (const extra of roots.slice(1)) {
@@ -4037,7 +4221,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4037
4221
  }
4038
4222
  const condNodeId = `cond_${stage.id}`;
4039
4223
  nodes.push(buildConditionNode(condNodeId, level, stage.when, markets, warnings, `Stage ${stage.id} condition`));
4040
- if (_optionalChain([parent, 'optionalAccess', _194 => _194.exitNodeId])) {
4224
+ if (_optionalChain([parent, 'optionalAccess', _237 => _237.exitNodeId])) {
4041
4225
  edges.push({ edge_id: `e${edgeCounter++}`, from_node_id: parent.exitNodeId, to_node_id: condNodeId });
4042
4226
  }
4043
4227
  if (!parent)
@@ -4075,7 +4259,7 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4075
4259
  visited.add(primaryRootId);
4076
4260
  const rootStage = stageById.get(primaryRootId);
4077
4261
  const rootBuyNodeIdByMarket = /* @__PURE__ */ new Map();
4078
- (_nullishCoalesce(_optionalChain([rootStage, 'optionalAccess', _195 => _195.actions]), () => ( []))).forEach((action, idx) => {
4262
+ (_nullishCoalesce(_optionalChain([rootStage, 'optionalAccess', _238 => _238.actions]), () => ( []))).forEach((action, idx) => {
4079
4263
  if (action.action !== "BUY")
4080
4264
  return;
4081
4265
  const resolved = resolveMarket(markets, action.market, action.side, [], `Stage ${primaryRootId} action ${idx + 1}`);
@@ -4163,17 +4347,17 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4163
4347
  }
4164
4348
  function buildConditionNode(nodeId, level, when, markets, warnings, context) {
4165
4349
  const resolved = resolveMarket(markets, when.watch_market, when.watch_side, warnings, context);
4166
- const isStockWatch = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([resolved, 'optionalAccess', _196 => _196.venue]));
4350
+ const isStockWatch = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([resolved, 'optionalAccess', _239 => _239.venue]));
4167
4351
  const signal = isStockWatch && when.signal === "IMPLIED_PROBABILITY" ? "PRICE_USD" : when.signal;
4168
4352
  const isTimeSignal = signal === "TIME_SINCE_GROUP_SECONDS" || signal === "TIME_TO_RESOLUTION_SECONDS";
4169
4353
  const watch = {
4170
4354
  // PlanMarketRef.venue is a free string (it comes off search results); the
4171
4355
  // node type wants the StrategyVenue union. The validator rejects anything
4172
4356
  // outside EXECUTABLE_VENUES downstream, so the narrowing is checked there.
4173
- venue: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _197 => _197.venue]), () => ( "POLYMARKET")),
4174
- market_id: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _198 => _198.marketId]), () => ( "")),
4175
- outcome_token: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _199 => _199.outcomeToken]), () => ( when.watch_side)),
4176
- ...isTimeSignal ? {} : { token_id: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _200 => _200.tokenId]), () => ( "")) }
4357
+ venue: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _240 => _240.venue]), () => ( "POLYMARKET")),
4358
+ market_id: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _241 => _241.marketId]), () => ( "")),
4359
+ outcome_token: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _242 => _242.outcomeToken]), () => ( when.watch_side)),
4360
+ ...isTimeSignal ? {} : { token_id: _nullishCoalesce(_optionalChain([resolved, 'optionalAccess', _243 => _243.tokenId]), () => ( "")) }
4177
4361
  };
4178
4362
  const timing = signal === "TIME_SINCE_GROUP_SECONDS" ? when.at ? { mode: "ABSOLUTE_TIME", absolute_trigger_time_iso: when.at } : {
4179
4363
  mode: "BEFORE_CLOSE",
@@ -4201,11 +4385,11 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4201
4385
  for (const group of strategy.decision_groups) {
4202
4386
  if (group.mode !== "SPLIT_100")
4203
4387
  continue;
4204
- const actionNodes = group.action_node_ids.map((id) => strategy.nodes.find((n) => n.node_id === id)).filter((n) => !!n && (_optionalChain([n, 'access', _201 => _201.action, 'optionalAccess', _202 => _202.action_type]) === "BUY_MARKET_OUTCOME" || _optionalChain([n, 'access', _203 => _203.action, 'optionalAccess', _204 => _204.action_type]) === "SELL_MARKET_OUTCOME"));
4205
- const underfunded = actionNodes.filter((n) => (_nullishCoalesce(_optionalChain([n, 'access', _205 => _205.action, 'optionalAccess', _206 => _206.allocation_pct]), () => ( 0))) < minPct);
4388
+ const actionNodes = group.action_node_ids.map((id) => strategy.nodes.find((n) => n.node_id === id)).filter((n) => !!n && (_optionalChain([n, 'access', _244 => _244.action, 'optionalAccess', _245 => _245.action_type]) === "BUY_MARKET_OUTCOME" || _optionalChain([n, 'access', _246 => _246.action, 'optionalAccess', _247 => _247.action_type]) === "SELL_MARKET_OUTCOME"));
4389
+ const underfunded = actionNodes.filter((n) => (_nullishCoalesce(_optionalChain([n, 'access', _248 => _248.action, 'optionalAccess', _249 => _249.allocation_pct]), () => ( 0))) < minPct);
4206
4390
  if (underfunded.length === 0)
4207
4391
  continue;
4208
- const pcts = new Map(group.action_node_ids.map((id) => [id, _nullishCoalesce(_optionalChain([strategy, 'access', _207 => _207.nodes, 'access', _208 => _208.find, 'call', _209 => _209((n) => n.node_id === id), 'optionalAccess', _210 => _210.action, 'optionalAccess', _211 => _211.allocation_pct]), () => ( 0))]));
4392
+ const pcts = new Map(group.action_node_ids.map((id) => [id, _nullishCoalesce(_optionalChain([strategy, 'access', _250 => _250.nodes, 'access', _251 => _251.find, 'call', _252 => _252((n) => n.node_id === id), 'optionalAccess', _253 => _253.action, 'optionalAccess', _254 => _254.allocation_pct]), () => ( 0))]));
4209
4393
  for (const n of underfunded)
4210
4394
  pcts.set(n.node_id, minPct);
4211
4395
  const total = [...pcts.values()].reduce((a, b) => a + b, 0);
@@ -4244,26 +4428,26 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4244
4428
  for (let cur = nodeId; cur && !seen.has(cur); cur = _nullishCoalesce(parentOf.get(cur), () => ( conditionOfAction.get(cur)))) {
4245
4429
  seen.add(cur);
4246
4430
  const n = nodeById.get(cur);
4247
- if (_optionalChain([n, 'optionalAccess', _212 => _212.type]) === "ACTION")
4248
- capital *= (_nullishCoalesce(_optionalChain([n, 'access', _213 => _213.action, 'optionalAccess', _214 => _214.allocation_pct]), () => ( 100))) / 100;
4431
+ if (_optionalChain([n, 'optionalAccess', _255 => _255.type]) === "ACTION")
4432
+ capital *= (_nullishCoalesce(_optionalChain([n, 'access', _256 => _256.action, 'optionalAccess', _257 => _257.allocation_pct]), () => ( 100))) / 100;
4249
4433
  }
4250
4434
  return capital;
4251
4435
  };
4252
4436
  const out = [];
4253
4437
  for (const n of strategy.nodes) {
4254
- if (n.type !== "ACTION" || _optionalChain([n, 'access', _215 => _215.action, 'optionalAccess', _216 => _216.action_type]) !== "BUY_MARKET_OUTCOME")
4438
+ if (n.type !== "ACTION" || _optionalChain([n, 'access', _258 => _258.action, 'optionalAccess', _259 => _259.action_type]) !== "BUY_MARKET_OUTCOME")
4255
4439
  continue;
4256
4440
  const target = n.action.target;
4257
- if (String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _217 => _217.venue]), () => ( ""))).toUpperCase() !== "HYPERLIQUID")
4441
+ if (String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _260 => _260.venue]), () => ( ""))).toUpperCase() !== "HYPERLIQUID")
4258
4442
  continue;
4259
- const leverage = Math.max(1, Math.floor(Number(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _218 => _218.leverage]), () => ( 1)))) || 1);
4443
+ const leverage = Math.max(1, Math.floor(Number(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _261 => _261.leverage]), () => ( 1)))) || 1);
4260
4444
  const marginUsd = capitalAt(n.node_id);
4261
4445
  const notionalUsd = marginUsd * leverage;
4262
4446
  if (notionalUsd >= exports.MIN_PERP_ORDER_NOTIONAL_USD)
4263
4447
  continue;
4264
4448
  out.push({
4265
4449
  nodeId: n.node_id,
4266
- coin: String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _219 => _219.market, 'optionalAccess', _220 => _220.market_id]), () => ( ""))).replace(/^hl:/, ""),
4450
+ coin: String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _262 => _262.market, 'optionalAccess', _263 => _263.market_id]), () => ( ""))).replace(/^hl:/, ""),
4267
4451
  marginUsd,
4268
4452
  leverage,
4269
4453
  notionalUsd,
@@ -4278,8 +4462,8 @@ var require_strategyPlan = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4278
4462
  const nodeById = new Map(strategy.nodes.map((n) => [n.node_id, n]));
4279
4463
  const lifted = [];
4280
4464
  for (const s of perpNotionalShortfalls(strategy)) {
4281
- const target = _optionalChain([nodeById, 'access', _221 => _221.get, 'call', _222 => _222(s.nodeId), 'optionalAccess', _223 => _223.action, 'optionalAccess', _224 => _224.target]);
4282
- const marketId = _nullishCoalesce(_optionalChain([target, 'optionalAccess', _225 => _225.market, 'optionalAccess', _226 => _226.market_id]), () => ( ""));
4465
+ const target = _optionalChain([nodeById, 'access', _264 => _264.get, 'call', _265 => _265(s.nodeId), 'optionalAccess', _266 => _266.action, 'optionalAccess', _267 => _267.target]);
4466
+ const marketId = _nullishCoalesce(_optionalChain([target, 'optionalAccess', _268 => _268.market, 'optionalAccess', _269 => _269.market_id]), () => ( ""));
4283
4467
  if (!target || !liftable(marketId) || !Number.isFinite(s.leverageNeeded) || s.leverageNeeded > exports.MAX_LIFTED_PERP_LEVERAGE)
4284
4468
  continue;
4285
4469
  target.leverage = s.leverageNeeded;
@@ -4606,7 +4790,7 @@ var require_strategyShapes = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4606
4790
  return takeProfitTrigger(pricing) === "CROSS_ABOVE" ? "CROSS_BELOW" : "CROSS_ABOVE";
4607
4791
  }
4608
4792
  function sameMarket(refs, a, b) {
4609
- return a !== null && b !== null && _optionalChain([refs, 'access', _227 => _227[a - 1], 'optionalAccess', _228 => _228.marketId]) === _optionalChain([refs, 'access', _229 => _229[b - 1], 'optionalAccess', _230 => _230.marketId]);
4793
+ return a !== null && b !== null && _optionalChain([refs, 'access', _270 => _270[a - 1], 'optionalAccess', _271 => _271.marketId]) === _optionalChain([refs, 'access', _272 => _272[b - 1], 'optionalAccess', _273 => _273.marketId]);
4610
4794
  }
4611
4795
  function thesisBreakWatch(spec, refs, L, primaryMarket, gates, errors) {
4612
4796
  const watchRef = _nullishCoalesce(spec.exit_watch_ref, () => ( null));
@@ -4634,12 +4818,12 @@ var require_strategyShapes = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4634
4818
  return void 0;
4635
4819
  const ref = refs[refIndex];
4636
4820
  if ((0, conditionalActionTypes_1.isBaseStocksVenueKey)(ref.venue))
4637
- return _optionalChain([ref, 'access', _231 => _231.outcomes, 'access', _232 => _232[0], 'optionalAccess', _233 => _233.currentPrice]);
4821
+ return _optionalChain([ref, 'access', _274 => _274.outcomes, 'access', _275 => _275[0], 'optionalAccess', _276 => _276.currentPrice]);
4638
4822
  if ((0, conditionalActionTypes_1.isHyperliquidVenueKey)(ref.venue)) {
4639
4823
  const label = side === "NO" ? "SHORT" : "LONG";
4640
- return _optionalChain([(_nullishCoalesce(ref.outcomes.find((o) => o.label.toUpperCase() === label), () => ( ref.outcomes[0]))), 'optionalAccess', _234 => _234.currentPrice]);
4824
+ return _optionalChain([(_nullishCoalesce(ref.outcomes.find((o) => o.label.toUpperCase() === label), () => ( ref.outcomes[0]))), 'optionalAccess', _277 => _277.currentPrice]);
4641
4825
  }
4642
- return _optionalChain([ref, 'access', _235 => _235.outcomes, 'access', _236 => _236.find, 'call', _237 => _237((o) => o.label.toUpperCase() === side), 'optionalAccess', _238 => _238.currentPrice]);
4826
+ return _optionalChain([ref, 'access', _278 => _278.outcomes, 'access', _279 => _279.find, 'call', _280 => _280((o) => o.label.toUpperCase() === side), 'optionalAccess', _281 => _281.currentPrice]);
4643
4827
  }
4644
4828
  function lookupCloseTime(refs, refIndex) {
4645
4829
  if (refIndex === null || refIndex === void 0 || refIndex < 0 || refIndex >= refs.length)
@@ -4813,7 +4997,7 @@ var require_strategyShapes = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
4813
4997
  }
4814
4998
  function requireLegs(legs, refs, label, errors) {
4815
4999
  if (!legs || legs.length < 2) {
4816
- errors.push(`${label}.legs: at least 2 legs ({ref, side, pct}) are required for this shape but ${_nullishCoalesce(_optionalChain([legs, 'optionalAccess', _239 => _239.length]), () => ( 0))} were given.`);
5000
+ errors.push(`${label}.legs: at least 2 legs ({ref, side, pct}) are required for this shape but ${_nullishCoalesce(_optionalChain([legs, 'optionalAccess', _282 => _282.length]), () => ( 0))} were given.`);
4817
5001
  return [];
4818
5002
  }
4819
5003
  const clamped = legs.slice(0, exports.MAX_LEGS);
@@ -5367,16 +5551,17 @@ var require_roiReach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5367
5551
  const seen = /* @__PURE__ */ new Set([buy.node_id]);
5368
5552
  for (let id = parentOf.get(buy.node_id); id !== void 0 && !seen.has(id); id = parentOf.get(id)) {
5369
5553
  seen.add(id);
5370
- const c = _optionalChain([byId, 'access', _240 => _240.get, 'call', _241 => _241(id), 'optionalAccess', _242 => _242.condition]);
5554
+ const c = _optionalChain([byId, 'access', _283 => _283.get, 'call', _284 => _284(id), 'optionalAccess', _285 => _285.condition]);
5371
5555
  if (c && !(0, strategyPlan_1.isSyntheticRootGate)(c.signal, c.trigger, c.threshold))
5372
5556
  gates.push(c);
5373
5557
  }
5374
- const market = _optionalChain([buy, 'access', _243 => _243.action, 'optionalAccess', _244 => _244.target, 'optionalAccess', _245 => _245.market]);
5558
+ const market = _optionalChain([buy, 'access', _286 => _286.action, 'optionalAccess', _287 => _287.target, 'optionalAccess', _288 => _288.market]);
5375
5559
  if (gates.length === 0)
5376
5560
  return priceNow(buy);
5377
5561
  const [gate] = gates;
5378
- const sameToken = _optionalChain([gate, 'access', _246 => _246.watch, 'optionalAccess', _247 => _247.market_id]) === _optionalChain([market, 'optionalAccess', _248 => _248.market_id]) && (_nullishCoalesce(_optionalChain([gate, 'access', _249 => _249.watch, 'optionalAccess', _250 => _250.outcome_token]), () => ( "YES"))).toUpperCase() === (_nullishCoalesce(_optionalChain([market, 'optionalAccess', _251 => _251.outcome_token]), () => ( "YES"))).toUpperCase();
5379
- return gates.length === 1 && gate.signal === "IMPLIED_PROBABILITY" && sameToken ? gate.threshold : void 0;
5562
+ const sameToken = _optionalChain([gate, 'access', _289 => _289.watch, 'optionalAccess', _290 => _290.market_id]) === _optionalChain([market, 'optionalAccess', _291 => _291.market_id]) && (_nullishCoalesce(_optionalChain([gate, 'access', _292 => _292.watch, 'optionalAccess', _293 => _293.outcome_token]), () => ( "YES"))).toUpperCase() === (_nullishCoalesce(_optionalChain([market, 'optionalAccess', _294 => _294.outcome_token]), () => ( "YES"))).toUpperCase();
5563
+ const namesEntryPrice = gate.signal === "IMPLIED_PROBABILITY" || gate.signal === "LIMIT_PRICE";
5564
+ return gates.length === 1 && namesEntryPrice && sameToken ? gate.threshold : void 0;
5380
5565
  }
5381
5566
  function unreachableRoiTakeProfits(strategy, priceNow) {
5382
5567
  const nodeMap = new Map(strategy.nodes.map((n) => [n.node_id, n]));
@@ -5386,8 +5571,8 @@ var require_roiReach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5386
5571
  if (!c || c.signal !== "ROI_PCT" || c.trigger !== "CROSS_ABOVE" || !(c.threshold > 0))
5387
5572
  continue;
5388
5573
  const buy = (0, validateConditionalAction_1.roiPositionBuy)(strategy, node.node_id, nodeMap);
5389
- const target = _optionalChain([buy, 'optionalAccess', _252 => _252.action, 'optionalAccess', _253 => _253.target]);
5390
- const market = _optionalChain([target, 'optionalAccess', _254 => _254.market]);
5574
+ const target = _optionalChain([buy, 'optionalAccess', _295 => _295.action, 'optionalAccess', _296 => _296.target]);
5575
+ const market = _optionalChain([target, 'optionalAccess', _297 => _297.market]);
5391
5576
  if (!buy || !target || !market)
5392
5577
  continue;
5393
5578
  const outcome = (_nullishCoalesce(market.outcome_token, () => ( "YES"))).toUpperCase();
@@ -5459,8 +5644,8 @@ var require_roiReach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5459
5644
  const c = node.condition;
5460
5645
  if (!c || c.signal !== "ROI_PCT" || c.trigger !== "CROSS_ABOVE" || !(c.threshold > 0))
5461
5646
  continue;
5462
- const target = _optionalChain([(0, validateConditionalAction_1.roiPositionBuy), 'call', _255 => _255(strategy, node.node_id, nodeMap), 'optionalAccess', _256 => _256.action, 'optionalAccess', _257 => _257.target]);
5463
- const token = _optionalChain([target, 'optionalAccess', _258 => _258.market, 'optionalAccess', _259 => _259.token_id]);
5647
+ const target = _optionalChain([(0, validateConditionalAction_1.roiPositionBuy), 'call', _298 => _298(strategy, node.node_id, nodeMap), 'optionalAccess', _299 => _299.action, 'optionalAccess', _300 => _300.target]);
5648
+ const token = _optionalChain([target, 'optionalAccess', _301 => _301.market, 'optionalAccess', _302 => _302.token_id]);
5464
5649
  if (target && token && !(0, conditionalActionTypes_1.isUsdPricedVenueKey)(target.venue) && target.venue !== "HYPERLIQUID")
5465
5650
  tokens.add(token);
5466
5651
  }
@@ -5476,7 +5661,7 @@ var require_roiReach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5476
5661
  asks.set(token, void 0);
5477
5662
  }
5478
5663
  }));
5479
- return unreachableRoiTakeProfits(strategy, (buy) => asks.get(_nullishCoalesce(_optionalChain([buy, 'access', _260 => _260.action, 'optionalAccess', _261 => _261.target, 'optionalAccess', _262 => _262.market, 'optionalAccess', _263 => _263.token_id]), () => ( "")))).map((u) => roiReachMessage(u));
5664
+ return unreachableRoiTakeProfits(strategy, (buy) => asks.get(_nullishCoalesce(_optionalChain([buy, 'access', _303 => _303.action, 'optionalAccess', _304 => _304.target, 'optionalAccess', _305 => _305.market, 'optionalAccess', _306 => _306.token_id]), () => ( "")))).map((u) => roiReachMessage(u));
5480
5665
  }
5481
5666
  }
5482
5667
  });
@@ -5497,7 +5682,7 @@ var require_minimumOrder = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5497
5682
  if (!Number.isFinite(principal) || principal <= 0)
5498
5683
  return [];
5499
5684
  const byId = new Map((_nullishCoalesce(strategy.nodes, () => ( []))).map((n) => [n.node_id, n]));
5500
- const isBuy = (n) => _optionalChain([n, 'optionalAccess', _264 => _264.action, 'optionalAccess', _265 => _265.action_type]) === "BUY_MARKET_OUTCOME";
5685
+ const isBuy = (n) => _optionalChain([n, 'optionalAccess', _307 => _307.action, 'optionalAccess', _308 => _308.action_type]) === "BUY_MARKET_OUTCOME";
5501
5686
  const root = byId.get(strategy.root_node_id);
5502
5687
  if (isBuy(root))
5503
5688
  return [{ buy: root, usd: principal }];
@@ -5509,7 +5694,7 @@ var require_minimumOrder = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5509
5694
  const node = byId.get(id);
5510
5695
  if (!isBuy(node))
5511
5696
  continue;
5512
- const pct = group.mode === "SPLIT_100" ? Number(_optionalChain([node, 'access', _266 => _266.action, 'optionalAccess', _267 => _267.allocation_pct])) : 100;
5697
+ const pct = group.mode === "SPLIT_100" ? Number(_optionalChain([node, 'access', _309 => _309.action, 'optionalAccess', _310 => _310.allocation_pct])) : 100;
5513
5698
  if (Number.isFinite(pct) && pct > 0)
5514
5699
  found.push({ buy: node, usd: principal * pct / 100 });
5515
5700
  }
@@ -5519,13 +5704,13 @@ var require_minimumOrder = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5519
5704
  function subMinimumEntryBuys(strategy, quoteOf) {
5520
5705
  const found = [];
5521
5706
  for (const { buy, usd } of entryBuys(strategy)) {
5522
- const target = _optionalChain([buy, 'access', _268 => _268.action, 'optionalAccess', _269 => _269.target]);
5523
- const market = _optionalChain([target, 'optionalAccess', _270 => _270.market]);
5707
+ const target = _optionalChain([buy, 'access', _311 => _311.action, 'optionalAccess', _312 => _312.target]);
5708
+ const market = _optionalChain([target, 'optionalAccess', _313 => _313.market]);
5524
5709
  if (!target || !market || target.venue !== "POLYMARKET")
5525
5710
  continue;
5526
5711
  const quote = quoteOf(buy);
5527
- const minShares = _optionalChain([quote, 'optionalAccess', _271 => _271.minShares]) !== void 0 && quote.minShares > 0 ? quote.minShares : polymarketConstants_1.CLOB_MIN_SHARES;
5528
- const entry = (0, roiReach_1.expectedEntry)(strategy, buy, () => _optionalChain([quote, 'optionalAccess', _272 => _272.ask]));
5712
+ const minShares = _optionalChain([quote, 'optionalAccess', _314 => _314.minShares]) !== void 0 && quote.minShares > 0 ? quote.minShares : polymarketConstants_1.CLOB_MIN_SHARES;
5713
+ const entry = (0, roiReach_1.expectedEntry)(strategy, buy, () => _optionalChain([quote, 'optionalAccess', _315 => _315.ask]));
5529
5714
  const price = typeof entry === "number" && entry > 0 && entry < 1 ? entry : void 0;
5530
5715
  const requiredUsd = Math.max(polymarketConstants_1.CLOB_MIN_USD, price === void 0 ? 0 : minShares * price);
5531
5716
  if (usd + 5e-3 >= requiredUsd)
@@ -5551,8 +5736,8 @@ var require_minimumOrder = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5551
5736
  return `${head}${why}. ${consequence} Raise initial_principal_usd or this buy's allocation_pct.`;
5552
5737
  }
5553
5738
  async function subMinimumEntryBuyWarnings(strategy, quoteOf) {
5554
- const tokenOf = (buy) => _nullishCoalesce(_optionalChain([buy, 'access', _273 => _273.action, 'optionalAccess', _274 => _274.target, 'optionalAccess', _275 => _275.market, 'optionalAccess', _276 => _276.token_id]), () => ( ""));
5555
- const tokens = new Set(entryBuys(strategy).filter(({ buy }) => _optionalChain([buy, 'access', _277 => _277.action, 'optionalAccess', _278 => _278.target, 'optionalAccess', _279 => _279.venue]) === "POLYMARKET").map(({ buy }) => tokenOf(buy)).filter(Boolean));
5739
+ const tokenOf = (buy) => _nullishCoalesce(_optionalChain([buy, 'access', _316 => _316.action, 'optionalAccess', _317 => _317.target, 'optionalAccess', _318 => _318.market, 'optionalAccess', _319 => _319.token_id]), () => ( ""));
5740
+ const tokens = new Set(entryBuys(strategy).filter(({ buy }) => _optionalChain([buy, 'access', _320 => _320.action, 'optionalAccess', _321 => _321.target, 'optionalAccess', _322 => _322.venue]) === "POLYMARKET").map(({ buy }) => tokenOf(buy)).filter(Boolean));
5556
5741
  const quotes = /* @__PURE__ */ new Map();
5557
5742
  await Promise.all([...tokens].map(async (token) => {
5558
5743
  try {
@@ -5633,7 +5818,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5633
5818
  }
5634
5819
  const needsMarket = mapped === "BUY" || mapped === "SELL";
5635
5820
  if (!needsMarket) {
5636
- if (_optionalChain([action, 'access', _280 => _280.target, 'access', _281 => _281.market, 'optionalAccess', _282 => _282.token_id])) {
5821
+ if (_optionalChain([action, 'access', _323 => _323.target, 'access', _324 => _324.market, 'optionalAccess', _325 => _325.token_id])) {
5637
5822
  throw new UnsupportedStrategy(`${context}: a ${mapped} action bound to a specific market can't be edited yet.`);
5638
5823
  }
5639
5824
  return {
@@ -5645,7 +5830,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5645
5830
  };
5646
5831
  }
5647
5832
  const market = action.target.market;
5648
- if (!_optionalChain([market, 'optionalAccess', _283 => _283.market_id]) || !market.token_id) {
5833
+ if (!_optionalChain([market, 'optionalAccess', _326 => _326.market_id]) || !market.token_id) {
5649
5834
  throw new UnsupportedStrategy(`${context}: ${mapped} action has no resolved market.`);
5650
5835
  }
5651
5836
  const outcome = decodeOutcome(market.outcome_token, action.target.venue);
@@ -5660,6 +5845,9 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5660
5845
  const condition = node.condition;
5661
5846
  if (!condition)
5662
5847
  throw new UnsupportedStrategy(`${context}: CONDITION node has no condition spec.`);
5848
+ if (condition.signal === "LIMIT_PRICE") {
5849
+ throw new UnsupportedStrategy(`${context}: Limit conditions are not supported by the edit assistant yet.`);
5850
+ }
5663
5851
  if (condition.conjuncts && condition.conjuncts.length > 0) {
5664
5852
  throw new UnsupportedStrategy(`${context}: AND-conditions are not supported by the edit assistant yet.`);
5665
5853
  }
@@ -5669,7 +5857,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5669
5857
  if (condition.reference && condition.reference.mode !== "SINCE_GROUP_START") {
5670
5858
  throw new UnsupportedStrategy(`${context}: reference mode "${condition.reference.mode}" is not supported by the edit assistant yet.`);
5671
5859
  }
5672
- if (_optionalChain([condition, 'access', _284 => _284.timing, 'optionalAccess', _285 => _285.mode]) === "ABSOLUTE_TIME" && !condition.timing.absolute_trigger_time_iso) {
5860
+ if (_optionalChain([condition, 'access', _327 => _327.timing, 'optionalAccess', _328 => _328.mode]) === "ABSOLUTE_TIME" && !condition.timing.absolute_trigger_time_iso) {
5673
5861
  throw new UnsupportedStrategy(`${context}: an absolute-time condition has no time.`);
5674
5862
  }
5675
5863
  if (!condition.watch.market_id) {
@@ -5691,8 +5879,8 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5691
5879
  signal: condition.signal,
5692
5880
  trigger: condition.trigger,
5693
5881
  threshold: condition.threshold,
5694
- seconds_before_close: condition.signal === "TIME_SINCE_GROUP_SECONDS" ? _nullishCoalesce(_optionalChain([condition, 'access', _286 => _286.timing, 'optionalAccess', _287 => _287.seconds_before_close]), () => ( null)) : null,
5695
- ..._optionalChain([condition, 'access', _288 => _288.timing, 'optionalAccess', _289 => _289.mode]) === "ABSOLUTE_TIME" ? { at: condition.timing.absolute_trigger_time_iso } : {}
5882
+ seconds_before_close: condition.signal === "TIME_SINCE_GROUP_SECONDS" ? _nullishCoalesce(_optionalChain([condition, 'access', _329 => _329.timing, 'optionalAccess', _330 => _330.seconds_before_close]), () => ( null)) : null,
5883
+ ..._optionalChain([condition, 'access', _331 => _331.timing, 'optionalAccess', _332 => _332.mode]) === "ABSOLUTE_TIME" ? { at: condition.timing.absolute_trigger_time_iso } : {}
5696
5884
  };
5697
5885
  }, decodeGroupActions = function(group, context) {
5698
5886
  return group.action_node_ids.map((id, i) => {
@@ -5703,10 +5891,10 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5703
5891
  });
5704
5892
  }, canonicalExitActionId = function(group) {
5705
5893
  const actionNodes = group.action_node_ids.map((id) => nodeById.get(id)).filter((n) => !!n);
5706
- const buy = actionNodes.find((n) => _optionalChain([n, 'access', _290 => _290.action, 'optionalAccess', _291 => _291.action_type]) === "BUY_MARKET_OUTCOME");
5894
+ const buy = actionNodes.find((n) => _optionalChain([n, 'access', _333 => _333.action, 'optionalAccess', _334 => _334.action_type]) === "BUY_MARKET_OUTCOME");
5707
5895
  if (buy)
5708
5896
  return buy.node_id;
5709
- const hold = actionNodes.find((n) => _optionalChain([n, 'access', _292 => _292.action, 'optionalAccess', _293 => _293.action_type]) === "HOLD");
5897
+ const hold = actionNodes.find((n) => _optionalChain([n, 'access', _335 => _335.action, 'optionalAccess', _336 => _336.action_type]) === "HOLD");
5710
5898
  if (hold)
5711
5899
  return hold.node_id;
5712
5900
  return null;
@@ -5714,8 +5902,8 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5714
5902
  if (seen.has(conditionId))
5715
5903
  return false;
5716
5904
  seen.add(conditionId);
5717
- for (const actionId of _nullishCoalesce(_optionalChain([groupByConditionId, 'access', _294 => _294.get, 'call', _295 => _295(conditionId), 'optionalAccess', _296 => _296.action_node_ids]), () => ( []))) {
5718
- if (_optionalChain([nodeById, 'access', _297 => _297.get, 'call', _298 => _298(actionId), 'optionalAccess', _299 => _299.action, 'optionalAccess', _300 => _300.action_type]) === "BUY_MARKET_OUTCOME")
5905
+ for (const actionId of _nullishCoalesce(_optionalChain([groupByConditionId, 'access', _337 => _337.get, 'call', _338 => _338(conditionId), 'optionalAccess', _339 => _339.action_node_ids]), () => ( []))) {
5906
+ if (_optionalChain([nodeById, 'access', _340 => _340.get, 'call', _341 => _341(actionId), 'optionalAccess', _342 => _342.action, 'optionalAccess', _343 => _343.action_type]) === "BUY_MARKET_OUTCOME")
5719
5907
  return true;
5720
5908
  if ((_nullishCoalesce(outgoingByAction.get(actionId), () => ( []))).some((child) => subtreeBuys(child, seen)))
5721
5909
  return true;
@@ -5724,7 +5912,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5724
5912
  }, walkChildren = function(group, ownerStageId) {
5725
5913
  const exitId = canonicalExitActionId(group);
5726
5914
  const actionNodes = group.action_node_ids.map((id) => nodeById.get(id));
5727
- const cashId = actionNodes.some((n) => _optionalChain([n, 'optionalAccess', _301 => _301.action, 'optionalAccess', _302 => _302.action_type]) === "BUY_MARKET_OUTCOME") ? _optionalChain([actionNodes, 'access', _303 => _303.find, 'call', _304 => _304((n) => _optionalChain([n, 'optionalAccess', _305 => _305.action, 'optionalAccess', _306 => _306.action_type]) === "HOLD"), 'optionalAccess', _307 => _307.node_id]) : void 0;
5915
+ const cashId = actionNodes.some((n) => _optionalChain([n, 'optionalAccess', _344 => _344.action, 'optionalAccess', _345 => _345.action_type]) === "BUY_MARKET_OUTCOME") ? _optionalChain([actionNodes, 'access', _346 => _346.find, 'call', _347 => _347((n) => _optionalChain([n, 'optionalAccess', _348 => _348.action, 'optionalAccess', _349 => _349.action_type]) === "HOLD"), 'optionalAccess', _350 => _350.node_id]) : void 0;
5728
5916
  for (const actionNodeId of group.action_node_ids) {
5729
5917
  const outgoing = _nullishCoalesce(outgoingByAction.get(actionNodeId), () => ( []));
5730
5918
  if (outgoing.length === 0)
@@ -5821,7 +6009,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5821
6009
  }
5822
6010
  const action = decodeAction(actionNode, `Root action ${i + 1}`);
5823
6011
  const previous = stages.find((st) => st.id === previousStageId);
5824
- const keptBack = action.action === "HOLD" && _optionalChain([previous, 'optionalAccess', _308 => _308.actions, 'access', _309 => _309.every, 'call', _310 => _310((a) => a.action === "BUY")]);
6012
+ const keptBack = action.action === "HOLD" && _optionalChain([previous, 'optionalAccess', _351 => _351.actions, 'access', _352 => _352.every, 'call', _353 => _353((a) => a.action === "BUY")]);
5825
6013
  const stageId = keptBack ? previous.id : nextStageId++;
5826
6014
  if (keptBack)
5827
6015
  previous.actions.push(action);
@@ -5843,9 +6031,9 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5843
6031
  throw new UnsupportedStrategy(`Unrecognized root node type "${rootNode.type}".`);
5844
6032
  }
5845
6033
  for (const pending of pendingTokenChecks) {
5846
- if (_optionalChain([outcomesByMarket, 'access', _311 => _311.get, 'call', _312 => _312(pending.marketId), 'optionalAccess', _313 => _313.has, 'call', _314 => _314(pending.label)]) || _optionalChain([outcomesByMarket, 'access', _315 => _315.get, 'call', _316 => _316(pending.marketId), 'optionalAccess', _317 => _317.has, 'call', _318 => _318(pending.side)]))
6034
+ if (_optionalChain([outcomesByMarket, 'access', _354 => _354.get, 'call', _355 => _355(pending.marketId), 'optionalAccess', _356 => _356.has, 'call', _357 => _357(pending.label)]) || _optionalChain([outcomesByMarket, 'access', _358 => _358.get, 'call', _359 => _359(pending.marketId), 'optionalAccess', _360 => _360.has, 'call', _361 => _361(pending.side)]))
5847
6035
  continue;
5848
- const externalToken = _optionalChain([resolveWatchToken, 'optionalCall', _319 => _319(pending.marketId, pending.side)]);
6036
+ const externalToken = _optionalChain([resolveWatchToken, 'optionalCall', _362 => _362(pending.marketId, pending.side)]);
5849
6037
  if (externalToken) {
5850
6038
  registerOutcome(pending.marketId, pending.side, externalToken);
5851
6039
  continue;
@@ -5856,7 +6044,7 @@ var require_strategyPlanDecompile = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5856
6044
  throw new UnsupportedStrategy("Strategy has a shape (e.g. a disconnected or shared sub-graph) the edit assistant can't represent yet.");
5857
6045
  }
5858
6046
  for (const market of markets) {
5859
- market.outcomes = [..._nullishCoalesce(_optionalChain([outcomesByMarket, 'access', _320 => _320.get, 'call', _321 => _321(market.marketId), 'optionalAccess', _322 => _322.values, 'call', _323 => _323()]), () => ( []))];
6047
+ market.outcomes = [..._nullishCoalesce(_optionalChain([outcomesByMarket, 'access', _363 => _363.get, 'call', _364 => _364(market.marketId), 'optionalAccess', _365 => _365.values, 'call', _366 => _366()]), () => ( []))];
5860
6048
  }
5861
6049
  const plan = {
5862
6050
  strategy_id: strategy.strategy_id,
@@ -5881,7 +6069,7 @@ var require_relatedMarketExit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5881
6069
  exports.addWatchedMarketExit = addWatchedMarketExit;
5882
6070
  var strategyPlan_1 = require_strategyPlan();
5883
6071
  function planUsesMarket(plan, marketNumber) {
5884
- return plan.stages.some((s) => _optionalChain([s, 'access', _324 => _324.when, 'optionalAccess', _325 => _325.watch_market]) === marketNumber || s.actions.some((a) => a.market === marketNumber));
6072
+ return plan.stages.some((s) => _optionalChain([s, 'access', _367 => _367.when, 'optionalAccess', _368 => _368.watch_market]) === marketNumber || s.actions.some((a) => a.market === marketNumber));
5885
6073
  }
5886
6074
  function isFullExitOff(stage, entryId) {
5887
6075
  return stage.after === entryId && stage.when !== null && stage.actions.length === 1 && stage.actions[0].action === "MOVE_TO_WALLET" && stage.actions[0].pct === 100;
@@ -5928,7 +6116,7 @@ var require_relatedMarketExit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5928
6116
  if (existingIndex >= 0 && planUsesMarket(plan, marketNumber)) {
5929
6117
  return { added: false, reason: "the plan already trades or watches that market" };
5930
6118
  }
5931
- const current = _optionalChain([exit, 'access', _326 => _326.market, 'access', _327 => _327.outcomes, 'access', _328 => _328.find, 'call', _329 => _329((o) => o.label.toUpperCase() === exit.side), 'optionalAccess', _330 => _330.currentPrice]);
6119
+ const current = _optionalChain([exit, 'access', _369 => _369.market, 'access', _370 => _370.outcomes, 'access', _371 => _371.find, 'call', _372 => _372((o) => o.label.toUpperCase() === exit.side), 'optionalAccess', _373 => _373.currentPrice]);
5932
6120
  if (typeof current === "number") {
5933
6121
  const alreadyTrue = exit.trigger === "CROSS_ABOVE" ? current >= exit.threshold : current <= exit.threshold;
5934
6122
  if (alreadyTrue) {
@@ -5989,7 +6177,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
5989
6177
  positions.push({ stageId: stage.id, action });
5990
6178
  }
5991
6179
  }
5992
- const buysOf = (stageId) => _nullishCoalesce(_optionalChain([byId, 'access', _331 => _331.get, 'call', _332 => _332(stageId), 'optionalAccess', _333 => _333.actions, 'access', _334 => _334.filter, 'call', _335 => _335((a) => a.action === "BUY" && a.market !== null), 'access', _336 => _336.map, 'call', _337 => _337((a) => a.market)]), () => ( []));
6180
+ const buysOf = (stageId) => _nullishCoalesce(_optionalChain([byId, 'access', _374 => _374.get, 'call', _375 => _375(stageId), 'optionalAccess', _376 => _376.actions, 'access', _377 => _377.filter, 'call', _378 => _378((a) => a.action === "BUY" && a.market !== null), 'access', _379 => _379.map, 'call', _380 => _380((a) => a.market)]), () => ( []));
5993
6181
  const soldMarket = (sale, stage, bought) => {
5994
6182
  if (sale.market !== null)
5995
6183
  return sale.market;
@@ -6024,7 +6212,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6024
6212
  if (!watched)
6025
6213
  return { applied: false, reason: `market ${exit.watchMarket} is not in the plan` };
6026
6214
  const usd = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(watched.venue);
6027
- const current = _nullishCoalesce(_optionalChain([watched, 'access', _338 => _338.outcomes, 'access', _339 => _339.find, 'call', _340 => _340((o) => o.label.toUpperCase() === (usd ? exit.side === "NO" ? "SHORT" : "LONG" : exit.side)), 'optionalAccess', _341 => _341.currentPrice]), () => ( (usd ? _optionalChain([watched, 'access', _342 => _342.outcomes, 'access', _343 => _343[0], 'optionalAccess', _344 => _344.currentPrice]) : void 0)));
6215
+ const current = _nullishCoalesce(_optionalChain([watched, 'access', _381 => _381.outcomes, 'access', _382 => _382.find, 'call', _383 => _383((o) => o.label.toUpperCase() === (usd ? exit.side === "NO" ? "SHORT" : "LONG" : exit.side)), 'optionalAccess', _384 => _384.currentPrice]), () => ( (usd ? _optionalChain([watched, 'access', _385 => _385.outcomes, 'access', _386 => _386[0], 'optionalAccess', _387 => _387.currentPrice]) : void 0)));
6028
6216
  const alreadyPast = (price) => typeof price === "number" && (exit.trigger === "CROSS_ABOVE" ? price >= exit.threshold : price <= exit.threshold);
6029
6217
  const isSameCondition = (stage) => {
6030
6218
  const when = stage.when;
@@ -6101,7 +6289,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6101
6289
  const side = _nullishCoalesce(buy.side, () => ( "YES"));
6102
6290
  const pricing = (0, strategyShapes_1.exitPricingForRef)(markets, request.market - 1, side);
6103
6291
  const soleBuy = buys.length === 1;
6104
- const stageFieldsInUse = soleBuy && ((_nullishCoalesce(_optionalChain([stage, 'access', _345 => _345.exit_tiers, 'optionalAccess', _346 => _346.length]), () => ( 0))) > 0 || typeof stage.exit_stop_loss_threshold === "number" || typeof stage.exit_seconds_before_close === "number");
6292
+ const stageFieldsInUse = soleBuy && ((_nullishCoalesce(_optionalChain([stage, 'access', _388 => _388.exit_tiers, 'optionalAccess', _389 => _389.length]), () => ( 0))) > 0 || typeof stage.exit_stop_loss_threshold === "number" || typeof stage.exit_seconds_before_close === "number");
6105
6293
  const authored = stages.filter((s) => {
6106
6294
  if (s.after !== stage.id || !s.when || s.when.watch_market !== request.market || s.when.user_stated === true || !isExitOnly(s))
6107
6295
  return false;
@@ -6109,8 +6297,8 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6109
6297
  });
6110
6298
  const heldTrigger = (s) => !(0, conditionalActionTypes_1.isUsdPricedVenueKey)(market.venue) && s.when.watch_side !== side ? flip(s.when.trigger) : s.when.trigger;
6111
6299
  const takesProfit = (s) => s.when.signal === "ROI_PCT" ? s.when.trigger === "CROSS_ABOVE" : heldTrigger(s) === (0, strategyShapes_1.takeProfitTrigger)(pricing);
6112
- const hasTakeProfit = soleBuy && (_nullishCoalesce(_optionalChain([stage, 'access', _347 => _347.exit_tiers, 'optionalAccess', _348 => _348.length]), () => ( 0))) > 0 || typeof _optionalChain([buy, 'access', _349 => _349.exits, 'optionalAccess', _350 => _350.take_profit_roi]) === "number" || authored.some((s) => takesProfit(s));
6113
- const hasStopLoss = soleBuy && typeof stage.exit_stop_loss_threshold === "number" || typeof _optionalChain([buy, 'access', _351 => _351.exits, 'optionalAccess', _352 => _352.stop_loss_roi]) === "number" || authored.some((s) => !takesProfit(s));
6300
+ const hasTakeProfit = soleBuy && (_nullishCoalesce(_optionalChain([stage, 'access', _390 => _390.exit_tiers, 'optionalAccess', _391 => _391.length]), () => ( 0))) > 0 || typeof _optionalChain([buy, 'access', _392 => _392.exits, 'optionalAccess', _393 => _393.take_profit_roi]) === "number" || authored.some((s) => takesProfit(s));
6301
+ const hasStopLoss = soleBuy && typeof stage.exit_stop_loss_threshold === "number" || typeof _optionalChain([buy, 'access', _394 => _394.exits, 'optionalAccess', _395 => _395.stop_loss_roi]) === "number" || authored.some((s) => !takesProfit(s));
6114
6302
  const takeProfit = !hasTakeProfit && typeof request.takeProfitRoi === "number" && request.takeProfitRoi > 0 ? request.takeProfitRoi : null;
6115
6303
  const stopLoss = !hasStopLoss && typeof request.stopLossRoi === "number" && request.stopLossRoi < 0 ? request.stopLossRoi : null;
6116
6304
  if (takeProfit === null && stopLoss === null)
@@ -6126,9 +6314,9 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6126
6314
  stage.exit_stop_loss_threshold = stopLoss;
6127
6315
  } else {
6128
6316
  buy.exits = {
6129
- take_profit_roi: _nullishCoalesce(_optionalChain([buy, 'access', _353 => _353.exits, 'optionalAccess', _354 => _354.take_profit_roi]), () => ( takeProfit)),
6130
- stop_loss_roi: _nullishCoalesce(_optionalChain([buy, 'access', _355 => _355.exits, 'optionalAccess', _356 => _356.stop_loss_roi]), () => ( stopLoss)),
6131
- seconds_before_close: _nullishCoalesce(_optionalChain([buy, 'access', _357 => _357.exits, 'optionalAccess', _358 => _358.seconds_before_close]), () => ( null))
6317
+ take_profit_roi: _nullishCoalesce(_optionalChain([buy, 'access', _396 => _396.exits, 'optionalAccess', _397 => _397.take_profit_roi]), () => ( takeProfit)),
6318
+ stop_loss_roi: _nullishCoalesce(_optionalChain([buy, 'access', _398 => _398.exits, 'optionalAccess', _399 => _399.stop_loss_roi]), () => ( stopLoss)),
6319
+ seconds_before_close: _nullishCoalesce(_optionalChain([buy, 'access', _400 => _400.exits, 'optionalAccess', _401 => _401.seconds_before_close]), () => ( null))
6132
6320
  };
6133
6321
  }
6134
6322
  filled.push({ market: request.market, takeProfitRoi: takeProfit, stopLossRoi: stopLoss });
@@ -6150,7 +6338,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6150
6338
  }
6151
6339
  let removed = dropped.size;
6152
6340
  const stages = plan.stages.filter((s) => !dropped.has(s.id)).map((s) => {
6153
- const fields = (_nullishCoalesce(_optionalChain([s, 'access', _359 => _359.exit_tiers, 'optionalAccess', _360 => _360.length]), () => ( 0))) > 0 || typeof s.exit_stop_loss_threshold === "number" || typeof s.exit_seconds_before_close === "number";
6341
+ const fields = (_nullishCoalesce(_optionalChain([s, 'access', _402 => _402.exit_tiers, 'optionalAccess', _403 => _403.length]), () => ( 0))) > 0 || typeof s.exit_stop_loss_threshold === "number" || typeof s.exit_seconds_before_close === "number";
6154
6342
  const buyExits = s.actions.filter((a) => (0, strategyShapes_1.hasPositionExits)(a.exits)).length;
6155
6343
  removed += (fields ? 1 : 0) + buyExits;
6156
6344
  return {
@@ -6169,7 +6357,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6169
6357
  return { plan, sized: 0 };
6170
6358
  const stages = plan.stages.map((s) => ({ ...s, actions: s.actions.map((a) => ({ ...a })) }));
6171
6359
  const byId = new Map(stages.map((s) => [s.id, s]));
6172
- const sameMarket = (a, b) => a === b || !!markets[a - 1] && _optionalChain([markets, 'access', _361 => _361[a - 1], 'optionalAccess', _362 => _362.marketId]) === _optionalChain([markets, 'access', _363 => _363[b - 1], 'optionalAccess', _364 => _364.marketId]);
6360
+ const sameMarket = (a, b) => a === b || !!markets[a - 1] && _optionalChain([markets, 'access', _404 => _404[a - 1], 'optionalAccess', _405 => _405.marketId]) === _optionalChain([markets, 'access', _406 => _406[b - 1], 'optionalAccess', _407 => _407.marketId]);
6173
6361
  const saleAt = (stage) => {
6174
6362
  const when = stage.when;
6175
6363
  if (!when || !stage.actions.some((a) => a.action === "SELL" || a.action === "MOVE_TO_WALLET"))
@@ -6255,7 +6443,7 @@ var require_positionExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6255
6443
  return { applied: true, plan: { ...plan, stages: [...plan.stages, deadline2] } };
6256
6444
  }
6257
6445
  const gate = roots.length === 1 ? roots[0] : void 0;
6258
- if (!_optionalChain([gate, 'optionalAccess', _365 => _365.when]))
6446
+ if (!_optionalChain([gate, 'optionalAccess', _408 => _408.when]))
6259
6447
  return { applied: false, reason: "the strategy enters at once, with no condition to wait for" };
6260
6448
  if (!gate.actions.some((a) => a.action === "BUY"))
6261
6449
  return { applied: false, reason: "its first condition buys nothing" };
@@ -6306,14 +6494,14 @@ var require_ladderExits = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6306
6494
  function wholePositionExits(plan, markets) {
6307
6495
  let stages = plan.stages.map((s) => ({ ...s, actions: s.actions.map((a) => ({ ...a })) }));
6308
6496
  const childrenOf = (id) => stages.filter((s) => s.after === id);
6309
- const keyOf = (n) => typeof n === "number" ? _nullishCoalesce(_optionalChain([markets, 'access', _366 => _366[n - 1], 'optionalAccess', _367 => _367.marketId]), () => ( `#${n}`)) : null;
6310
- const usdAt = (n) => (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([markets, 'access', _368 => _368[n - 1], 'optionalAccess', _369 => _369.venue]));
6497
+ const keyOf = (n) => typeof n === "number" ? _nullishCoalesce(_optionalChain([markets, 'access', _409 => _409[n - 1], 'optionalAccess', _410 => _410.marketId]), () => ( `#${n}`)) : null;
6498
+ const usdAt = (n) => (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([markets, 'access', _411 => _411[n - 1], 'optionalAccess', _412 => _412.venue]));
6311
6499
  const buysOf = (stage, key, side) => stage.actions.some((a) => a.action === "BUY" && keyOf(a.market) === key && (_nullishCoalesce(a.side, () => ( "YES"))) === side);
6312
6500
  const buysAnything = (stage) => stage.actions.some((a) => a.action === "BUY");
6313
6501
  const soldKey = (sale, stage, held) => {
6314
6502
  if (sale.market !== null && sale.market !== void 0)
6315
6503
  return keyOf(sale.market);
6316
- const watched = keyOf(_optionalChain([stage, 'access', _370 => _370.when, 'optionalAccess', _371 => _371.watch_market]));
6504
+ const watched = keyOf(_optionalChain([stage, 'access', _413 => _413.when, 'optionalAccess', _414 => _414.watch_market]));
6317
6505
  if (watched && held.includes(watched))
6318
6506
  return watched;
6319
6507
  return held.length === 1 ? held[0] : null;
@@ -6736,13 +6924,13 @@ var require_positionRecipe = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6736
6924
  const heldLevel = (p, when) => {
6737
6925
  if (when.watch_market !== p.position.market || when.signal !== "IMPLIED_PROBABILITY" && when.signal !== "PRICE_USD")
6738
6926
  return void 0;
6739
- return (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _372 => _372(p.position.market), 'optionalAccess', _373 => _373.venue])) || when.watch_side === p.position.side ? when.threshold : 1 - when.threshold;
6927
+ return (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _415 => _415(p.position.market), 'optionalAccess', _416 => _416.venue])) || when.watch_side === p.position.side ? when.threshold : 1 - when.threshold;
6740
6928
  };
6741
6929
  const trueAt = (p, when, price) => {
6742
6930
  const level = heldLevel(p, when);
6743
6931
  if (level === void 0 || price === void 0)
6744
6932
  return false;
6745
- const held = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _374 => _374(p.position.market), 'optionalAccess', _375 => _375.venue])) || when.watch_side === p.position.side;
6933
+ const held = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _417 => _417(p.position.market), 'optionalAccess', _418 => _418.venue])) || when.watch_side === p.position.side;
6746
6934
  return when.trigger === "CROSS_ABOVE" === held ? price >= level : price <= level;
6747
6935
  };
6748
6936
  const firstFill = (p) => {
@@ -6792,7 +6980,7 @@ var require_positionRecipe = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6792
6980
  };
6793
6981
  const exitTree = (p, buyStage, added = []) => {
6794
6982
  const fill = firstFill(p);
6795
- const armedAt = (when) => trueAt(p, when, fill) ? _nullishCoalesce(_optionalChain([added, 'access', _376 => _376.find, 'call', _377 => _377((a) => a.level !== void 0 && !trueAt(p, when, a.level)), 'optionalAccess', _378 => _378.stage]), () => ( buyStage)) : buyStage;
6983
+ const armedAt = (when) => trueAt(p, when, fill) ? _nullishCoalesce(_optionalChain([added, 'access', _419 => _419.find, 'call', _420 => _420((a) => a.level !== void 0 && !trueAt(p, when, a.level)), 'optionalAccess', _421 => _421.stage]), () => ( buyStage)) : buyStage;
6796
6984
  const holders = [buyStage];
6797
6985
  const chain = (ordered) => {
6798
6986
  let parent = ordered.length > 0 ? armedAt(ordered[0].when) : buyStage;
@@ -6828,11 +7016,11 @@ var require_positionRecipe = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6828
7016
  };
6829
7017
  const cashBack = () => ({ action: "MOVE_TO_WALLET", market: null, side: null, pct: 100 });
6830
7018
  const beforeEntry = (group) => {
6831
- const gate = _optionalChain([group, 'access', _379 => _379[0], 'optionalAccess', _380 => _380.entry, 'access', _381 => _381[0]]);
7019
+ const gate = _optionalChain([group, 'access', _422 => _422[0], 'optionalAccess', _423 => _423.entry, 'access', _424 => _424[0]]);
6832
7020
  const conditions = /* @__PURE__ */ new Map();
6833
7021
  for (const p of group) {
6834
7022
  const own = p.position.market;
6835
- const usd = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _382 => _382(own), 'optionalAccess', _383 => _383.venue]));
7023
+ const usd = (0, conditionalActionTypes_1.isUsdPricedVenueKey)(_optionalChain([marketAt, 'call', _425 => _425(own), 'optionalAccess', _426 => _426.venue]));
6836
7024
  const stop = (0, strategyShapes_1.stopLossTrigger)((0, strategyShapes_1.exitPricingForRef)(markets, own - 1, p.position.side));
6837
7025
  for (const when of p.fulls) {
6838
7026
  if (when.signal === "ROI_PCT")
@@ -6973,7 +7161,7 @@ var require_alignExitWatchSides = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
6973
7161
  if (!parent)
6974
7162
  break;
6975
7163
  const buy = parent.actions.find((a) => a.action === "BUY" && a.market === when.watch_market);
6976
- if (_optionalChain([buy, 'optionalAccess', _384 => _384.side])) {
7164
+ if (_optionalChain([buy, 'optionalAccess', _427 => _427.side])) {
6977
7165
  heldSide = buy.side;
6978
7166
  break;
6979
7167
  }
@@ -7029,8 +7217,8 @@ var require_summarizeStrategyEdit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7029
7217
  continue;
7030
7218
  out.push({
7031
7219
  actionType: node.action.action_type,
7032
- marketId: _nullishCoalesce(_optionalChain([node, 'access', _385 => _385.action, 'access', _386 => _386.target, 'access', _387 => _387.market, 'optionalAccess', _388 => _388.market_id]), () => ( null)),
7033
- outcome: _nullishCoalesce(_optionalChain([node, 'access', _389 => _389.action, 'access', _390 => _390.target, 'access', _391 => _391.market, 'optionalAccess', _392 => _392.outcome_token]), () => ( null)),
7220
+ marketId: _nullishCoalesce(_optionalChain([node, 'access', _428 => _428.action, 'access', _429 => _429.target, 'access', _430 => _430.market, 'optionalAccess', _431 => _431.market_id]), () => ( null)),
7221
+ outcome: _nullishCoalesce(_optionalChain([node, 'access', _432 => _432.action, 'access', _433 => _433.target, 'access', _434 => _434.market, 'optionalAccess', _435 => _435.outcome_token]), () => ( null)),
7034
7222
  pct: _nullishCoalesce(node.action.allocation_pct, () => ( 100)),
7035
7223
  venue: node.action.target.venue
7036
7224
  });
@@ -7067,7 +7255,7 @@ var require_summarizeStrategyEdit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7067
7255
  function marketLabel(marketId, marketTitles) {
7068
7256
  if (!marketId)
7069
7257
  return null;
7070
- return _nullishCoalesce(_optionalChain([marketTitles, 'optionalAccess', _393 => _393[marketId]]), () => ( marketId));
7258
+ return _nullishCoalesce(_optionalChain([marketTitles, 'optionalAccess', _436 => _436[marketId]]), () => ( marketId));
7071
7259
  }
7072
7260
  function describeAction(a, marketTitles) {
7073
7261
  const verb = _nullishCoalesce(ACTION_VERB[a.actionType], () => ( a.actionType));
@@ -7080,8 +7268,10 @@ var require_summarizeStrategyEdit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7080
7268
  function describeCondition(c, marketTitles) {
7081
7269
  const label = _nullishCoalesce(marketLabel(c.marketId, marketTitles), () => ( c.marketId));
7082
7270
  const signalLabel = c.signal === "PRICE_USD" && (0, conditionalActionTypes_1.isHyperliquidVenueKey)(c.venue) ? "price (USD)" : _nullishCoalesce(SIGNAL_LABEL[c.signal], () => ( c.signal));
7083
- const dir = c.trigger === "CROSS_ABOVE" ? "crosses above" : "crosses below";
7084
7271
  const side = isSoleOutcome(c.side, c.venue) ? "" : ` (${c.side})`;
7272
+ if (c.signal === "LIMIT_PRICE")
7273
+ return `limit order on "${label}"${side} at ${c.threshold}`;
7274
+ const dir = c.trigger === "CROSS_ABOVE" ? "crosses above" : "crosses below";
7085
7275
  return `${signalLabel} of "${label}"${side} ${dir} ${c.threshold}`;
7086
7276
  }
7087
7277
  function diffActions(before, after, marketTitles, lines) {
@@ -7193,9 +7383,9 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7193
7383
  return { seconds_before_close: Number(c.threshold) };
7194
7384
  if (c.signal !== "TIME_SINCE_GROUP_SECONDS")
7195
7385
  return void 0;
7196
- if (_optionalChain([c, 'access', _394 => _394.timing, 'optionalAccess', _395 => _395.mode]) === "ABSOLUTE_TIME" && c.timing.absolute_trigger_time_iso)
7386
+ if (_optionalChain([c, 'access', _437 => _437.timing, 'optionalAccess', _438 => _438.mode]) === "ABSOLUTE_TIME" && c.timing.absolute_trigger_time_iso)
7197
7387
  return { at: c.timing.absolute_trigger_time_iso };
7198
- if (_optionalChain([c, 'access', _396 => _396.timing, 'optionalAccess', _397 => _397.mode]) === "BEFORE_CLOSE")
7388
+ if (_optionalChain([c, 'access', _439 => _439.timing, 'optionalAccess', _440 => _440.mode]) === "BEFORE_CLOSE")
7199
7389
  return { seconds_before_close: Number(_nullishCoalesce(c.timing.seconds_before_close, () => ( 0))) };
7200
7390
  return { seconds_after: Number(c.threshold) };
7201
7391
  }
@@ -7211,7 +7401,7 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7211
7401
  for (const id of group.action_node_ids)
7212
7402
  parentOf.set(id, group.condition_node_id);
7213
7403
  }
7214
- const isBuy = (n) => _optionalChain([n, 'optionalAccess', _398 => _398.action, 'optionalAccess', _399 => _399.action_type]) === "BUY_MARKET_OUTCOME";
7404
+ const isBuy = (n) => _optionalChain([n, 'optionalAccess', _441 => _441.action, 'optionalAccess', _442 => _442.action_type]) === "BUY_MARKET_OUTCOME";
7215
7405
  const childrenOf = /* @__PURE__ */ new Map();
7216
7406
  for (const [child, parent] of parentOf)
7217
7407
  childrenOf.set(parent, [..._nullishCoalesce(childrenOf.get(parent), () => ( [])), child]);
@@ -7244,7 +7434,7 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7244
7434
  const signalExits = /* @__PURE__ */ new Map();
7245
7435
  for (const node of nodes) {
7246
7436
  const c = node.condition;
7247
- if (node.type !== "CONDITION" || !_optionalChain([c, 'optionalAccess', _400 => _400.watch]))
7437
+ if (node.type !== "CONDITION" || !_optionalChain([c, 'optionalAccess', _443 => _443.watch]))
7248
7438
  continue;
7249
7439
  if ((0, strategyPlan_1.isSyntheticRootGate)(String(c.signal), String(c.trigger), Number(c.threshold)))
7250
7440
  continue;
@@ -7257,18 +7447,18 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7257
7447
  const onYes = unit === "ODDS" && token === "NO" ? { direction: flip(watched), level: Number((1 - c.threshold).toFixed(4)) } : { direction: watched, level: c.threshold };
7258
7448
  const base = { market_id: marketId, title: titleOf(marketId), venue, unit };
7259
7449
  const timing = timeOf(c);
7260
- const holdsForBuy = actions.length > 0 && actions.every((a) => _optionalChain([a, 'access', _401 => _401.action, 'optionalAccess', _402 => _402.action_type]) === "HOLD") && actions.some((a) => leadsToBuy(a.node_id));
7450
+ const holdsForBuy = actions.length > 0 && actions.every((a) => _optionalChain([a, 'access', _444 => _444.action, 'optionalAccess', _445 => _445.action_type]) === "HOLD") && actions.some((a) => leadsToBuy(a.node_id));
7261
7451
  if (actions.some(isBuy) || holdsForBuy) {
7262
7452
  waits.push(timing ? { kind: "WAIT", market_id: marketId, title: base.title, venue, ...timing } : { kind: "WAIT", ...base, ...onYes });
7263
7453
  continue;
7264
7454
  }
7265
- const sales = actions.filter((a) => _optionalChain([a, 'access', _403 => _403.action, 'optionalAccess', _404 => _404.action_type]) === "MOVE_TO_WALLET" || _optionalChain([a, 'access', _405 => _405.action, 'optionalAccess', _406 => _406.action_type]) === "SELL_MARKET_OUTCOME");
7266
- if (sales.length === 0 || !actions.every((a) => sales.includes(a) || _optionalChain([a, 'access', _407 => _407.action, 'optionalAccess', _408 => _408.action_type]) === "HOLD"))
7455
+ const sales = actions.filter((a) => _optionalChain([a, 'access', _446 => _446.action, 'optionalAccess', _447 => _447.action_type]) === "MOVE_TO_WALLET" || _optionalChain([a, 'access', _448 => _448.action, 'optionalAccess', _449 => _449.action_type]) === "SELL_MARKET_OUTCOME");
7456
+ if (sales.length === 0 || !actions.every((a) => sales.includes(a) || _optionalChain([a, 'access', _450 => _450.action, 'optionalAccess', _451 => _451.action_type]) === "HOLD"))
7267
7457
  continue;
7268
- const share = sales.length < actions.length ? sales.reduce((sum, a) => sum + Number(_nullishCoalesce(_optionalChain([a, 'access', _409 => _409.action, 'optionalAccess', _410 => _410.allocation_pct]), () => ( 0))), 0) : void 0;
7458
+ const share = sales.length < actions.length ? sales.reduce((sum, a) => sum + Number(_nullishCoalesce(_optionalChain([a, 'access', _452 => _452.action, 'optionalAccess', _453 => _453.allocation_pct]), () => ( 0))), 0) : void 0;
7269
7459
  const partial = share !== void 0 ? { share } : {};
7270
7460
  const position = positionAbove(node.node_id);
7271
- const held = _optionalChain([position, 'optionalAccess', _411 => _411.action, 'optionalAccess', _412 => _412.target, 'optionalAccess', _413 => _413.market]);
7461
+ const held = _optionalChain([position, 'optionalAccess', _454 => _454.action, 'optionalAccess', _455 => _455.target, 'optionalAccess', _456 => _456.market]);
7272
7462
  if (timing) {
7273
7463
  ownExits.push({ kind: "TIME_EXIT", market_id: marketId, title: base.title, venue, ...timing, ...held ? { sells: titleOf(held.market_id) } : {}, ...partial });
7274
7464
  continue;
@@ -7300,8 +7490,8 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7300
7490
  const seenBuys = /* @__PURE__ */ new Set();
7301
7491
  const buyRules = [];
7302
7492
  for (const node of buys) {
7303
- const target = _optionalChain([node, 'access', _414 => _414.action, 'optionalAccess', _415 => _415.target]);
7304
- const market = _optionalChain([target, 'optionalAccess', _416 => _416.market]);
7493
+ const target = _optionalChain([node, 'access', _457 => _457.action, 'optionalAccess', _458 => _458.target]);
7494
+ const market = _optionalChain([target, 'optionalAccess', _459 => _459.market]);
7305
7495
  if (!market)
7306
7496
  continue;
7307
7497
  const key = `${market.market_id}|${market.outcome_token}`;
@@ -7312,15 +7502,15 @@ var require_strategyThesis = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7312
7502
  kind: "BUY",
7313
7503
  market_id: market.market_id,
7314
7504
  title: titleOf(market.market_id),
7315
- venue: String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _417 => _417.venue]), () => ( ""))),
7505
+ venue: String(_nullishCoalesce(_optionalChain([target, 'optionalAccess', _460 => _460.venue]), () => ( ""))),
7316
7506
  position: String(market.outcome_token).toUpperCase(),
7317
- ...typeof _optionalChain([target, 'optionalAccess', _418 => _418.leverage]) === "number" ? { leverage: target.leverage } : {}
7507
+ ...typeof _optionalChain([target, 'optionalAccess', _461 => _461.leverage]) === "number" ? { leverage: target.leverage } : {}
7318
7508
  });
7319
7509
  }
7320
7510
  const exits = [...signalExits.values()].map(({ rule, positions }) => {
7321
7511
  if ((positions.size === 0 || positions.size >= buys.length) && rule.share === void 0)
7322
7512
  return rule;
7323
- const sold = [...positions].map((id) => _optionalChain([byId, 'access', _419 => _419.get, 'call', _420 => _420(id), 'optionalAccess', _421 => _421.action, 'optionalAccess', _422 => _422.target, 'optionalAccess', _423 => _423.market, 'optionalAccess', _424 => _424.market_id])).filter((id) => !!id);
7513
+ const sold = [...positions].map((id) => _optionalChain([byId, 'access', _462 => _462.get, 'call', _463 => _463(id), 'optionalAccess', _464 => _464.action, 'optionalAccess', _465 => _465.target, 'optionalAccess', _466 => _466.market, 'optionalAccess', _467 => _467.market_id])).filter((id) => !!id);
7324
7514
  return { ...rule, kind: "SELL", sells: sold.length > 0 ? sold.map(titleOf).join(" and ") : "everything" };
7325
7515
  });
7326
7516
  return [...waits, ...buyRules, ...ownExits, ...exits];
@@ -7415,7 +7605,7 @@ var require_constants = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7415
7605
  exports.HYPERLIQUID_TESTNET_API_URL = "https://api.hyperliquid-testnet.xyz";
7416
7606
  exports.HYPERLIQUID_MAINNET_WS_URL = "wss://api.hyperliquid.xyz/ws";
7417
7607
  exports.HYPERLIQUID_TESTNET_WS_URL = "wss://api.hyperliquid-testnet.xyz/ws";
7418
- var hyperliquidNetworkFromEnv = (env = process.env) => _optionalChain([env, 'access', _425 => _425.HYPERLIQUID_NETWORK, 'optionalAccess', _426 => _426.trim, 'call', _427 => _427(), 'access', _428 => _428.toLowerCase, 'call', _429 => _429()]) === "testnet" ? "testnet" : "mainnet";
7608
+ var hyperliquidNetworkFromEnv = (env = process.env) => _optionalChain([env, 'access', _468 => _468.HYPERLIQUID_NETWORK, 'optionalAccess', _469 => _469.trim, 'call', _470 => _470(), 'access', _471 => _471.toLowerCase, 'call', _472 => _472()]) === "testnet" ? "testnet" : "mainnet";
7419
7609
  exports.hyperliquidNetworkFromEnv = hyperliquidNetworkFromEnv;
7420
7610
  var hyperliquidApiUrl = (network) => network === "testnet" ? exports.HYPERLIQUID_TESTNET_API_URL : exports.HYPERLIQUID_MAINNET_API_URL;
7421
7611
  exports.hyperliquidApiUrl = hyperliquidApiUrl;
@@ -7459,6 +7649,7 @@ var require_schemaDoc = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7459
7649
  "PRICE_USD",
7460
7650
  "ROI_PCT",
7461
7651
  "PNL_USD",
7652
+ "LIMIT_PRICE",
7462
7653
  "TIME_SINCE_GROUP_SECONDS",
7463
7654
  "TIME_TO_RESOLUTION_SECONDS"
7464
7655
  ];
@@ -7480,6 +7671,14 @@ var require_schemaDoc = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
7480
7671
  //
7481
7672
  // Do not author PNL_USD: it is compared as a raw absolute value. Use ROI_PCT,
7482
7673
  // or an absolute price.
7674
+ //
7675
+ // LIMIT_PRICE is a Limit condition: a resting limit order on Polymarket's
7676
+ // order book for the ONE buy or sell in its SINGLE group, at \`threshold\`
7677
+ // (the order price, strictly between 0 and 1). It is met when the order has
7678
+ // filled. A buy uses CROSS_BELOW (this price or lower), a sell CROSS_ABOVE
7679
+ // (this price or higher), and \`watch\` is the trade's own market and token.
7680
+ // A price condition followed by a buy is NOT a limit order: it sends a market
7681
+ // order once the price is seen there. See Example 7.
7483
7682
 
7484
7683
  export type StrategyNodeType = "CONDITION" | "ACTION";
7485
7684
  export type StrategyVenue = ${venueUnion};
@@ -7507,6 +7706,10 @@ export interface StrategyConditionSpec {
7507
7706
  // ROI_PCT needs none: it always measures the position bought above the condition.
7508
7707
  reference?: { mode: StrategyReferenceMode; fixed_reference_value?: number; };
7509
7708
  stabilizers?: { hysteresis_delta?: number; cooldown_seconds?: number; };
7709
+ // LIMIT_PRICE only: how long the order rests before it is cancelled, in
7710
+ // seconds from when it is placed (at least ${validateConditionalAction_1.MIN_LIMIT_EXPIRY_SECONDS}). Omitted, it rests until it
7711
+ // fills or the run ends. Stored at import.
7712
+ limit?: { expires_after_seconds?: number; expires_at_day_end?: boolean; price_from?: "BEST_BID" | "BEST_ASK"; };
7510
7713
  conjuncts?: StrategyConditionConjunct[];
7511
7714
  }
7512
7715
 
@@ -7646,11 +7849,22 @@ Each node has \`node_id\`, \`type\` ("CONDITION" | "ACTION"), \`level\` (\u22650
7646
7849
  - \`watch\`: { venue, market_id, outcome_token } \u2014 token_id optional locally but required at import for BUY/SELL targets
7647
7850
  - \`signal\`: one of ${exports.SIGNAL_TYPES.join(", ")}
7648
7851
  - \`trigger\`: CROSS_ABOVE or CROSS_BELOW
7649
- - \`threshold\`: number (probability 0\u20131 for IMPLIED_PROBABILITY; dollars for PRICE_USD, BASE_STOCKS (per share) and HYPERLIQUID (mark price) only; signed percent return on the position above for ROI_PCT, any venue (20 is +20%, -10 is -10%; must be above -100); PNL_USD is not supported at runtime)
7852
+ - \`threshold\`: number (probability 0\u20131 for IMPLIED_PROBABILITY; dollars for PRICE_USD, BASE_STOCKS (per share) and HYPERLIQUID (mark price) only; signed percent return on the position above for ROI_PCT, any venue (20 is +20%, -10 is -10%; must be above -100); the order price for LIMIT_PRICE \u2014 a fraction strictly between 0 and 1 on POLYMARKET (0.42 is 42c), or dollars per coin on a HYPERLIQUID perp; PNL_USD is not supported at runtime)
7650
7853
  - \`timing?\`: required when signal is TIME_SINCE_GROUP_SECONDS
7651
7854
  - \`conjuncts?\`: additional AND conditions (validated locally; dropped at import)
7652
7855
  - \`reference?\`: optional { mode: "SINCE_GROUP_START" | "SINCE_STRATEGY_START" | "FIXED_REFERENCE_VALUE" }. \`mode\` is stored as \`referenceMode\` but is **never read** by the interpreter. \`ROI_PCT\` needs none: it always measures the position bought above the condition (see Example 3). Do not author \`PNL_USD\`.
7653
7856
  - \`stabilizers?\`: validated locally; dropped at import
7857
+ - \`limit?\`: \`LIMIT_PRICE\` only. \`{ "expires_after_seconds": 86400 }\` cancels the resting order that long after it is placed (at least ${validateConditionalAction_1.MIN_LIMIT_EXPIRY_SECONDS}). \`{ "expires_at_day_end": true }\` cancels it at the next 12am Pacific Time after it is placed instead (the dated order Polymarket's own ticket offers); use one or the other. With neither, the order is good till cancelled: it rests until it fills or the run ends. Stored at import. \`{ "price_from": "BEST_BID" }\` or \`"BEST_ASK"\` takes the order's price from the order book at the moment the order is placed instead of from \`threshold\`, which must then be 0: use it for an order placed after a condition, where a price fixed in advance may no longer fit the market. \`BEST_BID\` is the highest bid (a buy joins the queue; a sell fills at once), \`BEST_ASK\` the lowest ask (a buy fills at once up to that price; a sell joins the queue). The price is read once and the order is not moved afterwards; with nothing on that side of the book the order is not placed and its branch is skipped. It combines with either expiry.
7858
+
7859
+ **Limit condition** (\`signal: "LIMIT_PRICE"\`) -- a resting limit order, not a watched price:
7860
+ - It is a CONDITION node with exactly one ACTION in a SINGLE group. When the condition is armed, the backend places a limit order on Polymarket's order book at \`threshold\` for that action's amount. A buy locks the branch's cash on the venue while it rests; a sell locks the shares.
7861
+ - The condition is met when the order has finished with a fill. What is chained under the action then arms as usual, on whatever filled.
7862
+ - Part fills: a part-filled BUY is ended early, the rest of it cancelled, when the market rises to the price of a sell chained beneath it on the same token, or when it gets no further fill for 10 minutes; the run continues with what filled. A buy that has filled nothing is never ended this way (use \`limit.expires_after_seconds\`). A part-filled SELL keeps resting; a stop beside it stays armed and, if it fires, cancels the sell and sells what is left. Simulated runs fill whole.
7863
+ - An order that ends with nothing filled (expired, cancelled by the venue, market closed) skips its branch (skip reason \`limit_unfilled\`).
7864
+ - Conditions under one action are alternatives, first to fire wins: if a sibling (a stop loss, say) fires first, the resting order is cancelled before the sibling trades, and any part already filled is recorded.
7865
+ - In a simulated run the order fills when the live book crosses the limit price.
7866
+ - **A plain price condition followed by a buy is not a limit order.** \`IMPLIED_PROBABILITY\` \`CROSS_BELOW\` 0.42 with a BUY sends a market order when the price is seen at 42c: it pays the taker fee and can fill worse than 42c. A Limit condition rests on the book and fills at 42c or better, or not at all. Market orders stay the default; nothing converts a price condition into a limit order.
7867
+ - Rules (\`validate\` enforces all of them): POLYMARKET, or HYPERLIQUID for a perp (Base stocks are rejected; use a price condition there); a Polymarket price is strictly between 0 and 1, a perp price is dollars per coin; exactly one action, which is BUY_MARKET_OUTCOME, SELL_MARKET_OUTCOME or MOVE_TO_WALLET; \`watch\` is the trade's own venue, market_id, outcome_token and token_id (for a sell: the position above it); a Limit buy uses CROSS_BELOW (this price or lower) and needs cash, so it sits at the root, under a cash HOLD, or after a sell, never directly under a position; a Limit sell uses CROSS_ABOVE (this price or higher) and is chained under the BUY whose position it sells (directly, or under a HOLD of that position); no AND clauses (\`conjuncts\`) and no \`timing\`; no \`whole_position\` on the sell; at most one Limit condition among the conditions under one action (chain a second under the first's action instead); \`limit.expires_after_seconds\` is at least ${validateConditionalAction_1.MIN_LIMIT_EXPIRY_SECONDS}.
7654
7868
 
7655
7869
  **ACTION node** \u2014 \`action\` object:
7656
7870
  - \`action_type\`: ${serverSupported_1.EXECUTABLE_ACTION_TYPES.join(" | ")}
@@ -7681,6 +7895,7 @@ Each group links one CONDITION to one or more ACTIONs at the same level.
7681
7895
  7. venue must be one of: ${serverSupported_1.EXECUTABLE_VENUES.join(", ")}
7682
7896
  7b. A BASE_STOCKS or HYPERLIQUID condition watch must use signal PRICE_USD (dollars, > 0); PRICE_USD is invalid on any other venue
7683
7897
  7c. A HYPERLIQUID target uses ids \`hl:<COIN>\` (or \`hl:<dex>:<COIN>\` for a HIP-3 perp, e.g. \`hl:xyz:NVDA\`), outcome_token LONG or SHORT, and an optional integer leverage from ${validateConditionalAction_1.MIN_PERP_LEVERAGE} to ${validateConditionalAction_1.MAX_PERP_LEVERAGE}; leverage on any other venue is rejected
7898
+ 7d. A LIMIT_PRICE condition (a resting limit order) is POLYMARKET only, has a threshold strictly between 0 and 1, holds exactly one BUY_MARKET_OUTCOME, SELL_MARKET_OUTCOME or MOVE_TO_WALLET, watches that trade's own market and token, uses CROSS_BELOW for a buy and CROSS_ABOVE for a sell, takes no conjuncts, timing or whole_position, and is the only Limit condition under its parent action; limit.expires_after_seconds is at least ${validateConditionalAction_1.MIN_LIMIT_EXPIRY_SECONDS}
7684
7899
  8. Edges must go ACTION -> CONDITION with a +1 level increment
7685
7900
  9. Each CONDITION is in exactly one decision group
7686
7901
  10. SPLIT_100 groups: allocation_pct sums to 100 \xB1 0.000001
@@ -8043,6 +8258,100 @@ short. A perp leg with no exit is closed when the strategy finishes.
8043
8258
  ]
8044
8259
  }
8045
8260
  \`\`\`
8261
+
8262
+ ## Example 7 \u2014 Limit buy, then a Limit sell (take profit) beside a stop loss
8263
+
8264
+ Three conditions, one position. \`cond_buy\` is a Limit condition at the root:
8265
+ a resting buy of YES at 42c with the whole principal, cancelled after a day if
8266
+ it has not filled (\`limit.expires_after_seconds\`). Once it fills, the two
8267
+ conditions chained under the buy are armed as alternatives:
8268
+ - \`cond_tp\` is a Limit sell: a resting sell of the position at 60c or higher.
8269
+ - \`cond_stop\` is a plain price condition: when YES is seen under 30c it sells
8270
+ at market. If it fires first, the resting sell is cancelled before the stop
8271
+ trades; if the Limit sell fills first, the stop is skipped.
8272
+
8273
+ Each Limit condition watches the same market and token its trade is on, a buy
8274
+ uses CROSS_BELOW and a sell CROSS_ABOVE. If the buy order ends unfilled the
8275
+ branch is skipped (\`limit_unfilled\`) and nothing is bought.
8276
+
8277
+ \`\`\`json
8278
+ {
8279
+ "version": "1.1.0",
8280
+ "strategy_id": "limit-buy-tp-stop-v1",
8281
+ "initial_principal_usd": 50,
8282
+ "root_node_id": "cond_buy",
8283
+ "nodes": [
8284
+ {
8285
+ "node_id": "cond_buy",
8286
+ "type": "CONDITION",
8287
+ "level": 0,
8288
+ "condition": {
8289
+ "watch": { "venue": "POLYMARKET", "market_id": "<market-id>", "outcome_token": "YES", "token_id": "<token-id>" },
8290
+ "signal": "LIMIT_PRICE",
8291
+ "trigger": "CROSS_BELOW",
8292
+ "threshold": 0.42,
8293
+ "limit": { "expires_after_seconds": 86400 }
8294
+ }
8295
+ },
8296
+ {
8297
+ "node_id": "act_buy",
8298
+ "type": "ACTION",
8299
+ "level": 0,
8300
+ "action": {
8301
+ "action_type": "BUY_MARKET_OUTCOME",
8302
+ "allocation_pct": 100,
8303
+ "target": {
8304
+ "venue": "POLYMARKET",
8305
+ "market": { "market_id": "<market-id>", "outcome_token": "YES", "token_id": "<token-id>" }
8306
+ }
8307
+ }
8308
+ },
8309
+ {
8310
+ "node_id": "cond_tp",
8311
+ "type": "CONDITION",
8312
+ "level": 1,
8313
+ "condition": {
8314
+ "watch": { "venue": "POLYMARKET", "market_id": "<market-id>", "outcome_token": "YES", "token_id": "<token-id>" },
8315
+ "signal": "LIMIT_PRICE",
8316
+ "trigger": "CROSS_ABOVE",
8317
+ "threshold": 0.6
8318
+ }
8319
+ },
8320
+ {
8321
+ "node_id": "act_tp",
8322
+ "type": "ACTION",
8323
+ "level": 1,
8324
+ "action": { "action_type": "MOVE_TO_WALLET", "allocation_pct": 100, "target": {} }
8325
+ },
8326
+ {
8327
+ "node_id": "cond_stop",
8328
+ "type": "CONDITION",
8329
+ "level": 1,
8330
+ "condition": {
8331
+ "watch": { "venue": "POLYMARKET", "market_id": "<market-id>", "outcome_token": "YES", "token_id": "<token-id>" },
8332
+ "signal": "IMPLIED_PROBABILITY",
8333
+ "trigger": "CROSS_BELOW",
8334
+ "threshold": 0.3
8335
+ }
8336
+ },
8337
+ {
8338
+ "node_id": "act_stop",
8339
+ "type": "ACTION",
8340
+ "level": 1,
8341
+ "action": { "action_type": "MOVE_TO_WALLET", "allocation_pct": 100, "target": {} }
8342
+ }
8343
+ ],
8344
+ "edges": [
8345
+ { "edge_id": "e1", "from_node_id": "act_buy", "to_node_id": "cond_tp" },
8346
+ { "edge_id": "e2", "from_node_id": "act_buy", "to_node_id": "cond_stop" }
8347
+ ],
8348
+ "decision_groups": [
8349
+ { "group_id": "g_buy", "condition_node_id": "cond_buy", "action_node_ids": ["act_buy"], "level": 0, "mode": "SINGLE" },
8350
+ { "group_id": "g_tp", "condition_node_id": "cond_tp", "action_node_ids": ["act_tp"], "level": 1, "mode": "SINGLE" },
8351
+ { "group_id": "g_stop", "condition_node_id": "cond_stop", "action_node_ids": ["act_stop"], "level": 1, "mode": "SINGLE" }
8352
+ ]
8353
+ }
8354
+ \`\`\`
8046
8355
  `;
8047
8356
  var SCHEMA_JSON_OBJECT = {
8048
8357
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -8118,6 +8427,15 @@ short. A perp leg with no exit is closed when the strategy finishes.
8118
8427
  cooldown_seconds: { type: "number" }
8119
8428
  }
8120
8429
  },
8430
+ // LIMIT_PRICE only: the resting order's lifetime. Stored at import.
8431
+ limit: {
8432
+ type: "object",
8433
+ properties: {
8434
+ expires_after_seconds: { type: "number", minimum: validateConditionalAction_1.MIN_LIMIT_EXPIRY_SECONDS },
8435
+ expires_at_day_end: { type: "boolean" },
8436
+ price_from: { type: "string", enum: ["BEST_BID", "BEST_ASK"] }
8437
+ }
8438
+ },
8121
8439
  // Validated locally but dropped at import.
8122
8440
  conjuncts: { type: "array", items: { type: "object" } }
8123
8441
  }
@@ -8218,6 +8536,7 @@ var require_strategy = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8218
8536
  Object.defineProperty(exports, "__esModule", { value: true });
8219
8537
  __exportStar(require_conditionalActionTypes(), exports);
8220
8538
  __exportStar(require_validateConditionalAction(), exports);
8539
+ __exportStar(require_strategyFieldWarnings(), exports);
8221
8540
  __exportStar(require_strategyValidationErrorCode(), exports);
8222
8541
  __exportStar(require_polymarketConstants(), exports);
8223
8542
  __exportStar(require_runGraphLock(), exports);
@@ -8314,9 +8633,9 @@ var require_hosts = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8314
8633
  exports.DEFAULT_POLY_WS_URL = "wss://ws-subscriptions-clob.polymarket.com/ws/market";
8315
8634
  function getHosts(overrides) {
8316
8635
  return {
8317
- gamma: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _430 => _430.gamma]), () => ( exports.DEFAULT_GAMMA_URL)),
8318
- clob: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _431 => _431.clob]), () => ( exports.DEFAULT_CLOB_URL)),
8319
- ws: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _432 => _432.ws]), () => ( exports.DEFAULT_POLY_WS_URL))
8636
+ gamma: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _473 => _473.gamma]), () => ( exports.DEFAULT_GAMMA_URL)),
8637
+ clob: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _474 => _474.clob]), () => ( exports.DEFAULT_CLOB_URL)),
8638
+ ws: _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _475 => _475.ws]), () => ( exports.DEFAULT_POLY_WS_URL))
8320
8639
  };
8321
8640
  }
8322
8641
  }
@@ -8509,7 +8828,7 @@ var require_priceHelpers = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8509
8828
  };
8510
8829
  exports.midpointFromBidAsk = midpointFromBidAsk;
8511
8830
  var bestOfBook = (bids, asks) => {
8512
- const levelPrices = (levels) => levels.map((level) => (0, exports.toNumber)(_optionalChain([level, 'optionalAccess', _433 => _433.price]))).filter((price) => typeof price === "number" && price > 0);
8831
+ const levelPrices = (levels) => levels.map((level) => (0, exports.toNumber)(_optionalChain([level, 'optionalAccess', _476 => _476.price]))).filter((price) => typeof price === "number" && price > 0);
8513
8832
  const bidPrices = levelPrices(bids);
8514
8833
  const askPrices = levelPrices(asks);
8515
8834
  return {
@@ -8638,23 +8957,23 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8638
8957
  if (Array.isArray(events) && events.length > 0 && events[0] && typeof events[0] === "object") {
8639
8958
  ev0 = events[0];
8640
8959
  }
8641
- const eventIdRaw = _nullishCoalesce(_nullishCoalesce(_optionalChain([ev0, 'optionalAccess', _434 => _434.id]), () => ( market.eventId)), () => ( market.event_id));
8960
+ const eventIdRaw = _nullishCoalesce(_nullishCoalesce(_optionalChain([ev0, 'optionalAccess', _477 => _477.id]), () => ( market.eventId)), () => ( market.event_id));
8642
8961
  const eventId = eventIdRaw !== void 0 && eventIdRaw !== null && String(eventIdRaw).length > 0 ? String(eventIdRaw) : void 0;
8643
- const eventTitle = (typeof _optionalChain([ev0, 'optionalAccess', _435 => _435.title]) === "string" && ev0.title ? String(ev0.title) : typeof market.eventTitle === "string" && market.eventTitle ? String(market.eventTitle) : void 0) || void 0;
8962
+ const eventTitle = (typeof _optionalChain([ev0, 'optionalAccess', _478 => _478.title]) === "string" && ev0.title ? String(ev0.title) : typeof market.eventTitle === "string" && market.eventTitle ? String(market.eventTitle) : void 0) || void 0;
8644
8963
  let series0 = null;
8645
8964
  const seriesArray = market.series;
8646
8965
  if (Array.isArray(seriesArray) && seriesArray.length > 0 && seriesArray[0] && typeof seriesArray[0] === "object") {
8647
8966
  series0 = seriesArray[0];
8648
8967
  }
8649
8968
  const eventImage = firstNonEmptyString([
8650
- _optionalChain([ev0, 'optionalAccess', _436 => _436.image]),
8969
+ _optionalChain([ev0, 'optionalAccess', _479 => _479.image]),
8651
8970
  market.image,
8652
- _optionalChain([series0, 'optionalAccess', _437 => _437.image])
8971
+ _optionalChain([series0, 'optionalAccess', _480 => _480.image])
8653
8972
  ]);
8654
8973
  const eventIcon = firstNonEmptyString([
8655
- _optionalChain([ev0, 'optionalAccess', _438 => _438.icon]),
8974
+ _optionalChain([ev0, 'optionalAccess', _481 => _481.icon]),
8656
8975
  market.icon,
8657
- _optionalChain([series0, 'optionalAccess', _439 => _439.icon])
8976
+ _optionalChain([series0, 'optionalAccess', _482 => _482.icon])
8658
8977
  ]);
8659
8978
  const groupItemTitle = typeof market.groupItemTitle === "string" && market.groupItemTitle ? String(market.groupItemTitle) : void 0;
8660
8979
  const negRisk = typeof market.negRisk === "boolean" ? market.negRisk : void 0;
@@ -8676,38 +8995,38 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8676
8995
  };
8677
8996
  }
8678
8997
  function normalizePolymarketResults(payload) {
8679
- const events = _optionalChain([payload, 'optionalAccess', _440 => _440.events]) || [];
8998
+ const events = _optionalChain([payload, 'optionalAccess', _483 => _483.events]) || [];
8680
8999
  if (!Array.isArray(events))
8681
9000
  return [];
8682
9001
  const results = [];
8683
9002
  for (const event of events) {
8684
- const eventId = String(_optionalChain([event, 'optionalAccess', _441 => _441.id]) || "");
8685
- const eventEnd = _optionalChain([event, 'optionalAccess', _442 => _442.endDate]) || _optionalChain([event, 'optionalAccess', _443 => _443.endDateIso]) || void 0;
8686
- const eventStart = _optionalChain([event, 'optionalAccess', _444 => _444.startTime]) || void 0;
8687
- const eventSeries = Array.isArray(_optionalChain([event, 'optionalAccess', _445 => _445.series])) ? event.series[0] : _optionalChain([event, 'optionalAccess', _446 => _446.series]);
8688
- const seriesId = _optionalChain([eventSeries, 'optionalAccess', _447 => _447.id]) != null ? String(eventSeries.id) : void 0;
8689
- const seriesSlug = _optionalChain([eventSeries, 'optionalAccess', _448 => _448.slug]) ? String(eventSeries.slug) : void 0;
8690
- const eventImage = typeof _optionalChain([event, 'optionalAccess', _449 => _449.image]) === "string" && event.image ? event.image : void 0;
8691
- const eventIcon = typeof _optionalChain([event, 'optionalAccess', _450 => _450.icon]) === "string" && event.icon ? event.icon : void 0;
8692
- const eventSlug = typeof _optionalChain([event, 'optionalAccess', _451 => _451.slug]) === "string" ? event.slug : void 0;
8693
- const eventTagIds = (0, parse_1.parseTagIds)(_optionalChain([event, 'optionalAccess', _452 => _452.tags]));
8694
- const eventTagSlugs = (0, parse_1.parseTagSlugs)(_optionalChain([event, 'optionalAccess', _453 => _453.tags]));
8695
- const markets = Array.isArray(_optionalChain([event, 'optionalAccess', _454 => _454.markets])) ? event.markets : [];
9003
+ const eventId = String(_optionalChain([event, 'optionalAccess', _484 => _484.id]) || "");
9004
+ const eventEnd = _optionalChain([event, 'optionalAccess', _485 => _485.endDate]) || _optionalChain([event, 'optionalAccess', _486 => _486.endDateIso]) || void 0;
9005
+ const eventStart = _optionalChain([event, 'optionalAccess', _487 => _487.startTime]) || void 0;
9006
+ const eventSeries = Array.isArray(_optionalChain([event, 'optionalAccess', _488 => _488.series])) ? event.series[0] : _optionalChain([event, 'optionalAccess', _489 => _489.series]);
9007
+ const seriesId = _optionalChain([eventSeries, 'optionalAccess', _490 => _490.id]) != null ? String(eventSeries.id) : void 0;
9008
+ const seriesSlug = _optionalChain([eventSeries, 'optionalAccess', _491 => _491.slug]) ? String(eventSeries.slug) : void 0;
9009
+ const eventImage = typeof _optionalChain([event, 'optionalAccess', _492 => _492.image]) === "string" && event.image ? event.image : void 0;
9010
+ const eventIcon = typeof _optionalChain([event, 'optionalAccess', _493 => _493.icon]) === "string" && event.icon ? event.icon : void 0;
9011
+ const eventSlug = typeof _optionalChain([event, 'optionalAccess', _494 => _494.slug]) === "string" ? event.slug : void 0;
9012
+ const eventTagIds = (0, parse_1.parseTagIds)(_optionalChain([event, 'optionalAccess', _495 => _495.tags]));
9013
+ const eventTagSlugs = (0, parse_1.parseTagSlugs)(_optionalChain([event, 'optionalAccess', _496 => _496.tags]));
9014
+ const markets = Array.isArray(_optionalChain([event, 'optionalAccess', _497 => _497.markets])) ? event.markets : [];
8696
9015
  for (const market of markets) {
8697
- if (_optionalChain([market, 'optionalAccess', _455 => _455.closed]))
9016
+ if (_optionalChain([market, 'optionalAccess', _498 => _498.closed]))
8698
9017
  continue;
8699
- const marketId = String(_optionalChain([market, 'optionalAccess', _456 => _456.id]) || "");
9018
+ const marketId = String(_optionalChain([market, 'optionalAccess', _499 => _499.id]) || "");
8700
9019
  if (!marketId)
8701
9020
  continue;
8702
- const title = String(_optionalChain([market, 'optionalAccess', _457 => _457.question]) || _optionalChain([event, 'optionalAccess', _458 => _458.title]) || "").trim();
9021
+ const title = String(_optionalChain([market, 'optionalAccess', _500 => _500.question]) || _optionalChain([event, 'optionalAccess', _501 => _501.title]) || "").trim();
8703
9022
  if (!title)
8704
9023
  continue;
8705
- const marketTagIds = (0, parse_1.parseTagIds)(_optionalChain([market, 'optionalAccess', _459 => _459.tags]));
9024
+ const marketTagIds = (0, parse_1.parseTagIds)(_optionalChain([market, 'optionalAccess', _502 => _502.tags]));
8706
9025
  const tagIds = [.../* @__PURE__ */ new Set([...eventTagIds, ...marketTagIds])].sort((a, b) => a - b);
8707
- const tagSlugs = [.../* @__PURE__ */ new Set([...eventTagSlugs, ...(0, parse_1.parseTagSlugs)(_optionalChain([market, 'optionalAccess', _460 => _460.tags]))])];
9026
+ const tagSlugs = [.../* @__PURE__ */ new Set([...eventTagSlugs, ...(0, parse_1.parseTagSlugs)(_optionalChain([market, 'optionalAccess', _503 => _503.tags]))])];
8708
9027
  const isRecurring = tagIds.some((id) => parse_2.RECURRING_TAG_IDS.has(id));
8709
- const outcomeLabels = (0, parse_1.parseJsonStringArray)(_optionalChain([market, 'optionalAccess', _461 => _461.outcomes]));
8710
- const outcomePrices = (0, parse_1.parseNumberArray)(_optionalChain([market, 'optionalAccess', _462 => _462.outcomePrices]));
9028
+ const outcomeLabels = (0, parse_1.parseJsonStringArray)(_optionalChain([market, 'optionalAccess', _504 => _504.outcomes]));
9029
+ const outcomePrices = (0, parse_1.parseNumberArray)(_optionalChain([market, 'optionalAccess', _505 => _505.outcomePrices]));
8711
9030
  const clobTokenIds = (0, protocolVersion_1.gammaOutcomeAssetIds)(market);
8712
9031
  const maxLen = Math.max(outcomeLabels.length, outcomePrices.length, clobTokenIds.length, 2);
8713
9032
  const outcomes = [];
@@ -8722,18 +9041,18 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8722
9041
  token_id: clobTokenIds[i] || void 0
8723
9042
  });
8724
9043
  }
8725
- const liquidityNum = typeof _optionalChain([market, 'optionalAccess', _463 => _463.liquidityNum]) === "number" ? market.liquidityNum : Number(_optionalChain([market, 'optionalAccess', _464 => _464.liquidity]) || 0);
8726
- const volumeNum = typeof _optionalChain([market, 'optionalAccess', _465 => _465.volume]) === "number" ? market.volume : Number(_optionalChain([market, 'optionalAccess', _466 => _466.volume]) || 0);
8727
- const volume24h = typeof _optionalChain([event, 'optionalAccess', _467 => _467.volume24hr]) === "number" ? event.volume24hr : Number(_optionalChain([event, 'optionalAccess', _468 => _468.volume24hr]) || 0);
8728
- const marketSlug = typeof _optionalChain([market, 'optionalAccess', _469 => _469.slug]) === "string" ? market.slug : void 0;
9044
+ const liquidityNum = typeof _optionalChain([market, 'optionalAccess', _506 => _506.liquidityNum]) === "number" ? market.liquidityNum : Number(_optionalChain([market, 'optionalAccess', _507 => _507.liquidity]) || 0);
9045
+ const volumeNum = typeof _optionalChain([market, 'optionalAccess', _508 => _508.volume]) === "number" ? market.volume : Number(_optionalChain([market, 'optionalAccess', _509 => _509.volume]) || 0);
9046
+ const volume24h = typeof _optionalChain([event, 'optionalAccess', _510 => _510.volume24hr]) === "number" ? event.volume24hr : Number(_optionalChain([event, 'optionalAccess', _511 => _511.volume24hr]) || 0);
9047
+ const marketSlug = typeof _optionalChain([market, 'optionalAccess', _512 => _512.slug]) === "string" ? market.slug : void 0;
8729
9048
  const derived = (0, parse_1.deriveRecurringWindowFromSlug)(marketSlug || seriesSlug);
8730
9049
  const derivedIso = derived ? (0, parse_1.derivedWindowToIso)(derived) : null;
8731
- const validFrom = _optionalChain([market, 'optionalAccess', _470 => _470.eventStartTime]) || eventStart || (isRecurring && derivedIso ? derivedIso.validFrom : void 0);
8732
- const isEventLive = _optionalChain([event, 'optionalAccess', _471 => _471.live]) === true;
8733
- const isEventEnded = _optionalChain([event, 'optionalAccess', _472 => _472.ended]) === true || _optionalChain([market, 'optionalAccess', _473 => _473.ended]) === true;
8734
- let closeTime = _optionalChain([market, 'optionalAccess', _474 => _474.endDate]) || _optionalChain([market, 'optionalAccess', _475 => _475.endDateIso]) || eventEnd || (isRecurring && derivedIso ? derivedIso.closeTime : void 0);
8735
- let isClosed = Boolean(_optionalChain([market, 'optionalAccess', _476 => _476.closed]) || _optionalChain([event, 'optionalAccess', _477 => _477.closed]));
8736
- let status = _optionalChain([market, 'optionalAccess', _478 => _478.closed]) ? "CLOSED" : "OPEN";
9050
+ const validFrom = _optionalChain([market, 'optionalAccess', _513 => _513.eventStartTime]) || eventStart || (isRecurring && derivedIso ? derivedIso.validFrom : void 0);
9051
+ const isEventLive = _optionalChain([event, 'optionalAccess', _514 => _514.live]) === true;
9052
+ const isEventEnded = _optionalChain([event, 'optionalAccess', _515 => _515.ended]) === true || _optionalChain([market, 'optionalAccess', _516 => _516.ended]) === true;
9053
+ let closeTime = _optionalChain([market, 'optionalAccess', _517 => _517.endDate]) || _optionalChain([market, 'optionalAccess', _518 => _518.endDateIso]) || eventEnd || (isRecurring && derivedIso ? derivedIso.closeTime : void 0);
9054
+ let isClosed = Boolean(_optionalChain([market, 'optionalAccess', _519 => _519.closed]) || _optionalChain([event, 'optionalAccess', _520 => _520.closed]));
9055
+ let status = _optionalChain([market, 'optionalAccess', _521 => _521.closed]) ? "CLOSED" : "OPEN";
8737
9056
  if (isRecurring) {
8738
9057
  const closeMs = closeTime ? new Date(closeTime).getTime() : Number.NaN;
8739
9058
  if (Number.isFinite(closeMs) && closeMs <= Date.now()) {
@@ -8751,7 +9070,7 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8751
9070
  venue: "polymarket",
8752
9071
  market_id: marketId,
8753
9072
  event_id: eventId || void 0,
8754
- event_title: _optionalChain([event, 'optionalAccess', _479 => _479.title]) ? String(event.title) : void 0,
9073
+ event_title: _optionalChain([event, 'optionalAccess', _522 => _522.title]) ? String(event.title) : void 0,
8755
9074
  event_slug: eventSlug,
8756
9075
  market_slug: marketSlug,
8757
9076
  event_image: eventImage,
@@ -8759,7 +9078,7 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8759
9078
  series_id: seriesId,
8760
9079
  series_slug: seriesSlug,
8761
9080
  title,
8762
- group_item_title: _optionalChain([market, 'optionalAccess', _480 => _480.groupItemTitle]) ? String(market.groupItemTitle) : void 0,
9081
+ group_item_title: _optionalChain([market, 'optionalAccess', _523 => _523.groupItemTitle]) ? String(market.groupItemTitle) : void 0,
8763
9082
  outcomes,
8764
9083
  tag_ids: tagIds,
8765
9084
  tag_slugs: tagSlugs,
@@ -8769,11 +9088,11 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8769
9088
  volume24h: Number.isFinite(volume24h) ? volume24h : void 0,
8770
9089
  close_time: closeTime,
8771
9090
  is_closed: isClosed,
8772
- is_active: _optionalChain([market, 'optionalAccess', _481 => _481.active]) !== false,
9091
+ is_active: _optionalChain([market, 'optionalAccess', _524 => _524.active]) !== false,
8773
9092
  is_live: isEventLive,
8774
9093
  is_ended: isEventEnded,
8775
- ..._optionalChain([market, 'optionalAccess', _482 => _482.acceptingOrders]) === false ? { accepting_orders: false } : {},
8776
- neg_risk: Boolean(_optionalChain([market, 'optionalAccess', _483 => _483.negRisk])),
9094
+ ..._optionalChain([market, 'optionalAccess', _525 => _525.acceptingOrders]) === false ? { accepting_orders: false } : {},
9095
+ neg_risk: Boolean(_optionalChain([market, 'optionalAccess', _526 => _526.negRisk])),
8777
9096
  status
8778
9097
  });
8779
9098
  }
@@ -8781,11 +9100,11 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8781
9100
  return results;
8782
9101
  }
8783
9102
  function normalizePolymarketSnapshot(market) {
8784
- const marketId = String(_optionalChain([market, 'optionalAccess', _484 => _484.id]) || "");
9103
+ const marketId = String(_optionalChain([market, 'optionalAccess', _527 => _527.id]) || "");
8785
9104
  if (!marketId)
8786
9105
  return null;
8787
- const labels = (0, parse_1.parseJsonStringArray)(_optionalChain([market, 'optionalAccess', _485 => _485.outcomes]));
8788
- const prices = (0, parse_1.parseNumberArray)(_optionalChain([market, 'optionalAccess', _486 => _486.outcomePrices]));
9106
+ const labels = (0, parse_1.parseJsonStringArray)(_optionalChain([market, 'optionalAccess', _528 => _528.outcomes]));
9107
+ const prices = (0, parse_1.parseNumberArray)(_optionalChain([market, 'optionalAccess', _529 => _529.outcomePrices]));
8789
9108
  const tokenIds = (0, protocolVersion_1.gammaOutcomeAssetIds)(market);
8790
9109
  const maxLen = Math.max(labels.length, prices.length, tokenIds.length, 2);
8791
9110
  const isGammaPlaceholder = maxLen === 2 && prices.length === 2 && Math.abs(prices[0] - 0.5) < 1e-9 && Math.abs(prices[1] - 0.5) < 1e-9;
@@ -8803,15 +9122,15 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8803
9122
  token_id: tokenIds[i] || void 0
8804
9123
  });
8805
9124
  }
8806
- const liquidity = typeof _optionalChain([market, 'optionalAccess', _487 => _487.liquidityNum]) === "number" ? market.liquidityNum : Number(_optionalChain([market, 'optionalAccess', _488 => _488.liquidity]) || 0);
8807
- const volume = typeof _optionalChain([market, 'optionalAccess', _489 => _489.volumeNum]) === "number" ? market.volumeNum : Number(_optionalChain([market, 'optionalAccess', _490 => _490.volume]) || 0);
8808
- let closed = typeof _optionalChain([market, 'optionalAccess', _491 => _491.closed]) === "boolean" ? market.closed : void 0;
8809
- let endDateIso = (typeof _optionalChain([market, 'optionalAccess', _492 => _492.endDate]) === "string" && market.endDate.length > 10 ? market.endDate : void 0) || (typeof _optionalChain([market, 'optionalAccess', _493 => _493.endDateIso]) === "string" && market.endDateIso.length > 0 ? market.endDateIso : void 0);
8810
- const events = Array.isArray(_optionalChain([market, 'optionalAccess', _494 => _494.events])) ? market.events : [];
8811
- const marketSlug = typeof _optionalChain([market, 'optionalAccess', _495 => _495.slug]) === "string" ? market.slug : void 0;
9125
+ const liquidity = typeof _optionalChain([market, 'optionalAccess', _530 => _530.liquidityNum]) === "number" ? market.liquidityNum : Number(_optionalChain([market, 'optionalAccess', _531 => _531.liquidity]) || 0);
9126
+ const volume = typeof _optionalChain([market, 'optionalAccess', _532 => _532.volumeNum]) === "number" ? market.volumeNum : Number(_optionalChain([market, 'optionalAccess', _533 => _533.volume]) || 0);
9127
+ let closed = typeof _optionalChain([market, 'optionalAccess', _534 => _534.closed]) === "boolean" ? market.closed : void 0;
9128
+ let endDateIso = (typeof _optionalChain([market, 'optionalAccess', _535 => _535.endDate]) === "string" && market.endDate.length > 10 ? market.endDate : void 0) || (typeof _optionalChain([market, 'optionalAccess', _536 => _536.endDateIso]) === "string" && market.endDateIso.length > 0 ? market.endDateIso : void 0);
9129
+ const events = Array.isArray(_optionalChain([market, 'optionalAccess', _537 => _537.events])) ? market.events : [];
9130
+ const marketSlug = typeof _optionalChain([market, 'optionalAccess', _538 => _538.slug]) === "string" ? market.slug : void 0;
8812
9131
  const seriesSlug = typeof market.seriesSlug === "string" ? market.seriesSlug : void 0;
8813
9132
  const slugDerived = (0, parse_1.deriveRecurringWindowFromSlug)(marketSlug || seriesSlug);
8814
- const isRecurring = events.some((e) => Array.isArray(_optionalChain([e, 'optionalAccess', _496 => _496.series])) && e.series.some((s) => _optionalChain([s, 'optionalAccess', _497 => _497.recurrence]))) || !!slugDerived;
9133
+ const isRecurring = events.some((e) => Array.isArray(_optionalChain([e, 'optionalAccess', _539 => _539.series])) && e.series.some((s) => _optionalChain([s, 'optionalAccess', _540 => _540.recurrence]))) || !!slugDerived;
8815
9134
  if (isRecurring) {
8816
9135
  let endMs;
8817
9136
  if (typeof endDateIso === "string") {
@@ -8830,7 +9149,7 @@ var require_normalizeMarket = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
8830
9149
  return {
8831
9150
  venue: "polymarket",
8832
9151
  market_id: marketId,
8833
- title: String(_optionalChain([market, 'optionalAccess', _498 => _498.question]) || ""),
9152
+ title: String(_optionalChain([market, 'optionalAccess', _541 => _541.question]) || ""),
8834
9153
  outcomes,
8835
9154
  liquidity: Number.isFinite(liquidity) ? liquidity : void 0,
8836
9155
  volume: Number.isFinite(volume) ? volume : void 0,
@@ -9016,9 +9335,9 @@ var require_gammaClient = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9016
9335
  const params = new URLSearchParams();
9017
9336
  params.set("q", query || "election");
9018
9337
  params.set("limit_per_type", String(Math.max(limit, 20)));
9019
- if (_optionalChain([opts, 'optionalAccess', _499 => _499.eventsTag]))
9338
+ if (_optionalChain([opts, 'optionalAccess', _542 => _542.eventsTag]))
9020
9339
  params.set("events_tag", opts.eventsTag);
9021
- if (_optionalChain([opts, 'optionalAccess', _500 => _500.eventsStatus]))
9340
+ if (_optionalChain([opts, 'optionalAccess', _543 => _543.eventsStatus]))
9022
9341
  params.set("events_status", opts.eventsStatus);
9023
9342
  const data = await get(`/public-search`, params);
9024
9343
  return (0, normalizeMarket_1.normalizePolymarketResults)(data);
@@ -9031,13 +9350,13 @@ var require_gammaClient = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9031
9350
  for (const id of uniqueIds)
9032
9351
  params.append("id", id);
9033
9352
  const data = await get(`/markets`, params);
9034
- const markets = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _501 => _501.data])) ? data.data : [];
9353
+ const markets = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _544 => _544.data])) ? data.data : [];
9035
9354
  const eventsById = /* @__PURE__ */ new Map();
9036
9355
  for (const market of markets) {
9037
9356
  if (!market || typeof market !== "object")
9038
9357
  continue;
9039
9358
  const embedded = Array.isArray(market.events) && market.events[0] ? market.events[0] : {};
9040
- const key = String(_nullishCoalesce(_optionalChain([embedded, 'optionalAccess', _502 => _502.id]), () => ( `market:${market.id}`)));
9359
+ const key = String(_nullishCoalesce(_optionalChain([embedded, 'optionalAccess', _545 => _545.id]), () => ( `market:${market.id}`)));
9041
9360
  const existing = eventsById.get(key);
9042
9361
  if (existing) {
9043
9362
  existing.markets.push(market);
@@ -9055,52 +9374,52 @@ var require_gammaClient = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9055
9374
  for (const id of uniqueIds)
9056
9375
  params.append("id", id);
9057
9376
  const data = await get(`/events`, params);
9058
- const events = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _503 => _503.events])) ? data.events : [];
9377
+ const events = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _546 => _546.events])) ? data.events : [];
9059
9378
  const wanted = new Set(uniqueIds);
9060
9379
  return (0, normalizeMarket_1.normalizePolymarketResults)({
9061
- events: events.filter((event) => wanted.has(String(_optionalChain([event, 'optionalAccess', _504 => _504.id]))))
9380
+ events: events.filter((event) => wanted.has(String(_optionalChain([event, 'optionalAccess', _547 => _547.id]))))
9062
9381
  });
9063
9382
  }
9064
9383
  async function fetchPolymarketKeyset(limit, opts) {
9065
9384
  const params = new URLSearchParams();
9066
9385
  params.set("limit", String(Math.max(1, limit)));
9067
- params.set("closed", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _505 => _505.closed]), () => ( "false")));
9068
- params.set("order", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _506 => _506.order]), () => ( "volume")));
9069
- params.set("ascending", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _507 => _507.ascending]), () => ( "false")));
9070
- if (_optionalChain([opts, 'optionalAccess', _508 => _508.tagSlug])) {
9386
+ params.set("closed", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _548 => _548.closed]), () => ( "false")));
9387
+ params.set("order", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _549 => _549.order]), () => ( "volume")));
9388
+ params.set("ascending", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _550 => _550.ascending]), () => ( "false")));
9389
+ if (_optionalChain([opts, 'optionalAccess', _551 => _551.tagSlug])) {
9071
9390
  params.set("tag_slug", opts.tagSlug);
9072
- } else if (typeof _optionalChain([opts, 'optionalAccess', _509 => _509.tagId]) === "number" && Number.isFinite(opts.tagId)) {
9391
+ } else if (typeof _optionalChain([opts, 'optionalAccess', _552 => _552.tagId]) === "number" && Number.isFinite(opts.tagId)) {
9073
9392
  params.set("tag_id", String(opts.tagId));
9074
9393
  }
9075
9394
  const data = await get(`/events/keyset`, params);
9076
- const events = Array.isArray(_optionalChain([data, 'optionalAccess', _510 => _510.events])) ? data.events : Array.isArray(data) ? data : [];
9395
+ const events = Array.isArray(_optionalChain([data, 'optionalAccess', _553 => _553.events])) ? data.events : Array.isArray(data) ? data : [];
9077
9396
  return (0, normalizeMarket_1.normalizePolymarketResults)({ events });
9078
9397
  }
9079
9398
  async function fetchPolymarketEvents(limit, opts) {
9080
9399
  const params = new URLSearchParams();
9081
9400
  params.set("limit", String(Math.max(1, Math.min(100, limit))));
9082
- if (typeof _optionalChain([opts, 'optionalAccess', _511 => _511.offset]) === "number" && Number.isFinite(opts.offset) && opts.offset > 0) {
9401
+ if (typeof _optionalChain([opts, 'optionalAccess', _554 => _554.offset]) === "number" && Number.isFinite(opts.offset) && opts.offset > 0) {
9083
9402
  params.set("offset", String(Math.floor(opts.offset)));
9084
9403
  }
9085
- params.set("closed", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _512 => _512.closed]), () => ( "false")));
9086
- params.set("order", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _513 => _513.order]), () => ( "volume")));
9087
- params.set("ascending", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _514 => _514.ascending]), () => ( "false")));
9088
- if (_optionalChain([opts, 'optionalAccess', _515 => _515.tagSlug])) {
9404
+ params.set("closed", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _555 => _555.closed]), () => ( "false")));
9405
+ params.set("order", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _556 => _556.order]), () => ( "volume")));
9406
+ params.set("ascending", _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _557 => _557.ascending]), () => ( "false")));
9407
+ if (_optionalChain([opts, 'optionalAccess', _558 => _558.tagSlug])) {
9089
9408
  params.set("tag_slug", opts.tagSlug);
9090
- } else if (typeof _optionalChain([opts, 'optionalAccess', _516 => _516.tagId]) === "number" && Number.isFinite(opts.tagId)) {
9409
+ } else if (typeof _optionalChain([opts, 'optionalAccess', _559 => _559.tagId]) === "number" && Number.isFinite(opts.tagId)) {
9091
9410
  params.set("tag_id", String(opts.tagId));
9092
9411
  }
9093
- if (_optionalChain([opts, 'optionalAccess', _517 => _517.active])) {
9412
+ if (_optionalChain([opts, 'optionalAccess', _560 => _560.active])) {
9094
9413
  params.set("active", opts.active);
9095
9414
  }
9096
- if (_optionalChain([opts, 'optionalAccess', _518 => _518.endDateMin])) {
9415
+ if (_optionalChain([opts, 'optionalAccess', _561 => _561.endDateMin])) {
9097
9416
  params.set("end_date_min", opts.endDateMin);
9098
9417
  }
9099
- if (_optionalChain([opts, 'optionalAccess', _519 => _519.endDateMax])) {
9418
+ if (_optionalChain([opts, 'optionalAccess', _562 => _562.endDateMax])) {
9100
9419
  params.set("end_date_max", opts.endDateMax);
9101
9420
  }
9102
9421
  const data = await get(`/events`, params);
9103
- const events = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _520 => _520.events])) ? data.events : [];
9422
+ const events = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _563 => _563.events])) ? data.events : [];
9104
9423
  return {
9105
9424
  results: (0, normalizeMarket_1.normalizePolymarketResults)({ events }),
9106
9425
  eventCount: events.length
@@ -9184,7 +9503,7 @@ var require_gammaClient = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9184
9503
  params.set("ascending", "true");
9185
9504
  params.set("limit", String(Math.max(1, limit)));
9186
9505
  const data = await get(`/events/keyset`, params);
9187
- const events = Array.isArray(_optionalChain([data, 'optionalAccess', _521 => _521.events])) ? data.events : Array.isArray(data) ? data : [];
9506
+ const events = Array.isArray(_optionalChain([data, 'optionalAccess', _564 => _564.events])) ? data.events : Array.isArray(data) ? data : [];
9188
9507
  return (0, normalizeMarket_1.normalizePolymarketResults)({ events }).filter((r) => r.is_live === true && r.is_ended !== true && !r.is_closed);
9189
9508
  } catch (e8) {
9190
9509
  return [];
@@ -9217,7 +9536,7 @@ var require_gammaClient = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9217
9536
  async function fetchGammaMarketByTokenId(tokenId) {
9218
9537
  try {
9219
9538
  const data = await get("/markets", new URLSearchParams({ clob_token_ids: tokenId }));
9220
- const markets = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _522 => _522.data])) ? data.data : [];
9539
+ const markets = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _565 => _565.data])) ? data.data : [];
9221
9540
  const row = markets[0];
9222
9541
  return row && typeof row === "object" && row.id ? row : null;
9223
9542
  } catch (e10) {
@@ -9748,7 +10067,7 @@ var require_legParser = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9748
10067
  return void 0;
9749
10068
  const numberMatch = /(?<![\w.])(-?\d+(?:[.,]\d+)*)(?:\s*(k|m|bn|b|tn|t|thousand|million|billion|trillion|c|¢|cents?)(?![a-z\d]))?/i.exec(text.replace(/\$/g, ""));
9750
10069
  const digits = numberMatch ? toNumber(numberMatch[1]) : void 0;
9751
- const magnitude = (_nullishCoalesce(_optionalChain([numberMatch, 'optionalAccess', _523 => _523[2]]), () => ( ""))).toLowerCase();
10070
+ const magnitude = (_nullishCoalesce(_optionalChain([numberMatch, 'optionalAccess', _566 => _566[2]]), () => ( ""))).toLowerCase();
9752
10071
  const value = digits === void 0 ? void 0 : /^(c|¢|cents?)$/.test(magnitude) ? digits / 100 : digits * (_nullishCoalesce(MAGNITUDE[magnitude], () => ( 1)));
9753
10072
  const unit = BPS_HINT.test(text) ? "bps" : void 0;
9754
10073
  let sign;
@@ -9807,16 +10126,16 @@ var require_legParser = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9807
10126
  return comparator === "ABOVE" ? parsed.value : comparator === "BELOW" ? parsed.upper : (parsed.value + parsed.upper) / 2;
9808
10127
  }
9809
10128
  function nearestLevelLegs(legs, parameter, eventTitle) {
9810
- const level = _optionalChain([parameter, 'optionalAccess', _524 => _524.value]);
10129
+ const level = _optionalChain([parameter, 'optionalAccess', _567 => _567.value]);
9811
10130
  if (level === void 0)
9812
10131
  return [];
9813
10132
  const placed = legs.flatMap((leg) => {
9814
10133
  const parsed = parseLegLabel(leg.groupItemTitle, eventTitle);
9815
10134
  if (parsed.kind === "DELTA" || parsed.kind === "UNPARSED")
9816
10135
  return [];
9817
- if (_optionalChain([parameter, 'optionalAccess', _525 => _525.comparator]) === "ABOVE" && parsed.kind === "BELOW" || _optionalChain([parameter, 'optionalAccess', _526 => _526.comparator]) === "BELOW" && parsed.kind === "ABOVE")
10136
+ if (_optionalChain([parameter, 'optionalAccess', _568 => _568.comparator]) === "ABOVE" && parsed.kind === "BELOW" || _optionalChain([parameter, 'optionalAccess', _569 => _569.comparator]) === "BELOW" && parsed.kind === "ABOVE")
9818
10137
  return [];
9819
- const at = anchorOf(parsed, _optionalChain([parameter, 'optionalAccess', _527 => _527.comparator]));
10138
+ const at = anchorOf(parsed, _optionalChain([parameter, 'optionalAccess', _570 => _570.comparator]));
9820
10139
  return at === void 0 ? [] : [{ leg, at }];
9821
10140
  });
9822
10141
  placed.sort((a, b) => Math.abs(a.at - level) - Math.abs(b.at - level));
@@ -9921,7 +10240,7 @@ var require_legParser = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
9921
10240
  let bestDistance = Infinity;
9922
10241
  for (const leg of candidates) {
9923
10242
  const outcome = _nullishCoalesce(leg.outcomes.find((o) => o.label.toUpperCase() === side), () => ( leg.outcomes[0]));
9924
- const price = _optionalChain([outcome, 'optionalAccess', _528 => _528.currentPrice]);
10243
+ const price = _optionalChain([outcome, 'optionalAccess', _571 => _571.currentPrice]);
9925
10244
  if (typeof price !== "number" || !Number.isFinite(price))
9926
10245
  continue;
9927
10246
  const distance = Math.abs(price - 0.5);
@@ -10036,7 +10355,7 @@ var require_wire = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10036
10355
  "../../packages/shared/dist/hyperliquid/wire.js"(exports) {
10037
10356
  "use strict";
10038
10357
  Object.defineProperty(exports, "__esModule", { value: true });
10039
- exports.marketLikeLimitPrice = exports.cloidFor = exports.minPerpMarginUsd = exports.minPerpOrderSize = exports.notionalOf = exports.sizeForNotional = exports.roundPerpSize = exports.roundPerpPrice = exports.maxPerpPriceDecimals = exports.MAX_PERP_PRICE_DECIMALS_BASE = exports.MAX_PRICE_SIGNIFICANT_FIGURES = void 0;
10358
+ exports.marketLikeLimitPrice = exports.cloidFor = exports.minPerpMarginUsd = exports.minPerpOrderSize = exports.notionalOf = exports.sizeForNotional = exports.roundPerpSize = exports.roundPerpLimitPrice = exports.roundPerpPrice = exports.maxPerpPriceDecimals = exports.MAX_PERP_PRICE_DECIMALS_BASE = exports.MAX_PRICE_SIGNIFICANT_FIGURES = void 0;
10040
10359
  var viem_1 = _chunkQGM4M3NIjs.__require.call(void 0, "viem");
10041
10360
  var constants_1 = require_constants();
10042
10361
  exports.MAX_PRICE_SIGNIFICANT_FIGURES = 5;
@@ -10061,6 +10380,23 @@ var require_wire = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10061
10380
  return out;
10062
10381
  };
10063
10382
  exports.roundPerpPrice = roundPerpPrice;
10383
+ var roundPerpLimitPrice = (px, szDecimals, isBuy) => {
10384
+ assertFinitePositive(px, "price");
10385
+ const toward = (scaled) => {
10386
+ const clean = Number(scaled.toPrecision(12));
10387
+ return isBuy ? Math.floor(clean) : Math.ceil(clean);
10388
+ };
10389
+ if (px >= 10 ** exports.MAX_PRICE_SIGNIFICANT_FIGURES)
10390
+ return String(toward(px));
10391
+ const sigDecimals = exports.MAX_PRICE_SIGNIFICANT_FIGURES - 1 - Math.floor(Math.log10(px));
10392
+ const decimals = Math.max(0, Math.min(sigDecimals, (0, exports.maxPerpPriceDecimals)(szDecimals)));
10393
+ const factor = 10 ** decimals;
10394
+ const out = stripTrailingZeros((toward(px * factor) / factor).toFixed(decimals));
10395
+ if (Number(out) <= 0)
10396
+ throw new Error(`price ${px} is under the smallest tick at szDecimals=${szDecimals}`);
10397
+ return out;
10398
+ };
10399
+ exports.roundPerpLimitPrice = roundPerpLimitPrice;
10064
10400
  var roundPerpSize = (sz, szDecimals) => {
10065
10401
  if (!Number.isFinite(sz) || sz < 0)
10066
10402
  throw new Error(`size must be a non-negative finite number, got ${sz}`);
@@ -10279,8 +10615,8 @@ var require_positions2 = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10279
10615
  entryPx: num(p.entryPx),
10280
10616
  markValueUsd: _nullishCoalesce(num(p.positionValue), () => ( 0)),
10281
10617
  unrealizedPnlUsd: _nullishCoalesce(num(p.unrealizedPnl), () => ( 0)),
10282
- leverage: _nullishCoalesce(_optionalChain([p, 'access', _529 => _529.leverage, 'optionalAccess', _530 => _530.value]), () => ( 1)),
10283
- leverageType: _nullishCoalesce(_optionalChain([p, 'access', _531 => _531.leverage, 'optionalAccess', _532 => _532.type]), () => ( "cross")),
10618
+ leverage: _nullishCoalesce(_optionalChain([p, 'access', _572 => _572.leverage, 'optionalAccess', _573 => _573.value]), () => ( 1)),
10619
+ leverageType: _nullishCoalesce(_optionalChain([p, 'access', _574 => _574.leverage, 'optionalAccess', _575 => _575.type]), () => ( "cross")),
10284
10620
  liquidationPx: num(p.liquidationPx),
10285
10621
  marginUsedUsd: _nullishCoalesce(num(p.marginUsed), () => ( 0))
10286
10622
  });
@@ -10506,7 +10842,7 @@ var require_config = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10506
10842
  }
10507
10843
  var CLIENT_NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,39}$/;
10508
10844
  function getClientName() {
10509
- const name = _optionalChain([process, 'access', _533 => _533.env, 'access', _534 => _534.MIRAMARKET_CLIENT, 'optionalAccess', _535 => _535.trim, 'call', _536 => _536()]);
10845
+ const name = _optionalChain([process, 'access', _576 => _576.env, 'access', _577 => _577.MIRAMARKET_CLIENT, 'optionalAccess', _578 => _578.trim, 'call', _579 => _579()]);
10510
10846
  return name && CLIENT_NAME.test(name) ? name : void 0;
10511
10847
  }
10512
10848
  }
@@ -10664,14 +11000,26 @@ var require_errors = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10664
11000
  return new CliError2(message, fallback, code);
10665
11001
  }
10666
11002
  function errorMessage2(err) {
10667
- if (err instanceof Error)
10668
- return err.message;
11003
+ const fromData = (value) => {
11004
+ const data = _optionalChain([value, 'optionalAccess', _580 => _580.data]);
11005
+ if (typeof data === "string" && data.trim().length > 0)
11006
+ return data.trim();
11007
+ return null;
11008
+ };
11009
+ if (err instanceof Error) {
11010
+ if (err.message.trim().length > 0)
11011
+ return err.message;
11012
+ return _nullishCoalesce(fromData(err), () => ( err.message));
11013
+ }
10669
11014
  if (typeof err === "string")
10670
11015
  return err;
10671
11016
  if (err && typeof err === "object") {
10672
11017
  const anyErr = err;
10673
- if (typeof anyErr.message === "string")
11018
+ if (typeof anyErr.message === "string" && anyErr.message.trim().length > 0)
10674
11019
  return anyErr.message;
11020
+ const data = fromData(err);
11021
+ if (data)
11022
+ return data;
10675
11023
  if (typeof anyErr.type === "string")
10676
11024
  return `Event(${anyErr.type})`;
10677
11025
  try {
@@ -10925,7 +11273,7 @@ var require_device_auth = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
10925
11273
  let interval = authorization.interval;
10926
11274
  const deadline = Date.now() + authorization.expiresIn * 1e3;
10927
11275
  while (Date.now() < deadline) {
10928
- if (_optionalChain([opts, 'access', _537 => _537.signal, 'optionalAccess', _538 => _538.aborted]))
11276
+ if (_optionalChain([opts, 'access', _581 => _581.signal, 'optionalAccess', _582 => _582.aborted]))
10929
11277
  throw new Error("Login cancelled.");
10930
11278
  await sleep(interval * 1e3);
10931
11279
  try {
@@ -11294,18 +11642,18 @@ var require_api_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11294
11642
  }
11295
11643
  async function listEvents(params) {
11296
11644
  const searchParams = new URLSearchParams();
11297
- if (_optionalChain([params, 'optionalAccess', _539 => _539.limit]) !== void 0)
11645
+ if (_optionalChain([params, 'optionalAccess', _583 => _583.limit]) !== void 0)
11298
11646
  searchParams.set("limit", String(params.limit));
11299
- if (_optionalChain([params, 'optionalAccess', _540 => _540.offset]) !== void 0)
11647
+ if (_optionalChain([params, 'optionalAccess', _584 => _584.offset]) !== void 0)
11300
11648
  searchParams.set("offset", String(params.offset));
11301
11649
  searchParams.set("closed", "false");
11302
11650
  const data = await gammaFetch("/events", searchParams);
11303
- const rawEvents = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _541 => _541.events])) ? data.events : [];
11651
+ const rawEvents = Array.isArray(data) ? data : Array.isArray(_optionalChain([data, 'optionalAccess', _585 => _585.events])) ? data.events : [];
11304
11652
  return { data: rawEvents.map(transformEvent) };
11305
11653
  }
11306
11654
  async function searchEvents(q, params) {
11307
11655
  const searchParams = new URLSearchParams({ q });
11308
- if (_optionalChain([params, 'optionalAccess', _542 => _542.limit]) !== void 0)
11656
+ if (_optionalChain([params, 'optionalAccess', _586 => _586.limit]) !== void 0)
11309
11657
  searchParams.set("limit_per_type", String(params.limit));
11310
11658
  const data = await gammaFetch("/public-search", searchParams);
11311
11659
  const events = (_nullishCoalesce(data.events, () => ( []))).map(transformEvent);
@@ -11313,7 +11661,7 @@ var require_api_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11313
11661
  }
11314
11662
  async function getEvent(id) {
11315
11663
  const data = await gammaFetch(`/events/${encodeURIComponent(id)}`, new URLSearchParams());
11316
- if (!_optionalChain([data, 'optionalAccess', _543 => _543.id]))
11664
+ if (!_optionalChain([data, 'optionalAccess', _587 => _587.id]))
11317
11665
  throw new Error("Event not found");
11318
11666
  return transformEvent(data);
11319
11667
  }
@@ -11457,6 +11805,22 @@ var require_portfolio_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11457
11805
  formatted: (parseInt(b, 10) / 1e6).toFixed(2)
11458
11806
  }));
11459
11807
  }
11808
+ if (raw.data.depositWalletBalances) {
11809
+ for (const [c, tokens] of Object.entries(raw.data.depositWalletBalances)) {
11810
+ if (chain && chain !== "all" && c !== chain)
11811
+ continue;
11812
+ for (const [token, value] of Object.entries(tokens)) {
11813
+ const numeric = parseFloat(value);
11814
+ balances.push({
11815
+ chain: c,
11816
+ token,
11817
+ balance: String(value),
11818
+ formatted: isNaN(numeric) ? "0.00" : numeric.toFixed(2),
11819
+ wallet: "deposit"
11820
+ });
11821
+ }
11822
+ }
11823
+ }
11460
11824
  return {
11461
11825
  balances,
11462
11826
  total: raw.data.formattedBalance,
@@ -11478,7 +11842,7 @@ var require_convex_api = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11478
11842
  "../../packages/miramarket-client/dist/convex-api.js"(exports) {
11479
11843
  "use strict";
11480
11844
  Object.defineProperty(exports, "__esModule", { value: true });
11481
- exports.getCurrentPolicyVersionsRef = exports.getLatestAcceptanceRef = exports.hasAcceptedCurrentPoliciesRef = exports.recordPolicyAcceptanceRef = exports.completeWithdrawalRef = exports.authorizeWithdrawalRef = exports.getCapitalSummaryRef = exports.deleteDraftStrategyRef = exports.updateStrategyDuringRunRef = exports.getStrategyEditStateRef = exports.renameStrategyRef = exports.exitCompletedStrategyRef = exports.cancelStrategyRunRef = exports.getStrategyDetailsRef = exports.getUserStrategiesRef = exports.myBudgetRef = exports.postKeyStrategyRef = exports.getLiveStartRef = exports.requestLiveStartRef = exports.validateAndStartStrategyRunRef = exports.startStrategyRunRef = exports.validateAndImportStrategyRef = exports.importStrategyRef = void 0;
11845
+ exports.getCurrentPolicyVersionsRef = exports.getLatestAcceptanceRef = exports.hasAcceptedCurrentPoliciesRef = exports.recordPolicyAcceptanceRef = exports.completeWithdrawalRef = exports.authorizeWithdrawalRef = exports.getCapitalSummaryRef = exports.deleteDraftStrategyRef = exports.updateStrategyDuringRunRef = exports.getStrategyEditStateRef = exports.renameStrategyRef = exports.exitCompletedStrategyRef = exports.cancelStrategyRunRef = exports.listLimitOrdersRef = exports.getStrategyDetailsRef = exports.getUserStrategiesRef = exports.myBudgetRef = exports.postKeyStrategyRef = exports.getLiveStartRef = exports.requestLiveStartRef = exports.validateAndStartStrategyRunRef = exports.startStrategyRunRef = exports.validateAndImportStrategyRef = exports.importStrategyRef = void 0;
11482
11846
  var server_1 = _chunkQGM4M3NIjs.__require.call(void 0, "convex/server");
11483
11847
  exports.importStrategyRef = (0, server_1.makeFunctionReference)("strategies:importStrategy");
11484
11848
  exports.validateAndImportStrategyRef = (0, server_1.makeFunctionReference)("strategies:validateAndImportStrategy");
@@ -11490,6 +11854,7 @@ var require_convex_api = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11490
11854
  exports.myBudgetRef = (0, server_1.makeFunctionReference)("agentStarts:myBudget");
11491
11855
  exports.getUserStrategiesRef = (0, server_1.makeFunctionReference)("strategies:getUserStrategies");
11492
11856
  exports.getStrategyDetailsRef = (0, server_1.makeFunctionReference)("strategies:getStrategyDetails");
11857
+ exports.listLimitOrdersRef = (0, server_1.makeFunctionReference)("limitOrders:listForRun");
11493
11858
  exports.cancelStrategyRunRef = (0, server_1.makeFunctionReference)("strategies:cancelStrategyRun");
11494
11859
  exports.exitCompletedStrategyRef = (0, server_1.makeFunctionReference)("strategies:exitCompletedStrategy");
11495
11860
  exports.renameStrategyRef = (0, server_1.makeFunctionReference)("strategies:renameStrategy");
@@ -11522,6 +11887,7 @@ var require_convex_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11522
11887
  exports.getConnectionBudget = getConnectionBudget;
11523
11888
  exports.getUserStrategies = getUserStrategies;
11524
11889
  exports.getStrategyDetails = getStrategyDetails;
11890
+ exports.listLimitOrders = listLimitOrders;
11525
11891
  exports.cancelStrategyRun = cancelStrategyRun;
11526
11892
  exports.exitCompletedStrategy = exitCompletedStrategy;
11527
11893
  exports.renameStrategy = renameStrategy;
@@ -11591,6 +11957,9 @@ var require_convex_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11591
11957
  function getStrategyDetails(client, strategyId) {
11592
11958
  return withConvexErrors(() => client.query(convex_api_1.getStrategyDetailsRef, { strategyId }));
11593
11959
  }
11960
+ function listLimitOrders(client, runId) {
11961
+ return withConvexErrors(() => client.query(convex_api_1.listLimitOrdersRef, { runId }));
11962
+ }
11594
11963
  function cancelStrategyRun(client, runId, strategyId) {
11595
11964
  return withConvexErrors(() => client.mutation(convex_api_1.cancelStrategyRunRef, { runId, strategyId }));
11596
11965
  }
@@ -11673,7 +12042,7 @@ var require_account_status = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
11673
12042
  var config_1 = require_config();
11674
12043
  var progress_1 = require_progress();
11675
12044
  async function getAccountStatus(opts) {
11676
- const runStep = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _544 => _544.runStep]), () => ( progress_1.runWithoutProgress));
12045
+ const runStep = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _588 => _588.runStep]), () => ( progress_1.runWithoutProgress));
11677
12046
  const blockers = [];
11678
12047
  const token = (0, auth_1.loadToken)();
11679
12048
  const legacy = Boolean(token) && (0, auth_1.isLegacyToken)(token);
@@ -12093,7 +12462,7 @@ var require_hyperliquid_client = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12093
12462
  positions: (_nullishCoalesce(wire.positions, () => ( []))).map(normalizePositionRow),
12094
12463
  withdrawableUsd: Number(_nullishCoalesce(wire.withdrawable, () => ( 0))),
12095
12464
  withdrawableByDexUsd: withdrawableByDexUsd(wire),
12096
- accountValueUsd: Number(_nullishCoalesce(_optionalChain([wire, 'access', _545 => _545.marginSummary, 'optionalAccess', _546 => _546.accountValue]), () => ( 0)))
12465
+ accountValueUsd: Number(_nullishCoalesce(_optionalChain([wire, 'access', _589 => _589.marginSummary, 'optionalAccess', _590 => _590.accountValue]), () => ( 0)))
12097
12466
  };
12098
12467
  }
12099
12468
  }
@@ -12255,7 +12624,7 @@ var require_login_flow = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12255
12624
  }
12256
12625
  const authorization = await (0, device_auth_1.requestDeviceAuthorization)();
12257
12626
  if (opts.silent) {
12258
- _optionalChain([opts, 'access', _547 => _547.onUrl, 'optionalCall', _548 => _548(authorization.verificationUriComplete, authorization.userCode, authorization.expiresIn)]);
12627
+ _optionalChain([opts, 'access', _591 => _591.onUrl, 'optionalCall', _592 => _592(authorization.verificationUriComplete, authorization.userCode, authorization.expiresIn)]);
12259
12628
  } else if (!opts.json) {
12260
12629
  note2(`${authorization.verificationUriComplete} (code: ${authorization.userCode})`, "Open this URL in your browser to log in");
12261
12630
  }
@@ -12365,6 +12734,7 @@ var require_roi_reach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12365
12734
  "../../packages/miramarket-client/dist/roi-reach.js"(exports) {
12366
12735
  "use strict";
12367
12736
  Object.defineProperty(exports, "__esModule", { value: true });
12737
+ exports.strategyFieldWarnings = void 0;
12368
12738
  exports.bestAsk = bestAsk;
12369
12739
  exports.bookQuote = bookQuote;
12370
12740
  exports.unreachableTakeProfitErrors = unreachableTakeProfitErrors;
@@ -12373,15 +12743,15 @@ var require_roi_reach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12373
12743
  var api_client_1 = require_api_client();
12374
12744
  var BOOK_TIMEOUT_MS = 5e3;
12375
12745
  async function bestAsk(tokenId) {
12376
- return await _asyncOptionalChain([(await bookQuote(tokenId)), 'optionalAccess', async _549 => _549.ask]);
12746
+ return await _asyncOptionalChain([(await bookQuote(tokenId)), 'optionalAccess', async _593 => _593.ask]);
12377
12747
  }
12378
12748
  async function bookQuote(tokenId) {
12379
12749
  const controller = new AbortController();
12380
12750
  const timer = setTimeout(() => controller.abort(), BOOK_TIMEOUT_MS);
12381
12751
  try {
12382
12752
  const book = await (0, api_client_1.getOrderbook)(tokenId, { signal: controller.signal });
12383
- const asks = (_nullishCoalesce(_optionalChain([book, 'optionalAccess', _550 => _550.asks]), () => ( []))).map((a) => Number(a.price)).filter((p) => Number.isFinite(p) && p > 0);
12384
- const minShares = Number(_optionalChain([book, 'optionalAccess', _551 => _551.min_order_size]));
12753
+ const asks = (_nullishCoalesce(_optionalChain([book, 'optionalAccess', _594 => _594.asks]), () => ( []))).map((a) => Number(a.price)).filter((p) => Number.isFinite(p) && p > 0);
12754
+ const minShares = Number(_optionalChain([book, 'optionalAccess', _595 => _595.min_order_size]));
12385
12755
  return {
12386
12756
  ...asks.length > 0 && { ask: Math.min(...asks) },
12387
12757
  ...Number.isFinite(minShares) && minShares > 0 && { minShares }
@@ -12402,6 +12772,10 @@ var require_roi_reach = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12402
12772
  return [];
12403
12773
  }
12404
12774
  }
12775
+ var shared_2 = require_dist();
12776
+ Object.defineProperty(exports, "strategyFieldWarnings", { enumerable: true, get: function() {
12777
+ return shared_2.strategyFieldWarnings;
12778
+ } });
12405
12779
  }
12406
12780
  });
12407
12781
 
@@ -12507,7 +12881,7 @@ var require_post_flow = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12507
12881
  if (rawJson.length > 5e5) {
12508
12882
  throw (0, errors_1.inputError)(`Strategy JSON exceeds size limit (500000 bytes)`);
12509
12883
  }
12510
- if (_optionalChain([strategy, 'access', _552 => _552.nodes, 'optionalAccess', _553 => _553.length]) > 500) {
12884
+ if (_optionalChain([strategy, 'access', _596 => _596.nodes, 'optionalAccess', _597 => _597.length]) > 500) {
12511
12885
  throw (0, errors_1.inputError)(`Too many nodes: ${strategy.nodes.length} exceeds limit of 500`);
12512
12886
  }
12513
12887
  const errors = (0, shared_1.validateConditionalActionStrategy)(strategy);
@@ -12605,7 +12979,7 @@ var require_market_ids = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12605
12979
  try {
12606
12980
  return await (0, http_client_1.request)(path, { base: GAMMA_API_BASE, auth: "none", label: "Gamma API", params: new URLSearchParams(params) });
12607
12981
  } catch (err) {
12608
- const code = _optionalChain([err, 'optionalAccess', _554 => _554.code]);
12982
+ const code = _optionalChain([err, 'optionalAccess', _598 => _598.code]);
12609
12983
  if (code === "NOT_FOUND" || code === "INVALID_REQUEST")
12610
12984
  return null;
12611
12985
  throw err;
@@ -12637,8 +13011,8 @@ var require_market_ids = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12637
13011
  question: _nullishCoalesce(str(row.question), () => ( "")),
12638
13012
  yesTokenId: tokenFor("YES", 0),
12639
13013
  noTokenId: tokenFor("NO", 1),
12640
- eventId: str(_optionalChain([parent, 'optionalAccess', _555 => _555.id])),
12641
- eventSlug: str(_optionalChain([parent, 'optionalAccess', _556 => _556.slug])),
13014
+ eventId: str(_optionalChain([parent, 'optionalAccess', _599 => _599.id])),
13015
+ eventSlug: str(_optionalChain([parent, 'optionalAccess', _600 => _600.slug])),
12642
13016
  closed: row.closed === true
12643
13017
  };
12644
13018
  }
@@ -12693,12 +13067,12 @@ var require_market_ids = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12693
13067
  return [...asMarket("market_id", markets2), ...asEvent("event_id", one(event))];
12694
13068
  }
12695
13069
  const fromUrl = slugsOfUrl(handle);
12696
- if (_optionalChain([fromUrl, 'optionalAccess', _557 => _557.market])) {
13070
+ if (_optionalChain([fromUrl, 'optionalAccess', _601 => _601.market])) {
12697
13071
  const found = asMarket("market_slug", await marketsWhere({ slug: fromUrl.market }));
12698
13072
  if (found.length > 0)
12699
13073
  return found;
12700
13074
  }
12701
- if (_optionalChain([fromUrl, 'optionalAccess', _558 => _558.event]))
13075
+ if (_optionalChain([fromUrl, 'optionalAccess', _602 => _602.event]))
12702
13076
  return asEvent("event_slug", await _asyncNullishCoalesce((await eventsWhere({ slug: fromUrl.event }))[0], async () => ( null)));
12703
13077
  if (fromUrl)
12704
13078
  return [];
@@ -12728,6 +13102,86 @@ ${shown}${more}`);
12728
13102
  }
12729
13103
  });
12730
13104
 
13105
+ // ../../packages/miramarket-client/dist/limit-orders.js
13106
+ var require_limit_orders = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
13107
+ "../../packages/miramarket-client/dist/limit-orders.js"(exports) {
13108
+ "use strict";
13109
+ Object.defineProperty(exports, "__esModule", { value: true });
13110
+ exports.limitPriceCents = limitPriceCents;
13111
+ exports.restDuration = restDuration;
13112
+ exports.limitConditions = limitConditions;
13113
+ exports.hasStoredLimitCondition = hasStoredLimitCondition;
13114
+ exports.limitOrderText = limitOrderText;
13115
+ exports.limitOrderRows = limitOrderRows;
13116
+ function limitPriceCents(price) {
13117
+ return `${Math.round(price * 1e3) / 10}c`;
13118
+ }
13119
+ function restDuration(seconds) {
13120
+ if (seconds >= 86400 && seconds % 86400 === 0)
13121
+ return `${seconds / 86400}d`;
13122
+ if (seconds >= 3600 && seconds % 3600 === 0)
13123
+ return `${seconds / 3600}h`;
13124
+ if (seconds >= 60 && seconds % 60 === 0)
13125
+ return `${seconds / 60}m`;
13126
+ return `${seconds}s`;
13127
+ }
13128
+ function limitConditions(strategy) {
13129
+ const byId = new Map((_nullishCoalesce(strategy.nodes, () => ( []))).map((n) => [n.node_id, n]));
13130
+ const found = [];
13131
+ for (const node of _nullishCoalesce(strategy.nodes, () => ( []))) {
13132
+ const c = node.condition;
13133
+ if (node.type !== "CONDITION" || _optionalChain([c, 'optionalAccess', _603 => _603.signal]) !== "LIMIT_PRICE")
13134
+ continue;
13135
+ const group = (_nullishCoalesce(strategy.decision_groups, () => ( []))).find((g) => g.condition_node_id === node.node_id);
13136
+ const actionType = _optionalChain([byId, 'access', _604 => _604.get, 'call', _605 => _605(_nullishCoalesce(_optionalChain([group, 'optionalAccess', _606 => _606.action_node_ids, 'optionalAccess', _607 => _607[0]]), () => ( ""))), 'optionalAccess', _608 => _608.action, 'optionalAccess', _609 => _609.action_type]);
13137
+ const side = actionType ? actionType === "BUY_MARKET_OUTCOME" ? "buy" : "sell" : c.trigger === "CROSS_BELOW" ? "buy" : "sell";
13138
+ const expiry = typeof _optionalChain([c, 'access', _610 => _610.limit, 'optionalAccess', _611 => _611.expires_after_seconds]) === "number" ? c.limit.expires_after_seconds : null;
13139
+ const dayEnd = _optionalChain([c, 'access', _612 => _612.limit, 'optionalAccess', _613 => _613.expires_at_day_end]) === true;
13140
+ const outcome = String(_nullishCoalesce(_optionalChain([c, 'access', _614 => _614.watch, 'optionalAccess', _615 => _615.outcome_token]), () => ( ""))).toUpperCase();
13141
+ const priceFrom = _optionalChain([c, 'access', _616 => _616.limit, 'optionalAccess', _617 => _617.price_from]) === "BEST_BID" || _optionalChain([c, 'access', _618 => _618.limit, 'optionalAccess', _619 => _619.price_from]) === "BEST_ASK" ? c.limit.price_from : null;
13142
+ const at = priceFrom === "BEST_BID" ? "the best bid" : priceFrom === "BEST_ASK" ? "the best ask" : limitPriceCents(c.threshold);
13143
+ found.push({
13144
+ node_id: node.node_id,
13145
+ side,
13146
+ price: c.threshold,
13147
+ expires_after_seconds: expiry,
13148
+ expires_at_day_end: dayEnd,
13149
+ price_from: priceFrom,
13150
+ text: `Limit ${side}${outcome ? ` ${outcome}` : ""} at ${at}, ` + (dayEnd ? "until 12am PT" : expiry === null ? "good till cancelled" : `good for ${restDuration(expiry)}`)
13151
+ });
13152
+ }
13153
+ return found;
13154
+ }
13155
+ function hasStoredLimitCondition(nodes) {
13156
+ return Array.isArray(nodes) && nodes.some((n) => typeof n === "object" && n !== null && n.conditionOperator === "limit");
13157
+ }
13158
+ var sharesText = (n) => String(Math.round(n * 1e6) / 1e6);
13159
+ function limitOrderText(order) {
13160
+ const head = `${order.status}, ${sharesText(order.filledShares)} of ${sharesText(order.shares)} filled @ ${order.limitPrice}`;
13161
+ const open = order.status === "placing" || order.status === "resting";
13162
+ if (open && typeof order.expiresAt === "number")
13163
+ return `${head}, expires ${new Date(order.expiresAt).toISOString()}`;
13164
+ if (!open && order.message)
13165
+ return `${head} (${order.message})`;
13166
+ return head;
13167
+ }
13168
+ function limitOrderRows(orders) {
13169
+ return orders.map((o) => ({
13170
+ conditionNodeKey: o.conditionNodeKey,
13171
+ actionNodeKey: o.actionNodeKey,
13172
+ side: o.side,
13173
+ limitPrice: o.limitPrice,
13174
+ shares: o.shares,
13175
+ filledShares: o.filledShares,
13176
+ status: o.status,
13177
+ expiresAt: typeof o.expiresAt === "number" ? new Date(o.expiresAt).toISOString() : null,
13178
+ ...o.message && { message: o.message },
13179
+ summary: limitOrderText(o)
13180
+ }));
13181
+ }
13182
+ }
13183
+ });
13184
+
12731
13185
  // ../../packages/miramarket-client/dist/preview.js
12732
13186
  var require_preview = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12733
13187
  "../../packages/miramarket-client/dist/preview.js"(exports) {
@@ -12736,6 +13190,7 @@ var require_preview = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12736
13190
  exports.buildPreview = buildPreview;
12737
13191
  exports.previewToText = previewToText;
12738
13192
  var shared_1 = require_dist();
13193
+ var limit_orders_1 = require_limit_orders();
12739
13194
  function detectDroppedSemantics(strategy) {
12740
13195
  const warnings = [];
12741
13196
  for (const node of strategy.nodes) {
@@ -12780,6 +13235,7 @@ var require_preview = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12780
13235
  action_nodes: actionCount,
12781
13236
  edges: strategy.edges.length,
12782
13237
  decision_groups: groups,
13238
+ limit_conditions: (0, limit_orders_1.limitConditions)(strategy),
12783
13239
  valid,
12784
13240
  validation_errors: errors.length,
12785
13241
  warnings
@@ -12796,6 +13252,11 @@ var require_preview = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12796
13252
  `decision_groups: ${p.decision_groups.length}`,
12797
13253
  `valid: ${p.valid}`
12798
13254
  ];
13255
+ if (p.limit_conditions.length > 0) {
13256
+ lines.push(`limit_conditions:`);
13257
+ for (const l of p.limit_conditions)
13258
+ lines.push(` - ${l.node_id}: ${l.text}`);
13259
+ }
12799
13260
  if (!p.valid)
12800
13261
  lines.push(`validation_errors: ${p.validation_errors}`);
12801
13262
  if (p.warnings.length > 0) {
@@ -12928,8 +13389,8 @@ var require_strategy_remote_edit = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
12928
13389
  return {
12929
13390
  strategy,
12930
13391
  isRunActive: state.isRunActive,
12931
- runId: _nullishCoalesce(_optionalChain([state, 'access', _559 => _559.latestRun, 'optionalAccess', _560 => _560._id]), () => ( null)),
12932
- runStatus: _nullishCoalesce(_optionalChain([state, 'access', _561 => _561.latestRun, 'optionalAccess', _562 => _562.status]), () => ( null)),
13392
+ runId: _nullishCoalesce(_optionalChain([state, 'access', _620 => _620.latestRun, 'optionalAccess', _621 => _621._id]), () => ( null)),
13393
+ runStatus: _nullishCoalesce(_optionalChain([state, 'access', _622 => _622.latestRun, 'optionalAccess', _623 => _623.status]), () => ( null)),
12933
13394
  lockedNodeKeys: [...state.lockedNodeKeys],
12934
13395
  hardLockedNodeKeys: [...state.hardLockedNodeKeys],
12935
13396
  waitingConditionKeys: [...state.waitingConditionKeys],
@@ -12993,7 +13454,7 @@ ${errors.join("\n")}`, "LOCKED_NODE_EDIT");
12993
13454
  for (const [id, node] of nodesById(strategy)) {
12994
13455
  const action = node.action;
12995
13456
  const condition = node.condition;
12996
- const market = _optionalChain([action, 'optionalAccess', _563 => _563.target, 'optionalAccess', _564 => _564.market]);
13457
+ const market = _optionalChain([action, 'optionalAccess', _624 => _624.target, 'optionalAccess', _625 => _625.market]);
12997
13458
  for (const f of DISCARDED_ACTION_FIELDS)
12998
13459
  if (action && f in action)
12999
13460
  found.push(`${id}: action.${f}`);
@@ -13312,6 +13773,7 @@ var require_dist2 = _chunkQGM4M3NIjs.__commonJS.call(void 0, {
13312
13773
  __exportStar(require_post_flow(), exports);
13313
13774
  __exportStar(require_roi_reach(), exports);
13314
13775
  __exportStar(require_market_ids(), exports);
13776
+ __exportStar(require_limit_orders(), exports);
13315
13777
  __exportStar(require_preview(), exports);
13316
13778
  __exportStar(require_strategy_edit(), exports);
13317
13779
  __exportStar(require_strategy_remote_edit(), exports);
@@ -13428,7 +13890,7 @@ function cliNote(body, title) {
13428
13890
  }
13429
13891
  }
13430
13892
  async function withSpinner(label, fn, opts) {
13431
- const json = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _565 => _565.json]), () => ( jsonMode));
13893
+ const json = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _626 => _626.json]), () => ( jsonMode));
13432
13894
  if (json || !process.stdout.isTTY) {
13433
13895
  return fn();
13434
13896
  }
@@ -13436,7 +13898,7 @@ async function withSpinner(label, fn, opts) {
13436
13898
  s.start(label);
13437
13899
  try {
13438
13900
  const result = await fn();
13439
- s.stop(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _566 => _566.successLabel]), () => ( label)));
13901
+ s.stop(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _627 => _627.successLabel]), () => ( label)));
13440
13902
  return result;
13441
13903
  } catch (err) {
13442
13904
  s.stop(useColor() ? _picocolors2.default.red("Failed") : "Failed");
@@ -13468,7 +13930,7 @@ var BaseCommand = class extends _core.Command {
13468
13930
  }
13469
13931
  if ("parse" in err) {
13470
13932
  if (this.jsonMode) {
13471
- const exitCode = _nullishCoalesce(_optionalChain([err, 'access', _567 => _567.oclif, 'optionalAccess', _568 => _568.exit]), () => ( import_miramarket_client2.EXIT_CODES.INPUT));
13933
+ const exitCode = _nullishCoalesce(_optionalChain([err, 'access', _628 => _628.oclif, 'optionalAccess', _629 => _629.exit]), () => ( import_miramarket_client2.EXIT_CODES.INPUT));
13472
13934
  this.emitFailure(firstLine(err.message), exitCode, "PARSE_ERROR");
13473
13935
  this.exit(exitCode);
13474
13936
  return;