dexbot 1.4.11 → 1.4.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 (497) hide show
  1. package/README.md +4 -4
  2. package/dist/analysis/chart_utils.d.ts.map +1 -1
  3. package/dist/analysis/chart_utils.js +9 -18
  4. package/dist/analysis/chart_utils.js.map +1 -1
  5. package/dist/analysis/math_utils.d.ts.map +1 -1
  6. package/dist/analysis/math_utils.js +6 -16
  7. package/dist/analysis/math_utils.js.map +1 -1
  8. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +1 -1
  9. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  10. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +31 -38
  11. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  12. package/dist/analysis/trend_detection/hurst_analyzer.js +7 -10
  13. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
  14. package/dist/analysis/trend_detection/kalman_trend_analyzer.js +10 -14
  15. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
  16. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +10 -15
  17. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
  18. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -10
  19. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
  20. package/dist/bot.d.ts.map +1 -1
  21. package/dist/bot.js +4 -12
  22. package/dist/bot.js.map +1 -1
  23. package/dist/credential-daemon.d.ts +0 -1
  24. package/dist/credential-daemon.d.ts.map +1 -1
  25. package/dist/credential-daemon.js +3 -123
  26. package/dist/credential-daemon.js.map +1 -1
  27. package/dist/dexbot.d.ts +0 -87
  28. package/dist/dexbot.d.ts.map +1 -1
  29. package/dist/dexbot.js +11 -14
  30. package/dist/dexbot.js.map +1 -1
  31. package/dist/market_adapter/ama_signal_runner.js +8 -9
  32. package/dist/market_adapter/ama_signal_runner.js.map +1 -1
  33. package/dist/market_adapter/candle_utils.js +1 -7
  34. package/dist/market_adapter/candle_utils.js.map +1 -1
  35. package/dist/market_adapter/core/asymmetric_bounds.js +1 -4
  36. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
  37. package/dist/market_adapter/core/config_normalizers.js +5 -9
  38. package/dist/market_adapter/core/config_normalizers.js.map +1 -1
  39. package/dist/market_adapter/core/kibana_candles.js +8 -15
  40. package/dist/market_adapter/core/kibana_candles.js.map +1 -1
  41. package/dist/market_adapter/core/kibana_client.js +7 -13
  42. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  43. package/dist/market_adapter/core/kibana_market_candles.js +6 -12
  44. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
  45. package/dist/market_adapter/core/market_adapter_service.js +92 -102
  46. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  47. package/dist/market_adapter/core/strategies/ama.js +5 -10
  48. package/dist/market_adapter/core/strategies/ama.js.map +1 -1
  49. package/dist/market_adapter/core/strategies/ama_slope_model.js +21 -24
  50. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
  51. package/dist/market_adapter/core/strategies/atr/calculator.js +3 -5
  52. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
  53. package/dist/market_adapter/core/strategies/collateral_manager.js +4 -6
  54. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
  55. package/dist/market_adapter/core/strategies/regime_gate.js +15 -22
  56. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  57. package/dist/market_adapter/index.d.ts +23 -23
  58. package/dist/market_adapter/index.d.ts.map +1 -1
  59. package/dist/market_adapter/index.js +24 -82
  60. package/dist/market_adapter/index.js.map +1 -1
  61. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
  62. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  63. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  64. package/dist/market_adapter/inputs/fetch_lp_data.js +59 -98
  65. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  66. package/dist/market_adapter/inputs/kibana_source.js +11 -17
  67. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  68. package/dist/market_adapter/interval_utils.js +1 -2
  69. package/dist/market_adapter/interval_utils.js.map +1 -1
  70. package/dist/market_adapter/log_format.js +1 -7
  71. package/dist/market_adapter/log_format.js.map +1 -1
  72. package/dist/market_adapter/lp_chart_core.js +20 -22
  73. package/dist/market_adapter/lp_chart_core.js.map +1 -1
  74. package/dist/market_adapter/lp_chart_runner.d.ts +1 -1
  75. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
  76. package/dist/market_adapter/lp_chart_runner.js +41 -57
  77. package/dist/market_adapter/lp_chart_runner.js.map +1 -1
  78. package/dist/market_adapter/lp_chart_strategy_loader.js +30 -34
  79. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  80. package/dist/market_adapter/market_adapter.d.ts +2 -2
  81. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  82. package/dist/market_adapter/market_adapter.js +157 -221
  83. package/dist/market_adapter/market_adapter.js.map +1 -1
  84. package/dist/market_adapter/merge_lp_data.js +17 -18
  85. package/dist/market_adapter/merge_lp_data.js.map +1 -1
  86. package/dist/market_adapter/test_helpers.js +3 -14
  87. package/dist/market_adapter/test_helpers.js.map +1 -1
  88. package/dist/market_adapter/utils/adapter_client.js +7 -16
  89. package/dist/market_adapter/utils/adapter_client.js.map +1 -1
  90. package/dist/market_adapter/utils/atomic_write.js +3 -5
  91. package/dist/market_adapter/utils/atomic_write.js.map +1 -1
  92. package/dist/market_adapter/utils/chain.d.ts.map +1 -1
  93. package/dist/market_adapter/utils/chain.js +9 -17
  94. package/dist/market_adapter/utils/chain.js.map +1 -1
  95. package/dist/market_adapter/utils/data_discovery.js +8 -10
  96. package/dist/market_adapter/utils/data_discovery.js.map +1 -1
  97. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
  98. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +11 -14
  99. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
  100. package/dist/market_adapter/utils/file_lock.js +14 -19
  101. package/dist/market_adapter/utils/file_lock.js.map +1 -1
  102. package/dist/market_adapter/utils/native_history.js +8 -14
  103. package/dist/market_adapter/utils/native_history.js.map +1 -1
  104. package/dist/market_adapter/utils/paths.js +3 -6
  105. package/dist/market_adapter/utils/paths.js.map +1 -1
  106. package/dist/modules/account_bots.d.ts +1 -1
  107. package/dist/modules/account_bots.d.ts.map +1 -1
  108. package/dist/modules/account_bots.js +90 -97
  109. package/dist/modules/account_bots.js.map +1 -1
  110. package/dist/modules/account_orders.d.ts +0 -9
  111. package/dist/modules/account_orders.d.ts.map +1 -1
  112. package/dist/modules/account_orders.js +26 -121
  113. package/dist/modules/account_orders.js.map +1 -1
  114. package/dist/modules/authority_resolver.js +12 -18
  115. package/dist/modules/authority_resolver.js.map +1 -1
  116. package/dist/modules/bitshares-native/chain_client.js +16 -21
  117. package/dist/modules/bitshares-native/chain_client.js.map +1 -1
  118. package/dist/modules/bitshares-native/crypto/ecc.browser.js +12 -72
  119. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
  120. package/dist/modules/bitshares-native/crypto/ecc.js +13 -40
  121. package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
  122. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
  123. package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -6
  124. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
  125. package/dist/modules/bitshares-native/index.d.ts +8 -8
  126. package/dist/modules/bitshares-native/index.d.ts.map +1 -1
  127. package/dist/modules/bitshares-native/index.js +11 -68
  128. package/dist/modules/bitshares-native/index.js.map +1 -1
  129. package/dist/modules/bitshares-native/lru_cache.js +3 -6
  130. package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
  131. package/dist/modules/bitshares-native/resolvers.js +9 -11
  132. package/dist/modules/bitshares-native/resolvers.js.map +1 -1
  133. package/dist/modules/bitshares-native/serial/chain_constants.js +3 -28
  134. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
  135. package/dist/modules/bitshares-native/serial/index.d.ts +4 -4
  136. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
  137. package/dist/modules/bitshares-native/serial/index.js +5 -46
  138. package/dist/modules/bitshares-native/serial/index.js.map +1 -1
  139. package/dist/modules/bitshares-native/serial/operations.d.ts +98 -98
  140. package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
  141. package/dist/modules/bitshares-native/serial/operations.js +372 -473
  142. package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
  143. package/dist/modules/bitshares-native/serial/serializer.js +3 -8
  144. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
  145. package/dist/modules/bitshares-native/serial/types.js +9 -74
  146. package/dist/modules/bitshares-native/serial/types.js.map +1 -1
  147. package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
  148. package/dist/modules/bitshares-native/signing_client.js +11 -48
  149. package/dist/modules/bitshares-native/signing_client.js.map +1 -1
  150. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
  151. package/dist/modules/bitshares-native/subscriptions.js +24 -27
  152. package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
  153. package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
  154. package/dist/modules/bitshares-native/transport.js +14 -26
  155. package/dist/modules/bitshares-native/transport.js.map +1 -1
  156. package/dist/modules/bitshares-native/tx/builder.js +29 -72
  157. package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
  158. package/dist/modules/bitshares-native/tx/tx_cache.js +12 -21
  159. package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
  160. package/dist/modules/bitshares_client.d.ts +21 -0
  161. package/dist/modules/bitshares_client.d.ts.map +1 -1
  162. package/dist/modules/bitshares_client.js +32 -86
  163. package/dist/modules/bitshares_client.js.map +1 -1
  164. package/dist/modules/bot_settings.d.ts.map +1 -1
  165. package/dist/modules/bot_settings.js +30 -49
  166. package/dist/modules/bot_settings.js.map +1 -1
  167. package/dist/modules/bots_file_lock.d.ts.map +1 -1
  168. package/dist/modules/bots_file_lock.js +5 -13
  169. package/dist/modules/bots_file_lock.js.map +1 -1
  170. package/dist/modules/broadcast_failure.js +1 -3
  171. package/dist/modules/broadcast_failure.js.map +1 -1
  172. package/dist/modules/chain_keys.d.ts +4 -9
  173. package/dist/modules/chain_keys.d.ts.map +1 -1
  174. package/dist/modules/chain_keys.js +77 -182
  175. package/dist/modules/chain_keys.js.map +1 -1
  176. package/dist/modules/chain_orders.d.ts +2 -2
  177. package/dist/modules/chain_orders.d.ts.map +1 -1
  178. package/dist/modules/chain_orders.js +81 -144
  179. package/dist/modules/chain_orders.js.map +1 -1
  180. package/dist/modules/config.d.ts.map +1 -1
  181. package/dist/modules/config.js +23 -28
  182. package/dist/modules/config.js.map +1 -1
  183. package/dist/modules/constants.d.ts +2 -9
  184. package/dist/modules/constants.d.ts.map +1 -1
  185. package/dist/modules/constants.js +38 -73
  186. package/dist/modules/constants.js.map +1 -1
  187. package/dist/modules/cr_planner.js +15 -26
  188. package/dist/modules/cr_planner.js.map +1 -1
  189. package/dist/modules/credential_policy.d.ts +3 -6
  190. package/dist/modules/credential_policy.d.ts.map +1 -1
  191. package/dist/modules/credential_policy.js +62 -153
  192. package/dist/modules/credential_policy.js.map +1 -1
  193. package/dist/modules/credential_runtime.d.ts +1 -1
  194. package/dist/modules/credential_runtime.d.ts.map +1 -1
  195. package/dist/modules/credential_runtime.js +34 -41
  196. package/dist/modules/credential_runtime.js.map +1 -1
  197. package/dist/modules/credential_session_cache.d.ts +1 -1
  198. package/dist/modules/credential_session_cache.d.ts.map +1 -1
  199. package/dist/modules/credential_session_cache.js +5 -42
  200. package/dist/modules/credential_session_cache.js.map +1 -1
  201. package/dist/modules/credit_runtime.d.ts.map +1 -1
  202. package/dist/modules/credit_runtime.js +126 -162
  203. package/dist/modules/credit_runtime.js.map +1 -1
  204. package/dist/modules/crypto/browser_provider.d.ts +1 -1
  205. package/dist/modules/crypto/browser_provider.d.ts.map +1 -1
  206. package/dist/modules/crypto/browser_provider.js +7 -11
  207. package/dist/modules/crypto/browser_provider.js.map +1 -1
  208. package/dist/modules/crypto/index.d.ts +6 -6
  209. package/dist/modules/crypto/index.d.ts.map +1 -1
  210. package/dist/modules/crypto/index.js +12 -30
  211. package/dist/modules/crypto/index.js.map +1 -1
  212. package/dist/modules/crypto/node_provider.d.ts +1 -1
  213. package/dist/modules/crypto/node_provider.d.ts.map +1 -1
  214. package/dist/modules/crypto/node_provider.js +3 -5
  215. package/dist/modules/crypto/node_provider.js.map +1 -1
  216. package/dist/modules/crypto/provider.js +1 -2
  217. package/dist/modules/crypto/pure_ripemd160.js +1 -3
  218. package/dist/modules/crypto/pure_ripemd160.js.map +1 -1
  219. package/dist/modules/crypto/pure_scrypt.js +1 -4
  220. package/dist/modules/crypto/pure_scrypt.js.map +1 -1
  221. package/dist/modules/crypto/pure_secp256k1.d.ts +1 -1
  222. package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
  223. package/dist/modules/crypto/pure_secp256k1.js +1 -16
  224. package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
  225. package/dist/modules/crypto/sync.d.ts.map +1 -1
  226. package/dist/modules/crypto/sync.js +16 -17
  227. package/dist/modules/crypto/sync.js.map +1 -1
  228. package/dist/modules/daemon_node_health.js +14 -16
  229. package/dist/modules/daemon_node_health.js.map +1 -1
  230. package/dist/modules/dexbot_class.d.ts +19 -14
  231. package/dist/modules/dexbot_class.d.ts.map +1 -1
  232. package/dist/modules/dexbot_class.js +127 -164
  233. package/dist/modules/dexbot_class.js.map +1 -1
  234. package/dist/modules/dexbot_cow_runtime.d.ts +28 -27
  235. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  236. package/dist/modules/dexbot_cow_runtime.js +55 -45
  237. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  238. package/dist/modules/dexbot_credential_client.d.ts +6 -2
  239. package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
  240. package/dist/modules/dexbot_credential_client.js +21 -31
  241. package/dist/modules/dexbot_credential_client.js.map +1 -1
  242. package/dist/modules/dexbot_fill_runtime.d.ts +23 -23
  243. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  244. package/dist/modules/dexbot_fill_runtime.js +119 -77
  245. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  246. package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -38
  247. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  248. package/dist/modules/dexbot_maintenance_runtime.js +81 -81
  249. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  250. package/dist/modules/dexbot_startup_runtime.d.ts +3 -3
  251. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  252. package/dist/modules/dexbot_startup_runtime.js +43 -81
  253. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  254. package/dist/modules/dexbot_state_recovery.d.ts +11 -11
  255. package/dist/modules/dexbot_state_recovery.js +32 -78
  256. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  257. package/dist/modules/env.js +3 -7
  258. package/dist/modules/env.js.map +1 -1
  259. package/dist/modules/fund_registry.d.ts.map +1 -1
  260. package/dist/modules/fund_registry.js +12 -24
  261. package/dist/modules/fund_registry.js.map +1 -1
  262. package/dist/modules/general_settings.js +10 -16
  263. package/dist/modules/general_settings.js.map +1 -1
  264. package/dist/modules/graceful_shutdown.d.ts.map +1 -1
  265. package/dist/modules/graceful_shutdown.js +12 -19
  266. package/dist/modules/graceful_shutdown.js.map +1 -1
  267. package/dist/modules/key_store.d.ts.map +1 -1
  268. package/dist/modules/key_store.js +27 -65
  269. package/dist/modules/key_store.js.map +1 -1
  270. package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
  271. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  272. package/dist/modules/launcher/bot_supervisor.js +89 -118
  273. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  274. package/dist/modules/launcher/child_env.js +1 -5
  275. package/dist/modules/launcher/child_env.js.map +1 -1
  276. package/dist/modules/launcher/credential_bootstrap.js +22 -31
  277. package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
  278. package/dist/modules/launcher/credential_daemon.js +37 -75
  279. package/dist/modules/launcher/credential_daemon.js.map +1 -1
  280. package/dist/modules/launcher/credential_secret.js +2 -37
  281. package/dist/modules/launcher/credential_secret.js.map +1 -1
  282. package/dist/modules/launcher/foreign_cred_daemon.js +25 -31
  283. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  284. package/dist/modules/launcher/headless_password.js +10 -12
  285. package/dist/modules/launcher/headless_password.js.map +1 -1
  286. package/dist/modules/launcher/launch_modes.js +3 -9
  287. package/dist/modules/launcher/launch_modes.js.map +1 -1
  288. package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
  289. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  290. package/dist/modules/launcher/market_adapter_runtime.js +25 -35
  291. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  292. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
  293. package/dist/modules/launcher/market_adapter_watchdog.js +42 -45
  294. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
  295. package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
  296. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  297. package/dist/modules/launcher/monolithic_runtime.js +67 -138
  298. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  299. package/dist/modules/launcher/runtime_entry.d.ts +1 -11
  300. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
  301. package/dist/modules/launcher/runtime_entry.js +12 -15
  302. package/dist/modules/launcher/runtime_entry.js.map +1 -1
  303. package/dist/modules/launcher/status_reporting.d.ts +1 -1
  304. package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
  305. package/dist/modules/launcher/status_reporting.js +15 -36
  306. package/dist/modules/launcher/status_reporting.js.map +1 -1
  307. package/dist/modules/launcher/supervisor_control.js +4 -9
  308. package/dist/modules/launcher/supervisor_control.js.map +1 -1
  309. package/dist/modules/logger.d.ts +1 -1
  310. package/dist/modules/logger.d.ts.map +1 -1
  311. package/dist/modules/logger.js +3 -38
  312. package/dist/modules/logger.js.map +1 -1
  313. package/dist/modules/market_adapter_whitelist.js +9 -18
  314. package/dist/modules/market_adapter_whitelist.js.map +1 -1
  315. package/dist/modules/node_failure_ledger.js +1 -3
  316. package/dist/modules/node_failure_ledger.js.map +1 -1
  317. package/dist/modules/node_health_cache.d.ts.map +1 -1
  318. package/dist/modules/node_health_cache.js +15 -25
  319. package/dist/modules/node_health_cache.js.map +1 -1
  320. package/dist/modules/node_manager.d.ts +1 -1
  321. package/dist/modules/node_manager.d.ts.map +1 -1
  322. package/dist/modules/node_manager.js +44 -43
  323. package/dist/modules/node_manager.js.map +1 -1
  324. package/dist/modules/order/accounting.d.ts.map +1 -1
  325. package/dist/modules/order/accounting.js +102 -118
  326. package/dist/modules/order/accounting.js.map +1 -1
  327. package/dist/modules/order/async_lock.d.ts +3 -15
  328. package/dist/modules/order/async_lock.d.ts.map +1 -1
  329. package/dist/modules/order/async_lock.js +6 -26
  330. package/dist/modules/order/async_lock.js.map +1 -1
  331. package/dist/modules/order/export.js +34 -75
  332. package/dist/modules/order/export.js.map +1 -1
  333. package/dist/modules/order/format.d.ts +1 -3
  334. package/dist/modules/order/format.d.ts.map +1 -1
  335. package/dist/modules/order/format.js +4 -24
  336. package/dist/modules/order/format.js.map +1 -1
  337. package/dist/modules/order/grid.d.ts +3 -3
  338. package/dist/modules/order/grid.d.ts.map +1 -1
  339. package/dist/modules/order/grid.js +206 -262
  340. package/dist/modules/order/grid.js.map +1 -1
  341. package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
  342. package/dist/modules/order/grid_reconcile.js +77 -94
  343. package/dist/modules/order/grid_reconcile.js.map +1 -1
  344. package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
  345. package/dist/modules/order/grid_reconcile_internal.js +117 -149
  346. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  347. package/dist/modules/order/index.d.ts.map +1 -1
  348. package/dist/modules/order/index.js +11 -45
  349. package/dist/modules/order/index.js.map +1 -1
  350. package/dist/modules/order/logger.js +28 -69
  351. package/dist/modules/order/logger.js.map +1 -1
  352. package/dist/modules/order/logger_state.d.ts.map +1 -1
  353. package/dist/modules/order/logger_state.js +3 -4
  354. package/dist/modules/order/logger_state.js.map +1 -1
  355. package/dist/modules/order/manager.d.ts +10 -0
  356. package/dist/modules/order/manager.d.ts.map +1 -1
  357. package/dist/modules/order/manager.js +131 -151
  358. package/dist/modules/order/manager.js.map +1 -1
  359. package/dist/modules/order/processed_fill_store.js +2 -7
  360. package/dist/modules/order/processed_fill_store.js.map +1 -1
  361. package/dist/modules/order/strategy.js +23 -25
  362. package/dist/modules/order/strategy.js.map +1 -1
  363. package/dist/modules/order/sync_engine.d.ts +27 -0
  364. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  365. package/dist/modules/order/sync_engine.js +232 -181
  366. package/dist/modules/order/sync_engine.js.map +1 -1
  367. package/dist/modules/order/utils/math.d.ts +1 -25
  368. package/dist/modules/order/utils/math.d.ts.map +1 -1
  369. package/dist/modules/order/utils/math.js +49 -172
  370. package/dist/modules/order/utils/math.js.map +1 -1
  371. package/dist/modules/order/utils/order.d.ts +46 -2
  372. package/dist/modules/order/utils/order.d.ts.map +1 -1
  373. package/dist/modules/order/utils/order.js +165 -143
  374. package/dist/modules/order/utils/order.js.map +1 -1
  375. package/dist/modules/order/utils/system.d.ts +3 -1
  376. package/dist/modules/order/utils/system.d.ts.map +1 -1
  377. package/dist/modules/order/utils/system.js +152 -211
  378. package/dist/modules/order/utils/system.js.map +1 -1
  379. package/dist/modules/order/utils/timeout.js +1 -4
  380. package/dist/modules/order/utils/timeout.js.map +1 -1
  381. package/dist/modules/order/utils/validate.js +91 -142
  382. package/dist/modules/order/utils/validate.js.map +1 -1
  383. package/dist/modules/order/utils/withPoolRef.js +21 -61
  384. package/dist/modules/order/utils/withPoolRef.js.map +1 -1
  385. package/dist/modules/order/working_grid.js +6 -9
  386. package/dist/modules/order/working_grid.js.map +1 -1
  387. package/dist/modules/path_api.d.ts.map +1 -1
  388. package/dist/modules/path_api.js +8 -11
  389. package/dist/modules/path_api.js.map +1 -1
  390. package/dist/modules/paths.d.ts.map +1 -1
  391. package/dist/modules/paths.js +61 -67
  392. package/dist/modules/paths.js.map +1 -1
  393. package/dist/modules/process_discovery.js +13 -21
  394. package/dist/modules/process_discovery.js.map +1 -1
  395. package/dist/modules/runtime.js +7 -11
  396. package/dist/modules/runtime.js.map +1 -1
  397. package/dist/modules/runtime_settings.d.ts.map +1 -1
  398. package/dist/modules/runtime_settings.js +14 -16
  399. package/dist/modules/runtime_settings.js.map +1 -1
  400. package/dist/modules/settings_merge.js +1 -3
  401. package/dist/modules/settings_merge.js.map +1 -1
  402. package/dist/modules/socket_json_client.js +3 -5
  403. package/dist/modules/socket_json_client.js.map +1 -1
  404. package/dist/modules/storage/browser_adapter.js +1 -4
  405. package/dist/modules/storage/browser_adapter.js.map +1 -1
  406. package/dist/modules/storage/index.d.ts +3 -2
  407. package/dist/modules/storage/index.d.ts.map +1 -1
  408. package/dist/modules/storage/index.js +5 -8
  409. package/dist/modules/storage/index.js.map +1 -1
  410. package/dist/modules/storage/node_adapter.d.ts +3 -4
  411. package/dist/modules/storage/node_adapter.d.ts.map +1 -1
  412. package/dist/modules/storage/node_adapter.js +12 -16
  413. package/dist/modules/storage/node_adapter.js.map +1 -1
  414. package/dist/modules/storage/types.js +1 -2
  415. package/dist/modules/types.d.ts +0 -6
  416. package/dist/modules/types.d.ts.map +1 -1
  417. package/dist/modules/types.js +1 -2
  418. package/dist/modules/types.js.map +1 -1
  419. package/dist/modules/utils/base58check.js +8 -15
  420. package/dist/modules/utils/base58check.js.map +1 -1
  421. package/dist/modules/utils/build_dir.js +3 -7
  422. package/dist/modules/utils/build_dir.js.map +1 -1
  423. package/dist/modules/utils/errors.js +1 -5
  424. package/dist/modules/utils/errors.js.map +1 -1
  425. package/dist/modules/utils/math_utils.d.ts +1 -1
  426. package/dist/modules/utils/math_utils.d.ts.map +1 -1
  427. package/dist/modules/utils/math_utils.js +2 -7
  428. package/dist/modules/utils/math_utils.js.map +1 -1
  429. package/dist/modules/validate_profiles.d.ts.map +1 -1
  430. package/dist/modules/validate_profiles.js +18 -25
  431. package/dist/modules/validate_profiles.js.map +1 -1
  432. package/dist/pm2.d.ts +4 -70
  433. package/dist/pm2.d.ts.map +1 -1
  434. package/dist/pm2.js +106 -132
  435. package/dist/pm2.js.map +1 -1
  436. package/dist/scripts/analyze-git.js +13 -17
  437. package/dist/scripts/analyze-git.js.map +1 -1
  438. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  439. package/dist/scripts/analyze-orders.js +48 -63
  440. package/dist/scripts/analyze-orders.js.map +1 -1
  441. package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
  442. package/dist/scripts/diagnose-kibana-candles.js +2 -1
  443. package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
  444. package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
  445. package/dist/scripts/diagnose-pool-history.js +2 -1
  446. package/dist/scripts/diagnose-pool-history.js.map +1 -1
  447. package/dist/scripts/divergence-calc.d.ts.map +1 -1
  448. package/dist/scripts/divergence-calc.js +2 -2
  449. package/dist/scripts/divergence-calc.js.map +1 -1
  450. package/dist/scripts/fix-err-message.js +17 -22
  451. package/dist/scripts/fix-err-message.js.map +1 -1
  452. package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
  453. package/dist/scripts/generate_lp_chart.js +7 -15
  454. package/dist/scripts/generate_lp_chart.js.map +1 -1
  455. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -1
  456. package/dist/scripts/generate_mainnet_corpus_report.js +3 -2
  457. package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
  458. package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
  459. package/dist/scripts/generate_market_adapter_whitelist.js +18 -24
  460. package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
  461. package/dist/scripts/native_release_gates.js +15 -19
  462. package/dist/scripts/native_release_gates.js.map +1 -1
  463. package/dist/scripts/print_grid.d.ts.map +1 -1
  464. package/dist/scripts/print_grid.js +2 -2
  465. package/dist/scripts/print_grid.js.map +1 -1
  466. package/dist/scripts/run-tests.js +12 -17
  467. package/dist/scripts/run-tests.js.map +1 -1
  468. package/dist/scripts/runner.d.ts.map +1 -1
  469. package/dist/scripts/runner.js +18 -20
  470. package/dist/scripts/runner.js.map +1 -1
  471. package/dist/scripts/sync-version.js +2 -2
  472. package/dist/scripts/sync-version.js.map +1 -1
  473. package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
  474. package/dist/scripts/test-credit-renewal.js +4 -3
  475. package/dist/scripts/test-credit-renewal.js.map +1 -1
  476. package/dist/scripts/update.js +77 -89
  477. package/dist/scripts/update.js.map +1 -1
  478. package/dist/scripts/validate_bots.d.ts.map +1 -1
  479. package/dist/scripts/validate_bots.js +2 -2
  480. package/dist/scripts/validate_bots.js.map +1 -1
  481. package/dist/scripts/verify-browser-bundle.js +12 -17
  482. package/dist/scripts/verify-browser-bundle.js.map +1 -1
  483. package/dist/unlock.d.ts +0 -30
  484. package/dist/unlock.d.ts.map +1 -1
  485. package/dist/unlock.js +95 -143
  486. package/dist/unlock.js.map +1 -1
  487. package/package.json +5 -8
  488. package/scripts/README.md +1 -1
  489. package/scripts/create-bot-symlinks.sh +2 -2
  490. package/dist/modules/utils/fs_utils.d.ts +0 -18
  491. package/dist/modules/utils/fs_utils.d.ts.map +0 -1
  492. package/dist/modules/utils/fs_utils.js +0 -32
  493. package/dist/modules/utils/fs_utils.js.map +0 -1
  494. package/dist/scripts/migrate_bot_keys.d.ts +0 -3
  495. package/dist/scripts/migrate_bot_keys.d.ts.map +0 -1
  496. package/dist/scripts/migrate_bot_keys.js +0 -225
  497. package/dist/scripts/migrate_bot_keys.js.map +0 -1
