dexbot 1.6.10 → 1.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/CHANGELOG.md +50 -3
  2. package/README.md +3 -1
  3. package/analysis/README.md +51 -11
  4. package/analysis/bot_fitting/README.md +12 -0
  5. package/analysis/tradingview/README.md +3 -3
  6. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
  7. package/analysis/trend_detection/README.md +31 -0
  8. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  9. package/claw/modules/chain_broadcast.ts +7 -1
  10. package/claw/modules/claw_launcher.ts +1 -1
  11. package/claw/modules/launcher_mode_detector.ts +9 -2
  12. package/claw/package.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  14. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  15. package/dist/analysis/account_resolver.d.ts +1 -1
  16. package/dist/analysis/account_resolver.js +15 -2
  17. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  18. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
  19. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  20. package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
  21. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
  22. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
  23. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
  24. package/dist/analysis/analyze_args.d.ts +31 -0
  25. package/dist/analysis/analyze_args.js +41 -0
  26. package/dist/analysis/analyze_dynamic_weight.js +7 -20
  27. package/dist/analysis/analyze_kalman.js +7 -17
  28. package/dist/analysis/analyze_regime.js +7 -17
  29. package/dist/analysis/analyze_regime_windows.js +8 -18
  30. package/dist/analysis/analyze_risk_profile.js +8 -18
  31. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  32. package/dist/analysis/analyze_volatility.js +7 -17
  33. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
  34. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
  35. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  36. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
  37. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
  38. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
  39. package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
  40. package/dist/analysis/bot_fitting/shared_utils.js +2 -2
  41. package/dist/analysis/bot_key_utils.d.ts +18 -10
  42. package/dist/analysis/bot_key_utils.js +10 -17
  43. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  44. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  45. package/dist/analysis/chain_pool.d.ts +3 -1
  46. package/dist/analysis/chart_ui.d.ts +5 -2
  47. package/dist/analysis/chart_ui.js +6 -3
  48. package/dist/analysis/chart_utils.d.ts +5 -5
  49. package/dist/analysis/chart_utils.js +9 -0
  50. package/dist/analysis/fills_cache.d.ts +64 -0
  51. package/dist/analysis/fills_cache.js +254 -0
  52. package/dist/analysis/fills_source.d.ts +2 -2
  53. package/dist/analysis/fills_source.js +19 -14
  54. package/dist/analysis/grid_correction_check.d.ts +1 -1
  55. package/dist/analysis/grid_correction_check.js +12 -11
  56. package/dist/analysis/math_utils.d.ts +7 -6
  57. package/dist/analysis/math_utils.js +5 -8
  58. package/dist/analysis/pnl_report.d.ts +39 -0
  59. package/dist/analysis/pnl_report.js +325 -0
  60. package/dist/analysis/price_sources.d.ts +8 -8
  61. package/dist/analysis/price_sources.js +5 -4
  62. package/dist/analysis/resolve_bot_accounts.js +2 -2
  63. package/dist/analysis/resolve_source.d.ts +1 -2
  64. package/dist/analysis/trade_profitability.d.ts +32 -2
  65. package/dist/analysis/trade_profitability.js +232 -106
  66. package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
  67. package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
  68. package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
  69. package/dist/analysis/tradingview/grid_reset_config.js +35 -6
  70. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
  71. package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
  72. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  73. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
  74. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
  75. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
  76. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  77. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
  78. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
  79. package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
  80. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  81. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  82. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  83. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  84. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  85. package/dist/credential-daemon.js +34 -20
  86. package/dist/dexbot.js +17 -14
  87. package/dist/market_adapter/candle_utils.d.ts +22 -18
  88. package/dist/market_adapter/candle_utils.js +24 -20
  89. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  90. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  91. package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
  92. package/dist/market_adapter/core/kibana_candles.js +9 -7
  93. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  94. package/dist/market_adapter/core/kibana_client.js +8 -7
  95. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  96. package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
  97. package/dist/market_adapter/core/market_adapter_service.js +184 -101
  98. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  99. package/dist/market_adapter/core/strategies/ama.js +7 -32
  100. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  101. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  102. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  103. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  104. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  105. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  106. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
  107. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
  108. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  109. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  110. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  111. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  112. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  113. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  114. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  115. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  116. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  117. package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
  118. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
  119. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
  120. package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
  121. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  122. package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
  123. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  124. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  125. package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
  126. package/dist/market_adapter/inputs/window_cache.js +8 -8
  127. package/dist/market_adapter/interval_utils.d.ts +4 -4
  128. package/dist/market_adapter/log_format.d.ts +6 -6
  129. package/dist/market_adapter/log_format.js +28 -22
  130. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  131. package/dist/market_adapter/lp_chart_core.js +26 -192
  132. package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
  133. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  134. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  135. package/dist/market_adapter/market_adapter.d.ts +94 -33
  136. package/dist/market_adapter/market_adapter.js +69 -75
  137. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  138. package/dist/market_adapter/utils/adapter_client.js +2 -2
  139. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  140. package/dist/market_adapter/utils/chain.d.ts +50 -41
  141. package/dist/market_adapter/utils/chain.js +40 -46
  142. package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
  143. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  144. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  145. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  146. package/dist/market_adapter/utils/file_lock.js +36 -32
  147. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  148. package/dist/market_adapter/utils/native_history.js +35 -28
  149. package/dist/modules/account_bots.d.ts +577 -21
  150. package/dist/modules/account_bots.js +182 -158
  151. package/dist/modules/account_orders.d.ts +66 -30
  152. package/dist/modules/account_orders.js +22 -20
  153. package/dist/modules/authority_resolver.d.ts +12 -2
  154. package/dist/modules/authority_resolver.js +15 -8
  155. package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
  156. package/dist/modules/bitshares-native/chain_client.js +45 -46
  157. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  158. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  159. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  160. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  161. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  162. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  163. package/dist/modules/bitshares-native/index.d.ts +1 -1
  164. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  165. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  166. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  167. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  168. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  169. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  170. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  171. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  172. package/dist/modules/bitshares-native/serial/types.js +55 -62
  173. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  174. package/dist/modules/bitshares-native/signing_client.js +19 -14
  175. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  176. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  177. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  178. package/dist/modules/bitshares-native/transport.js +5 -4
  179. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  180. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  181. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  182. package/dist/modules/bitshares_client.d.ts +45 -13
  183. package/dist/modules/bitshares_client.js +28 -19
  184. package/dist/modules/bot_defaults.d.ts +6 -15
  185. package/dist/modules/bot_defaults.js +1 -5
  186. package/dist/modules/bot_settings.d.ts +44 -10
  187. package/dist/modules/bot_settings.js +11 -8
  188. package/dist/modules/bots_file_lock.d.ts +6 -6
  189. package/dist/modules/bots_file_lock.js +16 -12
  190. package/dist/modules/broadcast_failure.d.ts +2 -2
  191. package/dist/modules/broadcast_failure.js +5 -4
  192. package/dist/modules/chain_keys.d.ts +42 -40
  193. package/dist/modules/chain_keys.js +53 -45
  194. package/dist/modules/chain_orders.d.ts +93 -59
  195. package/dist/modules/chain_orders.js +31 -23
  196. package/dist/modules/constants.d.ts +530 -32
  197. package/dist/modules/constants.js +52 -60
  198. package/dist/modules/cr_planner.d.ts +40 -2
  199. package/dist/modules/credential_policy.d.ts +68 -8
  200. package/dist/modules/credential_policy.js +37 -31
  201. package/dist/modules/credential_session_cache.d.ts +2 -2
  202. package/dist/modules/credit_pricing.d.ts +42 -6
  203. package/dist/modules/credit_pricing.js +44 -30
  204. package/dist/modules/credit_runtime.d.ts +276 -118
  205. package/dist/modules/credit_runtime.js +462 -165
  206. package/dist/modules/crypto/browser_provider.js +6 -4
  207. package/dist/modules/crypto/node_provider.js +1 -1
  208. package/dist/modules/crypto/pure_scrypt.js +35 -4
  209. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  210. package/dist/modules/crypto/sync.d.ts +9 -9
  211. package/dist/modules/crypto/sync.js +16 -9
  212. package/dist/modules/dexbot_class.d.ts +195 -139
  213. package/dist/modules/dexbot_class.js +78 -28
  214. package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
  215. package/dist/modules/dexbot_cow_runtime.js +248 -206
  216. package/dist/modules/dexbot_credential_client.d.ts +19 -11
  217. package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
  218. package/dist/modules/dexbot_fill_runtime.js +48 -41
  219. package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
  220. package/dist/modules/dexbot_maintenance_runtime.js +117 -80
  221. package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
  222. package/dist/modules/dexbot_startup_runtime.js +43 -43
  223. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  224. package/dist/modules/dexbot_state_recovery.js +18 -13
  225. package/dist/modules/fund_registry.d.ts +4 -2
  226. package/dist/modules/fund_registry.js +10 -10
  227. package/dist/modules/general_settings.d.ts +30 -4
  228. package/dist/modules/graceful_shutdown.d.ts +3 -3
  229. package/dist/modules/graceful_shutdown.js +2 -2
  230. package/dist/modules/grid_price_source.d.ts +1 -1
  231. package/dist/modules/key_store.d.ts +14 -8
  232. package/dist/modules/key_store.js +7 -6
  233. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  234. package/dist/modules/launcher/adapter_requirement.js +5 -5
  235. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  236. package/dist/modules/launcher/bot_supervisor.js +12 -11
  237. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  238. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  239. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  240. package/dist/modules/launcher/credential_daemon.js +2 -2
  241. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  242. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  243. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  244. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  245. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  246. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  247. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  248. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  249. package/dist/modules/launcher/supervisor_control.js +4 -2
  250. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  251. package/dist/modules/market_adapter_whitelist.js +15 -3
  252. package/dist/modules/node_manager.d.ts +41 -11
  253. package/dist/modules/node_manager.js +5 -4
  254. package/dist/modules/order/accounting.d.ts +53 -24
  255. package/dist/modules/order/accounting.js +40 -14
  256. package/dist/modules/order/async_lock.d.ts +5 -2
  257. package/dist/modules/order/async_lock.js +1 -1
  258. package/dist/modules/order/export.d.ts +7 -6
  259. package/dist/modules/order/export.js +1 -7
  260. package/dist/modules/order/format.d.ts +39 -19
  261. package/dist/modules/order/format.js +62 -16
  262. package/dist/modules/order/genesis_policy.d.ts +21 -18
  263. package/dist/modules/order/genesis_policy.js +12 -8
  264. package/dist/modules/order/grid.d.ts +142 -36
  265. package/dist/modules/order/grid.js +148 -123
  266. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  267. package/dist/modules/order/grid_reconcile.js +13 -12
  268. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  269. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  270. package/dist/modules/order/index.d.ts +263 -1
  271. package/dist/modules/order/logger.d.ts +45 -11
  272. package/dist/modules/order/logger.js +38 -40
  273. package/dist/modules/order/logger_state.d.ts +4 -4
  274. package/dist/modules/order/manager.d.ts +226 -180
  275. package/dist/modules/order/manager.js +101 -83
  276. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  277. package/dist/modules/order/processed_fill_store.js +16 -27
  278. package/dist/modules/order/strategy.d.ts +21 -13
  279. package/dist/modules/order/strategy.js +5 -6
  280. package/dist/modules/order/sync_engine.d.ts +91 -33
  281. package/dist/modules/order/sync_engine.js +99 -54
  282. package/dist/modules/order/utils/math.d.ts +157 -102
  283. package/dist/modules/order/utils/math.js +77 -38
  284. package/dist/modules/order/utils/order.d.ts +326 -106
  285. package/dist/modules/order/utils/order.js +200 -99
  286. package/dist/modules/order/utils/slot.d.ts +1 -1
  287. package/dist/modules/order/utils/system.d.ts +176 -26
  288. package/dist/modules/order/utils/system.js +86 -69
  289. package/dist/modules/order/utils/validate.d.ts +89 -41
  290. package/dist/modules/order/utils/validate.js +24 -22
  291. package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
  292. package/dist/modules/order/utils/withPoolRef.js +18 -12
  293. package/dist/modules/order/working_grid.d.ts +14 -13
  294. package/dist/modules/paths.d.ts +3 -4
  295. package/dist/modules/paths.js +3 -27
  296. package/dist/modules/process_discovery.d.ts +1 -1
  297. package/dist/modules/process_discovery.js +2 -1
  298. package/dist/modules/runtime.d.ts +7 -3
  299. package/dist/modules/runtime.js +4 -3
  300. package/dist/modules/runtime_settings.d.ts +15 -10
  301. package/dist/modules/runtime_settings.js +30 -24
  302. package/dist/modules/settings_merge.d.ts +29 -3
  303. package/dist/modules/settings_merge.js +56 -78
  304. package/dist/modules/socket_json_client.d.ts +7 -4
  305. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  306. package/dist/modules/storage/browser_adapter.js +7 -30
  307. package/dist/modules/storage/index.d.ts +1 -1
  308. package/dist/modules/storage/node_adapter.d.ts +45 -27
  309. package/dist/modules/storage/node_adapter.js +9 -9
  310. package/dist/modules/storage/types.d.ts +5 -4
  311. package/dist/modules/types.d.ts +1071 -2
  312. package/dist/modules/types.js +4 -1
  313. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  314. package/dist/modules/utils/asset_symbols.js +2 -1
  315. package/dist/modules/utils/errors.d.ts +9 -0
  316. package/dist/modules/utils/errors.js +23 -1
  317. package/dist/modules/utils/time_range.d.ts +4 -0
  318. package/dist/modules/utils/time_range.js +18 -0
  319. package/dist/modules/validate_profiles.js +53 -43
  320. package/dist/modules/version_notice.d.ts +14 -3
  321. package/dist/modules/version_notice.js +6 -4
  322. package/dist/pm2.d.ts +29 -27
  323. package/dist/pm2.js +5 -5
  324. package/dist/scripts/analyze-credit.d.ts +2 -1
  325. package/dist/scripts/analyze-credit.js +23 -24
  326. package/dist/scripts/analyze-orders.d.ts +77 -9
  327. package/dist/scripts/analyze-orders.js +66 -84
  328. package/dist/scripts/chart_command.d.ts +27 -18
  329. package/dist/scripts/chart_command.js +16 -15
  330. package/dist/scripts/check_any.d.ts +18 -0
  331. package/dist/scripts/check_any.js +126 -0
  332. package/dist/scripts/diagnose-pool-history.js +12 -7
  333. package/dist/scripts/pnl.d.ts +3 -0
  334. package/dist/scripts/pnl.js +40 -0
  335. package/dist/scripts/print_grid.js +0 -1
  336. package/dist/scripts/run-tests.js +39 -7
  337. package/dist/scripts/runner.js +1 -1
  338. package/dist/scripts/test-credit-renewal.js +30 -21
  339. package/dist/scripts/update.d.ts +10 -5
  340. package/dist/scripts/update.js +168 -103
  341. package/dist/scripts/update_dist_freshness.js +1 -0
  342. package/dist/scripts/update_layout.d.ts +61 -0
  343. package/dist/scripts/update_layout.js +180 -0
  344. package/dist/scripts/validate_bots.js +2 -1
  345. package/dist/scripts/verify-browser-bundle.js +8 -0
  346. package/dist/unlock.d.ts +28 -3
  347. package/dist/unlock.js +72 -10
  348. package/docs/BITSHARES_ONBOARDING.md +2 -0
  349. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  350. package/docs/COW_INVARIANTS.md +13 -6
  351. package/docs/DEXBOT_COMPARISON.md +8 -8
  352. package/docs/EVOLUTION.md +12 -10
  353. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  354. package/docs/GRID_RECALCULATION.md +15 -16
  355. package/docs/GRID_RECONCILE.md +14 -3
  356. package/docs/LIFECYCLE.md +11 -11
  357. package/docs/MPA_CREDIT_USAGE.md +22 -3
  358. package/docs/README.md +15 -4
  359. package/docs/WORKFLOW.md +1 -0
  360. package/docs/architecture.md +12 -9
  361. package/docs/developer_guide.md +6 -6
  362. package/market_adapter/README.md +9 -26
  363. package/modules/README.md +4 -1
  364. package/package.json +4 -1
  365. package/scripts/README.md +14 -0
