dexbot 1.6.11 → 1.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +2 -1
  3. package/analysis/README.md +11 -11
  4. package/analysis/ama_fitting/README.md +5 -3
  5. package/analysis/tradingview/README.md +1 -1
  6. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
  7. package/claw/README.md +1 -0
  8. package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
  9. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  10. package/claw/modules/chain_broadcast.ts +7 -1
  11. package/claw/modules/claw_bridge.ts +0 -3
  12. package/claw/modules/claw_launcher.ts +1 -1
  13. package/claw/modules/claw_skill_md.ts +1 -0
  14. package/claw/modules/launcher_mode_detector.ts +9 -2
  15. package/claw/package.json +3 -3
  16. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  17. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  18. package/claw/tsconfig.json +2 -2
  19. package/dist/analysis/account_resolver.d.ts +1 -1
  20. package/dist/analysis/account_resolver.js +2 -1
  21. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  22. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +3 -21
  23. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  24. package/dist/analysis/ama_fitting/fetch_lp_candles.js +55 -45
  25. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -8
  26. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +45 -24
  27. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +34 -78
  28. package/dist/analysis/analyze_args.d.ts +43 -0
  29. package/dist/analysis/analyze_args.js +61 -0
  30. package/dist/analysis/analyze_dynamic_weight.js +7 -17
  31. package/dist/analysis/analyze_kalman.js +7 -17
  32. package/dist/analysis/analyze_regime.js +7 -17
  33. package/dist/analysis/analyze_regime_windows.js +8 -18
  34. package/dist/analysis/analyze_risk_profile.js +8 -18
  35. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  36. package/dist/analysis/analyze_volatility.js +7 -17
  37. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +221 -28
  38. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +23 -103
  39. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  40. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +32 -150
  41. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
  42. package/dist/analysis/bot_fitting/shared_utils.d.ts +77 -9
  43. package/dist/analysis/bot_fitting/shared_utils.js +125 -9
  44. package/dist/analysis/bot_key_utils.d.ts +18 -10
  45. package/dist/analysis/bot_key_utils.js +7 -4
  46. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  47. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  48. package/dist/analysis/chain_pool.d.ts +3 -1
  49. package/dist/analysis/chart_ui.d.ts +35 -3
  50. package/dist/analysis/chart_ui.js +43 -4
  51. package/dist/analysis/chart_utils.d.ts +5 -5
  52. package/dist/analysis/chart_utils.js +9 -0
  53. package/dist/analysis/fills_cache.d.ts +4 -24
  54. package/dist/analysis/fills_cache.js +3 -84
  55. package/dist/analysis/fills_source.d.ts +33 -3
  56. package/dist/analysis/fills_source.js +83 -13
  57. package/dist/analysis/grid_correction_check.d.ts +2 -24
  58. package/dist/analysis/grid_correction_check.js +27 -69
  59. package/dist/analysis/math_utils.d.ts +91 -6
  60. package/dist/analysis/math_utils.js +119 -7
  61. package/dist/analysis/pnl_report.js +29 -29
  62. package/dist/analysis/price_sources.d.ts +30 -9
  63. package/dist/analysis/price_sources.js +28 -4
  64. package/dist/analysis/resolve_bot_accounts.js +2 -2
  65. package/dist/analysis/resolve_source.d.ts +1 -1
  66. package/dist/analysis/resolve_source.js +31 -10
  67. package/dist/analysis/trade_profitability.d.ts +29 -2
  68. package/dist/analysis/trade_profitability.js +73 -147
  69. package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -8
  70. package/dist/analysis/tradingview/analyze_tradingview.js +7 -6
  71. package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
  72. package/dist/analysis/tradingview/grid_reset_config.js +23 -11
  73. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
  74. package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
  75. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  76. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -34
  77. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
  78. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +26 -84
  79. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  80. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +16 -41
  81. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
  82. package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
  83. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  84. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  85. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  86. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  87. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  88. package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
  89. package/dist/analysis/worker_pool.d.ts +38 -0
  90. package/dist/analysis/worker_pool.js +67 -0
  91. package/dist/credential-daemon.js +34 -20
  92. package/dist/dexbot.js +78 -59
  93. package/dist/market_adapter/ama_signal_runner.js +21 -54
  94. package/dist/market_adapter/candle_utils.d.ts +29 -19
  95. package/dist/market_adapter/candle_utils.js +35 -21
  96. package/dist/market_adapter/cli_args.d.ts +22 -0
  97. package/dist/market_adapter/cli_args.js +30 -0
  98. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  99. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  100. package/dist/market_adapter/core/config_normalizers.js +11 -6
  101. package/dist/market_adapter/core/kibana_candles.d.ts +56 -19
  102. package/dist/market_adapter/core/kibana_candles.js +12 -9
  103. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  104. package/dist/market_adapter/core/kibana_client.js +8 -7
  105. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  106. package/dist/market_adapter/core/market_adapter_service.d.ts +320 -153
  107. package/dist/market_adapter/core/market_adapter_service.js +228 -269
  108. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
  109. package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
  110. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
  111. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
  112. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  113. package/dist/market_adapter/core/strategies/ama.js +2 -4
  114. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  115. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  116. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  117. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  118. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  119. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  120. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
  121. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
  122. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  123. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  124. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  125. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  126. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  127. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  128. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  129. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  130. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  131. package/dist/market_adapter/inputs/fetch_book_data.js +3 -2
  132. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +160 -332
  133. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +50 -8
  134. package/dist/market_adapter/inputs/fetch_lp_data.js +47 -22
  135. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  136. package/dist/market_adapter/inputs/kibana_feed_source.js +26 -41
  137. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  138. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  139. package/dist/market_adapter/inputs/window_cache.d.ts +93 -156
  140. package/dist/market_adapter/inputs/window_cache.js +59 -184
  141. package/dist/market_adapter/interval_utils.d.ts +15 -5
  142. package/dist/market_adapter/interval_utils.js +16 -1
  143. package/dist/market_adapter/log_format.d.ts +6 -6
  144. package/dist/market_adapter/log_format.js +28 -21
  145. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  146. package/dist/market_adapter/lp_chart_core.js +26 -192
  147. package/dist/market_adapter/lp_chart_runner.d.ts +10 -7
  148. package/dist/market_adapter/lp_chart_runner.js +37 -19
  149. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  150. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  151. package/dist/market_adapter/market_adapter.d.ts +94 -32
  152. package/dist/market_adapter/market_adapter.js +94 -120
  153. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  154. package/dist/market_adapter/utils/adapter_client.js +2 -2
  155. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  156. package/dist/market_adapter/utils/chain.d.ts +50 -41
  157. package/dist/market_adapter/utils/chain.js +40 -46
  158. package/dist/market_adapter/utils/data_discovery.d.ts +49 -2
  159. package/dist/market_adapter/utils/data_discovery.js +220 -27
  160. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  161. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  162. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  163. package/dist/market_adapter/utils/file_lock.js +36 -32
  164. package/dist/market_adapter/utils/month_shards.d.ts +84 -0
  165. package/dist/market_adapter/utils/month_shards.js +237 -0
  166. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  167. package/dist/market_adapter/utils/native_history.js +35 -28
  168. package/dist/modules/account_bots.d.ts +578 -21
  169. package/dist/modules/account_bots.js +272 -267
  170. package/dist/modules/account_orders.d.ts +79 -30
  171. package/dist/modules/account_orders.js +60 -64
  172. package/dist/modules/authority_resolver.d.ts +12 -2
  173. package/dist/modules/authority_resolver.js +15 -8
  174. package/dist/modules/bitshares-native/chain_client.d.ts +39 -4
  175. package/dist/modules/bitshares-native/chain_client.js +59 -59
  176. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  177. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  178. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  179. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  180. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  181. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  182. package/dist/modules/bitshares-native/index.d.ts +1 -1
  183. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  184. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  185. package/dist/modules/bitshares-native/resolvers.js +22 -25
  186. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  187. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  188. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  189. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  190. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  191. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  192. package/dist/modules/bitshares-native/serial/types.js +73 -108
  193. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  194. package/dist/modules/bitshares-native/signing_client.js +19 -14
  195. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  196. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  197. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  198. package/dist/modules/bitshares-native/transport.js +5 -4
  199. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  200. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  201. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  202. package/dist/modules/bitshares_client.d.ts +45 -13
  203. package/dist/modules/bitshares_client.js +28 -19
  204. package/dist/modules/bot_defaults.d.ts +8 -16
  205. package/dist/modules/bot_defaults.js +1 -5
  206. package/dist/modules/bot_settings.d.ts +44 -10
  207. package/dist/modules/bot_settings.js +11 -8
  208. package/dist/modules/bots_file_lock.d.ts +6 -6
  209. package/dist/modules/bots_file_lock.js +16 -12
  210. package/dist/modules/broadcast_failure.d.ts +4 -3
  211. package/dist/modules/broadcast_failure.js +5 -4
  212. package/dist/modules/chain_keys.d.ts +42 -40
  213. package/dist/modules/chain_keys.js +53 -45
  214. package/dist/modules/chain_orders.d.ts +94 -60
  215. package/dist/modules/chain_orders.js +81 -118
  216. package/dist/modules/cli_start_onboarding.d.ts +2 -1
  217. package/dist/modules/constants.d.ts +534 -32
  218. package/dist/modules/constants.js +35 -48
  219. package/dist/modules/cr_planner.d.ts +41 -3
  220. package/dist/modules/cr_planner.js +1 -5
  221. package/dist/modules/credential_policy.d.ts +68 -8
  222. package/dist/modules/credential_policy.js +37 -31
  223. package/dist/modules/credential_session_cache.d.ts +2 -2
  224. package/dist/modules/credit_pricing.d.ts +43 -6
  225. package/dist/modules/credit_pricing.js +70 -60
  226. package/dist/modules/credit_runtime.d.ts +283 -118
  227. package/dist/modules/credit_runtime.js +500 -231
  228. package/dist/modules/crypto/browser_provider.js +6 -4
  229. package/dist/modules/crypto/node_provider.js +1 -1
  230. package/dist/modules/crypto/pure_scrypt.js +35 -4
  231. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  232. package/dist/modules/crypto/sync.d.ts +9 -9
  233. package/dist/modules/crypto/sync.js +16 -9
  234. package/dist/modules/daemon_node_health.d.ts +4 -3
  235. package/dist/modules/dexbot_class.d.ts +213 -146
  236. package/dist/modules/dexbot_class.js +183 -86
  237. package/dist/modules/dexbot_cow_runtime.d.ts +160 -87
  238. package/dist/modules/dexbot_cow_runtime.js +302 -234
  239. package/dist/modules/dexbot_credential_client.d.ts +19 -18
  240. package/dist/modules/dexbot_credential_client.js +1 -2
  241. package/dist/modules/dexbot_fill_runtime.d.ts +63 -49
  242. package/dist/modules/dexbot_fill_runtime.js +53 -47
  243. package/dist/modules/dexbot_maintenance_runtime.d.ts +127 -71
  244. package/dist/modules/dexbot_maintenance_runtime.js +187 -147
  245. package/dist/modules/dexbot_startup_runtime.d.ts +11 -11
  246. package/dist/modules/dexbot_startup_runtime.js +56 -57
  247. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  248. package/dist/modules/dexbot_state_recovery.js +18 -13
  249. package/dist/modules/fund_registry.d.ts +4 -2
  250. package/dist/modules/fund_registry.js +10 -10
  251. package/dist/modules/general_settings.d.ts +30 -4
  252. package/dist/modules/graceful_shutdown.d.ts +3 -3
  253. package/dist/modules/graceful_shutdown.js +19 -13
  254. package/dist/modules/grid_price_source.d.ts +1 -1
  255. package/dist/modules/key_store.d.ts +14 -8
  256. package/dist/modules/key_store.js +7 -7
  257. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  258. package/dist/modules/launcher/adapter_requirement.js +5 -5
  259. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  260. package/dist/modules/launcher/bot_supervisor.js +12 -11
  261. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  262. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  263. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  264. package/dist/modules/launcher/credential_daemon.js +2 -2
  265. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  266. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  267. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  268. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  269. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  270. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  271. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  272. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  273. package/dist/modules/launcher/supervisor_control.js +4 -2
  274. package/dist/modules/lazy_shim.d.ts +11 -0
  275. package/dist/modules/lazy_shim.js +16 -0
  276. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  277. package/dist/modules/market_adapter_whitelist.js +15 -3
  278. package/dist/modules/node_connect_policy.d.ts +3 -2
  279. package/dist/modules/node_failure_ledger.d.ts +6 -5
  280. package/dist/modules/node_manager.d.ts +41 -11
  281. package/dist/modules/node_manager.js +5 -4
  282. package/dist/modules/order/accounting.d.ts +53 -24
  283. package/dist/modules/order/accounting.js +16 -15
  284. package/dist/modules/order/async_lock.d.ts +5 -2
  285. package/dist/modules/order/async_lock.js +1 -1
  286. package/dist/modules/order/export.d.ts +7 -6
  287. package/dist/modules/order/export.js +1 -7
  288. package/dist/modules/order/format.d.ts +16 -7
  289. package/dist/modules/order/format.js +15 -3
  290. package/dist/modules/order/genesis_policy.d.ts +24 -21
  291. package/dist/modules/order/genesis_policy.js +17 -10
  292. package/dist/modules/order/grid.d.ts +144 -36
  293. package/dist/modules/order/grid.js +226 -145
  294. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  295. package/dist/modules/order/grid_reconcile.js +13 -12
  296. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  297. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  298. package/dist/modules/order/index.d.ts +264 -1
  299. package/dist/modules/order/logger.d.ts +46 -19
  300. package/dist/modules/order/logger.js +38 -49
  301. package/dist/modules/order/logger_state.d.ts +4 -4
  302. package/dist/modules/order/manager.d.ts +232 -191
  303. package/dist/modules/order/manager.js +110 -130
  304. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  305. package/dist/modules/order/processed_fill_store.js +16 -27
  306. package/dist/modules/order/strategy.d.ts +21 -13
  307. package/dist/modules/order/strategy.js +5 -6
  308. package/dist/modules/order/sync_engine.d.ts +91 -33
  309. package/dist/modules/order/sync_engine.js +84 -53
  310. package/dist/modules/order/utils/math.d.ts +157 -102
  311. package/dist/modules/order/utils/math.js +77 -38
  312. package/dist/modules/order/utils/order.d.ts +310 -110
  313. package/dist/modules/order/utils/order.js +153 -126
  314. package/dist/modules/order/utils/slot.d.ts +1 -1
  315. package/dist/modules/order/utils/system.d.ts +156 -26
  316. package/dist/modules/order/utils/system.js +103 -71
  317. package/dist/modules/order/utils/validate.d.ts +89 -41
  318. package/dist/modules/order/utils/validate.js +26 -24
  319. package/dist/modules/order/utils/withPoolRef.d.ts +6 -4
  320. package/dist/modules/order/utils/withPoolRef.js +18 -12
  321. package/dist/modules/order/working_grid.d.ts +14 -13
  322. package/dist/modules/paths.d.ts +1 -4
  323. package/dist/modules/paths.js +33 -61
  324. package/dist/modules/process_discovery.d.ts +1 -1
  325. package/dist/modules/process_discovery.js +2 -1
  326. package/dist/modules/runtime.d.ts +7 -3
  327. package/dist/modules/runtime.js +4 -3
  328. package/dist/modules/runtime_settings.d.ts +14 -11
  329. package/dist/modules/runtime_settings.js +30 -24
  330. package/dist/modules/settings_merge.d.ts +29 -3
  331. package/dist/modules/settings_merge.js +56 -78
  332. package/dist/modules/socket_json_client.d.ts +9 -5
  333. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  334. package/dist/modules/storage/browser_adapter.js +7 -30
  335. package/dist/modules/storage/index.d.ts +1 -1
  336. package/dist/modules/storage/node_adapter.d.ts +45 -27
  337. package/dist/modules/storage/node_adapter.js +9 -9
  338. package/dist/modules/storage/types.d.ts +5 -4
  339. package/dist/modules/types.d.ts +1090 -6
  340. package/dist/modules/types.js +4 -1
  341. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  342. package/dist/modules/utils/asset_symbols.js +2 -1
  343. package/dist/modules/utils/errors.d.ts +9 -0
  344. package/dist/modules/utils/errors.js +24 -4
  345. package/dist/modules/utils/time_range.d.ts +1 -12
  346. package/dist/modules/utils/time_range.js +1 -1
  347. package/dist/modules/validate_profiles.js +53 -43
  348. package/dist/modules/version_notice.d.ts +23 -11
  349. package/dist/modules/version_notice.js +6 -4
  350. package/dist/pm2.d.ts +28 -27
  351. package/dist/pm2.js +61 -40
  352. package/dist/scripts/analyze-credit.d.ts +2 -1
  353. package/dist/scripts/analyze-credit.js +23 -24
  354. package/dist/scripts/analyze-git.js +2 -15
  355. package/dist/scripts/analyze-orders.d.ts +77 -9
  356. package/dist/scripts/analyze-orders.js +65 -40
  357. package/dist/scripts/chart_command.d.ts +27 -18
  358. package/dist/scripts/chart_command.js +15 -13
  359. package/dist/scripts/check_any.d.ts +22 -0
  360. package/dist/scripts/check_any.js +158 -0
  361. package/dist/scripts/diagnose-pool-history.js +13 -13
  362. package/dist/scripts/print_grid.js +0 -1
  363. package/dist/scripts/run-tests.js +39 -8
  364. package/dist/scripts/runner.js +1 -1
  365. package/dist/scripts/sync-version.js +0 -10
  366. package/dist/scripts/test-credit-renewal.js +30 -21
  367. package/dist/scripts/update.d.ts +10 -5
  368. package/dist/scripts/update.js +168 -103
  369. package/dist/scripts/update_dist_freshness.js +1 -0
  370. package/dist/scripts/update_layout.d.ts +61 -0
  371. package/dist/scripts/update_layout.js +180 -0
  372. package/dist/scripts/validate_bots.js +2 -1
  373. package/dist/scripts/verify-browser-bundle.js +8 -0
  374. package/dist/unlock.d.ts +28 -3
  375. package/dist/unlock.js +63 -35
  376. package/docs/BITSHARES_ONBOARDING.md +10 -12
  377. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -2
  378. package/docs/COW_INVARIANTS.md +13 -6
  379. package/docs/DEXBOT_COMPARISON.md +8 -8
  380. package/docs/EVOLUTION.md +10 -8
  381. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  382. package/docs/GRID_RECALCULATION.md +4 -2
  383. package/docs/GRID_RECONCILE.md +14 -3
  384. package/docs/LIFECYCLE.md +11 -11
  385. package/docs/MPA_CREDIT_USAGE.md +22 -3
  386. package/docs/README.md +14 -3
  387. package/docs/WORKFLOW.md +1 -0
  388. package/docs/architecture.md +31 -19
  389. package/docs/developer_guide.md +6 -6
  390. package/market_adapter/README.md +12 -5
  391. package/modules/README.md +4 -1
  392. package/package.json +9 -9
  393. package/scripts/README.md +43 -38
  394. package/tests/README.md +25 -10
  395. package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
  396. package/dist/scripts/diagnose-kibana-candles.js +0 -82
  397. package/scripts/git-viewer.sh +0 -489
  398. package/scripts/postinstall.js +0 -16
