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
@@ -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;
@@ -119,42 +159,43 @@ declare class OrderManager {
119
159
  initialSpreadCount: number;
120
160
  currentSpreadCount: number;
121
161
  outOfSpread: number;
122
- assets: any;
123
- accountId: any;
124
- accountTotals: any;
125
- funds: any;
126
- _accountTotalsPromise: any;
127
- _accountTotalsResolve: any;
162
+ assets: AssetPair;
163
+ accountId: string | null;
164
+ accountTotals: AccountTotals;
165
+ funds: ManagerFunds;
166
+ _accountTotalsPromise: Promise<void> | null;
167
+ _accountTotalsResolve: (() => void) | null;
128
168
  _isFetchingTotals: boolean;
129
169
  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>;
170
+ ordersNeedingPriceCorrection: PendingPriceCorrection[];
171
+ shadowOrderIds: Map<string, number>;
172
+ processedFillTracker: Map<string, number>;
173
+ processedFillStore: ProcessedFillStoreLike | null;
174
+ _syncLock: ManagerLock;
175
+ _fillProcessingLock: ManagerLock;
176
+ _divergenceLock: ManagerLock;
177
+ _gridLock: ManagerLock;
178
+ _fundLock: ManagerLock;
179
+ _gridSidesUpdated: Set<string>;
140
180
  _pauseFundRecalc: number;
141
181
  _pauseFundRecalcWatchdog: ReturnType<typeof setTimeout> | null;
142
182
  _fillBatchInFlight: number;
143
183
  _pauseRecalcLogging: boolean;
144
184
  _pauseRecalcLoggingWatchdog: ReturnType<typeof setTimeout> | null;
145
185
  _throwOnIllegalState: boolean;
146
- _pipelineBlockedSince: any;
186
+ _pipelineBlockedSince: number | null;
147
187
  _recoveryAttempted: boolean;
148
188
  _syncGeneration: number;
149
189
  _gridVersion: number;
150
- _gridPersistenceSuspendedReason: any;
151
- _pendingBroadcasts: Map<any, any>;
190
+ _gridPersistenceSuspendedReason: string | null;
191
+ _pendingBroadcasts: Map<string, PendingBroadcast>;
152
192
  _committedOrderIds: Set<string>;
153
193
  _committedOrderIdsBuiltAt: number;
154
194
  _orderIdAssignedAt: Map<string, number>;
195
+ _placedAt: Map<string, number>;
155
196
  _gapSlots: number;
156
- _genesis: any;
157
- _missingGenesis: any;
197
+ _genesis: GridGenesis | null;
198
+ _missingGenesis: unknown;
158
199
  _genesisInvariantViolations: number;
159
200
  _genesisInvariantLoggedAt: number;
160
201
  _gridDirtyAt: number | null;
@@ -181,16 +222,21 @@ declare class OrderManager {
181
222
  _lastFilledAt: number;
182
223
  lastFillPivotSource: 'fill' | 'book' | null;
183
224
  _deferredRebalanceAt: number;
184
- _lastHeldPlanSignature: any;
225
+ _lastHeldPlanSignature: {
226
+ boundaryIdx: number | null;
227
+ pivot: number | null;
228
+ fillsAt: number | null;
229
+ } | null;
185
230
  _heldPlanSuppressionCount: number;
231
+ _onBroadcastRegionEnd?: () => void;
186
232
  _onBroadcastRegionEndListeners: Array<() => void>;
187
233
  _lastBoundaryHoldResyncAt: number;
188
234
  _gapEvacStreaks: Map<string, number>;
189
235
  _gapEvacCancelQueued: Set<string>;
190
- _metrics: any;
236
+ _metrics: BotMetrics;
191
237
  private _currentWorkingGridStack;
192
- _cowEngine: any;
193
- accountOrders: any;
238
+ _cowEngine: COWRebalanceEngine | null;
239
+ accountOrders: AccountOrdersLike;
194
240
  btsBalance: {
195
241
  free: number;
196
242
  total: number;
@@ -199,8 +245,8 @@ declare class OrderManager {
199
245
  /**
200
246
  * @param {Object} [config] - Configuration overrides
201
247
  */
202
- constructor(config?: Record<string, any>);
203
- _getCOWEngine(): any;
248
+ constructor(config?: Record<string, unknown>);
249
+ _getCOWEngine(): COWRebalanceEngine | null;
204
250
  _clearWorkingGridRef(): void;
205
251
  /**
206
252
  * Push a working grid onto the rebalance stack (LIFO), set the state to
@@ -212,7 +258,7 @@ declare class OrderManager {
212
258
  * @param {Object} workingGrid - The working grid to push
213
259
  * @param {Object} [result] - Result object to carry the push marker on
214
260
  */
215
- _pushWorkingGridRef(workingGrid: any, result?: any): any;
261
+ _pushWorkingGridRef(workingGrid: WorkingGrid, result?: WorkingGridResult | null): WorkingGridResult | null;
216
262
  /**
217
263
  * Pop the stack entry owned by a result, exactly once (marker-guarded).
218
264
  * Results that were never pushed (aborted plans, no-trigger
@@ -222,7 +268,7 @@ declare class OrderManager {
222
268
  * a later throw in the same frame cannot pop a second time.
223
269
  * @param {Object} [result] - Result object carrying the push marker
224
270
  */
225
- _popWorkingGridRef(result?: any): void;
271
+ _popWorkingGridRef(result?: WorkingGridResult | null): void;
226
272
  /**
227
273
  * Release the stack entry for a grid after its commit settles, exactly
228
274
  * once per commit invocation. Identity-checked: plan-path grids
@@ -232,8 +278,8 @@ declare class OrderManager {
232
278
  * the check is a no-op for them.
233
279
  * @param {Object} workingGrid - The committed working grid
234
280
  */
235
- _releaseWorkingGridRef(workingGrid: any): void;
236
- _setRebalanceState(state: any): void;
281
+ _releaseWorkingGridRef(workingGrid: WorkingGrid): void;
282
+ _setRebalanceState(state: string): void;
237
283
  _resetRebalanceStateToDepth(): void;
238
284
  /**
239
285
  * @returns {boolean}
@@ -252,7 +298,7 @@ declare class OrderManager {
252
298
  * @param {boolean} value
253
299
  * @returns {void}
254
300
  */
255
- setShuttingDown(value: any): void;
301
+ setShuttingDown(value: boolean): void;
256
302
  /**
257
303
  * Auto-clears a stale broadcast flag after 120s so a hung
258
304
  * broadcast cannot permanently block rebalancing.
@@ -272,11 +318,11 @@ declare class OrderManager {
272
318
  */
273
319
  startBootstrap(): void;
274
320
  /**
275
- * @returns {any}
321
+ * @returns {unknown}
276
322
  */
277
323
  finishBootstrap(): {
278
324
  hadDrift: boolean;
279
- driftInfo: null;
325
+ driftInfo: FundDriftCheck | null;
280
326
  };
281
327
  /**
282
328
  * @returns {void}
@@ -314,7 +360,7 @@ declare class OrderManager {
314
360
  * (deductBtsFees, tryDeductFromChainFree, updateOptimisticFreeBalance).
315
361
  * @returns {Promise<void>}
316
362
  */
317
- resetFunds(): Promise<any>;
363
+ resetFunds(): Promise<void>;
318
364
  /**
319
365
  * Computes committed amounts directly from the orders map to ensure the
320
366
  * snapshot is internally consistent even when called inside a
@@ -323,35 +369,19 @@ declare class OrderManager {
323
369
  * value can lag behind the actual orders state (virtualized orders
324
370
  * release committed capital via updateOptimisticFreeBalance without
325
371
  * triggering a recalc). Reading from the orders map avoids that race.
326
- * @returns {any}
372
+ * @returns {unknown}
327
373
  */
328
- getChainFundsSnapshot(): {
329
- allocatedBuy: number;
330
- allocatedSell: number;
331
- btsBalance: {
332
- free: number;
333
- total: number;
334
- locked: number;
335
- } | null;
336
- chainFreeBuy: number;
337
- chainFreeSell: number;
338
- committedChainBuy: number;
339
- committedChainSell: number;
340
- freePlusLockedBuy: number;
341
- freePlusLockedSell: number;
342
- chainTotalBuy: number;
343
- chainTotalSell: number;
344
- };
374
+ getChainFundsSnapshot(): ChainFundsSnapshot;
345
375
  /**
346
376
  * @param {number} [timeoutMs]
347
377
  * @returns {Promise<void>}
348
378
  */
349
- waitForAccountTotals(timeoutMs?: any): Promise<void>;
379
+ waitForAccountTotals(timeoutMs?: number): Promise<void>;
350
380
  /**
351
381
  * @param {string} [accountId] - Blockchain account ID
352
382
  * @returns {Promise<void>}
353
383
  */
354
- fetchAccountTotals(accountId: any): Promise<void>;
384
+ fetchAccountTotals(accountId: string | null): Promise<void>;
355
385
  /**
356
386
  * Refresh accountTotals from chain when the cached snapshot is stale.
357
387
  *
@@ -398,13 +428,13 @@ declare class OrderManager {
398
428
  * @returns {Promise<boolean>} true when the re-anchor refreshed successfully
399
429
  */
400
430
  reanchorAccountTotals(label?: string): Promise<boolean>;
401
- _fetchAccountBalancesAndSetTotals(): Promise<any>;
431
+ _fetchAccountBalancesAndSetTotals(): Promise<void>;
402
432
  /**
403
- * @param {any} totals - Account balance totals
433
+ * @param {unknown} totals - Account balance totals
404
434
  * @returns {Promise<void>}
405
435
  */
406
- setAccountTotals(totals?: any): Promise<any>;
407
- _setAccountTotals(totals: any): Promise<void>;
436
+ setAccountTotals(totals?: Partial<AccountTotals>): Promise<void>;
437
+ _setAccountTotals(totals: Partial<AccountTotals>): Promise<void>;
408
438
  _triggerAccountTotalsFetchIfNeeded(): void;
409
439
  /**
410
440
  * @returns {void}
@@ -413,7 +443,7 @@ declare class OrderManager {
413
443
  /**
414
444
  * @returns {Promise<void>}
415
445
  */
416
- recalculateFunds(): Promise<any>;
446
+ recalculateFunds(): Promise<void>;
417
447
  _recalculateFunds(): Promise<void>;
418
448
  /**
419
449
  * Suppress fund recalculation during batch mutations.
@@ -466,42 +496,42 @@ declare class OrderManager {
466
496
  * @param {Object} info
467
497
  * @returns {Promise<any>}
468
498
  */
469
- syncFromOpenOrders(orders: any, info: any): any;
499
+ syncFromOpenOrders(orders: unknown[] | null, info?: UnknownRecord): Promise<SyncResult>;
470
500
  /**
471
501
  * @param {Object} fill - Fill event data
472
502
  * @param {Object} [options]
473
503
  * @returns {Promise<any>}
474
504
  */
475
- syncFromFillHistory(fill: any, options: any): any;
505
+ syncFromFillHistory(fill: unknown, options?: UnknownRecord): Promise<FillHistorySyncResult>;
476
506
  /**
477
507
  * @param {Array} fills - Array of fill event objects (same block group)
478
508
  * @param {Object} [options]
479
509
  * @returns {Promise<any>}
480
510
  */
481
- syncFromFillHistoryBatch(fills: any, options: any): any;
511
+ syncFromFillHistoryBatch(fills: unknown[], options?: UnknownRecord): Promise<FillHistorySyncResult>;
482
512
  /**
483
513
  * @param {Object} data - Chain data to synchronize
484
514
  * @param {string} src - Source identifier
485
515
  * @returns {Promise<any>}
486
516
  */
487
- synchronizeWithChain(data: any, src: any): Promise<any>;
488
- _applySync(data: any, src: any): Promise<any>;
489
- _initializeAssets(): Promise<any>;
517
+ synchronizeWithChain(data: unknown, src: string): Promise<SyncResult>;
518
+ _applySync(data: unknown, src: string): Promise<SyncResult>;
519
+ _initializeAssets(): Promise<void>;
490
520
  /**
491
521
  * @param {string[]|Set<string>} orderIds - Order IDs to lock
492
522
  * @returns {void}
493
523
  */
494
- lockOrders(orderIds: any): void;
524
+ lockOrders(orderIds: Iterable<string> | null | undefined): void;
495
525
  /**
496
526
  * @param {string[]|Set<string>} orderIds - Order IDs to unlock
497
527
  * @returns {void}
498
528
  */
499
- unlockOrders(orderIds: any): void;
529
+ unlockOrders(orderIds: Iterable<string> | null | undefined): void;
500
530
  /**
501
531
  * @param {string} id - Order ID
502
532
  * @returns {boolean}
503
533
  */
504
- isOrderLocked(id: any): boolean;
534
+ isOrderLocked(id: string): boolean;
505
535
  /**
506
536
  * Number of distinct live orders currently shadow-locked.
507
537
  *
@@ -512,31 +542,25 @@ declare class OrderManager {
512
542
  */
513
543
  getActiveShadowLockCount(): number;
514
544
  _cleanExpiredLocks(): void;
515
- _normalizeOrderUpdateOptions(options?: Record<string, any>): {
545
+ _normalizeOrderUpdateOptions(options?: UnknownRecord): {
516
546
  skipAccounting: boolean;
517
547
  fee: number;
518
548
  };
519
- _normalizeCommitOptions(options?: Record<string, any>): {
549
+ _normalizeCommitOptions(options?: UnknownRecord): {
520
550
  skipRecalc: boolean;
521
551
  boundaryHeld: boolean;
522
552
  };
523
- _updateOrder(order: any, context?: any, options?: any): Promise<any>;
524
- _applyOrderUpdate(order: any, context?: any, options?: any): Promise<boolean>;
525
- /**
526
- * Backward-compatible accessor for _currentWorkingGrid.
527
- * Returns the top of the working grid stack (null if empty).
528
- */
529
- get _currentWorkingGrid(): any;
530
- set _currentWorkingGrid(val: any);
531
- _peekWorkingGrid(): any;
532
- _syncWorkingGridFromMasterMutation(orderId: any, context: any): void;
553
+ _updateOrder(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
554
+ _applyOrderUpdate(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
555
+ _peekWorkingGrid(): WorkingGrid | null;
556
+ _syncWorkingGridFromMasterMutation(orderId: string, context: string): void;
533
557
  /**
534
558
  * @param {Array<import('./types').Order>} updates - Order updates to apply
535
559
  * @param {string} [context] - Update context label
536
- * @param {any} [options]
560
+ * @param {unknown} [options]
537
561
  * @returns {Promise<boolean>}
538
562
  */
539
- applyGridUpdateBatch(updates: any, context?: any, options?: any): Promise<any>;
563
+ applyGridUpdateBatch(updates: ManagedOrder[], context?: string, options?: UnknownRecord): Promise<boolean>;
540
564
  /**
541
565
  * Flag the in-memory master grid as dirty so the next flushGridDirty()
542
566
  * call persists it. Internal helper — every successful _applyOrderUpdate
@@ -572,17 +596,12 @@ declare class OrderManager {
572
596
  * @param {string} [contextLabel='flush-grid-dirty'] - Label for logs
573
597
  * @returns {Promise<{skipped?: boolean, suspended?: boolean, isValid?: boolean, reason?: string}>}
574
598
  */
575
- flushGridDirty(contextLabel?: any): Promise<{
599
+ flushGridDirty(contextLabel?: string): Promise<{
576
600
  isValid: boolean;
577
601
  reason: string;
578
602
  } | {
579
603
  isValid: boolean;
580
604
  reason: null;
581
- } | {
582
- isValid: boolean;
583
- skipped: boolean;
584
- suspended: boolean;
585
- reason: any;
586
605
  } | {
587
606
  skipped: boolean;
588
607
  reason: string;
@@ -590,7 +609,7 @@ declare class OrderManager {
590
609
  } | {
591
610
  skipped: boolean;
592
611
  suspended: boolean;
593
- reason: any;
612
+ reason: string;
594
613
  }>;
595
614
  /**
596
615
  * @param {Array<import('./types').Order>} orders - Filled orders
@@ -598,11 +617,11 @@ declare class OrderManager {
598
617
  * @param {Object} [options]
599
618
  * @returns {Promise<any>}
600
619
  */
601
- processFilledOrders(orders: any, excl: any, options?: any): Promise<any>;
620
+ processFilledOrders(orders: COWFillLike[], excl: Set<string>, options?: UnknownRecord): Promise<RebalanceResult>;
602
621
  /**
603
622
  * @returns {Array<import('./types').Order>}
604
623
  */
605
- getInitialOrdersToActivate(): any[];
624
+ getInitialOrdersToActivate(): ManagedOrder[];
606
625
  /**
607
626
  * Get orders matching the specified type and state.
608
627
  *
@@ -610,7 +629,7 @@ declare class OrderManager {
610
629
  * @param {string} state - Order state (ORDER_STATES.ACTIVE/PARTIAL/VIRTUAL)
611
630
  * @returns {Array} Array of matching orders
612
631
  */
613
- getOrdersByTypeAndState(type: any, state: any): any[];
632
+ getOrdersByTypeAndState(type: OrderType | null, state: OrderState): ManagedOrder[];
614
633
  /**
615
634
  * Write boundaryIdx under COW-commit-only discipline.
616
635
  *
@@ -619,7 +638,7 @@ declare class OrderManager {
619
638
  * so a misbehaving caller doesn't silently lose the update, but the warning
620
639
  * flags a violation of the COW boundary-write invariant.
621
640
  */
622
- _setBoundary(newIdx: number): void;
641
+ _setBoundary(newIdx: number | null): void;
623
642
  /**
624
643
  * Restore boundaryIdx outside the COW commit path (startup, recovery,
625
644
  * disk-load). This is the same write as _setBoundary but without the
@@ -650,7 +669,7 @@ declare class OrderManager {
650
669
  *
651
670
  * @param {string} reason - Log/debug label for the drop
652
671
  */
653
- _clearPendingFillCrawls(reason?: any): void;
672
+ _clearPendingFillCrawls(reason?: string): void;
654
673
  /**
655
674
  * Observability (fix #4, docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md §2): emit the live
656
675
  * boundary whenever roles are (re)assigned, so a silent boundary crawl that
@@ -686,7 +705,7 @@ declare class OrderManager {
686
705
  * @param {number} [atMs] - Fill timestamp to preserve (defaults to now)
687
706
  * @returns {boolean} True when the pivot was written
688
707
  */
689
- _setLastFillPivot(type: any, price: number, provenance: 'fill' | 'book', atMs?: number): boolean;
708
+ _setLastFillPivot(type: OrderType, price: number, provenance: 'fill' | 'book', atMs?: number): boolean;
690
709
  /**
691
710
  * Reset the LAST-FILL-GUARD pivot to cold state, clearing the whole
692
711
  * scalar family (per-side mirrors included): leaves seedLastFilledPricesFromBook's
@@ -716,7 +735,7 @@ declare class OrderManager {
716
735
  * cold-check and per-side seeding in seedLastFilledPricesFromBook.
717
736
  * @param {Array} fills
718
737
  */
719
- recordLastFilledPrices(fills: any): void;
738
+ recordLastFilledPrices(fills: COWFillLike[]): void;
720
739
  /**
721
740
  * Seed last-filled guard from the live book at startup. Book-derived
722
741
  * (survives restart), analogous to the deleted MarketAnchor book-seed.
@@ -726,32 +745,45 @@ declare class OrderManager {
726
745
  * the book alone.
727
746
  * @param {Array} chainOpenOrders - raw chain open orders (from readOpenOrdersGuarded)
728
747
  */
729
- seedLastFilledPricesFromBook(chainOpenOrders: any): void;
748
+ seedLastFilledPricesFromBook(chainOpenOrders: unknown[]): void;
730
749
  /**
731
750
  * @returns {Object|null} The consumed signal or null
732
751
  */
733
- consumeIllegalStateSignal(): any;
752
+ consumeIllegalStateSignal(): IllegalStateSignal | null;
734
753
  /**
735
754
  * @returns {Object|null} The consumed signal or null
736
755
  */
737
- consumeAccountingFailureSignal(): any;
756
+ consumeAccountingFailureSignal(): AccountingFailureSignal | null;
738
757
  /**
739
758
  * @param {Object} BitShares - BitShares API instance
740
759
  * @param {Function} batchCb - Batch callback
741
760
  * @returns {Promise<Object>}
742
761
  */
743
- checkSpreadCondition(BitShares: any, batchCb: any): Promise<any>;
762
+ checkSpreadCondition(BitShares: unknown, batchCb?: ((correction: unknown) => Promise<{
763
+ executed?: boolean;
764
+ }>) | null): Promise<{
765
+ ordersPlaced: number;
766
+ partialsMoved: number;
767
+ fundsExhausted?: boolean;
768
+ }>;
744
769
  /**
745
770
  * @param {Function} batchCb - Batch callback
746
771
  * @returns {Promise<Object>}
747
772
  */
748
- checkGridHealth(batchCb: any): Promise<any>;
773
+ checkGridHealth(batchCb?: ((correction: unknown) => Promise<{
774
+ executed?: boolean;
775
+ }>) | null): Promise<{
776
+ buyDust: boolean;
777
+ sellDust: boolean;
778
+ buyDustOrders: unknown[];
779
+ sellDustOrders: unknown[];
780
+ }>;
749
781
  /**
750
782
  * @returns {Object} Current spread calculation
751
783
  */
752
784
  calculateCurrentSpread(): number;
753
785
  /**
754
- * @returns {any}
786
+ * @returns {unknown}
755
787
  */
756
788
  checkFundDriftAfterFills(): {
757
789
  isValid: boolean;
@@ -773,9 +805,9 @@ declare class OrderManager {
773
805
  };
774
806
  /**
775
807
  * @param {Object|number} [pipelineSignals] - Pipeline state signals or queue length
776
- * @returns {any}
808
+ * @returns {unknown}
777
809
  */
778
- isPipelineEmpty(pipelineSignals?: number | Record<string, any>): {
810
+ isPipelineEmpty(pipelineSignals?: number | Record<string, unknown>): {
779
811
  isEmpty: boolean;
780
812
  reasons: string[];
781
813
  };
@@ -788,16 +820,18 @@ declare class OrderManager {
788
820
  * @param {number} targetBoundary
789
821
  * @returns {Object}
790
822
  */
791
- reconcileGrid(targetGrid: any, targetBoundary: any): {
792
- actions: any[];
823
+ reconcileGrid(targetGrid: Map<string, ManagedOrder>, targetBoundary: number | null): {
824
+ actions: CowAction[];
793
825
  aborted: boolean;
794
- boundaryIdx: any;
795
- evacReady: any[];
826
+ boundaryIdx: number | null;
827
+ evacReady: {
828
+ id: string;
829
+ }[];
796
830
  summary: {
797
- total: any;
798
- creates: any;
799
- cancels: any;
800
- updates: any;
831
+ total: number;
832
+ creates: number;
833
+ cancels: number;
834
+ updates: number;
801
835
  };
802
836
  };
803
837
  /**
@@ -825,7 +859,7 @@ declare class OrderManager {
825
859
  * @param {Array} candidates - evacReady candidates [{id, idx, type, price, size, orderId}]
826
860
  * @returns {number} Number of corrections queued
827
861
  */
828
- _processGapEvacuationTeeth(candidates: any): number;
862
+ _processGapEvacuationTeeth(candidates: unknown): number;
829
863
  /**
830
864
  * Wait (bounded) until any non-COW broadcast/placement activity — the
831
865
  * refcounted _broadcastingFlag — has released. Startup/structural
@@ -856,20 +890,32 @@ declare class OrderManager {
856
890
  * on the flag it holds itself.
857
891
  * @returns {Promise<any>}
858
892
  */
859
- performSafeRebalance(fills?: any, excludeIds?: any, options?: any): Promise<any>;
860
- _applySafeRebalanceCOW(fills?: any, excludeIds?: any): Promise<any>;
893
+ performSafeRebalance(fills?: COWFillLike[], excludeIds?: Set<string>, options?: {
894
+ skipBroadcastWait?: boolean;
895
+ deferIfBroadcasting?: boolean;
896
+ [key: string]: unknown;
897
+ }): Promise<RebalanceResult>;
898
+ _applySafeRebalanceCOW(fills?: COWFillLike[], excludeIds?: Set<string>): Promise<RebalanceResult>;
861
899
  _getCowComparePrecisions(): {
862
900
  buyPrecision: number;
863
901
  sellPrecision: number;
864
902
  priceRelativeTolerance: number;
865
903
  };
866
- _commitWorkingGrid(workingGrid: any, _workingIndexes: any, workingBoundary: any, options?: any): Promise<boolean>;
904
+ _commitWorkingGrid(workingGrid: WorkingGrid, _workingIndexes: unknown, workingBoundary: number | null, options?: {
905
+ skipRecalc?: boolean;
906
+ boundaryHeld?: boolean;
907
+ result?: WorkingGridResult;
908
+ [key: string]: unknown;
909
+ }): Promise<boolean>;
867
910
  /**
868
911
  * @param {Object} [options]
869
912
  * @param {boolean} [options.allowBootstrapTransient]
870
- * @returns {any}
913
+ * @returns {unknown}
871
914
  */
872
- validateGridStateForPersistence(options?: Record<string, any>): {
915
+ validateGridStateForPersistence(options?: {
916
+ allowBootstrapTransient?: boolean;
917
+ [key: string]: unknown;
918
+ }): {
873
919
  isValid: boolean;
874
920
  reason: string;
875
921
  } | {
@@ -880,12 +926,12 @@ declare class OrderManager {
880
926
  * @param {string} [reason]
881
927
  * @returns {void}
882
928
  */
883
- suspendGridPersistence(reason?: any): void;
929
+ suspendGridPersistence(reason?: string): void;
884
930
  /**
885
931
  * @param {string} [reason]
886
932
  * @returns {void}
887
933
  */
888
- resumeGridPersistence(reason?: any): void;
934
+ resumeGridPersistence(reason?: string | null): void;
889
935
  /**
890
936
  * @param {Array<Object>} [snapshotOrders] - Optional explicit orders to persist.
891
937
  * When provided, this list is persisted as-is and the live `manager.orders`
@@ -894,9 +940,9 @@ declare class OrderManager {
894
940
  * swapping the live map and exposing it to concurrent readers.
895
941
  * @returns {Promise<any>}
896
942
  */
897
- persistGrid(snapshotOrders: any, recentFillKeys?: any, fundSnapshot?: {
943
+ persistGrid(snapshotOrders?: ManagedOrder[], recentFillKeys?: Record<string, number>, fundSnapshot?: {
898
944
  btsFeesOwed: number;
899
- accountTotals: any;
945
+ accountTotals: AccountTotals;
900
946
  }): Promise<{
901
947
  isValid: boolean;
902
948
  reason: string;
@@ -907,12 +953,12 @@ declare class OrderManager {
907
953
  isValid: boolean;
908
954
  skipped: boolean;
909
955
  suspended: boolean;
910
- reason: any;
956
+ reason: string;
911
957
  }>;
912
- get _lastIllegalState(): any;
913
- set _lastIllegalState(value: any);
914
- get _lastAccountingFailure(): any;
915
- set _lastAccountingFailure(value: any);
958
+ get _lastIllegalState(): IllegalStateSignal | null;
959
+ set _lastIllegalState(value: IllegalStateSignal | null);
960
+ get _lastAccountingFailure(): AccountingFailureSignal | null;
961
+ set _lastAccountingFailure(value: AccountingFailureSignal | null);
916
962
  get _recoveryState(): {
917
963
  phase: string;
918
964
  attemptCount: number;