dexbot 1.4.20 → 1.4.22

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 (674) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +23 -13
  3. package/analysis/ama_fitting/analyze_ama_price_changes.ts +7 -3
  4. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +3 -3
  5. package/analysis/ama_fitting/calibrate_convergence_er.ts +8 -6
  6. package/analysis/ama_fitting/fetch_lp_candles.ts +8 -3
  7. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +30 -67
  8. package/analysis/ama_fitting/optimizer_high_resolution.ts +22 -13
  9. package/analysis/ama_fitting/package.json +1 -1
  10. package/analysis/analyze_derivatives.ts +4 -4
  11. package/analysis/analyze_dynamic_weight.ts +21 -5
  12. package/analysis/analyze_kalman.ts +54 -25
  13. package/analysis/analyze_regime.ts +2 -2
  14. package/analysis/analyze_regime_windows.ts +27 -19
  15. package/analysis/analyze_risk_profile.ts +3 -3
  16. package/analysis/analyze_trade_heatmap.ts +3 -3
  17. package/analysis/analyze_volatility.ts +2 -2
  18. package/analysis/bot_fitting/README.md +93 -19
  19. package/analysis/bot_fitting/backtest_ama_sweep.ts +316 -199
  20. package/analysis/bot_fitting/backtest_bot_fitting.ts +520 -85
  21. package/analysis/bot_fitting/shared_utils.ts +16 -10
  22. package/analysis/bot_key_utils.ts +14 -11
  23. package/analysis/bot_usage/discover_bot_accounts.ts +5 -3
  24. package/analysis/bot_usage/kibana_bot_queries.ts +2 -257
  25. package/analysis/chart_css.ts +6 -4
  26. package/analysis/chart_ui.ts +0 -1
  27. package/analysis/chart_utils.ts +11 -2
  28. package/analysis/derivative_chart_generator.ts +2 -2
  29. package/analysis/math_utils.ts +1 -8
  30. package/analysis/price_sources.ts +8 -2
  31. package/analysis/resolve_source.ts +1 -1
  32. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +2455 -0
  33. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +218 -0
  34. package/analysis/trade_profitability.ts +61 -28
  35. package/analysis/tradingview/analyze_tradingview.ts +1 -1
  36. package/analysis/tradingview/h-bts_tradingview.html +1570 -0
  37. package/analysis/tradingview/t-bts_tradingview.html +1570 -0
  38. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +302 -74
  39. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  40. package/analysis/trend_detection/derivative_analyzer.ts +12 -3
  41. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +25 -27
  42. package/analysis/trend_detection/hurst_analyzer.ts +1 -1
  43. package/analysis/trend_detection/kalman_chart_generator.ts +42 -14
  44. package/analysis/trend_detection/package.json +1 -1
  45. package/analysis/trend_detection/regime_chart_generator.ts +39 -19
  46. package/analysis/trend_detection/tests/test_kalman_trend.ts +1 -1
  47. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +1 -1
  48. package/analysis/trend_detection/volatility_chart_generator.ts +1 -1
  49. package/claw/ecosystem.config.cjs +2 -3
  50. package/claw/examples/memu_integration_example.ts +17 -17
  51. package/claw/index.ts +1 -1
  52. package/claw/modules/chain_actions.ts +51 -54
  53. package/claw/modules/chain_broadcast.ts +66 -104
  54. package/claw/modules/claw_bridge.ts +63 -83
  55. package/claw/modules/claw_catalog.ts +48 -17
  56. package/claw/modules/claw_infra.ts +1 -5
  57. package/claw/modules/claw_launcher.ts +48 -50
  58. package/claw/modules/claw_skill_md.ts +15 -21
  59. package/claw/modules/credit_runtime_adapter.ts +3 -19
  60. package/claw/modules/decision_loop.ts +9 -9
  61. package/claw/modules/dexbot_bridge.ts +8 -8
  62. package/claw/modules/dexbot_profiles.ts +5 -21
  63. package/claw/modules/feed_price_source.ts +1 -1
  64. package/claw/modules/honest_ecosystem.ts +24 -8
  65. package/claw/modules/kibana_price_source.ts +1 -1
  66. package/claw/modules/launcher_mode_detector.ts +1 -1
  67. package/claw/modules/launcher_paths.ts +1 -1
  68. package/claw/modules/liquidity_pools.ts +10 -3
  69. package/claw/modules/mcp_utils.ts +109 -0
  70. package/claw/modules/memu_bridge.ts +76 -54
  71. package/claw/modules/mpa_utils.ts +26 -3
  72. package/claw/modules/position_discovery.ts +17 -28
  73. package/claw/modules/position_health.ts +1 -1
  74. package/claw/modules/position_manager.ts +32 -41
  75. package/claw/modules/position_manager_watch.ts +3 -2
  76. package/claw/modules/short_mpa_strategy.ts +1 -9
  77. package/claw/modules/skill_utils.ts +5 -3
  78. package/claw/modules/utils.ts +9 -1
  79. package/claw/package.json +3 -3
  80. package/claw/runtimes/openclaw-plugin/index.ts +27 -10
  81. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  82. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  83. package/claw/scripts/claw_bridge.ts +1 -1
  84. package/claw/scripts/claw_mcp_server.ts +19 -78
  85. package/claw/scripts/honest_assets_report.ts +19 -84
  86. package/claw/scripts/memu_mcp_server.ts +57 -155
  87. package/claw/skills/launcher-ops/references/launcher-workflow.md +2 -2
  88. package/claw/tests/package.json +1 -1
  89. package/claw/tests/test_claw_bridge.ts +47 -19
  90. package/claw/tests/test_claw_catalog_and_credentials.ts +8 -4
  91. package/claw/tests/test_claw_chain_layer.ts +39 -19
  92. package/claw/tests/test_claw_data_flow.ts +28 -20
  93. package/claw/tests/test_claw_domain_logic.ts +25 -19
  94. package/claw/tests/test_claw_manifest_and_matrix.ts +23 -3
  95. package/claw/tests/test_claw_mcp_transport.ts +13 -8
  96. package/claw/tests/test_claw_regressions.ts +254 -128
  97. package/claw/tests/test_claw_skill_generation.ts +1 -1
  98. package/claw/tests/test_nullclaw_tmp_integration.ts +2 -3
  99. package/claw/tests/test_position_health.ts +1 -77
  100. package/claw/tests/test_position_manager.ts +20 -18
  101. package/claw/tests/test_position_manager_watch_health.ts +39 -43
  102. package/claw/tests/test_short_mpa_strategy.ts +20 -17
  103. package/claw/tsconfig.json +4 -3
  104. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +7 -3
  105. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -1
  106. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +3 -3
  107. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
  108. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +8 -6
  109. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -1
  110. package/dist/analysis/ama_fitting/fetch_lp_candles.js +8 -3
  111. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -1
  112. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +2 -2
  113. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -1
  114. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +31 -75
  115. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -1
  116. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -1
  117. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +21 -13
  118. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -1
  119. package/dist/analysis/analyze_derivatives.d.ts +0 -18
  120. package/dist/analysis/analyze_derivatives.d.ts.map +1 -1
  121. package/dist/analysis/analyze_derivatives.js +4 -4
  122. package/dist/analysis/analyze_derivatives.js.map +1 -1
  123. package/dist/analysis/analyze_dynamic_weight.d.ts +0 -11
  124. package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -1
  125. package/dist/analysis/analyze_dynamic_weight.js +19 -5
  126. package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
  127. package/dist/analysis/analyze_kalman.d.ts +0 -10
  128. package/dist/analysis/analyze_kalman.d.ts.map +1 -1
  129. package/dist/analysis/analyze_kalman.js +51 -26
  130. package/dist/analysis/analyze_kalman.js.map +1 -1
  131. package/dist/analysis/analyze_regime.d.ts +0 -17
  132. package/dist/analysis/analyze_regime.d.ts.map +1 -1
  133. package/dist/analysis/analyze_regime.js +2 -2
  134. package/dist/analysis/analyze_regime.js.map +1 -1
  135. package/dist/analysis/analyze_regime_windows.d.ts +0 -16
  136. package/dist/analysis/analyze_regime_windows.d.ts.map +1 -1
  137. package/dist/analysis/analyze_regime_windows.js +28 -21
  138. package/dist/analysis/analyze_regime_windows.js.map +1 -1
  139. package/dist/analysis/analyze_risk_profile.js +3 -3
  140. package/dist/analysis/analyze_risk_profile.js.map +1 -1
  141. package/dist/analysis/analyze_trade_heatmap.js +3 -3
  142. package/dist/analysis/analyze_trade_heatmap.js.map +1 -1
  143. package/dist/analysis/analyze_volatility.d.ts +0 -19
  144. package/dist/analysis/analyze_volatility.d.ts.map +1 -1
  145. package/dist/analysis/analyze_volatility.js +2 -2
  146. package/dist/analysis/analyze_volatility.js.map +1 -1
  147. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +30 -14
  148. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -1
  149. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +330 -193
  150. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -1
  151. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +136 -1
  152. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -1
  153. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +527 -83
  154. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -1
  155. package/dist/analysis/bot_fitting/shared_utils.d.ts +2 -13
  156. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -1
  157. package/dist/analysis/bot_fitting/shared_utils.js +15 -9
  158. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -1
  159. package/dist/analysis/bot_key_utils.d.ts +1 -1
  160. package/dist/analysis/bot_key_utils.d.ts.map +1 -1
  161. package/dist/analysis/bot_key_utils.js +14 -11
  162. package/dist/analysis/bot_key_utils.js.map +1 -1
  163. package/dist/analysis/bot_usage/discover_bot_accounts.js +5 -3
  164. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -1
  165. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -337
  166. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
  167. package/dist/analysis/bot_usage/kibana_bot_queries.js +2 -242
  168. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
  169. package/dist/analysis/chart_css.d.ts +2 -14
  170. package/dist/analysis/chart_css.d.ts.map +1 -1
  171. package/dist/analysis/chart_css.js +6 -3
  172. package/dist/analysis/chart_css.js.map +1 -1
  173. package/dist/analysis/chart_ui.d.ts.map +1 -1
  174. package/dist/analysis/chart_ui.js.map +1 -1
  175. package/dist/analysis/chart_utils.d.ts.map +1 -1
  176. package/dist/analysis/chart_utils.js +15 -2
  177. package/dist/analysis/chart_utils.js.map +1 -1
  178. package/dist/analysis/derivative_chart_generator.js +2 -2
  179. package/dist/analysis/derivative_chart_generator.js.map +1 -1
  180. package/dist/analysis/math_utils.d.ts +3 -5
  181. package/dist/analysis/math_utils.d.ts.map +1 -1
  182. package/dist/analysis/math_utils.js +3 -5
  183. package/dist/analysis/math_utils.js.map +1 -1
  184. package/dist/analysis/price_sources.d.ts +1 -0
  185. package/dist/analysis/price_sources.d.ts.map +1 -1
  186. package/dist/analysis/price_sources.js +8 -2
  187. package/dist/analysis/price_sources.js.map +1 -1
  188. package/dist/analysis/resolve_source.d.ts.map +1 -1
  189. package/dist/analysis/resolve_source.js +1 -1
  190. package/dist/analysis/resolve_source.js.map +1 -1
  191. package/dist/analysis/trade_profitability.d.ts.map +1 -1
  192. package/dist/analysis/trade_profitability.js +58 -29
  193. package/dist/analysis/trade_profitability.js.map +1 -1
  194. package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
  195. package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
  196. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  197. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +302 -74
  198. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  199. package/dist/analysis/trend_detection/derivative_analyzer.d.ts +1 -0
  200. package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -1
  201. package/dist/analysis/trend_detection/derivative_analyzer.js +12 -3
  202. package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -1
  203. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
  204. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +26 -27
  205. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
  206. package/dist/analysis/trend_detection/hurst_analyzer.d.ts +1 -1
  207. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -1
  208. package/dist/analysis/trend_detection/hurst_analyzer.js +1 -1
  209. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
  210. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -1
  211. package/dist/analysis/trend_detection/kalman_chart_generator.js +41 -13
  212. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -1
  213. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -1
  214. package/dist/analysis/trend_detection/regime_chart_generator.js +38 -19
  215. package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -1
  216. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +1 -1
  217. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -1
  218. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +1 -1
  219. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -1
  220. package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -1
  221. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -1
  222. package/dist/bot.js +3 -3
  223. package/dist/bot.js.map +1 -1
  224. package/dist/credential-daemon.d.ts +1 -1
  225. package/dist/credential-daemon.js +2 -2
  226. package/dist/credential-daemon.js.map +1 -1
  227. package/dist/dexbot.d.ts.map +1 -1
  228. package/dist/dexbot.js +25 -22
  229. package/dist/dexbot.js.map +1 -1
  230. package/dist/market_adapter/ama_signal_runner.js +6 -4
  231. package/dist/market_adapter/ama_signal_runner.js.map +1 -1
  232. package/dist/market_adapter/candle_utils.d.ts +1 -3
  233. package/dist/market_adapter/candle_utils.d.ts.map +1 -1
  234. package/dist/market_adapter/candle_utils.js +1 -11
  235. package/dist/market_adapter/candle_utils.js.map +1 -1
  236. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
  237. package/dist/market_adapter/core/asymmetric_bounds.js +33 -30
  238. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
  239. package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -1
  240. package/dist/market_adapter/core/config_normalizers.js +10 -1
  241. package/dist/market_adapter/core/config_normalizers.js.map +1 -1
  242. package/dist/market_adapter/core/kibana_candles.d.ts +18 -42
  243. package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
  244. package/dist/market_adapter/core/kibana_candles.js +101 -7
  245. package/dist/market_adapter/core/kibana_candles.js.map +1 -1
  246. package/dist/market_adapter/core/kibana_client.d.ts +1 -17
  247. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
  248. package/dist/market_adapter/core/kibana_client.js +40 -7
  249. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  250. package/dist/market_adapter/core/kibana_market_candles.d.ts +0 -27
  251. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
  252. package/dist/market_adapter/core/kibana_market_candles.js +1 -1
  253. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
  254. package/dist/market_adapter/core/market_adapter_service.d.ts +22 -13
  255. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  256. package/dist/market_adapter/core/market_adapter_service.js +96 -38
  257. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  258. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
  259. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +1 -1
  260. package/dist/market_adapter/core/signals/hurst_analyzer.js +28 -17
  261. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +1 -1
  262. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts +5 -0
  263. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +1 -1
  264. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js +24 -24
  265. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +1 -1
  266. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +1 -1
  267. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js +5 -1
  268. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +1 -1
  269. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +1 -1
  270. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +20 -3
  271. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +1 -1
  272. package/dist/market_adapter/core/strategies/ama.js +1 -1
  273. package/dist/market_adapter/core/strategies/ama.js.map +1 -1
  274. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +2 -2
  275. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
  276. package/dist/market_adapter/core/strategies/ama_slope_model.js +16 -4
  277. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
  278. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +4 -3
  279. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
  280. package/dist/market_adapter/core/strategies/atr/calculator.js +16 -8
  281. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
  282. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -1
  283. package/dist/market_adapter/core/strategies/collateral_manager.js +8 -3
  284. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
  285. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +40 -1
  286. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +1 -1
  287. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +116 -2
  288. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +1 -1
  289. package/dist/market_adapter/core/strategies/regime_gate.d.ts +1 -2
  290. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  291. package/dist/market_adapter/core/strategies/regime_gate.js +27 -21
  292. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  293. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +1 -1
  294. package/dist/market_adapter/core/strategies/volatility_shift.js +3 -0
  295. package/dist/market_adapter/core/strategies/volatility_shift.js.map +1 -1
  296. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +71 -57
  297. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  298. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +0 -26
  299. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  300. package/dist/market_adapter/inputs/fetch_lp_data.js +72 -19
  301. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  302. package/dist/market_adapter/inputs/kibana_source.d.ts +5 -30
  303. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
  304. package/dist/market_adapter/inputs/kibana_source.js +6 -3
  305. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  306. package/dist/market_adapter/lp_chart_core.js +1 -1
  307. package/dist/market_adapter/lp_chart_core.js.map +1 -1
  308. package/dist/market_adapter/lp_chart_runner.d.ts +10 -1
  309. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
  310. package/dist/market_adapter/lp_chart_runner.js +2 -2
  311. package/dist/market_adapter/lp_chart_runner.js.map +1 -1
  312. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +1 -2
  313. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
  314. package/dist/market_adapter/lp_chart_strategy_loader.js +5 -5
  315. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  316. package/dist/market_adapter/market_adapter.d.ts +1 -2
  317. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  318. package/dist/market_adapter/market_adapter.js +5 -7
  319. package/dist/market_adapter/market_adapter.js.map +1 -1
  320. package/dist/market_adapter/test_helpers.d.ts +3 -3
  321. package/dist/market_adapter/test_helpers.d.ts.map +1 -1
  322. package/dist/market_adapter/test_helpers.js +3 -3
  323. package/dist/market_adapter/test_helpers.js.map +1 -1
  324. package/dist/market_adapter/utils/adapter_client.js +1 -1
  325. package/dist/market_adapter/utils/adapter_client.js.map +1 -1
  326. package/dist/market_adapter/utils/atomic_write.js +1 -1
  327. package/dist/market_adapter/utils/atomic_write.js.map +1 -1
  328. package/dist/market_adapter/utils/chain.d.ts +0 -2
  329. package/dist/market_adapter/utils/chain.d.ts.map +1 -1
  330. package/dist/market_adapter/utils/chain.js +2 -3
  331. package/dist/market_adapter/utils/chain.js.map +1 -1
  332. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
  333. package/dist/market_adapter/utils/data_discovery.js +24 -8
  334. package/dist/market_adapter/utils/data_discovery.js.map +1 -1
  335. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
  336. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +2 -5
  337. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
  338. package/dist/market_adapter/utils/file_lock.d.ts +4 -1
  339. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
  340. package/dist/market_adapter/utils/file_lock.js +89 -25
  341. package/dist/market_adapter/utils/file_lock.js.map +1 -1
  342. package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
  343. package/dist/market_adapter/utils/native_history.js +5 -1
  344. package/dist/market_adapter/utils/native_history.js.map +1 -1
  345. package/dist/modules/account_bots.d.ts +3 -0
  346. package/dist/modules/account_bots.d.ts.map +1 -1
  347. package/dist/modules/account_bots.js +157 -47
  348. package/dist/modules/account_bots.js.map +1 -1
  349. package/dist/modules/account_orders.d.ts +1 -7
  350. package/dist/modules/account_orders.d.ts.map +1 -1
  351. package/dist/modules/account_orders.js +9 -17
  352. package/dist/modules/account_orders.js.map +1 -1
  353. package/dist/modules/authority_resolver.js +1 -1
  354. package/dist/modules/authority_resolver.js.map +1 -1
  355. package/dist/modules/bitshares-native/chain_client.js +1 -1
  356. package/dist/modules/bitshares-native/chain_client.js.map +1 -1
  357. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +0 -12
  358. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
  359. package/dist/modules/bitshares-native/crypto/ecc.browser.js +1 -1
  360. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
  361. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -1
  362. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
  363. package/dist/modules/bitshares-native/index.d.ts.map +1 -1
  364. package/dist/modules/bitshares-native/index.js +1 -1
  365. package/dist/modules/bitshares-native/index.js.map +1 -1
  366. package/dist/modules/bitshares-native/lru_cache.js +1 -1
  367. package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
  368. package/dist/modules/bitshares-native/resolvers.d.ts +0 -2
  369. package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -1
  370. package/dist/modules/bitshares-native/resolvers.js +18 -4
  371. package/dist/modules/bitshares-native/resolvers.js.map +1 -1
  372. package/dist/modules/bitshares-native/serial/chain_constants.js +1 -1
  373. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
  374. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
  375. package/dist/modules/bitshares-native/serial/index.js +1 -1
  376. package/dist/modules/bitshares-native/serial/index.js.map +1 -1
  377. package/dist/modules/bitshares-native/serial/operations.js +1 -1
  378. package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
  379. package/dist/modules/bitshares-native/serial/serializer.js +1 -1
  380. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
  381. package/dist/modules/bitshares-native/serial/types.js +1 -1
  382. package/dist/modules/bitshares-native/serial/types.js.map +1 -1
  383. package/dist/modules/bitshares-native/signing_client.js +2 -2
  384. package/dist/modules/bitshares-native/signing_client.js.map +1 -1
  385. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
  386. package/dist/modules/bitshares-native/subscriptions.js +5 -14
  387. package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
  388. package/dist/modules/bitshares-native/transport.js +1 -1
  389. package/dist/modules/bitshares-native/transport.js.map +1 -1
  390. package/dist/modules/bitshares-native/tx/builder.js +1 -1
  391. package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
  392. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +3 -2
  393. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +1 -1
  394. package/dist/modules/bitshares-native/tx/tx_cache.js +7 -4
  395. package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
  396. package/dist/modules/bitshares_client.d.ts +2 -14
  397. package/dist/modules/bitshares_client.d.ts.map +1 -1
  398. package/dist/modules/bitshares_client.js +32 -41
  399. package/dist/modules/bitshares_client.js.map +1 -1
  400. package/dist/modules/bot_settings.d.ts.map +1 -1
  401. package/dist/modules/bot_settings.js +12 -19
  402. package/dist/modules/bot_settings.js.map +1 -1
  403. package/dist/modules/bots_file_lock.d.ts +1 -1
  404. package/dist/modules/bots_file_lock.js +1 -1
  405. package/dist/modules/broadcast_failure.d.ts +13 -0
  406. package/dist/modules/broadcast_failure.d.ts.map +1 -1
  407. package/dist/modules/broadcast_failure.js +0 -13
  408. package/dist/modules/broadcast_failure.js.map +1 -1
  409. package/dist/modules/chain_keys.js +2 -2
  410. package/dist/modules/chain_keys.js.map +1 -1
  411. package/dist/modules/chain_orders.d.ts +2 -3
  412. package/dist/modules/chain_orders.d.ts.map +1 -1
  413. package/dist/modules/chain_orders.js +23 -42
  414. package/dist/modules/chain_orders.js.map +1 -1
  415. package/dist/modules/config.d.ts.map +1 -1
  416. package/dist/modules/config.js +5 -2
  417. package/dist/modules/config.js.map +1 -1
  418. package/dist/modules/constants.d.ts +21 -21
  419. package/dist/modules/constants.d.ts.map +1 -1
  420. package/dist/modules/constants.js +53 -60
  421. package/dist/modules/constants.js.map +1 -1
  422. package/dist/modules/cr_planner.d.ts +1 -7
  423. package/dist/modules/cr_planner.d.ts.map +1 -1
  424. package/dist/modules/cr_planner.js +3 -77
  425. package/dist/modules/cr_planner.js.map +1 -1
  426. package/dist/modules/credential_policy.d.ts +0 -4
  427. package/dist/modules/credential_policy.d.ts.map +1 -1
  428. package/dist/modules/credential_policy.js +18 -3
  429. package/dist/modules/credential_policy.js.map +1 -1
  430. package/dist/modules/credit_runtime.d.ts +0 -7
  431. package/dist/modules/credit_runtime.d.ts.map +1 -1
  432. package/dist/modules/credit_runtime.js +21 -60
  433. package/dist/modules/credit_runtime.js.map +1 -1
  434. package/dist/modules/crypto/index.d.ts +0 -2
  435. package/dist/modules/crypto/index.d.ts.map +1 -1
  436. package/dist/modules/crypto/index.js +0 -2
  437. package/dist/modules/crypto/index.js.map +1 -1
  438. package/dist/modules/crypto/sync.js.map +1 -1
  439. package/dist/modules/daemon_node_health.js +1 -1
  440. package/dist/modules/daemon_node_health.js.map +1 -1
  441. package/dist/modules/dexbot_class.d.ts +8 -134
  442. package/dist/modules/dexbot_class.d.ts.map +1 -1
  443. package/dist/modules/dexbot_class.js +39 -199
  444. package/dist/modules/dexbot_class.js.map +1 -1
  445. package/dist/modules/dexbot_credential_client.js +1 -1
  446. package/dist/modules/dexbot_credential_client.js.map +1 -1
  447. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  448. package/dist/modules/dexbot_fill_runtime.js +3 -6
  449. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  450. package/dist/modules/dexbot_maintenance_runtime.d.ts +6 -34
  451. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  452. package/dist/modules/dexbot_maintenance_runtime.js +27 -19
  453. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  454. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  455. package/dist/modules/dexbot_startup_runtime.js +31 -15
  456. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  457. package/dist/modules/dexbot_state_recovery.d.ts +2 -2
  458. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  459. package/dist/modules/dexbot_state_recovery.js +11 -7
  460. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  461. package/dist/modules/fund_registry.d.ts.map +1 -1
  462. package/dist/modules/fund_registry.js +24 -6
  463. package/dist/modules/fund_registry.js.map +1 -1
  464. package/dist/modules/general_settings.d.ts +1 -2
  465. package/dist/modules/general_settings.d.ts.map +1 -1
  466. package/dist/modules/general_settings.js +1 -2
  467. package/dist/modules/general_settings.js.map +1 -1
  468. package/dist/modules/graceful_shutdown.d.ts.map +1 -1
  469. package/dist/modules/graceful_shutdown.js +10 -1
  470. package/dist/modules/graceful_shutdown.js.map +1 -1
  471. package/dist/modules/grid_price_source.d.ts +19 -0
  472. package/dist/modules/grid_price_source.d.ts.map +1 -0
  473. package/dist/modules/grid_price_source.js +23 -0
  474. package/dist/modules/grid_price_source.js.map +1 -0
  475. package/dist/modules/key_store.d.ts +0 -5
  476. package/dist/modules/key_store.d.ts.map +1 -1
  477. package/dist/modules/key_store.js +1 -14
  478. package/dist/modules/key_store.js.map +1 -1
  479. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  480. package/dist/modules/launcher/bot_supervisor.js +15 -26
  481. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  482. package/dist/modules/launcher/child_env.d.ts +1 -2
  483. package/dist/modules/launcher/child_env.d.ts.map +1 -1
  484. package/dist/modules/launcher/child_env.js +1 -1
  485. package/dist/modules/launcher/child_env.js.map +1 -1
  486. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
  487. package/dist/modules/launcher/foreign_cred_daemon.js +7 -13
  488. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  489. package/dist/modules/launcher/market_adapter_runtime.d.ts +3 -4
  490. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  491. package/dist/modules/launcher/market_adapter_runtime.js +10 -29
  492. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  493. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
  494. package/dist/modules/launcher/market_adapter_watchdog.js +3 -2
  495. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
  496. package/dist/modules/launcher/monolithic_runtime.d.ts +0 -1
  497. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  498. package/dist/modules/launcher/monolithic_runtime.js +4 -18
  499. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  500. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
  501. package/dist/modules/launcher/runtime_entry.js +4 -5
  502. package/dist/modules/launcher/runtime_entry.js.map +1 -1
  503. package/dist/modules/launcher/status_reporting.d.ts +1 -2
  504. package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
  505. package/dist/modules/launcher/status_reporting.js +2 -5
  506. package/dist/modules/launcher/status_reporting.js.map +1 -1
  507. package/dist/modules/launcher/supervisor_control.js +1 -1
  508. package/dist/modules/launcher/supervisor_control.js.map +1 -1
  509. package/dist/modules/market_adapter_whitelist.d.ts +2 -2
  510. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
  511. package/dist/modules/market_adapter_whitelist.js +12 -6
  512. package/dist/modules/market_adapter_whitelist.js.map +1 -1
  513. package/dist/modules/node_failure_ledger.d.ts +23 -0
  514. package/dist/modules/node_failure_ledger.d.ts.map +1 -1
  515. package/dist/modules/node_failure_ledger.js +0 -23
  516. package/dist/modules/node_failure_ledger.js.map +1 -1
  517. package/dist/modules/node_manager.d.ts.map +1 -1
  518. package/dist/modules/node_manager.js +3 -3
  519. package/dist/modules/node_manager.js.map +1 -1
  520. package/dist/modules/order/accounting.js +3 -3
  521. package/dist/modules/order/accounting.js.map +1 -1
  522. package/dist/modules/order/async_lock.d.ts +6 -0
  523. package/dist/modules/order/async_lock.d.ts.map +1 -1
  524. package/dist/modules/order/async_lock.js +11 -0
  525. package/dist/modules/order/async_lock.js.map +1 -1
  526. package/dist/modules/order/export.d.ts +1 -1
  527. package/dist/modules/order/export.js +10 -10
  528. package/dist/modules/order/export.js.map +1 -1
  529. package/dist/modules/order/format.d.ts +1 -8
  530. package/dist/modules/order/format.d.ts.map +1 -1
  531. package/dist/modules/order/format.js +0 -14
  532. package/dist/modules/order/format.js.map +1 -1
  533. package/dist/modules/order/grid.d.ts +2 -12
  534. package/dist/modules/order/grid.d.ts.map +1 -1
  535. package/dist/modules/order/grid.js +23 -24
  536. package/dist/modules/order/grid.js.map +1 -1
  537. package/dist/modules/order/grid_reconcile.d.ts +1 -1
  538. package/dist/modules/order/grid_reconcile.js +1 -1
  539. package/dist/modules/order/grid_reconcile_internal.js +1 -1
  540. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  541. package/dist/modules/order/logger.d.ts +3 -0
  542. package/dist/modules/order/logger.d.ts.map +1 -1
  543. package/dist/modules/order/logger.js +23 -14
  544. package/dist/modules/order/logger.js.map +1 -1
  545. package/dist/modules/order/logger_state.d.ts +5 -22
  546. package/dist/modules/order/logger_state.d.ts.map +1 -1
  547. package/dist/modules/order/logger_state.js +6 -25
  548. package/dist/modules/order/logger_state.js.map +1 -1
  549. package/dist/modules/order/manager.d.ts +1 -4
  550. package/dist/modules/order/manager.d.ts.map +1 -1
  551. package/dist/modules/order/manager.js +34 -33
  552. package/dist/modules/order/manager.js.map +1 -1
  553. package/dist/modules/order/processed_fill_store.d.ts +0 -5
  554. package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
  555. package/dist/modules/order/processed_fill_store.js +10 -15
  556. package/dist/modules/order/processed_fill_store.js.map +1 -1
  557. package/dist/modules/order/strategy.d.ts +6 -4
  558. package/dist/modules/order/strategy.d.ts.map +1 -1
  559. package/dist/modules/order/strategy.js +6 -4
  560. package/dist/modules/order/strategy.js.map +1 -1
  561. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  562. package/dist/modules/order/sync_engine.js +17 -10
  563. package/dist/modules/order/sync_engine.js.map +1 -1
  564. package/dist/modules/order/utils/math.d.ts +7 -1
  565. package/dist/modules/order/utils/math.d.ts.map +1 -1
  566. package/dist/modules/order/utils/math.js +19 -1
  567. package/dist/modules/order/utils/math.js.map +1 -1
  568. package/dist/modules/order/utils/order.d.ts.map +1 -1
  569. package/dist/modules/order/utils/order.js +11 -4
  570. package/dist/modules/order/utils/order.js.map +1 -1
  571. package/dist/modules/order/utils/system.d.ts +3 -8
  572. package/dist/modules/order/utils/system.d.ts.map +1 -1
  573. package/dist/modules/order/utils/system.js +14 -4
  574. package/dist/modules/order/utils/system.js.map +1 -1
  575. package/dist/modules/order/utils/validate.js +1 -1
  576. package/dist/modules/order/utils/validate.js.map +1 -1
  577. package/dist/modules/path_api.js +1 -1
  578. package/dist/modules/path_api.js.map +1 -1
  579. package/dist/modules/paths.d.ts +1 -7
  580. package/dist/modules/paths.d.ts.map +1 -1
  581. package/dist/modules/paths.js +1 -1
  582. package/dist/modules/paths.js.map +1 -1
  583. package/dist/modules/process_discovery.d.ts +3 -0
  584. package/dist/modules/process_discovery.d.ts.map +1 -1
  585. package/dist/modules/process_discovery.js +15 -1
  586. package/dist/modules/process_discovery.js.map +1 -1
  587. package/dist/modules/runtime_settings.js +4 -2
  588. package/dist/modules/runtime_settings.js.map +1 -1
  589. package/dist/modules/settings_merge.d.ts +5 -1
  590. package/dist/modules/settings_merge.d.ts.map +1 -1
  591. package/dist/modules/settings_merge.js +17 -4
  592. package/dist/modules/settings_merge.js.map +1 -1
  593. package/dist/modules/socket_json_client.d.ts.map +1 -1
  594. package/dist/modules/socket_json_client.js +12 -2
  595. package/dist/modules/socket_json_client.js.map +1 -1
  596. package/dist/modules/storage/browser_adapter.d.ts +8 -3
  597. package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
  598. package/dist/modules/storage/browser_adapter.js +58 -7
  599. package/dist/modules/storage/browser_adapter.js.map +1 -1
  600. package/dist/modules/storage/index.d.ts +1 -1
  601. package/dist/modules/storage/index.js +1 -1
  602. package/dist/modules/types.d.ts +1 -1
  603. package/dist/modules/types.d.ts.map +1 -1
  604. package/dist/modules/utils/sanitize_key.d.ts +7 -0
  605. package/dist/modules/utils/sanitize_key.d.ts.map +1 -0
  606. package/dist/modules/utils/sanitize_key.js +15 -0
  607. package/dist/modules/utils/sanitize_key.js.map +1 -0
  608. package/dist/modules/validate_profiles.d.ts.map +1 -1
  609. package/dist/modules/validate_profiles.js +6 -8
  610. package/dist/modules/validate_profiles.js.map +1 -1
  611. package/dist/pm2.d.ts.map +1 -1
  612. package/dist/pm2.js +8 -9
  613. package/dist/pm2.js.map +1 -1
  614. package/dist/scripts/analyze-git.d.ts +1 -1
  615. package/dist/scripts/analyze-git.js +1 -1
  616. package/dist/scripts/analyze-orders.d.ts +2 -2
  617. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  618. package/dist/scripts/analyze-orders.js +39 -28
  619. package/dist/scripts/analyze-orders.js.map +1 -1
  620. package/dist/scripts/diagnose-pool-history.js +1 -1
  621. package/dist/scripts/divergence-calc.d.ts +1 -1
  622. package/dist/scripts/divergence-calc.js +3 -3
  623. package/dist/scripts/native_release_gates.js +4 -2
  624. package/dist/scripts/native_release_gates.js.map +1 -1
  625. package/dist/scripts/print_grid.d.ts +1 -1
  626. package/dist/scripts/print_grid.js +1 -1
  627. package/dist/scripts/run-tests.js +38 -19
  628. package/dist/scripts/run-tests.js.map +1 -1
  629. package/dist/scripts/runner.d.ts +3 -5
  630. package/dist/scripts/runner.d.ts.map +1 -1
  631. package/dist/scripts/runner.js +4 -6
  632. package/dist/scripts/runner.js.map +1 -1
  633. package/dist/scripts/sync-version.d.ts +2 -2
  634. package/dist/scripts/sync-version.js +2 -2
  635. package/dist/scripts/update.d.ts +1 -1
  636. package/dist/scripts/update.js +2 -2
  637. package/dist/scripts/update.js.map +1 -1
  638. package/dist/scripts/validate_bots.d.ts +1 -1
  639. package/dist/scripts/validate_bots.js +1 -1
  640. package/dist/scripts/verify-browser-bundle.d.ts +1 -1
  641. package/dist/scripts/verify-browser-bundle.js +1 -1
  642. package/dist/unlock.js +4 -4
  643. package/dist/unlock.js.map +1 -1
  644. package/docs/BITSHARES_ONBOARDING.md +63 -18
  645. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +14 -23
  646. package/docs/COW_INVARIANTS.md +4 -4
  647. package/docs/CREDENTIAL_SECURITY.md +0 -11
  648. package/docs/DEXBOT_COMPARISON.md +12 -12
  649. package/docs/EVOLUTION.md +17 -43
  650. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +27 -83
  651. package/docs/GRID_RECALCULATION.md +1 -13
  652. package/docs/GRID_RECONCILE.md +24 -24
  653. package/docs/LIFECYCLE.md +4 -4
  654. package/docs/LOGGING.md +1 -1
  655. package/docs/MPA_CREDIT_USAGE.md +3 -3
  656. package/docs/README.md +2 -2
  657. package/docs/WORKFLOW.md +2 -2
  658. package/docs/architecture.md +48 -43
  659. package/docs/developer_guide.md +22 -24
  660. package/market_adapter/README.md +0 -2
  661. package/modules/README.md +2 -1
  662. package/package.json +22 -14
  663. package/scripts/README.md +34 -8
  664. package/scripts/clean-dist.js +10 -2
  665. package/tests/README.md +4 -3
  666. package/claw/openclaw.plugin.json +0 -13
  667. package/dist/market_adapter/merge_lp_data.d.ts +0 -3
  668. package/dist/market_adapter/merge_lp_data.d.ts.map +0 -1
  669. package/dist/market_adapter/merge_lp_data.js +0 -125
  670. package/dist/market_adapter/merge_lp_data.js.map +0 -1
  671. package/dist/market_adapter/utils/paths.d.ts +0 -3
  672. package/dist/market_adapter/utils/paths.d.ts.map +0 -1
  673. package/dist/market_adapter/utils/paths.js +0 -5
  674. package/dist/market_adapter/utils/paths.js.map +0 -1
