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
@@ -1,3 +1,83 @@
1
- declare function createSubscriptionManager(chainClient: any, overrides?: any): any;
1
+ interface WarnThrottleState {
2
+ lastAt: number;
3
+ suppressed: number;
4
+ }
5
+ interface HistoryEntry {
6
+ id?: string;
7
+ op?: unknown[];
8
+ block_num?: number;
9
+ trx_in_block?: number;
10
+ [key: string]: unknown;
11
+ }
12
+ interface AccountInfo {
13
+ account?: {
14
+ id?: string;
15
+ statistics?: string;
16
+ };
17
+ [key: string]: unknown;
18
+ }
19
+ interface SubscriptionEntry {
20
+ accountName: string;
21
+ accountId: string | null;
22
+ statisticsId: string | null;
23
+ lastDeliveredHistoryId: string;
24
+ lastNoticeAt: number;
25
+ active: boolean;
26
+ callbacks: Set<(fills: HistoryEntry[]) => unknown>;
27
+ onError: ((err: unknown) => void) | null;
28
+ reconnectRetryTimer: ReturnType<typeof setTimeout> | null;
29
+ reconnecting: boolean;
30
+ _gapRecovery: boolean;
31
+ _channelFailures: number;
32
+ _channelDegraded: boolean;
33
+ _channelRecoveryCycles: number;
34
+ _recoveryAlerted: boolean;
35
+ _channelRetryTimer: ReturnType<typeof setTimeout> | null;
36
+ _channelRetryStep: number;
37
+ _channelRetryRefills: number;
38
+ _warnThrottle: Record<string, WarnThrottleState>;
39
+ _processingHistory?: boolean;
40
+ [key: string]: unknown;
41
+ }
42
+ interface SubscriptionChainClient {
43
+ transport: {
44
+ getNodeUrl?(): string | undefined;
45
+ addMessageHandler(handler: (params: unknown) => void): UnsubscribeFn;
46
+ };
47
+ db: {
48
+ get_full_accounts(refs: string[], subscribe: boolean): Promise<Array<[string, AccountInfo]>>;
49
+ call(method: string, args: unknown[]): Promise<unknown>;
50
+ [key: string]: (...args: never[]) => Promise<unknown>;
51
+ };
52
+ history?: {
53
+ getAccountHistory?: (...args: unknown[]) => Promise<unknown[]>;
54
+ get_account_history?: (...args: unknown[]) => Promise<unknown[]>;
55
+ getAccountHistoryOperations?: (...args: unknown[]) => Promise<unknown[]>;
56
+ call(method: string, args: unknown[]): Promise<unknown>;
57
+ };
58
+ forceReconnect?(reason: string): unknown;
59
+ reportNodeFailure?(node: string, message: string, source: string): void;
60
+ getApiLimitGetAccountHistory?(): number | null;
61
+ [key: string]: unknown;
62
+ }
63
+ type UnsubscribeFn = {
64
+ (): void;
65
+ isActive?(): boolean;
66
+ };
67
+ interface SubscriptionOverrides {
68
+ noticeCoalesceMs?: number;
69
+ channelErrorLogIntervalMs?: number;
70
+ channelRetryLadderMs?: number[];
71
+ channelRetryMaxRefills?: number;
72
+ [key: string]: unknown;
73
+ }
74
+ declare function createSubscriptionManager(chainClient: SubscriptionChainClient, overrides?: SubscriptionOverrides): {
75
+ subscribe: (accountName: string, callback: (fills: HistoryEntry[]) => unknown, onError?: ((err: unknown) => void) | null) => Promise<() => void>;
76
+ unsubscribe: (accountName: string, callback?: (fills: HistoryEntry[]) => unknown) => Promise<void>;
77
+ onReconnect: () => Promise<void>;
78
+ resubscribeAll: () => Promise<void>;
79
+ removeNoticeSubscription: () => void;
80
+ getSubscriptions: () => Map<string, SubscriptionEntry>;
81
+ };
2
82
  export { createSubscriptionManager };
3
83
  //# sourceMappingURL=subscriptions.d.ts.map
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module';
3
3
  const require = createRequire(import.meta.url);
4
4
  import { NATIVE_CLIENT } from '../constants.js';
5
5
  import Logger from '../order/logger.js';
6
- import { getErrorMessage } from '../utils/errors.js';
6
+ import { getErrorMessage, getErrorField } from '../utils/errors.js';
7
7
  const { SUBSCRIPTIONS, OPERATIONS } = NATIVE_CLIENT;
8
8
  const SUBSCRIBE_CALLBACK_ID = SUBSCRIPTIONS.CALLBACK_ID;
9
9
  const OP_FILL_ORDER = OPERATIONS.FILL_ORDER;
