dexbot 1.6.11 → 1.6.13

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 (398) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +2 -1
  3. package/analysis/README.md +11 -11
  4. package/analysis/ama_fitting/README.md +5 -3
  5. package/analysis/tradingview/README.md +1 -1
  6. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
  7. package/claw/README.md +1 -0
  8. package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
  9. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  10. package/claw/modules/chain_broadcast.ts +7 -1
  11. package/claw/modules/claw_bridge.ts +0 -3
  12. package/claw/modules/claw_launcher.ts +1 -1
  13. package/claw/modules/claw_skill_md.ts +1 -0
  14. package/claw/modules/launcher_mode_detector.ts +9 -2
  15. package/claw/package.json +3 -3
  16. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  17. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  18. package/claw/tsconfig.json +2 -2
  19. package/dist/analysis/account_resolver.d.ts +1 -1
  20. package/dist/analysis/account_resolver.js +2 -1
  21. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  22. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +3 -21
  23. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  24. package/dist/analysis/ama_fitting/fetch_lp_candles.js +55 -45
  25. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -8
  26. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +45 -24
  27. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +34 -78
  28. package/dist/analysis/analyze_args.d.ts +43 -0
  29. package/dist/analysis/analyze_args.js +61 -0
  30. package/dist/analysis/analyze_dynamic_weight.js +7 -17
  31. package/dist/analysis/analyze_kalman.js +7 -17
  32. package/dist/analysis/analyze_regime.js +7 -17
  33. package/dist/analysis/analyze_regime_windows.js +8 -18
  34. package/dist/analysis/analyze_risk_profile.js +8 -18
  35. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  36. package/dist/analysis/analyze_volatility.js +7 -17
  37. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +221 -28
  38. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +23 -103
  39. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  40. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +32 -150
  41. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
  42. package/dist/analysis/bot_fitting/shared_utils.d.ts +77 -9
  43. package/dist/analysis/bot_fitting/shared_utils.js +125 -9
  44. package/dist/analysis/bot_key_utils.d.ts +18 -10
  45. package/dist/analysis/bot_key_utils.js +7 -4
  46. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  47. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  48. package/dist/analysis/chain_pool.d.ts +3 -1
  49. package/dist/analysis/chart_ui.d.ts +35 -3
  50. package/dist/analysis/chart_ui.js +43 -4
  51. package/dist/analysis/chart_utils.d.ts +5 -5
  52. package/dist/analysis/chart_utils.js +9 -0
  53. package/dist/analysis/fills_cache.d.ts +4 -24
  54. package/dist/analysis/fills_cache.js +3 -84
  55. package/dist/analysis/fills_source.d.ts +33 -3
  56. package/dist/analysis/fills_source.js +83 -13
  57. package/dist/analysis/grid_correction_check.d.ts +2 -24
  58. package/dist/analysis/grid_correction_check.js +27 -69
  59. package/dist/analysis/math_utils.d.ts +91 -6
  60. package/dist/analysis/math_utils.js +119 -7
  61. package/dist/analysis/pnl_report.js +29 -29
  62. package/dist/analysis/price_sources.d.ts +30 -9
  63. package/dist/analysis/price_sources.js +28 -4
  64. package/dist/analysis/resolve_bot_accounts.js +2 -2
  65. package/dist/analysis/resolve_source.d.ts +1 -1
  66. package/dist/analysis/resolve_source.js +31 -10
  67. package/dist/analysis/trade_profitability.d.ts +29 -2
  68. package/dist/analysis/trade_profitability.js +73 -147
  69. package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -8
  70. package/dist/analysis/tradingview/analyze_tradingview.js +7 -6
  71. package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
  72. package/dist/analysis/tradingview/grid_reset_config.js +23 -11
  73. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
  74. package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
  75. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  76. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -34
  77. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
  78. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +26 -84
  79. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  80. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +16 -41
  81. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
  82. package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
  83. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  84. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  85. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  86. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  87. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  88. package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
  89. package/dist/analysis/worker_pool.d.ts +38 -0
  90. package/dist/analysis/worker_pool.js +67 -0
  91. package/dist/credential-daemon.js +34 -20
  92. package/dist/dexbot.js +78 -59
  93. package/dist/market_adapter/ama_signal_runner.js +21 -54
  94. package/dist/market_adapter/candle_utils.d.ts +29 -19
  95. package/dist/market_adapter/candle_utils.js +35 -21
  96. package/dist/market_adapter/cli_args.d.ts +22 -0
  97. package/dist/market_adapter/cli_args.js +30 -0
  98. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  99. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  100. package/dist/market_adapter/core/config_normalizers.js +11 -6
  101. package/dist/market_adapter/core/kibana_candles.d.ts +56 -19
  102. package/dist/market_adapter/core/kibana_candles.js +12 -9
  103. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  104. package/dist/market_adapter/core/kibana_client.js +8 -7
  105. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  106. package/dist/market_adapter/core/market_adapter_service.d.ts +320 -153
  107. package/dist/market_adapter/core/market_adapter_service.js +228 -269
  108. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
  109. package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
  110. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
  111. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
  112. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  113. package/dist/market_adapter/core/strategies/ama.js +2 -4
  114. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  115. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  116. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  117. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  118. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  119. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  120. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
  121. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
  122. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  123. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  124. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  125. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  126. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  127. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  128. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  129. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  130. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  131. package/dist/market_adapter/inputs/fetch_book_data.js +3 -2
  132. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +160 -332
  133. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +50 -8
  134. package/dist/market_adapter/inputs/fetch_lp_data.js +47 -22
  135. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  136. package/dist/market_adapter/inputs/kibana_feed_source.js +26 -41
  137. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  138. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  139. package/dist/market_adapter/inputs/window_cache.d.ts +93 -156
  140. package/dist/market_adapter/inputs/window_cache.js +59 -184
  141. package/dist/market_adapter/interval_utils.d.ts +15 -5
  142. package/dist/market_adapter/interval_utils.js +16 -1
  143. package/dist/market_adapter/log_format.d.ts +6 -6
  144. package/dist/market_adapter/log_format.js +28 -21
  145. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  146. package/dist/market_adapter/lp_chart_core.js +26 -192
  147. package/dist/market_adapter/lp_chart_runner.d.ts +10 -7
  148. package/dist/market_adapter/lp_chart_runner.js +37 -19
  149. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  150. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  151. package/dist/market_adapter/market_adapter.d.ts +94 -32
  152. package/dist/market_adapter/market_adapter.js +94 -120
  153. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  154. package/dist/market_adapter/utils/adapter_client.js +2 -2
  155. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  156. package/dist/market_adapter/utils/chain.d.ts +50 -41
  157. package/dist/market_adapter/utils/chain.js +40 -46
  158. package/dist/market_adapter/utils/data_discovery.d.ts +49 -2
  159. package/dist/market_adapter/utils/data_discovery.js +220 -27
  160. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  161. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  162. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  163. package/dist/market_adapter/utils/file_lock.js +36 -32
  164. package/dist/market_adapter/utils/month_shards.d.ts +84 -0
  165. package/dist/market_adapter/utils/month_shards.js +237 -0
  166. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  167. package/dist/market_adapter/utils/native_history.js +35 -28
  168. package/dist/modules/account_bots.d.ts +578 -21
  169. package/dist/modules/account_bots.js +272 -267
  170. package/dist/modules/account_orders.d.ts +79 -30
  171. package/dist/modules/account_orders.js +60 -64
  172. package/dist/modules/authority_resolver.d.ts +12 -2
  173. package/dist/modules/authority_resolver.js +15 -8
  174. package/dist/modules/bitshares-native/chain_client.d.ts +39 -4
  175. package/dist/modules/bitshares-native/chain_client.js +59 -59
  176. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  177. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  178. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  179. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  180. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  181. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  182. package/dist/modules/bitshares-native/index.d.ts +1 -1
  183. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  184. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  185. package/dist/modules/bitshares-native/resolvers.js +22 -25
  186. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  187. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  188. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  189. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  190. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  191. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  192. package/dist/modules/bitshares-native/serial/types.js +73 -108
  193. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  194. package/dist/modules/bitshares-native/signing_client.js +19 -14
  195. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  196. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  197. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  198. package/dist/modules/bitshares-native/transport.js +5 -4
  199. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  200. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  201. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  202. package/dist/modules/bitshares_client.d.ts +45 -13
  203. package/dist/modules/bitshares_client.js +28 -19
  204. package/dist/modules/bot_defaults.d.ts +8 -16
  205. package/dist/modules/bot_defaults.js +1 -5
  206. package/dist/modules/bot_settings.d.ts +44 -10
  207. package/dist/modules/bot_settings.js +11 -8
  208. package/dist/modules/bots_file_lock.d.ts +6 -6
  209. package/dist/modules/bots_file_lock.js +16 -12
  210. package/dist/modules/broadcast_failure.d.ts +4 -3
  211. package/dist/modules/broadcast_failure.js +5 -4
  212. package/dist/modules/chain_keys.d.ts +42 -40
  213. package/dist/modules/chain_keys.js +53 -45
  214. package/dist/modules/chain_orders.d.ts +94 -60
  215. package/dist/modules/chain_orders.js +81 -118
  216. package/dist/modules/cli_start_onboarding.d.ts +2 -1
  217. package/dist/modules/constants.d.ts +534 -32
  218. package/dist/modules/constants.js +35 -48
  219. package/dist/modules/cr_planner.d.ts +41 -3
  220. package/dist/modules/cr_planner.js +1 -5
  221. package/dist/modules/credential_policy.d.ts +68 -8
  222. package/dist/modules/credential_policy.js +37 -31
  223. package/dist/modules/credential_session_cache.d.ts +2 -2
  224. package/dist/modules/credit_pricing.d.ts +43 -6
  225. package/dist/modules/credit_pricing.js +70 -60
  226. package/dist/modules/credit_runtime.d.ts +283 -118
  227. package/dist/modules/credit_runtime.js +500 -231
  228. package/dist/modules/crypto/browser_provider.js +6 -4
  229. package/dist/modules/crypto/node_provider.js +1 -1
  230. package/dist/modules/crypto/pure_scrypt.js +35 -4
  231. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  232. package/dist/modules/crypto/sync.d.ts +9 -9
  233. package/dist/modules/crypto/sync.js +16 -9
  234. package/dist/modules/daemon_node_health.d.ts +4 -3
  235. package/dist/modules/dexbot_class.d.ts +213 -146
  236. package/dist/modules/dexbot_class.js +183 -86
  237. package/dist/modules/dexbot_cow_runtime.d.ts +160 -87
  238. package/dist/modules/dexbot_cow_runtime.js +302 -234
  239. package/dist/modules/dexbot_credential_client.d.ts +19 -18
  240. package/dist/modules/dexbot_credential_client.js +1 -2
  241. package/dist/modules/dexbot_fill_runtime.d.ts +63 -49
  242. package/dist/modules/dexbot_fill_runtime.js +53 -47
  243. package/dist/modules/dexbot_maintenance_runtime.d.ts +127 -71
  244. package/dist/modules/dexbot_maintenance_runtime.js +187 -147
  245. package/dist/modules/dexbot_startup_runtime.d.ts +11 -11
  246. package/dist/modules/dexbot_startup_runtime.js +56 -57
  247. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  248. package/dist/modules/dexbot_state_recovery.js +18 -13
  249. package/dist/modules/fund_registry.d.ts +4 -2
  250. package/dist/modules/fund_registry.js +10 -10
  251. package/dist/modules/general_settings.d.ts +30 -4
  252. package/dist/modules/graceful_shutdown.d.ts +3 -3
  253. package/dist/modules/graceful_shutdown.js +19 -13
  254. package/dist/modules/grid_price_source.d.ts +1 -1
  255. package/dist/modules/key_store.d.ts +14 -8
  256. package/dist/modules/key_store.js +7 -7
  257. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  258. package/dist/modules/launcher/adapter_requirement.js +5 -5
  259. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  260. package/dist/modules/launcher/bot_supervisor.js +12 -11
  261. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  262. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  263. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  264. package/dist/modules/launcher/credential_daemon.js +2 -2
  265. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  266. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  267. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  268. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  269. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  270. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  271. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  272. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  273. package/dist/modules/launcher/supervisor_control.js +4 -2
  274. package/dist/modules/lazy_shim.d.ts +11 -0
  275. package/dist/modules/lazy_shim.js +16 -0
  276. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  277. package/dist/modules/market_adapter_whitelist.js +15 -3
  278. package/dist/modules/node_connect_policy.d.ts +3 -2
  279. package/dist/modules/node_failure_ledger.d.ts +6 -5
  280. package/dist/modules/node_manager.d.ts +41 -11
  281. package/dist/modules/node_manager.js +5 -4
  282. package/dist/modules/order/accounting.d.ts +53 -24
  283. package/dist/modules/order/accounting.js +16 -15
  284. package/dist/modules/order/async_lock.d.ts +5 -2
  285. package/dist/modules/order/async_lock.js +1 -1
  286. package/dist/modules/order/export.d.ts +7 -6
  287. package/dist/modules/order/export.js +1 -7
  288. package/dist/modules/order/format.d.ts +16 -7
  289. package/dist/modules/order/format.js +15 -3
  290. package/dist/modules/order/genesis_policy.d.ts +24 -21
  291. package/dist/modules/order/genesis_policy.js +17 -10
  292. package/dist/modules/order/grid.d.ts +144 -36
  293. package/dist/modules/order/grid.js +226 -145
  294. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  295. package/dist/modules/order/grid_reconcile.js +13 -12
  296. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  297. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  298. package/dist/modules/order/index.d.ts +264 -1
  299. package/dist/modules/order/logger.d.ts +46 -19
  300. package/dist/modules/order/logger.js +38 -49
  301. package/dist/modules/order/logger_state.d.ts +4 -4
  302. package/dist/modules/order/manager.d.ts +232 -191
  303. package/dist/modules/order/manager.js +110 -130
  304. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  305. package/dist/modules/order/processed_fill_store.js +16 -27
  306. package/dist/modules/order/strategy.d.ts +21 -13
  307. package/dist/modules/order/strategy.js +5 -6
  308. package/dist/modules/order/sync_engine.d.ts +91 -33
  309. package/dist/modules/order/sync_engine.js +84 -53
  310. package/dist/modules/order/utils/math.d.ts +157 -102
  311. package/dist/modules/order/utils/math.js +77 -38
  312. package/dist/modules/order/utils/order.d.ts +310 -110
  313. package/dist/modules/order/utils/order.js +153 -126
  314. package/dist/modules/order/utils/slot.d.ts +1 -1
  315. package/dist/modules/order/utils/system.d.ts +156 -26
  316. package/dist/modules/order/utils/system.js +103 -71
  317. package/dist/modules/order/utils/validate.d.ts +89 -41
  318. package/dist/modules/order/utils/validate.js +26 -24
  319. package/dist/modules/order/utils/withPoolRef.d.ts +6 -4
  320. package/dist/modules/order/utils/withPoolRef.js +18 -12
  321. package/dist/modules/order/working_grid.d.ts +14 -13
  322. package/dist/modules/paths.d.ts +1 -4
  323. package/dist/modules/paths.js +33 -61
  324. package/dist/modules/process_discovery.d.ts +1 -1
  325. package/dist/modules/process_discovery.js +2 -1
  326. package/dist/modules/runtime.d.ts +7 -3
  327. package/dist/modules/runtime.js +4 -3
  328. package/dist/modules/runtime_settings.d.ts +14 -11
  329. package/dist/modules/runtime_settings.js +30 -24
  330. package/dist/modules/settings_merge.d.ts +29 -3
  331. package/dist/modules/settings_merge.js +56 -78
  332. package/dist/modules/socket_json_client.d.ts +9 -5
  333. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  334. package/dist/modules/storage/browser_adapter.js +7 -30
  335. package/dist/modules/storage/index.d.ts +1 -1
  336. package/dist/modules/storage/node_adapter.d.ts +45 -27
  337. package/dist/modules/storage/node_adapter.js +9 -9
  338. package/dist/modules/storage/types.d.ts +5 -4
  339. package/dist/modules/types.d.ts +1090 -6
  340. package/dist/modules/types.js +4 -1
  341. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  342. package/dist/modules/utils/asset_symbols.js +2 -1
  343. package/dist/modules/utils/errors.d.ts +9 -0
  344. package/dist/modules/utils/errors.js +24 -4
  345. package/dist/modules/utils/time_range.d.ts +1 -12
  346. package/dist/modules/utils/time_range.js +1 -1
  347. package/dist/modules/validate_profiles.js +53 -43
  348. package/dist/modules/version_notice.d.ts +23 -11
  349. package/dist/modules/version_notice.js +6 -4
  350. package/dist/pm2.d.ts +28 -27
  351. package/dist/pm2.js +61 -40
  352. package/dist/scripts/analyze-credit.d.ts +2 -1
  353. package/dist/scripts/analyze-credit.js +23 -24
  354. package/dist/scripts/analyze-git.js +2 -15
  355. package/dist/scripts/analyze-orders.d.ts +77 -9
  356. package/dist/scripts/analyze-orders.js +65 -40
  357. package/dist/scripts/chart_command.d.ts +27 -18
  358. package/dist/scripts/chart_command.js +15 -13
  359. package/dist/scripts/check_any.d.ts +22 -0
  360. package/dist/scripts/check_any.js +158 -0
  361. package/dist/scripts/diagnose-pool-history.js +13 -13
  362. package/dist/scripts/print_grid.js +0 -1
  363. package/dist/scripts/run-tests.js +39 -8
  364. package/dist/scripts/runner.js +1 -1
  365. package/dist/scripts/sync-version.js +0 -10
  366. package/dist/scripts/test-credit-renewal.js +30 -21
  367. package/dist/scripts/update.d.ts +10 -5
  368. package/dist/scripts/update.js +168 -103
  369. package/dist/scripts/update_dist_freshness.js +1 -0
  370. package/dist/scripts/update_layout.d.ts +61 -0
  371. package/dist/scripts/update_layout.js +180 -0
  372. package/dist/scripts/validate_bots.js +2 -1
  373. package/dist/scripts/verify-browser-bundle.js +8 -0
  374. package/dist/unlock.d.ts +28 -3
  375. package/dist/unlock.js +63 -35
  376. package/docs/BITSHARES_ONBOARDING.md +10 -12
  377. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -2
  378. package/docs/COW_INVARIANTS.md +13 -6
  379. package/docs/DEXBOT_COMPARISON.md +8 -8
  380. package/docs/EVOLUTION.md +10 -8
  381. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  382. package/docs/GRID_RECALCULATION.md +4 -2
  383. package/docs/GRID_RECONCILE.md +14 -3
  384. package/docs/LIFECYCLE.md +11 -11
  385. package/docs/MPA_CREDIT_USAGE.md +22 -3
  386. package/docs/README.md +14 -3
  387. package/docs/WORKFLOW.md +1 -0
  388. package/docs/architecture.md +31 -19
  389. package/docs/developer_guide.md +6 -6
  390. package/market_adapter/README.md +12 -5
  391. package/modules/README.md +4 -1
  392. package/package.json +9 -9
  393. package/scripts/README.md +43 -38
  394. package/tests/README.md +25 -10
  395. package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
  396. package/dist/scripts/diagnose-kibana-candles.js +0 -82
  397. package/scripts/git-viewer.sh +0 -489
  398. package/scripts/postinstall.js +0 -16