@@ -1,21 +1,30 @@
1
- "use strict";
2
1
  /** Maintenance runtime - periodic sync loops, grid health checks, rebalance */
3
- const { createHash } = require('./crypto/sync');
4
- const fs = require('fs');
5
- const { path } = require('./path_api');
6
- const { spawn } = require('child_process');
7
- const chainOrders = require('./chain_orders');
8
- const { readOpenOrdersGuarded } = require('./chain_orders');
9
- const grid = require('./order/grid');
10
- const { ORDER_STATES, ORDER_TYPES, TIMING, BTS_PRECISION, NATIVE_CLIENT } = require('./constants');
11
- const { PATHS } = require('./paths');
12
- const Format = require('./order/format');
13
- const { getStorage } = require('./storage');
2
+ import { createRequire } from 'node:module';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { dirname as _esmDirname } from 'node:path';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = _esmDirname(__filename);
7
+ const require = createRequire(import.meta.url);
8
+ import fs from 'node:fs';
9
+ import { spawn } from 'node:child_process';
10
+ import { createHash } from './crypto/sync.js';
11
+ import { path } from './path_api.js';
12
+ import * as chainOrders from './chain_orders.js';
13
+ import * as grid from './order/grid.js';
14
+ import { ORDER_STATES, ORDER_TYPES, TIMING, BTS_PRECISION, NATIVE_CLIENT } from './constants.js';
15
+ const { readOpenOrdersGuarded } = chainOrders;
16
+ import { PATHS } from './paths.js';
17
+ import * as Format from './order/format.js';
18
+ import { getStorage } from './storage/index.js';
14
19
  const storage = getStorage();
