dexbot 1.6.18 → 1.7.1

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 (146) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +24 -18
  3. package/analysis/README.md +117 -5
  4. package/claw/package.json +1 -1
  5. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  6. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  7. package/dist/analysis/account_resolver.js +5 -6
  8. package/dist/analysis/analyze_dynamic_weight.js +2 -1
  9. package/dist/analysis/analyze_kalman.js +3 -2
  10. package/dist/analysis/analyze_liquidity.d.ts +17 -0
  11. package/dist/analysis/analyze_liquidity.js +336 -0
  12. package/dist/analysis/analyze_regime.js +3 -2
  13. package/dist/analysis/analyze_regime_windows.js +3 -2
  14. package/dist/analysis/analyze_volatility.js +3 -2
  15. package/dist/analysis/bot_key_utils.d.ts +44 -1
  16. package/dist/analysis/bot_key_utils.js +76 -7
  17. package/dist/analysis/fills_cache.js +2 -1
  18. package/dist/analysis/grid_correction_check.d.ts +1 -19
  19. package/dist/analysis/grid_correction_check.js +12 -30
  20. package/dist/analysis/liquidity/liquidity_chain.d.ts +66 -0
  21. package/dist/analysis/liquidity/liquidity_chain.js +178 -0
  22. package/dist/analysis/liquidity/liquidity_chart_generator.d.ts +19 -0
  23. package/dist/analysis/liquidity/liquidity_chart_generator.js +693 -0
  24. package/dist/analysis/liquidity/liquidity_depth_model.d.ts +166 -0
  25. package/dist/analysis/liquidity/liquidity_depth_model.js +258 -0
  26. package/dist/analysis/liquidity/liquidity_view.d.ts +53 -0
  27. package/dist/analysis/liquidity/liquidity_view.js +66 -0
  28. package/dist/analysis/resolve_bot_accounts.js +7 -6
  29. package/dist/analysis/trade_profitability.js +4 -2
  30. package/dist/analysis/tradingview/analyze_tradingview.js +2 -1
  31. package/dist/credential-daemon.js +13 -2
  32. package/dist/dexbot.js +77 -172
  33. package/dist/modules/account_bots.d.ts +11 -1
  34. package/dist/modules/account_orders.d.ts +12 -0
  35. package/dist/modules/account_orders.js +30 -0
  36. package/dist/modules/asset_lookup.d.ts +25 -0
  37. package/dist/modules/asset_lookup.js +75 -0
  38. package/dist/modules/bitshares-native/transport.js +24 -6
  39. package/dist/modules/bitshares_client.d.ts +24 -6
  40. package/dist/modules/bitshares_client.js +44 -7
  41. package/dist/modules/bot_settings.d.ts +2 -0
  42. package/dist/modules/chain_scan.d.ts +64 -0
  43. package/dist/modules/chain_scan.js +80 -0
  44. package/dist/modules/cli_colors.d.ts +5 -0
  45. package/dist/modules/cli_colors.js +7 -0
  46. package/dist/modules/cli_progress.d.ts +51 -0
  47. package/dist/modules/cli_progress.js +113 -0
  48. package/dist/modules/constants.d.ts +26 -3
  49. package/dist/modules/constants.js +63 -8
  50. package/dist/modules/dexbot_class.d.ts +1 -6
  51. package/dist/modules/dexbot_class.js +14 -0
  52. package/dist/modules/dexbot_cow_runtime.d.ts +97 -7
  53. package/dist/modules/dexbot_cow_runtime.js +634 -136
  54. package/dist/modules/dexbot_fill_runtime.js +132 -23
  55. package/dist/modules/dexbot_maintenance_runtime.js +242 -74
  56. package/dist/modules/dexbot_startup_runtime.js +32 -20
  57. package/dist/modules/dexbot_state_recovery.d.ts +33 -1
  58. package/dist/modules/dexbot_state_recovery.js +167 -5
  59. package/dist/modules/launcher/runtime_entry.d.ts +21 -1
  60. package/dist/modules/launcher/runtime_entry.js +36 -1
  61. package/dist/modules/liquidity_pool_ref.d.ts +32 -0
  62. package/dist/modules/liquidity_pool_ref.js +116 -0
  63. package/dist/modules/node_connect_policy.d.ts +8 -1
  64. package/dist/modules/node_connect_policy.js +18 -2
  65. package/dist/modules/node_flap_score.d.ts +87 -0
  66. package/dist/modules/node_flap_score.js +124 -0
  67. package/dist/modules/node_health_cache.d.ts +40 -3
  68. package/dist/modules/node_health_cache.js +66 -20
  69. package/dist/modules/node_manager.d.ts +101 -19
  70. package/dist/modules/node_manager.js +255 -65
  71. package/dist/modules/order/accounting.js +56 -7
  72. package/dist/modules/order/format.d.ts +24 -10
  73. package/dist/modules/order/format.js +30 -10
  74. package/dist/modules/order/grid.js +91 -13
  75. package/dist/modules/order/grid_reconcile.d.ts +5 -1
  76. package/dist/modules/order/grid_reconcile.js +333 -189
  77. package/dist/modules/order/grid_reconcile_internal.d.ts +38 -2
  78. package/dist/modules/order/grid_reconcile_internal.js +298 -100
  79. package/dist/modules/order/index.d.ts +19 -1
  80. package/dist/modules/order/lifecycle.d.ts +353 -0
  81. package/dist/modules/order/lifecycle.js +1109 -0
  82. package/dist/modules/order/manager.d.ts +273 -5
  83. package/dist/modules/order/manager.js +654 -48
  84. package/dist/modules/order/placement_lock.d.ts +102 -0
  85. package/dist/modules/order/placement_lock.js +222 -0
  86. package/dist/modules/order/strategy.js +13 -1
  87. package/dist/modules/order/sync_engine.d.ts +33 -1
  88. package/dist/modules/order/sync_engine.js +241 -73
  89. package/dist/modules/order/utils/math.d.ts +39 -1
  90. package/dist/modules/order/utils/math.js +83 -1
  91. package/dist/modules/order/utils/order.d.ts +181 -5
  92. package/dist/modules/order/utils/order.js +455 -9
  93. package/dist/modules/order/utils/system.d.ts +81 -1
  94. package/dist/modules/order/utils/system.js +331 -44
  95. package/dist/modules/order/utils/validate.d.ts +7 -1
  96. package/dist/modules/order/utils/validate.js +80 -3
  97. package/dist/modules/outcome.d.ts +54 -0
  98. package/dist/modules/outcome.js +51 -0
  99. package/dist/modules/settings_merge.d.ts +4 -0
  100. package/dist/modules/settings_merge.js +9 -0
  101. package/dist/modules/timing_policy.d.ts +82 -0
  102. package/dist/modules/timing_policy.js +244 -0
  103. package/dist/modules/types.d.ts +137 -0
  104. package/dist/modules/utils/asset_symbols.d.ts +13 -2
  105. package/dist/modules/utils/asset_symbols.js +21 -2
  106. package/dist/scripts/analysis_runner.d.ts +10 -0
  107. package/dist/scripts/analysis_runner.js +33 -0
  108. package/dist/scripts/analyze-credit.js +54 -17
  109. package/dist/scripts/analyze-orders.d.ts +4 -2
  110. package/dist/scripts/analyze-orders.js +115 -35
  111. package/dist/scripts/asset.d.ts +26 -0
  112. package/dist/scripts/asset.js +165 -0
  113. package/dist/scripts/bts_distribution.d.ts +1 -0
  114. package/dist/scripts/bts_distribution.js +194 -142
  115. package/dist/scripts/chart_command.d.ts +1 -1
  116. package/dist/scripts/chart_command.js +60 -86
  117. package/dist/scripts/chart_targets.d.ts +18 -0
  118. package/dist/scripts/chart_targets.js +48 -0
  119. package/dist/scripts/dw.js +1 -1
  120. package/dist/scripts/liquid.d.ts +24 -0
  121. package/dist/scripts/liquid.js +134 -0
  122. package/dist/scripts/rich_list.js +12 -16
  123. package/dist/scripts/test-credit-renewal.js +12 -5
  124. package/dist/scripts/token_distribution.d.ts +2 -0
  125. package/dist/scripts/token_distribution.js +132 -108
  126. package/dist/scripts/tv.js +1 -1
  127. package/dist/scripts/verify-browser-bundle.js +18 -0
  128. package/docs/COW_INVARIANTS.md +69 -10
  129. package/docs/DEXBOT_COMPARISON.md +6 -6
  130. package/docs/EVOLUTION.md +10 -8
  131. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  132. package/docs/GRID_PRICE_INVARIANT.md +5 -2
  133. package/docs/GRID_RECONCILE.md +36 -11
  134. package/docs/LOGGING.md +50 -4
  135. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +177 -27
  136. package/docs/README.md +23 -2
  137. package/docs/WORKFLOW.md +12 -4
  138. package/docs/architecture.md +42 -5
  139. package/docs/developer_guide.md +25 -8
  140. package/modules/README.md +8 -1
  141. package/package.json +3 -1
  142. package/scripts/README.md +39 -7
  143. package/scripts/pdev.sh +14 -1
  144. package/scripts/pmain.sh +23 -8
  145. package/scripts/ptest.sh +7 -0
  146. package/tests/README.md +30 -1