@@ -78,16 +78,16 @@ Phase 2 and 3 both respect the `dryRun` flag: when true, no on-chain mutations a
78
78
 
79
79
  ### Phase 1 — Pure Planning Under `_gridLock`
80
80
 
81
- **`grid_reconcile.ts:205-356`**
81
+ **`grid_reconcile.ts:208-375`**
82
82
 
83
- 1. **Phantom order sanitization** (lines 211-244): For each `isOrderPlaced()` order whose `orderId` is not in the chain snapshot, reset it to VIRTUAL with `skipAccounting` to prevent fund inflation. Two absence-decision guards make this safe:
84
- - **Freshly-assigned deferral** (lines 215-233): an `orderId` assigned within `TIMING.SYNC_LOCK_TIMEOUT_MS` (via `manager._orderIdAssignedAt`) may be an in-flight create/adopt whose broadcast has not landed or is not yet visible to a lagging/truncated read — virtualizing it and re-creating would duplicate a real live order (the reconcile-timeout death-spiral root cause). It is skipped (deferred) rather than virtualized.
85
- - **Ghost heuristic** (line 225): an order with `size <= 0` && `PARTIAL` (a known filled ghost) still passes through so known fills get cleaned up.
83
+ 1. **Phantom order sanitization** (lines 216-245): For each `isOrderPlaced()` order whose `orderId` is not in the chain snapshot, reset it to VIRTUAL with `skipAccounting` to prevent fund inflation. Two absence-decision guards make this safe:
84
+ - **Freshly-assigned deferral** (lines 226-235): an `orderId` assigned within `TIMING.SYNC_LOCK_TIMEOUT_MS` (via `manager._orderIdAssignedAt`) may be an in-flight create/adopt whose broadcast has not landed or is not yet visible to a lagging/truncated read — virtualizing it and re-creating would duplicate a real live order (the reconcile-timeout death-spiral root cause). It is skipped (deferred) rather than virtualized.
85
+ - **Ghost heuristic** (line 229): an order with `size <= 0` && `PARTIAL` (a known filled ghost) still passes through so known fills get cleaned up.
86
86
  - Virtualization always uses `{ skipAccounting: true }` so startup cleanup never inflates `ChainFree`.