@@ -22,7 +22,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
22
22
  // timers exist to batch RAPID notices, and tests issue notices strictly
23
23
  // sequentially — no batching to preserve, so inline is equivalent.
24
24
  const noticeCoalesceMs = Number.isFinite(overrides?.noticeCoalesceMs)
25
- ? Math.max(0, overrides.noticeCoalesceMs)
25
+ ? Math.max(0, Number(overrides.noticeCoalesceMs))
26
26
  : (Number.isFinite(SUBSCRIPTIONS.NOTICE_COALESCE_MS)
27
27
  ? Math.max(0, SUBSCRIPTIONS.NOTICE_COALESCE_MS)
28
28
  : 0);
@@ -41,7 +41,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
41
41
  ? Math.max(1, SUBSCRIPTIONS.CHANNEL_DEGRADED_FAILURE_THRESHOLD)
42
42
  : 3;
43
43
  const channelErrorLogIntervalMs = Number.isFinite(overrides?.channelErrorLogIntervalMs)
44
- ? Math.max(0, overrides.channelErrorLogIntervalMs)
44
+ ? Math.max(0, Number(overrides.channelErrorLogIntervalMs))
45
45
  : (Number.isFinite(SUBSCRIPTIONS.CHANNEL_ERROR_LOG_INTERVAL_MS)
46
46
  ? Math.max(0, SUBSCRIPTIONS.CHANNEL_ERROR_LOG_INTERVAL_MS)
47
47
  : 60000);
@@ -55,7 +55,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
55
55
  ? Math.max(1, SUBSCRIPTIONS.CHANNEL_RECOVERY_ALERT_AFTER)
56
56
  : 3;
57
57
  const channelRetryMaxRefills = Number.isFinite(overrides?.channelRetryMaxRefills)
58
- ? Math.max(0, overrides.channelRetryMaxRefills)
58
+ ? Math.max(0, Number(overrides.channelRetryMaxRefills))
59
59
  : (Number.isFinite(SUBSCRIPTIONS.CHANNEL_RETRY_MAX_REFILLS) ? Math.max(0, SUBSCRIPTIONS.CHANNEL_RETRY_MAX_REFILLS) : 3);
60
60
  // NOTE: the forced-reconnect cooldown is NOT debounced here. It is enforced
61
61
  // once per client in chain_client.forceReconnect so this watchdog and the
@@ -414,7 +414,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
414
414
  // window is safe: downstream dedups every fill by its history id (see
415
415
  // dexbot_fill_runtime _isNewFillKey). See AGENTS/bitshares-core for the
416
416
  // get_account_history range semantics this relies on.
417
- const lookbackOps = Number.isFinite(options?.lookbackOps) ? Math.max(0, Math.floor(options.lookbackOps)) : 0;
417
+ const lookbackOps = Number.isFinite(options?.lookbackOps) ? Math.max(0, Math.floor(Number(options.lookbackOps))) : 0;
418
418
  let lookbackStopHistoryId = cursorHistoryId;
419
419
  let lookbackStopInstance = cursorInstance;
420
420
  // Actual `stop` handed to get_account_history. For the no-lookback case this is
@@ -445,7 +445,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
445
445
  let startHistoryId = SUBSCRIPTIONS.HISTORY_API_OBJECT;
446
446
  let pagesFetched = 0;
447
447
  const maxPagesDefault = SUBSCRIPTIONS.HISTORY_MAX_PAGES;
448
- const maxPages = Number.isFinite(options.maxPages) ? options.maxPages : maxPagesDefault;
448
+ const maxPages = Number.isFinite(options.maxPages) ? Number(options.maxPages) : maxPagesDefault;
449
449
  // Cap page size to the node's api_limit_get_account_history to avoid FC_ASSERT.
450
450
  const configuredLimit = typeof chainClient.getApiLimitGetAccountHistory === 'function'
451
451
  ? chainClient.getApiLimitGetAccountHistory()
@@ -726,7 +726,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
726
726
  const inst = parseObjectIdInstance(fill.id);
727
727
  if (Number.isFinite(inst) && inst > latestInstance) {
728
728
  latestInstance = inst;
729
- latestId = fill.id;
729
+ latestId = fill.id ?? null;
730
730
  }
731
731
  }
732
732
  const failed = [];
