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
@@ -1,9 +1,9 @@
1
1
  /** Credential client module - connects to credential daemon for key operations */
2
2
  interface BroadcastUncertainErrorDetails {
3
- operations?: any[] | null;
3
+ operations?: unknown[] | null;
4
4
  accountName?: string | null;
5
5
  batchId?: string | null;
6
- payload?: any;
6
+ payload?: unknown;
7
7
  timeoutMs?: number | null;
8
8
  }
9
9
  interface CredentialClientOptions {
@@ -34,7 +34,7 @@ interface CredentialClientOptions {
34
34
  }
35
35
  interface CredentialDaemonMeta {
36
36
  uncertainOnTimeout?: boolean;
37
- operations?: any[] | null;
37
+ operations?: unknown[] | null;
38
38
  accountName?: string | null;
39
39
  batchId?: string | null;
40
40
  }
@@ -42,16 +42,24 @@ export interface CredentialDaemonResponse {
42
42
  success?: boolean;
43
43
  error?: string;
44
44
  code?: string;
45
- raw?: any;
46
- operation_results?: any[];
45
+ raw?: unknown;
46
+ operation_results?: unknown[];
47
47
  /** Transaction envelope returned by some daemon/API broadcast replies. */
48
48
  trx?: {
49
- operation_results?: any[];
50
- [key: string]: any;
49
+ operation_results?: unknown[];
50
+ [key: string]: unknown;
51
51
  } | null;
52
52
  /** Node reported by the daemon as in play at the failure (typed replies). */
53
53
  nodeUrl?: string | null;
54
54
  }
55
+ interface RequestPayload {
56
+ type: string;
57
+ accountName: string;
58
+ operations: unknown[];
59
+ sessionId?: string | null;
60
+ hmac?: string;
61
+ nodeUrl?: string;
62
+ }
55
63
  declare const DEFAULT_SOCKET_PATH: string;
56
64
  declare const DEFAULT_READY_FILE: string;
57
65
  declare const DEFAULT_BROADCAST_TIMEOUT_MS: number;
@@ -72,16 +80,16 @@ declare const DEFAULT_BROADCAST_TIMEOUT_MS: number;
72
80
  */
73
81
  declare class BroadcastUncertainError extends Error {
74
82
  code: string;
75
- operations: any[] | null;
83
+ operations: unknown[] | null;
76
84
  accountName: string | null;
77
85
  batchId: string | null;
78
- payload: any;
86
+ payload: unknown;
79
87
  timeoutMs: number | null;
80
88
  constructor(message: string, details?: BroadcastUncertainErrorDetails);
81
89
  }
82
- declare function sendCredentialDaemonRequest(socketPath: string, payload: any, timeoutMs: number, meta?: CredentialDaemonMeta): Promise<CredentialDaemonResponse>;
90
+ declare function sendCredentialDaemonRequest(socketPath: string, payload: RequestPayload, timeoutMs: number, meta?: CredentialDaemonMeta): Promise<CredentialDaemonResponse>;
83
91
  declare function isCredentialDaemonReady(options?: CredentialClientOptions): boolean;
84
92
  declare function waitForCredentialDaemon(timeoutMs?: number, options?: CredentialClientOptions): Promise<void>;
85
- declare function executeOperationsViaCredentialDaemon(accountName: string, operations: any[], options?: CredentialClientOptions): Promise<CredentialDaemonResponse>;
93
+ declare function executeOperationsViaCredentialDaemon(accountName: string, operations: unknown[], options?: CredentialClientOptions): Promise<CredentialDaemonResponse>;
86
94
  export { DEFAULT_READY_FILE, DEFAULT_SOCKET_PATH, DEFAULT_BROADCAST_TIMEOUT_MS, sendCredentialDaemonRequest, executeOperationsViaCredentialDaemon, isCredentialDaemonReady, waitForCredentialDaemon, BroadcastUncertainError };
87
95
  //# sourceMappingURL=dexbot_credential_client.d.ts.map
@@ -1,9 +1,20 @@
1
1
  /** Fill processing runtime - handles order fill events and replay-safe accounting */
2
+ import * as chainOrders from './chain_orders.js';
3
+ import type { BotLike, ManagerLogger, IncomingFill } from './types.js';
4
+ type ChainOrdersLike = typeof chainOrders;
5
+ export interface FillOpLike {
6
+ order_id?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ type MissingKeyMessageFn = (op: FillOpLike, fill: unknown) => string;
10
+ type FallbackKeyMessageFn = (op: FillOpLike, fill: unknown, fillKey: string) => string;
11
+ export type ReplayMessageFn = (op: FillOpLike, fill: unknown, fillKey: string) => string;
12
+ type FillErrorFn = (op: FillOpLike, fill: unknown, err: unknown) => string;
2
13
  interface SweepOrphanFillOptions {
3
14
  context: string;
4
15
  label: string;
5
- logger?: any;
6
- replayMessage?: any;
16
+ logger?: Partial<ManagerLogger>;
17
+ replayMessage?: ReplayMessageFn;
7
18
  }
8
19
  /**
9
20
  * Handle a sweep fill whose grid order could not be resolved (orphan): derive a
@@ -23,8 +34,8 @@ interface SweepOrphanFillOptions {
23
34
  * @returns true when the fill was missing a replay-safe history identifier OR
24
35
  * the fill was deferred to the adoption sync (order still live on-chain).
25
36
  */
26
- declare function processSweepOrphanFill(bot: any, fill: any, fillOp: any, processedFillKeys: Set<any>, opts: SweepOrphanFillOptions): Promise<boolean>;
27
- declare function wireProcessedFillTracking(bot: any): void;
37
+ declare function processSweepOrphanFill(bot: BotLike, fill: unknown, fillOp: FillOpLike, processedFillKeys: Set<string>, opts: SweepOrphanFillOptions): Promise<boolean>;
38
+ declare function wireProcessedFillTracking(bot: BotLike): void;
28
39
  /**
29
40
  * Flush all pending processed fill writes to persistent storage.
30
41
  * @param {import('./dexbot_class.js').DEXBot} bot
@@ -32,7 +43,7 @@ declare function wireProcessedFillTracking(bot: any): void;
32
43
  * @param {Object} [options] - Flush options forwarded to ProcessedFillStore.flush
33
44
  * @returns {Promise<void>}
34
45
  */
35
- declare function flushProcessedFillPersistence(bot: any, reason?: any, options?: any): Promise<void>;
46
+ declare function flushProcessedFillPersistence(bot: BotLike, reason?: string, options?: Record<string, unknown>): Promise<void>;
36
47
  /**
37
48
  * Flush pending processed fill writes for specific fill keys.
38
49
  * @param {import('./dexbot_class.js').DEXBot} bot
@@ -41,21 +52,28 @@ declare function flushProcessedFillPersistence(bot: any, reason?: any, options?:
41
52
  * @param {Object} [options] - Flush options forwarded to ProcessedFillStore.flushKeys
42
53
  * @returns {Promise<void>}
43
54
  */
44
- declare function flushProcessedFillPersistenceForKeys(bot: any, fillKeys: any, reason?: any, options?: any): Promise<void>;
55
+ declare function flushProcessedFillPersistenceForKeys(bot: BotLike, fillKeys: string[] | Set<string>, reason?: string, options?: Record<string, unknown>): Promise<void>;
45
56
  /**
46
57
  * Build a degraded orphan fill replay key when the standard fill history id is missing.
47
58
  * The fallback key is derived from order_id, block_num, pays/receives amounts and asset IDs.
48
59
  * @param {import('./dexbot_class.js').DEXBot} bot
49
- * @param {any} fill - Raw fill event
60
+ * @param {unknown} fill - Raw fill event
50
61
  * @returns {string|null} Orphan fallback key or null if insufficient data
51
62
  */
52
- declare function buildOrphanFillFallbackKey(bot: any, fill: any): string | null;
63
+ export interface FillLike {
64
+ op?: unknown[];
65
+ block_num?: unknown;
66
+ trx_in_block?: unknown;
67
+ op_in_trx?: unknown;
68
+ [key: string]: unknown;
69
+ }
70
+ declare function buildOrphanFillFallbackKey(bot: BotLike, fill: FillLike): string | null;
53
71
  /**
54
72
  * Apply fill accounting with replay-safe deduplication.
55
73
  * Prevents the same fill from being accounted twice across restarts or re-syncs.
56
74
  * @param {import('./dexbot_class.js').DEXBot} bot
57
- * @param {any} fill - Raw fill event
58
- * @param {any} fillOp - Extracted fill operation data
75
+ * @param {unknown} fill - Raw fill event
76
+ * @param {unknown} fillOp - Extracted fill operation data
59
77
  * @param {Object} [options] - Options
60
78
  * @param {Function} [options.missingKeyMessage] - Callback to generate log message when fill key is missing
61
79
  * @param {Function} [options.fallbackKeyMessage] - Callback to generate log message when fallback key is used
@@ -69,16 +87,16 @@ declare function buildOrphanFillFallbackKey(bot: any, fill: any): string | null;
69
87
  * @param {boolean} [options.allowOrphanFallbackKey=false] - Allow degraded orphan fallback key
70
88
  * @returns {Promise<any>}
71
89
  */
72
- declare function applyReplaySafeFillAccounting(bot: any, fill: any, fillOp: any, { missingKeyMessage, fallbackKeyMessage, replayMessage, errorMessage, logger, missingKeyLevel, fallbackKeyLevel, replayLevel, persistenceMode, allowOrphanFallbackKey }?: {
73
- missingKeyMessage?: any;
74
- fallbackKeyMessage?: any;
75
- replayMessage?: any;
76
- errorMessage?: any;
77
- logger?: any;
90
+ declare function applyReplaySafeFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, { missingKeyMessage, fallbackKeyMessage, replayMessage, errorMessage, logger, missingKeyLevel, fallbackKeyLevel, replayLevel, persistenceMode, allowOrphanFallbackKey }?: {
91
+ missingKeyMessage?: MissingKeyMessageFn;
92
+ fallbackKeyMessage?: FallbackKeyMessageFn;
93
+ replayMessage?: ReplayMessageFn;
94
+ errorMessage?: FillErrorFn;
95
+ logger?: Partial<ManagerLogger>;
78
96
  missingKeyLevel?: string;
79
97
  fallbackKeyLevel?: string;
80
98
  replayLevel?: string;
81
- persistenceMode?: any;
99
+ persistenceMode?: string;
82
100
  allowOrphanFallbackKey?: boolean;
83
101
  }): Promise<{
84
102
  status: string;
@@ -93,15 +111,22 @@ declare function applyReplaySafeFillAccounting(bot: any, fill: any, fillOp: any,
93
111
  } | {
94
112
  status: string;
95
113
  fillKey: any;
96
- error: any;
114
+ error: unknown;
97
115
  usedFallbackKey?: undefined;
98
116
  }>;
117
+ /** Shared options for the replay-safe accounting wrappers. */
118
+ interface ReplaySafeFillAccountingOptions {
119
+ context?: string;
120
+ logger?: Partial<ManagerLogger>;
121
+ replayMessage?: ReplayMessageFn;
122
+ persistenceMode?: string;
123
+ }
99
124
  /**
100
125
  * Apply replay-safe fill accounting for tracked fills (with fill history id).
101
126
  * Wraps applyReplaySafeFillAccounting with context and default message builders.
102
127
  * @param {import('./dexbot_class.js').DEXBot} bot
103
- * @param {any} fill - Raw fill event
104
- * @param {any} fillOp - Extracted fill operation data
128
+ * @param {unknown} fill - Raw fill event
129
+ * @param {unknown} fillOp - Extracted fill operation data
105
130
  * @param {Object} [options] - Options
106
131
  * @param {string} [options.context] - Context label for log messages
107
132
  * @param {Object} [options.logger] - Logger instance
@@ -109,12 +134,7 @@ declare function applyReplaySafeFillAccounting(bot: any, fill: any, fillOp: any,
109
134
  * @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
110
135
  * @returns {Promise<any>}
111
136
  */
112
- declare function applyReplaySafeTrackedFillAccounting(bot: any, fill: any, fillOp: any, { context, logger, replayMessage, persistenceMode }?: {
113
- context?: string;
114
- logger?: any;
115
- replayMessage?: any;
116
- persistenceMode?: any;
117
- }): Promise<{
137
+ declare function applyReplaySafeTrackedFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
118
138
  status: string;
119
139
  fillKey: any;
120
140
  usedFallbackKey?: undefined;
@@ -127,15 +147,15 @@ declare function applyReplaySafeTrackedFillAccounting(bot: any, fill: any, fillO
127
147
  } | {
128
148
  status: string;
129
149
  fillKey: any;
130
- error: any;
150
+ error: unknown;
131
151
  usedFallbackKey?: undefined;
132
152
  }>;
133
153
  /**
134
154
  * Apply replay-safe fill accounting for orphan fills (missing fill history id).
135
155
  * Uses a degraded orphan fallback key when the standard key is unavailable.
136
156
  * @param {import('./dexbot_class.js').DEXBot} bot
137
- * @param {any} fill - Raw fill event
138
- * @param {any} fillOp - Extracted fill operation data
157
+ * @param {unknown} fill - Raw fill event
158
+ * @param {unknown} fillOp - Extracted fill operation data
139
159
  * @param {Object} [options] - Options
140
160
  * @param {string} [options.context] - Context label for log messages
141
161
  * @param {Object} [options.logger] - Logger instance
@@ -143,12 +163,7 @@ declare function applyReplaySafeTrackedFillAccounting(bot: any, fill: any, fillO
143
163
  * @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
144
164
  * @returns {Promise<any>}
145
165
  */
146
- declare function applyReplaySafeOrphanFillAccounting(bot: any, fill: any, fillOp: any, { context, logger, replayMessage, persistenceMode }?: {
147
- context?: string;
148
- logger?: any;
149
- replayMessage?: any;
150
- persistenceMode?: any;
151
- }): Promise<{
166
+ declare function applyReplaySafeOrphanFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
152
167
  status: string;
153
168
  fillKey: any;
154
169
  usedFallbackKey?: undefined;
@@ -161,7 +176,7 @@ declare function applyReplaySafeOrphanFillAccounting(bot: any, fill: any, fillOp
161
176
  } | {
162
177
  status: string;
163
178
  fillKey: any;
164
- error: any;
179
+ error: unknown;
165
180
  usedFallbackKey?: undefined;
166
181
  }>;
167
182
  /**
@@ -171,7 +186,7 @@ declare function applyReplaySafeOrphanFillAccounting(bot: any, fill: any, fillOp
171
186
  * @param {Object} chainOrders - Chain orders module
172
187
  * @returns {Function} Async callback function accepting an array of fill events
173
188
  */
174
- declare function createFillCallback(bot: any, chainOrders: any): (fills: any) => Promise<void>;
189
+ declare function createFillCallback(bot: BotLike, chainOrders: ChainOrdersLike): (fills: IncomingFill[]) => Promise<void>;
175
190
  /**
176
191
  * Consume the deferred-drain marker at the start of a fill cycle.
177
192
  *
@@ -182,10 +197,10 @@ declare function createFillCallback(bot: any, chainOrders: any): (fills: any) =>
182
197
  * manager._orphanFillsCreditedAt so the fund-invariant tolerance is widened
183
198
  * (×5) for this cycle only — the drain itself must not trip the invariant.
184
199
  * Idempotent: returns true only when a marker was actually consumed.
185
- * @param {any} bot
200
+ * @param {unknown} bot
186
201
  * @returns {boolean} true when the drain marker was consumed (tolerance widened)
187
202
  */
188
- export declare function consumeDeferredDrainMarker(bot: any): boolean;
203
+ export declare function consumeDeferredDrainMarker(bot: BotLike): boolean;
189
204
  /**
190
205
  * Decide whether the fill consumer must defer because a broadcast region is
191
206
  * active — WITHOUT acquiring _fillProcessingLock first.
@@ -213,7 +228,7 @@ export declare function consumeDeferredDrainMarker(bot: any): boolean;
213
228
  * @returns {{ defer: boolean; stuckFallback: boolean }} defer=true means the
214
229
  * caller must return without acquiring the lock.
215
230
  */
216
- declare function shouldDeferFillForBroadcast(bot: any, nowMs?: number): {
231
+ declare function shouldDeferFillForBroadcast(bot: BotLike, nowMs?: number): {
217
232
  defer: boolean;
218
233
  stuckFallback: boolean;
219
234
  };
@@ -224,7 +239,7 @@ declare function shouldDeferFillForBroadcast(bot: any, nowMs?: number): {
224
239
  * @param {import('./dexbot_class.js').DEXBot} bot
225
240
  * @param {Object} chainOrders - Chain orders module
226
241
  */
227
- declare function scheduleFillConsumerRestart(bot: any, chainOrders: any): void;
242
+ declare function scheduleFillConsumerRestart(bot: BotLike, chainOrders: ChainOrdersLike): void;
228
243
  /**
229
244
  * Level-triggered retry for fills parked by consumeFillQueue's pre-lock
230
245
  * gates (order-pipeline or broadcast deferral).
@@ -243,13 +258,13 @@ declare function scheduleFillConsumerRestart(bot: any, chainOrders: any): void;
243
258
  * drains; once drained the timer settles. At most one retry is pending per
244
259
  * bot. The timer is unref'd so a parked queue never holds the process open
245
260
  * (and fakes that never clear the gate cannot hang the test runner).
246
- * @param {any} bot
261
+ * @param {unknown} bot
247
262
  * @param {Object} chainOrders - Chain orders module for blockchain operations
248
263
  * @param {string} reason - Gate label for logging
249
264
  * @param {Object} [options]
250
265
  * @param {number} [options.retryDelayMs] - Override the derived backoff (tests)
251
266
  */
252
- declare function scheduleDeferredFillRetry(bot: any, chainOrders: any, reason: string, options?: {
267
+ declare function scheduleDeferredFillRetry(bot: BotLike, chainOrders: ChainOrdersLike, reason: string, options?: {
253
268
  retryDelayMs?: number;
254
269
  }): void;
255
270
  /**
@@ -259,7 +274,7 @@ declare function scheduleDeferredFillRetry(bot: any, chainOrders: any, reason: s
259
274
  * @param {Object} chainOrders - Chain orders module for blockchain operations
260
275
  * @returns {Promise<void>}
261
276
  */
262
- declare function processFillsWithBootstrapMode(bot: any, chainOrders: any): Promise<void>;
277
+ declare function processFillsWithBootstrapMode(bot: BotLike, chainOrders: ChainOrdersLike): Promise<void>;
263
278
  /**
264
279
  * Park fills deferred on a stale accountTotals refresh for a bounded retry.
265
280
  *
@@ -276,13 +291,13 @@ declare function processFillsWithBootstrapMode(bot: any, chainOrders: any): Prom
276
291
  * released. Retries never stop (attempt counter resets on the first cycle
277
292
  * with no deferrals); the parked array is capped at MAX_INCOMING_FILL_QUEUE
278
293
  * with a critical log as a catastrophic backstop.
279
- * @param {any} bot
294
+ * @param {unknown} bot
280
295
  * @param {Object} chainOrders - Chain orders module for blockchain operations
281
- * @param {any[]} fills - Raw fill events to park
296
+ * @param {unknown[]} fills - Raw fill events to park
282
297
  * @param {Object} [options]
283
298
  * @param {number} [options.retryDelayMs] - Override the computed backoff (tests)
284
299
  */
285
- export declare function parkFillsForTotalsRetry(bot: any, chainOrders: any, fills: any[], options?: {
300
+ export declare function parkFillsForTotalsRetry(bot: BotLike, chainOrders: ChainOrdersLike, fills: unknown[], options?: {
286
301
  retryDelayMs?: number;
287
302
  }): void;
288
303
  /**
@@ -294,6 +309,6 @@ export declare function parkFillsForTotalsRetry(bot: any, chainOrders: any, fill
294
309
  * @param {import('./dexbot_class.js').DEXBot} bot
295
310
  * @param {Object} chainOrders - Chain orders module for blockchain operations
296
311
  */
297
- declare function consumeFillQueue(bot: any, chainOrders: any): Promise<void>;
312
+ declare function consumeFillQueue(bot: BotLike, chainOrders: ChainOrdersLike): Promise<void>;
298
313
  export { wireProcessedFillTracking, flushProcessedFillPersistence, flushProcessedFillPersistenceForKeys, buildOrphanFillFallbackKey, applyReplaySafeFillAccounting, applyReplaySafeTrackedFillAccounting, applyReplaySafeOrphanFillAccounting, processSweepOrphanFill, createFillCallback, scheduleFillConsumerRestart, scheduleDeferredFillRetry, shouldDeferFillForBroadcast, consumeFillQueue, processFillsWithBootstrapMode };
299
314
  //# sourceMappingURL=dexbot_fill_runtime.d.ts.map
@@ -4,7 +4,7 @@ const require = createRequire(import.meta.url);
4
4
  import * as chainOrders from './chain_orders.js';
5
5
  import { PROCESSED_FILL_PERSISTENCE_MODES } from './order/processed_fill_store.js';
6
6
  import { NATIVE_CLIENT, FILL_PROCESSING, TIMING, MAINTENANCE, ORDER_TYPES } from './constants.js';
7
- import { getErrorMessage, resolveSeamMsOrNull } from './utils/errors.js';
7
+ import { getErrorMessage, resolveSeamMsOrNull, getErrorField } from './utils/errors.js';
8
8
  import { isOrderDoesNotExistError } from './dexbot_maintenance_runtime.js';
9
9
  import { slotIndexForPrice, isChainPriceOutOfGrid, isSlotInRail } from './order/utils/math.js';
10
10
  import { ORDER_STATES } from './constants.js';
@@ -21,7 +21,7 @@ const { readOpenOrdersGuarded } = chainOrders;
21
21
  * orders on shared accounts or other markets, which keep the legacy
22
22
  * credit-as-orphan path.
23
23
  * @param {import('./dexbot_class.js').DEXBot} bot
24
- * @param {any} fillOp - Fill operation ({order_id, ...})
24
+ * @param {unknown} fillOp - Fill operation ({order_id, ...})
25
25
  * @returns {Promise<boolean>} True when the order is live and in-grid-range
26
26
  */
27
27
  async function isUnknownFillOrderAdoptable(bot, fillOp) {
@@ -82,7 +82,7 @@ async function isUnknownFillOrderAdoptable(bot, fillOp) {
82
82
  }
83
83
  let minPrice = Infinity;
84
84
  let maxPrice = 0;
85
- for (const o of (bot.manager?.orders?.values?.() ?? [])) {
85
+ for (const o of Array.from(bot.manager?.orders?.values?.() ?? [])) {
86
86
  const p = Number(o?.price);
87
87
  if (!Number.isFinite(p) || p <= 0)
88
88
  continue;
@@ -128,7 +128,7 @@ async function processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, opts
128
128
  return false;
129
129
  }
130
130
  if (await isUnknownFillOrderAdoptable(bot, fillOp)) {
131
- (opts.logger ?? bot.manager.logger).log(`[${opts.label}] Unknown order ${fillOp.order_id} is LIVE on-chain inside grid range — deferring proceeds credit to adoption sync`, 'warn');
131
+ (opts.logger ?? bot.manager.logger).log?.(`[${opts.label}] Unknown order ${fillOp.order_id} is LIVE on-chain inside grid range — deferring proceeds credit to adoption sync`, 'warn');
132
132
  // Release the dedupe key consumed by _isNewFillKey so the fill can be
133
133
  // re-processed against the adopted slot after the sync runs.
134
134
  if (orphanFillKey) {
@@ -137,7 +137,7 @@ async function processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, opts
137
137
  }
138
138
  return true;
139
139
  }
140
- (opts.logger ?? bot.manager.logger).log(`[${opts.label}] Processing funds for unknown order ${fillOp.order_id} (not in grid but crediting proceeds)`, 'warn');
140
+ (opts.logger ?? bot.manager.logger).log?.(`[${opts.label}] Processing funds for unknown order ${fillOp.order_id} (not in grid but crediting proceeds)`, 'warn');
141
141
  const accountingResult = await bot._applyReplaySafeOrphanFillAccounting(fill, fillOp, {
142
142
  context: opts.context,
143
143
  logger: opts.logger,
@@ -208,21 +208,16 @@ async function flushProcessedFillPersistenceForKeys(bot, fillKeys, reason = 'man
208
208
  bot._processedFillStore.setShuttingDown(bot._shuttingDown);
209
209
  await bot._processedFillStore.flushKeys(fillKeys, reason, options);
210
210
  }
211
- /**
212
- * Build a degraded orphan fill replay key when the standard fill history id is missing.
213
- * The fallback key is derived from order_id, block_num, pays/receives amounts and asset IDs.
214
- * @param {import('./dexbot_class.js').DEXBot} bot
215
- * @param {any} fill - Raw fill event
216
- * @returns {string|null} Orphan fallback key or null if insufficient data
217
- */
218
211
  function buildOrphanFillFallbackKey(bot, fill) {
219
212
  const fillOp = fill?.op?.[1];
220
213
  const orderId = fillOp?.order_id;
221
214
  const blockNum = fill?.block_num;
222
- const paysAssetId = fillOp?.pays?.asset_id;
223
- const paysAmount = fillOp?.pays?.amount;
224
- const receivesAssetId = fillOp?.receives?.asset_id;
225
- const receivesAmount = fillOp?.receives?.amount;
215
+ const pays = fillOp?.pays;
216
+ const receives = fillOp?.receives;
217
+ const paysAssetId = pays?.asset_id;
218
+ const paysAmount = pays?.amount;
219
+ const receivesAssetId = receives?.asset_id;
220
+ const receivesAmount = receives?.amount;
226
221
  if (fillOp?.is_maker == null) {
227
222
  bot?._warn?.(`[ORPHAN-FALLBACK] is_maker undefined for fill ${fillOp?.order_id}; defaulting to 'maker' for dedup key`);
228
223
  }
@@ -242,8 +237,8 @@ function buildOrphanFillFallbackKey(bot, fill) {
242
237
  * Apply fill accounting with replay-safe deduplication.
243
238
  * Prevents the same fill from being accounted twice across restarts or re-syncs.
244
239
  * @param {import('./dexbot_class.js').DEXBot} bot
245
- * @param {any} fill - Raw fill event
246
- * @param {any} fillOp - Extracted fill operation data
240
+ * @param {unknown} fill - Raw fill event
241
+ * @param {unknown} fillOp - Extracted fill operation data
247
242
  * @param {Object} [options] - Options
248
243
  * @param {Function} [options.missingKeyMessage] - Callback to generate log message when fill key is missing
249
244
  * @param {Function} [options.fallbackKeyMessage] - Callback to generate log message when fallback key is used
@@ -291,12 +286,20 @@ async function applyReplaySafeFillAccounting(bot, fill, fillOp, { missingKeyMess
291
286
  throw err;
292
287
  }
293
288
  }
289
+ /**
290
+ * Resolve wrapper options with shared defaults (logger falls back to the
291
+ * manager's logger, persistence mode to batched). Centralized so both
292
+ * wrappers apply identical defaults.
293
+ */
294
+ function resolveReplaySafeFillOptions(bot, { context, logger = bot.manager?.logger, replayMessage, persistenceMode = PROCESSED_FILL_PERSISTENCE_MODES.BATCHED, } = {}) {
295
+ return { context, logger, replayMessage, persistenceMode };
296
+ }
294
297
  /**
295
298
  * Apply replay-safe fill accounting for tracked fills (with fill history id).
296
299
  * Wraps applyReplaySafeFillAccounting with context and default message builders.
297
300
  * @param {import('./dexbot_class.js').DEXBot} bot
298
- * @param {any} fill - Raw fill event
299
- * @param {any} fillOp - Extracted fill operation data
301
+ * @param {unknown} fill - Raw fill event
302
+ * @param {unknown} fillOp - Extracted fill operation data
300
303
  * @param {Object} [options] - Options
301
304
  * @param {string} [options.context] - Context label for log messages
302
305
  * @param {Object} [options.logger] - Logger instance
@@ -304,7 +307,8 @@ async function applyReplaySafeFillAccounting(bot, fill, fillOp, { missingKeyMess
304
307
  * @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
305
308
  * @returns {Promise<any>}
306
309
  */
307
- async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, { context, logger = bot.manager?.logger, replayMessage, persistenceMode = PROCESSED_FILL_PERSISTENCE_MODES.BATCHED } = {}) {
310
+ async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, options = {}) {
311
+ const { context, logger, replayMessage, persistenceMode } = resolveReplaySafeFillOptions(bot, options);
308
312
  return applyReplaySafeFillAccounting(bot, fill, fillOp, {
309
313
  logger,
310
314
  missingKeyMessage: (op) => `[${context}] Missing fill history id for ${op.order_id}; deferring to open-orders sync`,
@@ -317,8 +321,8 @@ async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, { context
317
321
  * Apply replay-safe fill accounting for orphan fills (missing fill history id).
318
322
  * Uses a degraded orphan fallback key when the standard key is unavailable.
319
323
  * @param {import('./dexbot_class.js').DEXBot} bot
320
- * @param {any} fill - Raw fill event
321
- * @param {any} fillOp - Extracted fill operation data
324
+ * @param {unknown} fill - Raw fill event
325
+ * @param {unknown} fillOp - Extracted fill operation data
322
326
  * @param {Object} [options] - Options
323
327
  * @param {string} [options.context] - Context label for log messages
324
328
  * @param {Object} [options.logger] - Logger instance
@@ -326,7 +330,8 @@ async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, { context
326
330
  * @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
327
331
  * @returns {Promise<any>}
328
332
  */
329
- async function applyReplaySafeOrphanFillAccounting(bot, fill, fillOp, { context, logger = bot.manager?.logger, replayMessage, persistenceMode = PROCESSED_FILL_PERSISTENCE_MODES.BATCHED } = {}) {
333
+ async function applyReplaySafeOrphanFillAccounting(bot, fill, fillOp, options = {}) {
334
+ const { context, logger, replayMessage, persistenceMode } = resolveReplaySafeFillOptions(bot, options);
330
335
  return applyReplaySafeFillAccounting(bot, fill, fillOp, {
331
336
  logger,
332
337
  missingKeyMessage: (op) => `[${context}] Missing fill history id and orphan fallback key for ${op.order_id}; deferring to open-orders sync`,
@@ -383,8 +388,8 @@ function maxConsecutiveFillConsumerFailures(bot) {
383
388
  */
384
389
  function computeFillConsumerBackoffMs(bot, failures) {
385
390
  const fp = bot.config.fillProcessing || FILL_PROCESSING;
386
- const initial = fp.CONSUMER_BACKOFF_INITIAL_MS;
387
- const max = fp.CONSUMER_BACKOFF_MAX_MS;
391
+ const initial = fp.CONSUMER_BACKOFF_INITIAL_MS ?? FILL_PROCESSING.CONSUMER_BACKOFF_INITIAL_MS;
392
+ const max = fp.CONSUMER_BACKOFF_MAX_MS ?? FILL_PROCESSING.CONSUMER_BACKOFF_MAX_MS;
388
393
  const stepAfterMax = Math.max(0, failures - maxConsecutiveFillConsumerFailures(bot));
389
394
  return Math.min(max, initial * Math.pow(2, stepAfterMax));
390
395
  }
@@ -398,7 +403,7 @@ function computeFillConsumerBackoffMs(bot, failures) {
398
403
  * manager._orphanFillsCreditedAt so the fund-invariant tolerance is widened
399
404
  * (×5) for this cycle only — the drain itself must not trip the invariant.
400
405
  * Idempotent: returns true only when a marker was actually consumed.
401
- * @param {any} bot
406
+ * @param {unknown} bot
402
407
  * @returns {boolean} true when the drain marker was consumed (tolerance widened)
403
408
  */
404
409
  export function consumeDeferredDrainMarker(bot) {
@@ -554,7 +559,7 @@ function scheduleFillConsumerRestart(bot, chainOrders) {
554
559
  * drains; once drained the timer settles. At most one retry is pending per
555
560
  * bot. The timer is unref'd so a parked queue never holds the process open
556
561
  * (and fakes that never clear the gate cannot hang the test runner).
557
- * @param {any} bot
562
+ * @param {unknown} bot
558
563
  * @param {Object} chainOrders - Chain orders module for blockchain operations
559
564
  * @param {string} reason - Gate label for logging
560
565
  * @param {Object} [options]
@@ -639,7 +644,7 @@ async function processFillsWithBootstrapMode(bot, chainOrders) {
639
644
  continue;
640
645
  const fillOp = fill.op[1];
641
646
  const gridOrder = bot.manager.orders.get(fillOp.order_id) ||
642
- Array.from(bot.manager.orders.values()).find((o) => o.orderId === fillOp.order_id);
647
+ (Array.from(bot.manager.orders.values())).find((o) => o.orderId === fillOp.order_id);
643
648
  if (!gridOrder) {
644
649
  if (await processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, { context: 'BOOTSTRAP', label: 'BOOTSTRAP' })) {
645
650
  requiresOpenOrdersSync = true;
@@ -722,9 +727,9 @@ async function processFillsWithBootstrapMode(bot, chainOrders) {
722
727
  * re-queued fill is skipped as a duplicate within _fillDedupeWindowMs — the
723
728
  * deferral would credit nothing AND poison the retry. Mirrors the
724
729
  * orphan-adoption release in processSweepOrphanFill.
725
- * @param {any} bot
730
+ * @param {unknown} bot
726
731
  * @param {Set<any>} processedFillKeys - Per-cycle key set to release from
727
- * @param {any[]} fills - Raw fill events whose keys were consumed
732
+ * @param {unknown[]} fills - Raw fill events whose keys were consumed
728
733
  */
729
734
  function releaseFillDedupeKeys(bot, processedFillKeys, fills) {
730
735
  if (!bot || !processedFillKeys || !Array.isArray(fills))
@@ -756,9 +761,9 @@ function releaseFillDedupeKeys(bot, processedFillKeys, fills) {
756
761
  * released. Retries never stop (attempt counter resets on the first cycle
757
762
  * with no deferrals); the parked array is capped at MAX_INCOMING_FILL_QUEUE
758
763
  * with a critical log as a catastrophic backstop.
759
- * @param {any} bot
764
+ * @param {unknown} bot
760
765
  * @param {Object} chainOrders - Chain orders module for blockchain operations
761
- * @param {any[]} fills - Raw fill events to park
766
+ * @param {unknown[]} fills - Raw fill events to park
762
767
  * @param {Object} [options]
763
768
  * @param {number} [options.retryDelayMs] - Override the computed backoff (tests)
764
769
  */
@@ -768,7 +773,7 @@ export function parkFillsForTotalsRetry(bot, chainOrders, fills, options = {}) {
768
773
  if (!Array.isArray(bot._fillTotalsParkedFills))
769
774
  bot._fillTotalsParkedFills = [];
770
775
  const parked = bot._fillTotalsParkedFills;
771
- const maxParked = Number(NATIVE_CLIENT?.SUBSCRIPTIONS?.MAX_INCOMING_FILL_QUEUE) > 0
776
+ const maxParked = Number(NATIVE_CLIENT.SUBSCRIPTIONS.MAX_INCOMING_FILL_QUEUE) > 0
772
777
  ? Number(NATIVE_CLIENT.SUBSCRIPTIONS.MAX_INCOMING_FILL_QUEUE)
773
778
  : 1000;
774
779
  if (parked.length + fills.length > maxParked) {
@@ -987,7 +992,7 @@ async function consumeFillQueue(bot, chainOrders) {
987
992
  continue;
988
993
  }
989
994
  const gridOrder = bot.manager.orders.get(fillOp.order_id) ||
990
- Array.from(bot.manager.orders.values()).find((o) => o.orderId === fillOp.order_id);
995
+ (Array.from(bot.manager.orders.values())).find((o) => o.orderId === fillOp.order_id);
991
996
  if (!gridOrder) {
992
997
  const staleMarkedAt = bot._staleCleanedOrderIds.get(fillOp.order_id);
993
998
  if (staleMarkedAt != null) {
@@ -1020,7 +1025,7 @@ async function consumeFillQueue(bot, chainOrders) {
1020
1025
  if (!bot._isNewFillKey(fillKey, processedFillKeys, '[FILL]', fillOp.order_id)) {
1021
1026
  continue;
1022
1027
  }
1023
- validFills.push(fill);
1028
+ validFills.push({ ...fill, gridOrder });
1024
1029
  const paysAmount = fillOp.pays ? fillOp.pays.amount : '?';
1025
1030
  const receivesAmount = fillOp.receives ? fillOp.receives.amount : '?';
1026
1031
  // Asset IDs are logged alongside the raw satoshi amounts so
@@ -1164,8 +1169,9 @@ async function consumeFillQueue(bot, chainOrders) {
1164
1169
  const initialRequiresSync = requiresOpenOrdersSync;
1165
1170
  for (const blockNum of sortedBlocks) {
1166
1171
  requiresOpenOrdersSync = false;
1167
- bot.manager.logger.log(`[FILL-BLOCK] Processing ${fillsByBlock.get(blockNum).length} fill(s) from block ${blockNum}`, 'debug');
1168
- const blockResult = await processValidFills(fillsByBlock.get(blockNum));
1172
+ const blockFills = fillsByBlock.get(blockNum) ?? [];
1173
+ bot.manager.logger.log(`[FILL-BLOCK] Processing ${blockFills.length} fill(s) from block ${blockNum}`, 'debug');
1174
+ const blockResult = await processValidFills(blockFills);
1169
1175
  accumulatedOrders.push(...blockResult);
1170
1176
  if (requiresOpenOrdersSync)
1171
1177
  anyRequiresSync = true;
@@ -1278,7 +1284,7 @@ async function consumeFillQueue(bot, chainOrders) {
1278
1284
  : 100;
1279
1285
  if (bot._fillCleanupCounter >= cleanupThreshold) {
1280
1286
  try {
1281
- await bot.accountOrders.cleanOldProcessedFills(TIMING.FILL_RECORD_RETENTION_MS);
1287
+ await bot.accountOrders?.cleanOldProcessedFills(TIMING.FILL_RECORD_RETENTION_MS);
1282
1288
  bot._fillCleanupCounter = 0;
1283
1289
  }
1284
1290
  catch (err) {
@@ -1336,8 +1342,9 @@ async function consumeFillQueue(bot, chainOrders) {
1336
1342
  bot._suspendGridPersistenceForCredentialOutage(`credential outage during fill processing: ${getErrorMessage(err)}`);
1337
1343
  }
1338
1344
  bot._log(`Error processing fills: ${getErrorMessage(err)}`, 'error');
1339
- if (err.stack)
1340
- bot._log(err.stack, 'error');
1345
+ const errorStack = getErrorField(err, 'stack');
1346
+ if (errorStack)
1347
+ bot._log(errorStack, 'error');
1341
1348
  }
1342
1349
  // Clean settle: a drain that reached the end with an empty queue is the
1343
1350
  // only place the retry counter is retired — otherwise the elevated count