87
87
 
88
- 2. **Duplicate detection** (lines 246-311): For each unmatched chain order, find the nearest active same-side grid order. If `priceDiff ≤ tolerance × 5`, flag it as a suspected duplicate and queue for a Phase 2 cancel (never cancelled under lock). Tolerance is computed from price impact via `calculatePriceTolerance`: capped at `PRICE_TOLERANCE_MAX_PERCENT` (1%) with a `PRICE_TOLERANCE_MIN_ABSOLUTE` (0.0001) floor. Duplicate IDs are removed from the unmatched set so they aren't also paired for updates/creates.
88
+ 2. **Duplicate detection** (lines 258-331): For each unmatched chain order, find the nearest active same-side grid order. If `priceDiff ≤ tolerance × 5`, flag it as a suspected duplicate and queue for a Phase 2 cancel (never cancelled under lock). Tolerance is computed from price impact via `calculatePriceTolerance`: capped at `PRICE_TOLERANCE_MAX_PERCENT` (1%) with a `PRICE_TOLERANCE_MIN_ABSOLUTE` (0.0001) floor. Duplicate IDs are removed from the unmatched set so they aren't also paired for updates/creates.
89
89
 
90
- 3. **Per-side reconciliation** via `_reconcileStartupSide(planOnly=true)` (lines 323-353):
90
+ 3. **Per-side reconciliation** via `_reconcileStartupSide(planOnly=true)` (lines 343-372):
91
91
  - Count `matchedOnGrid` (active grid orders with `orderId`)