@@ -814,7 +814,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
814
814
  for (const item of data) {
815
815
  if (!item)
816
816
  continue;
817
- const id = typeof item === 'object' ? item.id : item;
817
+ const id = item && typeof item === 'object' ? item.id : item;
818
818
  if (typeof id !== 'string')
819
819
  continue;
820
820
  noticeObjectIds.push(id);
@@ -956,7 +956,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
956
956
  catch (err) {
957
957
  sub.lastNoticeAt = Date.now();
958
958
  recordChannelFailure(sub, err, options?.context);
959
- if (sub.onError && !err?.subscriptionErrorReported) {
959
+ if (sub.onError && !getErrorField(err, 'subscriptionErrorReported')) {
960
960
  try {
961
961
  sub.onError(err);
962
962
  }
@@ -1023,7 +1023,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
1023
1023
  try {
1024
1024
  const accounts = await chainClient.db.get_full_accounts([entry.accountName], true);
1025
1025
  if (accounts && accounts[0] && accounts[0][1] && accounts[0][1].account) {
1026
- entry.accountId = accounts[0][1].account.id;
1026
+ entry.accountId = accounts[0][1].account.id ?? null;
1027
1027
  entry.statisticsId = accounts[0][1].account.statistics || null;
1028
1028
  }
1029
1029
  }
@@ -1162,7 +1162,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
1162
1162
  return () => { };
1163
1163
  }
1164
1164
  if (accounts && accounts[0] && accounts[0][1] && accounts[0][1].account) {
1165
- entry.accountId = accounts[0][1].account.id;
1165
+ entry.accountId = accounts[0][1].account.id ?? null;
1166
1166
  entry.statisticsId = accounts[0][1].account.statistics || null;
1167
1167
  }
1168
1168
  if (!entry.accountId) {
@@ -1281,7 +1281,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
1281
1281
  continue;
1282
1282
  refreshTasks.push(chainClient.db.get_full_accounts([entry.accountName], true).then((accounts) => {
1283
1283
  if (accounts && accounts[0] && accounts[0][1] && accounts[0][1].account) {
1284
- entry.accountId = accounts[0][1].account.id;
1284
+ entry.accountId = accounts[0][1].account.id ?? null;
1285
1285
  entry.statisticsId = accounts[0][1].account.statistics || null;
1286
1286
  }
1287
1287
  }).catch((err) => {
@@ -15,8 +15,8 @@ declare class AllNodesFailed extends Error {
15
15
  declare class RpcError extends Error {
16
16
  code: string;
17
17
  method: string;
18
- params: any[];
19
- constructor(message: string, code: string | undefined, method: string, params: any[]);
18
+ params: unknown[];
19
+ constructor(message: string, code: string | undefined, method: string, params: unknown[]);
20
20
  }
21
21
  interface TransportConfig {
22
22
  connectTimeoutMs?: number;
@@ -27,13 +27,14 @@ interface TransportConfig {
27
27
  shouldSkipNode?: ((nodeUrl: string) => boolean) | null;
28
28
  validateNode?: (() => Promise<void>) | null;
29
29
  keepAliveIntervalMs?: number;
30
+ reconnectBaseDelayMs?: number;
30
31
  }
31
32
  declare function createTransport(config?: TransportConfig): {
32
33
  connect: (servers?: string[], autoReconnect?: boolean) => Promise<void>;
33
34
  disconnect: () => void;
34
35
  forceReconnect: (reason?: string) => void;
35
- call: (method: string, params: any[], timeoutMs?: number) => Promise<any>;
36
- addMessageHandler: (handler: (params: any) => void) => (() => void) & {
36
+ call: (method: string, params: unknown[], timeoutMs?: number) => Promise<unknown>;
37
+ addMessageHandler: (handler: (params: unknown) => void) => (() => void) & {
37
38
  isActive: () => boolean;
38
39
  };
39
40
  getStatus: () => string;
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module';
3
3
  const require = createRequire(import.meta.url);
4
4
  import { NATIVE_CLIENT } from '../constants.js';
5
5
  import Logger from '../order/logger.js';
6
- import { getErrorMessage } from '../utils/errors.js';
6
+ import { getErrorMessage, getErrorField } from '../utils/errors.js';
7
7
  let _WebSocketCtor = null;
8
8
  function getWebSocketConstructor() {
9
9
  if (!_WebSocketCtor) {
@@ -62,7 +62,7 @@ class RpcError extends Error {
62
62
  }
63
63
  }
64
64
  function createTransport(config = {}) {
65
- const { connectTimeoutMs = CONNECT_TIMEOUT_MS, rpcTimeoutMs = RPC_TIMEOUT_MS, onStatusChange = null, onReconnect = null, onNodeFailure = null, shouldSkipNode = null, validateNode = null, keepAliveIntervalMs = KEEPALIVE_INTERVAL_MS, } = config;
65
+ const { connectTimeoutMs = CONNECT_TIMEOUT_MS, rpcTimeoutMs = RPC_TIMEOUT_MS, onStatusChange = null, onReconnect = null, onNodeFailure = null, shouldSkipNode = null, validateNode = null, keepAliveIntervalMs = KEEPALIVE_INTERVAL_MS, reconnectBaseDelayMs = 1000, } = config;
66
66
  let ws = null;
67
67
  let nodeUrl = null;
68
68
  let reconnectTimer = null;
@@ -188,7 +188,7 @@ function createTransport(config = {}) {
188
188
  }, SLOW_RECONNECT_INTERVAL_MS);
189
189
  return;
190
190
  }
191
- const delay = Math.min(1000 * Math.pow(2, reconnectAttempts) + Math.random() * 1000, 30000);
191
+ const delay = Math.min(reconnectBaseDelayMs * Math.pow(2, reconnectAttempts) + Math.random() * reconnectBaseDelayMs, 30000);
192
192
  reconnectAttempts++;
193
193
  reconnectTimer = setTimeout(() => {
194
194
  reconnectTimer = null;
@@ -424,7 +424,8 @@ function createTransport(config = {}) {
424
424
  catch (firstErr) {
425
425
  // All parallel attempts failed. Fall back to sequential retry for
426
426
  // environments where parallel connection floods are problematic.
427
- const errMsg = firstErr?.errors ? firstErr.errors.map((e) => e?.message || e).join('; ') : (firstErr?.message || firstErr);
427
+ const firstErrErrors = getErrorField(firstErr, 'errors');
428
+ const errMsg = firstErrErrors ? firstErrErrors.map((e) => getErrorMessage(e)).join('; ') : (getErrorMessage(firstErr));
428
429
  transportLogger.warn(`Parallel connect failed (${candidates.length} nodes), falling back to sequential: ${errMsg}`);
429
430
  }
430
431
  // Sequential fallback pass.
@@ -4,6 +4,7 @@ declare class TransactionTooLargeError extends Error {
4
4
  code: string;
5
5
  constructor(message: string);
6
6
  }
7
+ type OpParams = Record<string, unknown>;
7
8
  interface ChainClientRef {
8
9
  getConfig?(): {
9
10
  chainId: string;
@@ -13,12 +14,46 @@ interface ChainClientRef {
13
14
  };
14
15
  reportNodeFailure?(nodeUrl: string, errorMessage?: string, source?: string): void;
15
16
  db: {
16
- call(method: string, args: any[]): Promise<any>;
17
- get_objects(ids: string[]): Promise<any[]>;
18
- get_dynamic_global_properties(): Promise<any>;
19
- [key: string]: (...args: any[]) => Promise<any>;
17
+ call(method: string, args: unknown[]): Promise<unknown>;
18
+ get_objects(ids: string[]): Promise<unknown[]>;
19
+ get_dynamic_global_properties(): Promise<unknown>;
20
+ [key: string]: (...args: never[]) => Promise<unknown>;
20
21
  };
21
22
  }
22
- declare function createTransactionBuilder(chainClient: ChainClientRef): any;
23
+ interface SignedTxResult {
24
+ signedTx: Buffer;
25
+ signedTxObject: Record<string, unknown>;
26
+ digest: Buffer;
27
+ signature: Buffer;
28
+ }
29
+ interface TransactionBuilder {
30
+ addOperation(type: string, params: OpParams): this;
31
+ limit_order_create(data: OpParams): this;
32
+ limit_order_cancel(data: OpParams): this;
33
+ limit_order_update(data: OpParams): this;
34
+ call_order_update(data: OpParams): this;
35
+ asset_settle(data: OpParams): this;
36
+ transfer(data: OpParams): this;
37
+ credit_offer_accept(data: OpParams): this;
38
+ credit_deal_repay(data: OpParams): this;
39
+ credit_deal_update(data: OpParams): this;
40
+ liquidity_pool_exchange(data: OpParams): this;
41
+ setRequiredFees(feeAssetId?: string): Promise<void>;
42
+ fetchRefBlock(): Promise<void>;
43
+ setExpiration(seconds?: number): void;
44
+ prepare(feeAssetId?: string): Promise<Buffer>;
45
+ _serializeUnsigned(): Buffer;
46
+ _buildSerializedOp(type: string, params: OpParams): [number, unknown];
47
+ _castParamsToSerializable(type: string, params: OpParams): OpParams;
48
+ sign(privateKey: Buffer): SignedTxResult;
49
+ broadcast(): Promise<never>;
50
+ _getSerializedOps(): Array<[number, unknown]>;
51
+ getOperationCount(): number;
52
+ getOperations(): Array<{
53
+ type: string;
54
+ params: OpParams;
55
+ }>;
56
+ }
57
+ declare function createTransactionBuilder(chainClient: ChainClientRef): TransactionBuilder & Record<string, unknown>;
23
58
  export { createTransactionBuilder, TransactionTooLargeError, MAX_TX_SIZE, MAX_OPS_PER_TX };
24
59
  //# sourceMappingURL=builder.d.ts.map
@@ -209,10 +209,11 @@ function createTransactionBuilder(chainClient) {
209
209
  }
210
210
  if (type === 'limit_order_update') {
211
211
  if (result.new_price) {
212
+ const np = result.new_price;
212
213
  result.new_price = {
213
- ...result.new_price,
214
- base: { ...result.new_price.base },
215
- quote: { ...result.new_price.quote },
214
+ ...np,
215
+ base: { ...np.base },
216
+ quote: { ...np.quote },
216
217
  };
217
218
  }
218
219
  }
@@ -4,15 +4,15 @@
4
4
  * setRequiredFees writes back onto the ops) to avoid stale fees when the
5
5
  * same op type has different parameters (e.g. different amounts or extensions).
6
6
  */
7
- declare function buildFeeCacheKey(opList: Array<[number, any]>, feeAssetId: string): string;
8
- declare function getFees(cacheKey: string): any[] | undefined;
9
- declare function setFees(cacheKey: string, fees: any[]): void;
7
+ declare function buildFeeCacheKey(opList: Array<[number, unknown]>, feeAssetId: string): string;
8
+ declare function getFees(cacheKey: string): unknown[] | undefined;
9
+ declare function setFees(cacheKey: string, fees: unknown[]): void;
10
10
  /**
11
11
  * Peek at cached fees without expiry-based deletion.
12
12
  * Returns the fee array even if stale (expired), or undefined if absent.
13
13
  * Useful as a fallback when a chain re-fetch fails.
14
14
  */
15
- declare function peekFees(cacheKey: string): any[] | undefined;
15
+ declare function peekFees(cacheKey: string): unknown[] | undefined;
16
16
  declare function invalidateFees(): void;
17
17
  export { buildFeeCacheKey, getFees, setFees, peekFees, invalidateFees };
18
18
  //# sourceMappingURL=tx_cache.d.ts.map
@@ -34,13 +34,16 @@
34
34
  * 16. _internal - @internal Internal state (connected flag) — test-only, do not rely on in production
35
35
  * ===============================================================================
36
36
  */
37
+ import NodeManager from './node_manager.js';
37
38
  import { withTimeout } from './order/utils/timeout.js';
39
+ import { createSigningClient } from './bitshares-native/index.js';
40
+ type NativeSigningClient = ReturnType<typeof createSigningClient>['client'];
38
41
  /**
39
42
  * Register a callback to be called after a successful reconnection.
40
43
  * @param {Function} callback - Called with no arguments after subscription re-establishment
41
44
  * @returns {Function} Unregister function
42
45
  */
43
- declare function onReconnect(callback: any): () => void;
46
+ declare function onReconnect(callback: unknown): () => void;
44
47
  /**
45
48
  * Whether a transport-reported node failure should count as a persistent strike
46
49
  * in the NodeManager ledger.
@@ -61,13 +64,30 @@ declare function onReconnect(callback: any): () => void;
61
64
  * rather than mere attempts.
62
65
  */
63
66
  export declare function shouldCountNodeStrike(source?: string): boolean;
64
- declare const _lazyBitShares: any;
67
+ interface LazyBitShares {
68
+ db: Record<string, (...args: unknown[]) => Promise<unknown>>;
69
+ history: Record<string, (...args: unknown[]) => Promise<unknown>>;
70
+ assets: Record<string, unknown>;
71
+ accounts: Record<string, unknown>;
72
+ chain: {
73
+ coreAsset: unknown;
74
+ };
75
+ connect(...args: unknown[]): unknown;
76
+ disconnect(...args: unknown[]): unknown;
77
+ subscribe(...args: unknown[]): Promise<unknown>;
78
+ unsubscribe(...args: unknown[]): Promise<unknown>;
79
+ node: unknown;
80
+ autoreconnect: boolean;
81
+ connectPromise: unknown;
82
+ [key: string]: unknown;
83
+ }
84
+ declare const _lazyBitShares: LazyBitShares;
65
85
  /**
66
86
  * Suppress or restore connection log output.
67
87
  * @param {boolean} suppress - Whether to suppress connection logs
68
88
  * @returns {void}
69
89
  */
70
- declare function setSuppressConnectionLog(suppress: any): void;
90
+ declare function setSuppressConnectionLog(suppress: boolean): void;
71
91
  /** Whether connection log output is currently suppressed. */
72
92
  declare function isSuppressConnectionLog(): boolean;
73
93
  /**
@@ -76,7 +96,7 @@ declare function isSuppressConnectionLog(): boolean;
76
96
  * @returns {Promise<boolean>} True if failover reconnect succeeded
77
97
  * @private
78
98
  */
79
- declare function assessFailover(reason?: any): Promise<any>;
99
+ declare function assessFailover(reason?: string): Promise<boolean>;
80
100
  /**
81
101
  * Wait for the BitShares connection to become ready.
82
102
  * @param {number} [timeoutMs=TIMING.CONNECTION_TIMEOUT_MS] - Max time to wait in ms
@@ -87,7 +107,7 @@ declare function assessFailover(reason?: any): Promise<any>;
87
107
  * @returns {Promise<boolean>} True when connected
88
108
  * @throws {Error} If connection times out
89
109
  */
90
- declare function waitForConnected(timeoutMs?: any, options?: {
110
+ declare function waitForConnected(timeoutMs?: number, options?: {
91
111
  retryDelayMs?: number;
92
112
  maxRetryDelayMs?: number;
93
113
  refreshNodesEveryMs?: number;
@@ -98,12 +118,12 @@ declare function waitForConnected(timeoutMs?: any, options?: {
98
118
  * @param {string|Object} privateKey - Private key or daemon signing token
99
119
  * @returns {Promise<Object>} Account client with initPromise, newTx(), broadcast()
100
120
  */
101
- declare function createAccountClient(accountName: any, privateKey: any): Promise<any>;
121
+ declare function createAccountClient(accountName: unknown, privateKey: unknown): Promise<NativeSigningClient>;
102
122
  /**
103
123
  * Get the current connection status.
104
124
  * @returns {string} Status string from native client
105
125
  */
106
- declare function getConnectionStatus(): any;
126
+ declare function getConnectionStatus(): string;
107
127
  /**
108
128
  * Disconnect the BitShares client.
109
129
  * @returns {Promise<void>}
@@ -114,17 +134,29 @@ declare function disconnectClient(): Promise<void>;
114
134
  * @param {string} [reason='adapter-cycle'] - Reason for reconnection
115
135
  * @returns {Promise<boolean>} True if reconnection succeeded
116
136
  */
117
- declare function reconnectForCycle(reason?: any): Promise<boolean>;
118
- declare function getNodeManager(): any;
119
- declare function getNodeStats(): any;
120
- declare function getNodeSummary(): any;
121
- declare function getConnectionError(): any;
137
+ declare function reconnectForCycle(reason?: string): Promise<boolean>;
138
+ declare function getNodeManager(): NodeManager | null;
139
+ declare function getNodeStats(): {
140
+ url: string;
141
+ status: string;
142
+ latencyMs: number | null;
143
+ failureCount: number;
144
+ lastCheckTime: string | null;
145
+ lastErrorMessage: string | null;
146
+ }[] | undefined;
147
+ declare function getNodeSummary(): {
148
+ monitoring: boolean;
149
+ counts: Record<string, number>;
150
+ bestNode: string | null;
151
+ avgLatency: number | null;
152
+ } | undefined;
153
+ declare function getConnectionError(): unknown;
122
154
  /** @internal Exposed for unit tests only — do not rely on in production code. */
123
155
  declare const _internal: {
124
156
  readonly connected: boolean;
125
157
  };
126
158
  declare const _default: {
127
- BitShares: any;
159
+ BitShares: LazyBitShares;
128
160
  createAccountClient: typeof createAccountClient;
129
161
  waitForConnected: typeof waitForConnected;
130
162
  getConnectionStatus: typeof getConnectionStatus;
@@ -70,8 +70,9 @@ function onReconnect(callback) {
70
70
  logger.warn(`onReconnect requires a function, got ${typeof callback}`);
71
71
  return () => { };
72
72
  }
73
- _reconnectCallbacks.add(callback);
74
- return () => { _reconnectCallbacks.delete(callback); };
73
+ const reconnectFn = callback;
74
+ _reconnectCallbacks.add(reconnectFn);
75
+ return () => { _reconnectCallbacks.delete(reconnectFn); };
75
76
  }
76
77
  async function notifyReconnectCallbacks() {
77
78
  if (_reconnectCallbacks.size === 0)
@@ -81,17 +82,17 @@ async function notifyReconnectCallbacks() {
81
82
  await Promise.resolve(cb());
82
83
  }
83
84
  catch (err) {
84
- logger.warn(`Reconnect callback error: ${err?.message || err}`);
85
+ logger.warn(`Reconnect callback error: ${getErrorMessage(err)}`);
85
86
  }
86
87
  }
87
88
  }
88
89
  // Lazy initialization guard
89
90
  let _initialized = false;
90
91
  // Native client references (lazily initialized)
91
- let _nativeClient = null;
92
- let _subscriptionManager = null;
93
- let _nativeBitSharesProxy = null;
94
- let _resolvers = null;
92
+ let _nativeClient;
93
+ let _subscriptionManager;
94
+ let _nativeBitSharesProxy;
95
+ let _resolvers;
95
96
  // Monotonic generation counter for native _nativeClient.connect() calls.
96
97
  // The native transport's connect() sweep cannot be cancelled, so a timeout
97
98
  // in the outer withTimeout wrapper only stops the *awaiter* — the sweep
@@ -230,22 +231,26 @@ function ensureInitialized() {
230
231
  // (15s) on every call(). An additional wrapper here would only add
231
232
  // dead slack past the native rejection and produce misleading
232
233
  // error messages. Pass through directly.
233
- return new Proxy(_nativeClient.db, {
234
+ const source = _nativeClient.db;
235
+ return new Proxy(source, {
234
236
  get(target, prop) {
235
- if (typeof target[prop] === 'function') {
236
- return (...args) => target[prop](...args);
237
+ const key = String(prop);
238
+ if (typeof target[key] === 'function') {
239
+ return (...args) => target[key](...args);
237
240
  }
238
- return (...args) => target.call(prop, args);
241
+ return (...args) => target.call(key, args);
239
242
  },
240
243
  });
241
244
  },
242
245
  get history() {
243
- return new Proxy(_nativeClient.history, {
246
+ const source = _nativeClient.history;
247
+ return new Proxy(source, {
244
248
  get(target, prop) {
245
- if (typeof target[prop] === 'function') {
246
- return (...args) => target[prop](...args);
249
+ const key = String(prop);
250
+ if (typeof target[key] === 'function') {
251
+ return (...args) => target[key](...args);
247
252
  }
248
- return (...args) => target.call(prop, args);
253
+ return (...args) => target.call(key, args);
249
254
  },
250
255
  });
251
256
  },
@@ -258,7 +263,7 @@ function ensureInitialized() {
258
263
  });
259
264
  const nodeSettings = settings?.NODES;
260
265
  const configuredNodes = Array.isArray(nodeSettings?.list)
261
- ? nodeSettings.list.filter((node) => typeof node === 'string' && node.trim())
266
+ ? nodeSettings.list.filter((node) => typeof node === 'string' && Boolean(node.trim()))
262
267
  : [];
263
268
  nodeManagerEnabled = nodeSettings?.enabled ?? NODE_MANAGEMENT.DEFAULT_ENABLED;
264
269
  const effectiveNodes = configuredNodes.length > 0 ? configuredNodes : NODE_MANAGEMENT.DEFAULT_NODES;
@@ -284,10 +289,14 @@ function ensureInitialized() {
284
289
  const _lazyBitShares = new Proxy({}, {
285
290
  get(_target, prop) {
286
291
  ensureInitialized();
292
+ if (typeof prop !== 'string')
293
+ return undefined;
287
294
  return _nativeBitSharesProxy[prop];
288
295
  },
289
296
  set(_target, prop, value) {
290
297
  ensureInitialized();
298
+ if (typeof prop !== 'string')
299
+ return false;
291
300
  _nativeBitSharesProxy[prop] = value;
292
301
  return true;
293
302
  },
@@ -364,7 +373,7 @@ async function restartBitsharesConnection(serverList, reason = 'startup') {
364
373
  await _subscriptionManager.onReconnect();
365
374
  }
366
375
  catch (err) {
367
- logger.warn(`Subscription re-establishment after reconnect failed: ${err?.message || err}`);
376
+ logger.warn(`Subscription re-establishment after reconnect failed: ${getErrorMessage(err)}`);
368
377
  }
369
378
  }
370
379
  // Notify registered reconnection callbacks (e.g. DEXBot safety-net sync)
@@ -613,7 +622,7 @@ async function waitForConnected(timeoutMs = TIMING.CONNECTION_TIMEOUT_MS, option
613
622
  retryDelayMs = Math.min(maxDelayMs, retryDelayMs > 0 ? retryDelayMs * 2 : maxDelayMs);
614
623
  }
615
624
  if (!connected) {
616
- const suffix = lastConnectionError?.message ? ` Last error: ${lastConnectionError.message}` : '';
625
+ const suffix = lastConnectionError?.message ? ` Last error: ${getErrorMessage(lastConnectionError)}` : '';
617
626
  throw new Error(`Timed out waiting for BitShares connection after ${timeoutMs}ms.${suffix}`);
618
627
  }
619
628
  return true;
@@ -627,7 +636,7 @@ async function waitForConnected(timeoutMs = TIMING.CONNECTION_TIMEOUT_MS, option
627
636
  async function createAccountClient(accountName, privateKey) {
628
637
  ensureInitialized();
629
638
  await waitForConnected(TIMING.CONNECTION_TIMEOUT_MS);
630
- const signingClient = createSigningClient(_nativeClient, accountName, privateKey);
639
+ const signingClient = createSigningClient(_nativeClient, String(accountName), privateKey);
631
640
  return signingClient.client;
632
641
  }
633
642
  /**
@@ -18,9 +18,10 @@
18
18
  * Mode rules are pinned by tests/test_bot_defaults_characterization.ts and
19
19
  * tests/test_bot_defaults_parity.ts — update them together with this file.
20
20
  */
21
- export interface SeedOptions {
21
+ import type { UnknownRecord } from './types.js';
22
+ interface SeedOptions {
22
23
  /** Defaults source; omit to use the merged DEFAULT_CONFIG. */
23
- defaults?: Record<string, any>;
24
+ defaults?: UnknownRecord;
24
25
  }
25
26
  /**
26
27
  * DEFAULT_CONFIG keys the draft seed must NEVER add. Seeding these would change
@@ -36,16 +37,6 @@ export declare const DRAFT_EXCLUDED_KEYS: string[];
36
37
  * fails when a new DEFAULT_CONFIG key is added without classifying it here.
37
38
  */
38
39
  export declare const DRAFT_SEED_ORDER: string[];
39
- /** Fields with no meaning since the grid-price offset was removed; stripped from drafts. */
40
- export declare const LEGACY_DRAFT_KEYS: string[];
41
- /**
42
- * Spellings that mean "no explicit grid price" — delegate to startPrice.
43
- * `none`/`null`/`start`/`startprice` are the editor's documented aliases;
44
- * `n`/`no`/`false`/`0`/`f` are the boolean-style deactivating answers accepted
45
- * elsewhere in the editor, `s` is shorthand for `startPrice`, and the boolean
46
- * `false` covers a hand-edited `gridPrice: false`.
47
- */
48
- export declare const GRID_PRICE_UNSET_INPUTS: Set<string>;
49
40
  /**
50
41
  * True when a grid-price value carries no reference and must degrade to the
51
42
  * startPrice fallback. Keeps `null`/`undefined`/`false`, empty/whitespace
@@ -55,7 +46,7 @@ export declare const GRID_PRICE_UNSET_INPUTS: Set<string>;
55
46
  * @param {*} value - Candidate grid-price value.
56
47
  * @returns {boolean}
57
48
  */
58
- export declare function isUnsetGridPrice(value: any): boolean;
49
+ export declare function isUnsetGridPrice(value: unknown): boolean;
59
50
  /**
60
51
  * Editor draft seed (formerly the `normalizeBotDraft` if-chain in
61
52
  * modules/account_bots.ts). Deep-clones the input, then applies defaults:
@@ -70,7 +61,7 @@ export declare function isUnsetGridPrice(value: any): boolean;
70
61
  * was a hardcoded null that ignored DEFAULT_CONFIG.gridPrice overrides);
71
62
  * * other scalars: filled only when `=== undefined` — explicit nulls survive.
72
63
  */
73
- export declare function seedBotDraft(base?: Record<string, any> | null, options?: SeedOptions): Record<string, any>;
64
+ export declare function seedBotDraft(base?: UnknownRecord | null, options?: SeedOptions): UnknownRecord;
74
65
  /**
75
66
  * Runtime entry default (formerly duplicated in `modules/bot_settings.ts` and
76
67
  * `claw/modules/dexbot_profiles.ts`). Only `active` is defaulted:
@@ -85,7 +76,7 @@ export declare function seedBotDraft(base?: Record<string, any> | null, options?
85
76
  * missing keys as mistakes (assetA/assetB must be genuinely absent when
86
77
  * unconfigured).
87
78
  */
88
- export declare function seedBotEntry<T extends Record<string, any>>(entry: T, options?: SeedOptions): T;
79
+ export declare function seedBotEntry<T extends UnknownRecord>(entry: T, options?: SeedOptions): T;
89
80
  /**
90
81
  * Runtime config seed (formerly `{ ...DEFAULT_CONFIG, ...config }` in the
91
82
  * OrderManager constructor). Produces exactly the spread result — same key
@@ -94,5 +85,6 @@ export declare function seedBotEntry<T extends Record<string, any>>(entry: T, op
94
85
  * `manager.config.botFunds` can no longer corrupt the global DEFAULT_CONFIG
95
86
  * (the historical shallow spread aliased every nested default object).
96
87
  */
97
- export declare function seedBotRuntimeConfig(config?: Record<string, any>, options?: SeedOptions): Record<string, any>;
88
+ export declare function seedBotRuntimeConfig(config?: UnknownRecord, options?: SeedOptions): UnknownRecord;
89
+ export {};
98
90
  //# sourceMappingURL=bot_defaults.d.ts.map