@@ -61,13 +61,25 @@
61
61
  */
62
62
  import Logger from './order/logger.js';
63
63
  import { runtime } from './runtime.js';
64
- import { getErrorMessage } from './utils/errors.js';
64
+ import { getErrorMessage, getErrorField } from './utils/errors.js';
65
65
  import { withTimeout } from './order/utils/timeout.js';
66
66
  const CLEANUP_HANDLER_TIMEOUT_MS = 10000;
67
67
  let cleanupHandlers = [];
68
68
  let shutdownInProgress = false;
69
69
  const shutdownLogger = new Logger('Shutdown');
70
70
  const exitWipeCallbacks = [];
71
+ /**
72
+ * Shared registration guard for the cleanup and exit-wipe lists. Both hold
73
+ * `{ name, handler }` records and reject non-function handlers, so the
74
+ * validation and push live in one place.
75
+ * @private
76
+ */
77
+ function registerHandler(list, name, handler, label) {
78
+ if (typeof handler !== 'function') {
79
+ throw new Error(`${label} for '${name}' must be a function`);
80
+ }
81
+ list.push({ name, handler });
82
+ }
71
83
  /**
72
84
  * Register a synchronous wipe callback that runs AFTER all LIFO cleanup
73
85
  * handlers have completed, immediately before process exit. Unlike regular
@@ -79,10 +91,7 @@ const exitWipeCallbacks = [];
79
91
  * @param {Function} wipeFn - Synchronous function to execute last
80
92
  */