92
92
  - `neededSlots = targetCount - matchedOnGrid`; pick virtual slots to activate
93
93
  - Match sorted unmatched chain orders to virtual slots → `plannedUpdates`
@@ -99,29 +99,29 @@ Returns `{ plannedCreates, plannedUpdates, plannedCancels, chainSellCount, chain
99
99
 
100
100
  ### Phase 2 — Blockchain Execution Outside Lock
101
101
 
102
- **`grid_reconcile.ts:358-480`**
102
+ **`grid_reconcile.ts:376-500`**
103
103
 
104
104
  Each sub-phase releases `_gridLock` before starting and re-acquires it per operation (through `synchronizeWithChain` in individual helpers). No single long-held lock blocks fills, sync, or divergence checks — but each operation still runs under the lock for consistency.
105
105
 
106
- **Cancellations** (lines 366-391): Execute `plannedCancels`. Each `_cancelChainOrder` acquires `_gridLock` internally. This covers duplicate cancels, edge-release cancels, and excess-order cancels.
106
+ **Cancellations** (lines 384-411): Execute `plannedCancels`. Each `_cancelChainOrder` acquires `_gridLock` internally. This covers duplicate cancels, edge-release cancels, and excess-order cancels.
107
107
 
108
- **Updates** (lines 393-465):
108
+ **Updates** (lines 413-485):
109
109
  - Batch via `_executeStartupUpdateBatch` when `supportsBatchUpdate` is available
110
110
  - Retry up to 3× (`maxBatchAttempts = 3`)
111
111
  - On each failure: `_recoverStartupSyncFailure()` re-fetches open orders from chain (guarded read) and re-syncs `manager` state via `manager.syncFromOpenOrders()`, then `_refreshStartupUpdatePlans()` rebuilds plans against the fresh chain state
112
112
  - If retries exhausted or batch helpers are unavailable → `_executeStartupSequentialUpdateFallback()` one-by-one with per-failure recovery
113
113
 
114
- **Creates** (lines 467-480): `_executePlannedStartupCreates` runs with the outside-in pair grouping — grouped from the outermost grid slots toward the center, BUY descending / SELL ascending, so the most price-critical orders are placed first. BitShares DEX batch-create operations are used where supported. Every created chain ID is captured into `phase2CreatedOrderIds` so Phase 3 cannot later cancel the freshly-created orders.
114
+ **Creates** (lines 487-500): `_executePlannedStartupCreates` runs with the outside-in pair grouping — grouped from the outermost grid slots toward the center, BUY descending / SELL ascending, so the most price-critical orders are placed first. BitShares DEX batch-create operations are used where supported. Every created chain ID is captured into `phase2CreatedOrderIds` so Phase 3 cannot later cancel the freshly-created orders.
115
115
 
116
116
  ### Phase 3 — Fresh Re-read, Adoption, Stale Surplus Cleanup
117
117
 
118
- **`grid_reconcile.ts:502-631`** (guarded by `if (!dryRun)` at line 504)
118
+ **`grid_reconcile.ts:502-641`** (guarded by `if (!dryRun)` at line 504)
119
119
 
120
120
  1. **Guarded fresh re-read** (lines 512-516): `readOpenOrdersGuarded` re-fetches all open orders. On a truncated/empty read it returns early (defers), keeping the pre-Phase-2 counts for the summary log — a capped window omits exactly the freshest Phase-2 creates.
121
121
 
122
122
  2. **Adopt uncertain-landed creates** (lines 533-578): For any fresh chain order not matching a grid `orderId` and not created by a slot, it attempts targeted slot adoption — matching a VIRTUAL slot by type+price+size (within tolerance) and registering it via `_applySync(..., 'createOrder')` with the create-fee deduction. Full `syncFromOpenOrders` is deliberately **not** used here (its pass-1 virtualizes ACTIVE slots missing from the snapshot, and a lagging read right after the Phase-2 broadcast would destroy the confirmed grid). If adoption fails, the ID is still protected from surplus-cancel; the next sync loop's orphan adoption registers it.
123
123
 
124
- 3. **Stale surplus cancellation** (lines 579-599): Per side, count orders exceeding `targetCount` that no grid slot holds via `orderId` (including the phase-2 created IDs). Cancel only these untracked surplus orders, sorted by chain ID for determinism. This catches orphans lost during grid reinitialization — on-chain orders with no corresponding grid slot.
124
+ 3. **Stale surplus cancellation** (lines 579-625): Per side, count orders exceeding `targetCount` that no grid slot holds via `orderId` (including the phase-2 created IDs). Cancel only these untracked surplus orders, sorted by chain ID for determinism. This catches orphans lost during grid reinitialization — on-chain orders with no corresponding grid slot.
125
125
 
126
126
  ### Partial Failure State
127
127
 
@@ -130,8 +130,8 @@ If Phase 2 partially succeeds (some cancels, some creates fail), there is no rol
130
130
  ### Timeouts and Read Coverage
131
131
 
132
132
  - **No per-attempt race** around the reconcile itself — the 1.4.8 change removed it to avoid orphaning mid-batch broadcasts (see the [`recalculateGrid`](../modules/order/grid.ts) call site in `modules/order/grid.ts`).
133
- - The whole resync is bounded by a **10-minute total timeout** (`PIPELINE_TIMING.TIMEOUT_MS * 2` at `grid.ts:1122`), applied via `Promise.race` at `grid.ts:1217`.
134
- - Every internal chain read goes through `readOpenOrdersGuarded` (`chain_orders.ts:611`) with the 30s / 3-retry / node-failover standard, and empty/truncated reads are treated as **ambiguous** — never as authoritative absence.
133
+ - The whole resync is bounded by a **10-minute total timeout** (`PIPELINE_TIMING.TIMEOUT_MS * 2` at `grid.ts:1184`), applied via `Promise.race` at `grid.ts:1279`.
134
+ - Every internal chain read goes through `readOpenOrdersGuarded` (`chain_orders.ts:610`) with the 30s / 3-retry / node-failover standard, and empty/truncated reads are treated as **ambiguous** — never as authoritative absence.
135
135
 
136
136
  ---
137
137
 
@@ -139,7 +139,7 @@ If Phase 2 partially succeeds (some cancels, some creates fail), there is no rol
139
139
 
140
140
  ### Fresh Grid Guard (`matchedOnGrid > 0`)
141
141
 
142
- **`grid_reconcile_internal.ts:1604-1616`**
142
+ **`grid_reconcile_internal.ts:1600`**
143
143
 
144
144
  When a brand-new grid is generated, every slot is VIRTUAL — `matchedOnGrid = 0`. Without a guard, every on-chain order appears "unmatched" and would be cancelled as excess:
145
145
 
@@ -153,11 +153,11 @@ When `matchedOnGrid === 0` AND scaling up (`neededSlots > 0`), excess cancellati
153
153
 
154
154
  ### Grid-Edge Lock
155
155
 
156
- **`grid_reconcile_internal.ts:259`** — `_isGridEdgeFullyActive` detects when the grid boundary is fully active (all slots on-chain) before cancelling excess orders.
156
+ **`grid_reconcile_internal.ts:244`** — `_isGridEdgeFullyActive` detects when the grid boundary is fully active (all slots on-chain) before cancelling excess orders.
157
157
 
158
- When all outermost orders of a side are ACTIVE with `orderId`, all balance is committed to the edges. Cancel the **largest** order among the update candidates (`_cancelLargestOrder`, line 329) to free maximum funds with minimum operations, since the DEX does not expose partial-reduce in one operation. The cancelled slot gets a replacement create.
158
+ When all outermost orders of a side are ACTIVE with `orderId`, all balance is committed to the edges. Cancel the **largest** order among the update candidates (`_cancelLargestOrder`, line 314) to free maximum funds with minimum operations, since the DEX does not expose partial-reduce in one operation. The cancelled slot gets a replacement create.
159
159
 
160
- Detection (`_isGridEdgeFullyActive`, line 259): sort orders by price (BUY descending, SELL ascending), and check the outermost ones are all `isOrderPlaced()`.
160
+ Detection (`_isGridEdgeFullyActive`, line 244): sort orders by price (BUY descending, SELL ascending), and check the outermost ones are all `isOrderPlaced()`.
161
161
 
162
162
  ### Duplicate Tolerance (5× Multiplier)
163
163
 
@@ -181,10 +181,10 @@ Reconcile Phase 1 runs under `_gridLock` with no side effects on the frozen mast
181
181
 
182
182
  ### Truncated-Read Ambiguity (since 1.4.8)
183
183
 
184
- Every chain read feeding an absence/surplus decision goes through `readOpenOrdersGuarded` (`chain_orders.ts:611`) and treats an empty or truncated snapshot as **unreadable** — never as "nothing landed" or "nothing to cancel":
184
+ Every chain read feeding an absence/surplus decision goes through `readOpenOrdersGuarded` (`chain_orders.ts:610`) and treats an empty or truncated snapshot as **unreadable** — never as "nothing landed" or "nothing to cancel":
185
185
 
186
- - `_recoverSyncFromChain` (`grid_reconcile_internal.ts:607`) — plus its three recovery sites in `_createOrderFromGrid` / `_cancelChainOrder` — defers on empty/truncated reads (`deferEmpty: true`). A pass-1 phantom cleanup would otherwise virtualize live slots from a partial window.
187
- - `_adoptPossiblyLandedCreate` (`grid_reconcile_internal.ts:947`) defers to an uncertain outcome on truncated reads, and the startup group batch uncertain verification follows the same rule.
186
+ - `_recoverSyncFromChain` (`grid_reconcile_internal.ts:592`) — plus its three recovery sites in `_createOrderFromGrid` / `_cancelChainOrder` — defers on empty/truncated reads (`deferEmpty: true`). A pass-1 phantom cleanup would otherwise virtualize live slots from a partial window.
187
+ - `_adoptPossiblyLandedCreate` (`grid_reconcile_internal.ts:932`) defers to an uncertain outcome on truncated reads, and the startup group batch uncertain verification follows the same rule.
188
188
  - Phase 3 final refresh (`grid_reconcile.ts:512`) skips adoption/surplus-cancel on a truncated read, keeping the pre-phase-2 counts for the summary log.
189
189
  - Adoption paths (`_adoptPossiblyLandedCreate`, grouping path, reconcile adoption loop) apply the create-fee deduction via `_applySync` for accounting parity.
190
190
 
@@ -194,7 +194,7 @@ The underlying rule is `INV-BROADCAST-004`: a capped `get_full_accounts` window
194
194
 
195
195
  ## Lock Hierarchy
196
196
 
197
- **`manager.ts:471-486`** — canonical reference in [`developer_guide.md`](developer_guide.md#lock-ordering-for-deadlock-prevention).
197
+ **`manager.ts:474-489`** — canonical reference in [`developer_guide.md`](developer_guide.md#lock-ordering-for-deadlock-prevention).
198
198
 
199
199
  ```
