dexbot 1.6.6 → 1.6.8

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 (632) hide show
  1. package/CHANGELOG.md +89 -1
  2. package/README.md +8 -5
  3. package/analysis/README.md +2 -3
  4. package/analysis/tradingview/README.md +78 -1
  5. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  6. package/claw/package.json +1 -1
  7. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  8. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  9. package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
  10. package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
  11. package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
  12. package/dist/analysis/tradingview/grid_reset_config.js +235 -0
  13. package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
  14. package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
  15. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
  16. package/dist/dexbot.js +44 -15
  17. package/dist/market_adapter/core/market_adapter_service.js +14 -2
  18. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
  19. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
  20. package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
  21. package/dist/market_adapter/inputs/window_cache.js +302 -48
  22. package/dist/market_adapter/market_adapter.d.ts +8 -1
  23. package/dist/market_adapter/market_adapter.js +22 -4
  24. package/dist/modules/account_bots.js +20 -9
  25. package/dist/modules/account_orders.d.ts +44 -4
  26. package/dist/modules/account_orders.js +104 -7
  27. package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
  28. package/dist/modules/bitshares-native/chain_client.js +197 -28
  29. package/dist/modules/bitshares-native/subscriptions.js +312 -10
  30. package/dist/modules/bitshares-native/transport.d.ts +1 -0
  31. package/dist/modules/bitshares-native/transport.js +97 -3
  32. package/dist/modules/bitshares_client.d.ts +20 -0
  33. package/dist/modules/bitshares_client.js +29 -0
  34. package/dist/modules/bot_settings.js +10 -1
  35. package/dist/modules/chain_keys.d.ts +37 -22
  36. package/dist/modules/chain_keys.js +145 -44
  37. package/dist/modules/cli_start_onboarding.d.ts +10 -0
  38. package/dist/modules/cli_start_onboarding.js +15 -0
  39. package/dist/modules/cli_start_output.d.ts +6 -0
  40. package/dist/modules/cli_start_output.js +8 -0
  41. package/dist/modules/config.d.ts +1 -0
  42. package/dist/modules/config.js +1 -0
  43. package/dist/modules/constants.d.ts +23 -2
  44. package/dist/modules/constants.js +196 -15
  45. package/dist/modules/dexbot_class.d.ts +6 -76
  46. package/dist/modules/dexbot_class.js +0 -32
  47. package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
  48. package/dist/modules/dexbot_cow_runtime.js +53 -96
  49. package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
  50. package/dist/modules/dexbot_fill_runtime.js +22 -3
  51. package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
  52. package/dist/modules/dexbot_maintenance_runtime.js +103 -11
  53. package/dist/modules/dexbot_startup_runtime.js +73 -20
  54. package/dist/modules/dexbot_state_recovery.d.ts +6 -0
  55. package/dist/modules/dexbot_state_recovery.js +34 -1
  56. package/dist/modules/order/async_lock.d.ts +8 -0
  57. package/dist/modules/order/async_lock.js +15 -0
  58. package/dist/modules/order/genesis_policy.d.ts +162 -0
  59. package/dist/modules/order/genesis_policy.js +267 -0
  60. package/dist/modules/order/grid.js +109 -135
  61. package/dist/modules/order/grid_reconcile.d.ts +9 -0
  62. package/dist/modules/order/grid_reconcile.js +13 -4
  63. package/dist/modules/order/grid_reconcile_internal.js +13 -2
  64. package/dist/modules/order/logger.d.ts +12 -2
  65. package/dist/modules/order/logger.js +29 -7
  66. package/dist/modules/order/manager.d.ts +53 -0
  67. package/dist/modules/order/manager.js +86 -25
  68. package/dist/modules/order/sync_engine.d.ts +19 -0
  69. package/dist/modules/order/sync_engine.js +284 -344
  70. package/dist/modules/order/utils/math.d.ts +22 -1
  71. package/dist/modules/order/utils/math.js +64 -1
  72. package/dist/modules/order/utils/order.d.ts +43 -58
  73. package/dist/modules/order/utils/order.js +302 -194
  74. package/dist/modules/order/utils/system.d.ts +97 -0
  75. package/dist/modules/order/utils/system.js +282 -3
  76. package/dist/modules/paths.d.ts +8 -1
  77. package/dist/modules/paths.js +11 -3
  78. package/dist/modules/utils/text_width.d.ts +19 -0
  79. package/dist/modules/utils/text_width.js +97 -0
  80. package/dist/modules/version_notice.d.ts +165 -0
  81. package/dist/modules/version_notice.js +364 -0
  82. package/dist/pm2.js +104 -18
  83. package/dist/scripts/update.js +62 -13
  84. package/dist/unlock.d.ts +14 -2
  85. package/dist/unlock.js +101 -4
  86. package/docs/BITSHARES_ONBOARDING.md +8 -1
  87. package/docs/COW_INVARIANTS.md +11 -2
  88. package/docs/CREDENTIAL_SECURITY.md +26 -0
  89. package/docs/DEXBOT_COMPARISON.md +4 -4
  90. package/docs/EVOLUTION.md +20 -18
  91. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  92. package/docs/GRID_PRICE_INVARIANT.md +204 -31
  93. package/docs/GRID_RECALCULATION.md +12 -0
  94. package/docs/LOGGING.md +17 -2
  95. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
  96. package/docs/README.md +3 -1
  97. package/docs/WORKFLOW.md +16 -5
  98. package/market_adapter/README.md +1 -1
  99. package/modules/README.md +18 -1
  100. package/package.json +14 -6
  101. package/scripts/README.md +28 -2
  102. package/scripts/clear-all.sh +13 -4
  103. package/scripts/clear-logs.sh +13 -4
  104. package/scripts/clear-market-adapter.sh +6 -0
  105. package/scripts/clear-orders.sh +5 -0
  106. package/scripts/lib/dexbot-paths.sh +108 -0
  107. package/tests/README.md +11 -3
  108. package/analysis/account_resolver.ts +0 -161
  109. package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
  110. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
  111. package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
  112. package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
  113. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
  114. package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
  115. package/analysis/analyze_dynamic_weight.ts +0 -243
  116. package/analysis/analyze_kalman.ts +0 -157
  117. package/analysis/analyze_regime.ts +0 -158
  118. package/analysis/analyze_regime_windows.ts +0 -470
  119. package/analysis/analyze_risk_profile.ts +0 -199
  120. package/analysis/analyze_trade_heatmap.ts +0 -362
  121. package/analysis/analyze_volatility.ts +0 -182
  122. package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
  123. package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
  124. package/analysis/bot_fitting/shared_utils.ts +0 -52
  125. package/analysis/bot_key_utils.ts +0 -426
  126. package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
  127. package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
  128. package/analysis/chain_pool.ts +0 -47
  129. package/analysis/chart_css.ts +0 -62
  130. package/analysis/chart_ui.ts +0 -105
  131. package/analysis/chart_utils.ts +0 -210
  132. package/analysis/fills_source.ts +0 -228
  133. package/analysis/grid_correction_check.ts +0 -786
  134. package/analysis/math_utils.ts +0 -53
  135. package/analysis/price_sources.ts +0 -136
  136. package/analysis/resolve_bot_accounts.ts +0 -199
  137. package/analysis/resolve_source.ts +0 -99
  138. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
  139. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
  140. package/analysis/trade_profitability.ts +0 -1335
  141. package/analysis/tradingview/analyze_tradingview.ts +0 -280
  142. package/analysis/tradingview/h-bts_tradingview.html +0 -1570
  143. package/analysis/tradingview/t-bts_tradingview.html +0 -1570
  144. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
  145. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
  146. package/analysis/trend_detection/hurst_analyzer.ts +0 -7
  147. package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
  148. package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
  149. package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
  150. package/analysis/trend_detection/package.json +0 -23
  151. package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
  152. package/analysis/trend_detection/regime_chart_generator.ts +0 -338
  153. package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
  154. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
  155. package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
  156. package/analysis/tsconfig.json +0 -29
  157. package/claw/tests/package.json +0 -3
  158. package/claw/tests/test_claw_bridge.ts +0 -570
  159. package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
  160. package/claw/tests/test_claw_chain_layer.ts +0 -739
  161. package/claw/tests/test_claw_data_flow.ts +0 -525
  162. package/claw/tests/test_claw_domain_logic.ts +0 -471
  163. package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
  164. package/claw/tests/test_claw_mcp_transport.ts +0 -243
  165. package/claw/tests/test_claw_regressions.ts +0 -711
  166. package/claw/tests/test_claw_skill_generation.ts +0 -103
  167. package/claw/tests/test_claw_state_store.ts +0 -44
  168. package/claw/tests/test_dexbot_profiles.ts +0 -654
  169. package/claw/tests/test_memu_bridge.ts +0 -189
  170. package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
  171. package/claw/tests/test_position_health.ts +0 -343
  172. package/claw/tests/test_position_manager.ts +0 -429
  173. package/claw/tests/test_position_manager_watch_health.ts +0 -100
  174. package/claw/tests/test_short_mpa_strategy.ts +0 -232
  175. package/dist/analysis/account_resolver.d.ts.map +0 -1
  176. package/dist/analysis/account_resolver.js.map +0 -1
  177. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  178. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  179. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  180. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  181. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  182. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  183. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  184. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  185. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  186. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  187. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  188. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  189. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  190. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  191. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  192. package/dist/analysis/analyze_kalman.js.map +0 -1
  193. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  194. package/dist/analysis/analyze_regime.js.map +0 -1
  195. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  196. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  197. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  198. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  199. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  200. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  201. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  202. package/dist/analysis/analyze_volatility.js.map +0 -1
  203. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  204. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  205. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  206. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  207. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  208. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  209. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  210. package/dist/analysis/bot_key_utils.js.map +0 -1
  211. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  212. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  213. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  214. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  215. package/dist/analysis/chain_pool.d.ts.map +0 -1
  216. package/dist/analysis/chain_pool.js.map +0 -1
  217. package/dist/analysis/chart_css.d.ts.map +0 -1
  218. package/dist/analysis/chart_css.js.map +0 -1
  219. package/dist/analysis/chart_ui.d.ts.map +0 -1
  220. package/dist/analysis/chart_ui.js.map +0 -1
  221. package/dist/analysis/chart_utils.d.ts.map +0 -1
  222. package/dist/analysis/chart_utils.js.map +0 -1
  223. package/dist/analysis/fills_source.d.ts.map +0 -1
  224. package/dist/analysis/fills_source.js.map +0 -1
  225. package/dist/analysis/grid_correction_check.d.ts.map +0 -1
  226. package/dist/analysis/grid_correction_check.js.map +0 -1
  227. package/dist/analysis/math_utils.d.ts.map +0 -1
  228. package/dist/analysis/math_utils.js.map +0 -1
  229. package/dist/analysis/price_sources.d.ts.map +0 -1
  230. package/dist/analysis/price_sources.js.map +0 -1
  231. package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
  232. package/dist/analysis/resolve_bot_accounts.js.map +0 -1
  233. package/dist/analysis/resolve_source.d.ts.map +0 -1
  234. package/dist/analysis/resolve_source.js.map +0 -1
  235. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  236. package/dist/analysis/trade_profitability.js.map +0 -1
  237. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  238. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  239. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
  240. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
  241. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  242. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  243. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  244. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  245. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  246. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  247. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  248. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  249. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  250. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  251. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  252. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  253. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  254. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  255. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  256. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  257. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
  258. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  259. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  260. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  261. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
  262. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  263. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  264. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
  265. package/dist/bot.d.ts.map +0 -1
  266. package/dist/bot.js.map +0 -1
  267. package/dist/credential-daemon.d.ts.map +0 -1
  268. package/dist/credential-daemon.js.map +0 -1
  269. package/dist/dexbot.d.ts.map +0 -1
  270. package/dist/dexbot.js.map +0 -1
  271. package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
  272. package/dist/market_adapter/ama_signal_runner.js.map +0 -1
  273. package/dist/market_adapter/candle_utils.d.ts.map +0 -1
  274. package/dist/market_adapter/candle_utils.js.map +0 -1
  275. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
  276. package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
  277. package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
  278. package/dist/market_adapter/core/config_normalizers.js.map +0 -1
  279. package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
  280. package/dist/market_adapter/core/kibana_candles.js.map +0 -1
  281. package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
  282. package/dist/market_adapter/core/kibana_client.js.map +0 -1
  283. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
  284. package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
  285. package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
  286. package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
  287. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
  288. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
  289. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
  290. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
  291. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
  292. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
  293. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
  294. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
  295. package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
  296. package/dist/market_adapter/core/strategies/ama.js.map +0 -1
  297. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
  298. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
  299. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
  300. package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
  301. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
  302. package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
  303. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
  304. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
  305. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
  306. package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
  307. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
  308. package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
  309. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
  310. package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
  311. package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
  312. package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
  313. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
  314. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
  315. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
  316. package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
  317. package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
  318. package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
  319. package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
  320. package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
  321. package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
  322. package/dist/market_adapter/inputs/window_cache.js.map +0 -1
  323. package/dist/market_adapter/interval_utils.d.ts.map +0 -1
  324. package/dist/market_adapter/interval_utils.js.map +0 -1
  325. package/dist/market_adapter/log_format.d.ts.map +0 -1
  326. package/dist/market_adapter/log_format.js.map +0 -1
  327. package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
  328. package/dist/market_adapter/lp_chart_core.js.map +0 -1
  329. package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
  330. package/dist/market_adapter/lp_chart_runner.js.map +0 -1
  331. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
  332. package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
  333. package/dist/market_adapter/market_adapter.d.ts.map +0 -1
  334. package/dist/market_adapter/market_adapter.js.map +0 -1
  335. package/dist/market_adapter/test_helpers.d.ts.map +0 -1
  336. package/dist/market_adapter/test_helpers.js.map +0 -1
  337. package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
  338. package/dist/market_adapter/utils/adapter_client.js.map +0 -1
  339. package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
  340. package/dist/market_adapter/utils/atomic_write.js.map +0 -1
  341. package/dist/market_adapter/utils/chain.d.ts.map +0 -1
  342. package/dist/market_adapter/utils/chain.js.map +0 -1
  343. package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
  344. package/dist/market_adapter/utils/data_discovery.js.map +0 -1
  345. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
  346. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
  347. package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
  348. package/dist/market_adapter/utils/file_lock.js.map +0 -1
  349. package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
  350. package/dist/market_adapter/utils/native_history.js.map +0 -1
  351. package/dist/modules/account_bots.d.ts.map +0 -1
  352. package/dist/modules/account_bots.js.map +0 -1
  353. package/dist/modules/account_orders.d.ts.map +0 -1
  354. package/dist/modules/account_orders.js.map +0 -1
  355. package/dist/modules/authority_resolver.d.ts.map +0 -1
  356. package/dist/modules/authority_resolver.js.map +0 -1
  357. package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
  358. package/dist/modules/bitshares-native/chain_client.js.map +0 -1
  359. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
  360. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
  361. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
  362. package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
  363. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
  364. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
  365. package/dist/modules/bitshares-native/index.d.ts.map +0 -1
  366. package/dist/modules/bitshares-native/index.js.map +0 -1
  367. package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
  368. package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
  369. package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
  370. package/dist/modules/bitshares-native/resolvers.js.map +0 -1
  371. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
  372. package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
  373. package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
  374. package/dist/modules/bitshares-native/serial/index.js.map +0 -1
  375. package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
  376. package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
  377. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
  378. package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
  379. package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
  380. package/dist/modules/bitshares-native/serial/types.js.map +0 -1
  381. package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
  382. package/dist/modules/bitshares-native/signing_client.js.map +0 -1
  383. package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
  384. package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
  385. package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
  386. package/dist/modules/bitshares-native/transport.js.map +0 -1
  387. package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
  388. package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
  389. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
  390. package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
  391. package/dist/modules/bitshares_client.d.ts.map +0 -1
  392. package/dist/modules/bitshares_client.js.map +0 -1
  393. package/dist/modules/bot_defaults.d.ts.map +0 -1
  394. package/dist/modules/bot_defaults.js.map +0 -1
  395. package/dist/modules/bot_settings.d.ts.map +0 -1
  396. package/dist/modules/bot_settings.js.map +0 -1
  397. package/dist/modules/bots_file_lock.d.ts.map +0 -1
  398. package/dist/modules/bots_file_lock.js.map +0 -1
  399. package/dist/modules/broadcast_failure.d.ts.map +0 -1
  400. package/dist/modules/broadcast_failure.js.map +0 -1
  401. package/dist/modules/chain_keys.d.ts.map +0 -1
  402. package/dist/modules/chain_keys.js.map +0 -1
  403. package/dist/modules/chain_orders.d.ts.map +0 -1
  404. package/dist/modules/chain_orders.js.map +0 -1
  405. package/dist/modules/cli_colors.d.ts.map +0 -1
  406. package/dist/modules/cli_colors.js.map +0 -1
  407. package/dist/modules/config.d.ts.map +0 -1
  408. package/dist/modules/config.js.map +0 -1
  409. package/dist/modules/constants.d.ts.map +0 -1
  410. package/dist/modules/constants.js.map +0 -1
  411. package/dist/modules/cr_planner.d.ts.map +0 -1
  412. package/dist/modules/cr_planner.js.map +0 -1
  413. package/dist/modules/credential_policy.d.ts.map +0 -1
  414. package/dist/modules/credential_policy.js.map +0 -1
  415. package/dist/modules/credential_runtime.d.ts.map +0 -1
  416. package/dist/modules/credential_runtime.js.map +0 -1
  417. package/dist/modules/credential_session_cache.d.ts.map +0 -1
  418. package/dist/modules/credential_session_cache.js.map +0 -1
  419. package/dist/modules/credit_pricing.d.ts.map +0 -1
  420. package/dist/modules/credit_pricing.js.map +0 -1
  421. package/dist/modules/credit_runtime.d.ts.map +0 -1
  422. package/dist/modules/credit_runtime.js.map +0 -1
  423. package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
  424. package/dist/modules/crypto/browser_provider.js.map +0 -1
  425. package/dist/modules/crypto/index.d.ts.map +0 -1
  426. package/dist/modules/crypto/index.js.map +0 -1
  427. package/dist/modules/crypto/node_provider.d.ts.map +0 -1
  428. package/dist/modules/crypto/node_provider.js.map +0 -1
  429. package/dist/modules/crypto/provider.d.ts.map +0 -1
  430. package/dist/modules/crypto/provider.js.map +0 -1
  431. package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
  432. package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
  433. package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
  434. package/dist/modules/crypto/pure_scrypt.js.map +0 -1
  435. package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
  436. package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
  437. package/dist/modules/crypto/sync.d.ts.map +0 -1
  438. package/dist/modules/crypto/sync.js.map +0 -1
  439. package/dist/modules/daemon_node_health.d.ts.map +0 -1
  440. package/dist/modules/daemon_node_health.js.map +0 -1
  441. package/dist/modules/dexbot_class.d.ts.map +0 -1
  442. package/dist/modules/dexbot_class.js.map +0 -1
  443. package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
  444. package/dist/modules/dexbot_cow_runtime.js.map +0 -1
  445. package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
  446. package/dist/modules/dexbot_credential_client.js.map +0 -1
  447. package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
  448. package/dist/modules/dexbot_fill_runtime.js.map +0 -1
  449. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
  450. package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
  451. package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
  452. package/dist/modules/dexbot_startup_runtime.js.map +0 -1
  453. package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
  454. package/dist/modules/dexbot_state_recovery.js.map +0 -1
  455. package/dist/modules/env.d.ts.map +0 -1
  456. package/dist/modules/env.js.map +0 -1
  457. package/dist/modules/fund_registry.d.ts.map +0 -1
  458. package/dist/modules/fund_registry.js.map +0 -1
  459. package/dist/modules/general_settings.d.ts.map +0 -1
  460. package/dist/modules/general_settings.js.map +0 -1
  461. package/dist/modules/graceful_shutdown.d.ts.map +0 -1
  462. package/dist/modules/graceful_shutdown.js.map +0 -1
  463. package/dist/modules/grid_price_source.d.ts.map +0 -1
  464. package/dist/modules/grid_price_source.js.map +0 -1
  465. package/dist/modules/key_store.d.ts.map +0 -1
  466. package/dist/modules/key_store.js.map +0 -1
  467. package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
  468. package/dist/modules/launcher/adapter_requirement.js.map +0 -1
  469. package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
  470. package/dist/modules/launcher/bot_supervisor.js.map +0 -1
  471. package/dist/modules/launcher/child_env.d.ts.map +0 -1
  472. package/dist/modules/launcher/child_env.js.map +0 -1
  473. package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
  474. package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
  475. package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
  476. package/dist/modules/launcher/credential_daemon.js.map +0 -1
  477. package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
  478. package/dist/modules/launcher/credential_secret.js.map +0 -1
  479. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
  480. package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
  481. package/dist/modules/launcher/headless_password.d.ts.map +0 -1
  482. package/dist/modules/launcher/headless_password.js.map +0 -1
  483. package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
  484. package/dist/modules/launcher/launch_modes.js.map +0 -1
  485. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
  486. package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
  487. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
  488. package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
  489. package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
  490. package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
  491. package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
  492. package/dist/modules/launcher/runtime_entry.js.map +0 -1
  493. package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
  494. package/dist/modules/launcher/status_reporting.js.map +0 -1
  495. package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
  496. package/dist/modules/launcher/supervisor_control.js.map +0 -1
  497. package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
  498. package/dist/modules/market_adapter_whitelist.js.map +0 -1
  499. package/dist/modules/node_connect_policy.d.ts.map +0 -1
  500. package/dist/modules/node_connect_policy.js.map +0 -1
  501. package/dist/modules/node_failure_ledger.d.ts.map +0 -1
  502. package/dist/modules/node_failure_ledger.js.map +0 -1
  503. package/dist/modules/node_health_cache.d.ts.map +0 -1
  504. package/dist/modules/node_health_cache.js.map +0 -1
  505. package/dist/modules/node_manager.d.ts.map +0 -1
  506. package/dist/modules/node_manager.js.map +0 -1
  507. package/dist/modules/order/accounting.d.ts.map +0 -1
  508. package/dist/modules/order/accounting.js.map +0 -1
  509. package/dist/modules/order/async_lock.d.ts.map +0 -1
  510. package/dist/modules/order/async_lock.js.map +0 -1
  511. package/dist/modules/order/export.d.ts.map +0 -1
  512. package/dist/modules/order/export.js.map +0 -1
  513. package/dist/modules/order/format.d.ts.map +0 -1
  514. package/dist/modules/order/format.js.map +0 -1
  515. package/dist/modules/order/grid.d.ts.map +0 -1
  516. package/dist/modules/order/grid.js.map +0 -1
  517. package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
  518. package/dist/modules/order/grid_reconcile.js.map +0 -1
  519. package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
  520. package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
  521. package/dist/modules/order/index.d.ts.map +0 -1
  522. package/dist/modules/order/index.js.map +0 -1
  523. package/dist/modules/order/logger.d.ts.map +0 -1
  524. package/dist/modules/order/logger.js.map +0 -1
  525. package/dist/modules/order/logger_state.d.ts.map +0 -1
  526. package/dist/modules/order/logger_state.js.map +0 -1
  527. package/dist/modules/order/manager.d.ts.map +0 -1
  528. package/dist/modules/order/manager.js.map +0 -1
  529. package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
  530. package/dist/modules/order/processed_fill_store.js.map +0 -1
  531. package/dist/modules/order/strategy.d.ts.map +0 -1
  532. package/dist/modules/order/strategy.js.map +0 -1
  533. package/dist/modules/order/sync_engine.d.ts.map +0 -1
  534. package/dist/modules/order/sync_engine.js.map +0 -1
  535. package/dist/modules/order/utils/math.d.ts.map +0 -1
  536. package/dist/modules/order/utils/math.js.map +0 -1
  537. package/dist/modules/order/utils/order.d.ts.map +0 -1
  538. package/dist/modules/order/utils/order.js.map +0 -1
  539. package/dist/modules/order/utils/slot.d.ts.map +0 -1
  540. package/dist/modules/order/utils/slot.js.map +0 -1
  541. package/dist/modules/order/utils/system.d.ts.map +0 -1
  542. package/dist/modules/order/utils/system.js.map +0 -1
  543. package/dist/modules/order/utils/timeout.d.ts.map +0 -1
  544. package/dist/modules/order/utils/timeout.js.map +0 -1
  545. package/dist/modules/order/utils/validate.d.ts.map +0 -1
  546. package/dist/modules/order/utils/validate.js.map +0 -1
  547. package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
  548. package/dist/modules/order/utils/withPoolRef.js.map +0 -1
  549. package/dist/modules/order/working_grid.d.ts.map +0 -1
  550. package/dist/modules/order/working_grid.js.map +0 -1
  551. package/dist/modules/path_api.d.ts.map +0 -1
  552. package/dist/modules/path_api.js.map +0 -1
  553. package/dist/modules/paths.d.ts.map +0 -1
  554. package/dist/modules/paths.js.map +0 -1
  555. package/dist/modules/process_discovery.d.ts.map +0 -1
  556. package/dist/modules/process_discovery.js.map +0 -1
  557. package/dist/modules/runtime.d.ts.map +0 -1
  558. package/dist/modules/runtime.js.map +0 -1
  559. package/dist/modules/runtime_settings.d.ts.map +0 -1
  560. package/dist/modules/runtime_settings.js.map +0 -1
  561. package/dist/modules/settings_merge.d.ts.map +0 -1
  562. package/dist/modules/settings_merge.js.map +0 -1
  563. package/dist/modules/socket_json_client.d.ts.map +0 -1
  564. package/dist/modules/socket_json_client.js.map +0 -1
  565. package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
  566. package/dist/modules/storage/browser_adapter.js.map +0 -1
  567. package/dist/modules/storage/index.d.ts.map +0 -1
  568. package/dist/modules/storage/index.js.map +0 -1
  569. package/dist/modules/storage/node_adapter.d.ts.map +0 -1
  570. package/dist/modules/storage/node_adapter.js.map +0 -1
  571. package/dist/modules/storage/types.d.ts.map +0 -1
  572. package/dist/modules/storage/types.js.map +0 -1
  573. package/dist/modules/types.d.ts.map +0 -1
  574. package/dist/modules/types.js.map +0 -1
  575. package/dist/modules/utils/base58check.d.ts.map +0 -1
  576. package/dist/modules/utils/base58check.js.map +0 -1
  577. package/dist/modules/utils/build_dir.d.ts.map +0 -1
  578. package/dist/modules/utils/build_dir.js.map +0 -1
  579. package/dist/modules/utils/chain_logs.d.ts.map +0 -1
  580. package/dist/modules/utils/chain_logs.js.map +0 -1
  581. package/dist/modules/utils/errors.d.ts.map +0 -1
  582. package/dist/modules/utils/errors.js.map +0 -1
  583. package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
  584. package/dist/modules/utils/sanitize_key.js.map +0 -1
  585. package/dist/modules/validate_profiles.d.ts.map +0 -1
  586. package/dist/modules/validate_profiles.js.map +0 -1
  587. package/dist/pm2.d.ts.map +0 -1
  588. package/dist/pm2.js.map +0 -1
  589. package/dist/scripts/analyze-credit.d.ts.map +0 -1
  590. package/dist/scripts/analyze-credit.js.map +0 -1
  591. package/dist/scripts/analyze-git.d.ts.map +0 -1
  592. package/dist/scripts/analyze-git.js.map +0 -1
  593. package/dist/scripts/analyze-orders.d.ts.map +0 -1
  594. package/dist/scripts/analyze-orders.js.map +0 -1
  595. package/dist/scripts/chart_command.d.ts.map +0 -1
  596. package/dist/scripts/chart_command.js.map +0 -1
  597. package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
  598. package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
  599. package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
  600. package/dist/scripts/diagnose-pool-history.js.map +0 -1
  601. package/dist/scripts/divergence-calc.d.ts.map +0 -1
  602. package/dist/scripts/divergence-calc.js.map +0 -1
  603. package/dist/scripts/dw.d.ts.map +0 -1
  604. package/dist/scripts/dw.js.map +0 -1
  605. package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
  606. package/dist/scripts/generate_lp_chart.js.map +0 -1
  607. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
  608. package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
  609. package/dist/scripts/native_release_gates.d.ts.map +0 -1
  610. package/dist/scripts/native_release_gates.js.map +0 -1
  611. package/dist/scripts/print_grid.d.ts.map +0 -1
  612. package/dist/scripts/print_grid.js.map +0 -1
  613. package/dist/scripts/run-tests.d.ts.map +0 -1
  614. package/dist/scripts/run-tests.js.map +0 -1
  615. package/dist/scripts/runner.d.ts.map +0 -1
  616. package/dist/scripts/runner.js.map +0 -1
  617. package/dist/scripts/sync-version.d.ts.map +0 -1
  618. package/dist/scripts/sync-version.js.map +0 -1
  619. package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
  620. package/dist/scripts/test-credit-renewal.js.map +0 -1
  621. package/dist/scripts/tv.d.ts.map +0 -1
  622. package/dist/scripts/tv.js.map +0 -1
  623. package/dist/scripts/update.d.ts.map +0 -1
  624. package/dist/scripts/update.js.map +0 -1
  625. package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
  626. package/dist/scripts/update_dist_freshness.js.map +0 -1
  627. package/dist/scripts/validate_bots.d.ts.map +0 -1
  628. package/dist/scripts/validate_bots.js.map +0 -1
  629. package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
  630. package/dist/scripts/verify-browser-bundle.js.map +0 -1
  631. package/dist/unlock.d.ts.map +0 -1
  632. package/dist/unlock.js.map +0 -1