@@ -13,66 +13,106 @@
13
13
  * SECTION 3: ORDER MANAGER CLASS
14
14
  * ===============================================================================
15
15
  */
16
+ import { WorkingGrid } from './working_grid.js';
17
+ import Logger from './logger.js';
18
+ import Accountant from './accounting.js';
19
+ import StrategyEngine from './strategy.js';
20
+ import SyncEngine from './sync_engine.js';
21
+ import type { GridGenesis } from './utils/math.js';
22
+ import type { OrderManagerLike, ManagedOrder, GridConfig, AssetPair, AccountTotals, ManagerFunds, PendingPriceCorrection, ProcessedFillStoreLike, PendingBroadcast, ManagerLock, IllegalStateSignal, AccountingFailureSignal, BotMetrics, AccountOrdersLike, CowAction, RebalanceResult, ProjectedFunds, SyncResult, FillHistorySyncResult, FundDriftCheck, ChainFundsSnapshot, OrderType, OrderState, UnknownRecord } from '../types.js';
23
+ /**
24
+ * Stale-placement veto: whether a placement action crosses the plan's own
25
+ * boundary and would fill immediately on stale market data.
26
+ * - BUY create/update targeting a slot ABOVE the boundary is dropped; SELL
27
+ * create/update targeting a slot BELOW the boundary is dropped. Strict
28
+ * comparison: a placement AT the boundary is kept (the boundary slot is
29
+ * the spread, which reconcile never targets).
30
+ * - The reference is the PLAN'S OWN targetBoundary — and ONLY that: the
31
+ * plan's slots derive from the same target grid, so a stale plan's
32
+ * placements cross its own boundary while legitimate re-placements never
33
+ * do (the boundary is capped, the fills are not). Fill-based veto lines
34
+ * are deliberately NOT used — after a burst the fills sit beyond the
35
+ * plan's legitimate re-place levels (e.g. SELL fills 5,6,7 with cap=1
36
+ * moves the boundary only to slot 6), so ANY fill comparison can veto
37
+ * valid placements, including the strategy's own rotations (a partial
38
+ * SELL rotated into a slot below the last BUY fill after the boundary
39
+ * crawled left). The guard is therefore "inert" for boundary-consistent
40
+ * engine output by construction.
41
+ * - Slot ids are compared within the plan's own grid generation
42
+ * (targetBoundary and target slots are both from the current plan), so a
43
+ * recenter between the fill capture and the plan cannot skew the
44
+ * comparison. Both CREATE and UPDATE actions are guarded: the
45
+ * cancel/create optimization can convert the same logical placement into
46
+ * an UPDATE op (target slot = newGridId), which the CREATE-only check
47
+ * would have missed.
48
+ * - When no plan boundary is available (hand-built plans), nothing is
49
+ * vetoed — fill evidence is not a reliable veto line. Non-placement
50
+ * actions and non-grid-slot targets are never vetoed.
51
+ * @param {Object} action - COW action
52
+ * @param {number} planBoundary - The plan's target boundary slot index
53
+ * @returns {string|null} Drop reason for the log, or null to keep the action
54
+ */
55
+ interface COWFillLike extends UnknownRecord {
56
+ id?: string;
57
+ type?: string;
58
+ price?: number;
59
+ size?: number;
60
+ isPartial?: boolean;
61
+ isDelayedRotationTrigger?: boolean;
62
+ order?: {
63
+ price?: number;
64
+ [key: string]: unknown;
65
+ } | null;
66
+ }
67
+ type WorkingGridResult = RebalanceResult & {
68
+ _workingGridPushed?: boolean;
69
+ };
70
+ interface COWExecuteParams {
71
+ masterGrid: Map<string, ManagedOrder>;
72
+ gridVersion: number;
73
+ boundaryIdx: number | null;
74
+ funds: ProjectedFunds | null;
75
+ manager?: OrderManagerLike | null;
76
+ fills?: COWFillLike[];
77
+ excludeIds?: Set<string>;
78
+ gapSlots?: number | null;
79
+ evacStreaks?: Map<string, number> | null;
80
+ reserveEdgeAnchors?: {
81
+ buy?: number | null;
82
+ sell?: number | null;
83
+ } | null;
84
+ }
16
85
  declare class COWRebalanceEngine {
17
- strategy: any;
18
- logger: any;
19
- assets: any;
20
- config: any;
21
- constructor(deps: any);
22
- execute({ masterGrid, gridVersion, boundaryIdx, funds, fills, excludeIds, gapSlots, evacStreaks, reserveEdgeAnchors }: any): Promise<{
23
- actions: never[];
24
- stateUpdates: never[];
25
- hadRotation: boolean;
26
- workingGrid: null;
27
- workingIndexes: null;
28
- workingBoundary: null;
29
- planningDuration: number;
30
- aborted: boolean;
31
- reason: any;
32
- } | {
33
- needsResync?: boolean | undefined;
34
- resyncReason?: string | undefined;
35
- evacReady: never[];
36
- actions: never[];
37
- stateUpdates: never[];
38
- hadRotation: boolean;
39
- workingGrid: null;
40
- workingIndexes: null;
41
- workingBoundary: null;
42
- planningDuration: number;
43
- aborted: boolean;
44
- reason: any;
45
- } | {
46
- evacReady: any;
47
- aborted: boolean;
48
- refillSlotIds?: any;
49
- actions: any;
50
- stateUpdates: any;
51
- hadRotation: any;
52
- workingGrid: any;
53
- workingIndexes: any;
54
- workingBoundary: any;
55
- planningDuration: any;
56
- }>;
86
+ strategy: StrategyEngine;
87
+ logger: Logger;
88
+ assets: AssetPair | null;
89
+ config: GridConfig;
90
+ constructor(deps: {
91
+ strategy: StrategyEngine;
92
+ logger: Logger;
93
+ assets: AssetPair | null;
94
+ config: GridConfig;
95
+ });
96
+ execute({ masterGrid, gridVersion, boundaryIdx, funds, manager, fills, excludeIds, gapSlots, evacStreaks, reserveEdgeAnchors }: COWExecuteParams): Promise<RebalanceResult>;
57
97
  }