@@ -94,16 +94,14 @@ function hasLending(bot) {
94
94
  // shared with the live credit runtime) — no local copies here.
95
95
  import { averageCollateralRatio as averageCreditCr, creditDealCollateralRatio as creditDealCr, dailyOfferFeeRate, extractOfferConversionRate, normalizeCollateralMap as normalizeOfferCollateralMap, } from '../modules/credit_pricing.js';
96
96
  function lendingAssetsOfType(bot, type) {
97
- if (!hasLending(bot))
98
- return [];
99
- return bot.debtPolicy.lending
97
+ const items = bot.debtPolicy?.lending ?? [];
98
+ return items
100
99
  .filter((item) => item && item.type === type && typeof item.asset === 'string' && item.asset.length > 0)
101
100
  .map((item) => String(item.asset));
102
101
  }
103
102
  function allLendingAssets(bot) {
104
- if (!hasLending(bot))
105
- return [];
106
- return bot.debtPolicy.lending
103
+ const items = bot.debtPolicy?.lending ?? [];
104
+ return items
107
105
  .filter((item) => item && typeof item.asset === 'string' && item.asset.length > 0)
108
106
  .map((item) => String(item.asset));
109
107
  }
@@ -271,8 +269,9 @@ async function main() {
271
269
  const res = await dbCall('get_objects', [batch]);
272
270
  if (Array.isArray(res)) {
273
271
  for (const o of res) {
274
- if (o?.id)
275
- out.set(String(o.id), o);
272
+ const offer = o;
273
+ if (offer?.id)
274
+ out.set(String(offer.id), offer);
276
275
  }
277
276
  }
278
277
  }
@@ -301,9 +300,10 @@ async function main() {
301
300
  if (!Array.isArray(rows) || rows.length === 0)
302
301
  break;
303
302
  for (const o of rows) {
304
- if (o?.id && !seen.has(String(o.id))) {
305
- seen.add(String(o.id));
306
- out.push(o);
303
+ const offer = o;
304
+ if (offer?.id && !seen.has(String(offer.id))) {
305
+ seen.add(String(offer.id));
306
+ out.push(offer);
307
307
  }
308
308
  }
309
309
  if (rows.length < 100)
@@ -324,7 +324,7 @@ async function main() {
324
324
  const out = new Map();
325
325
  try {
326
326
  const res = await dbCall('get_full_accounts', [[account], false]);
327
- const entry = Array.isArray(res) && Array.isArray(res[0]) && res[0].length >= 2 ? res[0][1] : res?.[0];
327
+ const entry = (Array.isArray(res) && Array.isArray(res[0]) && res[0].length >= 2 ? res[0][1] : res?.[0]);
328
328
  const balances = entry?.balances || [];
329
329
  for (const b of balances) {
330
330
  const aid = String(b?.asset_type || b?.asset_id || b?.asset || '');
@@ -437,11 +437,12 @@ async function main() {
437
437
  const debt = new Map();
438
438
  const coll = new Map();
439
439
  for (const it of items) {
440
+ const item = it;
440
441
  if (kind === 'mpa') {
441
- const dId = mpaDebtAssetId(it);
442
- const cId = mpaCollateralAssetId(it);
443
- const dRaw = mpaDebtRaw(it);
444
- const cRaw = mpaCollateralRaw(it);
442
+ const dId = mpaDebtAssetId(item);
443
+ const cId = mpaCollateralAssetId(item);
444
+ const dRaw = mpaDebtRaw(item);
445
+ const cRaw = mpaCollateralRaw(item);
445
446
  if (dId) {
446
447
  const f = await toFloat(dRaw, dId);
447
448
  if (f != null) {
@@ -464,10 +465,10 @@ async function main() {
464
465
  }
465
466
  }
466
467
  else {
467
- const dId = typeof it?.debt_asset === 'string' ? it.debt_asset : null;
468
- const cId = typeof it?.collateral_asset === 'string' ? it.collateral_asset : null;
469
- const dRaw = Number(it?.debt_amount);
470
- const cRaw = Number(it?.collateral_amount);
468
+ const dId = typeof item.debt_asset === 'string' ? item.debt_asset : null;
469
+ const cId = typeof item.collateral_asset === 'string' ? item.collateral_asset : null;
470
+ const dRaw = Number(item.debt_amount);
471
+ const cRaw = Number(item.collateral_amount);
471
472
  if (dId && Number.isFinite(dRaw)) {
472
473
  const f = await toFloat(dRaw, dId);
473
474
  if (f != null) {
@@ -475,7 +476,7 @@ async function main() {
475
476
  e.total += f;
476
477
  e.count += 1;
477
478
  e.max = Math.max(e.max, f);
478
- const ms = parseExpiryMs(it?.latest_repay_time ?? it?.latestRepayTime);
479
+ const ms = parseExpiryMs(item.latest_repay_time ?? item.latestRepayTime);
479
480
  if (ms !== null && (e.earliest == null || ms < e.earliest))
480
481
  e.earliest = ms;
481
482
  debt.set(dId, e);
@@ -510,9 +511,7 @@ async function main() {
510
511
  // (type creditOffer) AND the pair is listed on the current credit
511
512
  // offer (acceptable_collateral). Anything else is reported separately
512
513
  // as ignored/unpriced and excluded from the average CR.
513
- const lendingItems = hasLending(bot) && Array.isArray(bot.debtPolicy?.lending)
514
- ? bot.debtPolicy.lending
515
- : [];
514
+ const lendingItems = bot.debtPolicy?.lending ?? [];
516
515
  // Configured credit pairs drive the whitelist, per-pair CR lines, and
517
516
  // the borrow-now preview.
518
517
  const creditPairs = [];
@@ -14,6 +14,74 @@
14
14
  * node dist/scripts/analyze-orders.js --export # standalone HTML report
15
15
  */
16
16
  import { CLI_COLORS as colors } from '../modules/cli_colors.js';
17
+ /** Loose JSON-object view used across the analyzer. */
18
+ type JsonObj = Record<string, unknown>;
19
+ interface GridSlot {
20
+ type?: string;
21
+ state?: string;
22
+ price: number;
23
+ size: number;
24
+ orderId?: string | null;
25
+ [key: string]: unknown;
26
+ }
27
+ interface GridSnapshot {
28
+ meta?: JsonObj;
29
+ grid?: GridSlot[];
30
+ assets?: {
31
+ assetA?: {
32
+ symbol?: unknown;
33
+ };
34
+ assetB?: {
35
+ symbol?: unknown;
36
+ };
37
+ };
38
+ boundaryIdx?: number | null;
39
+ [key: string]: unknown;
40
+ }
41
+ interface WeightSnapshot {
42
+ effectiveWeights?: JsonObj;
43
+ baseWeights?: JsonObj;
44
+ rawAsymmetryFactor?: unknown;
45
+ appliedAsymmetryFactor?: unknown;
46
+ maxAsymmetryFactor?: unknown;
47
+ isReady?: unknown;
48
+ trend?: unknown;
49
+ finalOffset?: unknown;
50
+ [key: string]: unknown;
51
+ }
52
+ interface DynamicGridSnapshot extends GridSnapshot {
53
+ dynamicWeights?: WeightSnapshot;
54
+ asymmetricBounds?: JsonObj;
55
+ amaCenterPrice?: unknown;
56
+ gridCenterPrice?: unknown;
57
+ updatedAt?: unknown;
58
+ }
59
+ interface BotConfig {
60
+ name?: unknown;
61
+ minPrice?: unknown;
62
+ maxPrice?: unknown;
63
+ targetSpreadPercent?: unknown;
64
+ incrementPercent?: unknown;
65
+ gridPrice?: unknown;
66
+ activeOrders?: unknown;
67
+ botFunds?: JsonObj;
68
+ weightDistribution?: JsonObj;
69
+ [key: string]: unknown;
70
+ }
71
+ interface DynamicWeightInfo {
72
+ amaCenterPrice?: unknown;
73
+ rawAsymmetryFactor?: unknown;
74
+ appliedAsymmetryFactor?: unknown;
75
+ trend?: unknown;
76
+ isRecent?: unknown;
77
+ minPrice?: unknown;
78
+ maxPrice?: unknown;
79
+ effectiveWeights?: JsonObj;
80
+ baseWeights?: JsonObj;
81
+ live?: JsonObj | null;
82
+ base?: JsonObj | null;
83
+ [key: string]: unknown;
84
+ }
17
85
  declare const DYNAMIC_GRID_SNAPSHOT_MAX_AGE_MS: number;
18
86
  declare const DYNAMIC_WEIGHT_EPSILON = 0.005;
19
87
  /**
@@ -23,9 +91,9 @@ declare const DYNAMIC_WEIGHT_EPSILON = 0.005;
23
91
  * analyzer only attempts to load a dynamic grid snapshot for AMA bots. Non-AMA
24
92
  * bots never have a meaningful dynamic grid file.
25
93
  */
26
- declare function isAmaGridPrice(config: any): boolean;
27
- declare function resolveAmaKey(config: any): string | null;
28
- declare function readDynamicGridSnapshot(botKey: string): any;
94
+ declare function isAmaGridPrice(config: unknown): boolean;
95
+ declare function resolveAmaKey(config: unknown): string | null;
96
+ declare function readDynamicGridSnapshot(botKey: string): DynamicGridSnapshot | null;
29
97
  /**
30
98
  * buildDynamicWeightInfo: Extract a display-ready market-adapter payload.
31
99
  *
@@ -34,7 +102,7 @@ declare function readDynamicGridSnapshot(botKey: string): any;
34
102
  * whitelisted and the snapshot contains effective weights. AMA center and
35
103
  * freshness status remain available for AMA-only bots.
36
104
  */
37
- declare function buildDynamicWeightInfo(botKey: string, config: any): any;
105
+ declare function buildDynamicWeightInfo(botKey: string, config: BotConfig): DynamicWeightInfo | null;
38
106
  /**
39
107
  * analyzeOrder: Comprehensive analysis of a single bot's order grid
40
108
  *
@@ -56,7 +124,7 @@ declare function buildDynamicWeightInfo(botKey: string, config: any): any;
56
124
  * @param {string} [botKey] - Bot key used to locate the dynamic grid snapshot
57
125
  * @returns {Object} Analysis result with spread, increment, funds, distribution
58
126
  */
59
- declare function analyzeOrder(botData: any, config: any, botKey: string): any;
127
+ declare function analyzeOrder(botData: GridSnapshot, config: BotConfig, botKey: string): JsonObj;
60
128
  /**
61
129
  * getRawWeightValues: Extract raw buy/sell value strings for column alignment,
62
130
  * without any color codes or formatting artifacts.
@@ -67,7 +135,7 @@ declare function analyzeOrder(botData: any, config: any, botKey: string): any;
67
135
  * @param {Object|null} dynamicWeight
68
136
  * @returns {{ buy: string, sell: string } | null}
69
137
  */
70
- declare function getRawWeightValues(weightDistribution: any, dynamicWeight: any): {
138
+ declare function getRawWeightValues(weightDistribution: JsonObj | null, dynamicWeight: DynamicWeightInfo | null): {
71
139
  buy: string;
72
140
  sell: string;
73
141
  } | null;
@@ -88,7 +156,7 @@ declare function getRawWeightValues(weightDistribution: any, dynamicWeight: any)
88
156
  * @param {number} [maxSellWidth] - Target width for sell-side values (for column alignment)
89
157
  * @returns {string|null} Formatted weight line or null if no valid data
90
158
  */
91
- declare function formatWeightLine(weightDistribution: any, dynamicWeight: any, maxBuyWidth?: number, maxSellWidth?: number): string | null;
159
+ declare function formatWeightLine(weightDistribution: JsonObj | null, dynamicWeight: DynamicWeightInfo | null, maxBuyWidth?: number, maxSellWidth?: number): string | null;
92
160
  /**
93
161
  * formatAnalysis: Format analysis results into readable console output
94
162
  *
@@ -117,7 +185,7 @@ declare function formatWeightLine(weightDistribution: any, dynamicWeight: any, m
117
185
  * @param {Object} analysis - Analysis result object from analyzeOrder()
118
186
  * @returns {string} Formatted multi-line output ready for console.log
119
187
  */
120
- declare function formatAnalysis(analysis: any): string;
188
+ declare function formatAnalysis(analysisInput: JsonObj): string;
121
189
  /**
122
190
  * main: Entry point - analyze all order files and display results
123
191
  *
@@ -148,6 +216,6 @@ declare function formatAnalysis(analysis: any): string;
148
216
  *
149
217
  * @param {Array<Object>} analyses - Array of analysis results from analyzeOrder()
150
218
  */
151
- declare function generateHtmlReport(analyses: any[]): void;
219
+ declare function generateHtmlReport(analyses: JsonObj[]): void;
152
220
  export { resolveAmaKey, isAmaGridPrice, readDynamicGridSnapshot, buildDynamicWeightInfo, formatWeightLine, getRawWeightValues, analyzeOrder, formatAnalysis, generateHtmlReport, colors, DYNAMIC_GRID_SNAPSHOT_MAX_AGE_MS, DYNAMIC_WEIGHT_EPSILON };
153
221
  //# sourceMappingURL=analyze-orders.d.ts.map
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import fs from 'node:fs';
17
17
  import path from 'node:path';
18
- import { formatCurrency } from '../modules/order/format.js';
18
+ import { formatCurrency, formatFundsValue } from '../modules/order/format.js';
19
19
  import { resolveConfiguredPriceBound } from '../modules/order/utils/order.js';
20
20
  import { ORDER_TYPES, ORDER_STATES, MARKET_ADAPTER } from '../modules/constants.js';
21
21
  import { applyAsymmetricBounds } from '../market_adapter/core/asymmetric_bounds.js';
@@ -54,7 +54,7 @@ const HEADER_WIDTH = 11 + BAR_WIDTH;
54
54
  */
55
55
  function createBotKey(bot, index) {
56
56
  if (bot && bot.name) {
57
- return sanitizeKey(bot.name);
57
+ return sanitizeKey(String(bot.name));
58
58
  }
59
59
  const identifier = bot && bot.assetA && bot.assetB
60
60
  ? `${bot.assetA}/${bot.assetB}`
@@ -64,9 +64,10 @@ function createBotKey(bot, index) {
64
64
  return `${sanitizeKey(identifier)}-${index}`;
65
65
  }
66
66
  function hasOrderGrid(data) {
67
- return Boolean(data && typeof data === 'object' && !Array.isArray(data) &&
68
- data.meta && typeof data.meta === 'object' &&
69
- Array.isArray(data.grid));
67
+ if (!data || typeof data !== 'object' || Array.isArray(data))
68
+ return false;
69
+ const d = data;
70
+ return Boolean(d.meta && typeof d.meta === 'object' && Array.isArray(d.grid));
70
71
  }
71
72
  /**
72
73
  * isAmaGridPrice: Detect bots whose grid price follows the AMA (Kaufman) stream.
@@ -82,7 +83,8 @@ function isAmaGridPrice(config) {
82
83
  function resolveAmaKey(config) {
83
84
  if (!config || typeof config !== 'object')
84
85
  return null;
85
- const gridPrice = typeof config.gridPrice === 'string' ? config.gridPrice.trim().toLowerCase() : '';
86
+ const cfg = config;
87
+ const gridPrice = typeof cfg.gridPrice === 'string' ? cfg.gridPrice.trim().toLowerCase() : '';
86
88
  if (!/^ama(?:[1-4])?$/.test(gridPrice))
87
89
  return null;
88
90
  if (gridPrice === 'ama')
@@ -158,8 +160,8 @@ function buildDynamicWeightInfo(botKey, config) {
158
160
  let live = null;
159
161
  let base = null;
160
162
  if (hasDynamicWeightData) {
161
- const effBuy = Number(dw.effectiveWeights.buy);
162
- const effSell = Number(dw.effectiveWeights.sell);
163
+ const effBuy = Number(dw.effectiveWeights?.buy);
164
+ const effSell = Number(dw.effectiveWeights?.sell);
163
165
  if (Number.isFinite(effBuy) && Number.isFinite(effSell)) {
164
166
  const baseFromSnapshot = dw.baseWeights && typeof dw.baseWeights === 'object' ? dw.baseWeights : null;
165
167
  const baseBuy = baseFromSnapshot && Number.isFinite(Number(baseFromSnapshot.buy))
@@ -223,14 +225,15 @@ function buildDynamicWeightInfo(botKey, config) {
223
225
  function isRealGridOrder(order) {
224
226
  if (!order || typeof order !== 'object')
225
227
  return false;
226
- const hasRealState = order.state === ORDER_STATES.ACTIVE || order.state === ORDER_STATES.PARTIAL;
227
- const hasRealType = order.type === ORDER_TYPES.BUY || order.type === ORDER_TYPES.SELL;
228
- const hasOrderId = typeof order.orderId === 'string' && order.orderId.trim().length > 0;
228
+ const o = order;
229
+ const hasRealState = o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL;
230
+ const hasRealType = o.type === ORDER_TYPES.BUY || o.type === ORDER_TYPES.SELL;
231
+ const hasOrderId = typeof o.orderId === 'string' && o.orderId.trim().length > 0;
229
232
  return hasRealState
230
233
  && hasRealType
231
234
  && hasOrderId
232
- && Number(order.price) > 0
233
- && Number(order.size) > 0;
235
+ && Number(o.price) > 0
236
+ && Number(o.size) > 0;
234
237
  }
235
238
  function getRealGridOrders(botData) {
236
239
  return Array.isArray(botData?.grid) ? botData.grid.filter(isRealGridOrder) : [];
@@ -253,49 +256,6 @@ function getModifiedTime(filePath) {
253
256
  function formatPercent(value) {
254
257
  return (value * 100).toFixed(2) + '%';
255
258
  }
256
- /**
257
- * formatFundsValue: Format a fund amount with compact notation (K/M for ≥1000)
258
- * and up to 4 significant figures, trimming uninformative trailing zeros.
259
- * Examples:
260
- * 194395 -> "194.4K"
261
- * 10000 -> "10K"
262
- * 1000 -> "1K"
263
- * 332.33 -> "332.3"
264
- * 10.389 -> "10.39"
265
- * 1500000 -> "1.5M"
266
- * @param {number} value
267
- * @returns {string}
268
- */
269
- function formatFundsValue(value) {
270
- if (value === 0)
271
- return '0';
272
- const absValue = Math.abs(value);
273
- let quotient;
274
- let suffix = '';
275
- if (absValue >= 1000000) {
276
- quotient = value / 1000000;
277
- suffix = 'M';
278
- }
279
- else if (absValue >= 1000) {
280
- quotient = value / 1000;
281
- suffix = 'K';
282
- }
283
- else {
284
- quotient = value;
285
- }
286
- const absQ = Math.abs(quotient);
287
- const intDigits = Math.floor(Math.log10(Math.max(absQ, 1e-10))) + 1;
288
- let formatted;
289
- if (intDigits >= 4) {
290
- formatted = String(Math.round(quotient));
291
- }
292
- else {
293
- const decimalPlaces = Math.max(0, 4 - intDigits);
294
- formatted = quotient.toFixed(decimalPlaces);
295
- formatted = formatted.replace(/(\.[0-9]*?)0+$/, '$1').replace(/\.$/, '');
296
- }
297
- return formatted + suffix;
298
- }
299
259
  /**
300
260
  * stripColorCodes: Remove ANSI color codes from a string
301
261
  * @param {string} str - String that may contain color codes
@@ -312,7 +272,7 @@ function stripColorCodes(str) {
312
272
  * @returns {string} Padded string with original colors preserved
313
273
  */
314
274
  // Load bot configurations
315
- const botsConfig = readJSON(BOTS_CONFIG).bots;
275
+ const botsConfig = readJSON(BOTS_CONFIG).bots ?? [];
316
276
  /**
317
277
  * formatBotFunds: Normalize a botFunds side value for display.
318
278
  *
@@ -409,8 +369,8 @@ function getOrderFiles() {
409
369
  * @returns {Object} Analysis result with spread, increment, funds, distribution
410
370
  */
411
371
  function analyzeOrder(botData, config, botKey) {
412
- const meta = botData.meta;
413
- const grid = botData.grid;
372
+ const meta = botData.meta || {};
373
+ const grid = Array.isArray(botData.grid) ? botData.grid : [];
414
374
  // Extract asset pair: prioritize assets object from order data, fall back to meta
415
375
  let assetA = meta.assetA;
416
376
  let assetB = meta.assetB;
@@ -426,9 +386,20 @@ function analyzeOrder(botData, config, botKey) {
426
386
  * The grid contains buy slots (prices below market), sell slots (above market),
427
387
  * and optional spread slots. Separation enables independent analysis.
428
388
  */
429
- const boundaryIdx = botData.boundaryIdx;
430
- const buySlots = grid.filter((s, i) => i <= boundaryIdx && s.type === ORDER_TYPES.BUY);
431
- const sellSlots = grid.filter((s, i) => i > boundaryIdx && s.type === ORDER_TYPES.SELL);
389
+ // A persisted boundary can be absent: GRID-LOAD erases a poisoned boundary
390
+ // (clearPersistedBoundary) and keeps running boundary-less until fills
391
+ // re-anchor. Index-based rail slicing then degenerates (null coerces to 0),
392
+ // hiding live rail orders. Detect it and classify by slot type so every live
393
+ // order stays visible in the report.
394
+ const hasBoundary = typeof botData.boundaryIdx === 'number' && Number.isFinite(botData.boundaryIdx);
395
+ const boundaryIdx = hasBoundary ? botData.boundaryIdx : 0;
396
+ const boundaryLess = !hasBoundary;
397
+ const buySlots = boundaryLess
398
+ ? grid.filter((s) => s.type === ORDER_TYPES.BUY)
399
+ : grid.filter((s, i) => i <= boundaryIdx && s.type === ORDER_TYPES.BUY);
400
+ const sellSlots = boundaryLess
401
+ ? grid.filter((s) => s.type === ORDER_TYPES.SELL)
402
+ : grid.filter((s, i) => i > boundaryIdx && s.type === ORDER_TYPES.SELL);
432
403
  const spreadSlots = grid.filter((s) => s.type === ORDER_TYPES.SPREAD);
433
404
  const activeBuySlots = buySlots.filter((s) => s.state === ORDER_STATES.ACTIVE || s.state === ORDER_STATES.PARTIAL);
434
405
  const virtualBuySlots = buySlots.filter((s) => s.state === ORDER_STATES.VIRTUAL);
@@ -453,13 +424,15 @@ function analyzeOrder(botData, config, botKey) {
453
424
  // design (a partially-placed grid IS partially masked); it is not a bug, but
454
425
  // the output should be read with that caveat in mind.
455
426
  const hasOrderId = (s) => !!(s && s.orderId);
456
- const placedBuys = grid.slice(0, boundaryIdx + 1).filter((s) => s.type === ORDER_TYPES.BUY && hasOrderId(s));
457
- const placedSells = grid.slice(boundaryIdx + 1).filter((s) => s.type === ORDER_TYPES.SELL && hasOrderId(s));
458
- const geoBuy = grid.slice(0, boundaryIdx + 1).filter((s) => s.type === ORDER_TYPES.BUY);
459
- const geoSell = grid.slice(boundaryIdx + 1).filter((s) => s.type === ORDER_TYPES.SELL);
427
+ const railBuys = boundaryLess ? grid.filter((s) => s.type === ORDER_TYPES.BUY) : grid.slice(0, boundaryIdx + 1);
428
+ const railSells = boundaryLess ? grid.filter((s) => s.type === ORDER_TYPES.SELL) : grid.slice(boundaryIdx + 1);
429
+ const placedBuys = railBuys.filter((s) => s.type === ORDER_TYPES.BUY && hasOrderId(s));
430
+ const placedSells = railSells.filter((s) => s.type === ORDER_TYPES.SELL && hasOrderId(s));
431
+ const geoBuy = railBuys.filter((s) => s.type === ORDER_TYPES.BUY);
432
+ const geoSell = railSells.filter((s) => s.type === ORDER_TYPES.SELL);
460
433
  const bestBuySlot = placedBuys.length
461
434
  ? placedBuys.reduce((a, b) => (b.price > a.price ? b : a))
462
- : (geoBuy.length ? geoBuy.reduce((a, b) => (b.price > a.price ? b : a)) : (grid[boundaryIdx] || null));
435
+ : (geoBuy.length ? geoBuy.reduce((a, b) => (b.price > a.price ? b : a)) : (boundaryLess ? null : (grid[boundaryIdx] || null)));
463
436
  const bestSellSlot = placedSells.length
464
437
  ? placedSells.reduce((a, b) => (b.price < a.price ? b : a))
465
438
  : (geoSell.length ? geoSell.reduce((a, b) => (b.price < a.price ? b : a)) : null);
@@ -480,9 +453,9 @@ function analyzeOrder(botData, config, botKey) {
480
453
  */
481
454
  if (config) {
482
455
  // Config exists - calculate variance from target
483
- targetSpread = config.targetSpreadPercent / 100;
456
+ targetSpread = Number(config.targetSpreadPercent) / 100;
484
457
  spreadDiff = realSpread - targetSpread;
485
- incrementCheck = checkGeometricIncrement(grid, config.incrementPercent / 100);
458
+ incrementCheck = checkGeometricIncrement(grid, Number(config.incrementPercent) / 100);
486
459
  }
487
460
  else {
488
461
  // No config - report actual values only
@@ -524,7 +497,7 @@ function analyzeOrder(botData, config, botKey) {
524
497
  return {
525
498
  pair: `${assetA}/${assetB}`,
526
499
  botName: config?.name || botKey,
527
- lastUpdated: new Date(meta.updatedAt || botData.lastUpdated),
500
+ lastUpdated: new Date(String(meta.updatedAt || botData.lastUpdated)),
528
501
  gridMinPrice: gridMinPrice,
529
502
  marketPrice: marketPrice,
530
503
  gridMaxPrice: gridMaxPrice,
@@ -545,6 +518,9 @@ function analyzeOrder(botData, config, botKey) {
545
518
  virtualFunds: virtualGridFunds,
546
519
  // Slot vs fund distribution analysis
547
520
  distribution: distribution,
521
+ // True when the snapshot carries no boundary (poisoned-boundary erasure):
522
+ // slot rows are classified by slot type, not rail geometry.
523
+ boundaryLess: boundaryLess,
548
524
  // Slot counts for structure overview
549
525
  slots: {
550
526
  buy: buySlots.length,
@@ -591,11 +567,11 @@ function computeGridRangeScalingDisplay(config, dynamicWeight) {
591
567
  if (!dynamicWeight || dynamicWeight.amaCenterPrice == null) {
592
568
  return null;
593
569
  }
594
- const centerPrice = dynamicWeight.amaCenterPrice;
570
+ const centerPrice = Number(dynamicWeight.amaCenterPrice);
595
571
  let minPrice, maxPrice;
596
572
  try {
597
- minPrice = resolveConfiguredPriceBound(config && config.minPrice, undefined, centerPrice, 'min');
598
- maxPrice = resolveConfiguredPriceBound(config && config.maxPrice, undefined, centerPrice, 'max');
573
+ minPrice = resolveConfiguredPriceBound((config && config.minPrice), undefined, centerPrice, 'min');
574
+ maxPrice = resolveConfiguredPriceBound((config && config.maxPrice), undefined, centerPrice, 'max');
599
575
  }
600
576
  catch (_) {
601
577
  return null;
@@ -607,7 +583,7 @@ function computeGridRangeScalingDisplay(config, dynamicWeight) {
607
583
  let resolvedMinPrice = minPrice;
608
584
  let resolvedMaxPrice = maxPrice;
609
585
  if (hasAsym) {
610
- const prices = computeAsymmetricBoundsPrices(centerPrice, minPrice, maxPrice, dynamicWeight.trend, dynamicWeight.appliedAsymmetryFactor);
586
+ const prices = computeAsymmetricBoundsPrices(centerPrice, minPrice, maxPrice, dynamicWeight.trend, Number(dynamicWeight.appliedAsymmetryFactor));
611
587
  if (prices) {
612
588
  resolvedMinPrice = prices.resolvedMinPrice;
613
589
  resolvedMaxPrice = prices.resolvedMaxPrice;
@@ -1014,13 +990,13 @@ function getRawWeightValues(weightDistribution, dynamicWeight) {
1014
990
  const useLive = !!(dynamicWeight
1015
991
  && dynamicWeight.isRecent
1016
992
  && dynamicWeight.live
1017
- && Number.isFinite(Number(dynamicWeight.live.buy))
1018
- && Number.isFinite(Number(dynamicWeight.live.sell)));
993
+ && Number.isFinite(Number(dynamicWeight.live?.buy))
994
+ && Number.isFinite(Number(dynamicWeight.live?.sell)));
1019
995
  if (!useLive) {
1020
996
  return { buy: staticBuy.toFixed(2), sell: staticSell.toFixed(2) };
1021
997
  }
1022
- const liveBuy = Number(dynamicWeight.live.buy);
1023
- const liveSell = Number(dynamicWeight.live.sell);
998
+ const liveBuy = Number(dynamicWeight.live?.buy);
999
+ const liveSell = Number(dynamicWeight.live?.sell);
1024
1000
  return {
1025
1001
  buy: liveBuy.toFixed(2),
1026
1002
  sell: liveSell.toFixed(2)
@@ -1064,15 +1040,15 @@ function formatWeightLine(weightDistribution, dynamicWeight, maxBuyWidth, maxSel
1064
1040
  const useLive = !!(dynamicWeight
1065
1041
  && dynamicWeight.isRecent
1066
1042
  && dynamicWeight.live
1067
- && Number.isFinite(Number(dynamicWeight.live.buy))
1068
- && Number.isFinite(Number(dynamicWeight.live.sell)));
1043
+ && Number.isFinite(Number(dynamicWeight.live?.buy))
1044
+ && Number.isFinite(Number(dynamicWeight.live?.sell)));
1069
1045
  if (!useLive) {
1070
1046
  const buyVal = staticBuy.toFixed(2);
1071
1047
  const sellVal = staticSell.toFixed(2);
1072
1048
  return ` Weight: ${maxBuyWidth ? buyVal.padEnd(maxBuyWidth) : buyVal} ${colors.buy}buy${colors.reset} | ${maxSellWidth ? sellVal.padEnd(maxSellWidth) : sellVal} ${colors.sell}sell${colors.reset}`;
1073
1049
  }
1074
- const liveBuy = Number(dynamicWeight.live.buy);
1075
- const liveSell = Number(dynamicWeight.live.sell);
1050
+ const liveBuy = Number(dynamicWeight.live?.buy);
1051
+ const liveSell = Number(dynamicWeight.live?.sell);
1076
1052
  // Compare the two live weights, not their deltas: the side with the larger
1077
1053
  // live weight is the one the bot is leaning on most heavily (the "losing"
1078
1054
  // side for that asset). When the two live weights are equal, no side is
@@ -1132,11 +1108,17 @@ function formatWeightLine(weightDistribution, dynamicWeight, maxBuyWidth, maxSel
1132
1108
  * @param {Object} analysis - Analysis result object from analyzeOrder()
1133
1109
  * @returns {string} Formatted multi-line output ready for console.log
1134
1110
  */
1135
- function formatAnalysis(analysis) {
1111
+ function formatAnalysis(analysisInput) {
1112
+ const analysis = analysisInput;
1136
1113
  const lines = [];
1137
1114
  // Header: Trading pair name
1138
1115
  lines.push(`\n${colors.cyan}📊 ${analysis.pair}${colors.reset} (${analysis.botName})`);
1139
1116
  lines.push(` ${colors.gray}Update: ${analysis.lastUpdated.toLocaleString()}${colors.reset}`);
1117
+ // Boundary-less snapshot: say so out loud so geometry rows are read as
1118
+ // type-based counts, not rail positions.
1119
+ if (analysis.boundaryLess) {
1120
+ lines.push(` ${colors.gray}⚠️ boundary-less mode - slot rows by slot type (no rail geometry)${colors.reset}`);
1121
+ }
1140
1122
  lines.push(``);
1141
1123
  // Warning: No config available for comparison
1142
1124
  if (!analysis.hasConfig) {
@@ -1149,7 +1131,7 @@ function formatAnalysis(analysis) {
1149
1131
  * Direction: ↑ if above target, ↓ if below target
1150
1132
  */
1151
1133
  if (analysis.hasConfig) {
1152
- lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} (${formatPercent(analysis.spread.target)}) | Incr.:${formatPercent(analysis.increment.avg).padStart(6)} (${formatPercent(analysis.increment.target)})`);
1134
+ lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} (${formatPercent(Number(analysis.spread.target))}) | Incr.:${formatPercent(analysis.increment.avg).padStart(6)} (${formatPercent(Number(analysis.increment.target))})`);
1153
1135
  }
1154
1136
  else {
1155
1137
  lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} | Incr.:${formatPercent(analysis.increment.avg).padStart(6)}`);
@@ -1,4 +1,27 @@
1
1
  #!/usr/bin/env node
2
+ interface AssetMeta {
3
+ id?: string;
4
+ precision?: number;
5
+ symbol?: string;
6
+ [key: string]: unknown;
7
+ }
8
+ interface ChainClientLike {
9
+ BitShares?: {
10
+ db?: Record<string, (...args: unknown[]) => Promise<unknown>>;
11
+ };
12
+ }
13
+ interface MpaBackingCtx {
14
+ [key: string]: unknown;
15
+ mpa: AssetMeta;
16
+ backing: AssetMeta;
17
+ isPredictionMarket: boolean;
18
+ feedPublicationTime: string | null;
19
+ }
20
+ interface FeedCtx {
21
+ [key: string]: unknown;
22
+ kind: string;
23
+ legs: MpaBackingCtx[];
24
+ }
2
25
  declare const FEED_STALE_WARN_AGE_MS: number;
3
26
  /** Chart command identity: 'tv' → TradingView exporter, 'dw' → dynamic-weight research chart. */
4
27
  type ChartCmd = 'tv' | 'dw';
@@ -13,27 +36,13 @@ interface ChartRenderer {
13
36
  /** Lines printed directly under the `Usage:` line. */
14
37
  usageBlurb: string[];
15
38
  }
16
- declare function resolveMpaBacking(mpaSymbol: string, bitsharesClient: any): Promise<{
17
- mpa: any;
18
- backing: any;
19
- isPredictionMarket: boolean;
20
- feedPublicationTime: string | null;
21
- } | null>;
22
- declare function pickFeedContext(symA: string, symB: string, source: string, bitsharesClient: any): Promise<{
23
- kind: string;
24
- legs: any[];
25
- } | null>;
39
+ declare function resolveMpaBacking(mpaSymbol: string, bitsharesClient: ChainClientLike): Promise<MpaBackingCtx | null>;
40
+ declare function pickFeedContext(symA: string, symB: string, source: string, bitsharesClient: ChainClientLike): Promise<FeedCtx | null>;
26
41
  declare function feedAgeMs(ctx: {
27
42
  feedPublicationTime: string | null;
28
43
  }, nowMs?: number): number | null;
29
- declare function feedName(feedCtx: {
30
- kind: string;
31
- legs: any[];
32
- }): string;
33
- declare function activateFeedIfCovered(symA: string, symB: string, assetA: any, assetB: any, source: string, bitsharesClient: any, label?: string): Promise<{
34
- kind: string;
35
- legs: any[];
36
- } | null>;
44
+ declare function feedName(feedCtx: FeedCtx): string;
45
+ declare function activateFeedIfCovered(symA: string, symB: string, assetA: AssetMeta, assetB: AssetMeta, source: string, bitsharesClient: ChainClientLike, label?: string): Promise<FeedCtx | null>;
37
46
  declare function parseArgs(argv: string[], cmd?: ChartCmd): {
38
47
  target: string | null;
39
48
  months: number;