@@ -10,7 +10,6 @@
10
10
  *
11
11
  * SECTION 1: CHAIN ORDER MATCHING & RECONCILIATION (5 functions)
12
12
  * - parseChainOrder(chainOrder, assets) - Parse blockchain order to grid format
13
- * - findMatchingGridOrderByOpenOrder(parsedChainOrder, opts) - Find matching grid order
14
13
  * - applyChainSizeToGridOrder(manager, gridOrder, chainSize) - Apply chain size to grid
15
14
  * - correctOrderPriceOnChain(manager, correctionInfo, ...) - Correct order price on chain
16
15
  * - correctAllPriceMismatches(manager, accountName, ...) - Correct all price mismatches
@@ -63,20 +62,21 @@
63
62
  * SECTION 10: STRATEGY CALCULATIONS (7 functions)
64
63
  * - resolveReserveCount(config, side) - Clamped per-side reserve count (>=0 int, 0 disables)
65
64
  * - resolveReserveOrders(config) - Total reserves buy+sell (fee/count totals)
66
- * - resolveLiveReserveEdgeAnchorPrice(manager, side) - Live-grid edge anchor (ladder/rail extreme first, config bound last; null when unresolved)
65
+ * - resolveLiveReserveEdgeAnchorPrice(manager, side) - Live-grid edge anchor (genesis ladder extreme; null when no usable ladder)
67
66
  * - resolveReserveEdgeAnchorPrice(config, side) - Config-bound anchor fallback (buy→minPrice, sell→maxPrice; null when unresolvable)