81
93
  function registerExitWipe(name, wipeFn) {
82
- if (typeof wipeFn !== 'function') {
83
- throw new Error(`Exit wipe callback for '${name}' must be a function`);
84
- }
85
- exitWipeCallbacks.push({ name, wipeFn });
94
+ registerHandler(exitWipeCallbacks, name, wipeFn, 'Exit wipe callback');
86
95
  }
87
96
  /**
88
97
  * Register a cleanup function to be called on graceful shutdown
@@ -91,10 +100,7 @@ function registerExitWipe(name, wipeFn) {
91
100
  * @param {Function} handler - Async or sync function to call on shutdown
92
101
  */
93
102
  function registerCleanup(name, handler) {
94
- if (typeof handler !== 'function') {
95
- throw new Error(`Cleanup handler for '${name}' must be a function`);
96
- }
97
- cleanupHandlers.push({ name, handler });
103
+ registerHandler(cleanupHandlers, name, handler, 'Cleanup handler');
98
104
  }
99
105
  /**
100
106
  * Remove a previously registered cleanup function.
@@ -155,9 +161,9 @@ async function executeCleanup() {
155
161
  }
156
162
  }
157
163
  for (let i = 0; i < exitWipeCallbacks.length; i++) {
158
- const { name, wipeFn } = exitWipeCallbacks[i];
164
+ const { name, handler } = exitWipeCallbacks[i];
159
165
  try {
160
- wipeFn();
166
+ handler();
161
167
  shutdownLogger.info(`✓ ${name} (exit wipe)`);
162
168
  }
163
169
  catch (err) {
@@ -186,7 +192,7 @@ function setupGracefulShutdown() {
186
192
  runtime.onSignal('exit', () => {
187
193
  for (let i = 0; i < exitWipeCallbacks.length; i++) {
188
194
  try {
189
- exitWipeCallbacks[i].wipeFn();
195
+ exitWipeCallbacks[i].handler();
190
196
  }
191
197
  catch (_) { }
192
198
  }
@@ -200,7 +206,7 @@ function setupGracefulShutdown() {
200
206
  });
201
207
  // Handle unhandled rejections
202
208
  runtime.onSignal('unhandledRejection', async (reason, promise) => {
203
- shutdownLogger.error(`Unhandled rejection at: ${promise} reason: ${reason?.stack || reason}`);
209
+ shutdownLogger.error(`Unhandled rejection at: ${promise} reason: ${getErrorField(reason, 'stack') || reason}`);
204
210
  await executeCleanup();
205
211
  runtime.exitAfterStderrDrain(1);
206
212
  });
@@ -14,6 +14,6 @@
14
14
  * @param {Object} bot - Bot configuration object
15
15
  * @returns {boolean} True if gridPrice starts with 'ama' (ama, ama1..ama4)
16
16
  */
