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
@@ -75,7 +75,7 @@ import * as Format from '../format.js';
75
75
  import * as MathUtils from './math.js';
76
76
  import Logger from '../../order/logger.js';
77
77
  import { sleep } from './system.js';
78
- import { getErrorMessage } from '../../utils/errors.js';
78
+ import { getErrorMessage, getErrorCode, getErrorName } from '../../utils/errors.js';
79
79
  import { hasGenesisLadder } from '../genesis_policy.js';
80
80
  import { parseSlotIndex as parseSlotIndexShared } from './slot.js';
81
81
  const { isValidNumber, toFiniteNumber } = Format;
@@ -198,6 +198,59 @@ function _filterUnmatchedChainOrders(manager, chainOrderId) {
198
198
  manager._lastUnmatchedChainOrders = manager._lastUnmatchedChainOrders.filter((u) => (u?.id || u?.orderId || u?.chainOrderId) !== chainOrderId);
199
199
  }
200
200
  }
201
+ /**
202
+ * Record a fresh on-chain placement timestamp for surplus-cancel grace.
203
+ * Called when a slot gains a chain orderId it did not have before (create,
204
+ * adopt, rotation target). Powers isFreshlyPlacedOrder below.
205
+ * @param {unknown} manager - OrderManager instance (owns `_placedAt`)
206
+ * @param {string} chainOrderId - Chain order id that was just placed
207
+ */
208
+ function recordOrderPlacement(manager, chainOrderId) {
209
+ try {
210
+ if (!manager || chainOrderId == null || String(chainOrderId).length === 0)
211
+ return;
212
+ if (!(manager._placedAt instanceof Map))
213
+ manager._placedAt = new Map();
214
+ manager._placedAt.set(String(chainOrderId), Date.now());
215
+ // Lazy GC: placement timestamps only matter inside the grace window.
216
+ if (manager._placedAt.size > 500) {
217
+ const cutoff = Date.now() - TIMING.SURPLUS_CANCEL_GRACE_MS * 2;
218
+ for (const [id, ts] of manager._placedAt) {
219
+ if (Number(ts) < cutoff)
220
+ manager._placedAt.delete(id);
221
+ }
222
+ }
223
+ }
224
+ catch { /* bookkeeping must never break placement */ }
225
+ }
226
+ /**
227
+ * True when the chain order was placed within the surplus-cancel grace
228
+ * window. Surplus sweeps must skip such orders: a fill landing between two
229
+ * controllers' count snapshots otherwise makes the second cancel what the
230
+ * first just placed (fee bleed + empty levels, no net change).
231
+ * @param {unknown} manager - OrderManager instance
232
+ * @param {string} chainOrderId - Chain order id to test
233
+ * @param {number} [graceMs] - Override grace window (defaults to TIMING.SURPLUS_CANCEL_GRACE_MS)
234
+ * @returns {boolean} True while the order is still inside its grace window
235
+ */
236
+ function isFreshlyPlacedOrder(manager, chainOrderId, graceMs) {
237
+ try {
238
+ if (chainOrderId == null || String(chainOrderId).length === 0)
239
+ return false;
240
+ const placedAt = manager?._placedAt instanceof Map
241
+ ? manager._placedAt.get(String(chainOrderId))
242
+ : null;
243
+ if (!Number.isFinite(Number(placedAt)))
244
+ return false;
245
+ const grace = Number.isFinite(Number(graceMs)) && Number(graceMs) > 0
246
+ ? Number(graceMs)
247
+ : TIMING.SURPLUS_CANCEL_GRACE_MS;
248
+ return Date.now() - Number(placedAt) < grace;
249
+ }
250
+ catch {
251
+ return false;
252
+ }
253
+ }
201
254
  /**
202
255
  * Remove a single correction entry by its full queue key
203
256
  * (chainOrderId + surplus flag). The queue's upsert key is
@@ -345,7 +398,7 @@ function _validatePriceCorrectionEntry(manager, entry) {
345
398
  if (!hasGenesisLadder(manager?._genesis)) {
346
399
  return { valid: false, reason: `no price ladder (INV-GRID-004) — slot ${slotId} has no authoritative price` };
347
400
  }
348
- if (!priceSlotEqual(slot.price, entry.expectedPrice, precision)) {
401
+ if (!priceSlotEqual(slot.price, Number(entry.expectedPrice), Number(precision))) {
349
402
  return { valid: false, reason: `slot ${slotId} now targets ${slot.price} (entry queued ${entry.expectedPrice})` };
350
403
  }
351
404
  // Size check: the broadcast sends amountToSell from the QUEUED snapshot.
@@ -383,7 +436,7 @@ function parseChainOrder(chainOrder, assets) {
383
436
  if (!chainOrder || !chainOrder.sell_price || !assets)
384
437
  return null;
385
438
  const { base, quote } = chainOrder.sell_price;
386
- if (!base || !quote || !base.asset_id || !quote.asset_id || base.amount === 0)
439
+ if (!base || !quote || !base.asset_id || !quote.asset_id || toFiniteNumber(base.amount) === 0)
387
440
  return null;
388
441
  let price;
389
442
  let type;
@@ -391,16 +444,18 @@ function parseChainOrder(chainOrder, assets) {
391
444
  const scaleFactor = precisionDelta >= 0
392
445
  ? Math.pow(10, precisionDelta)
393
446
  : Math.pow(10, Math.abs(precisionDelta));
447
+ const baseAmount = toFiniteNumber(base.amount);
448
+ const quoteAmount = toFiniteNumber(quote.amount);
394
449
  if (base.asset_id === assets.assetA.id && quote.asset_id === assets.assetB.id) {
395
450
  price = precisionDelta >= 0
396
- ? (quote.amount / base.amount) * scaleFactor
397
- : (quote.amount / base.amount) / scaleFactor;
451
+ ? (quoteAmount / baseAmount) * scaleFactor
452
+ : (quoteAmount / baseAmount) / scaleFactor;
398
453
  type = ORDER_TYPES.SELL;
399
454
  }
400
455
  else if (base.asset_id === assets.assetB.id && quote.asset_id === assets.assetA.id) {
401
456
  price = precisionDelta >= 0
402
- ? (base.amount / quote.amount) * scaleFactor
403
- : (base.amount / quote.amount) / scaleFactor;
457
+ ? (baseAmount / quoteAmount) * scaleFactor
458
+ : (baseAmount / quoteAmount) / scaleFactor;
404
459
  type = ORDER_TYPES.BUY;
405
460
  }
406
461
  else
@@ -481,7 +536,9 @@ function _currentCorrectionGridOrder(manager, correctionInfo) {
481
536
  if (!slotId || !(manager?.orders instanceof Map))
482
537
  return null;
483
538
  const liveSlot = manager.orders.get(slotId);
484
- return liveSlot?.orderId === correctionInfo?.chainOrderId ? liveSlot : null;
539
+ if (!liveSlot || liveSlot.orderId !== correctionInfo?.chainOrderId)
540
+ return null;
541
+ return liveSlot;
485
542
  }
486
543
  /**
487
544
  * Correct a single order's price on blockchain.
@@ -498,12 +555,24 @@ function _currentCorrectionGridOrder(manager, correctionInfo) {
498
555
  */