15
- const fundRegistry = require('./fund_registry');
16
- const { BitShares } = require('./bitshares_client');
17
- const { BroadcastUncertainError } = require('./dexbot_credential_client');
18
- const { Config } = require('./config');
20
+ const { ensureDir, unlink: safeUnlink } = storage;
21
+ import * as fundRegistry from './fund_registry.js';
22
+ import * as bitsharesModule from './bitshares_client.js';
23
+ const { BitShares } = bitsharesModule;
24
+ import { BroadcastUncertainError } from './dexbot_credential_client.js';
25
+ import * as configModule from './config.js';
26
+ const { Config } = configModule;
27
+ import { getErrorMessage } from './utils/errors.js';
19
28
  function hasOpenOrdersSyncLoopMsSet(...args) { return require('./config').hasOpenOrdersSyncLoopMsSet(...args); }
20
29
  function getOpenOrdersSyncLoopMs(...args) { return require('./config').getOpenOrdersSyncLoopMs(...args); }
21
30
  function isGridBloated(...args) { return grid.isGridBloated(...args); }
@@ -47,8 +56,6 @@ function getActiveOrdersTotal(config) { return require('./order/utils/order').ge
47
56
  function correctAllPriceMismatches(...args) { return require('./order/utils/order').correctAllPriceMismatches(...args); }
48
57
  function isOrderOnChain(...args) { return require('./order/utils/order').isOrderOnChain(...args); }
49
58
  function parseChainOrder(...args) { return require('./order/utils/order').parseChainOrder(...args); }
50
- const { ensureDir, safeUnlink } = require('./utils/fs_utils');
51
- const { getErrorMessage } = require('./utils/errors');
52
59
  const CODE_ROOT = path.join(__dirname, '..');
53
60
  const PROFILES_DIR = PATHS.PROFILES_DIR;
54
61
  const PROFILES_BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
@@ -102,7 +109,7 @@ function usesAmaGridPrice(bot) {
102
109
  /**
103
110
  * Find a bot entry in the bots config snapshot that matches a runtime config.
104
111
  * Matches by botKey or name.
105
- * @param {import('./types').BotsConfigSnapshot} snapshot - Bots configuration snapshot
112
+ * @param {import('./types.js').BotsConfigSnapshot} snapshot - Bots configuration snapshot
106
113
  * @param {Object} config - Runtime bot configuration
107
114
  * @returns {Object|null} Matched bot entry or null
108
115
  */
@@ -124,7 +131,7 @@ function findSnapshotBotForRuntimeConfig(snapshot, config) {
124
131
  }
125
132
  /**
126
133
  * Check if a runtime bot configuration requires the market adapter.
127
- * @param {import('./types').BotsConfigSnapshot} snapshot - Bots configuration snapshot
134
+ * @param {import('./types.js').BotsConfigSnapshot} snapshot - Bots configuration snapshot
128
135
  * @param {Object} config - Runtime bot configuration
129
136
  * @returns {boolean} True if the bot uses AMA grid pricing
130
137
  */
@@ -196,7 +203,7 @@ async function maybeRunTargetedDriftReconciliation(bot, context) {
196
203
  const now = Date.now();
197
204
  const cooldownMs = Number.isFinite(Number(bot._targetedDriftSyncCooldownMs))
198
205
  ? Number(bot._targetedDriftSyncCooldownMs)
199
- : 60_000;
206
+ : TIMING.TARGETED_DRIFT_SYNC_COOLDOWN_MS;
200
207
  const lastSyncAt = Number(bot._lastTargetedDriftSyncAt || 0);
201
208
  if (lastSyncAt > 0 && now - lastSyncAt < cooldownMs) {
202
209
  bot._log(`[TARGETED-SYNC] Deferring ${context} reconciliation for ${Math.ceil((cooldownMs - (now - lastSyncAt)) / TIMING.MILLISECONDS_PER_SECOND)}s: ${trigger.reason}`, 'debug');
@@ -245,7 +252,7 @@ async function maybeRunTargetedDriftReconciliation(bot, context) {
245
252
  }
246
253
  /**
247
254
  * Load and fingerprint the bots.json configuration file.
248
- * @returns {import('./types').BotsConfigSnapshot} Snapshot with exists flag, fingerprint, active bots list, and adapter requirement
255
+ * @returns {import('./types.js').BotsConfigSnapshot} Snapshot with exists flag, fingerprint, active bots list, and adapter requirement
249
256
  */
250
257
  function loadBotsConfigSnapshot() {
251
258
  if (!storage.exists(PROFILES_BOTS_FILE)) {
@@ -363,9 +370,9 @@ async function stopMarketAdapterPm2() {
363
370
  /**
364
371
  * Synchronize market adapter state based on periodic config checks.
365
372
  * Starts or stops the market adapter based on whether any active bot uses AMA grid pricing.
366
- * @param {import('./dexbot_class').DEXBot} bot
373
+ * @param {import('./dexbot_class.js').DEXBot} bot
367
374
  * @param {string} [context='periodic'] - Context label for logging
368
- * @returns {Promise<import('./types').MarketAdapterSyncResult>}
375
+ * @returns {Promise<import('./types.js').MarketAdapterSyncResult>}
369
376
  */
370
377
  async function syncMarketAdapterOnPeriodicConfigCheck(bot, context = 'periodic') {
371
378
  if (bot._marketAdapterWatchdogInFlight) {
@@ -499,9 +506,9 @@ async function syncMarketAdapterOnPeriodicConfigCheck(bot, context = 'periodic')
499
506
  /**
500
507
  * Refresh the dynamic weight distribution from the AMA center snapshot.
501
508
  * Applies live dynamic weights if the bot is whitelisted and weights are ready.
502
- * @param {import('./dexbot_class').DEXBot} bot
509
+ * @param {import('./dexbot_class.js').DEXBot} bot
503
510
  * @param {string} [context='runtime'] - Context label for logging
504
- * @returns {import('./types').DynamicWeightRefreshResult}
511
+ * @returns {import('./types.js').DynamicWeightRefreshResult}
505
512
  */
506
513
  function refreshDynamicWeightDistribution(bot, context = 'runtime') {
507
514
  const baseWeights = cloneWeightDistribution(bot._baseWeightDistribution, bot.config?.weightDistribution || bot.manager?.config?.weightDistribution);
@@ -557,7 +564,7 @@ function refreshDynamicWeightDistribution(bot, context = 'runtime') {
557
564
  * Read and parse a trigger file's metadata payload.
558
565
  * Determines whether the trigger originated from the market adapter or was manual.
559
566
  * @param {string} triggerFile - Path to the trigger file
560
- * @returns {import('./types').GridResyncMetadata} Parsed trigger metadata
567
+ * @returns {import('./types.js').GridResyncMetadata} Parsed trigger metadata
561
568
  */
562
569
  function readTriggerMetadata(triggerFile) {
563
570
  const manualTriggerMetadata = (payload = null) => ({
@@ -591,7 +598,7 @@ function readTriggerMetadata(triggerFile) {
591
598
  * Build grid resync metadata from a reason string.
592
599
  * Maps known reason strings to structured metadata with refresh flags.
593
600
  * @param {string} reason - Resync reason identifier (e.g. 'manual_grid_resync', 'rms_structural_grid_resync')
594
- * @returns {import('./types').GridResyncMetadata}
601
+ * @returns {import('./types.js').GridResyncMetadata}
595
602
  */
596
603
  function buildGridResyncMetadata(reason) {
597
604
  const resetSource = String(reason || '').trim() || 'dexbot_grid_resync';
@@ -615,8 +622,8 @@ function buildGridResyncMetadata(reason) {
615
622
  }
616
623
  /**
617
624
  * Build grid resync options from a reason string or metadata object.
618
- * @param {string|import('./types').GridResyncMetadata} reasonOrMetadata - Reason string or metadata object
619
- * @returns {import('./types').GridResyncOptions}
625
+ * @param {string|import('./types.js').GridResyncMetadata} reasonOrMetadata - Reason string or metadata object
626
+ * @returns {import('./types.js').GridResyncOptions}
620
627
  */
621
628
  function buildGridResyncOptions(reasonOrMetadata) {
622
629
  const metadata = typeof reasonOrMetadata === 'string'
@@ -703,8 +710,8 @@ function updateBotGridResetMetadata(botKey, options = {}) {
703
710
  /**
704
711
  * Perform a full grid resync: reload config, optionally refresh center price,
705
712
  * recalculate the grid, persist, and record reset metadata.
706
- * @param {import('./dexbot_class').DEXBot} bot
707
- * @param {import('./types').GridResyncOptions} [options] - Grid resync options
713
+ * @param {import('./dexbot_class.js').DEXBot} bot
714
+ * @param {import('./types.js').GridResyncOptions} [options] - Grid resync options
708
715
  * @param {boolean} [options.skipIdle=false] - Skip the idle-cooldown deferral
709
716
  * @returns {Promise<boolean>} True if resync succeeded
710
717
  */
@@ -843,7 +850,7 @@ function performGridResync(bot, options = {}) {
843
850
  /**
844
851
  * Handle a pending trigger file detected at startup or during runtime.
845
852
  * Processes the trigger and performs a grid resync if the trigger file exists.
846
- * @param {import('./dexbot_class').DEXBot} bot
853
+ * @param {import('./dexbot_class.js').DEXBot} bot
847
854
  * @returns {Promise<boolean>} True if reset was handled successfully
848
855
  */
849
856
  async function handlePendingTriggerReset(bot) {
@@ -864,7 +871,7 @@ async function handlePendingTriggerReset(bot) {
864
871
  /**
865
872
  * Set up a file watcher on the profiles directory to detect trigger file creation.
866
873
  * When a trigger file appears, debounces and processes the grid resync.
867
- * @param {import('./dexbot_class').DEXBot} bot
874
+ * @param {import('./dexbot_class.js').DEXBot} bot
868
875
  * @returns {Promise<void>}
869
876
  */
870
877
  async function setupTriggerFileDetection(bot) {
@@ -923,7 +930,7 @@ async function setupTriggerFileDetection(bot) {
923
930
  /**
924
931
  * Perform periodic grid health checks (divergence, spread condition, dust detection).
925
932
  * Called as part of the periodic blockchain fetch interval.
926
- * @param {import('./dexbot_class').DEXBot} bot
933
+ * @param {import('./dexbot_class.js').DEXBot} bot
927
934
  * @returns {Promise<void>}
928
935
  */
929
936
  async function performPeriodicGridChecks(bot) {
@@ -936,7 +943,7 @@ async function performPeriodicGridChecks(bot) {
936
943
  }
937
944
  /**
938
945
  * Check if the continuous open-orders sync loop is enabled.
939
- * @param {import('./dexbot_class').DEXBot} bot
946
+ * @param {import('./dexbot_class.js').DEXBot} bot
940
947
  * @returns {boolean} True if the sync loop is enabled in TIMING config
941
948
  */
942
949
  function isOpenOrdersSyncLoopEnabled(bot) {
@@ -948,7 +955,7 @@ function isOpenOrdersSyncLoopEnabled(bot) {
948
955
  /**
949
956
  * Start the continuous open-orders sync loop.
950
957
  * Periodically reads on-chain orders and synchronizes with the grid manager.
951
- * @param {import('./dexbot_class').DEXBot} bot
958
+ * @param {import('./dexbot_class.js').DEXBot} bot
952
959
  */
953
960
  function startOpenOrdersSyncLoop(bot) {
954
961
  if (bot._mainLoopPromise)
@@ -1022,7 +1029,7 @@ function startOpenOrdersSyncLoop(bot) {
1022
1029
  }
1023
1030
  /**
1024
1031
  * Stop the continuous open-orders sync loop.
1025
- * @param {import('./dexbot_class').DEXBot} bot
1032
+ * @param {import('./dexbot_class.js').DEXBot} bot
1026
1033
  * @returns {Promise<void>}
1027
1034
  */
1028
1035
  async function stopOpenOrdersSyncLoop(bot) {
@@ -1034,7 +1041,7 @@ async function stopOpenOrdersSyncLoop(bot) {
1034
1041
  /**
1035
1042
  * Set up the periodic blockchain fetch interval.
1036
1043
  * Periodically fetches account totals and syncs open orders from the blockchain.
1037
- * @param {import('./dexbot_class').DEXBot} bot
1044
+ * @param {import('./dexbot_class.js').DEXBot} bot
1038
1045
  */
1039
1046
  function setupBlockchainFetchInterval(bot) {
1040
1047
  let intervalMin = bot.config?.timing?.BLOCKCHAIN_FETCH_INTERVAL_MIN;
@@ -1159,7 +1166,7 @@ function setupBlockchainFetchInterval(bot) {
1159
1166
  }
1160
1167
  /**
1161
1168
  * Stop the periodic blockchain fetch interval.
1162
- * @param {import('./dexbot_class').DEXBot} bot
1169
+ * @param {import('./dexbot_class.js').DEXBot} bot
1163
1170
  */
1164
1171
  function stopBlockchainFetchInterval(bot) {
1165
1172
  if (bot._blockchainFetchInterval !== null && bot._blockchainFetchInterval !== undefined) {
@@ -1171,10 +1178,10 @@ function stopBlockchainFetchInterval(bot) {
1171
1178
  /**
1172
1179
  * Release the market adapter runtime for a bot.
1173
1180
  * In PM2 mode this is a no-op; in direct mode it calls the shared runtime's releaseBot.
1174
- * @param {import('./dexbot_class').DEXBot} bot
1181
+ * @param {import('./dexbot_class.js').DEXBot} bot
1175
1182
  * @param {string} botId - Bot identifier
1176
1183
  * @param {string} [context='shutdown'] - Context label for logging
1177
- * @returns {Promise<import('./types').MarketAdapterReleaseResult>}
1184
+ * @returns {Promise<import('./types.js').MarketAdapterReleaseResult>}
1178
1185
  */
1179
1186
  async function releaseMarketAdapterRuntime(_bot, botId, context = 'shutdown') {
1180
1187
  if (isPm2Runtime()) {
@@ -1195,25 +1202,14 @@ async function releaseMarketAdapterRuntime(_bot, botId, context = 'shutdown') {
1195
1202
  // Dust is cancelled immediately on detection — no timer infrastructure needed.
1196
1203
  /**
1197
1204
  * Check if an error message indicates that an order does not exist on the blockchain.
1205
+ * Delegates to the canonical implementation in order/utils/order.ts (single source
1206
+ * of truth shared with the correction/reconcile-cancel paths).
1198
1207
  * @param {string} message - Error message to check
1199
1208
  * @param {string} [orderId] - Optional order ID for context-aware matching
1200
1209
  * @returns {boolean} True if the message indicates a nonexistent order
1201
1210
  */
1202
1211
  function isOrderDoesNotExistError(message, orderId) {
1203
- if (typeof message !== 'string' || message.length === 0)
1204
- return false;
1205
- const normalized = message.toLowerCase();
1206
- if (/\border\b.*\bdoes not exist\b/i.test(message))
1207
- return true;
1208
- if (/\bdoes not exist\b.*\border\b/i.test(message))
1209
- return true;
1210
- if (orderId && normalized.includes(String(orderId).toLowerCase())) {
1211
- return /\bdoes not exist\b/i.test(message)
1212
- || /\bcould not find object\b/i.test(message)
1213
- || /\bunable to find object\b/i.test(message)
1214
- || /\bobject\b.*\bnot found\b/i.test(message);
1215
- }
1216
- return false;
1212
+ return require('./order/utils/order').isOrderGoneErrorMessage(message, orderId);
1217
1213
  }
1218
1214
  /**
1219
1215
  * Calculate the remaining idle delay (ms) before grid maintenance can proceed.
@@ -1224,7 +1220,7 @@ function isOrderDoesNotExistError(message, orderId) {
1224
1220
  function getMaintenanceIdleDelayMs(ctx) {
1225
1221
  const settleDelayMs = Number.isFinite(TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
1226
1222
  ? Math.max(0, TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
1227
- : 6_000;
1223
+ : TIMING.BLOCKCHAIN_SETTLE_DELAY_MS;
1228
1224
  if (settleDelayMs <= 0)
1229
1225
  return 0;
1230
1226
  if (ctx?._incomingFillQueue?.length > 0)
@@ -1265,7 +1261,7 @@ function scheduleMaintenanceAfterIdle(ctx, context, options = {}) {
1265
1261
  /**
1266
1262
  * Schedule a deferred grid resync after idle delay elapses.
1267
1263
  * @param {Object} ctx - Bot context
1268
- * @param {import('./types').GridResyncOptions} [options] - Grid resync options
1264
+ * @param {import('./types.js').GridResyncOptions} [options] - Grid resync options
1269
1265
  */
1270
1266
  function scheduleDeferredGridResync(ctx, options = {}) {
1271
1267
  if (!ctx ||
@@ -1278,7 +1274,7 @@ function scheduleDeferredGridResync(ctx, options = {}) {
1278
1274
  const triggerFileWasPresent = !!(ctx.triggerFile && storage.exists(ctx.triggerFile));
1279
1275
  const settleDelayMs = Number.isFinite(TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
1280
1276
  ? Math.max(0, TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
1281
- : 6_000;
1277
+ : TIMING.BLOCKCHAIN_SETTLE_DELAY_MS;
1282
1278
  const delayMs = idleDelayMs + settleDelayMs;
1283
1279
  if (!(delayMs > 0))
1284
1280
  return;
@@ -1309,7 +1305,7 @@ function scheduleDeferredGridResync(ctx, options = {}) {
1309
1305
  * Execute the core maintenance logic: recalculate funds, check pipeline,
1310
1306
  * refresh dynamic weights, check grid health, cancel dust orders,
1311
1307
  * apply divergence corrections, and fix spread conditions.
1312
- * @param {import('./dexbot_class').DEXBot} bot
1308
+ * @param {import('./dexbot_class.js').DEXBot} bot
1313
1309
  * @param {string} context - Context label for logging (e.g. 'periodic', 'dust-timer')
1314
1310
  * @returns {Promise<void>}
1315
1311
  */
@@ -1564,8 +1560,8 @@ async function executeMaintenanceLogic(bot, context) {
1564
1560
  * broadcast), so a BROADCAST_DEADLINE reply cannot be caused by an expired
1565
1561
  * session — re-using the original signing token is correct.
1566
1562
  *
1567
- * @param {import('./dexbot_class').DEXBot} bot
1568
- * @param {import('./types').Order} order
1563
+ * @param {import('./dexbot_class.js').DEXBot} bot
1564
+ * @param {import('./types.js').Order} order
1569
1565
  * @returns {Promise<*>} Result from chainOrders.cancelOrder
1570
1566
  */
1571
1567
  async function cancelOrderDeferredOnUncertain(bot, order) {
@@ -1584,10 +1580,10 @@ async function cancelOrderDeferredOnUncertain(bot, order) {
1584
1580
  * Each dust order is cancelled on chain and its slot is rotated through
1585
1581
  * the normal synthetic-fill pipeline. Failures are logged and retried on
1586
1582
  * the next detection cycle (next fill batch or 5-min health check).
1587
- * @param {import('./dexbot_class').DEXBot} bot
1583
+ * @param {import('./dexbot_class.js').DEXBot} bot
1588
1584
  * @param {Object} [options] - Dust cancellation options
1589
- * @param {import('./types').Order[]} [options.buy=[]] - Buy-side dust orders
1590
- * @param {import('./types').Order[]} [options.sell=[]] - Sell-side dust orders
1585
+ * @param {import('./types.js').Order[]} [options.buy=[]] - Buy-side dust orders
1586
+ * @param {import('./types.js').Order[]} [options.sell=[]] - Sell-side dust orders
1591
1587
  * @returns {Promise<{cancelledCount: number, batchResult: {aborted: boolean}|null}>}
1592
1588
  */
1593
1589
  async function cancelDustOrders(bot, { buy: buyDust = [], sell: sellDust = [] } = {}) {
@@ -1653,7 +1649,7 @@ async function cancelDustOrders(bot, { buy: buyDust = [], sell: sellDust = [] }
1653
1649
  /**
1654
1650
  * Run grid maintenance with idle detection and lock acquisition.
1655
1651
  * Checks if the bot is idle before proceeding, and acquires the fill processing lock.
1656
- * @param {import('./dexbot_class').DEXBot} bot
1652
+ * @param {import('./dexbot_class.js').DEXBot} bot
1657
1653
  * @param {string} [context='periodic'] - Context label for logging
1658
1654
  * @param {Object} [options] - Maintenance options
1659
1655
  * @param {boolean} [options.skipIdle=false] - Skip idle delay check
@@ -1696,7 +1692,7 @@ const _lastBtsAcquisitionTimestamps = new Map();
1696
1692
  * Check if the bot's BTS balance is below the minimum threshold and trigger acquisition.
1697
1693
  * Only applies to non-BTS pairs. Uses hysteresis: triggers at 1× min_BTS_value,
1698
1694
  * fills to BTS_ACQUIRE_TARGET_MULTIPLIER × min_BTS_value.
1699
- * @param {import('./dexbot_class').DEXBot} bot
1695
+ * @param {import('./dexbot_class.js').DEXBot} bot
1700
1696
  * @returns {Promise<void>}
1701
1697
  */
1702
1698
  async function checkBtsBalanceAndAcquire(bot) {
@@ -1745,7 +1741,7 @@ async function checkBtsBalanceAndAcquire(bot) {
1745
1741
  /**
1746
1742
  * Acquire BTS by swapping one of the trading pair assets through an AMM pool.
1747
1743
  * Tries both assets for a BTS pool, picks the best (lowest price impact).
1748
- * @param {import('./dexbot_class').DEXBot} bot
1744
+ * @param {import('./dexbot_class.js').DEXBot} bot
1749
1745
  * @param {number} deficit - Amount of BTS needed (float)
1750
1746
  * @returns {Promise<void>}
1751
1747
  */
@@ -1833,7 +1829,7 @@ async function acquireBts(bot, deficit) {
1833
1829
  }
1834
1830
  /**
1835
1831
  * Run a single dust health check cycle.
1836
- * @param {import('./dexbot_class').DEXBot} bot
1832
+ * @param {import('./dexbot_class.js').DEXBot} bot
1837
1833
  */
1838
1834
  async function runDustHealthCheck(bot) {
1839
1835
  if (bot._shuttingDown || !bot.manager)
@@ -1874,7 +1870,7 @@ async function runDustHealthCheck(bot) {
1874
1870
  }
1875
1871
  /**
1876
1872
  * Set up the periodic dust health check interval.
1877
- * @param {import('./dexbot_class').DEXBot} bot
1873
+ * @param {import('./dexbot_class.js').DEXBot} bot
1878
1874
  */
1879
1875
  function setupDustHealthCheckInterval(bot) {
1880
1876
  bot._dustHealthCheckTimer = setInterval(() => {
@@ -1886,7 +1882,7 @@ function setupDustHealthCheckInterval(bot) {
1886
1882
  }
1887
1883
  /**
1888
1884
  * Request a full grid reset from fresh on-chain state.
1889
- * @param {import('./dexbot_class').DEXBot} bot
1885
+ * @param {import('./dexbot_class.js').DEXBot} bot
1890
1886
  * @param {string} [reason='structural change']
1891
1887
  * @param {{refreshCenterPrice?: boolean, skipIdle?: boolean, skipFillLock?: boolean}} [options={}]
1892
1888
  * @returns {Promise<Object>}
@@ -1904,10 +1900,13 @@ async function requestGridReset(bot, reason = 'structural change', options = {})
1904
1900
  // Structural recovery resyncs are chain-read/rebuild operations that do not
1905
1901
  // mutate order state in place; running them behind the fill-processing lock
1906
1902
  // lets a fill storm starve recovery indefinitely. Skip the lock when the
1907
- // caller explicitly requests it (structural resync wiring). While the
1908
- // rebuild runs unlocked, raise _recoverySyncInFlight so the fill consumer
1909
- // defers fills entirely (no concurrent mutation race) instead of racing
1910
- // them behind a lock.
1903
+ // caller explicitly requests it (structural resync wiring), when there is
1904
+ // no lock, or when re-entrant (already under the fill lock — acquire()
1905
+ // would just re-run the callback and we want the in-flight guard active
1906
+ // so the fill consumer defers fills entirely). While the rebuild runs
1907
+ // unlocked, raise _recoverySyncInFlight so the fill consumer defers fills
1908
+ // entirely (no concurrent mutation race) instead of racing them behind a
1909
+ // lock.
1911
1910
  if (options.skipFillLock === true || !bot.manager._fillProcessingLock || bot.manager._fillProcessingLock.isReentrant()) {
1912
1911
  bot._recoverySyncInFlight = (bot._recoverySyncInFlight || 0) + 1;
1913
1912
  try {
@@ -1921,7 +1920,7 @@ async function requestGridReset(bot, reason = 'structural change', options = {})
1921
1920
  }
1922
1921
  /**
1923
1922
  * Wire the structural grid resync request handler on the manager.
1924
- * @param {import('./dexbot_class').DEXBot} bot
1923
+ * @param {import('./dexbot_class.js').DEXBot} bot
1925
1924
  */
1926
1925
  function wireStructuralGridResyncRequest(bot) {
1927
1926
  if (!bot.manager || bot.manager.requestStructuralGridResync)
@@ -2002,7 +2001,7 @@ function wireStructuralGridResyncRequest(bot) {
2002
2001
  }
2003
2002
  /**
2004
2003
  * Get current pipeline signal state for congestion checks.
2005
- * @param {import('./dexbot_class').DEXBot} bot
2004
+ * @param {import('./dexbot_class.js').DEXBot} bot
2006
2005
  * @returns {Object}
2007
2006
  */
2008
2007
  function getPipelineSignals(bot) {
@@ -2017,7 +2016,7 @@ function getPipelineSignals(bot) {
2017
2016
  }
2018
2017
  /**
2019
2018
  * Mark that grid activity occurred (updates idle timer).
2020
- * @param {import('./dexbot_class').DEXBot} bot
2019
+ * @param {import('./dexbot_class.js').DEXBot} bot
2021
2020
  * @param {string} [reason='activity']
2022
2021
  */
2023
2022
  function markGridActivity(bot, reason = 'activity') {
@@ -2026,7 +2025,7 @@ function markGridActivity(bot, reason = 'activity') {
2026
2025
  }
2027
2026
  /**
2028
2027
  * Get current metrics for monitoring and debugging.
2029
- * @param {import('./dexbot_class').DEXBot} bot
2028
+ * @param {import('./dexbot_class.js').DEXBot} bot
2030
2029
  * @returns {Object}
2031
2030
  */
2032
2031
  function getMetrics(bot) {
@@ -2043,7 +2042,7 @@ function getMetrics(bot) {
2043
2042
  }
2044
2043
  /**
2045
2044
  * Read open orders from chain, sync with local state, and process any fills found.
2046
- * @param {import('./dexbot_class').DEXBot} bot
2045
+ * @param {import('./dexbot_class.js').DEXBot} bot
2047
2046
  * @param {string} tag - Context label for logging
2048
2047
  * @returns {Promise<Object>}
2049
2048
  */
@@ -2097,7 +2096,8 @@ async function syncOpenOrdersAndProcessFills(bot, tag) {
2097
2096
  return { syncResult: null, aborted: true, hasUnmatched: -1, openOrders: null };
2098
2097
  }
2099
2098
  }
2100
- module.exports = {
2099
+ export { loadBotsConfigSnapshot, refreshDynamicWeightDistribution, performGridResync, updateBotGridResetMetadata, handlePendingTriggerReset, setupTriggerFileDetection, performPeriodicGridChecks, isOpenOrdersSyncLoopEnabled, startOpenOrdersSyncLoop, stopOpenOrdersSyncLoop, setupBlockchainFetchInterval, stopBlockchainFetchInterval, executeMaintenanceLogic, cancelDustOrders, isOrderDoesNotExistError, runGridMaintenance, stopMarketAdapterPm2, releaseMarketAdapterRuntime, syncMarketAdapterOnPeriodicConfigCheck, findSnapshotBotForRuntimeConfig, runtimeConfigNeedsMarketAdapter, usesAmaGridPrice, checkBtsBalanceAndAcquire, acquireBts, runDustHealthCheck, setupDustHealthCheckInterval, requestGridReset, wireStructuralGridResyncRequest, getPipelineSignals, markGridActivity, getMetrics, syncOpenOrdersAndProcessFills };
2100
+ export default {
2101
2101
  loadBotsConfigSnapshot,
2102
2102
  refreshDynamicWeightDistribution,
2103
2103
  performGridResync,