17
- declare function usesAmaGridPrice(bot: any): boolean;
17
+ declare function usesAmaGridPrice(bot: Record<string, unknown> | null | undefined): boolean;
18
18
  export { usesAmaGridPrice };
19
19
  //# sourceMappingURL=grid_price_source.d.ts.map
@@ -1,19 +1,25 @@
1
+ /** One chain operation to sign/broadcast. */
2
+ interface ChainOrderOperation {
3
+ op_name: string;
4
+ op_data: unknown;
5
+ }
1
6
  export interface SigningResult {
2
7
  success: boolean;
3
- raw?: any;
4
- operation_results?: any[];
8
+ raw?: unknown;
9
+ operation_results?: unknown[];
5
10
  }
6
11
  export interface KeyStore {
7
- resolveSigningKey(accountName: string, vaultSecret?: any, chainClient?: any): Promise<any>;
8
- isDaemonSigningKey(key: any): boolean;
9
- executeOperations(accountName: string, operations: any[], signingKey: any, extraOptions?: Record<string, any>): Promise<SigningResult>;
12
+ resolveSigningKey(accountName: string, vaultSecret?: unknown, chainClient?: unknown): Promise<unknown>;
13
+ isDaemonSigningKey(key: unknown): boolean;
14
+ executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
10
15
  }
11
16
  export declare class DaemonKeyStore implements KeyStore {
12
- resolveSigningKey(accountName: string, vaultSecret?: any, chainClient?: any): Promise<any>;
13
- isDaemonSigningKey(key: any): boolean;
14
- executeOperations(accountName: string, operations: any[], signingKey: any, extraOptions?: Record<string, any>): Promise<SigningResult>;
17
+ resolveSigningKey(accountName: string, vaultSecret?: unknown, chainClient?: unknown): Promise<unknown>;
18
+ isDaemonSigningKey(key: unknown): boolean;
19
+ executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
15
20
  }
16
21
  export declare function setKeyStore(impl: KeyStore | null): void;
17
22
  export declare function resetKeyStore(): void;
18
23
  export declare function getKeyStore(): KeyStore;
24
+ export {};
19
25
  //# sourceMappingURL=key_store.d.ts.map
@@ -42,7 +42,6 @@ function buildDaemonBroadcastOptions(signingKey, extraOptions, sessionIdOverride
42
42
  requestType: 'broadcast',
43
43
  batchId: signingKey.batchId || null,
44
44
  ...(extraOptions.nodeUrl ? { nodeUrl: extraOptions.nodeUrl } : {}),
45
- ...(extraOptions.fallbackNodes ? { fallbackNodes: extraOptions.fallbackNodes } : {}),
46
45
  ...(typeof extraOptions.onNodeFailed === 'function' ? { onNodeFailed: extraOptions.onNodeFailed } : {}),
47
46
  };
48
47
  }
@@ -95,14 +94,15 @@ export class DaemonKeyStore {
95
94
  return chainKeys.isDaemonSigningToken(key);
96
95
  }
