dexbot 1.6.12 → 1.6.14

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 (213) hide show
  1. package/CHANGELOG.md +65 -1
  2. package/README.md +2 -2
  3. package/analysis/README.md +9 -11
  4. package/analysis/ama_fitting/README.md +5 -3
  5. package/claw/README.md +1 -0
  6. package/claw/docs/AI_BOT_LIBRARY_API.md +3 -1
  7. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
  8. package/claw/modules/claw_bridge.ts +0 -3
  9. package/claw/modules/claw_catalog.ts +8 -4
  10. package/claw/modules/claw_skill_md.ts +1 -0
  11. package/claw/modules/dexbot_profiles.ts +59 -15
  12. package/claw/modules/types.ts +2 -1
  13. package/claw/package.json +3 -3
  14. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  15. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  16. package/claw/skills/margin-trading/SKILL.md +1 -1
  17. package/claw/skills/margin-trading/references/position-management.md +1 -1
  18. package/claw/tsconfig.json +2 -2
  19. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +1 -14
  20. package/dist/analysis/ama_fitting/fetch_lp_candles.js +51 -41
  21. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -24
  22. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +36 -18
  23. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +18 -66
  24. package/dist/analysis/analyze_args.d.ts +12 -0
  25. package/dist/analysis/analyze_args.js +20 -0
  26. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +1 -16
  27. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +20 -101
  28. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +26 -92
  29. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
  30. package/dist/analysis/bot_fitting/shared_utils.d.ts +71 -3
  31. package/dist/analysis/bot_fitting/shared_utils.js +124 -8
  32. package/dist/analysis/chart_ui.d.ts +30 -1
  33. package/dist/analysis/chart_ui.js +37 -1
  34. package/dist/analysis/fills_cache.d.ts +3 -23
  35. package/dist/analysis/fills_cache.js +3 -84
  36. package/dist/analysis/fills_source.d.ts +31 -1
  37. package/dist/analysis/fills_source.js +69 -1
  38. package/dist/analysis/grid_correction_check.d.ts +1 -23
  39. package/dist/analysis/grid_correction_check.js +15 -58
  40. package/dist/analysis/math_utils.d.ts +85 -1
  41. package/dist/analysis/math_utils.js +116 -1
  42. package/dist/analysis/price_sources.d.ts +22 -1
  43. package/dist/analysis/price_sources.js +23 -0
  44. package/dist/analysis/resolve_source.js +31 -10
  45. package/dist/analysis/trade_profitability.d.ts +6 -0
  46. package/dist/analysis/trade_profitability.js +23 -97
  47. package/dist/analysis/tradingview/analyze_tradingview.d.ts +1 -17
  48. package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
  49. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +27 -40
  50. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
  51. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +22 -80
  52. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +11 -37
  53. package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
  54. package/dist/analysis/worker_pool.d.ts +38 -0
  55. package/dist/analysis/worker_pool.js +67 -0
  56. package/dist/dexbot.js +67 -48
  57. package/dist/market_adapter/ama_signal_runner.js +21 -54
  58. package/dist/market_adapter/candle_utils.d.ts +7 -1
  59. package/dist/market_adapter/candle_utils.js +11 -1
  60. package/dist/market_adapter/cli_args.d.ts +22 -0
  61. package/dist/market_adapter/cli_args.js +30 -0
  62. package/dist/market_adapter/core/config_normalizers.js +11 -6
  63. package/dist/market_adapter/core/kibana_candles.d.ts +3 -1
  64. package/dist/market_adapter/core/kibana_candles.js +3 -2
  65. package/dist/market_adapter/core/market_adapter_service.d.ts +85 -85
  66. package/dist/market_adapter/core/market_adapter_service.js +93 -158
  67. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
  68. package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
  69. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
  70. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
  71. package/dist/market_adapter/inputs/fetch_book_data.js +0 -1
  72. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +63 -107
  73. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +8 -1
  74. package/dist/market_adapter/inputs/fetch_lp_data.js +25 -7
  75. package/dist/market_adapter/inputs/kibana_feed_source.js +4 -26
  76. package/dist/market_adapter/inputs/window_cache.d.ts +4 -72
  77. package/dist/market_adapter/inputs/window_cache.js +52 -177
  78. package/dist/market_adapter/interval_utils.d.ts +11 -1
  79. package/dist/market_adapter/interval_utils.js +16 -1
  80. package/dist/market_adapter/lp_chart_runner.d.ts +3 -0
  81. package/dist/market_adapter/lp_chart_runner.js +37 -19
  82. package/dist/market_adapter/market_adapter.js +27 -72
  83. package/dist/market_adapter/utils/data_discovery.d.ts +45 -1
  84. package/dist/market_adapter/utils/data_discovery.js +220 -27
  85. package/dist/market_adapter/utils/month_shards.d.ts +84 -0
  86. package/dist/market_adapter/utils/month_shards.js +237 -0
  87. package/dist/modules/account_bots.d.ts +8 -6
  88. package/dist/modules/account_bots.js +112 -131
  89. package/dist/modules/account_orders.d.ts +49 -4
  90. package/dist/modules/account_orders.js +114 -49
  91. package/dist/modules/bitshares-native/chain_client.d.ts +1 -1
  92. package/dist/modules/bitshares-native/chain_client.js +14 -13
  93. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
  94. package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
  95. package/dist/modules/bitshares-native/resolvers.js +22 -25
  96. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
  97. package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
  98. package/dist/modules/bitshares-native/serial/types.js +22 -50
  99. package/dist/modules/bitshares-native/signing_client.d.ts +1 -1
  100. package/dist/modules/bot_defaults.d.ts +18 -3
  101. package/dist/modules/bot_defaults.js +34 -8
  102. package/dist/modules/bot_settings.d.ts +5 -1
  103. package/dist/modules/bot_settings.js +55 -21
  104. package/dist/modules/broadcast_failure.d.ts +2 -1
  105. package/dist/modules/chain_orders.d.ts +1 -1
  106. package/dist/modules/chain_orders.js +51 -96
  107. package/dist/modules/cli_start_onboarding.d.ts +2 -1
  108. package/dist/modules/config.js +6 -1
  109. package/dist/modules/constants.d.ts +14 -6
  110. package/dist/modules/constants.js +32 -6
  111. package/dist/modules/cr_planner.d.ts +1 -1
  112. package/dist/modules/cr_planner.js +1 -5
  113. package/dist/modules/credit_pricing.d.ts +2 -1
  114. package/dist/modules/credit_pricing.js +36 -40
  115. package/dist/modules/credit_runtime.d.ts +7 -0
  116. package/dist/modules/credit_runtime.js +45 -73
  117. package/dist/modules/daemon_node_health.d.ts +4 -3
  118. package/dist/modules/dexbot_class.d.ts +33 -17
  119. package/dist/modules/dexbot_class.js +113 -61
  120. package/dist/modules/dexbot_cow_runtime.d.ts +62 -181
  121. package/dist/modules/dexbot_cow_runtime.js +380 -69
  122. package/dist/modules/dexbot_credential_client.d.ts +1 -23
  123. package/dist/modules/dexbot_credential_client.js +2 -3
  124. package/dist/modules/dexbot_fill_runtime.d.ts +2 -3
  125. package/dist/modules/dexbot_fill_runtime.js +17 -7
  126. package/dist/modules/dexbot_maintenance_runtime.d.ts +36 -81
  127. package/dist/modules/dexbot_maintenance_runtime.js +137 -133
  128. package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
  129. package/dist/modules/dexbot_startup_runtime.js +25 -14
  130. package/dist/modules/dexbot_state_recovery.js +16 -0
  131. package/dist/modules/general_settings.d.ts +1 -1
  132. package/dist/modules/graceful_shutdown.js +17 -11
  133. package/dist/modules/key_store.d.ts +0 -5
  134. package/dist/modules/key_store.js +1 -2
  135. package/dist/modules/lazy_shim.d.ts +11 -0
  136. package/dist/modules/lazy_shim.js +16 -0
  137. package/dist/modules/node_connect_policy.d.ts +3 -2
  138. package/dist/modules/node_failure_ledger.d.ts +6 -5
  139. package/dist/modules/order/accounting.js +11 -11
  140. package/dist/modules/order/export.js +2 -2
  141. package/dist/modules/order/format.d.ts +26 -3
  142. package/dist/modules/order/format.js +33 -3
  143. package/dist/modules/order/genesis_policy.d.ts +4 -4
  144. package/dist/modules/order/genesis_policy.js +6 -3
  145. package/dist/modules/order/grid.d.ts +26 -12
  146. package/dist/modules/order/grid.js +468 -80
  147. package/dist/modules/order/grid_reconcile.d.ts +1 -1
  148. package/dist/modules/order/grid_reconcile.js +5 -5
  149. package/dist/modules/order/grid_reconcile_internal.js +48 -40
  150. package/dist/modules/order/index.d.ts +35 -8
  151. package/dist/modules/order/logger.d.ts +1 -8
  152. package/dist/modules/order/logger.js +2 -11
  153. package/dist/modules/order/manager.d.ts +18 -15
  154. package/dist/modules/order/manager.js +91 -74
  155. package/dist/modules/order/strategy.d.ts +2 -2
  156. package/dist/modules/order/strategy.js +51 -21
  157. package/dist/modules/order/sync_engine.js +4 -0
  158. package/dist/modules/order/utils/math.d.ts +3 -3
  159. package/dist/modules/order/utils/math.js +38 -27
  160. package/dist/modules/order/utils/order.d.ts +58 -58
  161. package/dist/modules/order/utils/order.js +158 -137
  162. package/dist/modules/order/utils/system.d.ts +202 -35
  163. package/dist/modules/order/utils/system.js +409 -31
  164. package/dist/modules/order/utils/validate.js +28 -6
  165. package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
  166. package/dist/modules/paths.js +32 -34
  167. package/dist/modules/runtime_settings.d.ts +3 -5
  168. package/dist/modules/runtime_settings.js +3 -3
  169. package/dist/modules/settings_merge.d.ts +2 -2
  170. package/dist/modules/socket_json_client.d.ts +2 -1
  171. package/dist/modules/types.d.ts +89 -30
  172. package/dist/modules/utils/errors.js +1 -3
  173. package/dist/modules/version_notice.d.ts +11 -10
  174. package/dist/pm2.d.ts +0 -1
  175. package/dist/pm2.js +56 -35
  176. package/dist/scripts/analyze-git.js +2 -15
  177. package/dist/scripts/analyze-orders.d.ts +1 -1
  178. package/dist/scripts/analyze-orders.js +4 -4
  179. package/dist/scripts/chart_command.js +2 -2
  180. package/dist/scripts/check_any.d.ts +4 -0
  181. package/dist/scripts/check_any.js +53 -21
  182. package/dist/scripts/diagnose-pool-history.js +1 -6
  183. package/dist/scripts/divergence-calc.js +6 -6
  184. package/dist/scripts/run-tests.js +0 -1
  185. package/dist/scripts/sync-version.js +0 -10
  186. package/dist/scripts/validate_bots.d.ts +1 -1
  187. package/dist/scripts/validate_bots.js +3 -3
  188. package/dist/unlock.js +7 -2
  189. package/docs/BITSHARES_ONBOARDING.md +8 -12
  190. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -3
  191. package/docs/COW_INVARIANTS.md +6 -6
  192. package/docs/DEXBOT_COMPARISON.md +7 -7
  193. package/docs/EVOLUTION.md +10 -8
  194. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
  195. package/docs/GRID_PRICE_INVARIANT.md +3 -3
  196. package/docs/GRID_RECALCULATION.md +4 -1
  197. package/docs/GRID_RECONCILE.md +4 -4
  198. package/docs/LIFECYCLE.md +11 -11
  199. package/docs/LOGGING.md +14 -0
  200. package/docs/MPA_CREDIT_USAGE.md +1 -1
  201. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
  202. package/docs/README.md +3 -3
  203. package/docs/WORKFLOW.md +1 -0
  204. package/docs/architecture.md +25 -16
  205. package/docs/developer_guide.md +7 -2
  206. package/market_adapter/README.md +6 -4
  207. package/package.json +6 -9
  208. package/scripts/README.md +43 -38
  209. package/tests/README.md +26 -11
  210. package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
  211. package/dist/scripts/diagnose-kibana-candles.js +0 -82
  212. package/scripts/git-viewer.sh +0 -489
  213. package/scripts/postinstall.js +0 -16