200
200
  Level 0: _fillProcessingLock Level 1: _divergenceLock
@@ -224,7 +224,7 @@ Commit `e64db685` replaced 6 single-value boolean state fields with refcounts/st
224
224
  | `maxBatchAttempts` | `3` | `grid_reconcile.ts:415` | Update-batch retry limit |
225
225
  | `PRICE_TOLERANCE_MAX_PERCENT` | `0.01` (1%) | `constants.ts:452` | Cap on price tolerance |
226
226
  | `PRICE_TOLERANCE_MIN_ABSOLUTE` | `0.0001` | `constants.ts:456` | Floor for price tolerance |
227
- | `PIPELINE_TIMING.TIMEOUT_MS` | `300000` (5min) | `constants.ts:805` | Base pipeline timing; resync uses 2× (10 min) |
227
+ | `PIPELINE_TIMING.TIMEOUT_MS` | `300000` (5min) | `constants.ts:800` | Base pipeline timing; resync uses 2× (10 min) |
228
228
 
229
229
  ---
230
230
 
@@ -250,7 +250,7 @@ Commit `e64db685` replaced 6 single-value boolean state fields with refcounts/st
250
250
  | File | Role |
251
251
  |------|------|
252
252
  | `modules/order/grid_reconcile.ts` | Public API + 3-phase orchestrator (642 lines) |