68
67
  * - compareReserveEdge(a, b, edge, anchorPrice) - Shared anchored edge comparator (single ordering source)
69
- * - reserveEdgeIdSet(allSlots, config, orderType, anchorPrice?) - Edge reserve id set (config count; shares the picker ordering)
68
+ * - reserveEdgeIdSet(allSlots, config, orderType, anchorPrice?, excludeIds?) - Edge reserve id set (config count; shares the picker ordering; excludeIds carries the window exclusion)
70
69
  * - selectReserveEdgeSlots(sortedAsc, count, excludeIds, edge, anchorPrice?) - Shared position picker (both edges anchor toward their bound)
71
70
  *
72
71
  * ===============================================================================
73
72
  */
74
- import { ORDER_TYPES, ORDER_STATES, TIMING, FEE_PARAMETERS, GRID_LIMITS, NATIVE_CLIENT, COW_PERFORMANCE, COW_ACTIONS } from '../../constants.js';
73
+ import { ORDER_TYPES, ORDER_STATES, TIMING, FEE_PARAMETERS, GRID_LIMITS, NATIVE_CLIENT, COW_PERFORMANCE, COW_ACTIONS, FILL_PROCESSING } from '../../constants.js';
75
74
  import * as Format from '../format.js';
76
75
  import * as MathUtils from './math.js';