@@ -21,7 +21,7 @@ import * as chainOrdersModule from './chain_orders.js';
21
21
  export declare function isEvacuationStampStillValid(liveBoundary: unknown, liveGapSlots: unknown, sourceId: unknown, destId: unknown, orderType: unknown): boolean;
22
22
  import * as workingGridModule from './order/working_grid.js';
23
23
  declare const WorkingGrid: typeof workingGridModule.WorkingGrid;
24
- import type { BotLike, OrderManagerLike, ManagedOrder, ChainOrder, UnknownRecord, AssetInfo, CowAction } from './types.js';
24
+ import type { BotLike, OrderManagerLike, ManagedOrder, ChainOrder, UnknownRecord, CowAction } from './types.js';
25
25
  /** Loose JSON-object view. */
26
26
  type JsonObj = UnknownRecord;
27
27
  /** Final integer tuple for a planned order op. */
@@ -58,18 +58,6 @@ export interface CowResult extends JsonObj {
58
58
  refillSlotIds?: string[];
59
59
  fills?: unknown[];
60
60
  }
61
- /** Result of the pre-broadcast guard chain. */
62
- export interface PreBroadcastGuardResult extends JsonObj {
63
- proceed: boolean;
64
- result?: JsonObj;
65
- crossingCandidates?: unknown[];
66
- intraBatchCandidates?: unknown[];
67
- }
68
- /** A CREATE op context with its resolved order + integer tuple. */
69
- type CreateContext = OpPhase & {
70
- finalInts: FinalInts;
71
- order: ManagedOrder;
72
- };
73
61
  /** A chain order enriched with the loose fields COW recovery reads. */