253
- | `modules/order/grid_reconcile_internal.ts` | Internal helpers — `_reconcileStartupSide`, grid detection, recovery, uncertainty (1690 lines) |
253
+ | `modules/order/grid_reconcile_internal.ts` | Internal helpers — `_reconcileStartupSide`, grid detection, recovery, uncertainty (1675 lines) |
254
254
  | `modules/order/manager.ts` | Lock hierarchy definition, `_applyOrderUpdate`, phantom guard, `reconcileGrid` entry, COW integration |
255
255
  | `modules/order/async_lock.ts` | AsyncLock engine with ALS re-entrancy (424 lines) |
256
256
  | `modules/order/sync_engine.ts` | Blockchain sync pipeline |
package/docs/LIFECYCLE.md CHANGED
@@ -134,7 +134,7 @@ sequenceDiagram
134
134
  participant STORE as Storage
135
135
 
136
136
  MA->>CL: AMA center snapshot updated
137
- CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:1664)
137
+ CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:1694)
138
138
  CL->>RT: performPeriodicGridChecks() (dexbot_maintenance_runtime.ts:1043)
139
139
  RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:1845)
140
140
  RT->>RT: executeMaintenanceLogic() (dexbot_maintenance_runtime.ts:1452)
@@ -158,10 +158,10 @@ the parameters.
158
158
 
159
159
  > Note: `runMaintenance()` is a **different** subsystem — the credit/MPA debt
160
160
  > runtime (`modules/credit_runtime.ts:3041`, reached via
161
- > `_runCreditRuntimeMaintenance` at `dexbot_class.ts:1769`). The grid maintenance
161
+ > `_runCreditRuntimeMaintenance` at `dexbot_class.ts:1794`). The grid maintenance
162
162
  > chain above is the one that matters for order/price upkeep.
163
163
 
164
- References: `modules/dexbot_class.ts:1664` (`_performPeriodicGridChecks`) →
164
+ References: `modules/dexbot_class.ts:1694` (`_performPeriodicGridChecks`) →
165
165
  `modules/dexbot_maintenance_runtime.ts:1043` (`performPeriodicGridChecks`) →
166
166
  `:1845` (`runGridMaintenance`) → `:1452` (`executeMaintenanceLogic`),
167
167
  `docs/GRID_RECALCULATION.md`, `docs/GRID_RECONCILE.md`.
@@ -191,7 +191,7 @@ enforced*, not compiler-enforced — learn them or you will introduce fund bugs.
191
191
  | How a fill becomes orders | `modules/dexbot_fill_runtime.ts` → `modules/order/manager.ts` |
192
192
  | Grid math / recalculation | `modules/order/grid.ts`, `docs/GRID_RECALCULATION.md` |
193
193
  | Funds & accounting | `modules/order/accounting.ts`, `docs/FUND_MOVEMENT_AND_ACCOUNTING.md` |
194
- | Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:1664` |
194
+ | Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:1694` |
195
195
  | Market signal source | `market_adapter/market_adapter.ts`, `analysis/README.md` |
196
196
  | Startup & orchestration | `modules/dexbot_class.ts`, `docs/developer_guide.md` §"Startup Sequence" |
197
197
  | Why COW exists | `docs/architecture.md` §"Copy-on-Write (COW) Grid Pattern", `docs/COW_INVARIANTS.md` |
package/docs/LOGGING.md CHANGED
@@ -309,7 +309,7 @@ Yes — each bot entry in `profiles/bots.json` accepts an optional `logging` fie
309
309
  }
310
310
  ```
311
311
 
312
- The per-bot `logging` is deep-merged on top of the global config from `general.settings.json`. See `modules/types.ts` (`BotLoggingOverrides`), `modules/runtime_settings.ts`, and `modules/order/manager.ts` for the wiring.
312
+ The per-bot `logging` is deep-merged on top of the global config from `general.settings.json`. See `modules/runtime_settings.ts` for the merge logic and `modules/order/manager.ts` for where the merged config reaches the logger.
313
313
 
314
314
  **Q: What about PM2?**
315
315
  The logger auto-detects PM2 and suppresses file writes (PM2 captures stdout/stderr). File rotation is also suppressed under PM2.
@@ -233,7 +233,7 @@ When `maxBorrowAmountPerOperation` is set, each credit-maintenance cycle runs `_
233
233
 
234
234
  - Discovers deals whose `debtAmount` exceeds `maxBorrowAmountPerOperation`.
235
235
  - Splits each oversized deal into `ceil(debt / maxPerOp)` equal pieces via atomic repay+reborrow transactions. Total debt across the new deals is preserved; only deal granularity changes.
236
- - Skips a deal if any piece would fall below the offer's `min_deal_amount` (the offer is cached for the runtime lifetime, so on-chain `min_deal_amount` changes mid-split are not re-read).
236
+ - Skips a deal if any piece would fall below the offer's `min_deal_amount` (offers are cached with a 10-minute TTL — `TIMING.OFFER_CACHE_TTL_MS` — so on-chain `min_deal_amount` changes are picked up on the next re-fetch).
237
237
  - Pauses `BLOCKCHAIN_SETTLE_DELAY_MS` between pieces; aborts on shutdown.
238
238
  - Stops once `CREDIT_DEAL_SPLIT_MAX_PIECES` pieces have been emitted in the current cycle. Remaining oversized deals are deferred to the next maintenance cycle.
239
239
  - Uses an in-process `_splitInFlight` guard so `runMaintenance` and `runCreditWatchdog` cannot start overlapping splits.
@@ -342,12 +342,12 @@ Treat this file as runtime state, not primary configuration. The source of truth
342
342
 
343
343
  - `modules/credit_runtime.ts`: debt workflow executor (Phase 0 oversized-deal splitter lives here)
344
344
  - `modules/cr_planner.ts`: MPA debt-first planner; clamps `debtDelta` by `maxBorrowAmountPerOperation`
345
- - `modules/types.ts`: `LendingEntryBase` — shared `mpa` / `creditOffer` type including `maxBorrowAmountPerOperation`
345
+ - `modules/cr_planner.ts`: `DebtFirstCrPlanOptions` — planner options carrying `maxBorrowAmountPerOperation`; lending-item shapes are validated inline in `bot_settings.ts`
346
346
  - `modules/dexbot_class.ts`: runtime startup and watchdog lifecycle
347
347
  - `modules/bot_settings.ts`: `debtPolicy` validation
348
348
  - `market_adapter/README.md`: AMA pricing, grid triggers, and dynamic-weight runtime
349
349
  - `modules/credential_policy.ts`: signing constraints for credit and call-order operations
350
- - `tests/test_credit_runtime.ts`: credit runtime behavior coverage (including 6 oversized-deal splitter tests)
350
+ - `tests/test_credit_runtime.ts`: credit runtime behavior coverage (including 3 oversized-deal splitter tests)
351
351
  - `tests/test_multi_asset_distribution.ts`: collateral distribution and multi-asset state coverage
352
352
 
353
353
  </details>
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This directory contains the comprehensive technical documentation for the DEXBot2 trading bot. It is designed to guide developers from high-level architecture down to the nuances of fund accounting and state management.
4
4
 
5
- **Version context:** v1.4.17 (released).
5
+ **Version context:** v1.4.21 (released).
6
6
 
7
7
  ---
8
8
 
@@ -144,7 +144,7 @@ This directory contains the comprehensive technical documentation for the DEXBot
144
144
 
145
145
  ### 🧭 [Evolution Report](EVOLUTION.md)
146
146
  *Project timeline and major architecture phases.*
147
- - **Coverage**: Historical milestones from the initial December 2025 bootstrap through the v1.4.20 stable release (grid persistence safety, dust pipeline fix, net inventory lots); credit/debt runtime and maintenance hardening are covered under Phase 5 (Mar–Jun 2026)
147
+ - **Coverage**: Historical milestones from the initial December 2025 bootstrap through the v1.4.22 stable release (grid persistence safety, dust pipeline fix, net inventory lots); credit/debt runtime and maintenance hardening are covered under Phase 5 (Mar–Jun 2026)
148
148
  - **Focus**: Architecture evolution, release history, test growth, and documentation changes
149
149
 
150
150
  ### 🗒️ [Changelog](../CHANGELOG.md)
package/docs/WORKFLOW.md CHANGED
@@ -211,7 +211,7 @@ recommended mode:
211
211
  - **Single process** — no PM2, no separate credential daemon management
212
212
  - **Auto-update** — detects new releases, builds, and restarts cleanly
213
213
  - **Crash restart** — background mode re-spawns on failure
214
- - **Per-bot log files** — each bot logs to `profiles/logs/<bot>.log`
214
+ - **Per-bot log files** — each bot logs to `<profiles>/logs/<bot>.log` (`~/.config/dexbot2/profiles/logs` by default)
215
215
  - **Built-in daemon** — the credential daemon is managed internally
216
216
 
217
217
  Legacy PM2 mode (`npm run pm2:unlock`) is de-emphasized but still available.
@@ -257,7 +257,7 @@ the canonical name is preferred in scripts and docs.
257
257
  | `dexbot restart` | `restartall` | Restart the monolithic runtime (unlock mode) |