58
- declare class OrderManager {
59
- config: any;
60
- marketName: any;
61
- logger: any;
62
- orders: any;
63
- boundaryIdx: any;
64
- targetGrid: any;
65
- accountant: any;
66
- strategy: any;
67
- sync: any;
98
+ declare class OrderManager implements OrderManagerLike {
99
+ config: GridConfig;
100
+ marketName: string | null;
101
+ logger: Logger;
102
+ orders: Map<string, ManagedOrder>;
103
+ boundaryIdx: number | null;
104
+ targetGrid: Map<string, ManagedOrder> | null;
105
+ accountant: Accountant;
106
+ strategy: StrategyEngine;
107
+ sync: SyncEngine;
68
108
  _rebalanceState: string;
69
109
  _bootstrapping: number;
70
110
  _endOfBootstrapValidationDone: boolean;
71
111
  _broadcastingFlag: number;
72
112
  _broadcastingStartedAt: number;
73
113
  _shuttingDown: boolean;
74
- _illegalStateSignal: any;
75
- _accountingFailureSignal: any;
114
+ _illegalStateSignal: IllegalStateSignal | null;
115
+ _accountingFailureSignal: AccountingFailureSignal | null;
76
116
  _recoveryStateValue: {
77
117
  phase: string;
78
118
  attemptCount: number;
@@ -91,10 +131,7 @@ declare class OrderManager {
91
131
  lastTriggeredAt: number;
92
132
  };
93
133
  };
94
- private _ordersByTypeCache;
95
- private _ordersByStateCache;
96
- private _ordersByTypeCacheVersion;
97
- private _ordersByStateCacheVersion;
134
+ private _orderIdIndexes;
98
135
  /**
99
136
  * Lazy-compute order-IDs grouped by type.
100
137
  *
@@ -116,46 +153,48 @@ declare class OrderManager {
116
153
  */
117
154
  get _ordersByState(): Record<string, Set<string>>;
118
155
  set _ordersByState(val: Record<string, Set<string>>);
156
+ /** Rebuild an order-id index for `field` over `keys`, memoized per `_gridVersion`. */
157
+ private _getOrderIdIndex;
119
158
  initialSpreadCount: number;
120
159
  currentSpreadCount: number;
121
160
  outOfSpread: number;
122
- assets: any;
123
- accountId: any;
124
- accountTotals: any;
125
- funds: any;
126
- _accountTotalsPromise: any;
127
- _accountTotalsResolve: any;
161
+ assets: AssetPair;
162
+ accountId: string | null;
163
+ accountTotals: AccountTotals;
164
+ funds: ManagerFunds;
165
+ _accountTotalsPromise: Promise<void> | null;
166
+ _accountTotalsResolve: (() => void) | null;
128
167
  _isFetchingTotals: boolean;
129
168
  accountTotalsStale: boolean;
130
- ordersNeedingPriceCorrection: any[];
131
- shadowOrderIds: Map<any, any>;
132
- processedFillTracker: Map<any, any>;
133
- processedFillStore: any;
134
- _syncLock: any;
135
- _fillProcessingLock: any;
136
- _divergenceLock: any;
137
- _gridLock: any;
138
- _fundLock: any;
139
- _gridSidesUpdated: Set<any>;
169
+ ordersNeedingPriceCorrection: PendingPriceCorrection[];
170
+ shadowOrderIds: Map<string, number>;
171
+ processedFillTracker: Map<string, number>;
172
+ processedFillStore: ProcessedFillStoreLike | null;
173
+ _syncLock: ManagerLock;
174
+ _fillProcessingLock: ManagerLock;
175
+ _divergenceLock: ManagerLock;
176
+ _gridLock: ManagerLock;
177
+ _fundLock: ManagerLock;
178
+ _gridSidesUpdated: Set<string>;
140
179
  _pauseFundRecalc: number;
141
180
  _pauseFundRecalcWatchdog: ReturnType<typeof setTimeout> | null;
142
181
  _fillBatchInFlight: number;
143
182
  _pauseRecalcLogging: boolean;
144
183
  _pauseRecalcLoggingWatchdog: ReturnType<typeof setTimeout> | null;
145
184
  _throwOnIllegalState: boolean;
146
- _pipelineBlockedSince: any;
185
+ _pipelineBlockedSince: number | null;
147
186
  _recoveryAttempted: boolean;
148
187
  _syncGeneration: number;
149
188
  _gridVersion: number;
150
- _gridPersistenceSuspendedReason: any;
151
- _pendingBroadcasts: Map<any, any>;
189
+ _gridPersistenceSuspendedReason: string | null;
190
+ _pendingBroadcasts: Map<string, PendingBroadcast>;
152
191
  _committedOrderIds: Set<string>;
153
192
  _committedOrderIdsBuiltAt: number;
154
193
  _orderIdAssignedAt: Map<string, number>;
155
194
  _placedAt: Map<string, number>;
156
195
  _gapSlots: number;
157
- _genesis: any;
158
- _missingGenesis: any;
196
+ _genesis: GridGenesis | null;
197
+ _missingGenesis: unknown;
159
198
  _genesisInvariantViolations: number;
160
199
  _genesisInvariantLoggedAt: number;
161
200
  _gridDirtyAt: number | null;
@@ -182,16 +221,20 @@ declare class OrderManager {
182
221
  _lastFilledAt: number;
183
222
  lastFillPivotSource: 'fill' | 'book' | null;
184
223
  _deferredRebalanceAt: number;
185
- _lastHeldPlanSignature: any;
224
+ _lastHeldPlanSignature: {
225
+ boundaryIdx: number | null;
226
+ pivot: number | null;
227
+ fillsAt: number | null;
228
+ } | null;
186
229
  _heldPlanSuppressionCount: number;
187
230
  _onBroadcastRegionEndListeners: Array<() => void>;
188
231
  _lastBoundaryHoldResyncAt: number;
189
232
  _gapEvacStreaks: Map<string, number>;
190
233
  _gapEvacCancelQueued: Set<string>;
191
- _metrics: any;
234
+ _metrics: BotMetrics;
192
235
  private _currentWorkingGridStack;
193
- _cowEngine: any;
194
- accountOrders: any;
236
+ _cowEngine: COWRebalanceEngine | null;
237
+ accountOrders: AccountOrdersLike;
195
238
  btsBalance: {
196
239
  free: number;
197
240
  total: number;
@@ -200,8 +243,8 @@ declare class OrderManager {
200
243
  /**
201
244
  * @param {Object} [config] - Configuration overrides
202
245
  */
203
- constructor(config?: Record<string, any>);
204
- _getCOWEngine(): any;
246
+ constructor(config?: Record<string, unknown>);
247
+ _getCOWEngine(): COWRebalanceEngine | null;
205
248
  _clearWorkingGridRef(): void;
206
249
  /**
207
250
  * Push a working grid onto the rebalance stack (LIFO), set the state to
@@ -213,7 +256,7 @@ declare class OrderManager {
213
256
  * @param {Object} workingGrid - The working grid to push
214
257
  * @param {Object} [result] - Result object to carry the push marker on
215
258
  */
216
- _pushWorkingGridRef(workingGrid: any, result?: any): any;
259
+ _pushWorkingGridRef(workingGrid: WorkingGrid, result?: WorkingGridResult | null): WorkingGridResult | null;
217
260
  /**
218
261
  * Pop the stack entry owned by a result, exactly once (marker-guarded).
219
262
  * Results that were never pushed (aborted plans, no-trigger
@@ -223,7 +266,7 @@ declare class OrderManager {
223
266
  * a later throw in the same frame cannot pop a second time.
224
267
  * @param {Object} [result] - Result object carrying the push marker
225
268
  */
226
- _popWorkingGridRef(result?: any): void;
269
+ _popWorkingGridRef(result?: WorkingGridResult | null): void;
227
270
  /**
228
271
  * Release the stack entry for a grid after its commit settles, exactly
229
272
  * once per commit invocation. Identity-checked: plan-path grids
@@ -233,8 +276,8 @@ declare class OrderManager {
233
276
  * the check is a no-op for them.
234
277
  * @param {Object} workingGrid - The committed working grid
235
278
  */
236
- _releaseWorkingGridRef(workingGrid: any): void;
237
- _setRebalanceState(state: any): void;
279
+ _releaseWorkingGridRef(workingGrid: WorkingGrid): void;
280
+ _setRebalanceState(state: string): void;
238
281
  _resetRebalanceStateToDepth(): void;
239
282
  /**
240
283
  * @returns {boolean}
@@ -253,7 +296,7 @@ declare class OrderManager {
253
296
  * @param {boolean} value
254
297
  * @returns {void}
255
298
  */
256
- setShuttingDown(value: any): void;
299
+ setShuttingDown(value: boolean): void;
257
300
  /**
258
301
  * Auto-clears a stale broadcast flag after 120s so a hung
259
302
  * broadcast cannot permanently block rebalancing.
@@ -273,11 +316,11 @@ declare class OrderManager {
273
316
  */
274
317
  startBootstrap(): void;
275
318
  /**
276
- * @returns {any}
319
+ * @returns {unknown}
277
320
  */
278
321
  finishBootstrap(): {
279
322
  hadDrift: boolean;
280
- driftInfo: null;
323
+ driftInfo: FundDriftCheck | null;
281
324
  };
282
325
  /**
283
326
  * @returns {void}
@@ -294,17 +337,15 @@ declare class OrderManager {
294
337
  * without rescheduling, so this is the only wake-up for fills enqueued
295
338
  * during a region; the watchdog path must fire it too or a hung broadcast's
296
339
  * queued fills wait for the next fill event.
297
- * Fans out to the legacy single listener plus every registered listener
298
- * (see addBroadcastRegionEndListener): a second wirer must never silently
299
- * displace the fill-queue drain. Guarded so a listener error never escapes
300
- * into a finally/watchdog frame.
340
+ * Fans out to every listener registered via addBroadcastRegionEndListener:
341
+ * a second wirer must never silently displace the fill-queue drain.
342
+ * Guarded so a listener error never escapes into a finally/watchdog frame.
301
343
  * @returns {void}
302
344
  */
303
345
  _fireBroadcastRegionEnd(): void;
304
346
  /**
305
- * Register an additional broadcast-region-end listener without displacing
306
- * the legacy single listener or previously registered ones. Duplicate
307
- * registrations of the same function reference are ignored.
347
+ * Register a broadcast-region-end listener. Duplicate registrations of the
348
+ * same function reference are ignored.
308
349
  * @param {() => void} listener
309
350
  * @returns {void}
310
351
  */
@@ -315,7 +356,7 @@ declare class OrderManager {
315
356
  * (deductBtsFees, tryDeductFromChainFree, updateOptimisticFreeBalance).
316
357
  * @returns {Promise<void>}
317
358
  */
318
- resetFunds(): Promise<any>;
359
+ resetFunds(): Promise<void>;
319
360
  /**
320
361
  * Computes committed amounts directly from the orders map to ensure the
321
362
  * snapshot is internally consistent even when called inside a
@@ -324,35 +365,19 @@ declare class OrderManager {
324
365
  * value can lag behind the actual orders state (virtualized orders
325
366
  * release committed capital via updateOptimisticFreeBalance without
326
367
  * triggering a recalc). Reading from the orders map avoids that race.
327
- * @returns {any}
368
+ * @returns {unknown}
328
369
  */
329
- getChainFundsSnapshot(): {
330
- allocatedBuy: number;
331
- allocatedSell: number;
332
- btsBalance: {
333
- free: number;
334
- total: number;
335
- locked: number;
336
- } | null;
337
- chainFreeBuy: number;
338
- chainFreeSell: number;
339
- committedChainBuy: number;
340
- committedChainSell: number;
341
- freePlusLockedBuy: number;
342
- freePlusLockedSell: number;
343
- chainTotalBuy: number;
344
- chainTotalSell: number;
345
- };
370
+ getChainFundsSnapshot(): ChainFundsSnapshot;
346
371
  /**
347
372
  * @param {number} [timeoutMs]
348
373
  * @returns {Promise<void>}
349
374
  */
350
- waitForAccountTotals(timeoutMs?: any): Promise<void>;
375
+ waitForAccountTotals(timeoutMs?: number): Promise<void>;
351
376
  /**
352
377
  * @param {string} [accountId] - Blockchain account ID
353
378
  * @returns {Promise<void>}
354
379
  */
355
- fetchAccountTotals(accountId: any): Promise<void>;
380
+ fetchAccountTotals(accountId: string | null): Promise<void>;
356
381
  /**
357
382
  * Refresh accountTotals from chain when the cached snapshot is stale.
358
383
  *
@@ -399,13 +424,13 @@ declare class OrderManager {
399
424
  * @returns {Promise<boolean>} true when the re-anchor refreshed successfully
400
425
  */
401
426
  reanchorAccountTotals(label?: string): Promise<boolean>;
402
- _fetchAccountBalancesAndSetTotals(): Promise<any>;
427
+ _fetchAccountBalancesAndSetTotals(): Promise<void>;
403
428
  /**
404
- * @param {any} totals - Account balance totals
429
+ * @param {unknown} totals - Account balance totals
405
430
  * @returns {Promise<void>}
406
431
  */
407
- setAccountTotals(totals?: any): Promise<any>;
408
- _setAccountTotals(totals: any): Promise<void>;
432
+ setAccountTotals(totals?: Partial<AccountTotals>): Promise<void>;
433
+ _setAccountTotals(totals: Partial<AccountTotals>): Promise<void>;
409
434
  _triggerAccountTotalsFetchIfNeeded(): void;
410
435
  /**
411
436
  * @returns {void}
@@ -414,7 +439,7 @@ declare class OrderManager {
414
439
  /**
415
440
  * @returns {Promise<void>}
416
441
  */
417
- recalculateFunds(): Promise<any>;
442
+ recalculateFunds(): Promise<void>;
418
443
  _recalculateFunds(): Promise<void>;
419
444
  /**
420
445
  * Suppress fund recalculation during batch mutations.
@@ -467,42 +492,42 @@ declare class OrderManager {
467
492
  * @param {Object} info
468
493
  * @returns {Promise<any>}
469
494
  */
470
- syncFromOpenOrders(orders: any, info: any): any;
495
+ syncFromOpenOrders(orders: unknown[] | null, info?: UnknownRecord): Promise<SyncResult>;
471
496
  /**
472
497
  * @param {Object} fill - Fill event data
473
498
  * @param {Object} [options]
474
499
  * @returns {Promise<any>}
475
500
  */
476
- syncFromFillHistory(fill: any, options: any): any;
501
+ syncFromFillHistory(fill: unknown, options?: UnknownRecord): Promise<FillHistorySyncResult>;
477
502
  /**
478
503
  * @param {Array} fills - Array of fill event objects (same block group)
479
504
  * @param {Object} [options]
480
505
  * @returns {Promise<any>}
481
506
  */
482
- syncFromFillHistoryBatch(fills: any, options: any): any;
507
+ syncFromFillHistoryBatch(fills: unknown[], options?: UnknownRecord): Promise<FillHistorySyncResult>;
483
508
  /**
484
509
  * @param {Object} data - Chain data to synchronize
485
510
  * @param {string} src - Source identifier
486
511
  * @returns {Promise<any>}
487
512
  */
488
- synchronizeWithChain(data: any, src: any): Promise<any>;
489
- _applySync(data: any, src: any): Promise<any>;
490
- _initializeAssets(): Promise<any>;
513
+ synchronizeWithChain(data: unknown, src: string): Promise<SyncResult>;
514
+ _applySync(data: unknown, src: string): Promise<SyncResult>;
515
+ _initializeAssets(): Promise<void>;
491
516
  /**
492
517
  * @param {string[]|Set<string>} orderIds - Order IDs to lock
493
518
  * @returns {void}
494
519
  */
495
- lockOrders(orderIds: any): void;
520
+ lockOrders(orderIds: Iterable<string> | null | undefined): void;
496
521
  /**
497
522
  * @param {string[]|Set<string>} orderIds - Order IDs to unlock
498
523
  * @returns {void}
499
524
  */
500
- unlockOrders(orderIds: any): void;
525
+ unlockOrders(orderIds: Iterable<string> | null | undefined): void;
501
526
  /**
502
527
  * @param {string} id - Order ID
503
528
  * @returns {boolean}
504
529
  */
505
- isOrderLocked(id: any): boolean;
530
+ isOrderLocked(id: string): boolean;
506
531
  /**
507
532
  * Number of distinct live orders currently shadow-locked.
508
533
  *
@@ -513,31 +538,25 @@ declare class OrderManager {
513
538
  */
514
539
  getActiveShadowLockCount(): number;
515
540
  _cleanExpiredLocks(): void;
516
- _normalizeOrderUpdateOptions(options?: Record<string, any>): {
541
+ _normalizeOrderUpdateOptions(options?: UnknownRecord): {
517
542
  skipAccounting: boolean;
518
543
  fee: number;
519
544
  };
520
- _normalizeCommitOptions(options?: Record<string, any>): {
545
+ _normalizeCommitOptions(options?: UnknownRecord): {
521
546
  skipRecalc: boolean;
522
547
  boundaryHeld: boolean;
523
548
  };
524
- _updateOrder(order: any, context?: any, options?: any): Promise<any>;
525
- _applyOrderUpdate(order: any, context?: any, options?: any): Promise<boolean>;
526
- /**
527
- * Backward-compatible accessor for _currentWorkingGrid.
528
- * Returns the top of the working grid stack (null if empty).
529
- */
530
- get _currentWorkingGrid(): any;
531
- set _currentWorkingGrid(val: any);
532
- _peekWorkingGrid(): any;
533
- _syncWorkingGridFromMasterMutation(orderId: any, context: any): void;
549
+ _updateOrder(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
550
+ _applyOrderUpdate(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
551
+ _peekWorkingGrid(): WorkingGrid | null;
552
+ _syncWorkingGridFromMasterMutation(orderId: string, context: string): void;
534
553
  /**
535
554
  * @param {Array<import('./types').Order>} updates - Order updates to apply
536
555
  * @param {string} [context] - Update context label
537
- * @param {any} [options]
556
+ * @param {unknown} [options]
538
557
  * @returns {Promise<boolean>}
539
558
  */
540
- applyGridUpdateBatch(updates: any, context?: any, options?: any): Promise<any>;
559
+ applyGridUpdateBatch(updates: ManagedOrder[], context?: string, options?: UnknownRecord): Promise<boolean>;
541
560
  /**
542
561
  * Flag the in-memory master grid as dirty so the next flushGridDirty()
543
562
  * call persists it. Internal helper — every successful _applyOrderUpdate
@@ -573,17 +592,12 @@ declare class OrderManager {
573
592
  * @param {string} [contextLabel='flush-grid-dirty'] - Label for logs
574
593
  * @returns {Promise<{skipped?: boolean, suspended?: boolean, isValid?: boolean, reason?: string}>}
575
594
  */
576
- flushGridDirty(contextLabel?: any): Promise<{
595
+ flushGridDirty(contextLabel?: string): Promise<{
577
596
  isValid: boolean;
578
597
  reason: string;
579
598
  } | {
580
599
  isValid: boolean;
581
600
  reason: null;
582
- } | {
583
- isValid: boolean;
584
- skipped: boolean;
585
- suspended: boolean;
586
- reason: any;
587
601
  } | {
588
602
  skipped: boolean;
589
603
  reason: string;
@@ -591,7 +605,7 @@ declare class OrderManager {
591
605
  } | {
592
606
  skipped: boolean;
593
607
  suspended: boolean;
594
- reason: any;
608
+ reason: string;
595
609
  }>;
596
610
  /**
597
611
  * @param {Array<import('./types').Order>} orders - Filled orders
@@ -599,11 +613,11 @@ declare class OrderManager {
599
613
  * @param {Object} [options]
600
614
  * @returns {Promise<any>}
601
615
  */
602
- processFilledOrders(orders: any, excl: any, options?: any): Promise<any>;
616
+ processFilledOrders(orders: COWFillLike[], excl: Set<string>, options?: UnknownRecord): Promise<RebalanceResult>;
603
617
  /**
604
618
  * @returns {Array<import('./types').Order>}
605
619
  */
606
- getInitialOrdersToActivate(): any[];
620
+ getInitialOrdersToActivate(): ManagedOrder[];
607
621
  /**
608
622
  * Get orders matching the specified type and state.
609
623
  *
@@ -611,7 +625,7 @@ declare class OrderManager {
611
625
  * @param {string} state - Order state (ORDER_STATES.ACTIVE/PARTIAL/VIRTUAL)
612
626
  * @returns {Array} Array of matching orders
613
627
  */
614
- getOrdersByTypeAndState(type: any, state: any): any[];
628
+ getOrdersByTypeAndState(type: OrderType | null, state: OrderState): ManagedOrder[];
615
629
  /**
616
630
  * Write boundaryIdx under COW-commit-only discipline.
617
631
  *
@@ -620,7 +634,7 @@ declare class OrderManager {
620
634
  * so a misbehaving caller doesn't silently lose the update, but the warning
621
635
  * flags a violation of the COW boundary-write invariant.
622
636
  */
623
- _setBoundary(newIdx: number): void;
637
+ _setBoundary(newIdx: number | null): void;
624
638
  /**
625
639
  * Restore boundaryIdx outside the COW commit path (startup, recovery,
626
640
  * disk-load). This is the same write as _setBoundary but without the
@@ -651,7 +665,7 @@ declare class OrderManager {
651
665
  *
652
666
  * @param {string} reason - Log/debug label for the drop
653
667
  */
654
- _clearPendingFillCrawls(reason?: any): void;
668
+ _clearPendingFillCrawls(reason?: string): void;
655
669
  /**
656
670
  * Observability (fix #4, docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md §2): emit the live
657
671
  * boundary whenever roles are (re)assigned, so a silent boundary crawl that
@@ -687,7 +701,7 @@ declare class OrderManager {
687
701
  * @param {number} [atMs] - Fill timestamp to preserve (defaults to now)
688
702
  * @returns {boolean} True when the pivot was written
689
703
  */
690
- _setLastFillPivot(type: any, price: number, provenance: 'fill' | 'book', atMs?: number): boolean;
704
+ _setLastFillPivot(type: OrderType, price: number, provenance: 'fill' | 'book', atMs?: number): boolean;
691
705
  /**
692
706
  * Reset the LAST-FILL-GUARD pivot to cold state, clearing the whole
693
707
  * scalar family (per-side mirrors included): leaves seedLastFilledPricesFromBook's
@@ -717,7 +731,7 @@ declare class OrderManager {
717
731
  * cold-check and per-side seeding in seedLastFilledPricesFromBook.
718
732
  * @param {Array} fills
719
733
  */
720
- recordLastFilledPrices(fills: any): void;
734
+ recordLastFilledPrices(fills: COWFillLike[]): void;
721
735
  /**
722
736
  * Seed last-filled guard from the live book at startup. Book-derived
723
737
  * (survives restart), analogous to the deleted MarketAnchor book-seed.
@@ -727,32 +741,45 @@ declare class OrderManager {
727
741
  * the book alone.
728
742
  * @param {Array} chainOpenOrders - raw chain open orders (from readOpenOrdersGuarded)
729
743
  */
730
- seedLastFilledPricesFromBook(chainOpenOrders: any): void;
744
+ seedLastFilledPricesFromBook(chainOpenOrders: unknown[]): void;
731
745
  /**
732
746
  * @returns {Object|null} The consumed signal or null
733
747
  */
734
- consumeIllegalStateSignal(): any;
748
+ consumeIllegalStateSignal(): IllegalStateSignal | null;
735
749
  /**
736
750
  * @returns {Object|null} The consumed signal or null
737
751
  */
738
- consumeAccountingFailureSignal(): any;
752
+ consumeAccountingFailureSignal(): AccountingFailureSignal | null;
739
753
  /**
740
754
  * @param {Object} BitShares - BitShares API instance
741
755
  * @param {Function} batchCb - Batch callback
742
756
  * @returns {Promise<Object>}
743
757
  */
744
- checkSpreadCondition(BitShares: any, batchCb: any): Promise<any>;
758
+ checkSpreadCondition(BitShares: unknown, batchCb?: ((correction: unknown) => Promise<{
759
+ executed?: boolean;
760
+ }>) | null): Promise<{
761
+ ordersPlaced: number;
762
+ partialsMoved: number;
763
+ stall?: import("../types.js").SpreadCorrectionStall;
764
+ }>;
745
765
  /**
746
766
  * @param {Function} batchCb - Batch callback
747
767
  * @returns {Promise<Object>}
748
768
  */
749
- checkGridHealth(batchCb: any): Promise<any>;
769
+ checkGridHealth(batchCb?: ((correction: unknown) => Promise<{
770
+ executed?: boolean;
771
+ }>) | null): Promise<{
772
+ buyDust: boolean;
773
+ sellDust: boolean;
774
+ buyDustOrders: unknown[];
775
+ sellDustOrders: unknown[];
776
+ }>;
750
777
  /**
751
778
  * @returns {Object} Current spread calculation
752
779
  */
753
780
  calculateCurrentSpread(): number;
754
781
  /**
755
- * @returns {any}
782
+ * @returns {unknown}
756
783
  */
757
784
  checkFundDriftAfterFills(): {
758
785
  isValid: boolean;
@@ -774,9 +801,9 @@ declare class OrderManager {
774
801
  };
775
802
  /**
776
803
  * @param {Object|number} [pipelineSignals] - Pipeline state signals or queue length
777
- * @returns {any}
804
+ * @returns {unknown}
778
805
  */
779
- isPipelineEmpty(pipelineSignals?: number | Record<string, any>): {
806
+ isPipelineEmpty(pipelineSignals?: number | Record<string, unknown>): {
780
807
  isEmpty: boolean;
781
808
  reasons: string[];
782
809
  };
@@ -789,16 +816,18 @@ declare class OrderManager {
789
816
  * @param {number} targetBoundary
790
817
  * @returns {Object}
791
818
  */
792
- reconcileGrid(targetGrid: any, targetBoundary: any): {
793
- actions: any[];
819
+ reconcileGrid(targetGrid: Map<string, ManagedOrder>, targetBoundary: number | null): {
820
+ actions: CowAction[];
794
821
  aborted: boolean;
795
- boundaryIdx: any;
796
- evacReady: any[];
822
+ boundaryIdx: number | null;
823
+ evacReady: {
824
+ id: string;
825
+ }[];
797
826
  summary: {
798
- total: any;
799
- creates: any;
800
- cancels: any;
801
- updates: any;
827
+ total: number;
828
+ creates: number;
829
+ cancels: number;
830
+ updates: number;
802
831
  };
803
832
  };
804
833
  /**
@@ -826,7 +855,7 @@ declare class OrderManager {
826
855
  * @param {Array} candidates - evacReady candidates [{id, idx, type, price, size, orderId}]
827
856
  * @returns {number} Number of corrections queued
828
857
  */
829
- _processGapEvacuationTeeth(candidates: any): number;
858
+ _processGapEvacuationTeeth(candidates: unknown): number;
830
859
  /**
831
860
  * Wait (bounded) until any non-COW broadcast/placement activity — the
832
861
  * refcounted _broadcastingFlag — has released. Startup/structural
@@ -857,20 +886,32 @@ declare class OrderManager {
857
886
  * on the flag it holds itself.
858
887
  * @returns {Promise<any>}
859
888
  */
860
- performSafeRebalance(fills?: any, excludeIds?: any, options?: any): Promise<any>;
861
- _applySafeRebalanceCOW(fills?: any, excludeIds?: any): Promise<any>;
889
+ performSafeRebalance(fills?: COWFillLike[], excludeIds?: Set<string>, options?: {
890
+ skipBroadcastWait?: boolean;
891
+ deferIfBroadcasting?: boolean;
892
+ [key: string]: unknown;
893
+ }): Promise<RebalanceResult>;
894
+ _applySafeRebalanceCOW(fills?: COWFillLike[], excludeIds?: Set<string>): Promise<RebalanceResult>;
862
895
  _getCowComparePrecisions(): {
863
896
  buyPrecision: number;
864
897
  sellPrecision: number;
865
898
  priceRelativeTolerance: number;
866
899
  };
867
- _commitWorkingGrid(workingGrid: any, _workingIndexes: any, workingBoundary: any, options?: any): Promise<boolean>;
900
+ _commitWorkingGrid(workingGrid: WorkingGrid, _workingIndexes: unknown, workingBoundary: number | null, options?: {
901
+ skipRecalc?: boolean;
902
+ boundaryHeld?: boolean;
903
+ result?: WorkingGridResult;
904
+ [key: string]: unknown;
905
+ }): Promise<boolean>;
868
906
  /**
869
907
  * @param {Object} [options]
870
908
  * @param {boolean} [options.allowBootstrapTransient]
871
- * @returns {any}
909
+ * @returns {unknown}
872
910
  */
873
- validateGridStateForPersistence(options?: Record<string, any>): {
911
+ validateGridStateForPersistence(options?: {
912
+ allowBootstrapTransient?: boolean;
913
+ [key: string]: unknown;
914
+ }): {
874
915
  isValid: boolean;
875
916
  reason: string;
876
917
  } | {
@@ -881,12 +922,12 @@ declare class OrderManager {
881
922
  * @param {string} [reason]
882
923
  * @returns {void}
883
924
  */
884
- suspendGridPersistence(reason?: any): void;
925
+ suspendGridPersistence(reason?: string): void;
885
926
  /**
886
927
  * @param {string} [reason]
887
928
  * @returns {void}
888
929
  */
889
- resumeGridPersistence(reason?: any): void;
930
+ resumeGridPersistence(reason?: string | null): void;
890
931
  /**
891
932
  * @param {Array<Object>} [snapshotOrders] - Optional explicit orders to persist.
892
933
  * When provided, this list is persisted as-is and the live `manager.orders`
@@ -895,9 +936,9 @@ declare class OrderManager {
895
936
  * swapping the live map and exposing it to concurrent readers.
896
937
  * @returns {Promise<any>}
897
938
  */
898
- persistGrid(snapshotOrders: any, recentFillKeys?: any, fundSnapshot?: {
939
+ persistGrid(snapshotOrders?: ManagedOrder[], recentFillKeys?: Record<string, number>, fundSnapshot?: {
899
940
  btsFeesOwed: number;
900
- accountTotals: any;
941
+ accountTotals: AccountTotals;
901
942
  }): Promise<{
902
943
  isValid: boolean;
903
944
  reason: string;
@@ -908,12 +949,12 @@ declare class OrderManager {
908
949
  isValid: boolean;
909
950
  skipped: boolean;
910
951
  suspended: boolean;
911
- reason: any;
952
+ reason: string;
912
953
  }>;
913
- get _lastIllegalState(): any;
914
- set _lastIllegalState(value: any);
915
- get _lastAccountingFailure(): any;
916
- set _lastAccountingFailure(value: any);
954
+ get _lastIllegalState(): IllegalStateSignal | null;
955
+ set _lastIllegalState(value: IllegalStateSignal | null);
956
+ get _lastAccountingFailure(): AccountingFailureSignal | null;
957
+ set _lastAccountingFailure(value: AccountingFailureSignal | null);
917
958
  get _recoveryState(): {
918
959
  phase: string;
919
960
  attemptCount: number;