74
62
  export interface ChainOrderLike extends ChainOrder {
75
63
  type?: unknown;
@@ -83,14 +71,6 @@ export interface ChainOrderLike extends ChainOrder {
83
71
  price?: unknown;
84
72
  order?: JsonObj;
85
73
  }
86
- /** Normalized integer tuple used by pending-broadcast recovery. */
87
- interface NormalizedChainOrder {
88
- side: string;
89
- assetA: string;
90
- assetB: string;
91
- sellInt: number;
92
- receiveInt: number;
93
- }
94
74
  /** A COW operation context (create/update/cancel/rotation). */
95
75
  export interface OpPhase extends JsonObj {
96
76
  kind?: unknown;
@@ -112,24 +92,6 @@ declare function buildOutsideInPairGroupsForOrders(orders: ManagedOrder[]): unkn
112
92
  * @returns {Array<Array>}
113
93
  */
114
94
  declare function buildOutsideInPairGroupsForCreateEntries(createEntries: PendingEntry[]): unknown[][];
115
- /**
116
- * Extract operation results from a batch transaction result.
117
- * @param {Object|Array|null} result
118
- * @param {string} [warnContext='']
119
- * @param {Function} [logFn] - Optional logger function, called with (msg, level) on unrecognized shape
120
- * @returns {Array}
121
- */
122
- declare function extractOperationResults(result: unknown, warnContext?: string, logFn?: ((message: string, level?: string) => void) | null): unknown[];
123
- /**
124
- * Find CREATE operation contexts whose broadcast result did not include a chain order id.
125
- * @param {Array} operationResults
126
- * @param {Array} opContexts
127
- * @returns {Array<{index:number, ctx:Object}>}
128
- */
129
- declare function findMissingCreateResultContexts(operationResults: unknown, opContexts: unknown): {
130
- index: number;
131
- ctx: OpPhase;
132
- }[];
133
95
  /**
134
96
  * Merge missing CREATE result contexts into manager._lastUnmatchedChainOrders.
135
97
  * @param {import('./dexbot_class.js').DEXBot} bot
@@ -165,21 +127,6 @@ declare function recordPendingBroadcast(bot: BotLike, entry: PendingEntry & {
165
127
  * @param {Map} pendingBroadcasts
166
128
  */
167
129
  declare function clearPendingBroadcasts(pendingBroadcasts: unknown): void;
168
- /**
169
- * Drop only the pending-broadcast entries for the given CREATE slots.
170
- *
171
- * Used by the re-plan path: the original plan's ops are abandoned with its
172
- * working grid, so their pending entries must not trip the recursion's own
173
- * pending-broadcast guard. Entries recorded by an EARLIER unresolved batch
174
- * (different slots) are KEPT — clearing them here would let the fresh plan
175
- * re-create slots whose earlier uncertain broadcast may have landed
176
- * (duplicate orders). The batch-entry guard only fires for batches WITH
177
- * CREATE actions, so a create-less batch can reach the re-plan path while
178
- * earlier entries are still live.
179
- * @param {import('./dexbot_class.js').DEXBot} bot
180
- * @param {Array} actions - The abandoned batch's actions (COW_ACTIONS)
181
- */
182
- declare function clearPendingBroadcastsForSlots(bot: BotLike, actions: JsonObj[]): void;
183
130
  /**
184
131
  * Pop a pushed working-grid stack entry exactly once, guarded on the push
185
132
  * marker (manager-owned discipline — see OrderManager._pushWorkingGridRef /
@@ -191,23 +138,6 @@ declare function clearPendingBroadcastsForSlots(bot: BotLike, actions: JsonObj[]
191
138
  * @param {Object} cowResult - Rebalance/COW result carrying _workingGridPushed
192
139
  */
193
140
  declare function popPushedWorkingGrid(bot: BotLike, cowResult: JsonObj): void;
194
- /**
195
- * Build a fingerprint for an on-chain order so it can be matched against
196
- * the pending-broadcast cache.
197
- * @param {import('./dexbot_class.js').DEXBot} bot
198
- * @param {Object} chainOrder
199
- * @param {string} slotId
200
- * @returns {string|null}
201
- */
202
- declare function buildChainOrderFingerprint(bot: BotLike, chainOrder: ChainOrderLike, slotId: string): string | null;
203
- /**
204
- * Normalize raw BitShares limit_order_object data into the integer tuple
205
- * used by pending-broadcast recovery.
206
- * @param {import('./dexbot_class.js').DEXBot} bot
207
- * @param {Object} chainOrder
208
- * @returns {{side: string, assetA: string, assetB: string, sellInt: number, receiveInt: number}|null}
209
- */
210
- declare function normalizeChainOrderForPendingMatch(bot: BotLike, chainOrder: ChainOrderLike): NormalizedChainOrder | null;
211
141
  /**
212
142
  * Find a chain order that matches a planned slot using price+size proximity.
213
143
  * @param {import('./dexbot_class.js').DEXBot} bot
@@ -248,27 +178,6 @@ declare function reconcileAfterUncertainBroadcast(bot: BotLike, err: unknown, op
248
178
  * @returns {Promise<number>} discardedCount
249
179
  */
250
180
  declare function restoreDiscardedCreates(bot: BotLike, discarded: PendingEntry[], opContexts: OpPhase[]): Promise<number>;
251
- /**
252
- * Reconcile a broadcast whose chain state is unknown (implementation).
253
- * @param {import('./dexbot_class.js').DEXBot} bot
254
- * @param {BroadcastUncertainError} err
255
- * @param {Array<Object>} opContexts
256
- * @param {Object} options
257
- * @returns {Promise<Object>}
258
- */
259
- declare function reconcileAfterUncertainBroadcastImpl(bot: BotLike, err: unknown, opContexts: OpPhase[], _options: JsonObj): Promise<UnknownRecord | {
260
- executed: boolean;
261
- hadRotation: boolean;
262
- uncertain: boolean;
263
- ambiguousRead: boolean;
264
- }>;
265
- /**
266
- * Check whether to execute creates in outside-in pair mode.
267
- * @param {import('./dexbot_class.js').DEXBot} bot
268
- * @param {Array} opContexts
269
- * @returns {boolean}
270
- */
271
- declare function shouldExecuteCreatePairMode(_bot: unknown, opContexts: OpPhase[]): boolean;
272
181
  /**
273
182
  * Execute operations with retry on BroadcastUncertainError.
274
183
  *
@@ -337,42 +246,6 @@ declare function executeChunkedWithRetryOnUncertain(bot: BotLike, operations: un
337
246
  result: unknown;
338
247
  opContexts: OpPhase[];
339
248
  }>;
340
- /**
341
- * Validate that operations can be executed with available funds before broadcasting.
342
- * @param {import('./dexbot_class.js').DEXBot} bot
343
- * @param {Array} operations
344
- * @param {Object} assetA
345
- * @param {Object} assetB
346
- * @returns {Object} { isValid: boolean, summary: string }
347
- */
348
- declare function validateOperationFunds(bot: BotLike, operations: JsonObj[], assetA: AssetInfo, assetB: AssetInfo): {
349
- isValid: boolean;
350
- summary: string;
351
- violations?: JsonObj[];
352
- };
353
- /**
354
- * Resolve the ideal size from an order-like object with fallback.
355
- * @param {import('./dexbot_class.js').DEXBot} bot
356
- * @param {Object|null} orderLike
357
- * @param {number|null} [fallbackSize=null]
358
- * @returns {number|null}
359
- */
360
- declare function resolveIdealSizeForValidation(_bot: unknown, orderLike: JsonObj | null | undefined, fallbackSize?: number | null): number | null;
361
- /**
362
- * Validate that an order size is safe to execute.
363
- * @param {import('./dexbot_class.js').DEXBot} bot
364
- * @param {number} size
365
- * @param {string} type
366
- * @param {Object|null} [orderLike=null]
367
- * @param {number|null} [fallbackSize=null]
368
- * @returns {unknown}
369
- */
370
- declare function validateOrderSizeForExecution(bot: BotLike, size: number, type: string, orderLike?: JsonObj | null, fallbackSize?: number | null): {
371
- isValid: boolean;
372
- reason: string | null;
373
- minAbsoluteSize: number;
374
- minDustSize: number | null;
375
- };
376
249
  declare function checkGridPriceInvariant(slotId: unknown, price: unknown, genesis: unknown): {
377
250
  ok: boolean;
378
251
  reason: string;
@@ -395,10 +268,47 @@ declare function checkGridPriceInvariant(slotId: unknown, price: unknown, genesi
395
268
  * planned price — an undefined grid, which the load and sync gates refuse).
396
269
  */
397
270
  declare function deriveRotationPrice(bot: BotLike, newGridId: unknown): number;
271
+ /**
272
+ * P2 observability (advisory, never blocks): count a BUY emitted at or above
273
+ * the last filled BUY pivot.
274
+ *
275
+ * This is the "re-stamp a just-filled BUY above the anchor" shape the
276
+ * LAST-FILL-GUARD exists to block (`BUY > pivot*(1-half)`), so a counted
277
+ * emission means the guard was bypassed (spread correction / stamped gap
278
+ * evacuation) or the pivot was unjudgeable and the probe failed open. The
279
+ * counter makes a bypass leak visible without changing placement policy —
280
+ * the guard already owns enforcement, and turning this into a second gate
281
+ * would re-introduce the reverted placement-guard class.
282
+ *
283
+ * Warns at most once per batch (keyed on `_currentCycleId`). Never throws.
284
+ *
285
+ * @returns {boolean} true when the emission was counted
286
+ */
287
+ declare function recordRestampBuyAboveAnchor(bot: BotLike, price: unknown, type: unknown): boolean;
288
+ /**
289
+ * Collect non-spread-correction CREATE/UPDATE destinations that sit inside
290
+ * the plan's gap band.
291
+ *
292
+ * Mode C(a) SHADOW: the gap band is not unconditionally illegal — spread
293
+ * correction legitimately places INTO it (the LAST-FILL-GUARD bypass exists
294
+ * for exactly that) and gap evacuation moves an order OUT of it. Excluding
295
+ * those origins leaves the genuinely suspicious set: a rail placement whose
296
+ * destination geometry IS the spread. The result is counted/warned, never
297
+ * blocked (see the guard call site for the revert-history rationale).
298
+ *
299
+ * Pure and never throws. A non-finite boundary/gap selects the empty set.
300
+ *
301
+ * @param {Array<Object>|null} actions - COW actions
302
+ * @param {unknown} boundary - The PLAN's boundary (workingBoundary), not the committed one
303
+ * @param {unknown} gapSlots - Gap slot count
304
+ * @returns {string[]} destinations inside the gap band
305
+ */
306
+ declare function collectGapBandPlacementShadowSlots(actions: CowAction[] | null | undefined, boundary: unknown, gapSlots: unknown): string[];
398
307
  /**
399
308
  * LAST-FILL-GUARD helper — pivot ± halfIncrement (replaces price-tolerance).
400
- * last fill @x with increment i: BUY < x*(1 - i/2/100), SELL > x*(1 + i/2/100)
401
- * e.g. x=1000, i=0.5% => BUY < 997.5, SELL > 1002.5
309
+ * last fill @x with increment i (blocked shapes): BUY > x*(1 - i/2/100),
310
+ * SELL < x*(1 + i/2/100)
311
+ * e.g. x=1000, i=0.5% => BUY > 997.5 and SELL < 1002.5 are blocked
402
312
  * Cold (pivot null or lastType null) => disabled. Spread-correction CREATES
403
313
  * bypass per-action (see broadcast sites); gap-evacuation rotation UPDATEs
404
314
  * bypass only via the violation-reducing allowance (origin='gap-evacuation',
@@ -421,6 +331,26 @@ declare function isLastFillGuardBlocked(price: number, _size: number, type: unkn
421
331
  halfInc?: number;
422
332
  threshold?: number | null;
423
333
  };
334
+ /**
335
+ * Whether a spread-correction CREATE may bypass the LAST-FILL-GUARD.
336
+ *
337
+ * The bypass exists so gap repair can close even after a recent fill (the
338
+ * correction is tightening the spread, not chasing it). It must not become a
339
+ * licence to place THROUGH the market the bot last traded at:
340
+ *
341
+ * 1. A real fill pivot (`lastFillPivotSource === 'fill'`) is always honored —
342
+ * no bypass. A sell below the last fill (or a buy above it) is the
343
+ * issue-#31 adverse fill.
344
+ * 2. A cold/book pivot is a heuristic (book seed) or absent, so the historical
345
+ * fail-open bypass is kept — but only while the LOCAL snapshot is fresh.
346
+ * A stale snapshot (known-unmatched chain orders, or an old sync) can hide
347
+ * the real window edge, so the bypass is withheld and the guard applies.
348
+ *
349
+ * Exported for tests.
350
+ * @param {Object} bot
351
+ * @returns {boolean} True when the bypass may be used
352
+ */
353
+ declare function isSpreadCorrectionBypassAllowed(bot: BotLike): boolean;
424
354
  /**
425
355
  * Refresh the LAST-FILL guard pivot from fills that arrived while the current
426
356
  * batch was being planned or broadcast but have not been ingested yet.
@@ -462,28 +392,6 @@ declare function buildCowResultFromPlan(bot: BotLike, plan: JsonObj): CowResult;
462
392
  * in-place rotations already have their size/price changes in the working grid.
463
393
  */
464
394
  declare function applyRotationTransitionsToWorkingGrid(bot: BotLike, workingGrid: InstanceType<typeof WorkingGrid>, executedContexts: OpPhase[]): void;
465
- /**
466
- * Poll the chain after an uncertain broadcast to check if CREATE operations
467
- * were actually accepted. Uses fingerprint matching against readOpenOrders.
468
- * Falls back to reconciliation if polling cannot confirm within retries.
469
- *
470
- * We specifically confirm CREATE operations because they leave a detectable
471
- * footprint on the chain (new order with matching fingerprint). UPDATEs and
472
- * CANCELs modify existing orders and cannot be reliably distinguished from
473
- * "not yet visible" state by simple polling.
474
- *
475
- * @param {Object} [options]
476
- * @param {number} [options.maxPollRetries] - Poll attempts before reconciliation fallback
477
- * @param {number} [options.pollIntervalMs] - Delay between polls; tests pass 0
478
- * to skip the production 1.5s pacing without changing the poll semantics
479
- * @returns {{ allConfirmed: boolean, confirmed: Array, unconfirmed: Array }}
480
- */
481
- declare function pollChainForConfirmation(bot: BotLike, opContexts: OpPhase[], options?: JsonObj): Promise<{
482
- allConfirmed: boolean;
483
- confirmed: CreateContext[];
484
- unconfirmed: OpPhase[];
485
- confirmedChainIds: string[];
486
- }>;
487
395
  /**
488
396
  * Normalize a producer-supplied refillSlotIds wire into a Set.
489
397
  * Absent/empty/non-array => empty (guarded default, never fail-open).
@@ -528,14 +436,6 @@ declare function resolveRefillBoundaryHold(workingBoundary: unknown, committedBo
528
436
  * @returns {number} Consecutive-hold count after this batch (0 when clear)
529
437
  */
530
438
  declare function trackBoundaryHold(manager: OrderManagerLike, held: boolean, keptBoundary: unknown, plannedBoundary: unknown, heldSlotIds: string[]): number;
531
- /**
532
- * Restore skipped update slots in the working grid to master state.
533
- * @param {import('./dexbot_class.js').DEXBot} bot
534
- * @param {unknown} workingGrid
535
- * @param {Set<string>} skippedSlotIds
536
- * @param {number} [skippedCount=0]
537
- */
538
- declare function restoreSkippedUpdateSlotsInWorkingGrid(bot: BotLike, workingGrid: InstanceType<typeof WorkingGrid>, skippedSlotIds: Set<string> | null | undefined, skippedCount?: number): void;
539
439
  declare function updateOrdersOnChainBatchCOW(bot: BotLike, cowResult: CowResult, options?: JsonObj): Promise<JsonObj>;
540
440
  declare function adoptPlacedBatchFromChain(bot: BotLike, chainOrders: typeof chainOrdersModule, logPrefix: string, opts?: JsonObj): Promise<boolean>;
541
441
  /**
@@ -648,42 +548,23 @@ declare function processBatchResults(bot: BotLike, result: JsonObj, opContexts:
648
548
  hadRotation: boolean;
649
549
  updateOperationCount: number;
650
550
  }>;
651
- export { isLastFillGuardBlocked, resolveOnGridPivot, checkGridPriceInvariant, deriveRotationPrice, refreshLastFillPivotFromQueue, runFinalPivotGate, buildOutsideInPairGroupsForOrders, buildOutsideInPairGroupsForCreateEntries, markMissingCreateResultsAsStructuralBlocker, formatUnmatchedChainOrderForLog, recordPendingBroadcast, clearPendingBroadcasts, popPushedWorkingGrid, findChainOrderForSlot, reconcileAfterUncertainBroadcast, reconcileAfterUncertainBroadcastImpl, executeWithRetryOnUncertain, executeChunkedWithRetryOnUncertain, formatPartialBroadcastSummary, buildActionsFromPlan, buildCowResultFromPlan, applyRotationTransitionsToWorkingGrid, pollChainForConfirmation, updateOrdersOnChainBatchCOW, processBatchResults, adoptPlacedBatchFromChain, resolveRefillBoundaryHold, toRefillSlotIdSet, trackBoundaryHold };
551
+ export { isSpreadCorrectionBypassAllowed, isLastFillGuardBlocked, resolveOnGridPivot, checkGridPriceInvariant, recordRestampBuyAboveAnchor, collectGapBandPlacementShadowSlots, deriveRotationPrice, refreshLastFillPivotFromQueue, runFinalPivotGate, buildOutsideInPairGroupsForOrders, buildOutsideInPairGroupsForCreateEntries, markMissingCreateResultsAsStructuralBlocker, formatUnmatchedChainOrderForLog, recordPendingBroadcast, clearPendingBroadcasts, popPushedWorkingGrid, findChainOrderForSlot, reconcileAfterUncertainBroadcast, executeWithRetryOnUncertain, executeChunkedWithRetryOnUncertain, formatPartialBroadcastSummary, buildActionsFromPlan, buildCowResultFromPlan, applyRotationTransitionsToWorkingGrid, updateOrdersOnChainBatchCOW, processBatchResults, adoptPlacedBatchFromChain, resolveRefillBoundaryHold, toRefillSlotIdSet, trackBoundaryHold };
652
552
  export { restoreDiscardedCreates };
653
553
  declare const _default: {
654
554
  buildOutsideInPairGroupsForOrders: typeof buildOutsideInPairGroupsForOrders;
655
555
  buildOutsideInPairGroupsForCreateEntries: typeof buildOutsideInPairGroupsForCreateEntries;
656
- extractOperationResults: typeof extractOperationResults;
657
- findMissingCreateResultContexts: typeof findMissingCreateResultContexts;
658
556
  markMissingCreateResultsAsStructuralBlocker: typeof markMissingCreateResultsAsStructuralBlocker;
659
557
  formatUnmatchedChainOrderForLog: typeof formatUnmatchedChainOrderForLog;
660
558
  recordPendingBroadcast: typeof recordPendingBroadcast;
661
559
  clearPendingBroadcasts: typeof clearPendingBroadcasts;
662
- clearPendingBroadcastsForSlots: typeof clearPendingBroadcastsForSlots;
663
- popPushedWorkingGrid: typeof popPushedWorkingGrid;
664
- buildChainOrderFingerprint: typeof buildChainOrderFingerprint;
665
- normalizeChainOrderForPendingMatch: typeof normalizeChainOrderForPendingMatch;
666
560
  findChainOrderForSlot: typeof findChainOrderForSlot;
667
561
  reconcileAfterUncertainBroadcast: typeof reconcileAfterUncertainBroadcast;
668
- reconcileAfterUncertainBroadcastImpl: typeof reconcileAfterUncertainBroadcastImpl;
669
- shouldExecuteCreatePairMode: typeof shouldExecuteCreatePairMode;
670
562
  executeWithRetryOnUncertain: typeof executeWithRetryOnUncertain;
671
563
  executeChunkedWithRetryOnUncertain: typeof executeChunkedWithRetryOnUncertain;
672
- formatPartialBroadcastSummary: typeof formatPartialBroadcastSummary;
673
- validateOperationFunds: typeof validateOperationFunds;
674
- resolveIdealSizeForValidation: typeof resolveIdealSizeForValidation;
675
- validateOrderSizeForExecution: typeof validateOrderSizeForExecution;
676
- buildActionsFromPlan: typeof buildActionsFromPlan;
564
+ popPushedWorkingGrid: typeof popPushedWorkingGrid;
677
565
  buildCowResultFromPlan: typeof buildCowResultFromPlan;
678
- restoreSkippedUpdateSlotsInWorkingGrid: typeof restoreSkippedUpdateSlotsInWorkingGrid;
679
- resolveRefillBoundaryHold: typeof resolveRefillBoundaryHold;
680
- toRefillSlotIdSet: typeof toRefillSlotIdSet;
681
- trackBoundaryHold: typeof trackBoundaryHold;
682
- applyRotationTransitionsToWorkingGrid: typeof applyRotationTransitionsToWorkingGrid;
683
- pollChainForConfirmation: typeof pollChainForConfirmation;
684
566
  updateOrdersOnChainBatchCOW: typeof updateOrdersOnChainBatchCOW;
685
567
  processBatchResults: typeof processBatchResults;
686
- runFinalPivotGate: typeof runFinalPivotGate;
687
568
  };
688
569
  export default _default;
689
570
  //# sourceMappingURL=dexbot_cow_runtime.d.ts.map