258
258
  | `dexbot delete` | — | Shut down and clean up the monolithic runtime (unlock mode) |
259
259
  | `dexbot whitelist` | `white` | Generate market adapter whitelist from AMA bot configs |
260
- | `dexbot clear` | — | Remove all log files from `profiles/logs/` |
260
+ | `dexbot clear` | — | Remove all log files from the logs directory (`<profiles>/logs`) |
261
261
 
262
262
  ## NPM Scripts for Branch Synchronization
263
263
 
@@ -548,12 +548,11 @@ The simplified approach prioritizes fund availability over aggressive correction
548
548
  Spread corrections respect these hard limits:
549
549
 
550
550
  ```javascript
551
- // In modules/constants.ts
552
- SPREAD_LIMITS: {
553
- MIN_SPREAD_ORDERS: 2, // Always maintain minimum gap
554
- TARGET_SPREAD_PERCENT: (user-configured), // Fixed width, no inflation
555
- MAX_REPLACEMENT_SLOTS: 5, // Conservative correction cap
556
- }
551
+ // In modules/constants.ts (GRID_LIMITS)
552
+ MIN_SPREAD_ORDERS: 2, // Always maintain minimum gap
553
+
554
+ // Spread width itself stays user-configured (`targetSpreadPercent`) — fixed, no inflation.
555
+ // Correction count has no separate slot cap; it is bounded by the funds check below.
557
556
 
558
557
  // Each correction order must be healthy
559
558
  const minHealthySize = calculateMinOrderSize(side);
@@ -590,28 +589,31 @@ BLOCKCHAIN_FETCH_INTERVAL_MIN: 240, // 4 hours = 240 minutes
590
589
 
591
590
  ### Implementation Flow
592
591
 
592
+ **1. Interval startup** — `setupBlockchainFetchInterval()` in
593
+ `modules/dexbot_maintenance_runtime.ts` starts the interval during bot initialization:
594
+
593
595
  ```javascript
594
- // 1. Timer started during bot initialization
595
- this.periodicRefreshTimer = setInterval(
596
- () => this._performPeriodicRefresh(),
597
- BLOCKCHAIN_FETCH_INTERVAL_MIN * 60 * 1000
598
- );
599
-
600
- // 2. When timer fires:
601
- async _performPeriodicRefresh() {
602
- // Fetch latest market price
603
- const latestPrice = await derivePrice('book'); // Or 'pool'
604
-
605
- // Update internal anchor if using dynamic pricing
606
- if (config.startPrice === 'book' || config.startPrice === 'pool') {
607
- this.manager.startPrice = latestPrice;
608
- }
609
-
610
- // Grid remains un-affected (fund-driven during normal ops)
611
- // Only used for valuation calculations and divergence checks
612
- }
596
+ bot._blockchainFetchInterval = setInterval(tick, BLOCKCHAIN_FETCH_INTERVAL_MIN * 60 * 1000);
613
597
  ```
614
598
 
599
+ **2. Tick guards** *(no lock held)*
600
+ - Skip if shutdown has begun or a previous tick is still in flight
601
+ - Sync market adapter watchdog config
602
+
603
+ **3. Periodic work** *(under the fill-processing lock)*
604
+ - Reset accountant recovery state
605
+ - Refresh dynamic weight distribution
606
+ - `fetchAccountTotals(accountId)` — refreshes balances and the valuation anchor
607
+ - Read open orders via guarded read — truncated/empty reads defer the sync; fills are still caught by subscriptions and the next cycle
608
+ - `synchronizeWithChain(...)` — re-aligns the grid with on-chain reality; detected fills run through the normal batched rebalance pipeline and the grid is persisted, unmatched chain orders log as surplus/divergence
609
+ - `performPeriodicGridChecks(bot)` — maintenance checks (see [Lifecycle](LIFECYCLE.md))
610
+
611
+ Grid placement remains fund-driven during normal operation; the periodic tick keeps
612
+ balances, valuations, and open-order state fresh rather than directly moving prices.
613
+ A per-instance override (`_blockchainFetchIntervalMin`, e.g. for shared accounts from
614
+ the fund registry) can shorten or lengthen the interval; setting a non-positive value
615
+ disables the loop entirely.
616
+
615
617
  ### When `startPrice` is Numeric
616
618
 
617
619
  If user set `startPrice: 105.5` in bots.json:
@@ -780,10 +782,10 @@ stateDiagram-v2
780
782
 
781
783
  A **phantom order** is an illegal state where an order exists as ACTIVE/PARTIAL without a corresponding blockchain `orderId`. This corrupts fund tracking and causes "doubled funds" warnings.
782
784
 
783
- **Why Phantoms Occur**:
784
- 1. **Grid Resize Bug**: `Grid._updateOrdersForSide()` could force VIRTUAL → ACTIVE without blockchain confirmation
785
- 2. **Sync Gap**: Orders without orderId could remain ACTIVE indefinitely if sync logic skipped them
786
- 3. **No Validation**: No centralized check prevented invalid state assignments
785
+ **Risks the Three-Layer Defense Guards Against**:
786
+ 1. **Resize State Forcing**: Grid resize forcing VIRTUAL → ACTIVE without blockchain confirmation
787
+ 2. **Sync Gaps**: Orders without `orderId` remaining ACTIVE if sync logic skips them
788
+ 3. **Unvalidated Assignment**: Invalid state assignments without a centralized check
787
789
 
788
790
  **Prevention System** (Three-Layer Defense):
789
791
 
@@ -983,7 +985,7 @@ graph TB
983
985
  SKIP --> DONE
984
986
  ```
985
987
 
986
- **Key Improvement (v1.0.0)**: Force reload mechanism now ensures fresh persisted grid data before comparison, preventing stale cache from causing false divergence detections.
988
+ The force reload mechanism loads fresh persisted grid data before comparison, preventing stale cache from causing false divergence detections.
987
989
 
988
990
  ---
989
991
 
@@ -1150,9 +1152,12 @@ The system continuously monitors three mathematical invariants:
1150
1152
 
1151
1153
  ### Index Consistency
1152
1154
 
1153
- - **Validation**: `validateIndices()` checks Map ↔ Set consistency
1154
- - **Repair**: `_repairIndices()` rebuilds indices if corruption detected
1155
- - **Defensive**: Called after critical operations
1155
+ - **Grid versioning**: `_gridVersion` is bumped on every grid mutation; the
1156
+ `_ordersByType` / `_ordersByState` index caches invalidate automatically when the
1157
+ version changes (no manual rebuild step)
1158
+ - **Structural checks**: tests use `assertOrdersStructurallySound()`
1159
+ (`tests/helpers/order_test_helpers.ts`) to verify every order in the Map is non-null
1160
+ with valid `state` and `type`
1156
1161
 
1157
1162
  ---
1158
1163
 
@@ -1234,15 +1239,15 @@ graph LR
1234
1239
  npm test
1235
1240
 
1236
1241
  # Specific logic area
1237
- tsx tests/test_accounting_logic.ts
1242
+ node dist/tests/test_accounting_logic.js
1238
1243
 
1239
1244
  # Signal tests
1240
- tsx tests/test_market_adapter_signal_gates.ts
1241
- tsx tests/test_dynamic_weight_override_wiring.ts
1245
+ node dist/tests/test_market_adapter_signal_gates.js
1246
+ node dist/tests/test_dynamic_weight_override_wiring.js
1242
1247
 
1243
1248
  # Credit/debt tests
1244
- tsx tests/test_cr_planner.ts
1245
- tsx tests/test_dexbot_credit_wiring.ts
1249
+ node dist/tests/test_cr_planner.js
1250
+ node dist/tests/test_dexbot_credit_wiring.js
1246
1251
  ```
1247
1252
 
1248
1253
  ### Test Quality Metrics
@@ -1278,7 +1283,7 @@ tsx tests/test_dexbot_credit_wiring.ts
1278
1283
 
1279
1284
  3. **Verify invariants**
1280
1285
  ```javascript
1281
- expect(manager.validateIndices()).toBe(true);
1286
+ assertOrdersStructurallySound(manager); // Order Map structurally valid
1282
1287
  expect(chainTotal === chainFree + chainCommitted).toBe(true);
