dexbot 1.6.10 → 1.6.12

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 (365) hide show
  1. package/CHANGELOG.md +50 -3
  2. package/README.md +3 -1
  3. package/analysis/README.md +51 -11
  4. package/analysis/bot_fitting/README.md +12 -0
  5. package/analysis/tradingview/README.md +3 -3
  6. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
  7. package/analysis/trend_detection/README.md +31 -0
  8. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  9. package/claw/modules/chain_broadcast.ts +7 -1
  10. package/claw/modules/claw_launcher.ts +1 -1
  11. package/claw/modules/launcher_mode_detector.ts +9 -2
  12. package/claw/package.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  14. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  15. package/dist/analysis/account_resolver.d.ts +1 -1
  16. package/dist/analysis/account_resolver.js +15 -2
  17. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  18. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
  19. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  20. package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
  21. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
  22. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
  23. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
  24. package/dist/analysis/analyze_args.d.ts +31 -0
  25. package/dist/analysis/analyze_args.js +41 -0
  26. package/dist/analysis/analyze_dynamic_weight.js +7 -20
  27. package/dist/analysis/analyze_kalman.js +7 -17
  28. package/dist/analysis/analyze_regime.js +7 -17
  29. package/dist/analysis/analyze_regime_windows.js +8 -18
  30. package/dist/analysis/analyze_risk_profile.js +8 -18
  31. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  32. package/dist/analysis/analyze_volatility.js +7 -17
  33. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
  34. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
  35. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  36. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
  37. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
  38. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
  39. package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
  40. package/dist/analysis/bot_fitting/shared_utils.js +2 -2
  41. package/dist/analysis/bot_key_utils.d.ts +18 -10
  42. package/dist/analysis/bot_key_utils.js +10 -17
  43. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  44. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  45. package/dist/analysis/chain_pool.d.ts +3 -1
  46. package/dist/analysis/chart_ui.d.ts +5 -2
  47. package/dist/analysis/chart_ui.js +6 -3
  48. package/dist/analysis/chart_utils.d.ts +5 -5
  49. package/dist/analysis/chart_utils.js +9 -0
  50. package/dist/analysis/fills_cache.d.ts +64 -0
  51. package/dist/analysis/fills_cache.js +254 -0
  52. package/dist/analysis/fills_source.d.ts +2 -2
  53. package/dist/analysis/fills_source.js +19 -14
  54. package/dist/analysis/grid_correction_check.d.ts +1 -1
  55. package/dist/analysis/grid_correction_check.js +12 -11
  56. package/dist/analysis/math_utils.d.ts +7 -6
  57. package/dist/analysis/math_utils.js +5 -8
  58. package/dist/analysis/pnl_report.d.ts +39 -0
  59. package/dist/analysis/pnl_report.js +325 -0
  60. package/dist/analysis/price_sources.d.ts +8 -8
  61. package/dist/analysis/price_sources.js +5 -4
  62. package/dist/analysis/resolve_bot_accounts.js +2 -2
  63. package/dist/analysis/resolve_source.d.ts +1 -2
  64. package/dist/analysis/trade_profitability.d.ts +32 -2
  65. package/dist/analysis/trade_profitability.js +232 -106
  66. package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
  67. package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
  68. package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
  69. package/dist/analysis/tradingview/grid_reset_config.js +35 -6
  70. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
  71. package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
  72. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  73. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
  74. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
  75. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
  76. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  77. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
  78. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
  79. package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
  80. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  81. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  82. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  83. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  84. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  85. package/dist/credential-daemon.js +34 -20
  86. package/dist/dexbot.js +17 -14
  87. package/dist/market_adapter/candle_utils.d.ts +22 -18
  88. package/dist/market_adapter/candle_utils.js +24 -20
  89. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  90. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  91. package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
  92. package/dist/market_adapter/core/kibana_candles.js +9 -7
  93. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  94. package/dist/market_adapter/core/kibana_client.js +8 -7
  95. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  96. package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
  97. package/dist/market_adapter/core/market_adapter_service.js +184 -101
  98. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  99. package/dist/market_adapter/core/strategies/ama.js +7 -32
  100. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  101. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  102. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  103. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  104. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  105. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  106. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
  107. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
  108. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  109. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  110. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  111. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  112. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  113. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  114. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  115. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  116. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  117. package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
  118. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
  119. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
  120. package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
  121. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  122. package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
  123. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  124. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  125. package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
  126. package/dist/market_adapter/inputs/window_cache.js +8 -8
  127. package/dist/market_adapter/interval_utils.d.ts +4 -4
  128. package/dist/market_adapter/log_format.d.ts +6 -6
  129. package/dist/market_adapter/log_format.js +28 -22
  130. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  131. package/dist/market_adapter/lp_chart_core.js +26 -192
  132. package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
  133. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  134. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  135. package/dist/market_adapter/market_adapter.d.ts +94 -33
  136. package/dist/market_adapter/market_adapter.js +69 -75
  137. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  138. package/dist/market_adapter/utils/adapter_client.js +2 -2
  139. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  140. package/dist/market_adapter/utils/chain.d.ts +50 -41
  141. package/dist/market_adapter/utils/chain.js +40 -46
  142. package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
  143. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  144. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  145. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  146. package/dist/market_adapter/utils/file_lock.js +36 -32
  147. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  148. package/dist/market_adapter/utils/native_history.js +35 -28
  149. package/dist/modules/account_bots.d.ts +577 -21
  150. package/dist/modules/account_bots.js +182 -158
  151. package/dist/modules/account_orders.d.ts +66 -30
  152. package/dist/modules/account_orders.js +22 -20
  153. package/dist/modules/authority_resolver.d.ts +12 -2
  154. package/dist/modules/authority_resolver.js +15 -8
  155. package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
  156. package/dist/modules/bitshares-native/chain_client.js +45 -46
  157. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  158. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  159. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  160. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  161. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  162. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  163. package/dist/modules/bitshares-native/index.d.ts +1 -1
  164. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  165. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  166. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  167. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  168. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  169. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  170. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  171. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  172. package/dist/modules/bitshares-native/serial/types.js +55 -62
  173. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  174. package/dist/modules/bitshares-native/signing_client.js +19 -14
  175. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  176. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  177. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  178. package/dist/modules/bitshares-native/transport.js +5 -4
  179. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  180. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  181. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  182. package/dist/modules/bitshares_client.d.ts +45 -13
  183. package/dist/modules/bitshares_client.js +28 -19
  184. package/dist/modules/bot_defaults.d.ts +6 -15
  185. package/dist/modules/bot_defaults.js +1 -5
  186. package/dist/modules/bot_settings.d.ts +44 -10
  187. package/dist/modules/bot_settings.js +11 -8
  188. package/dist/modules/bots_file_lock.d.ts +6 -6
  189. package/dist/modules/bots_file_lock.js +16 -12
  190. package/dist/modules/broadcast_failure.d.ts +2 -2
  191. package/dist/modules/broadcast_failure.js +5 -4
  192. package/dist/modules/chain_keys.d.ts +42 -40
  193. package/dist/modules/chain_keys.js +53 -45
  194. package/dist/modules/chain_orders.d.ts +93 -59
  195. package/dist/modules/chain_orders.js +31 -23
  196. package/dist/modules/constants.d.ts +530 -32
  197. package/dist/modules/constants.js +52 -60
  198. package/dist/modules/cr_planner.d.ts +40 -2
  199. package/dist/modules/credential_policy.d.ts +68 -8
  200. package/dist/modules/credential_policy.js +37 -31
  201. package/dist/modules/credential_session_cache.d.ts +2 -2
  202. package/dist/modules/credit_pricing.d.ts +42 -6
  203. package/dist/modules/credit_pricing.js +44 -30
  204. package/dist/modules/credit_runtime.d.ts +276 -118
  205. package/dist/modules/credit_runtime.js +462 -165
  206. package/dist/modules/crypto/browser_provider.js +6 -4
  207. package/dist/modules/crypto/node_provider.js +1 -1
  208. package/dist/modules/crypto/pure_scrypt.js +35 -4
  209. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  210. package/dist/modules/crypto/sync.d.ts +9 -9
  211. package/dist/modules/crypto/sync.js +16 -9
  212. package/dist/modules/dexbot_class.d.ts +195 -139
  213. package/dist/modules/dexbot_class.js +78 -28
  214. package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
  215. package/dist/modules/dexbot_cow_runtime.js +248 -206
  216. package/dist/modules/dexbot_credential_client.d.ts +19 -11
  217. package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
  218. package/dist/modules/dexbot_fill_runtime.js +48 -41
  219. package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
  220. package/dist/modules/dexbot_maintenance_runtime.js +117 -80
  221. package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
  222. package/dist/modules/dexbot_startup_runtime.js +43 -43
  223. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  224. package/dist/modules/dexbot_state_recovery.js +18 -13
  225. package/dist/modules/fund_registry.d.ts +4 -2
  226. package/dist/modules/fund_registry.js +10 -10
  227. package/dist/modules/general_settings.d.ts +30 -4
  228. package/dist/modules/graceful_shutdown.d.ts +3 -3
  229. package/dist/modules/graceful_shutdown.js +2 -2
  230. package/dist/modules/grid_price_source.d.ts +1 -1
  231. package/dist/modules/key_store.d.ts +14 -8
  232. package/dist/modules/key_store.js +7 -6
  233. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  234. package/dist/modules/launcher/adapter_requirement.js +5 -5
  235. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  236. package/dist/modules/launcher/bot_supervisor.js +12 -11
  237. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  238. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  239. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  240. package/dist/modules/launcher/credential_daemon.js +2 -2
  241. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  242. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  243. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  244. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  245. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  246. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  247. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  248. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  249. package/dist/modules/launcher/supervisor_control.js +4 -2
  250. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  251. package/dist/modules/market_adapter_whitelist.js +15 -3
  252. package/dist/modules/node_manager.d.ts +41 -11
  253. package/dist/modules/node_manager.js +5 -4
  254. package/dist/modules/order/accounting.d.ts +53 -24
  255. package/dist/modules/order/accounting.js +40 -14
  256. package/dist/modules/order/async_lock.d.ts +5 -2
  257. package/dist/modules/order/async_lock.js +1 -1
  258. package/dist/modules/order/export.d.ts +7 -6
  259. package/dist/modules/order/export.js +1 -7
  260. package/dist/modules/order/format.d.ts +39 -19
  261. package/dist/modules/order/format.js +62 -16
  262. package/dist/modules/order/genesis_policy.d.ts +21 -18
  263. package/dist/modules/order/genesis_policy.js +12 -8
  264. package/dist/modules/order/grid.d.ts +142 -36
  265. package/dist/modules/order/grid.js +148 -123
  266. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  267. package/dist/modules/order/grid_reconcile.js +13 -12
  268. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  269. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  270. package/dist/modules/order/index.d.ts +263 -1
  271. package/dist/modules/order/logger.d.ts +45 -11
  272. package/dist/modules/order/logger.js +38 -40
  273. package/dist/modules/order/logger_state.d.ts +4 -4
  274. package/dist/modules/order/manager.d.ts +226 -180
  275. package/dist/modules/order/manager.js +101 -83
  276. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  277. package/dist/modules/order/processed_fill_store.js +16 -27
  278. package/dist/modules/order/strategy.d.ts +21 -13
  279. package/dist/modules/order/strategy.js +5 -6
  280. package/dist/modules/order/sync_engine.d.ts +91 -33
  281. package/dist/modules/order/sync_engine.js +99 -54
  282. package/dist/modules/order/utils/math.d.ts +157 -102
  283. package/dist/modules/order/utils/math.js +77 -38
  284. package/dist/modules/order/utils/order.d.ts +326 -106
  285. package/dist/modules/order/utils/order.js +200 -99
  286. package/dist/modules/order/utils/slot.d.ts +1 -1
  287. package/dist/modules/order/utils/system.d.ts +176 -26
  288. package/dist/modules/order/utils/system.js +86 -69
  289. package/dist/modules/order/utils/validate.d.ts +89 -41
  290. package/dist/modules/order/utils/validate.js +24 -22
  291. package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
  292. package/dist/modules/order/utils/withPoolRef.js +18 -12
  293. package/dist/modules/order/working_grid.d.ts +14 -13
  294. package/dist/modules/paths.d.ts +3 -4
  295. package/dist/modules/paths.js +3 -27
  296. package/dist/modules/process_discovery.d.ts +1 -1
  297. package/dist/modules/process_discovery.js +2 -1
  298. package/dist/modules/runtime.d.ts +7 -3
  299. package/dist/modules/runtime.js +4 -3
  300. package/dist/modules/runtime_settings.d.ts +15 -10
  301. package/dist/modules/runtime_settings.js +30 -24
  302. package/dist/modules/settings_merge.d.ts +29 -3
  303. package/dist/modules/settings_merge.js +56 -78
  304. package/dist/modules/socket_json_client.d.ts +7 -4
  305. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  306. package/dist/modules/storage/browser_adapter.js +7 -30
  307. package/dist/modules/storage/index.d.ts +1 -1
  308. package/dist/modules/storage/node_adapter.d.ts +45 -27
  309. package/dist/modules/storage/node_adapter.js +9 -9
  310. package/dist/modules/storage/types.d.ts +5 -4
  311. package/dist/modules/types.d.ts +1071 -2
  312. package/dist/modules/types.js +4 -1
  313. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  314. package/dist/modules/utils/asset_symbols.js +2 -1
  315. package/dist/modules/utils/errors.d.ts +9 -0
  316. package/dist/modules/utils/errors.js +23 -1
  317. package/dist/modules/utils/time_range.d.ts +4 -0
  318. package/dist/modules/utils/time_range.js +18 -0
  319. package/dist/modules/validate_profiles.js +53 -43
  320. package/dist/modules/version_notice.d.ts +14 -3
  321. package/dist/modules/version_notice.js +6 -4
  322. package/dist/pm2.d.ts +29 -27
  323. package/dist/pm2.js +5 -5
  324. package/dist/scripts/analyze-credit.d.ts +2 -1
  325. package/dist/scripts/analyze-credit.js +23 -24
  326. package/dist/scripts/analyze-orders.d.ts +77 -9
  327. package/dist/scripts/analyze-orders.js +66 -84
  328. package/dist/scripts/chart_command.d.ts +27 -18
  329. package/dist/scripts/chart_command.js +16 -15
  330. package/dist/scripts/check_any.d.ts +18 -0
  331. package/dist/scripts/check_any.js +126 -0
  332. package/dist/scripts/diagnose-pool-history.js +12 -7
  333. package/dist/scripts/pnl.d.ts +3 -0
  334. package/dist/scripts/pnl.js +40 -0
  335. package/dist/scripts/print_grid.js +0 -1
  336. package/dist/scripts/run-tests.js +39 -7
  337. package/dist/scripts/runner.js +1 -1
  338. package/dist/scripts/test-credit-renewal.js +30 -21
  339. package/dist/scripts/update.d.ts +10 -5
  340. package/dist/scripts/update.js +168 -103
  341. package/dist/scripts/update_dist_freshness.js +1 -0
  342. package/dist/scripts/update_layout.d.ts +61 -0
  343. package/dist/scripts/update_layout.js +180 -0
  344. package/dist/scripts/validate_bots.js +2 -1
  345. package/dist/scripts/verify-browser-bundle.js +8 -0
  346. package/dist/unlock.d.ts +28 -3
  347. package/dist/unlock.js +72 -10
  348. package/docs/BITSHARES_ONBOARDING.md +2 -0
  349. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  350. package/docs/COW_INVARIANTS.md +13 -6
  351. package/docs/DEXBOT_COMPARISON.md +8 -8
  352. package/docs/EVOLUTION.md +12 -10
  353. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  354. package/docs/GRID_RECALCULATION.md +15 -16
  355. package/docs/GRID_RECONCILE.md +14 -3
  356. package/docs/LIFECYCLE.md +11 -11
  357. package/docs/MPA_CREDIT_USAGE.md +22 -3
  358. package/docs/README.md +15 -4
  359. package/docs/WORKFLOW.md +1 -0
  360. package/docs/architecture.md +12 -9
  361. package/docs/developer_guide.md +6 -6
  362. package/market_adapter/README.md +9 -26
  363. package/modules/README.md +4 -1
  364. package/package.json +4 -1
  365. package/scripts/README.md +14 -0