97
96
  async executeOperations(accountName, operations, signingKey, extraOptions = {}) {
97
+ const daemonKey = signingKey;
98
98
  if (this.isDaemonSigningKey(signingKey)) {
99
- if (!signingKey.botHmacSecret) {
99
+ if (!daemonKey.botHmacSecret) {
100
100
  keyStoreLogger.error(`Daemon signing token for ${accountName} has no botHmacSecret — the daemon will reject this request ` +
101
101
  `(Strict Mode). This happens when a broadcast is attempted after the bot shut down or the token lost ` +
102
102
  `its secret. Restarting the bot resolves it.`);
103
103
  }
104
104
  try {
105
- const result = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(signingKey, extraOptions));
105
+ const result = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(daemonKey, extraOptions));
106
106
  return normalizeDaemonResult(result);
107
107
  }
108
108
  catch (err) {
@@ -123,19 +123,19 @@ export class DaemonKeyStore {
123
123
  catch { }
124
124
  }
125
125
  const newSessionId = await chainKeys.probeAccountInDaemon(accountName);
126
- signingKey.sessionId = newSessionId;
126
+ daemonKey.sessionId = newSessionId;
127
127
  if (isSourceAuthError) {
128
128
  try {
129
129
  const freshSecret = credentialPolicy.loadBotHmacSecret(accountName, PATHS.PROFILES.DAEMON_POLICIES_JSON, { quiet: true });
130
- if (freshSecret && freshSecret !== signingKey.botHmacSecret) {
131
- signingKey.botHmacSecret = freshSecret;
130
+ if (freshSecret && freshSecret !== daemonKey.botHmacSecret) {
131
+ daemonKey.botHmacSecret = freshSecret;
132
132
  keyStoreLogger.warn(`Reloaded botHmacSecret from disk for ${accountName} before retry`);
133
133
  }
134
134
  }
135
135
  catch (_) { }
136
136
  await sleep(500);
137
137
  }
138
- const retryResult = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(signingKey, extraOptions, signingKey.sessionId));
138
+ const retryResult = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(daemonKey, extraOptions, daemonKey.sessionId ?? undefined));
139
139
  return normalizeDaemonResult(retryResult);
140
140
  }
141
141
  throw err;
@@ -1,17 +1,23 @@
1
+ interface AdapterBotConfig {
2
+ name?: string;
3
+ gridPrice?: unknown;
4
+ active?: boolean;
5
+ [key: string]: unknown;
6
+ }
1
7
  /**
2
8
  * Check whether the unlock wrapper owns the market adapter lifecycle.
3
9
  * Bots skip their own adapter sync/poll when this is true.
4
10
  * @param {NodeJS.ProcessEnv} [env=process.env] - Environment to inspect
5
11
  * @returns {boolean} True when running as a wrapper-supervised bot child
6
12
  */
7
- declare function isWrapperAdapterOwner(env?: any): boolean;
13
+ declare function isWrapperAdapterOwner(env?: Record<string, string | undefined>): boolean;
8
14
  /**
9
15
  * Build the semantic adapter fingerprint for an active-bot list.
10
16
  * Only AMA-priced bots contribute; sorted so bot order is irrelevant.
11
- * @param {any[]} activeBots - Bots with active !== false
17
+ * @param {unknown[]} activeBots - Bots with active !== false
12
18
  * @returns {string} Fingerprint ('' when no AMA bot is active)
13
19
  */
14
- declare function buildAdapterFingerprint(activeBots: any[]): string;
20
+ declare function buildAdapterFingerprint(activeBots: AdapterBotConfig[]): string;
15
21
  /**
16
22
  * Read bots.json and summarize the market-adapter requirement.
17
23
  * Never throws: missing/empty files report exists:false, unparseable files
@@ -24,8 +30,8 @@ declare function buildAdapterFingerprint(activeBots: any[]): string;
24
30
  declare function readAdapterRequirement(botsFile?: string): {
25
31
  exists: boolean;
26
32
  fingerprint: string;
27
- config: any;
28
- activeBots: any[];
33
+ config: unknown;
34
+ activeBots: AdapterBotConfig[];
29
35
  needsMarketAdapter: boolean;
30
36
  corrupt?: boolean;
31
37
  readError?: boolean;
@@ -65,7 +65,7 @@ function normalizeGridPrice(value) {
65
65
  /**
66
66
  * Build the semantic adapter fingerprint for an active-bot list.
67
67
  * Only AMA-priced bots contribute; sorted so bot order is irrelevant.
68
- * @param {any[]} activeBots - Bots with active !== false
68
+ * @param {unknown[]} activeBots - Bots with active !== false
69
69
  * @returns {string} Fingerprint ('' when no AMA bot is active)
70
70
  */