77
76
  import Logger from '../../order/logger.js';
78
77
  import { sleep } from './system.js';
79
78
  import { getErrorMessage } from '../../utils/errors.js';
79
+ import { hasGenesisLadder } from '../genesis_policy.js';
80
80
  import { parseSlotIndex as parseSlotIndexShared } from './slot.js';
81
81
  const { isValidNumber, toFiniteNumber } = Format;
82
82
  const { blockchainToFloat, floatToBlockchainInt, quantizeFloat, priceSlotEqual } = MathUtils;
@@ -264,10 +264,10 @@ function findLiveOrderOwnerByChainId(manager, chainOrderId, slotId) {
264
264
  * An entry is actionable only when the live slot:
265
265
  * 1. still exists in the master grid,
266
266
  * 2. still owns this chainOrderId (not re-slotted / adopted elsewhere),
267
- * 3. still targets the queued price — via priceSlotEqual on genesis
268
- * grids (same integer-round-trip predicate the pass-1 detector
269
- * uses) or calculatePriceTolerance on legacy grids (same predicate
270
- * the detector uses there).
267
+ * 3. still targets the queued price — priceSlotEqual against the slot's own
268
+ * level (the same integer-round-trip predicate the pass-1 detector
269
+ * uses). A ladder-less manager is an INV-GRID-004 fault, so the entry is
270
+ * dropped rather than matched by tolerance.
271
271
  *
272
272
  * Cancel-only duplicate-orphan decisions need an ownership check. They are
273
273
  * queued when a chain order has no matching grid slot, but startup reconcile
@@ -335,21 +335,17 @@ function _validatePriceCorrectionEntry(manager, entry) {
335
335
  }
336
336
  const assets = manager?.assets;
337
337
  const precision = entry.type === ORDER_TYPES.SELL ? assets?.assetA?.precision : assets?.assetB?.precision;
338
- let priceMatches = false;
339
- try {
340
- const genesis = manager?._genesis;
341
- if (genesis && Array.isArray(genesis.priceLevels)) {
342
- priceMatches = priceSlotEqual(slot.price, entry.expectedPrice, precision);
343
- }
344
- else {
345
- const tolerance = MathUtils.calculatePriceTolerance(entry.expectedPrice, entry.size, entry.type, assets);
346
- priceMatches = Math.abs(slot.price - entry.expectedPrice) <= (tolerance ?? 0);
347
- }
348
- }
349
- catch {
350
- priceMatches = slot.price === entry.expectedPrice;
351
- }
352
- if (!priceMatches) {
338
+ // A correction is stale when the slot no longer targets the price it was
339
+ // queued for. That is integer equality at the asset precision (the slot's
340
+ // level is its ladder level). A ladder-less manager is an INV-GRID-004
341
+ // fault: no slot has a price authority, so the entry cannot be validated
342
+ // and is dropped. The E2 sync gate refuses such a grid outright (queues
343
+ // nothing); it is the structural resync that restores the ladder, after
344
+ // which a later sync re-evaluates the slot.
345
+ if (!hasGenesisLadder(manager?._genesis)) {
346
+ return { valid: false, reason: `no price ladder (INV-GRID-004) — slot ${slotId} has no authoritative price` };
347
+ }
348
+ if (!priceSlotEqual(slot.price, entry.expectedPrice, precision)) {
353
349
  return { valid: false, reason: `slot ${slotId} now targets ${slot.price} (entry queued ${entry.expectedPrice})` };
354
350
  }
355
351
  // Size check: the broadcast sends amountToSell from the QUEUED snapshot.
@@ -422,74 +418,6 @@ function parseChainOrder(chainOrder, assets) {
422
418
  }
423
419
  return { orderId: chainOrder.id, price, type, size };
424
420
  }
425
- /**
426
- * Find grid order matching a blockchain order.
427
- * First tries exact orderId match, then falls back to price/size matching within tolerance.
428
- * Used during synchronization to link blockchain orders to grid slots.
429
- *
430
- * @param {Object} parsedChainOrder - Parsed blockchain order {orderId, price, type, size}
431
- * @param {Object} [opts={}] - Options object
432
- * @param {Map} [opts.orders] - Grid orders map to search
433
- * @param {Object} [opts.assets] - Asset metadata for precision
434
- * @param {Function} [opts.calcToleranceFn] - Function to calculate price tolerance
435
- * @param {Object} [opts.logger] - Optional logger
436
- * @param {boolean} [opts.skipSizeMatch=false] - Skip size matching check
437
- * @param {boolean} [opts.allowSmallerChainSize=false] - Allow chain order to be smaller
438
- * @param {boolean} [opts.requireAvailableSlot=false] - Skip slots already bound to a different chain order
439
- * @param {Set<string>} [opts.excludeGridOrderIds] - Skip grid slot ids already assigned in this sync pass
440
- * @returns {Object|null} Matching grid order or null if no match found
441
- */
442
- function findMatchingGridOrderByOpenOrder(parsedChainOrder, opts) {
443
- const { orders, assets, calcToleranceFn } = opts || {};
444
- if (!parsedChainOrder || !orders)
445
- return null;
446
- if (parsedChainOrder.orderId) {
447
- for (const gridOrder of orders.values()) {
448
- if (gridOrder?.orderId === parsedChainOrder.orderId)
449
- return gridOrder;
450
- }
451
- }
452
- const chainSize = toFiniteNumber(parsedChainOrder.size);
453
- const chainPrice = toFiniteNumber(parsedChainOrder.price);
454
- const isSell = parsedChainOrder.type === ORDER_TYPES.SELL;
455
- const precision = isSell ? assets?.assetA?.precision : assets?.assetB?.precision;
456
- if (typeof precision !== 'number')
457
- return null;
458
- const chainInt = floatToBlockchainInt(chainSize, precision);
459
- let bestMatch = null;
460
- let bestPriceDiff = Infinity;
461
- for (const gridOrder of orders.values()) {
462
- const typeMatch = gridOrder?.type === parsedChainOrder.type ||
463
- (opts?.allowSpreadType && gridOrder?.type === ORDER_TYPES.SPREAD);
464
- if (!gridOrder || !typeMatch)
465
- continue;
466
- if (opts?.excludeGridOrderIds?.has?.(gridOrder.id))
467
- continue;
468
- if (![ORDER_STATES.ACTIVE, ORDER_STATES.PARTIAL, ORDER_STATES.VIRTUAL].includes(gridOrder.state))
469
- continue;
470
- if (opts?.requireAvailableSlot && gridOrder.orderId && gridOrder.orderId !== parsedChainOrder.orderId)
471
- continue;
472
- const priceDiff = Math.abs(gridOrder.price - chainPrice);
473
- // Virtual/spread slots have size=0 — fall back to chain order's size so the
474
- // precision-based tolerance is meaningful instead of collapsing to 0.
475
- const effectiveSize = gridOrder.size > 0 ? gridOrder.size : chainSize;
476
- // When calcToleranceFn returns null (e.g. zero-size virtual slot), fall back to
477
- // exact matching (tolerance=0). This is intentional — virtual/spread slots should
478
- // only match chain orders at exactly their grid price.
479
- const priceTolerance = calcToleranceFn?.(gridOrder.price, effectiveSize, parsedChainOrder.type) || 0;
480
- if (priceDiff > priceTolerance)
481
- continue;
482
- const gridInt = floatToBlockchainInt(gridOrder.size, precision);
483
- const sizeMismatch = opts?.allowSmallerChainSize ? (chainInt > gridInt + 1) : (Math.abs(gridInt - chainInt) > 1);
484
- if (!opts?.skipSizeMatch && sizeMismatch)
485
- continue;
486
- if (priceDiff < bestPriceDiff) {
487
- bestPriceDiff = priceDiff;
488
- bestMatch = gridOrder;
489
- }
490
- }
491
- return bestMatch;
492
- }
493
421
  /**
494
422
  * Update grid order size based on blockchain state.
495
423
  * Detects partial fills and updates accounting if size changed.
@@ -843,6 +771,70 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
843
771
  }
844
772
  return { corrected, failed, unresolved };
845
773
  }
774
+ /**
775
+ * Resolve the wall-clock budget for the sequential price-update drain in
776
+ * correctAllPriceMismatches. Cancel-class entries are never budgeted; only
777
+ * the SYNC_DELAY_MS-spaced update loop is bounded, so an unbounded backlog
778
+ * cannot hold _gridLock (no acquisition timeout) for minutes. Reads the bot
779
+ * config override first, then the frozen default. Non-finite/non-positive
780
+ * falls back to the frozen default, then to 4000ms.
781
+ * @param {any} manager
782
+ * @returns {number} Positive hold budget in milliseconds
783
+ */
784
+ function resolveCorrectionHoldBudget(manager) {
785
+ const raw = manager?.config?.fillProcessing?.CORRECTION_LOCK_HOLD_BUDGET_MS
786
+ ?? FILL_PROCESSING?.CORRECTION_LOCK_HOLD_BUDGET_MS;
787
+ const n = Number(raw);
788
+ if (Number.isFinite(n) && n > 0)
789
+ return Math.floor(n);
790
+ return 4000;
791
+ }
792
+ /**
793
+ * Resolve the optional hard cap on price updates drained per cycle. Layered
794
+ * on top of the hold-time budget: unset (null/undefined/non-finite) means no
795
+ * count cap and the elapsed-time budget alone governs; a finite value >= 0 is
796
+ * honored verbatim (0 intentionally drains no updates this cycle).
797
+ * @param {any} manager
798
+ * @returns {number} Finite cap, or Infinity when uncapped
799
+ */
800
+ function resolveCorrectionMaxUpdates(manager) {
801
+ const raw = manager?.config?.fillProcessing?.CORRECTION_MAX_UPDATES_PER_CYCLE
802
+ ?? FILL_PROCESSING?.CORRECTION_MAX_UPDATES_PER_CYCLE;
803
+ if (raw == null)
804
+ return Infinity;
805
+ const n = Number(raw);
806
+ if (Number.isFinite(n) && n >= 0)
807
+ return Math.floor(n);
808
+ return Infinity;
809
+ }
810
+ /**
811
+ * Resolve the correction-backlog warn threshold (see
812
+ * CORRECTION_QUEUE_WARN_THRESHOLD). Non-positive disables the alarm.
813
+ * @param {any} manager
814
+ * @returns {number}
815
+ */
816
+ function resolveCorrectionWarnThreshold(manager) {
817
+ const raw = manager?.config?.fillProcessing?.CORRECTION_QUEUE_WARN_THRESHOLD
818
+ ?? FILL_PROCESSING?.CORRECTION_QUEUE_WARN_THRESHOLD;
819
+ const n = Number(raw);
820
+ if (Number.isFinite(n) && n > 0)
821
+ return Math.floor(n);
822
+ return 0;
823
+ }
824
+ /**
825
+ * Resolve the correction-backlog warn rate-limit window.
826
+ * @param {any} manager
827
+ * @returns {number}
828
+ */
829
+ function resolveCorrectionWarnRateLimitMs(manager) {
830
+ const raw = manager?.config?.fillProcessing?.CORRECTION_QUEUE_WARN_RATE_LIMIT_MS
831
+ ?? FILL_PROCESSING?.CORRECTION_QUEUE_WARN_RATE_LIMIT_MS
832
+ ?? TIMING?.STALE_TOTALS_WARN_RATE_LIMIT_MS;
833
+ const n = Number(raw);
834
+ if (Number.isFinite(n) && n > 0)
835
+ return n;
836
+ return 5 * 60 * 1000;
837
+ }
846
838
  /**
847
839
  * Correct all pending price mismatches atomically.
848
840
  * Cancel-type corrections (duplicate orphans, surplus) are batched into
@@ -857,6 +849,31 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
857
849
  async function correctAllPriceMismatches(manager, accountName, privateKey, accountOrders) {
858
850
  if (!manager || !manager._gridLock)
859
851
  return { corrected: 0, failed: 0, results: [] };
852
+ // 6b: backlog alarm (rate-limited). Emitted even when the drain defers
853
+ // below, because deferral is exactly when the queue is growing.
854
+ const queuedBefore = Array.isArray(manager.ordersNeedingPriceCorrection)
855
+ ? manager.ordersNeedingPriceCorrection.length
856
+ : 0;
857
+ const warnThreshold = resolveCorrectionWarnThreshold(manager);
858
+ if (warnThreshold > 0 && queuedBefore >= warnThreshold) {
859
+ const now = Date.now();
860
+ const warnRateLimitMs = resolveCorrectionWarnRateLimitMs(manager);
861
+ const lastWarn = Number(manager._correctionQueueWarnAt) || 0;
862
+ if (now - lastWarn >= warnRateLimitMs) {
863
+ manager._correctionQueueWarnAt = now;
864
+ manager?.logger?.log?.(`[CORRECTION] Backlog: ${queuedBefore} pending correction(s) (threshold ${warnThreshold}); ` +
865
+ `draining budgeted price updates per cycle so _gridLock is not held across a long drain`, 'warn');
866
+ }
867
+ }
868
+ // 7a: pre-acquire deferral. _gridLock has NO acquisition timeout, so
869
+ // taking it while a broadcast/placement region is active holds it across
870
+ // the region and starves every concurrent per-op lock acquisition (the
871
+ // broadcaster's own _applySync/cancel calls). Leave corrections queued —
872
+ // the next sync / maintenance tick drains them once the region ends.
873
+ if (manager.isBroadcastingActive?.() === true) {
874
+ manager?.logger?.log?.(`[CORRECTION] Drain deferred: broadcast/placement region active; ${queuedBefore} correction(s) stay queued`, 'debug');
875
+ return { corrected: 0, failed: 0, results: [], staleDropped: 0, deferred: true, reason: 'broadcast-active' };
876
+ }
860
877
  return await manager._gridLock.acquire(async () => {
861
878
  const results = [];
862
879
  let corrected = 0;
@@ -905,27 +922,56 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
905
922
  `(queued ${entry.queuedBy || 'unknown-source'}@${entry.queuedAt ? new Date(entry.queuedAt).toISOString() : 'unknown-time'}): ` +
906
923
  `${check.reason}; re-queued by next sync if still off-target`, 'info');
907
924
  }
908
- const canBatch = liveEntries.length > 1
925
+ // 6a: cancel-class entries are always fully drained (batched, no
926
+ // inter-op delay, fund-safety-critical). Only the SYNC_DELAY_MS-spaced
927
+ // price-update loop is budgeted; the unselected remainder stays queued
928
+ // durably and re-drains next cycle.
929
+ const cancelEntries = liveEntries.filter((c) => c.cancelOnly === true || c.isSurplus === true);
930
+ const updateEntries = liveEntries.filter((c) => !(c.cancelOnly === true || c.isSurplus === true));
931
+ const canBatch = cancelEntries.length > 1
909
932
  && typeof accountOrders?.buildCancelOrderOp === 'function'
910
933
  && typeof accountOrders?.executeBatch === 'function';
911
- let serialEntries = liveEntries;
934
+ let serialCancels = cancelEntries;
912
935
  if (canBatch) {
913
- const cancelEntries = liveEntries.filter((c) => c.cancelOnly === true || c.isSurplus === true);
914
- const updateEntries = liveEntries.filter((c) => !(c.cancelOnly === true || c.isSurplus === true));
915
- if (cancelEntries.length > 1) {
916
- const batchOutcome = await _batchCancelCorrections(manager, cancelEntries, accountName, privateKey, accountOrders);
917
- corrected += batchOutcome.corrected;
918
- failed += batchOutcome.failed;
919
- serialEntries = [...batchOutcome.unresolved, ...updateEntries];
920
- }
936
+ const batchOutcome = await _batchCancelCorrections(manager, cancelEntries, accountName, privateKey, accountOrders);
937
+ corrected += batchOutcome.corrected;
938
+ failed += batchOutcome.failed;
939
+ // Unresolved cancels still serialize (they must not be dropped).
940
+ serialCancels = batchOutcome.unresolved;
941
+ }
942
+ for (const correctionInfo of serialCancels) {
943
+ const result = await correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders);
944
+ results.push({ ...correctionInfo, result });
945
+ if (result && result.success)
946
+ corrected++;
947
+ else
948
+ failed++;
949
+ await sleep(TIMING.SYNC_DELAY_MS);
921
950
  }
922
- for (const correctionInfo of serialEntries) {
951
+ // Price updates are bounded by wall-clock lock-hold budget (primary)
952
+ // plus an optional hard count cap. The window opens *after* cancels so
953
+ // fund-critical cancels are never delayed by the update budget, and it
954
+ // is measured from the clock rather than a fixed count so a slow chain
955
+ // (large RPC round-trip) drains fewer updates instead of holding
956
+ // _gridLock past the 20s fill-lock timeout. Leftovers stay queued in
957
+ // order for the next cycle.
958
+ const holdBudgetMs = resolveCorrectionHoldBudget(manager);
959
+ const maxUpdates = resolveCorrectionMaxUpdates(manager);
960
+ const updateDeadline = Date.now() + holdBudgetMs;
961
+ let updatesProcessed = 0;
962
+ let deferredUpdates = 0;
963
+ for (const correctionInfo of updateEntries) {
964
+ if (updatesProcessed >= maxUpdates || Date.now() >= updateDeadline) {
965
+ deferredUpdates++;
966
+ continue;
967
+ }
923
968
  const result = await correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders);
924
969
  results.push({ ...correctionInfo, result });
925
970
  if (result && result.success)
926
971
  corrected++;
927
972
  else
928
973
  failed++;
974
+ updatesProcessed++;
929
975
  await sleep(TIMING.SYNC_DELAY_MS);
930
976
  }
931
977
  // Persist master grid mutations from surplus-type-mismatch cancellations.
@@ -935,7 +981,15 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
935
981
  if (corrected > 0 && typeof manager.persistGrid === 'function') {
936
982
  await manager.persistGrid();
937
983
  }
938
- return { corrected, failed, results, staleDropped };
984
+ if (deferredUpdates > 0) {
985
+ const queuedAfter = Array.isArray(manager.ordersNeedingPriceCorrection)
986
+ ? manager.ordersNeedingPriceCorrection.length
987
+ : 0;
988
+ manager?.logger?.log?.(`[CORRECTION] Deferred ${deferredUpdates} price update(s) to the next cycle ` +
989
+ `(hold budget ${holdBudgetMs}ms${Number.isFinite(maxUpdates) ? `, cap ${maxUpdates}` : ''}, ` +
990
+ `${queuedAfter} still queued)`, 'info');
991
+ }
992
+ return { corrected, failed, results, staleDropped, deferredUpdates };
939
993
  });
940
994
  }
941
995
  // ================================================================================
@@ -1517,6 +1571,8 @@ function isNonBlockingUnmatchedOrder(order) {
1517
1571
  * - `boundary-unknown-deferred`: gap geometry is unknown pre-boundary; the
1518
1572
  * comment at sync_engine.ts names the accepted cost as one sync cycle
1519
1573
  * after the boundary commits. Self-resolving, not stranded.
1574
+ * - `no-genesis-deferred`: included deliberately — a ladder-less grid is
1575
+ * repaired by exactly the reload this escalation performs.
1520
1576
  *
1521
1577
  * Anything not listed is treated as NOT escalatable, so a future transient
1522
1578
  * reason is excluded by default rather than silently becoming a resync
@@ -1525,6 +1581,9 @@ function isNonBlockingUnmatchedOrder(order) {
1525
1581
  const STRANDED_HOLD_REASONS = new Set([
1526
1582
  'out-of-rail-deferred',
1527
1583
  'out-of-grid-deferred',
1584
+ // Undefined grid (INV-GRID-004): a reload/rebuild IS the remedy, so this
1585
+ // hold escalates rather than sitting until a fill happens to trigger one.
1586
+ 'no-genesis-deferred',
1528
1587
  ]);
1529
1588
  /**
1530
1589
  * @param {Object} order - Unmatched chain order entry.
@@ -1780,6 +1839,23 @@ function checkSizeThreshold(sizes, threshold, precision, includeNonFinite = fals
1780
1839
  function checkSizesBeforeMinimum(sizes, minSize, precision) {
1781
1840
  return checkSizeThreshold(sizes, minSize, precision, true);
1782
1841
  }
1842
+ /**
1843
+ * Bounded rail-center index for a slot array of `length` with `gapSlots`.
1844
+ * The same fallback used by `calculateIdealBoundary` (non-numeric reference)
1845
+ * and `deriveTargetBoundary` (Tier-4 recovery): never a rail edge, wrong by
1846
+ * at most half the rail. Shared so the two spellings cannot drift.
1847
+ *
1848
+ * @param {number} length - Slot count
1849
+ * @param {number} gapSlots - Gap band size
1850
+ * @returns {number} Clamped center index (0 when the rail is empty)
1851
+ */
1852
+ function railCenterIndex(length, gapSlots) {
1853
+ const len = Number(length);
1854
+ if (!Number.isFinite(len) || len <= 0)
1855
+ return 0;
1856
+ const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
1857
+ return Math.max(0, Math.floor((len - 1 - gap) / 2));
1858
+ }
1783
1859
  /**
1784
1860
  * Calculate ideal grid boundary based on reference price.
1785
1861
  * Places boundary near reference price with gap spacing in mind.
@@ -1800,8 +1876,7 @@ function calculateIdealBoundary(allSlots, referencePrice, gapSlots) {
1800
1876
  if (!allSlots || allSlots.length === 0)
1801
1877
  return -1;
1802
1878
  if (!Number.isFinite(Number(referencePrice))) {
1803
- const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
1804
- return Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
1879
+ return railCenterIndex(allSlots.length, gapSlots);
1805
1880
  }
1806
1881
  let splitIdx = allSlots.findIndex((s) => s.price >= referencePrice);
1807
1882
  if (splitIdx === -1)
@@ -2219,8 +2294,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2219
2294
  // never a rail-edge fabrication. The next fill batch re-anchors
2220
2295
  // from live prices via Tier 1.
2221
2296
  if (referencePrice === null && Array.isArray(allSlots) && allSlots.length > 0) {
2222
- const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
2223
- const centerIdx = Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
2297
+ const centerIdx = railCenterIndex(allSlots.length, gapSlots);
2224
2298
  const centerPrice = Number(allSlots[centerIdx]?.price);
2225
2299
  if (Number.isFinite(centerPrice))
2226
2300
  referencePrice = centerPrice;
@@ -2247,8 +2321,19 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2247
2321
  // `edgeAnchors` (resolveLiveReserveEdgeAnchorPrice) is the same anchor the
2248
2322
  // placement sites use; without it the classification falls back to the
2249
2323
  // config-bound anchor, which can disagree with the slots actually placed.
2250
- const reserveBuyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null);
2251
- const reserveSellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null);
2324
+ // The window exclusion is the same one every placement picker applies: a
2325
+ // window that reaches the grid edge (e.g. a keep-low window sitting on
2326
+ // the floor) must not let the edge pick land on window members — otherwise
2327
+ // a genuine window fill is treated as a static reserve fill and never
2328
+ // crawls, and the hole is refilled same-side. Unknown geometry
2329
+ // (null boundary) fails open to the previous classification.
2330
+ const windowBoundaryIdx = (currentBoundaryIdx === null || currentBoundaryIdx === undefined)
2331
+ ? newBoundaryIdx
2332
+ : currentBoundaryIdx;
2333
+ const windowBuyIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.BUY, windowBoundaryIdx, gapSlots);
2334
+ const windowSellIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.SELL, windowBoundaryIdx, gapSlots);
2335
+ const reserveBuyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
2336
+ const reserveSellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
2252
2337
  // Pending crawls: fills recorded by earlier batches whose derivation
2253
2338
  // never committed (refused broadcast, P4 abort, or pre-restart loss —
2254
2339
  // the Sep-10 case: 4 fills consumed under a null boundary, crawl lost,
@@ -2376,8 +2461,13 @@ export function consumePendingFillCrawls(manager) {
2376
2461
  // two disagree: the config-bound fallback is null for mode-string/relative
2377
2462
  // bounds, so a restart would rank a stale below-rail slot as a reserve and
2378
2463
  // silently drop a crawl the live run recorded as ordinary market movement.
2379
- const reserveBuyIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.BUY, resolveLiveReserveEdgeAnchorPrice(manager, 'buy'));
2380
- const reserveSellIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.SELL, resolveLiveReserveEdgeAnchorPrice(manager, 'sell'));
2464
+ // The window exclusion must match placement too (same source as the count
2465
+ // fix) — a window over the reserve edge must not be read as a reserve, or
2466
+ // its owed crawl is dropped instead of applied.
2467
+ const windowBuyIds = liveWindowIdSet(manager, ORDER_TYPES.BUY);
2468
+ const windowSellIds = liveWindowIdSet(manager, ORDER_TYPES.SELL);
2469
+ const reserveBuyIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.BUY, resolveLiveReserveEdgeAnchorPrice(manager, 'buy'), windowBuyIds);
2470
+ const reserveSellIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.SELL, resolveLiveReserveEdgeAnchorPrice(manager, 'sell'), windowSellIds);
2381
2471
  let netShift = 0;
2382
2472
  let count = 0;
2383
2473
  for (const e of pending) {
@@ -2439,13 +2529,25 @@ export function consumePendingFillCrawls(manager) {
2439
2529
  * Buy reserves pin at the grid floor, sell reserves at the grid ceiling.
2440
2530
  * Non-finite/non-integer/negative values disable (0).
2441
2531
  *
2532
+ * The legacy numeric form (`reserveOrders: n`) is migrated here at read time
2533
+ * to `{ buy: n, sell: 0 }`: the editor seeder rewrites the persisted JSON, but
2534
+ * a hand-edited bots.json that bypassed the editor must not have its reserve
2535
+ * count silently read as 0.
2536
+ *
2442
2537
  * @param {Object} config - Bot configuration
2443
2538
  * @param {string} side - 'buy' or 'sell'
2444
2539
  * @returns {number} Reserve count for the side (>= 0 integer)
2445
2540
  */
2446
2541
  function resolveReserveCount(config, side) {
2447
2542
  const key = side === 'sell' ? 'sell' : 'buy';
2448
- const raw = Number(config?.reserveOrders?.[key] ?? 0);
2543
+ const rawReserve = config?.reserveOrders;
2544
+ if (typeof rawReserve === 'number') {
2545
+ if (side === 'sell')
2546
+ return 0;
2547
+ const n = Math.floor(rawReserve);
2548
+ return Number.isFinite(n) && n >= 0 ? n : 0;
2549
+ }
2550
+ const raw = Number(rawReserve?.[key] ?? 0);
2449
2551
  if (!Number.isInteger(raw) || raw < 0)
2450
2552
  return 0;
2451
2553
  return raw;
@@ -2511,41 +2613,47 @@ function reserveEdgeIdSet(allSlots, config, orderType, anchorPrice = null, exclu
2511
2613
  return ids;
2512
2614
  }
2513
2615
  /**
2514
- * Window member ids for one side, mirroring the window every placement
2515
- * picker excludes from its reserve pick: in-rail slots of the side (geometry
2516
- * via resolveGapBand/isSlotInRail — the same source the reconcile pickers
2517
- * use), ordered closest to market first (buys: highest price first; sells:
2518
- * lowest first), sliced to the configured activeOrders count. The slice runs
2519
- * over the FULL master rail, not just live orders — window membership is
2520
- * geometric (a virtual hole inside the window still blocks the reserve pick
2521
- * there), so live-only slices would misclassify live reserves as window
2522
- * members whenever the window itself is under-filled.
2616
+ * Window member ids for one side from an explicit slot list and geometry.
2523
2617
  *
2524
- * Returns null when the boundary geometry is unknown: the pickers cannot
2525
- * place reserves without it either, so callers fail open (no exclusion)
2526
- * and keep their previous classification instead of guessing.
2618
+ * Mirror of the window every placement picker excludes from its reserve
2619
+ * pick: in-rail slots of the side (geometry via isSlotInRail), ordered
2620
+ * closest to market first (buys: highest price first; sells: lowest first),
2621
+ * sliced to the configured activeOrders count. The slice runs over the FULL
2622
+ * rail, not just live orders — window membership is geometric (a virtual
2623
+ * hole inside the window still blocks the reserve pick there), so live-only
2624
+ * slices would misclassify live reserves as window members whenever the
2625
+ * window itself is under-filled.
2527
2626
  *
2528
- * @param {any} manager - OrderManager (orders Map, config, boundaryIdx)
2529
- * @param {string} orderType - ORDER_TYPES.BUY or ORDER_TYPES.SELL
2627
+ * Returns null when the boundary geometry is unknown (null boundary): the
2628
+ * pickers cannot place reserves without it either, so callers fail open
2629
+ * (no exclusion) and keep their previous classification instead of guessing.
2630
+ *
2631
+ * @param {Array<Object>} allSlots - Slots (master grid or clone)
2632
+ * @param {Object} config - Bot configuration (activeOrders count source)
2633
+ * @param {string} orderType - ORDER_TYPES.BUY or SELL
2634
+ * @param {number|null|undefined} boundaryIdx - Boundary the rail is derived from
2635
+ * @param {number} gapSlots - Gap band size
2530
2636
  * @returns {Set<string>|null} Window slot ids, or null when geometry unknown
2531
2637
  */
2532
- function liveWindowIdSet(manager, orderType) {
2638
+ function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots) {
2533
2639
  try {
2534
2640
  const isSell = orderType === ORDER_TYPES.SELL;
2535
2641
  const type = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
2536
2642
  const side = isSell ? 'sell' : 'buy';
2537
- const count = Math.max(0, Math.floor(Number(manager?.config?.activeOrders?.[side])) || 0);
2538
- if (!(count > 0) || !manager?.orders || typeof manager.orders.values !== 'function')
2643
+ const count = Math.max(0, Math.floor(Number(config?.activeOrders?.[side])) || 0);
2644
+ if (!(count > 0))
2539
2645
  return new Set();
2540
- const resolved = MathUtils.resolveGapBand(manager);
2541
- if (resolved?.boundaryIdx == null || resolved?.sellStartIdx == null)
2646
+ if (!Array.isArray(allSlots))
2647
+ return new Set();
2648
+ if (boundaryIdx === null || boundaryIdx === undefined || !Number.isFinite(Number(boundaryIdx)))
2542
2649
  return null;
2543
- const inRail = (o) => MathUtils.isSlotInRail(resolved.boundaryIdx, resolved.gapSlots, type, o);
2650
+ const gap = Number.isFinite(Number(gapSlots)) ? Number(gapSlots) : 0;
2651
+ const inRail = (o) => MathUtils.isSlotInRail(boundaryIdx, gap, type, o);
2544
2652
  // Same type filter as the window pickers with known geometry: the
2545
2653
  // side's concrete type plus SPREAD placeholders (normalized empties
2546
2654
  // sitting in this side's rail).
2547
2655
  const typeFilter = (o) => o && o.id != null && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD);
2548
- const ids = Array.from(manager.orders.values())
2656
+ const ids = allSlots
2549
2657
  .filter(typeFilter)
2550
2658
  .filter(inRail)
2551
2659
  .sort((a, b) => isSell ? Number(a.price) - Number(b.price) : Number(b.price) - Number(a.price))
@@ -2557,6 +2665,28 @@ function liveWindowIdSet(manager, orderType) {
2557
2665
  return null;
2558
2666
  }
2559
2667
  }
2668
+ /**
2669
+ * Window member ids for one side from the live manager (see
2670
+ * windowIdSetFromSlots). Delegates so the manager and explicit-geometry
2671
+ * callers share one definition.
2672
+ *
2673
+ * @param {any} manager - OrderManager (orders Map, config, boundaryIdx)
2674
+ * @param {string} orderType - ORDER_TYPES.BUY or ORDER_TYPES.SELL
2675
+ * @returns {Set<string>|null} Window slot ids, or null when geometry unknown
2676
+ */
2677
+ function liveWindowIdSet(manager, orderType) {
2678
+ try {
2679
+ if (!manager?.orders || typeof manager.orders.values !== 'function')
2680
+ return new Set();
2681
+ const resolved = MathUtils.resolveGapBand(manager);
2682
+ if (resolved?.boundaryIdx == null || resolved?.sellStartIdx == null)
2683
+ return null;
2684
+ return windowIdSetFromSlots(Array.from(manager.orders.values()), manager.config, orderType, resolved.boundaryIdx, resolved.gapSlots);
2685
+ }
2686
+ catch {
2687
+ return null;
2688
+ }
2689
+ }
2560
2690
  /**
2561
2691
  * Refill-slot wire for the COW boundary hold (single source for both plan
2562
2692
  * producers: the fill-driven COW engine and the divergence fold).
@@ -2585,10 +2715,13 @@ function liveWindowIdSet(manager, orderType) {
2585
2715
  * @param {Iterable<Object>} [options.slots] - Master slots (reserve classification)
2586
2716
  * @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
2587
2717
  * edge anchors (same pair the strategy classifies reserve fills against)
2718
+ * @param {any} [options.manager] - OrderManager for the window exclusion (same
2719
+ * set the placement pickers exclude); omit to fall back to the previous
2720
+ * exclusion-free classification (fail-open)
2588
2721
  * @returns {string[]} Refill slot ids (CREATE ids minus reserve edge ids)
2589
2722
  */
2590
2723
  function collectRefillSlotIds(actions, options = {}) {
2591
- const { config = null, slots = null, edgeAnchors = null } = options;
2724
+ const { config = null, slots = null, edgeAnchors = null, manager = null } = options;
2592
2725
  const out = [];
2593
2726
  if (!Array.isArray(actions))
2594
2727
  return out;
@@ -2608,8 +2741,15 @@ function collectRefillSlotIds(actions, options = {}) {
2608
2741
  : (typeof slots?.values === 'function'
2609
2742
  ? Array.from(slots.values())
2610
2743
  : Array.from(slots));
2611
- const buyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null);
2612
- const sellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null);
2744
+ // Window exclusion keeps classification in agreement with the
2745
+ // placement pickers: a window reaching the grid edge must not have
2746
+ // its window hole-CREATEs dropped from the wire as if they were
2747
+ // reserves, or a guard-skipped window refill would no longer pin
2748
+ // the committed boundary (stranding the hole it failed to fill).
2749
+ const windowBuyIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.BUY) : null;
2750
+ const windowSellIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.SELL) : null;
2751
+ const buyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
2752
+ const sellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
2613
2753
  if (buyIds || sellIds)