499
556
  async function correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders) {
500
557
  const { gridOrder, chainOrderId, expectedPrice, size, type, isSurplus, cancelOnly } = correctionInfo;
558
+ if (!chainOrderId)
559
+ return { success: false, error: 'missing chainOrderId' };
560
+ const expectedPriceNum = Number(expectedPrice);
561
+ const sizeNum = Number(size);
562
+ const typeStr = type == null ? '' : String(type);
501
563
  const stillNeeded = manager.ordersNeedingPriceCorrection?.some((c) => c.chainOrderId === chainOrderId);
502
564
  if (!stillNeeded)
503
565
  return { success: true, skipped: true };
504
566
  // Cancel-only entries (e.g., duplicate price level orphans) — cancel without
505
567
  // updating any grid slot. The orphan has no matching grid slot to convert.
506
568
  if (cancelOnly) {
569
+ // Surplus-cancel grace: a fill landing between two controllers' count
570
+ // snapshots must not get a seconds-old placement cancelled. Skip
571
+ // quietly; the entry stays queued and re-evaluates next cycle.
572
+ if (isFreshlyPlacedOrder(manager, chainOrderId)) {
573
+ manager.logger?.log?.(`[CORRECTION] Skipping cancel-only for freshly placed ${chainOrderId} — inside grace window`, 'info');
574
+ return { success: true, skipped: true };
575
+ }
507
576
  let shouldRemove = false;
508
577
  try {
509
578
  const sideLabel = type === ORDER_TYPES.SELL ? 'SELL' : 'BUY';
@@ -531,6 +600,10 @@ async function correctOrderPriceOnChain(manager, correctionInfo, accountName, pr
531
600
  }
532
601
  // Surplus/type-mismatch entries need cancellation, not a price update
533
602
  if (isSurplus) {
603
+ if (isFreshlyPlacedOrder(manager, chainOrderId)) {
604
+ manager.logger?.log?.(`[CORRECTION] Skipping surplus cancel for freshly placed ${chainOrderId} — inside grace window`, 'info');
605
+ return { success: true, skipped: true };
606
+ }
534
607
  let shouldRemove = false;
535
608
  try {
536
609
  const sideLabel = type === ORDER_TYPES.SELL ? 'SELL' : 'BUY';
@@ -564,12 +637,12 @@ async function correctOrderPriceOnChain(manager, correctionInfo, accountName, pr
564
637
  }
565
638
  let amountToSell, minToReceive;
566
639
  if (type === ORDER_TYPES.SELL) {
567
- amountToSell = size;
568
- minToReceive = size * expectedPrice;
640
+ amountToSell = sizeNum;
641
+ minToReceive = sizeNum * expectedPriceNum;
569
642
  }
570
643
  else {
571
- amountToSell = size;
572
- minToReceive = size / expectedPrice;
644
+ amountToSell = sizeNum;
645
+ minToReceive = sizeNum / expectedPriceNum;
573
646
  }
574
647
  let shouldRemove = false;
575
648
  // CROSSING-PLACEMENT GUARD: re-pricing the chain order to its slot's
@@ -580,9 +653,9 @@ async function correctOrderPriceOnChain(manager, correctionInfo, accountName, pr
580
653
  // the next sync's price-mismatch detection re-queues the correction
581
654
  // once the crossed order is resolved (same lifecycle as a 'skipped'
582
655
  // update below).
583
- const crossed = MathUtils.findCrossedOrder(buildCrossingCheckCandidates(manager), expectedPrice, type, manager.assets, (o) => isCrossingCheckCandidate(o, chainOrderId));
656
+ const crossed = MathUtils.findCrossedOrder(buildCrossingCheckCandidates(manager), expectedPriceNum, typeStr, manager.assets, (o) => isCrossingCheckCandidate(o, chainOrderId));
584
657
  if (crossed) {
585
- manager.logger?.log?.(`[CROSS-GUARD] Skipping price correction for ${chainOrderId} -> ${type} @${expectedPrice}: ` +
658
+ manager.logger?.log?.(`[CROSS-GUARD] Skipping price correction for ${chainOrderId} -> ${typeStr} @${expectedPriceNum}: ` +
586
659
  `crosses live ${crossed.type} ${crossed.id} (${crossed.orderId}) @${crossed.price}; ` +
587
660
  `retried after the crossed order resolves.`, 'warn');
588
661
  // The guard returns before the try/finally below, so drop the entry
@@ -612,7 +685,7 @@ async function correctOrderPriceOnChain(manager, correctionInfo, accountName, pr
612
685
  shouldRemove = true;
613
686
  _filterUnmatchedChainOrders(manager, chainOrderId);
614
687
  }
615
- else if (error?.code === 'BROADCAST_UNCERTAIN' || error?.name === 'BroadcastUncertainError') {
688
+ else if (getErrorCode(error) === 'BROADCAST_UNCERTAIN' || getErrorName(error) === 'BroadcastUncertainError') {
616
689
  // Uncertain update: the delta may have landed. Re-applying the same
617
690
  // delta on a later (possibly lagging) read would double-shrink the
618
691
  // order. Drop the entry instead of re-queueing blindly — the next
@@ -638,6 +711,8 @@ async function correctOrderPriceOnChain(manager, correctionInfo, accountName, pr
638
711
  */
639
712
  async function _resolveCancelledCorrection(manager, entry) {
640
713
  const chainOrderId = entry.chainOrderId;
714
+ if (!chainOrderId)
715
+ return;
641
716
  if (entry.cancelOnly) {
642
717
  clearDuplicateOrphanDetection(chainOrderId);
643
718
  }
@@ -722,7 +797,7 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
722
797
  catch (err) {
723
798
  // Op construction failed (e.g. account resolution): fall back entirely.
724
799
  logger?.log?.(`[CORRECTION] Batch cancel build failed (${presentIds.length} order(s)): ${getErrorMessage(err)}; falling back to serial cancels`, 'warn');
725
- return { corrected, failed, unresolved: entries.filter((e) => presentIds.includes(e.chainOrderId)) };
800
+ return { corrected, failed, unresolved: entries.filter((e) => e.chainOrderId != null && presentIds.includes(e.chainOrderId)) };
726
801
  }
727
802
  const configuredMax = Number(COW_PERFORMANCE?.MAX_CANCELS_PER_BROADCAST);
728
803
  const maxCancels = Number.isFinite(configuredMax) && configuredMax >= 1 ? Math.floor(configuredMax) : 1;
@@ -778,7 +853,7 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
778
853
  * cannot hold _gridLock (no acquisition timeout) for minutes. Reads the bot
779
854
  * config override first, then the frozen default. Non-finite/non-positive
780
855
  * falls back to the frozen default, then to 4000ms.
781
- * @param {any} manager
856
+ * @param {unknown} manager
782
857
  * @returns {number} Positive hold budget in milliseconds
783
858
  */
784
859
  function resolveCorrectionHoldBudget(manager) {
@@ -794,7 +869,7 @@ function resolveCorrectionHoldBudget(manager) {
794
869
  * on top of the hold-time budget: unset (null/undefined/non-finite) means no
795
870
  * count cap and the elapsed-time budget alone governs; a finite value >= 0 is
796
871
  * honored verbatim (0 intentionally drains no updates this cycle).
797
- * @param {any} manager
872
+ * @param {unknown} manager
798
873
  * @returns {number} Finite cap, or Infinity when uncapped
799
874
  */
800
875
  function resolveCorrectionMaxUpdates(manager) {
@@ -807,10 +882,28 @@ function resolveCorrectionMaxUpdates(manager) {
807
882
  return Math.floor(n);
808
883
  return Infinity;
809
884
  }
885
+ /**
886
+ * Resolve the inter-op delay between successive correction broadcasts.
887
+ * Reads the bot config override first, then the frozen default, falling back
888
+ * to TIMING.SYNC_DELAY_MS. A finite value >= 0 is honored verbatim (0 lets
889
+ * tests drive the drain with no wall-clock sleeps).
890
+ * @param {unknown} manager
891
+ * @returns {number} Non-negative delay in milliseconds
892
+ */
893
+ function resolveCorrectionInterOpDelayMs(manager) {
894
+ const raw = manager?.config?.fillProcessing?.CORRECTION_INTER_OP_DELAY_MS
895
+ ?? FILL_PROCESSING?.CORRECTION_INTER_OP_DELAY_MS;
896
+ if (raw != null) {
897
+ const n = Number(raw);
898
+ if (Number.isFinite(n) && n >= 0)
899
+ return Math.floor(n);
900
+ }
901
+ return TIMING.SYNC_DELAY_MS;
902
+ }
810
903
  /**
811
904
  * Resolve the correction-backlog warn threshold (see
812
905
  * CORRECTION_QUEUE_WARN_THRESHOLD). Non-positive disables the alarm.
813
- * @param {any} manager
906
+ * @param {unknown} manager
814
907
  * @returns {number}
815
908
  */
816
909
  function resolveCorrectionWarnThreshold(manager) {
@@ -823,7 +916,7 @@ function resolveCorrectionWarnThreshold(manager) {
823
916
  }
824
917
  /**
825
918
  * Resolve the correction-backlog warn rate-limit window.
826
- * @param {any} manager
919
+ * @param {unknown} manager
827
920
  * @returns {number}
828
921
  */
829
922
  function resolveCorrectionWarnRateLimitMs(manager) {
@@ -926,8 +1019,23 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
926
1019
  // inter-op delay, fund-safety-critical). Only the SYNC_DELAY_MS-spaced
927
1020
  // price-update loop is budgeted; the unselected remainder stays queued
928
1021
  // durably and re-drains next cycle.
929
- const cancelEntries = liveEntries.filter((c) => c.cancelOnly === true || c.isSurplus === true);
1022
+ //
1023
+ // Freshly placed orders are held back from BOTH the batched and the
1024
+ // serial cancel paths here: the per-entry grace check inside
1025
+ // correctOrderPriceOnChain cannot protect the batch path, which
1026
+ // bypasses it. Held-back entries are simply left in
1027
+ // ordersNeedingPriceCorrection (never removed) and re-drain next cycle.
1028
+ const cancelEntries = liveEntries.filter((c) => {
1029
+ if (!(c.cancelOnly === true || c.isSurplus === true))
1030
+ return false;
1031
+ if (isFreshlyPlacedOrder(manager, c.chainOrderId)) {
1032
+ manager?.logger?.log?.(`[CORRECTION] Deferring cancel of freshly placed ${c.chainOrderId} — inside grace window`, 'info');
1033
+ return false;
1034
+ }
1035
+ return true;
1036
+ });
930
1037
  const updateEntries = liveEntries.filter((c) => !(c.cancelOnly === true || c.isSurplus === true));
1038
+ const interOpDelayMs = resolveCorrectionInterOpDelayMs(manager);
931
1039
  const canBatch = cancelEntries.length > 1
932
1040
  && typeof accountOrders?.buildCancelOrderOp === 'function'
933
1041
  && typeof accountOrders?.executeBatch === 'function';
@@ -946,7 +1054,7 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
946
1054
  corrected++;
947
1055
  else
948
1056
  failed++;
949
- await sleep(TIMING.SYNC_DELAY_MS);
1057
+ await sleep(interOpDelayMs);
950
1058
  }
951
1059
  // Price updates are bounded by wall-clock lock-hold budget (primary)
952
1060
  // plus an optional hard count cap. The window opens *after* cancels so
@@ -972,7 +1080,7 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
972
1080
  else
973
1081
  failed++;
974
1082
  updatesProcessed++;
975
- await sleep(TIMING.SYNC_DELAY_MS);
1083
+ await sleep(interOpDelayMs);
976
1084
  }
977
1085
  // Persist master grid mutations from surplus-type-mismatch cancellations.
978
1086
  // Without this, corrections that cancel an order and convert its grid slot
@@ -1100,7 +1208,7 @@ function resolveConfiguredPriceBound(value, fallback, startPrice, mode) {
1100
1208
  const hint = mode === 'min'
1101
1209
  ? `'Nx' means center/N for minPrice, so use a value > 1 (e.g. '1.43x' to place the bound at 70% of center)`
1102
1210
  : `'Nx' means center*N for maxPrice, so use a value > 1`;
1103
- throw new Error(`Invalid ${boundName} '${configuredValue.trim()}': a bound multiplier must be > 1. ${hint}.`);
1211
+ throw new Error(`Invalid ${boundName} '${String(configuredValue).trim()}': a bound multiplier must be > 1. ${hint}.`);
1104
1212
  }
1105
1213
  const relative = MathUtils.resolveRelativePrice(configuredValue, startPrice, mode);
1106
1214
  if (Number.isFinite(relative)) {
@@ -1113,13 +1221,6 @@ function resolveConfiguredPriceBound(value, fallback, startPrice, mode) {
1113
1221
  }
1114
1222
  return numeric;
1115
1223
  }
1116
- /**
1117
- * Convert order to virtual state.
1118
- * Clears on-chain ID and raw blockchain data, marks as VIRTUAL.
1119
- *
1120
- * @param {Object} order - Order to virtualize
1121
- * @returns {Object} Virtualized order (VIRTUAL state, no orderId)
1122
- */
1123
1224
  function virtualizeOrder(order) {
1124
1225
  if (!order)
1125
1226
  return order;
@@ -1280,12 +1381,28 @@ function resolveSpreadOrderSide(price, startPrice) {
1280
1381
  /**
1281
1382
  * Parse a grid slot id ("slot-123") to its rail index. Delegates to
1282
1383
  * shared slot.ts single source (GRID_PRICE_SLOT_DETERMINISM_PLAN §2.1).
1283
- * @param {any} id - grid slot id string
1384
+ * @param {unknown} id - grid slot id string
1284
1385
  * @returns {number|null}
1285
1386
  */
1286
1387
  function parseSlotIndex(id) {
1287
1388
  return parseSlotIndexShared(id);
1288
1389
  }
1390
+ /**
1391
+ * Precision governing both price and size comparison for a parsed chain
1392
+ * order: base (assetA) for sells, quote (assetB) for buys.
1393
+ */
1394
+ function slotMatchPrecision(type, assets) {
1395
+ return type === ORDER_TYPES.SELL ? assets.assetA.precision : assets.assetB.precision;
1396
+ }
1397
+ /**
1398
+ * Whether a parsed chain order's size matches a slot's, within the shared
1399
+ * 1%-of-size tolerance (min 2 quanta). Single source of truth for adoption
1400
+ * size matching so the strict and tolerant matchers cannot disagree.
1401
+ */
1402
+ function slotSizeMatches(parsed, slot, precision) {
1403
+ const sizeTolerance = Math.max(2, Math.floor(floatToBlockchainInt(slot.size, precision) * 0.01));
1404
+ return Math.abs(floatToBlockchainInt(parsed.size, precision) - floatToBlockchainInt(slot.size, precision)) <= sizeTolerance;
1405
+ }
1289
1406
  /**
1290
1407
  * Whether a parsed chain order matches a grid slot exactly:
1291
1408
  * type-compatible (slot may be SPREAD), price strictly equal via integer
@@ -1306,16 +1423,10 @@ function chainOrderMatchesSlot(parsed, slot, assets) {
1306
1423
  if (parsed.type !== slot.type && slot.type !== ORDER_TYPES.SPREAD)
1307
1424
  return false;
1308
1425
  // Genesis-frozen: price equality via integer round-trip (single epsilon); slot id is handled by caller via slotIndexForPrice
1309
- {
1310
- const precision = parsed.type === ORDER_TYPES.SELL ? assets.assetA.precision : assets.assetB.precision;
1311
- if (!priceSlotEqual(parsed.price, slot.price, precision))
1312
- return false;
1313
- }
1314
- const precision = parsed.type === ORDER_TYPES.SELL ? assets.assetA.precision : assets.assetB.precision;
1315
- const sizeTolerance = Math.max(2, Math.floor(floatToBlockchainInt(slot.size, precision) * 0.01));
1316
- if (Math.abs(floatToBlockchainInt(parsed.size, precision) - floatToBlockchainInt(slot.size, precision)) > sizeTolerance)
1426
+ const precision = slotMatchPrecision(parsed.type, assets);
1427
+ if (!priceSlotEqual(parsed.price, slot.price, precision))
1317
1428
  return false;
1318
- return true;
1429
+ return slotSizeMatches(parsed, slot, precision);
1319
1430
  }
1320
1431
  /**
1321
1432
  * Whether a parsed chain order matches a grid slot within price tolerance:
@@ -1337,10 +1448,10 @@ function chainOrderMatchesSlotWithTolerance(parsed, slot, assets) {
1337
1448
  return false;
1338
1449
  if (parsed.type !== slot.type && slot.type !== ORDER_TYPES.SPREAD)
1339
1450
  return false;
1340
- const precision = parsed.type === ORDER_TYPES.SELL ? assets.assetA.precision : assets.assetB.precision;
1451
+ const precision = slotMatchPrecision(parsed.type, assets);
1341
1452
  let tolerance = null;
1342
1453
  try {
1343
- tolerance = MathUtils.calculatePriceTolerance(Math.min(parsed.price, slot.price), Math.max(parsed.size, slot.size), parsed.type, assets);
1454
+ tolerance = MathUtils.calculatePriceTolerance(Math.min(parsed.price, slot.price), Math.max(Number(parsed.size) || 0, slot.size), parsed.type, assets);
1344
1455
  }
1345
1456
  catch {
1346
1457
  tolerance = null;
@@ -1355,10 +1466,7 @@ function chainOrderMatchesSlotWithTolerance(parsed, slot, assets) {
1355
1466
  tolerance = Math.min(tolerance, quantumCap);
1356
1467
  if (Math.abs(parsed.price - slot.price) > tolerance)
1357
1468
  return false;
1358
- const sizeTolerance = Math.max(2, Math.floor(floatToBlockchainInt(slot.size, precision) * 0.01));
1359
- if (Math.abs(floatToBlockchainInt(parsed.size, precision) - floatToBlockchainInt(slot.size, precision)) > sizeTolerance)
1360
- return false;
1361
- return true;
1469
+ return slotSizeMatches(parsed, slot, precision);
1362
1470
  }
1363
1471
  /**
1364
1472
  * Identity of a crossing-check candidate. Master orders carry orderId,
@@ -1422,7 +1530,7 @@ function isCrossingCheckCandidate(o, excludeChainOrderId = null, cancelOpIndexBy
1422
1530
  * master-grid-only checks cannot see (the pending/unmatched batch guards
1423
1531
  * fire only for CREATE batches).
1424
1532
  * @param {Object} manager - OrderManager instance (orders Map, _pendingBroadcasts, _lastUnmatchedChainOrders)
1425
- * @returns {any[]} Candidate orders/wrappers for findCrossedOrder
1533
+ * @returns {unknown[]} Candidate orders/wrappers for findCrossedOrder
1426
1534
  */
1427
1535
  function buildCrossingCheckCandidates(manager) {
1428
1536
  if (!manager)
@@ -1499,10 +1607,12 @@ function buildOutsideInPairGroups(items, { isValid = Boolean, getType, getPrice
1499
1607
  * @returns {Array} Array of operation result tuples, or empty array if unrecognized.
1500
1608
  */
1501
1609
  function extractBatchOperationResults(result) {
1502
- const ops = ((result && Array.isArray(result.operation_results) && result.operation_results) ||
1503
- (result && result.raw && Array.isArray(result.raw.operation_results) && result.raw.operation_results) ||
1504
- (result && result.raw && result.raw.trx && Array.isArray(result.raw.trx.operation_results) && result.raw.trx.operation_results) ||
1505
- (result && Array.isArray(result) && result[0] && result[0].trx && Array.isArray(result[0].trx.operation_results) && result[0].trx.operation_results) ||
1610
+ const r = result;
1611
+ const asArray = Array.isArray(result) ? result : null;
1612
+ const ops = ((r && Array.isArray(r.operation_results) && r.operation_results) ||
1613
+ (r && r.raw && Array.isArray(r.raw.operation_results) && r.raw.operation_results) ||
1614
+ (r && r.raw && r.raw.trx && Array.isArray(r.raw.trx.operation_results) && r.raw.trx.operation_results) ||
1615
+ (asArray && asArray[0] && asArray[0].trx && Array.isArray(asArray[0].trx.operation_results) && asArray[0].trx.operation_results) ||
1506
1616
  null);
1507
1617
  return (ops && ops.length > 0) ? ops : null;
1508
1618
  }
@@ -1516,10 +1626,10 @@ function formatUnmatchedChainOrder(order) {
1516
1626
  if (!order)
1517
1627
  return 'unknown unmatched order';
1518
1628
  const parts = [
1519
- `${order.chainOrderId || 'unknown'}:${order.type || 'unknown'}@${Format.formatPrice6(order.price)}`,
1629
+ `${order.chainOrderId || 'unknown'}:${order.type || 'unknown'}@${Format.formatPrice6(Number(order.price))}`,
1520
1630
  ];
1521
1631
  if (order.size !== undefined)
1522
- parts.push(`size=${Format.formatAmount(order.size)}`);
1632
+ parts.push(`size=${Format.formatAmount(Number(order.size))}`);
1523
1633
  if (order.slotId)
1524
1634
  parts.push(`slot=${order.slotId}`);
1525
1635
  if (order.reason)
@@ -1608,7 +1718,7 @@ function isStrandedHoldOrder(order) {
1608
1718
  *
1609
1719
  * @param {string} slotId - Grid slot id (slot-<idx>)
1610
1720
  * @param {number} price - Price about to be emitted
1611
- * @param {any} genesis - manager._genesis (priceLevels table)
1721
+ * @param {unknown} genesis - manager._genesis (priceLevels table)
1612
1722
  * @returns {{ok: boolean, reason: string, expected: number|null, idx: number|null, drift: number|null}}
1613
1723
  */
1614
1724
  function checkGridPriceInvariant(slotId, price, genesis) {
@@ -1649,7 +1759,7 @@ function checkGridPriceInvariant(slotId, price, genesis) {
1649
1759
  * reconcile sites treat `false` as blocking (skip the emission and let the next
1650
1760
  * cycle re-plan). See docs/GRID_PRICE_INVARIANT.md.
1651
1761
  *
1652
- * @param {any} manager - OrderManager (reads _genesis, writes logger)
1762
+ * @param {unknown} manager - OrderManager (reads _genesis, writes logger)
1653
1763
  * @param {string} slotId - Destination slot id whose level the price must match
1654
1764
  * @param {number} price - Price about to be emitted
1655
1765
  * @param {string} site - Emitting site label (CREATE / UPDATE / RECONCILE-*)
@@ -1659,7 +1769,7 @@ function checkGridPriceInvariant(slotId, price, genesis) {
1659
1769
  */
1660
1770
  function reportGridPriceInvariant(manager, slotId, price, site) {
1661
1771
  try {
1662
- const inv = checkGridPriceInvariant(slotId, price, manager?._genesis);
1772
+ const inv = checkGridPriceInvariant(slotId, price, hasGenesisLadder(manager?._genesis) ? manager._genesis : null);
1663
1773
  if (inv.ok)
1664
1774
  return true;
1665
1775
  manager?.logger?.log?.(`[GRID-PRICE-INVARIANT] ${site} for ${slotId} at ${Format.formatPrice6(Number(price))} ` +
@@ -1700,10 +1810,10 @@ function isOrderOnChain(order) {
1700
1810
  * @param {Object} ORDER_TYPES - ORDER_TYPES constants
1701
1811
  * @returns {string} Type to keep for the on-chain slot
1702
1812
  */
1703
- function resolveOnChainRetypeType(slot, idx, buyEndIdx, ORDER_TYPES) {
1704
- return (slot.type === ORDER_TYPES.BUY || slot.type === ORDER_TYPES.SELL)
1813
+ function resolveOnChainRetypeType(slot, idx, buyEndIdx, orderTypes) {
1814
+ return (slot.type === orderTypes.BUY || slot.type === orderTypes.SELL)
1705
1815
  ? slot.type
1706
- : (idx <= buyEndIdx ? ORDER_TYPES.BUY : ORDER_TYPES.SELL);
1816
+ : (idx <= buyEndIdx ? orderTypes.BUY : orderTypes.SELL);
1707
1817
  }
1708
1818
  /**
1709
1819
  * Check if order is virtual (not on blockchain yet).
@@ -1878,33 +1988,19 @@ function calculateIdealBoundary(allSlots, referencePrice, gapSlots) {
1878
1988
  if (!Number.isFinite(Number(referencePrice))) {
1879
1989
  return railCenterIndex(allSlots.length, gapSlots);
1880
1990
  }
1881
- let splitIdx = allSlots.findIndex((s) => s.price >= referencePrice);
1991
+ let splitIdx = allSlots.findIndex((s) => Number(s.price) >= Number(referencePrice));
1882
1992
  if (splitIdx === -1)
1883
1993
  splitIdx = allSlots.length;
1884
1994
  const buySpread = Math.floor(gapSlots / 2);
1885
1995
  return Math.max(0, Math.min(allSlots.length - 1, splitIdx - buySpread - 1));
1886
1996
  }
1887
- /**
1888
- * Assign BUY/SELL/SPREAD roles to grid slots based on boundary.
1889
- * Slots below boundary are BUY, above boundary are SELL, between are SPREAD.
1890
- * Can optionally override even on-chain orders.
1891
- *
1892
- * @param {Array<Object>} allSlots - All grid slots to assign
1893
- * @param {number} boundaryIdx - Boundary index
1894
- * @param {number} gapSlots - Number of gap slots between buy and sell
1895
- * @param {Object} ORDER_TYPES - ORDER_TYPES constants
1896
- * @param {Object} ORDER_STATES - ORDER_STATES constants
1897
- * @param {Object} [options={}] - Options
1898
- * @param {boolean} [options.assignOnChain=false] - Override on-chain orders if true
1899
- * @returns {Array<Object>} Slots with updated type assignments
1900
- */
1901
1997
  function assignGridRoles(allSlots, boundaryIdx, gapSlots, ORDER_TYPES, _ORDER_STATES, options = {}) {
1902
1998
  const assignOnChain = options.assignOnChain === true;
1903
1999
  const getCurrentSlot = (typeof options.getCurrentSlot === 'function') ? options.getCurrentSlot : null;
1904
2000
  const buyEndIdx = boundaryIdx;
1905
2001
  const sellStartIdx = MathUtils.getSellStartIdx(boundaryIdx, gapSlots);
1906
2002
  return allSlots.map((slot, i) => {
1907
- const liveSlot = getCurrentSlot ? (getCurrentSlot(slot.id) || slot) : slot;
2003
+ const liveSlot = getCurrentSlot && slot.id ? (getCurrentSlot(slot.id) || slot) : slot;
1908
2004
  // Empty VIRTUAL slots (size 0, no orderId) keep their RAIL type by
1909
2005
  // geometry (Phase 2): an in-rail hole stays BUY/SELL VIRTUAL so
1910
2006
  // candidate-selection and evacuation geometry keep working; only
@@ -2213,7 +2309,7 @@ function isShiftEligibleFill(fill) {
2213
2309
  return fill?.isPartial !== true || fill?.isDelayedRotationTrigger === true;
2214
2310
  }
2215
2311
  function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSlots, crossChunkBudget, pendingCrawls, edgeAnchors) {
2216
- let newBoundaryIdx = currentBoundaryIdx;
2312
+ let newBoundaryIdx = currentBoundaryIdx ?? null;
2217
2313
  // Recovery when the committed boundary is unknown (GRID-LOAD rejected a
2218
2314
  // poisoned snapshot, re-derivation failed, and no fill has re-anchored
2219
2315
  // since). Anchor tiers are position signals, weakest last. What must
@@ -2348,12 +2444,12 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2348
2444
  && (e.side === ORDER_TYPES.BUY || e.side === ORDER_TYPES.SELL)
2349
2445
  && !(e.side === ORDER_TYPES.BUY && reserveBuyIds && reserveBuyIds.has(e.slotId))
2350
2446
  && !(e.side === ORDER_TYPES.SELL && reserveSellIds && reserveSellIds.has(e.slotId)));
2351
- for (const fill of fills) {
2447
+ for (const fill of fills ?? []) {
2352
2448
  if (!isShiftEligibleFill(fill))
2353
2449
  continue;
2354
- if (fill && fill.type === ORDER_TYPES.BUY && reserveBuyIds && reserveBuyIds.has(fill.id))
2450
+ if (fill && fill.type === ORDER_TYPES.BUY && reserveBuyIds && fill.id != null && reserveBuyIds.has(fill.id))
2355
2451
  continue;
2356
- if (fill && fill.type === ORDER_TYPES.SELL && reserveSellIds && reserveSellIds.has(fill.id))
2452
+ if (fill && fill.type === ORDER_TYPES.SELL && reserveSellIds && fill.id != null && reserveSellIds.has(fill.id))
2357
2453
  continue;
2358
2454
  if (fill.type === ORDER_TYPES.SELL)
2359
2455
  netShift++;
@@ -2377,7 +2473,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2377
2473
  // consumes from the same pool so the total across all chunks
2378
2474
  // never exceeds half the active window.
2379
2475
  // Falls back to a per-call cap when no budget is set.
2380
- const fallbackCap = Math.max(Math.floor((config.activeOrders?.sell ?? 1) / 2), Math.floor((config.activeOrders?.buy ?? 1) / 2), 1);
2476
+ const fallbackCap = Math.max(Math.floor((config?.activeOrders?.sell ?? 1) / 2), Math.floor((config?.activeOrders?.buy ?? 1) / 2), 1);
2381
2477
  const effectiveBudget = crossChunkBudget ?? fallbackCap;
2382
2478
  const cap = Math.min(Math.abs(effectiveBudget), fallbackCap);
2383
2479
  if (recovered && anchoredFromFills) {
@@ -2424,7 +2520,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2424
2520
  * dropped rather than stranding live orders. Commits clear the record, so
2425
2521
  * entries present here predate every commit since recording — always owed.
2426
2522
  *
2427
- * @param {any} manager - OrderManager (boundaryIdx, orders, config restored)
2523
+ * @param {unknown} manager - OrderManager (boundaryIdx, orders, config restored)
2428
2524
  * @returns {{applied: boolean, from?: number, to?: number, count?: number, reason?: string}}
2429
2525
  */
2430
2526
  export function consumePendingFillCrawls(manager) {
@@ -2486,7 +2582,9 @@ export function consumePendingFillCrawls(manager) {
2486
2582
  clear();
2487
2583
  return { applied: false, reason: 'nothing-owed' };
2488
2584
  }
2489
- const fallbackCap = Math.max(Math.floor((config?.activeOrders?.sell ?? 1) / 2), Math.floor((config?.activeOrders?.buy ?? 1) / 2), 1);
2585
+ const activeOrdersCfg = config?.activeOrders;
2586
+ const activeOrdersObj = (activeOrdersCfg && typeof activeOrdersCfg === 'object') ? activeOrdersCfg : {};
2587
+ const fallbackCap = Math.max(Math.floor(Number(activeOrdersObj.sell ?? 1) / 2), Math.floor(Number(activeOrdersObj.buy ?? 1) / 2), 1);
2490
2588
  if (Math.abs(netShift) > fallbackCap)
2491
2589
  netShift = Math.sign(netShift) * fallbackCap;
2492
2590
  let gapSlots = Number(manager?._gapSlots);
@@ -2509,7 +2607,7 @@ export function consumePendingFillCrawls(manager) {
2509
2607
  check = MathUtils.validatePersistedBoundary(candidate, slots, gapSlots);
2510
2608
  }
2511
2609
  catch (err) {
2512
- check = { ok: false, reason: 'validator-threw', detail: String(err?.message ?? err) };
2610
+ check = { ok: false, reason: 'validator-threw', detail: getErrorMessage(err) };
2513
2611
  }
2514
2612
  if (!check || check.ok !== true) {
2515
2613
  clear();
@@ -2608,7 +2706,7 @@ function reserveEdgeIdSet(allSlots, config, orderType, anchorPrice = null, exclu
2608
2706
  .filter((s) => s && s.id != null && s.price != null && s.type === type && parseSlotIndex(s.id) !== null)
2609
2707
  .sort((a, b) => Number(a.price) - Number(b.price));
2610
2708
  for (const s of selectReserveEdgeSlots(ascending, n, excludeIds, isSell ? 'ceiling' : 'floor', anchor)) {
2611
- ids.add(s.id);
2709
+ ids.add(String(s.id));
2612
2710
  }
2613
2711
  return ids;
2614
2712
  }
@@ -2652,7 +2750,7 @@ function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots
2652
2750
  // Same type filter as the window pickers with known geometry: the
2653
2751
  // side's concrete type plus SPREAD placeholders (normalized empties
2654
2752
  // sitting in this side's rail).
2655
- const typeFilter = (o) => o && o.id != null && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD);
2753
+ const typeFilter = (o) => !!o && o.id != null && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD);
2656
2754
  const ids = allSlots
2657
2755
  .filter(typeFilter)
2658
2756
  .filter(inRail)
@@ -2670,7 +2768,7 @@ function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots
2670
2768
  * windowIdSetFromSlots). Delegates so the manager and explicit-geometry
2671
2769
  * callers share one definition.
2672
2770
  *
2673
- * @param {any} manager - OrderManager (orders Map, config, boundaryIdx)
2771
+ * @param {unknown} manager - OrderManager (orders Map, config, boundaryIdx)
2674
2772
  * @param {string} orderType - ORDER_TYPES.BUY or ORDER_TYPES.SELL
2675
2773
  * @returns {Set<string>|null} Window slot ids, or null when geometry unknown
2676
2774
  */
@@ -2715,7 +2813,7 @@ function liveWindowIdSet(manager, orderType) {
2715
2813
  * @param {Iterable<Object>} [options.slots] - Master slots (reserve classification)
2716
2814
  * @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
2717
2815
  * edge anchors (same pair the strategy classifies reserve fills against)
2718
- * @param {any} [options.manager] - OrderManager for the window exclusion (same
2816
+ * @param {unknown} [options.manager] - OrderManager for the window exclusion (same
2719
2817
  * set the placement pickers exclude); omit to fall back to the previous
2720
2818
  * exclusion-free classification (fail-open)
2721
2819
  * @returns {string[]} Refill slot ids (CREATE ids minus reserve edge ids)
@@ -2738,7 +2836,7 @@ function collectRefillSlotIds(actions, options = {}) {
2738
2836
  // required — Array.from(map) would hand reserveEdgeIdSet pairs.
2739
2837
  const allSlots = Array.isArray(slots)
2740
2838
  ? slots
2741
- : (typeof slots?.values === 'function'
2839
+ : (slots && typeof slots.values === 'function'
2742
2840
  ? Array.from(slots.values())
2743
2841
  : Array.from(slots));
2744
2842
  // Window exclusion keeps classification in agreement with the
@@ -2925,6 +3023,8 @@ function getActiveOrdersTotal(config) {
2925
3023
  * @returns {number} Available budget for the side
2926
3024
  */
2927
3025
  function getSideBudget(side, funds, config, totalTarget) {
3026
+ if (!funds)
3027
+ return 0;
2928
3028
  const isBuy = side === 'buy';
2929
3029
  const allocated = isBuy ? (funds.allocatedBuy || 0) : (funds.allocatedSell || 0);
2930
3030
  if (allocated <= 0)
@@ -2964,7 +3064,7 @@ function calculateBudgetedSizes(slots, side, budget, weightDist, incrementPercen
2964
3064
  // Precision not available — floatToBlockchainInt will throw
2965
3065
  }
2966
3066
  }
2967
- const incrementFactor = incrementPercent / 100;
3067
+ const incrementFactor = Number(incrementPercent) / 100;
2968
3068
  return MathUtils.allocateFundsByWeights(budget, slots.length, weightDist, incrementFactor, isBuy, // Reverse for BUY (Market-Close is last in array)
2969
3069
  0, precision);
2970
3070
  }
@@ -3014,7 +3114,7 @@ function detectCrossedBookPlan(manager, actions) {
3014
3114
  try {
3015
3115
  const startPrice = Number(manager?.config?.startPrice);
3016
3116
  const book = new Map();
3017
- for (const o of Array.from(manager?.orders?.values?.() ?? [])) {
3117
+ for (const o of manager.orders.values()) {
3018
3118
  if (!o || !o.orderId || o.price == null)
3019
3119
  continue;
3020
3120
  const price = Number(o.price);
@@ -3088,9 +3188,9 @@ function detectCrossedBookPlan(manager, actions) {
3088
3188
  * - the batch's fresh CREATE ids extracted from the broadcast result
3089
3189
  * (operation_results[i][1] aligns positionally with placedContexts[i]).
3090
3190
  *
3091
- * @param {any} mgr - bot.manager
3092
- * @param {any} placedResults - broadcast result (has operation_results); null when unavailable
3093
- * @param {any[]} placedContexts - opContexts (aligned with operation_results); null when unavailable
3191
+ * @param {unknown} mgr - bot.manager
3192
+ * @param {unknown} placedResults - broadcast result (has operation_results); null when unavailable
3193
+ * @param {unknown[]} placedContexts - opContexts (aligned with operation_results); null when unavailable
3094
3194
  * @param {string[]|null} [extraCreateIds=null] - fresh CREATE chain ids from another
3095
3195
  * authoritative source (e.g. the uncertain-broadcast poll confirmation) when
3096
3196
  * no broadcast result exists; merged into createIds so the lagging-create
@@ -3099,7 +3199,7 @@ function detectCrossedBookPlan(manager, actions) {
3099
3199
  */
3100
3200
  function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCreateIds = null) {
3101
3201
  const masterIds = new Set();
3102
- const grid = mgr && mgr.grid;
3202
+ const grid = mgr.grid;
3103
3203
  if (Array.isArray(grid)) {
3104
3204
  for (const slot of grid) {
3105
3205
  if (slot && slot.orderId && /^1\.7\.\d+$/.test(String(slot.orderId))) {
@@ -3126,9 +3226,10 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
3126
3226
  const ctx = placedContexts[i];
3127
3227
  if (!ctx || ctx.kind !== 'create')
3128
3228
  continue;
3129
- const opResult = opResults[i] && opResults[i][1];
3130
- if (opResult && /^1\.7\.\d+$/.test(String(opResult))) {
3131
- createIds.add(String(opResult));
3229
+ const rawOpResult = opResults[i] ? opResults[i][1] : undefined;
3230
+ const opResult = typeof rawOpResult === 'string' ? rawOpResult : null;
3231
+ if (opResult && /^1\.7\.\d+$/.test(opResult)) {
3232
+ createIds.add(opResult);
3132
3233
  }
3133
3234
  }
3134
3235
  }
@@ -3164,5 +3265,5 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
3164
3265
  return { masterIds: [...masterIds], createIds: [...createIds], all: [...all] };
3165
3266
  }
3166
3267
  export { parseChainOrder, applyChainSizeToGridOrder, buildFillKey, correctOrderPriceOnChain, correctAllPriceMismatches, _validatePriceCorrectionEntry, _stampCorrectionProvenance, findLiveOrderOwnerByChainId, buildCreateOrderArgs, getOrderTypeFromUpdatedFlags, resolveConfiguredPriceBound, virtualizeOrder, convertToSpreadPlaceholder, toRailHolePlaceholder, geometryTypeForSlotIndex, detectGapEvacuationCandidates, updateGapEvacuationStreaks, resolveSpreadOrderSide, chainOrderMatchesSlot, chainOrderMatchesSlotWithTolerance, crossingCandidateChainId, isCrossingCheckCandidate, buildCrossingCheckCandidates, parseSlotIndex, filterOrdersByType, buildOutsideInPairGroups, extractBatchOperationResults, formatUnmatchedChainOrder, isNonBlockingUnmatchedOrder, isStrandedHoldOrder, isOrderOnChain, isOrderVirtual, hasOnChainId, isOrderPlaced, isPhantomOrder, isSlotAvailable, isEmptyGridSlot, isOrderHealthy, checkSizeThreshold, checkSizesBeforeMinimum, calculateIdealBoundary, assignGridRoles, resolveOnChainRetypeType, shouldFlagOutOfSpread, buildIndexes, validateIndexes, ordersEqual, buildDelta, deriveTargetBoundary, isShiftEligibleFill, resolveReserveCount, resolveReserveOrders, selectReserveEdgeSlots, getActiveOrdersTotal, getSideBudget, calculateBudgetedSizes, buildCreateOpFingerprint, isOrderGoneErrorMessage, recordDuplicateOrphanDetection, clearDuplicateOrphanDetection, duplicateOrphanLogInfo, chainOrderUnchangedFromCache, detectCrossedBookPlan, collectKnownOnChainOrderIds, reserveEdgeIdSet, liveWindowIdSet, checkGridPriceInvariant, reportGridPriceInvariant };
3167
- export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds };
3268
+ export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds, recordOrderPlacement, isFreshlyPlacedOrder, _filterUnmatchedChainOrders };
3168
3269
  //# sourceMappingURL=order.js.map