@@ -63,85 +63,136 @@
63
63
  *
64
64
  * ===============================================================================
65
65
  */
66
- declare class DEXBot {
67
- config: any;
66
+ import * as DexbotStartupRuntime from './dexbot_startup_runtime.js';
67
+ import cowRuntime from './dexbot_cow_runtime.js';
68
+ import type { ChainOrderLike, CowResult, OpPhase } from './dexbot_cow_runtime.js';
69
+ import { normalizeBotEntry } from './bot_settings.js';
70
+ import type { FillOpLike, FillLike, ReplayMessageFn } from './dexbot_fill_runtime.js';
71
+ import type { BotLike, AssetPair, IncomingFill, ManagerLogger, UnknownRecord, GridConfig, OrderManagerLike, AccountOrdersLike, BotMetrics, ProcessedFillStoreLike, CreditRuntimeLike, FillBatchResult, SigningToken } from './types.js';
72
+ declare class DEXBot implements BotLike {
73
+ static normalizeBotEntry: typeof normalizeBotEntry;
74
+ config: GridConfig;
68
75
  _baseWeightDistribution: {
69
76
  sell: number;
70
77
  buy: number;
71
78
  };
72
- account: any;
79
+ account: string | null;
73
80
  accountId: string | null;
74
- privateKey: any;
75
- manager: any;
76
- accountOrders: any;
81
+ privateKey: string | SigningToken | null;
82
+ manager: OrderManagerLike;
83
+ accountOrders: AccountOrdersLike;
77
84
  triggerFile: string;
78
- _recentlyQueuedFills: Map<any, any>;
85
+ _recentlyQueuedFills: Map<string, number>;
79
86
  _fillCleanupCounter: number;
80
87
  _fillDedupeWindowMs: number;
81
88
  _fillRecordRetentionMs: number;
82
89
  _processedFillPersistBatchMs: number;
83
90
  _processedFillPersistBatchSize: number;
84
- _processedFillStore: any;
85
- _recentlyProcessedFills: any;
86
- _pendingProcessedFillWrites: any;
87
- _incomingFillQueue: any[];
91
+ _processedFillStore: ProcessedFillStoreLike;
92
+ _recentlyProcessedFills: Map<string, number>;
93
+ _pendingProcessedFillWrites: unknown;
94
+ _incomingFillQueue: IncomingFill[];
88
95
  logPrefix: string;
89
- _credentialDaemonWatchdogInterval: any;
96
+ _credentialDaemonWatchdogInterval: ReturnType<typeof setInterval> | null;
90
97
  _credentialDaemonDown: boolean;
91
98
  _credentialRecoveryNeeded: boolean;
92
99
  _credentialRecoveryInFlight: boolean;
93
100
  _credentialDaemonWatchdogInFlight: boolean;
94
101
  _staleCleanedOrderIds: Map<string, number>;
95
102
  _staleCleanupRetentionMs: number;
96
- _metrics: any;
103
+ _metrics: BotMetrics;
97
104
  _shuttingDown: boolean;
98
105
  _shutdownPromise: Promise<void> | null;
99
- _blockchainFetchInterval: any;
106
+ _blockchainFetchInterval: ReturnType<typeof setInterval> | null;
100
107
  _blockchainFetchInFlight: number;
101
- _botsConfigPollInterval: any;
108
+ _botsConfigPollInterval: ReturnType<typeof setInterval> | null;
102
109
  _botsConfigPollInFlight: boolean;
103
110
  _marketAdapterWatchdogFingerprint: string | null;
104
111
  _appliedBotConfigFingerprint: string | null;
105
- _appliedBotConfigEntry: any;
112
+ _appliedBotConfigEntry: unknown;
106
113
  _lastBotConfigHintFingerprint: string | null;
107
- _fillsUnsubscribe: any;
108
- _triggerWatcher: any;
109
- _triggerDebounceTimer: any;
110
- _deferredGridResyncTimer: any;
111
- _maintenanceIdleTimer: any;
114
+ _fillsUnsubscribe: (() => Promise<unknown>) | null;
115
+ _triggerWatcher: {
116
+ close?: () => void;
117
+ } | null;
118
+ _triggerDebounceTimer: ReturnType<typeof setTimeout> | null;
119
+ _deferredGridResyncTimer: ReturnType<typeof setTimeout> | null;
120
+ _maintenanceIdleTimer: ReturnType<typeof setTimeout> | null;
112
121
  _mainLoopActive: boolean;
113
- _mainLoopPromise: any;
114
- _creditRuntime: any;
115
- _creditWatchdogInterval: any;
122
+ _mainLoopPromise: Promise<unknown> | null;
123
+ _creditRuntime: CreditRuntimeLike | null;
124
+ _creditWatchdogInterval: ReturnType<typeof setInterval> | null;
116
125
  _batchInFlight: number;
117
126
  _cowBroadcastInFlight: boolean;
118
127
  _recoverySyncInFlight: number;
119
128
  _deferredFillsPending: boolean;
120
- _postRecoveryRebalanceTimer: any;
121
- _deferredFillRetryTimer: any;
129
+ _postRecoveryRebalanceTimer: ReturnType<typeof setTimeout> | null;
130
+ _deferredFillRetryTimer: ReturnType<typeof setTimeout> | null;
122
131
  _lastTargetedDriftSyncAt: number;
123
132
  _lightweightSyncCheckAt: number;
133
+ _lastUncertainResyncAt: number;
134
+ _lastResolvedPollIntervalMs: number;
135
+ _fillBroadcastDeferSince: number;
136
+ _fillBroadcastDeferRegionAt: number;
137
+ _fillTotalsParkedFills: IncomingFill[];
138
+ _fillTotalsRetryTimer: ReturnType<typeof setTimeout> | null;
139
+ _fillTotalsRetryDelayMs: number;
124
140
  _targetedDriftSyncCooldownMs: number;
125
141
  _maintenanceCooldownCycles: number;
126
142
  _lastGridActivityAt: number;
127
143
  _currentCycleId: number;
128
144
  _consecutiveConsumeFailures: number;
129
145
  _consumeFailureFirstAt: number;
130
- _reconnectUnregister: any;
131
- _credentialRecoveryDeferredTimer: any;
132
- _structuralGridResyncTimer: any;
146
+ _reconnectUnregister: (() => void) | null;
147
+ _credentialRecoveryDeferredTimer: ReturnType<typeof setTimeout> | null;
148
+ _structuralGridResyncTimer: ReturnType<typeof setTimeout> | null;
133
149
  _structuralGridResyncRunning: number;
134
- _dustHealthCheckTimer: any;
150
+ _dustHealthCheckTimer: ReturnType<typeof setInterval> | null;
135
151
  _lastBroadcastHeartbeatAt: number | undefined;
136
152
  _lastDeferredDustCount: number;
137
153
  _currentBatchId: string | number | null | undefined;
154
+ assets: AssetPair | null;
155
+ botKey: string;
156
+ name: string;
157
+ _blockchainFetchIntervalMin: number;
158
+ _deferredFillRetryDelayMs: number;
159
+ _deferredFillRetryWaits: number;
160
+ _fillTotalsRetryAttempt: number;
161
+ _gridLockHoldWarnAt: number;
162
+ _gridModule: unknown;
163
+ _gridPriceInvariantRejectStreak: Map<string, number>;
164
+ _gridReconcileModule: unknown;
165
+ _lastDeferredHoldResyncAt: number;
166
+ _lastGridPriceInvariantResyncAt: number;
167
+ _lastHeldChainOrderSignature: string | null;
168
+ _lastHeldChainOrderSignatureSince: number;
169
+ _lastHeldChainOrderWarnAt: number;
170
+ _lastSpreadStaleResyncAt: number;
171
+ _marketAdapterWatchdogInFlight: boolean;
172
+ _outOfSpreadSince: number;
173
+ _outOfSpreadStaleWarned: boolean;
174
+ _postRecoveryRebalanceDefers: number;
175
+ _skipEmptyReadConfirmDelay: boolean;
176
+ _spreadFundsExhausted: boolean;
177
+ _strandedHoldSince: Map<string, number>;
178
+ _structuralGridResyncDeferCount: number;
179
+ _structuralGridResyncDeferStartedAt: number;
180
+ _testPollIntervalMs: number;
181
+ _getPm2ProcessNames: (...args: unknown[]) => Promise<string[]>;
182
+ _listenForFillsHook: (...args: unknown[]) => unknown;
183
+ _loadBotsConfigSnapshot: (...args: unknown[]) => unknown;
184
+ _readOpenOrdersHook: (...args: unknown[]) => unknown;
185
+ _startMarketAdapterPm2: (...args: unknown[]) => unknown;
186
+ _stopMarketAdapterPm2: (...args: unknown[]) => unknown;
187
+ _submitCancelOrder: (...args: unknown[]) => unknown;
188
+ _syncMarketAdapterHook: (...args: unknown[]) => unknown;
138
189
  /**
139
190
  * Create a new DEXBot instance
140
191
  * @param {Object} config - Bot configuration from profiles/bots.json
141
192
  * @param {Object} options - Optional settings
142
193
  * @param {string} options.logPrefix - Prefix for console logs (e.g., "[bot.js]")
143
194
  */
144
- constructor(config: any, options?: {
195
+ constructor(config: GridConfig, options?: {
145
196
  logPrefix?: string;
146
197
  });
147
198
  /**
@@ -151,20 +202,20 @@ declare class DEXBot {
151
202
  * @throws {Error} If critical validation fails
152
203
  * @private
153
204
  */
154
- _validateStartupConfig(config: any): void;
205
+ _validateStartupConfig(config: Record<string, unknown>): void;
155
206
  /**
156
207
  * Log a message to the console with the bot's prefix.
157
208
  * @param {string} msg - The message to log.
158
209
  * @param {string} [level='info'] - The log level ('debug', 'info', 'warn', 'error').
159
210
  * @private
160
211
  */
161
- _log(msg: any, level?: any): void;
212
+ _log(msg: unknown, level?: string): void;
162
213
  /**
163
214
  * Log a warning message to the console with the bot's prefix.
164
215
  * @param {string} msg - The message to log.
165
216
  * @private
166
217
  */
167
- _warn(msg: any): void;
218
+ _warn(msg: unknown): void;
168
219
  /**
169
220
  * Persist the grid and trigger immediate recovery if validation fails.
170
221
  * Used during startup to ensure bot begins in a stable state.
@@ -184,30 +235,30 @@ declare class DEXBot {
184
235
  * @returns {{incomingFillQueueLength: number, shadowLocks: number, batchInFlight: boolean, recoveryInFlight: boolean, broadcasting: boolean}}
185
236
  */
186
237
  _getPipelineSignals(): {
187
- incomingFillQueueLength: any;
188
- shadowLocks: any;
238
+ incomingFillQueueLength: number;
239
+ shadowLocks: number;
189
240
  batchInFlight: boolean;
190
241
  recoveryInFlight: boolean;
191
- broadcasting: any;
242
+ broadcasting: boolean;
192
243
  };
193
244
  /**
194
245
  * Mark that grid activity occurred (updates idle timer).
195
246
  * @param {string} [reason='activity'] - Reason for activity
196
247
  * @returns {void}
197
248
  */
198
- _markGridActivity(reason?: any): void;
249
+ _markGridActivity(reason?: string): void;
199
250
  /**
200
251
  * Trigger a full state recovery sync (fetch chain + sync from open orders + persist).
201
252
  * @param {string} [reason='state recovery sync'] - Reason for recovery
202
253
  * @returns {Promise<void>}
203
254
  */
204
- _triggerStateRecoverySync(reason?: any): Promise<void>;
255
+ _triggerStateRecoverySync(reason?: string): Promise<void>;
205
256
  /**
206
257
  * Abort the current flow if an illegal state signal was raised.
207
258
  * @param {string} flowContext - Description of the flow being aborted
208
259
  * @returns {Promise<boolean>} True if flow was aborted
209
260
  */
210
- _abortFlowIfIllegalState(flowContext: any): Promise<boolean>;
261
+ _abortFlowIfIllegalState(flowContext: string): Promise<boolean>;
211
262
  /**
212
263
  * Handle a hard abort from batch processing due to illegal state or accounting failure.
213
264
  * @param {Error} err - The error that triggered the abort
@@ -215,7 +266,7 @@ declare class DEXBot {
215
266
  * @param {number} [opsCount=0] - Number of operations in the batch
216
267
  * @returns {Promise<Object>} Abort result object
217
268
  */
218
- _handleBatchHardAbort(err: any, phase?: any, opsCount?: any): Promise<{
269
+ _handleBatchHardAbort(err: unknown, phase?: string, opsCount?: number): Promise<{
219
270
  abortedForAccountingFailure: boolean;
220
271
  executed: boolean;
221
272
  hadRotation: boolean;
@@ -230,14 +281,14 @@ declare class DEXBot {
230
281
  * @param {string} [context='recoverable-grid-update'] - Context label for logging
231
282
  * @returns {Promise<number>} Number of updates applied
232
283
  */
233
- _applyRecoverableGridUpdates(updates: any, context?: any): Promise<number>;
284
+ _applyRecoverableGridUpdates(updates: unknown[], context?: string): Promise<number>;
234
285
  /**
235
286
  * Recover from explicit stale order errors by virtualizing affected grid slots.
236
287
  * @param {Set<string>|string[]} staleOrderIds - Set or array of stale chain order IDs
237
288
  * @param {string} [reason='stale order cleanup'] - Reason for cleanup
238
289
  * @returns {Promise<{executed: boolean, hadRotation: boolean, stale: boolean, recoveredByVirtualization?: boolean}>}
239
290
  */
240
- _recoverExplicitStaleOrders(staleOrderIds: any, reason?: any): Promise<{
291
+ _recoverExplicitStaleOrders(staleOrderIds: unknown, reason?: string): Promise<{
241
292
  executed: boolean;
242
293
  hadRotation: boolean;
243
294
  stale: boolean;
@@ -253,7 +304,7 @@ declare class DEXBot {
253
304
  * @param {Error} err - The size drift error
254
305
  * @returns {Promise<{executed: boolean, hadRotation: boolean, recoveredBySync: boolean, reason: string}>}
255
306
  */
256
- _recoverBatchSizeDrift(err: any, opContexts?: any): Promise<{
307
+ _recoverBatchSizeDrift(err: unknown, opContexts?: unknown[]): Promise<{
257
308
  executed: boolean;
258
309
  hadRotation: boolean;
259
310
  recoveredBySync: boolean;
@@ -291,7 +342,7 @@ declare class DEXBot {
291
342
  * @param {'startup'|'recovery'} context - Controls log prefix.
292
343
  * @returns {Promise<boolean>} True if the snapshot was rejected (cleared).
293
344
  */
294
- _rejectCorruptedGridSnapshot(context: any): Promise<boolean>;
345
+ _rejectCorruptedGridSnapshot(context: string): Promise<boolean>;
295
346
  /**
296
347
  * Attempt to repair size-drift for specific order IDs by reading their
297
348
  * current on-chain state and correcting the local grid directly.
@@ -299,7 +350,7 @@ declare class DEXBot {
299
350
  * @param {string[]} orderIds
300
351
  * @returns {Promise<boolean>} True if all affected orders were repaired
301
352
  */
302
- _targetedOrderRepair(orderIds: any): Promise<boolean>;
353
+ _targetedOrderRepair(orderIds: string[]): Promise<boolean>;
303
354
  /**
304
355
  * Initialize bot state from storage and blockchain.
305
356
  * Consolidates common initialization logic for start() and startWithPrivateKey().
@@ -307,13 +358,13 @@ declare class DEXBot {
307
358
  * @private
308
359
  */
309
360
  _initializeStartupState(): Promise<{
310
- persistedGrid: any;
311
- persistedBtsFeesOwed: any;
312
- persistedBoundaryIdx: any;
313
- persistedBtsBalance: any;
314
- persistedRecentFillKeys: any;
315
- persistedGenesis: any;
316
- persistedGapEvacStreaks: any;
361
+ persistedGrid: unknown[] | null;
362
+ persistedBtsFeesOwed: unknown;
363
+ persistedBoundaryIdx: number | null;
364
+ persistedBtsBalance: unknown;
365
+ persistedRecentFillKeys: unknown;
366
+ persistedGenesis: {} | null;
367
+ persistedGapEvacStreaks: {} | null;
317
368
  }>;
318
369
  /**
319
370
  * Wire processed fill tracking into the manager.
@@ -326,7 +377,7 @@ declare class DEXBot {
326
377
  * @param {Object} [options={}] - Flush options
327
378
  * @returns {Promise<void>}
328
379
  */
329
- _flushProcessedFillPersistence(reason?: any, options?: any): Promise<void>;
380
+ _flushProcessedFillPersistence(reason?: string, options?: Record<string, unknown>): Promise<void>;
330
381
  /**
331
382
  * Flush persistence for specific fill keys.
332
383
  * @param {Set<string>|string[]} fillKeys - Fill keys to persist
@@ -334,18 +385,18 @@ declare class DEXBot {
334
385
  * @param {Object} [options={}] - Flush options
335
386
  * @returns {Promise<void>}
336
387
  */
337
- _flushProcessedFillPersistenceForKeys(fillKeys: any, reason?: any, options?: any): Promise<void>;
388
+ _flushProcessedFillPersistenceForKeys(fillKeys: string[] | Set<string>, reason?: string, options?: Record<string, unknown>): Promise<void>;
338
389
  /**
339
390
  * Build a fallback deduplication key for an orphan fill (when standard keys are unavailable).
340
391
  * @param {Object} fill - Fill event object
341
392
  * @returns {string|null} Fallback key or null
342
393
  */
343
- _buildOrphanFillFallbackKey(fill: any): string | null;
344
- _isNewFillKey(fillKey: any, processedFillKeys: any, label?: any, orderId?: any): boolean;
394
+ _buildOrphanFillFallbackKey(fill: FillLike): string | null;
395
+ _isNewFillKey(fillKey: string, processedFillKeys: Set<string>, label?: string, orderId?: string): boolean;
345
396
  /**
346
397
  * Apply replay-safe fill accounting for tracked fills (those with a valid grid order).
347
398
  * @param {Object} fill - Fill event object
348
- * @param {any} fillOp - Fill operation data
399
+ * @param {unknown} fillOp - Fill operation data
349
400
  * @param {Object} [options={}]
350
401
  * @param {string} [options.context]
351
402
  * @param {Object} [options.logger]
@@ -353,11 +404,11 @@ declare class DEXBot {
353
404
  * @param {string} [options.persistenceMode='batched']
354
405
  * @returns {Promise<any>}
355
406
  */
356
- _applyReplaySafeTrackedFillAccounting(fill: any, fillOp: any, { context, logger, replayMessage, persistenceMode }?: {
407
+ _applyReplaySafeTrackedFillAccounting(fill: unknown, fillOp: FillOpLike, { context, logger, replayMessage, persistenceMode }?: {
357
408
  context?: string;
358
- logger?: any;
359
- replayMessage?: any;
360
- persistenceMode?: any;
409
+ logger?: Partial<ManagerLogger>;
410
+ replayMessage?: ReplayMessageFn;
411
+ persistenceMode?: string;
361
412
  }): Promise<{
362
413
  status: string;
363
414
  fillKey: any;
@@ -371,13 +422,13 @@ declare class DEXBot {
371
422
  } | {
372
423
  status: string;
373
424
  fillKey: any;
374
- error: any;
425
+ error: unknown;
375
426
  usedFallbackKey?: undefined;
376
427
  }>;
377
428
  /**
378
429
  * Apply replay-safe fill accounting for orphan fills (grid order not found).
379
430
  * @param {Object} fill - Fill event object
380
- * @param {any} fillOp - Fill operation data
431
+ * @param {unknown} fillOp - Fill operation data
381
432
  * @param {Object} [options={}]
382
433
  * @param {string} [options.context]
383
434
  * @param {Object} [options.logger]
@@ -385,11 +436,11 @@ declare class DEXBot {
385
436
  * @param {string} [options.persistenceMode='batched']
386
437
  * @returns {Promise<any>}
387
438
  */
388
- _applyReplaySafeOrphanFillAccounting(fill: any, fillOp: any, { context, logger, replayMessage, persistenceMode }?: {
439
+ _applyReplaySafeOrphanFillAccounting(fill: unknown, fillOp: FillOpLike, { context, logger, replayMessage, persistenceMode }?: {
389
440
  context?: string;
390
- logger?: any;
391
- replayMessage?: any;
392
- persistenceMode?: any;
441
+ logger?: Partial<ManagerLogger>;
442
+ replayMessage?: ReplayMessageFn;
443
+ persistenceMode?: string;
393
444
  }): Promise<{
394
445
  status: string;
395
446
  fillKey: any;
@@ -403,7 +454,7 @@ declare class DEXBot {
403
454
  } | {
404
455
  status: string;
405
456
  fillKey: any;
406
- error: any;
457
+ error: unknown;
407
458
  usedFallbackKey?: undefined;
408
459
  }>;
409
460
  /**
@@ -411,7 +462,7 @@ declare class DEXBot {
411
462
  * @param {string} [context='runtime'] - Context label for logging
412
463
  * @returns {any|null}
413
464
  */
414
- _refreshDynamicWeightDistribution(context?: any): {
465
+ _refreshDynamicWeightDistribution(context?: string): {
415
466
  applied: boolean;
416
467
  source: string;
417
468
  weightDistribution: any;
@@ -420,7 +471,7 @@ declare class DEXBot {
420
471
  applied: boolean;
421
472
  source: string;
422
473
  weightDistribution: any;
423
- snapshotUpdatedAt: any;
474
+ snapshotUpdatedAt: {} | null;
424
475
  };
425
476
  /**
426
477
  * Finalize the bot startup after account and initial grid sync are complete.
@@ -428,7 +479,7 @@ declare class DEXBot {
428
479
  * @param {Object} startupState - The startup state from _initializeStartupState.
429
480
  * @private
430
481
  */
431
- _finishStartupSequence(startupState: any): Promise<void>;
482
+ _finishStartupSequence(startupState: Parameters<typeof DexbotStartupRuntime.finishStartupSequence>[1]): Promise<void>;
432
483
  /**
433
484
  * Create the fill callback for listenForFills.
434
485
  * Separated from start() to allow deferred activation after startup completes.
@@ -436,23 +487,23 @@ declare class DEXBot {
436
487
  * @returns {Function} Async callback for processing fills
437
488
  * @private
438
489
  */
439
- _createFillCallback(chainOrders: any): (fills: any) => Promise<void>;
490
+ _createFillCallback(chainOrders: typeof import('./chain_orders.js')): (fills: IncomingFill[]) => Promise<void>;
440
491
  /**
441
492
  * Read open orders from chain, sync with local state, and process any fills found.
442
493
  * Shared helper used by post-reset spread check and targeted drift reconciliation.
443
494
  * @param {string} tag - Context label for logging
444
495
  * @returns {Promise<{syncResult: Object|null, aborted: boolean, hasUnmatched: number, openOrders: Array|null}>}
445
496
  */
446
- _syncOpenOrdersAndProcessFills(tag: any): Promise<{
497
+ _syncOpenOrdersAndProcessFills(tag: string): Promise<{
447
498
  syncResult: null;
448
499
  aborted: boolean;
449
500
  hasUnmatched: number;
450
501
  openOrders: null;
451
502
  } | {
452
- syncResult: any;
503
+ syncResult: import("./types.js").SyncResult;
453
504
  aborted: boolean;
454
- hasUnmatched: any;
455
- openOrders: any[];
505
+ hasUnmatched: number;
506
+ openOrders: import("./types.js").ChainOrder[];
456
507
  }>;
457
508
  /**
458
509
  * Schedule the fill-consumer restart after the failure budget
@@ -462,7 +513,7 @@ declare class DEXBot {
462
513
  * @param {Object} chainOrders - Chain orders module for blockchain operations
463
514
  * @private
464
515
  */
465
- _scheduleFillConsumerRestart(chainOrders: any): void;
516
+ _scheduleFillConsumerRestart(chainOrders: typeof import('./chain_orders.js')): void;
466
517
  /**
467
518
  * Consume queued fills from incomingFillQueue and rebalance.
468
519
  *
@@ -476,7 +527,7 @@ declare class DEXBot {
476
527
  * @param {Object} chainOrders - Chain orders module for blockchain operations
477
528
  * @private
478
529
  */
479
- _consumeFillQueue(chainOrders: any): Promise<void>;
530
+ _consumeFillQueue(chainOrders: typeof import('./chain_orders.js')): Promise<void>;
480
531
  /**
481
532
  * Process fills during bootstrap phase using the standard fill pipeline.
482
533
  *
@@ -497,20 +548,20 @@ declare class DEXBot {
497
548
  * @param {Object} chainOrders - Chain orders instance for broadcasting
498
549
  * @returns {Promise<void>}
499
550
  */
500
- _processFillsWithBootstrapMode(chainOrders: any): Promise<void>;
551
+ _processFillsWithBootstrapMode(chainOrders: typeof import('./chain_orders.js')): Promise<void>;
501
552
  /**
502
553
  * Set up account identifier and configure global context.
503
554
  * @param {string} accountName - The name of the account to set up
504
555
  * @private
505
556
  */
506
- _setupAccountContext(accountName: any): Promise<void>;
557
+ _setupAccountContext(accountName: string): Promise<void>;
507
558
  /**
508
559
  * Initialize the bot by connecting to BitShares and setting up the account.
509
560
  * @param {string|Object|Buffer} [vaultSecret=null] - The unlock secret for authentication.
510
561
  * @returns {Promise<void>}
511
562
  * @throws {Error} If initialization fails or preferredAccount is missing.
512
563
  */
513
- initialize(vaultSecret?: any): Promise<void>;
564
+ initialize(vaultSecret?: string | null): Promise<void>;
514
565
  /**
515
566
  * Places initial orders on the blockchain.
516
567
  * @returns {Promise<void>}
@@ -521,13 +572,13 @@ declare class DEXBot {
521
572
  * @param {Array<Object>} orders - Array of order objects
522
573
  * @returns {Array<Array<Object>>} Grouped order arrays
523
574
  */
524
- _buildOutsideInPairGroupsForOrders(orders: any): any;
575
+ _buildOutsideInPairGroupsForOrders(orders: unknown[]): unknown[][];
525
576
  /**
526
577
  * Build outside-in pair groups for create entry contexts.
527
578
  * @param {Array<Object>} createEntries - Array of create entry objects with context.order
528
579
  * @returns {Array<Array<Object>>} Grouped entry arrays
529
580
  */
530
- _buildOutsideInPairGroupsForCreateEntries(createEntries: any): any;
581
+ _buildOutsideInPairGroupsForCreateEntries(createEntries: unknown[]): unknown[][];
531
582
  /**
532
583
  * Resolve the fill/broadcast batch size from the grid gap-slot count.
533
584
  *
@@ -578,14 +629,14 @@ declare class DEXBot {
578
629
  * @param {Array<{index:number, ctx:Object}>} missingCreateResults - Missing CREATE results.
579
630
  * @returns {void}
580
631
  */
581
- _markMissingCreateResultsAsStructuralBlocker(missingCreateResults: any): void;
632
+ _markMissingCreateResultsAsStructuralBlocker(missingCreateResults: unknown): void;
582
633
  /**
583
634
  * Format an unmatched chain order/blocker for COW logs.
584
635
  *
585
636
  * @param {Object} order - Unmatched chain order or structural blocker.
586
637
  * @returns {string} Compact human-readable diagnostic.
587
638
  */
588
- _formatUnmatchedChainOrderForLog(order: any): any;
639
+ _formatUnmatchedChainOrderForLog(order: unknown): string;
589
640
  /**
590
641
  * Record a pending CREATE broadcast on the manager.
591
642
  *
@@ -606,7 +657,7 @@ declare class DEXBot {
606
657
  * @param {Object} entry.finalInts - { amountToSell, minToReceive, ... } blockchain integers
607
658
  * @returns {void}
608
659
  */
609
- _recordPendingBroadcast(entry: any): string | null;
660
+ _recordPendingBroadcast(entry: unknown): string | null;
610
661
  /**
611
662
  * Clear the pending-broadcast cache.
612
663
  *
@@ -631,7 +682,7 @@ declare class DEXBot {
631
682
  * @param {Object} planned - { sell, receive, orderType } integers from the planned op
632
683
  * @returns {Object|null} Matching chain order, or null
633
684
  */
634
- _findChainOrderForSlot(chainOrders: any, slotId: any, planned: any): any;
685
+ _findChainOrderForSlot(chainOrders: ChainOrderLike[], slotId: string, planned: Parameters<typeof cowRuntime.findChainOrderForSlot>[3]): ChainOrderLike | null;
635
686
  /**
636
687
  * Reconcile a broadcast whose chain state is unknown.
637
688
  *
@@ -658,7 +709,12 @@ declare class DEXBot {
658
709
  * @param {Array<Object>} opContexts - Original opContexts from the failed batch
659
710
  * @returns {Promise<Object>} Result object compatible with batch return shape
660
711
  */
661
- _reconcileAfterUncertainBroadcast(err: any, opContexts: any, options?: Record<string, any>): Promise<any>;
712
+ _reconcileAfterUncertainBroadcast(err: unknown, opContexts: OpPhase[], options?: UnknownRecord): Promise<UnknownRecord | {
713
+ executed: boolean;
714
+ hadRotation: boolean;
715
+ uncertain: boolean;
716
+ ambiguousRead: boolean;
717
+ }>;
662
718
  /**
663
719
  * Execute operations with retry on BroadcastUncertainError.
664
720
  * The daemon already retries internally against a 25s deadline. If it
@@ -672,9 +728,9 @@ declare class DEXBot {
672
728
  * execution where earlier groups already committed). Re-broadcasting
673
729
  * the full operations array would duplicate those creates on chain.
674
730
  */
675
- _executeWithRetryOnUncertain(operations: any, opContexts: any): Promise<{
676
- result: any;
677
- opContexts: any;
731
+ _executeWithRetryOnUncertain(operations: unknown[], opContexts: OpPhase[]): Promise<{
732
+ result: unknown;
733
+ opContexts: OpPhase[];
678
734
  }>;
679
735
  /**
680
736
  * Execute operations with retry-on-uncertain semantics AND a per-broadcast
@@ -685,9 +741,9 @@ declare class DEXBot {
685
741
  * @param {Array<Object>} opContexts - Array of operation context metadata (1:1 with operations)
686
742
  * @returns {Promise<{result: Object, opContexts: Array}>} Execution result with contexts
687
743
  */
688
- _executeChunkedWithRetryOnUncertain(operations: any, opContexts: any): Promise<{
689
- result: any;
690
- opContexts: any;
744
+ _executeChunkedWithRetryOnUncertain(operations: unknown[], opContexts: OpPhase[]): Promise<{
745
+ result: unknown;
746
+ opContexts: OpPhase[];
691
747
  }>;
692
748
  /**
693
749
  * Execute a batch of order operations if the rebalance result has executable actions.
@@ -695,7 +751,7 @@ declare class DEXBot {
695
751
  * @param {string} [contextLabel='rebalance'] - Context label for logging
696
752
  * @returns {Promise<Object>} Batch execution result
697
753
  */
698
- _executeBatchIfNeeded(rebalanceResult: any, contextLabel?: any): Promise<any>;
754
+ _executeBatchIfNeeded(rebalanceResult: unknown, contextLabel?: unknown): Promise<unknown>;
699
755
  /**
700
756
  * Process filled orders in (gap-slot + 1)-sized batches per _getGapSlotBatchSize().
701
757
  * Each chunk triggers its own processFilledOrders → COW plan → broadcast cycle.
@@ -706,13 +762,7 @@ declare class DEXBot {
706
762
  * @param {Object} [options={}] - Passed through to processFilledOrders
707
763
  * @returns {{aborted: boolean}}
708
764
  */
709
- _processFillsWithBatching(fills: any, excl: any, contextLabel: any, options?: any): Promise<{
710
- aborted: boolean;
711
- deferred?: undefined;
712
- } | {
713
- aborted: boolean;
714
- deferred: boolean;
715
- }>;
765
+ _processFillsWithBatching(fills: unknown, excl: unknown, contextLabel: unknown, options?: UnknownRecord): Promise<FillBatchResult>;
716
766
  /**
717
767
  * Check if the bot requires credential daemon for write operations.
718
768
  * @returns {boolean}
@@ -723,26 +773,26 @@ declare class DEXBot {
723
773
  * @param {string} reason - Reason for suspension
724
774
  * @returns {void}
725
775
  */
726
- _suspendGridPersistenceForCredentialOutage(reason: any): void;
776
+ _suspendGridPersistenceForCredentialOutage(reason: unknown): void;
727
777
  /**
728
778
  * Resume grid persistence after credential daemon recovery.
729
779
  * @param {string} reason - Reason for resuming
730
780
  * @returns {void}
731
781
  */
732
- _resumeGridPersistenceAfterCredentialRecovery(reason: any): void;
782
+ _resumeGridPersistenceAfterCredentialRecovery(reason: unknown): void;
733
783
  /**
734
784
  * Ensure the credential daemon is writable before broadcasting operations.
735
785
  * @param {string} [contextLabel='write batch'] - Context label for logging
736
786
  * @returns {Promise<void>}
737
787
  * @throws {Error} With code CREDENTIAL_DAEMON_UNAVAILABLE if daemon is down
738
788
  */
739
- _ensureCredentialDaemonWritable(contextLabel?: any): Promise<void>;
789
+ _ensureCredentialDaemonWritable(contextLabel?: unknown): Promise<void>;
740
790
  /**
741
791
  * Check if an error is related to credential daemon unavailability.
742
792
  * @param {Error|*} err - Error to check
743
793
  * @returns {boolean}
744
794
  */
745
- _isCredentialDaemonError(err: any): boolean;
795
+ _isCredentialDaemonError(err: unknown): boolean;
746
796
  /**
747
797
  * Run state recovery after credential daemon is restored.
748
798
  * @returns {Promise<void>}
@@ -764,27 +814,20 @@ declare class DEXBot {
764
814
  * @param {Object} rebalanceResult - COW result containing workingGrid + actions.
765
815
  * @returns {Promise<Object>} The batch result.
766
816
  */
767
- updateOrdersOnChainBatch(rebalanceResult: any): Promise<any>;
817
+ updateOrdersOnChainBatch(rebalanceResult: unknown): Promise<unknown>;
768
818
  /**
769
819
  * Converts simple plan payloads (place/update/rotate/cancel) into a COW batch.
770
820
  * Used by spread/divergence maintenance and bootstrap helpers.
771
821
  * @param {Object|Array} plan - Plan object or array of ordersToPlace
772
822
  * @returns {Promise<Object>} Batch execution result
773
823
  */
774
- updateOrdersOnChainPlan(plan: any): Promise<any>;
824
+ updateOrdersOnChainPlan(plan: UnknownRecord): Promise<UnknownRecord>;
775
825
  /**
776
826
  * Build a COW result object (workingGrid + actions) from a simple plan.
777
827
  * @param {Object|Array} plan - Plan object or array of ordersToPlace
778
828
  * @returns {{workingGrid: any, workingIndexes: Object, workingBoundary: number, actions: Array}}
779
829
  */
780
- _buildCowResultFromPlan(plan: any): {
781
- refillSlotIds?: any;
782
- workingGrid: any;
783
- workingIndexes: any;
784
- workingBoundary: any;
785
- actions: any[];
786
- origin: any;
787
- };
830
+ _buildCowResultFromPlan(plan: UnknownRecord): CowResult;
788
831
  /**
789
832
  * COW broadcast: Execute blockchain operations and commit working grid on success.
790
833
  * Master grid is ONLY updated after successful blockchain confirmation.
@@ -792,12 +835,8 @@ declare class DEXBot {
792
835
  * @returns {Promise<Object>} The batch result.
793
836
  * @private
794
837
  */
795
- _updateOrdersOnChainBatchCOW(cowResult: any, options?: any): Promise<any>;
796
- _processBatchResults(result: any, opContexts: any): Promise<{
797
- executed: boolean;
798
- hadRotation: boolean;
799
- updateOperationCount: number;
800
- }>;
838
+ _updateOrdersOnChainBatchCOW(cowResult: CowResult, options?: UnknownRecord): Promise<UnknownRecord>;
839
+ _processBatchResults(result: UnknownRecord, opContexts: OpPhase[]): Promise<UnknownRecord>;
801
840
  /**
802
841
  * Perform grid recalculation triggered by trigger file.
803
842
  * Reloads config from disk, recalculates grid, resets funds, and removes trigger file.
@@ -806,7 +845,7 @@ declare class DEXBot {
806
845
  * @returns {Promise<boolean>} True if resync succeeded
807
846
  * @private
808
847
  */
809
- _performGridResync(options?: any): Promise<boolean>;
848
+ _performGridResync(options?: UnknownRecord): Promise<unknown>;
810
849
  /**
811
850
  * Handle any pending trigger file reset at startup.
812
851
  * This is called FIRST during startup before any grid operations.
@@ -825,14 +864,14 @@ declare class DEXBot {
825
864
  * @param {string|Object|Buffer} [vaultSecret=null] - The unlock secret.
826
865
  * @returns {Promise<void>}
827
866
  */
828
- start(vaultSecret?: any): Promise<void>;
867
+ start(vaultSecret?: unknown): Promise<void>;
829
868
  /**
830
869
  * Start bot with a pre-decrypted private key.
831
870
  * Alternative to start(vaultSecret) when the signing secret is already available.
832
871
  * @param {string|Object} privateKey - Pre-decrypted private key or daemon signing token
833
872
  * @returns {Promise<void>}
834
873
  */
835
- startWithPrivateKey(privateKey: any): Promise<void>;
874
+ startWithPrivateKey(privateKey: unknown): Promise<void>;
836
875
  /**
837
876
  * Common startup sequence logic shared between start() and startWithPrivateKey().
838
877
  * @private
@@ -883,17 +922,17 @@ declare class DEXBot {
883
922
  * @private
884
923
  */
885
924
  _stopBotsConfigPollInterval(): void;
886
- _releaseMarketAdapterRuntime(context?: any): Promise<any>;
925
+ _releaseMarketAdapterRuntime(context?: unknown): Promise<any>;
887
926
  /**
888
927
  * Get or create the credit runtime for debt policy management.
889
928
  * @returns {import('./credit_runtime.js').CreditRuntime|null}
890
929
  */
891
- _getCreditRuntime(): any;
930
+ _getCreditRuntime(): CreditRuntimeLike | null;
892
931
  /**
893
932
  * Set up the credit runtime by loading its persisted state.
894
933
  * @returns {Promise<import('./credit_runtime.js').CreditRuntime|null>}
895
934
  */
896
- _setupCreditRuntime(): Promise<any>;
935
+ _setupCreditRuntime(): Promise<CreditRuntimeLike | null>;
897
936
  /**
898
937
  * Refresh credit runtime state from chain and sync internal tracking.
899
938
  * @returns {Promise<void>}
@@ -905,7 +944,7 @@ declare class DEXBot {
905
944
  * @param {Object} [options={}] - Maintenance options
906
945
  * @returns {Promise<*>} Maintenance result from runtime
907
946
  */
908
- _runCreditRuntimeMaintenance(context?: any, options?: any): Promise<any>;
947
+ _runCreditRuntimeMaintenance(context?: unknown, options?: UnknownRecord): Promise<unknown>;
909
948
  /**
910
949
  * Start the credit deal watchdog interval.
911
950
  * @returns {void}
@@ -916,10 +955,7 @@ declare class DEXBot {
916
955
  * @returns {void}
917
956
  */
918
957
  _stopCreditWatchdogInterval(): void;
919
- requestGridReset(reason?: any, options?: {
920
- refreshCenterPrice?: boolean;
921
- [key: string]: any;
922
- }): Promise<any>;
958
+ requestGridReset(reason?: unknown, options?: UnknownRecord): Promise<unknown>;
923
959
  _wireStructuralGridResyncRequest(): void;
924
960
  /**
925
961
  * Wire the manager's broadcast-region-end hook to drain the deferred fill
@@ -937,7 +973,24 @@ declare class DEXBot {
937
973
  * Get current metrics for monitoring and debugging.
938
974
  * @returns {Object} Metrics snapshot
939
975
  */
940
- getMetrics(): any;
976
+ getMetrics(): {
977
+ queueDepth: number;
978
+ fillProcessingLockActive: boolean;
979
+ divergenceLockActive: boolean;
980
+ shadowLocksActive: number;
981
+ recoveryExhaustedAt: number | null;
982
+ recentFillsTracked: number;
983
+ unmatchedChainOrders: number;
984
+ heldChainOrders: number;
985
+ blockingChainOrders: number;
986
+ fillsProcessed: number;
987
+ batchesExecuted: number;
988
+ fillProcessingTimeMs: number;
989
+ lockContentionEvents: number;
990
+ maxQueueDepth: number;
991
+ gridLockContention: number;
992
+ fundRecalcCount: number;
993
+ };
941
994
  /**
942
995
  * Execute grid maintenance checks in strict order with pipeline consensus.
943
996
  *
@@ -969,7 +1022,7 @@ declare class DEXBot {
969
1022
  * @param {Object} context - Maintenance context for logging.
970
1023
  * @private
971
1024
  */
972
- _executeMaintenanceLogic(context: any): Promise<void>;
1025
+ _executeMaintenanceLogic(context: unknown): Promise<void>;
973
1026
  /**
974
1027
  * Cancel dust partial orders immediately — no maps, no timers, no delay.
975
1028
  * Each dust order is cancelled on chain and its slot rotated through the
@@ -978,13 +1031,16 @@ declare class DEXBot {
978
1031
  * @returns {Promise<{cancelledCount: number, batchResult: {aborted: boolean}|null}>}
979
1032
  * @private
980
1033
  */
981
- _cancelDustOrders({ buy: buyDust, sell: sellDust }?: any): Promise<{
1034
+ _cancelDustOrders({ buy: buyDust, sell: sellDust }?: {
1035
+ buy?: unknown[];
1036
+ sell?: unknown[];
1037
+ }): Promise<{
982
1038
  cancelledCount: number;
983
1039
  batchResult: null;
984
1040
  } | {
985
1041
  cancelledCount: number;
986
1042
  batchResult: {
987
- aborted: any;
1043
+ aborted: boolean | undefined;
988
1044
  };
989
1045
  }>;
990
1046
  /**
@@ -1027,7 +1083,7 @@ declare class DEXBot {
1027
1083
  * @param {Object} options - Maintenance options
1028
1084
  * @private
1029
1085
  */
1030
- _runGridMaintenance(context?: any, options?: any): Promise<void>;
1086
+ _runGridMaintenance(context?: unknown, options?: UnknownRecord): Promise<unknown>;
1031
1087
  /**
1032
1088
  * Gracefully shutdown the bot.
1033
1089
  * Waits for current fill processing to complete, persists state, and stops intervals.