71
71
  function buildAdapterFingerprint(activeBots) {
@@ -78,13 +78,13 @@ function buildAdapterFingerprint(activeBots) {
78
78
  }
79
79
  /**
80
80
  * Summarize parsed bots.json content for adapter decisions.
81
- * @param {any} parsed - Parsed bots.json object
81
+ * @param {unknown} parsed - Parsed bots.json object
82
82
  * @returns {{activeBots: any[], needsMarketAdapter: boolean, fingerprint: string}}
83
83
  */
84
84
  function summarizeBotsConfig(parsed) {
85
- const bots = Array.isArray(parsed?.bots)
86
- ? parsed.bots.filter(Boolean)
87
- : [];
85
+ const rec = parsed;
86
+ const rawBots = Array.isArray(rec?.bots) ? rec.bots : [];
87
+ const bots = rawBots.filter(Boolean);
88
88
  const activeBots = bots.filter((bot) => bot && bot.active !== false);
89
89
  return {
90
90
  activeBots,
@@ -1,37 +1,119 @@
1
+ import { spawn } from 'node:child_process';
2
+ import type { ChildProcess, ChildProcessByStdio } from 'node:child_process';
3
+ import type { Readable } from 'node:stream';
4
+ import { buildScopedChildEnv } from './child_env.js';
5
+ import { type BotEntry } from '../bot_settings.js';
1
6
  import { formatUptime } from '../process_discovery.js';
7
+ import type { Socket } from 'net';
2
8
  import { usesAmaGridPrice } from '../grid_price_source.js';
3
9
  declare const SOCKET_PATH: string;
4
- declare function parseCronExpression(expression: any): {
5
- minute: Set<unknown> | null;
6
- hour: Set<unknown> | null;
7
- dayOfMonth: Set<unknown> | null;
8
- month: Set<unknown> | null;
9
- dayOfWeek: Set<unknown> | null;
10
- };
11
- declare function getNextCronDate(schedule: any, fromDate?: any): Date;
12
- declare function forwardSignal(child: any, signal: any): void;
13
- declare function isPidAlive(pid: any): boolean;
14
- declare function waitForPidExit(pid: any, timeoutMs: any): Promise<boolean>;
15
- declare function candidateRuntimeScriptPaths(scriptSegments: any): Set<string>;
16
- declare function pidMatchesScriptCandidates(pid: any, expectedPaths: any): boolean;
17
- declare function isNodeProcessWithExactScript(pid: any, scriptSegments: any): boolean;
10
+ type SupervisedChild = ChildProcessByStdio<null, Readable, Readable>;
11
+ interface SupervisedApp {
12
+ kind: 'bot' | 'service' | 'job';
13
+ name: string;
14
+ script: string;
15
+ args?: string | string[];
16
+ cwd: string;
17
+ max_memory_restart?: string;
18
+ error_file?: string;
19
+ out_file?: string;
20
+ max_restarts?: number;
21
+ min_uptime?: number;
22
+ restart_delay?: number;
23
+ autorestart?: boolean;
24
+ bulk_control?: boolean;
25
+ cron_schedule?: string;
26
+ env?: Record<string, string>;
27
+ [key: string]: unknown;
28
+ }
29
+ interface CronSchedule {
30
+ minute: Set<number> | null;
31
+ hour: Set<number> | null;
32
+ dayOfMonth: Set<number> | null;
33
+ month: Set<number> | null;
34
+ dayOfWeek: Set<number> | null;
35
+ }
36
+ interface BotRuntimeState {
37
+ name: string;
38
+ appEntry: SupervisedApp | null;
39
+ child: SupervisedChild | null;
40
+ restartCount: number;
41
+ lastStartTime: number;
42
+ status: string;
43
+ pendingRestart: boolean;
44
+ bulkControl: boolean;
45
+ cronExpression: string | null;
46
+ cronSchedule: CronSchedule | null;
47
+ nextScheduledAt: number;
48
+ scheduledRunTimer: ReturnType<typeof setTimeout> | null;
49
+ autorestart?: boolean;
50
+ maxRestarts: number;
51
+ minUptimeMs: number;
52
+ restartDelayMs: number;
53
+ memoryLimitBytes: number | null;
54
+ stoppedByUser: boolean;
55
+ [key: string]: unknown;
56
+ }
57
+ interface SupervisorOptions {
58
+ bots?: BotEntry[] | null;
59
+ buildEnv?: typeof buildScopedChildEnv;
60
+ spawnFn?: typeof spawn;
61
+ log?: (...args: unknown[]) => void;
62
+ logError?: (...args: unknown[]) => void;
63
+ controlSocket?: boolean;
64
+ getChildRss?: (child: SupervisedChild) => number;
65
+ memoryCheckIntervalMs?: number;
66
+ statusLogIntervalMs?: number;
67
+ staggerDelayMs?: number;
68
+ setTimeoutFn?: typeof setTimeout;
69
+ clearTimeoutFn?: typeof clearTimeout;
70
+ nowFn?: () => number;
71
+ stopMarketAdapter?: () => Promise<{
72
+ pid: number | null;
73
+ stopped: boolean;
74
+ }>;
75
+ updaterActive?: boolean;
76
+ }
77
+ declare function parseCronExpression(expression: unknown): CronSchedule;
78
+ declare function getNextCronDate(schedule: CronSchedule, fromDate?: Date): Date;
79
+ declare function forwardSignal(child: ChildProcess | null | undefined, signal: NodeJS.Signals): void;
80
+ declare function isPidAlive(pid: number): boolean;
81
+ declare function waitForPidExit(pid: number, timeoutMs: number): Promise<boolean>;
82
+ declare function candidateRuntimeScriptPaths(scriptSegments: string[]): Set<string>;
83
+ declare function pidMatchesScriptCandidates(pid: number, expectedPaths: Set<string> | null | undefined): boolean;
84
+ declare function isNodeProcessWithExactScript(pid: number, scriptSegments: string[]): boolean;
18
85
  declare function readMarketAdapterLockPid(): number | null;
19
- declare function stopMarketAdapterFromLock(timeoutMs?: any): Promise<{
86
+ declare function stopMarketAdapterFromLock(timeoutMs?: number): Promise<{
20
87
  pid: number | null;
21
88
  stopped: boolean;
22
89
  }>;
23
- declare function waitForChildSpawn(child: any): Promise<unknown>;
24
- declare function createBotSupervisor({ bots, buildEnv, spawnFn, log, logError, controlSocket, getChildRss, memoryCheckIntervalMs, statusLogIntervalMs, staggerDelayMs, setTimeoutFn, clearTimeoutFn, nowFn, stopMarketAdapter, updaterActive, }?: any): {
25
- start: () => Promise<Map<any, any>>;
26
- shutdown: ({ preserveSockets }?: any) => Promise<unknown>;
27
- shutdownSignalHandler: (signal: any) => void;
28
- getStatus: () => Record<string, any>;
90
+ declare function waitForChildSpawn(child: ChildProcess): Promise<void>;
91
+ declare function createBotSupervisor({ bots, buildEnv, spawnFn, log, logError, controlSocket, getChildRss, memoryCheckIntervalMs, statusLogIntervalMs, staggerDelayMs, setTimeoutFn, clearTimeoutFn, nowFn, stopMarketAdapter, updaterActive, }?: SupervisorOptions): {
92
+ start: () => Promise<Map<string, BotRuntimeState>>;
93
+ shutdown: ({ preserveSockets }?: {
94
+ preserveSockets?: Socket[];
95
+ }) => Promise<void>;
96
+ shutdownSignalHandler: (signal: NodeJS.Signals) => void;
97
+ getStatus: () => Record<string, {
98
+ status: string;
99
+ pid: number | null;
100
+ restarts: number;
101
+ uptimeMs: number;
102
+ nextScheduledAt: number;
103
+ }>;
29
104
  printStatusSummary: () => void;
30
- restartAll: ({ logAction }?: any) => Promise<void>;
31
- restartRunning: ({ logAction }?: any) => Promise<void>;
105
+ restartAll: ({ logAction }?: {
106
+ logAction?: string;
107
+ }) => Promise<void>;
108
+ restartRunning: ({ logAction }?: {
109
+ logAction?: boolean;
110
+ }) => Promise<void>;
32
111
  stopAll: () => void;
33
112
  hasUserStopped: () => boolean;
34
- waitForStableStartup: ({ timeoutMs, pollIntervalMs }?: any) => Promise<void>;
113
+ waitForStableStartup: ({ timeoutMs, pollIntervalMs }?: {
114
+ timeoutMs?: number;
115
+ pollIntervalMs?: number;
116
+ }) => Promise<void>;
35
117
  };
36
118
  export { createBotSupervisor, SOCKET_PATH, parseCronExpression, getNextCronDate, forwardSignal, isPidAlive, waitForPidExit, candidateRuntimeScriptPaths, pidMatchesScriptCandidates, isNodeProcessWithExactScript, readMarketAdapterLockPid, stopMarketAdapterFromLock, usesAmaGridPrice, waitForChildSpawn, formatUptime };
37
119
  //# sourceMappingURL=bot_supervisor.d.ts.map
@@ -17,7 +17,7 @@ import { sleep } from '../order/utils/system.js';
17
17
  const storage = getStorage();
18
18
  const { ensureDir, readJSON, unlink: safeUnlink } = storage;
19
19
  import { buildRuntimeScriptPath, SCRIPTS_ROOT as CODE_ROOT } from './runtime_entry.js';
20
- import { getErrorMessage } from '../utils/errors.js';
20
+ import { getErrorMessage, getErrorCode } from '../utils/errors.js';
21
21
  import { usesAmaGridPrice } from '../grid_price_source.js';
22
22
  const BOT_SCRIPT = buildRuntimeScriptPath(CODE_ROOT, ['bot']);
23
23
  const SOCKET_PATH = Config.DEXBOT_SUPERVISOR_SOCKET || PATHS.PROFILES.SUPERVISOR_SOCK;
@@ -209,7 +209,7 @@ function forwardSignal(child, signal) {
209
209
  child.kill(signal);
210
210
  }
211
211
  catch (err) {
212
- if (err.code !== 'ESRCH')
212
+ if (getErrorCode(err) !== 'ESRCH')
213
213
  throw err;
214
214
  }
215
215
  }
@@ -232,13 +232,14 @@ function readProcCwd(pid) {
232
232
  return getProcessDiscovery().readCwd(pid);
233
233
  }
234
234
  function normalizeProcScriptArg(arg, cwd) {
235
- if (!arg || String(arg).startsWith('-'))
235
+ const argStr = arg == null ? '' : String(arg);
236
+ if (!argStr || argStr.startsWith('-'))
236
237
  return '';
237
- if (!/\.(?:[cm]?js|ts)$/i.test(String(arg)))
238
+ if (!/\.(?:[cm]?js|ts)$/i.test(argStr))
238
239
  return '';
239
- return path.isAbsolute(arg)
240
- ? path.normalize(arg)
241
- : path.resolve(cwd || PATHS.PROJECT_ROOT, arg);
240
+ return path.isAbsolute(argStr)
241
+ ? path.normalize(argStr)
242
+ : path.resolve(cwd || PATHS.PROJECT_ROOT, argStr);
242
243
  }
243
244
  function scriptPathForRoot(root, scriptSegments, ext) {
244
245
  const segments = [...scriptSegments];
@@ -421,7 +422,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
421
422
  }
422
423
  log(`Starting scheduled job: ${state.name}`);
423
424
  try {
424
- const child = spawnApp(state.appEntry);
425
+ const child = state.appEntry ? spawnApp(state.appEntry) : null;
425
426
  if (child) {
426
427
  await waitForChildSpawn(child);
427
428
  }
@@ -612,7 +613,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
612
613
  state.pendingRestart = false;
613
614
  state.stoppedByUser = true;
614
615
  try {
615
- state.child.kill('SIGTERM');
616
+ state.child?.kill('SIGTERM');
616
617
  }
617
618
  catch (_) { }
618
619
  userStopped = true;
@@ -749,7 +750,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
749
750
  }
750
751
  catch (_) {
751
752
  enqueueSocketResponse(() => new Promise((resolve) => {
752
- socket.write(JSON.stringify({ error: 'invalid JSON' }) + '\n', resolve);
753
+ socket.write(JSON.stringify({ error: 'invalid JSON' }) + '\n', () => resolve());
753
754
  }));
754
755
  continue;
755
756
  }
@@ -760,7 +761,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
760
761
  enqueueSocketResponse(async () => {
761
762
  const resp = await handleSocketCommand({ ...cmd, preserveSockets: [socket] });
762
763
  await new Promise((resolve) => {
763
- socket.write(JSON.stringify(resp) + '\n', resolve);
764
+ socket.write(JSON.stringify(resp) + '\n', () => resolve());
764
765
  });
765
766
  if (cmd.cmd === 'delete') {
766
767
  socket.end();
@@ -7,7 +7,7 @@ declare function fetchBootstrapPassword({ socketPath, timeoutMs, retries, }?: {
7
7
  }): Promise<unknown>;
8
8
  declare function createPasswordBootstrapServer({ password, secret, timeoutMs, }?: {
9
9
  password?: string;
10
- secret?: any;
10
+ secret?: unknown;
11
11
  timeoutMs?: number;
12
12
  }): Promise<{
13
13
  socketPath: string;
@@ -72,7 +72,7 @@ async function cleanupStaleBootstrapDirs() {
72
72
  const socketPath = path.join(dirPath, 'bootstrap.sock');
73
73
  try {
74
74
  const socketStat = storage.stat(socketPath);
75
- if (socketStat.isSocket()) {
75
+ if (socketStat.isSocket?.()) {
76
76
  // Probe the socket with a short connect. If it succeeds the
77
77
  // server is (or was very recently) listening — do not delete.
78
78
  const probeResult = await probeBootstrapSocket(socketPath, 300);
@@ -1,6 +1,6 @@
1
1
  import type { StdioOptions } from 'child_process';
2
2
  declare const DEFAULT_POLL_INTERVAL_MS = 1000;
3
- declare function waitForExit(child: any): Promise<any>;
3
+ declare function waitForExit(child: import('node:child_process').ChildProcess): Promise<number | null>;
4
4
  declare function createCredentialDaemonController({ root, codeRoot, socketPath, readyFilePath, pollIntervalMs, }?: {
5
5
  root?: string | undefined;
6
6
  codeRoot?: string | undefined;
@@ -15,11 +15,11 @@ declare function createCredentialDaemonController({ root, codeRoot, socketPath,
15
15
  passwordFile?: string | null;
16
16
  }) => Promise<boolean>;
17
17
  forwardSignal: (signal: string) => void;
18
- getManagedDaemonPid: () => any;
19
- isDaemonReady: () => Promise<unknown>;
18
+ getManagedDaemonPid: () => number | null;
19
+ isDaemonReady: () => Promise<boolean>;
20
20
  releaseManagedDaemon: () => void;
21
21
  stopManagedDaemon: () => Promise<void>;
22
- waitForManagedDaemon: () => Promise<any>;
22
+ waitForManagedDaemon: () => Promise<number | null>;
23
23
  };
24
24
  export { createCredentialDaemonController, DEFAULT_POLL_INTERVAL_MS, waitForExit };
25
25
  //# sourceMappingURL=credential_daemon.d.ts.map
@@ -15,7 +15,7 @@ const storage = getStorage();
15
15
  const { unlink: safeUnlink } = storage;
16
16
  import { assertPrivatePathSecurity, ensureCredentialRuntimeDirSync, getCredentialReadyFilePath, getCredentialSocketPath, } from '../credential_runtime.js';
17
17
  import { buildRuntimeScriptArgs, SCRIPTS_ROOT as DEFAULT_CODE_ROOT } from './runtime_entry.js';
18
- import { getErrorMessage } from '../utils/errors.js';
18
+ import { getErrorMessage, getErrorCode } from '../utils/errors.js';
19
19
  const DEFAULT_POLL_INTERVAL_MS = 1000;
20
20
  function waitForExit(child) {
21
21
  return new Promise((resolve, reject) => {
@@ -58,7 +58,7 @@ function createCredentialDaemonController({ root = PATHS.PROJECT_ROOT, codeRoot
58
58
  daemonProcess.kill(signal);
59
59
  }
60
60
  catch (err) {
61
- if (err.code === 'ESRCH')
61
+ if (getErrorCode(err) === 'ESRCH')
62
62
  return;
63
63
  throw err;
64
64
  }
@@ -1,3 +1,3 @@
1
- declare function normalizeBootstrapCredential(credential: any): any;
1
+ declare function normalizeBootstrapCredential(credential: unknown): unknown;
2
2
  export { normalizeBootstrapCredential };
3
3
  //# sourceMappingURL=credential_secret.d.ts.map
@@ -15,8 +15,8 @@
15
15
  * and lets the caller fall through to the normal "prompt for master
16
16
  * password" path.
17
17
  */
18
- declare function readCredentialSocketInode(socketPath: any): number;
19
- declare function findCredentialSocketOwnerPid(socketPath: any, isLikelyProcess: any): number;
18
+ declare function readCredentialSocketInode(socketPath: string): number;
19
+ declare function findCredentialSocketOwnerPid(socketPath: string, isLikelyProcess: ((pid: number) => boolean) | null | undefined): number;
20
20
  /**
21
21
  * Detect and clean up a credential daemon that is listening on our socket
22
22
  * but was NOT started by the current unlock session.
@@ -1,7 +1,7 @@
1
1
  import { buildScopedChildEnv } from './child_env.js';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { isLikelyMarketAdapterProcess } from '../../market_adapter/utils/file_lock.js';
4
- declare function loadLockInfo(lockPath: string): any;
4
+ declare function loadLockInfo(lockPath: string): Record<string, unknown>;
5
5
  declare function isLockStale(lockPath?: string, _staleAfterMs?: number, isAdapterProcess?: typeof isLikelyMarketAdapterProcess): boolean;
6
6
  declare function createMarketAdapterRuntime({ root, script, lockFile, spawnFn, buildEnv, }?: {
7
7
  root?: string | undefined;
@@ -14,17 +14,72 @@ declare function createMarketAdapterRuntime({ root, script, lockFile, spawnFn, b
14
14
  activeBotCount: number;
15
15
  botIds: unknown[];
16
16
  hasOwnedChild: boolean;
17
- ownedPid: any;
17
+ ownedPid: number | null;
18
18
  runningExternally: boolean;
19
- lockInfo: any;
19
+ lockInfo: Record<string, unknown>;
20
20
  };
21
- releaseBot: (botId: string) => Promise<any>;
21
+ releaseBot: (botId: string) => Promise<{
22
+ running: boolean;
23
+ stopped: boolean;
24
+ } | {
25
+ running: boolean;
26
+ owned: boolean;
27
+ stopped: boolean;
28
+ }>;
22
29
  shutdown: () => Promise<{
23
30
  running: boolean;
24
31
  stopped: boolean;
25
32
  }>;
26
- syncBot: (botId: string, shouldRun: boolean) => Promise<any>;
33
+ syncBot: (botId: string, shouldRun: boolean) => Promise<{
34
+ running: boolean;
35
+ owned: boolean;
36
+ started: boolean;
37
+ external?: undefined;
38
+ } | {
39
+ running: boolean;
40
+ owned: boolean;
41
+ external: boolean;
42
+ started: boolean;
43
+ } | {
44
+ running: boolean;
45
+ stopped: boolean;
46
+ }>;
47
+ };
48
+ declare function getSharedMarketAdapterRuntime(options?: {}): {
49
+ getStatus: () => {
50
+ activeBotCount: number;
51
+ botIds: unknown[];
52
+ hasOwnedChild: boolean;
53
+ ownedPid: number | null;
54
+ runningExternally: boolean;
55
+ lockInfo: Record<string, unknown>;
56
+ };
57
+ releaseBot: (botId: string) => Promise<{
58
+ running: boolean;
59
+ stopped: boolean;
60
+ } | {
61
+ running: boolean;
62
+ owned: boolean;
63
+ stopped: boolean;
64
+ }>;
65
+ shutdown: () => Promise<{
66
+ running: boolean;
67
+ stopped: boolean;
68
+ }>;
69
+ syncBot: (botId: string, shouldRun: boolean) => Promise<{
70
+ running: boolean;
71
+ owned: boolean;
72
+ started: boolean;
73
+ external?: undefined;
74
+ } | {
75
+ running: boolean;
76
+ owned: boolean;
77
+ external: boolean;
78
+ started: boolean;
79
+ } | {
80
+ running: boolean;
81
+ stopped: boolean;
82
+ }>;
27
83
  };
28
- declare function getSharedMarketAdapterRuntime(options?: {}): any;
29
84
  export { createMarketAdapterRuntime, getSharedMarketAdapterRuntime, isLikelyMarketAdapterProcess, isLockStale, loadLockInfo };
30
85
  //# sourceMappingURL=market_adapter_runtime.d.ts.map
@@ -1,5 +1,13 @@
1
- declare function createMarketAdapterWatchdog({ codeRoot, root, lockFile, botsFile, logWarn, logError, }?: any): {
2
- schedule: (errorLog: any) => () => void;
1
+ interface WatchdogOptions {
2
+ codeRoot?: string;
3
+ root?: string;
4
+ lockFile?: string;
5
+ botsFile?: string;
6
+ logWarn?: (...args: unknown[]) => void;
7
+ logError?: (...args: unknown[]) => void;
8
+ }
9
+ declare function createMarketAdapterWatchdog({ codeRoot, root, lockFile, botsFile, logWarn, logError, }?: WatchdogOptions): {
10
+ schedule: (errorLog: string) => () => void;
3
11
  stop: () => Promise<void>;
4
12
  isLikelyRunning: () => boolean;
5
13
  readAdapterStatus: () => {
@@ -58,6 +58,10 @@ function createMarketAdapterWatchdog({ codeRoot = DEFAULT_CODE_ROOT, root = PATH
58
58
  }
59
59
  catch (_) { }
60
60
  const exited = await withTimeout(new Promise((resolve) => {
61
+ if (!_child) {
62
+ resolve(true);
63
+ return;
64
+ }
61
65
  _child.once('close', () => resolve(true));
62
66
  }), LAUNCHER.SUPERVISOR.SHUTDOWN_TIMEOUT_MS, { onTimeout: 'resolve', defaultValue: false });
63
67
  if (!exited && _child && _child.exitCode == null) {