2614
2754
  reserveIds = new Set([...(buyIds ?? []), ...(sellIds ?? [])]);
2615
2755
  }
@@ -2635,8 +2775,10 @@ function collectRefillSlotIds(actions, options = {}) {
2635
2775
  *
2636
2776
  * Known limit: this is the statically resolved config bound, not the
2637
2777
  * gridPrice/AMA-referenced live rail bound. Placement call sites should use
2638
- * resolveLiveReserveEdgeAnchorPrice(manager, side), which prefers the live
2639
- * grid geometry and only falls back to this function.
2778
+ * resolveLiveReserveEdgeAnchorPrice(manager, side), which prefers the genesis
2779
+ * ladder extreme and returns null when there is no usable ladder. Callers that
2780
+ * need a fallback (e.g. reserveEdgeIdSet) still resolve this config bound when
2781
+ * the live anchor is null; the live resolver itself no longer computes it.
2640
2782
  *
2641
2783
  * @param {Object} config - Bot configuration
2642
2784
  * @param {string} side - 'buy' or 'sell'
@@ -2660,72 +2802,38 @@ function resolveReserveEdgeAnchorPrice(config, side) {
2660
2802
  *
2661
2803
  * The anchor must come from the geometry the bot is actually trading, never
2662
2804
  * from a config value that can be a mode string ("pool"/"book"), a relative
2663
- * multiplier, or a stale bound. Tiers, strongest first:
2664
- *
2665
- * 1. Genesis ladder extreme — `_genesis.priceLevels` is the exact ladder the
2666
- * loaded grid was built from: sorted ascending, index-aligned with
2667
- * `slot-<idx>` (assertSlotPriceInvariant), refreshed by initializeGrid,
2668
- * persisted with the grid, and unaffected by the raw-profile re-merge a
2669
- * resync performs. Slot 0 is always on the buy rail and the last level
2670
- * always on the sell rail, so the ladder extremes are the live rail
2671
- * bounds.
2672
- * 2. Live in-rail extreme of the master grid — geometry-only rail
2673
- * membership (resolveGapBand + isSlotInRail, the same predicate the
2674
- * selectors use) for snapshots without a genesis.
2675
- * 3. Config bound (resolveReserveEdgeAnchorPrice) — the previous behavior,
2676
- * kept as the last resolved tier.
2677
- * 4. null — callers keep the legacy rank-based selection.
2678
- *
2679
- * @param {Object} manager - OrderManager (needs _genesis, orders, boundary)
2805
+ * multiplier, or a stale bound, and never from the live slot prices of a grid
2806
+ * whose levels have no authority. The only source is the genesis ladder:
2807
+ * `_genesis.priceLevels` is the exact ladder the loaded grid was built from —
2808
+ * sorted ascending, index-aligned with `slot-<idx>` (assertSlotPriceInvariant),
2809
+ * refreshed by initializeGrid, persisted with the grid, and unaffected by the
2810
+ * raw-profile re-merge a resync performs. Slot 0 is always on the buy rail and
2811
+ * the last level always on the sell rail, so the ladder extremes are the live
2812
+ * rail bounds.
2813
+ *
2814
+ * A manager with no usable ladder returns null. That is the undefined-grid state
2815
+ * (INV-GRID-004), which the load and sync gates refuse, not a degraded mode to
2816
+ * paper over. The former tiers — the live in-rail slot extreme and the resolved
2817
+ * config bound — are gone with the legacy matcher they only existed to cover;
2818
+ * any config-bound fallback is now resolved by the individual consumer that
2819
+ * wants one (see reserveEdgeIdSet), not by this live-edge resolver. The fault
2820
+ * itself is reported
2821
+ * once per grid generation by the sync-entry gate; this resolver stays silent
2822
+ * because it is called from per-fill and per-placement paths.
2823
+ *
2824
+ * @param {Object} manager - OrderManager (needs _genesis)
2680
2825
  * @param {string} side - 'buy' or 'sell'
2681
2826
  * @returns {number|null} Finite anchor price, or null
2682
2827
  */
2683
2828
  function resolveLiveReserveEdgeAnchorPrice(manager, side) {
2684
2829
  const isSell = side === 'sell';
2685
- // Tier 1 — the ladder the loaded grid was generated from.
2686
2830
  const levels = manager?._genesis?.priceLevels;
2687
2831
  if (Array.isArray(levels) && levels.length > 0) {
2688
2832
  const extreme = Number(isSell ? levels[levels.length - 1] : levels[0]);
2689
2833
  if (Number.isFinite(extreme) && extreme > 0)
2690
2834
  return extreme;
2691
2835
  }
2692
- // Tier 2 — live in-rail extreme of the master grid.
2693
- const sideType = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
2694
- if (manager?.orders && typeof manager.orders.values === 'function') {
2695
- let best = null;
2696
- try {
2697
- const band = MathUtils.resolveGapBand(manager);
2698
- for (const entry of manager.orders.values()) {
2699
- if (!entry || typeof entry !== 'object')
2700
- continue;
2701
- if (!('type' in entry) || !('price' in entry))
2702
- continue;
2703
- if (entry.type !== sideType)
2704
- continue;
2705
- // Shelf/manual ids (e.g. fork-kept deep-* orders below the rail)
2706
- // are never rail geometry: isSlotInRail is fail-open for
2707
- // unparseable ids, so without this gate a cheap shelf order drags
2708
- // the anchor down to itself and then qualifies as the reserve edge
2709
- // (issue #27 follow-up). No-op upstream (grids only mint slot-N).
2710
- if (parseSlotIndex(entry?.id) === null)
2711
- continue;
2712
- if (!MathUtils.isSlotInRail(band.boundaryIdx, band.gapSlots, sideType, entry))
2713
- continue;
2714
- const price = Number(entry.price);
2715
- if (!Number.isFinite(price) || price <= 0)
2716
- continue;
2717
- if (best === null || (isSell ? price > best : price < best))
2718
- best = price;
2719
- }
2720
- }
2721
- catch (e) {
2722
- best = null;
2723
- }
2724
- if (best !== null)
2725
- return best;
2726
- }
2727
- // Tier 3 — configured/resolved bound.
2728
- return resolveReserveEdgeAnchorPrice(manager?.config, side);
2836
+ return null;
2729
2837
  }
2730
2838
  /**
2731
2839
  * Shared anchored edge comparator for reserve selection (single source).
@@ -3055,6 +3163,6 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
3055
3163
  const all = new Set([...masterIds, ...createIds]);
3056
3164
  return { masterIds: [...masterIds], createIds: [...createIds], all: [...all] };
3057
3165
  }
3058
- export { parseChainOrder, findMatchingGridOrderByOpenOrder, 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 };
3166
+ 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 };
3059
3167
  export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds };
3060
3168
  //# sourceMappingURL=order.js.map