@@ -728,12 +728,7 @@ declare class DEXBot implements BotLike {
728
728
  * @param {Array<Object>} opContexts - Original opContexts from the failed batch
729
729
  * @returns {Promise<Object>} Result object compatible with batch return shape
730
730
  */
731
- _reconcileAfterUncertainBroadcast(err: unknown, opContexts: OpPhase[], options?: UnknownRecord): Promise<UnknownRecord | {
732
- executed: boolean;
733
- hadRotation: boolean;
734
- uncertain: boolean;
735
- ambiguousRead: boolean;
736
- }>;
731
+ _reconcileAfterUncertainBroadcast(err: unknown, opContexts: OpPhase[], options?: UnknownRecord): Promise<UnknownRecord>;
737
732
  /**
738
733
  * Execute operations with retry on BroadcastUncertainError.
739
734
  * The daemon already retries internally against a 25s deadline. If it
@@ -1115,6 +1115,14 @@ class DEXBot {
1115
1115
  if (typeof this.manager?.pauseFundRecalc === 'function') {
1116
1116
  this.manager.pauseFundRecalc();
1117
1117
  }
1118
+ // One absolute boundary re-anchor per drained fill batch: each fill
1119
+ // event re-anchoring + a fresh COW plan amplified churn (6 re-anchors
1120
+ // in ~1 min). The crawl still runs per chunk; the absolute anchor is
1121
+ // the expensive geometry jump. A BUDGET (not a boolean) is nest-safe:
1122
+ // a nested/overlapping fill cycle restores the outer budget instead of
1123
+ // silently re-enabling multiple anchors.
1124
+ const prevReanchorBudget = this.manager._boundaryReanchorBudget;
1125
+ this.manager._boundaryReanchorBudget = 1;
1118
1126
  let anyDeferred = false;
1119
1127
  try {
1120
1128
  const activeSell = this.manager?.config?.coreOrders?.sell ?? 1;
@@ -1183,6 +1191,12 @@ class DEXBot {
1183
1191
  if (this.manager) {
1184
1192
  delete this.manager._boundaryShiftBudget;
1185
1193
  delete this.manager._boundaryShiftBudgetBase;
1194
+ if (prevReanchorBudget === undefined) {
1195
+ delete this.manager._boundaryReanchorBudget;
1196
+ }
1197
+ else {
1198
+ this.manager._boundaryReanchorBudget = prevReanchorBudget;
1199
+ }
1186
1200
  }
1187
1201
  if (typeof this.manager?.resumeFundRecalc === 'function') {
1188
1202
  await this.manager.resumeFundRecalc();
@@ -20,6 +20,97 @@ import { isLastFillGuardBlocked } from './order/utils/system.js';
20
20
  * keeps the plan-build authority (fail-open to the stamp, never to the guard).
21
21
  */
22
22
  export declare function isEvacuationStampStillValid(liveBoundary: unknown, liveGapSlots: unknown, sourceId: unknown, destId: unknown, orderType: unknown): boolean;
23
+ /**
24
+ * Detect a live-rail conflict: the resting BUY/SELL rails cannot coexist with
25
+ * a `gapSlots`-wide spread band, i.e. no boundary value satisfies
26
+ * `maxBuy <= boundary` and `minSell >= boundary + gapSlots + 1` at once.
27
+ *
28
+ * Why this matters for gap evacuation: the stale-stamp check below refuses an
29
+ * evacuation whose source is no longer in-band under the LIVE (pre-commit)
30
+ * boundary. That is correct when the live geometry is itself consistent (the
31
+ * 2026-10-30 incident: plan boundary 124 wanted buys 125-128 evacuated, live
32
+ * 128 kept them on the rail, the bid edge survived). It is WRONG when the live
33
+ * rails already overlap: then the batch's boundary retreat is FORCED — some
34
+ * order has to move — and refusing the evacuation leaves the stranded order
35
+ * inside the band permanently (observed class: a buy fill inside the band
36
+ * crawls the boundary down, the retreat strands the two buys above it, the
37
+ * guard skips their rotation as stale, the rail clamp cannot move the boundary
38
+ * back because the sell rail caps it, and the 4-slot spread band keeps two
39
+ * live buys forever → real spread 1.2% against a 2.0% target).
40
+ *
41
+ * The test is boundary-independent (a crossing is a crossing at any boundary),
42
+ * so it cannot be satisfied by simply moving the boundary: only an evacuation
43
+ * resolves it. Ladder positions use the same live-price resolution as
44
+ * deriveRailBoundary, so a stale slot id cannot fake a rail member.
45
+ *
46
+ * @param manager - Manager exposing orders/assets/_genesis
47
+ * @param gapSlots - Gap-band width (slots)
48
+ * @returns `{ crossed, maxBuyIdx, minSellIdx, upper }`; `crossed` is false when
49
+ * either rail is empty (one-sided book proves nothing) or geometry is
50
+ * unknown (fail closed: keep the stale-stamp refusal).
51
+ */
52
+ export declare function liveRailsConflictWithGap(manager: unknown, gapSlots: unknown): {
53
+ crossed: boolean;
54
+ maxBuyIdx: number | null;
55
+ minSellIdx: number | null;
56
+ upper: number | null;
57
+ };
58
+ /**
59
+ * Decide whether a stale-stamp refusal of a gap-evacuation rotation must yield
60
+ * to the forced-retreat allowance. Single authority for the three call sites
61
+ * (stamped build branch, unstamped build branch, final pivot gate) so the
62
+ * conditions can never drift apart.
63
+ *
64
+ * Two conditions, both required:
65
+ * 1. The stamp could actually be EVALUATED: an unparseable source/dest id is
66
+ * not a geometry disagreement — `isEvacuationStampStillValid` refuses those
67
+ * too, and overriding that would ship a rotation whose geometry nobody
68
+ * proved. Never override an unprovable stamp.
69
+ * 2. The live rails already conflict (see liveRailsConflictWithGap): some
70
+ * order must move at ANY boundary, so the plan's retreat is the only
71
+ * consistent geometry and the pre-commit "still on the rail" reading is not
72
+ * authoritative.
73
+ *
74
+ * @param manager - Manager exposing orders/assets/_genesis
75
+ * @param gapSlots - LIVE gap-band width (slots)
76
+ * @param sourceId - Evacuation source slot id
77
+ * @param destId - Evacuation destination slot id
78
+ * @returns The conflict record when the allowance applies, otherwise null.
79
+ */
80
+ export declare function forcedRetreatJustifiesEvacuation(manager: unknown, gapSlots: unknown, sourceId: unknown, destId: unknown): {
81
+ crossed: boolean;
82
+ maxBuyIdx: number | null;
83
+ minSellIdx: number | null;
84
+ upper: number | null;
85
+ } | null;
86
+ /**
87
+ * Split pending price corrections into "drain now" and "held back because this
88
+ * batch supersedes them".
89
+ *
90
+ * A cancel-only gap-evacuation whose chain order the batch ROTATES is
91
+ * superseded by the plan: the rotation moves that order onto its rail in place,
92
+ * and cancelling it first destroys the batch's own source. Observed live on a
93
+ * stranded 4-slot band: the teeth queued cancels for the two rotation sources,
94
+ * the pre-batch drain executed them, and the UPDATE batch was rejected
95
+ * pre-broadcast ("2 target(s) missing on chain") → structural resync + full grid
96
+ * reload + two CREATEs, instead of two in-place price updates.
97
+ *
98
+ * Held entries are put back after the drain: if the rotation is dropped or the
99
+ * batch aborts they stay queued (their own staleness check drops them once the
100
+ * slot no longer owns the order).
101
+ *
102
+ * @param entries - `manager.ordersNeedingPriceCorrection`
103
+ * @param actions - The batch's planned actions
104
+ * @returns `{ kept, held }` (both empty-safe)
105
+ */
106
+ export declare function splitEvacuationCancelsSupersededByRotations(entries: unknown, actions: unknown): {
107
+ kept: Array<{
108
+ [key: string]: unknown;
109
+ }>;
110
+ held: Array<{
111
+ [key: string]: unknown;
112
+ }>;
113
+ };
23
114
  import * as workingGridModule from './order/working_grid.js';
24
115
  declare const WorkingGrid: typeof workingGridModule.WorkingGrid;
25
116
  import type { BotLike, OrderManagerLike, ManagedOrder, ChainOrder, UnknownRecord, CowAction } from './types.js';
@@ -176,12 +267,7 @@ declare function findChainOrderForSlot(bot: BotLike, chainOrders: ChainOrderLike
176
267
  * @param {Object} [options]
177
268
  * @returns {Promise<Object>}
178
269
  */
179
- declare function reconcileAfterUncertainBroadcast(bot: BotLike, err: unknown, opContexts: OpPhase[], options?: JsonObj): Promise<UnknownRecord | {
180
- executed: boolean;
181
- hadRotation: boolean;
182
- uncertain: boolean;
183
- ambiguousRead: boolean;
184
- }>;
270
+ declare function reconcileAfterUncertainBroadcast(bot: BotLike, err: unknown, opContexts: OpPhase[], options?: JsonObj): Promise<UnknownRecord>;
185
271
  /**
186
272
  * Restore discarded CREATE slots to creation-uncertain state and clear
187
273
  * their pending entries; residual pending entries that survive the
@@ -398,8 +484,12 @@ declare function toRefillSlotIdSet(refillSlotIds: unknown): Set<string>;
398
484
  * Unrelated vetoes (skip ids outside the refill set) never pin geometry.
399
485
  * The grid still commits; only the boundary value is held (same discipline
400
486
  * as the overrun-hold in validateBoundaryCommit).
487
+ *
488
+ * `refillSide` (BUY/SELL) scopes the hold to the boundary's PROMOTION
489
+ * direction; a fill-driven retreat, or a wire whose side cannot be resolved
490
+ * (null), keeps the legacy hold.
401
491
  */
402
- declare function resolveRefillBoundaryHold(workingBoundary: unknown, committedBoundary: unknown, skippedUpdateSlotIds: Iterable<string> | null | undefined, clampedUpdateSlotIds: Iterable<string> | null | undefined, refillSlotIds: unknown, skippedCreateSlotIds?: Iterable<string> | null | undefined): {
492
+ declare function resolveRefillBoundaryHold(workingBoundary: unknown, committedBoundary: unknown, skippedUpdateSlotIds: Iterable<string> | null | undefined, clampedUpdateSlotIds: Iterable<string> | null | undefined, refillSlotIds: unknown, skippedCreateSlotIds?: Iterable<string> | null | undefined, refillSide?: unknown): {
403
493
  effectiveBoundary: unknown;
404
494
  heldRefillSlotIds: string[];
405
495
  };