1283
1288
  ```
1284
1289
 
@@ -1382,7 +1387,7 @@ The strategy engine has been significantly strengthened with improvements to fun
1382
1387
  - Before executing batch order placements, available funds are validated
1383
1388
  - Prevents insufficient fund errors during large rotation cycles
1384
1389
  - Uses atomic check-and-deduct pattern for safety
1385
- - Located in: `modules/order/strategy.ts` - `rebalanceSideRobust()`
1390
+ - Located in: `modules/dexbot_cow_runtime.ts` - `validateOperationFunds()`
1386
1391
 
1387
1392
  **2. Dust Partial Handling**
1388
1393
  - Improved dust detection algorithm prevents false positives
@@ -1408,9 +1413,9 @@ The strategy engine has been significantly strengthened with improvements to fun
1408
1413
  - Located in: `modules/order/manager.ts` - `processFilledOrders()`
1409
1414
 
1410
1415
  **6. Precision Spread Management (Logarithmic Logic)**
1411
- - **Discrete Step Tracking**: Replaced the legacy linear multiplier (`SPREAD_WIDENING_MULTIPLIER`) with a discrete 1-slot logarithmic buffer. This ensures correction triggers exactly when the market moves by one full increment.
1412
- - **Center-Gap Awareness**: Refined the grid initialization math to account for the "Center Gap" naturally created during symmetric centering. This reduces the initial spread by ~0.5% (one full increment) compared to the previous version.
1413
- - **Collision-Free Safety**: Increased `MIN_SPREAD_FACTOR` to 2.1 to ensure that the security minimum (2 spread orders) never conflicts with the spread correction threshold, even at micro-spread configurations.
1416
+ - **Discrete Step Tracking**: A discrete 1-slot logarithmic buffer ensures correction triggers exactly when the market moves by one full increment.
1417
+ - **Center-Gap Awareness**: Grid initialization math accounts for the "Center Gap" naturally created during symmetric centering, reducing the initial spread by ~0.5% (one full increment).
1418
+ - **Collision-Free Safety**: `MIN_SPREAD_FACTOR` of 2.1 ensures that the security minimum (2 spread orders) never conflicts with the spread correction threshold, even at micro-spread configurations.
1414
1419
 
1415
1420
  ### Related Documentation
1416
1421
 
@@ -79,7 +79,7 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
79
79
 
80
80
  | Term | Meaning |
81
81
  |------|---------|
82
- | **Fixed-Cap Batch Fill Processing** | Groups fills with a hard cap using `MAX_FILL_BATCH_SIZE` (default 4): `<= cap` uses one unified batch; `> cap` chunks at cap size. In the documented 29-fill Feb 7 crash scenario, this reduces the estimated divergence window from ~90s to ~24s; see [`FUND_MOVEMENT_AND_ACCOUNTING.md`](FUND_MOVEMENT_AND_ACCOUNTING.md#14-fill-batch-processing--cache-fund-timeline). |
82
+ | **Fixed-Cap Batch Fill Processing** | Groups fills with a hard cap using `MAX_FILL_BATCH_SIZE` (default 4): `<= cap` uses one unified batch; `> cap` chunks at cap size. In the documented 29-fill Feb 7 crash scenario, this reduces the estimated divergence window from ~90s to ~24s; see [`FUND_MOVEMENT_AND_ACCOUNTING.md`](FUND_MOVEMENT_AND_ACCOUNTING.md#15-fill-batch-processing--timeline). |
83
83
  | **Recovery Retry System** | Count+time-based retry mechanism with periodic reset. Replaces one-shot `_recoveryAttempted` flag. Max 5 attempts per episode with 60s minimum interval between retries. |
84
84
  | **Orphan-Fill Deduplication** | Map+TTL-based tracking of stale-cleaned order IDs to prevent double-crediting. Delayed orphan fill events are still blocked by checking `_staleCleanedOrderIds`. |
85
85
 
@@ -226,9 +226,7 @@ If you see prices like `0.000795` when expecting `1350`:
226
226
 
227
227
  ## Precision & Quantization Best Practices
228
228
 
229
- **Problem**: Floating-point arithmetic accumulates rounding errors over many calculations. After repeated price derivations, fund allocations, and order sizing, float values drift from their true blockchain precision.
230
-
231
- **Solution**: Use centralized quantization utilities from `modules/order/utils/math.ts` to eliminate accumulation.
229
+ Floating-point arithmetic accumulates rounding errors across repeated price derivations, fund allocations, and order sizing. Always use the centralized quantization utilities in `modules/order/utils/math.ts` to eliminate accumulation.
232
230
 
233
231
  ### When to Quantize
234
232
 
@@ -304,7 +302,7 @@ _updateOrder(order, context, { skipAccounting, fee })
304
302
  // COW rebalance pipeline
305
303
  performSafeRebalance(fills, excludeIds) // Entry point; delegates to COW
306
304
  _applySafeRebalanceCOW(fills, excludeIds) // Creates WorkingGrid, runs planning
307
- _reconcileGridCOW(targetGrid, boundary, wg) // Computes delta against working copy
305
+ _workingGrid.buildDelta(masterGrid) // Computes actions vs master (utils/order.ts buildDelta)
308
306
  _commitWorkingGrid(workingGrid, indexes, boundary, { skipRecalc }) // Atomic swap: working → master
309
307
 
310
308
  // COW state tracking
@@ -630,8 +628,9 @@ if (isOrderHealthy(order, minHealthySize)) {
630
628
  #### `getPrecisionSlack(precision, factor)`
631
629
  ```javascript
632
630
  // Calculate float comparison tolerance for given precision
633
- // Returns: 10^(-precision) * factor (typically factor = 0.001 = 0.1%)
634
- const slack = getPrecisionSlack(5, 0.001); // Returns 0.00001 * 0.001 = 0.00000001
631
+ // Location: modules/order/utils/math.ts
632
+ // Returns: factor * quantumForPrecision(precision) (factor defaults to 2)
633
+ const slack = getPrecisionSlack(5); // Returns 2 * 10^-5 = 0.00002
635
634
 
636
635
  // Use case: Floating-point safe comparisons
637
636
  if (Math.abs(order.size - expected) <= slack) {
@@ -907,7 +906,7 @@ convention marker — AsyncLock does not enforce it at runtime.
907
906
  - Divergence checks (Level 1) nest inside fill processing
908
907
  - Sync operations (Level 2) are acquired before grid mutations — the timeout-protected lock is inner, so a stuck sync releases the outer lock
909
908
  - Grid mutations (Level 3) and fund operations (Level 4) are innermost
910
- - All paths follow the same order — the historical `gridLockAlreadyHeld` workaround flag has been eliminated
909
+ - All paths follow the same order
911
910
 
912
911
  **`adjustTotalBalance` Locking Contract** (v1.4.7):
913
912
 
@@ -1240,11 +1239,9 @@ manager.accountant._verifyFundInvariants(
1240
1239
 
1241
1240
  **2. Index Consistency Check**
1242
1241
  ```javascript
1243
- // Periodically
1244
- const isValid = manager.validateIndices();
1245
- if (!isValid) {
1246
- manager._repairIndices();
1247
- }
1242
+ // Index caches invalidate automatically via _gridVersion bumps — no manual
1243
+ // validation/repair API exists. For structural checks (e.g. in tests):
1244
+ assertOrdersStructurallySound(manager); // tests/helpers/order_test_helpers.ts
1248
1245
  ```
1249
1246
 
1250
1247
  **3. Grid Diagnostics**
@@ -1499,9 +1496,10 @@ manager.logger.logFundsStatus(manager, 'CONTEXT');
1499
1496
  console.log(manager.getMetrics());
1500
1497
  ```
1501
1498
 
1502
- ### Validate Indices
1499
+ ### Check Order Map Integrity
1503
1500
  ```javascript
1504
- const isValid = manager.validateIndices();
1501
+ // Structural check (tests); index caches self-invalidate via _gridVersion
1502
+ assertOrdersStructurallySound(manager);
1505
1503
  ```
1506
1504
 
1507
1505
  ### Check Specific Order
@@ -1629,10 +1627,10 @@ The test suite validates the following fund-related behaviors:
1629
1627
  npm test
1630
1628
 
1631
1629
  # Specific logic area
1632
- tsx tests/test_accounting_logic.ts
1630
+ node dist/tests/test_accounting_logic.js
1633
1631
 
1634
1632
  # Specific integration test
1635
- tsx tests/test_fills.ts
1633
+ node dist/tests/test_fills.js
1636
1634
  ```
1637
1635
 
1638
1636
  ### Understanding Test Structure
@@ -1705,7 +1703,7 @@ console.log(' - Testing [action] updates [fund pool]...');
1705
1703
  // Assert
1706
1704
  const finalFunds = manager.funds[poolName][side];
1707
1705
  assert.strictEqual(finalFunds, expectedValue);
1708
- assert.strictEqual(manager.validateIndices(), true); // Indices OK?
1706
+ assertOrdersStructurallySound(manager); // Order Map structurally sound?
1709
1707
  }
1710
1708
  ```
1711
1709
 
@@ -1774,7 +1772,7 @@ try {
1774
1772
  // Perform operation
1775
1773
  await fundDependentOperation();
1776
1774
  // Check state consistency
1777
- assert.strictEqual(manager.validateIndices(), true);
1775
+ assertOrdersStructurallySound(manager);
1778
1776
  } finally {
1779
1777
  manager.unlockOrders(['order-1']);
1780
1778
  }
@@ -1799,13 +1797,13 @@ The test suite provides comprehensive coverage of fund calculations and rebalanc
1799
1797
  **Running Tests**:
1800
1798
  ```bash
1801
1799
  # Test strategy rebalancing
1802
- tsx tests/test_strategy_logic.ts
1800
+ node dist/tests/test_strategy_logic.js
1803
1801
 
1804
1802
  # Test grid divergence
1805
- tsx tests/test_grid_logic.ts
1803
+ node dist/tests/test_grid_logic.js
1806
1804
 
1807
1805
  # Test accounting precision
1808
- tsx tests/test_accounting_logic.ts
1806
+ node dist/tests/test_accounting_logic.js
1809
1807
 
1810
1808
  # Run full suite
1811
1809
  npm test
@@ -1833,7 +1831,7 @@ manager.orders.forEach(order => {
1833
1831
  });
1834
1832
 
1835
1833
  // 4. Check index consistency
1836
- console.log('Indices valid?', manager.validateIndices());
1834
+ assertOrdersStructurallySound(manager); // throws if any order entry is corrupt
1837
1835
 
1838
1836
  // 5. Examine specific fund pool
1839
1837
  console.log('Virtual buy:', manager.funds.virtual.buy);
@@ -1860,7 +1858,7 @@ A: Check if it's locked (`isOrderLocked()`), in exclusion list, or below dust th
1860
1858
  A: Follow the "How to Add New Features" section above.
1861
1859
 
1862
1860
  **Q: Where are the tests?**
1863
- A: All tests are in the `tests/` directory. Run `npm test` for the full suite, or `tsx tests/<file>.ts` for individual test files.
1861
+ A: All tests are in the `tests/` directory. Run `npm test` for the full suite, or `npm run build:tests && node dist/tests/<file>.js` for individual test files.
1864
1862
 
1865
1863
  ---
1866
1864
 
@@ -573,7 +573,6 @@ market_adapter/
573
573
  |-- ama_signal_runner.ts one-cycle JSON signal CLI
574
574
  |-- candle_utils.ts candle transforms, gap detection, pruning
575
575
  |-- interval_utils.ts shared interval label helpers
576
- |-- merge_lp_data.ts candle export merge utility
577
576
  |-- lp_chart_core.ts chart HTML renderer
578
577
  |-- lp_chart_strategy_loader.ts AMA strategy/profile resolver for charts
579
578
  |-- lp_chart_runner.ts LP chart orchestration
@@ -612,7 +611,6 @@ market_adapter/
612
611
  | |-- data_discovery.ts data directory auto-discovery
613
612
  | |-- atomic_write.ts atomic file write utility
614
613
  | |-- dynamic_grid_snapshot.ts dynamic grid snapshot helpers
615
- | `-- paths.ts path resolution helpers
616
614
  |-- data/ runtime candle caches and exports
617
615
  `-- state/ runtime state, centers, and lock file
618
616
  ```
package/modules/README.md CHANGED
@@ -127,7 +127,8 @@ modules/
127
127
  └── utils/
128
128
  ├── base58check.ts Base58Check encoding
129
129
  ├── build_dir.ts BUILD_DIR constant helper
130
- └── errors.ts getErrorMessage helper
130
+ ├── errors.ts getErrorMessage helper
131
+ └── sanitize_key.ts shared sanitizeKey helper
131
132
  ```
132
133
 
133
134
  ## Key Relationships