dexbot 1.6.7 → 1.6.9

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 (626) hide show
  1. package/CHANGELOG.md +73 -1
  2. package/README.md +3 -3
  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 +55 -16
  17. package/dist/market_adapter/core/market_adapter_service.d.ts +81 -1
  18. package/dist/market_adapter/core/market_adapter_service.js +239 -20
  19. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
  20. package/dist/market_adapter/core/signals/hurst_analyzer.js +40 -18
  21. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +26 -2
  22. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +132 -29
  23. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
  24. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
  25. package/dist/market_adapter/core/strategies/regime_gate.d.ts +61 -3
  26. package/dist/market_adapter/core/strategies/regime_gate.js +207 -7
  27. package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
  28. package/dist/market_adapter/inputs/window_cache.js +302 -48
  29. package/dist/market_adapter/interval_utils.d.ts +18 -1
  30. package/dist/market_adapter/interval_utils.js +31 -1
  31. package/dist/market_adapter/market_adapter.d.ts +158 -2
  32. package/dist/market_adapter/market_adapter.js +399 -65
  33. package/dist/market_adapter/test_helpers.d.ts +2 -2
  34. package/dist/market_adapter/test_helpers.js +2 -2
  35. package/dist/market_adapter/utils/file_json_cache.d.ts +29 -0
  36. package/dist/market_adapter/utils/file_json_cache.js +106 -0
  37. package/dist/modules/account_bots.js +10 -0
  38. package/dist/modules/account_orders.d.ts +24 -2
  39. package/dist/modules/account_orders.js +41 -4
  40. package/dist/modules/bot_settings.js +10 -1
  41. package/dist/modules/config.d.ts +7 -0
  42. package/dist/modules/config.js +2 -0
  43. package/dist/modules/constants.d.ts +16 -4
  44. package/dist/modules/constants.js +144 -38
  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 +4 -87
  49. package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
  50. package/dist/modules/dexbot_maintenance_runtime.js +59 -11
  51. package/dist/modules/dexbot_startup_runtime.js +73 -20
  52. package/dist/modules/dexbot_state_recovery.d.ts +6 -0
  53. package/dist/modules/dexbot_state_recovery.js +21 -0
  54. package/dist/modules/order/async_lock.d.ts +8 -0
  55. package/dist/modules/order/async_lock.js +15 -0
  56. package/dist/modules/order/genesis_policy.d.ts +162 -0
  57. package/dist/modules/order/genesis_policy.js +267 -0
  58. package/dist/modules/order/grid.js +172 -160
  59. package/dist/modules/order/grid_reconcile.d.ts +9 -0
  60. package/dist/modules/order/grid_reconcile.js +13 -4
  61. package/dist/modules/order/grid_reconcile_internal.js +2 -2
  62. package/dist/modules/order/manager.d.ts +4 -0
  63. package/dist/modules/order/manager.js +14 -1
  64. package/dist/modules/order/sync_engine.d.ts +19 -0
  65. package/dist/modules/order/sync_engine.js +284 -344
  66. package/dist/modules/order/utils/math.d.ts +22 -1
  67. package/dist/modules/order/utils/math.js +64 -1
  68. package/dist/modules/order/utils/order.d.ts +43 -58
  69. package/dist/modules/order/utils/order.js +220 -197
  70. package/dist/modules/order/utils/system.js +8 -1
  71. package/dist/modules/paths.d.ts +1 -0
  72. package/dist/modules/paths.js +1 -0
  73. package/dist/modules/version_notice.d.ts +311 -0
  74. package/dist/modules/version_notice.js +709 -0
  75. package/dist/pm2.js +16 -0
  76. package/dist/unlock.js +28 -0
  77. package/docs/BITSHARES_ONBOARDING.md +8 -1
  78. package/docs/COW_INVARIANTS.md +3 -2
  79. package/docs/DEXBOT_COMPARISON.md +4 -4
  80. package/docs/EVOLUTION.md +22 -20
  81. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  82. package/docs/GRID_PRICE_INVARIANT.md +149 -31
  83. package/docs/GRID_RECALCULATION.md +18 -2
  84. package/docs/README.md +3 -1
  85. package/docs/WORKFLOW.md +16 -5
  86. package/market_adapter/README.md +29 -1
  87. package/modules/README.md +18 -1
  88. package/package.json +13 -5
  89. package/scripts/README.md +28 -2
  90. package/scripts/clear-all.sh +13 -4
  91. package/scripts/clear-logs.sh +13 -4
  92. package/scripts/clear-market-adapter.sh +6 -0
  93. package/scripts/clear-orders.sh +5 -0
  94. package/scripts/lib/dexbot-paths.sh +108 -0
  95. package/tests/README.md +11 -3
  96. package/analysis/account_resolver.ts +0 -161
  97. package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
  98. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
  99. package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
  100. package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
  101. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
  102. package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
  103. package/analysis/analyze_dynamic_weight.ts +0 -243
  104. package/analysis/analyze_kalman.ts +0 -157
  105. package/analysis/analyze_regime.ts +0 -158
  106. package/analysis/analyze_regime_windows.ts +0 -470
  107. package/analysis/analyze_risk_profile.ts +0 -199
  108. package/analysis/analyze_trade_heatmap.ts +0 -362
  109. package/analysis/analyze_volatility.ts +0 -182
  110. package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
  111. package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
  112. package/analysis/bot_fitting/shared_utils.ts +0 -52
  113. package/analysis/bot_key_utils.ts +0 -426
  114. package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
  115. package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
  116. package/analysis/chain_pool.ts +0 -47
  117. package/analysis/chart_css.ts +0 -62
  118. package/analysis/chart_ui.ts +0 -105
  119. package/analysis/chart_utils.ts +0 -210
  120. package/analysis/fills_source.ts +0 -228
  121. package/analysis/grid_correction_check.ts +0 -786
  122. package/analysis/math_utils.ts +0 -53
  123. package/analysis/price_sources.ts +0 -136
  124. package/analysis/resolve_bot_accounts.ts +0 -199
  125. package/analysis/resolve_source.ts +0 -99
  126. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
  127. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
  128. package/analysis/trade_profitability.ts +0 -1335
  129. package/analysis/tradingview/analyze_tradingview.ts +0 -280
  130. package/analysis/tradingview/h-bts_tradingview.html +0 -1570
  131. package/analysis/tradingview/t-bts_tradingview.html +0 -1570
  132. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
  133. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
  134. package/analysis/trend_detection/hurst_analyzer.ts +0 -7
  135. package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
  136. package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
  137. package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
  138. package/analysis/trend_detection/package.json +0 -23
  139. package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
  140. package/analysis/trend_detection/regime_chart_generator.ts +0 -338
  141. package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
  142. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
  143. package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
  144. package/analysis/tsconfig.json +0 -29
  145. package/claw/tests/package.json +0 -3
  146. package/claw/tests/test_claw_bridge.ts +0 -570
  147. package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
  148. package/claw/tests/test_claw_chain_layer.ts +0 -739
  149. package/claw/tests/test_claw_data_flow.ts +0 -525
  150. package/claw/tests/test_claw_domain_logic.ts +0 -471
  151. package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
  152. package/claw/tests/test_claw_mcp_transport.ts +0 -243
  153. package/claw/tests/test_claw_regressions.ts +0 -711
  154. package/claw/tests/test_claw_skill_generation.ts +0 -103
  155. package/claw/tests/test_claw_state_store.ts +0 -44
  156. package/claw/tests/test_dexbot_profiles.ts +0 -654
  157. package/claw/tests/test_memu_bridge.ts +0 -189
  158. package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
  159. package/claw/tests/test_position_health.ts +0 -343
  160. package/claw/tests/test_position_manager.ts +0 -429
  161. package/claw/tests/test_position_manager_watch_health.ts +0 -100
  162. package/claw/tests/test_short_mpa_strategy.ts +0 -232
  163. package/dist/analysis/account_resolver.d.ts.map +0 -1
  164. package/dist/analysis/account_resolver.js.map +0 -1
  165. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  166. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  167. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  168. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  169. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  170. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  171. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  172. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  173. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  174. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  175. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  176. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  177. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  178. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  179. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  180. package/dist/analysis/analyze_kalman.js.map +0 -1
  181. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  182. package/dist/analysis/analyze_regime.js.map +0 -1
  183. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  184. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  185. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  186. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  187. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  188. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  189. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  190. package/dist/analysis/analyze_volatility.js.map +0 -1
  191. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  192. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  193. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  194. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  195. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  196. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  197. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  198. package/dist/analysis/bot_key_utils.js.map +0 -1
  199. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  200. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  201. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  202. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  203. package/dist/analysis/chain_pool.d.ts.map +0 -1
  204. package/dist/analysis/chain_pool.js.map +0 -1
  205. package/dist/analysis/chart_css.d.ts.map +0 -1
  206. package/dist/analysis/chart_css.js.map +0 -1
  207. package/dist/analysis/chart_ui.d.ts.map +0 -1
  208. package/dist/analysis/chart_ui.js.map +0 -1
  209. package/dist/analysis/chart_utils.d.ts.map +0 -1
  210. package/dist/analysis/chart_utils.js.map +0 -1
  211. package/dist/analysis/fills_source.d.ts.map +0 -1
  212. package/dist/analysis/fills_source.js.map +0 -1
  213. package/dist/analysis/grid_correction_check.d.ts.map +0 -1
  214. package/dist/analysis/grid_correction_check.js.map +0 -1
  215. package/dist/analysis/math_utils.d.ts.map +0 -1
  216. package/dist/analysis/math_utils.js.map +0 -1
  217. package/dist/analysis/price_sources.d.ts.map +0 -1
  218. package/dist/analysis/price_sources.js.map +0 -1
  219. package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
  220. package/dist/analysis/resolve_bot_accounts.js.map +0 -1
  221. package/dist/analysis/resolve_source.d.ts.map +0 -1
  222. package/dist/analysis/resolve_source.js.map +0 -1
  223. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  224. package/dist/analysis/trade_profitability.js.map +0 -1
  225. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  226. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  227. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
  228. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
  229. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  230. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  231. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  232. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  233. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  234. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  235. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  236. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  237. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  238. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  239. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  240. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  241. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  242. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  243. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  244. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  245. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
  246. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  247. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  248. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  249. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
  250. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  251. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  252. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
  253. package/dist/bot.d.ts.map +0 -1
  254. package/dist/bot.js.map +0 -1
  255. package/dist/credential-daemon.d.ts.map +0 -1
  256. package/dist/credential-daemon.js.map +0 -1
  257. package/dist/dexbot.d.ts.map +0 -1
  258. package/dist/dexbot.js.map +0 -1
  259. package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
  260. package/dist/market_adapter/ama_signal_runner.js.map +0 -1
  261. package/dist/market_adapter/candle_utils.d.ts.map +0 -1
  262. package/dist/market_adapter/candle_utils.js.map +0 -1
  263. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
  264. package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
  265. package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
  266. package/dist/market_adapter/core/config_normalizers.js.map +0 -1
  267. package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
  268. package/dist/market_adapter/core/kibana_candles.js.map +0 -1
  269. package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
  270. package/dist/market_adapter/core/kibana_client.js.map +0 -1
  271. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
  272. package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
  273. package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
  274. package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
  275. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
  276. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
  277. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
  278. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
  279. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
  280. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
  281. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
  282. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
  283. package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
  284. package/dist/market_adapter/core/strategies/ama.js.map +0 -1
  285. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
  286. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
  287. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
  288. package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
  289. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
  290. package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
  291. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
  292. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
  293. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
  294. package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
  295. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
  296. package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
  297. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
  298. package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
  299. package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
  300. package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
  301. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
  302. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
  303. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
  304. package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
  305. package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
  306. package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
  307. package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
  308. package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
  309. package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
  310. package/dist/market_adapter/inputs/window_cache.js.map +0 -1
  311. package/dist/market_adapter/interval_utils.d.ts.map +0 -1
  312. package/dist/market_adapter/interval_utils.js.map +0 -1
  313. package/dist/market_adapter/log_format.d.ts.map +0 -1
  314. package/dist/market_adapter/log_format.js.map +0 -1
  315. package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
  316. package/dist/market_adapter/lp_chart_core.js.map +0 -1
  317. package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
  318. package/dist/market_adapter/lp_chart_runner.js.map +0 -1
  319. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
  320. package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
  321. package/dist/market_adapter/market_adapter.d.ts.map +0 -1
  322. package/dist/market_adapter/market_adapter.js.map +0 -1
  323. package/dist/market_adapter/test_helpers.d.ts.map +0 -1
  324. package/dist/market_adapter/test_helpers.js.map +0 -1
  325. package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
  326. package/dist/market_adapter/utils/adapter_client.js.map +0 -1
  327. package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
  328. package/dist/market_adapter/utils/atomic_write.js.map +0 -1
  329. package/dist/market_adapter/utils/chain.d.ts.map +0 -1
  330. package/dist/market_adapter/utils/chain.js.map +0 -1
  331. package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
  332. package/dist/market_adapter/utils/data_discovery.js.map +0 -1
  333. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
  334. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
  335. package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
  336. package/dist/market_adapter/utils/file_lock.js.map +0 -1
  337. package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
  338. package/dist/market_adapter/utils/native_history.js.map +0 -1
  339. package/dist/modules/account_bots.d.ts.map +0 -1
  340. package/dist/modules/account_bots.js.map +0 -1
  341. package/dist/modules/account_orders.d.ts.map +0 -1
  342. package/dist/modules/account_orders.js.map +0 -1
  343. package/dist/modules/authority_resolver.d.ts.map +0 -1
  344. package/dist/modules/authority_resolver.js.map +0 -1
  345. package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
  346. package/dist/modules/bitshares-native/chain_client.js.map +0 -1
  347. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
  348. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
  349. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
  350. package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
  351. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
  352. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
  353. package/dist/modules/bitshares-native/index.d.ts.map +0 -1
  354. package/dist/modules/bitshares-native/index.js.map +0 -1
  355. package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
  356. package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
  357. package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
  358. package/dist/modules/bitshares-native/resolvers.js.map +0 -1
  359. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
  360. package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
  361. package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
  362. package/dist/modules/bitshares-native/serial/index.js.map +0 -1
  363. package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
  364. package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
  365. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
  366. package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
  367. package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
  368. package/dist/modules/bitshares-native/serial/types.js.map +0 -1
  369. package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
  370. package/dist/modules/bitshares-native/signing_client.js.map +0 -1
  371. package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
  372. package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
  373. package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
  374. package/dist/modules/bitshares-native/transport.js.map +0 -1
  375. package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
  376. package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
  377. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
  378. package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
  379. package/dist/modules/bitshares_client.d.ts.map +0 -1
  380. package/dist/modules/bitshares_client.js.map +0 -1
  381. package/dist/modules/bot_defaults.d.ts.map +0 -1
  382. package/dist/modules/bot_defaults.js.map +0 -1
  383. package/dist/modules/bot_settings.d.ts.map +0 -1
  384. package/dist/modules/bot_settings.js.map +0 -1
  385. package/dist/modules/bots_file_lock.d.ts.map +0 -1
  386. package/dist/modules/bots_file_lock.js.map +0 -1
  387. package/dist/modules/broadcast_failure.d.ts.map +0 -1
  388. package/dist/modules/broadcast_failure.js.map +0 -1
  389. package/dist/modules/chain_keys.d.ts.map +0 -1
  390. package/dist/modules/chain_keys.js.map +0 -1
  391. package/dist/modules/chain_orders.d.ts.map +0 -1
  392. package/dist/modules/chain_orders.js.map +0 -1
  393. package/dist/modules/cli_colors.d.ts.map +0 -1
  394. package/dist/modules/cli_colors.js.map +0 -1
  395. package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
  396. package/dist/modules/cli_start_onboarding.js.map +0 -1
  397. package/dist/modules/cli_start_output.d.ts.map +0 -1
  398. package/dist/modules/cli_start_output.js.map +0 -1
  399. package/dist/modules/config.d.ts.map +0 -1
  400. package/dist/modules/config.js.map +0 -1
  401. package/dist/modules/constants.d.ts.map +0 -1
  402. package/dist/modules/constants.js.map +0 -1
  403. package/dist/modules/cr_planner.d.ts.map +0 -1
  404. package/dist/modules/cr_planner.js.map +0 -1
  405. package/dist/modules/credential_policy.d.ts.map +0 -1
  406. package/dist/modules/credential_policy.js.map +0 -1
  407. package/dist/modules/credential_runtime.d.ts.map +0 -1
  408. package/dist/modules/credential_runtime.js.map +0 -1
  409. package/dist/modules/credential_session_cache.d.ts.map +0 -1
  410. package/dist/modules/credential_session_cache.js.map +0 -1
  411. package/dist/modules/credit_pricing.d.ts.map +0 -1
  412. package/dist/modules/credit_pricing.js.map +0 -1
  413. package/dist/modules/credit_runtime.d.ts.map +0 -1
  414. package/dist/modules/credit_runtime.js.map +0 -1
  415. package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
  416. package/dist/modules/crypto/browser_provider.js.map +0 -1
  417. package/dist/modules/crypto/index.d.ts.map +0 -1
  418. package/dist/modules/crypto/index.js.map +0 -1
  419. package/dist/modules/crypto/node_provider.d.ts.map +0 -1
  420. package/dist/modules/crypto/node_provider.js.map +0 -1
  421. package/dist/modules/crypto/provider.d.ts.map +0 -1
  422. package/dist/modules/crypto/provider.js.map +0 -1
  423. package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
  424. package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
  425. package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
  426. package/dist/modules/crypto/pure_scrypt.js.map +0 -1
  427. package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
  428. package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
  429. package/dist/modules/crypto/sync.d.ts.map +0 -1
  430. package/dist/modules/crypto/sync.js.map +0 -1
  431. package/dist/modules/daemon_node_health.d.ts.map +0 -1
  432. package/dist/modules/daemon_node_health.js.map +0 -1
  433. package/dist/modules/dexbot_class.d.ts.map +0 -1
  434. package/dist/modules/dexbot_class.js.map +0 -1
  435. package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
  436. package/dist/modules/dexbot_cow_runtime.js.map +0 -1
  437. package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
  438. package/dist/modules/dexbot_credential_client.js.map +0 -1
  439. package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
  440. package/dist/modules/dexbot_fill_runtime.js.map +0 -1
  441. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
  442. package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
  443. package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
  444. package/dist/modules/dexbot_startup_runtime.js.map +0 -1
  445. package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
  446. package/dist/modules/dexbot_state_recovery.js.map +0 -1
  447. package/dist/modules/env.d.ts.map +0 -1
  448. package/dist/modules/env.js.map +0 -1
  449. package/dist/modules/fund_registry.d.ts.map +0 -1
  450. package/dist/modules/fund_registry.js.map +0 -1
  451. package/dist/modules/general_settings.d.ts.map +0 -1
  452. package/dist/modules/general_settings.js.map +0 -1
  453. package/dist/modules/graceful_shutdown.d.ts.map +0 -1
  454. package/dist/modules/graceful_shutdown.js.map +0 -1
  455. package/dist/modules/grid_price_source.d.ts.map +0 -1
  456. package/dist/modules/grid_price_source.js.map +0 -1
  457. package/dist/modules/key_store.d.ts.map +0 -1
  458. package/dist/modules/key_store.js.map +0 -1
  459. package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
  460. package/dist/modules/launcher/adapter_requirement.js.map +0 -1
  461. package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
  462. package/dist/modules/launcher/bot_supervisor.js.map +0 -1
  463. package/dist/modules/launcher/child_env.d.ts.map +0 -1
  464. package/dist/modules/launcher/child_env.js.map +0 -1
  465. package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
  466. package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
  467. package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
  468. package/dist/modules/launcher/credential_daemon.js.map +0 -1
  469. package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
  470. package/dist/modules/launcher/credential_secret.js.map +0 -1
  471. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
  472. package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
  473. package/dist/modules/launcher/headless_password.d.ts.map +0 -1
  474. package/dist/modules/launcher/headless_password.js.map +0 -1
  475. package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
  476. package/dist/modules/launcher/launch_modes.js.map +0 -1
  477. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
  478. package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
  479. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
  480. package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
  481. package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
  482. package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
  483. package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
  484. package/dist/modules/launcher/runtime_entry.js.map +0 -1
  485. package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
  486. package/dist/modules/launcher/status_reporting.js.map +0 -1
  487. package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
  488. package/dist/modules/launcher/supervisor_control.js.map +0 -1
  489. package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
  490. package/dist/modules/market_adapter_whitelist.js.map +0 -1
  491. package/dist/modules/node_connect_policy.d.ts.map +0 -1
  492. package/dist/modules/node_connect_policy.js.map +0 -1
  493. package/dist/modules/node_failure_ledger.d.ts.map +0 -1
  494. package/dist/modules/node_failure_ledger.js.map +0 -1
  495. package/dist/modules/node_health_cache.d.ts.map +0 -1
  496. package/dist/modules/node_health_cache.js.map +0 -1
  497. package/dist/modules/node_manager.d.ts.map +0 -1
  498. package/dist/modules/node_manager.js.map +0 -1
  499. package/dist/modules/order/accounting.d.ts.map +0 -1
  500. package/dist/modules/order/accounting.js.map +0 -1
  501. package/dist/modules/order/async_lock.d.ts.map +0 -1
  502. package/dist/modules/order/async_lock.js.map +0 -1
  503. package/dist/modules/order/export.d.ts.map +0 -1
  504. package/dist/modules/order/export.js.map +0 -1
  505. package/dist/modules/order/format.d.ts.map +0 -1
  506. package/dist/modules/order/format.js.map +0 -1
  507. package/dist/modules/order/grid.d.ts.map +0 -1
  508. package/dist/modules/order/grid.js.map +0 -1
  509. package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
  510. package/dist/modules/order/grid_reconcile.js.map +0 -1
  511. package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
  512. package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
  513. package/dist/modules/order/index.d.ts.map +0 -1
  514. package/dist/modules/order/index.js.map +0 -1
  515. package/dist/modules/order/logger.d.ts.map +0 -1
  516. package/dist/modules/order/logger.js.map +0 -1
  517. package/dist/modules/order/logger_state.d.ts.map +0 -1
  518. package/dist/modules/order/logger_state.js.map +0 -1
  519. package/dist/modules/order/manager.d.ts.map +0 -1
  520. package/dist/modules/order/manager.js.map +0 -1
  521. package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
  522. package/dist/modules/order/processed_fill_store.js.map +0 -1
  523. package/dist/modules/order/strategy.d.ts.map +0 -1
  524. package/dist/modules/order/strategy.js.map +0 -1
  525. package/dist/modules/order/sync_engine.d.ts.map +0 -1
  526. package/dist/modules/order/sync_engine.js.map +0 -1
  527. package/dist/modules/order/utils/math.d.ts.map +0 -1
  528. package/dist/modules/order/utils/math.js.map +0 -1
  529. package/dist/modules/order/utils/order.d.ts.map +0 -1
  530. package/dist/modules/order/utils/order.js.map +0 -1
  531. package/dist/modules/order/utils/slot.d.ts.map +0 -1
  532. package/dist/modules/order/utils/slot.js.map +0 -1
  533. package/dist/modules/order/utils/system.d.ts.map +0 -1
  534. package/dist/modules/order/utils/system.js.map +0 -1
  535. package/dist/modules/order/utils/timeout.d.ts.map +0 -1
  536. package/dist/modules/order/utils/timeout.js.map +0 -1
  537. package/dist/modules/order/utils/validate.d.ts.map +0 -1
  538. package/dist/modules/order/utils/validate.js.map +0 -1
  539. package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
  540. package/dist/modules/order/utils/withPoolRef.js.map +0 -1
  541. package/dist/modules/order/working_grid.d.ts.map +0 -1
  542. package/dist/modules/order/working_grid.js.map +0 -1
  543. package/dist/modules/path_api.d.ts.map +0 -1
  544. package/dist/modules/path_api.js.map +0 -1
  545. package/dist/modules/paths.d.ts.map +0 -1
  546. package/dist/modules/paths.js.map +0 -1
  547. package/dist/modules/process_discovery.d.ts.map +0 -1
  548. package/dist/modules/process_discovery.js.map +0 -1
  549. package/dist/modules/runtime.d.ts.map +0 -1
  550. package/dist/modules/runtime.js.map +0 -1
  551. package/dist/modules/runtime_settings.d.ts.map +0 -1
  552. package/dist/modules/runtime_settings.js.map +0 -1
  553. package/dist/modules/settings_merge.d.ts.map +0 -1
  554. package/dist/modules/settings_merge.js.map +0 -1
  555. package/dist/modules/socket_json_client.d.ts.map +0 -1
  556. package/dist/modules/socket_json_client.js.map +0 -1
  557. package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
  558. package/dist/modules/storage/browser_adapter.js.map +0 -1
  559. package/dist/modules/storage/index.d.ts.map +0 -1
  560. package/dist/modules/storage/index.js.map +0 -1
  561. package/dist/modules/storage/node_adapter.d.ts.map +0 -1
  562. package/dist/modules/storage/node_adapter.js.map +0 -1
  563. package/dist/modules/storage/types.d.ts.map +0 -1
  564. package/dist/modules/storage/types.js.map +0 -1
  565. package/dist/modules/types.d.ts.map +0 -1
  566. package/dist/modules/types.js.map +0 -1
  567. package/dist/modules/utils/base58check.d.ts.map +0 -1
  568. package/dist/modules/utils/base58check.js.map +0 -1
  569. package/dist/modules/utils/build_dir.d.ts.map +0 -1
  570. package/dist/modules/utils/build_dir.js.map +0 -1
  571. package/dist/modules/utils/chain_logs.d.ts.map +0 -1
  572. package/dist/modules/utils/chain_logs.js.map +0 -1
  573. package/dist/modules/utils/errors.d.ts.map +0 -1
  574. package/dist/modules/utils/errors.js.map +0 -1
  575. package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
  576. package/dist/modules/utils/sanitize_key.js.map +0 -1
  577. package/dist/modules/utils/text_width.d.ts.map +0 -1
  578. package/dist/modules/utils/text_width.js.map +0 -1
  579. package/dist/modules/validate_profiles.d.ts.map +0 -1
  580. package/dist/modules/validate_profiles.js.map +0 -1
  581. package/dist/pm2.d.ts.map +0 -1
  582. package/dist/pm2.js.map +0 -1
  583. package/dist/scripts/analyze-credit.d.ts.map +0 -1
  584. package/dist/scripts/analyze-credit.js.map +0 -1
  585. package/dist/scripts/analyze-git.d.ts.map +0 -1
  586. package/dist/scripts/analyze-git.js.map +0 -1
  587. package/dist/scripts/analyze-orders.d.ts.map +0 -1
  588. package/dist/scripts/analyze-orders.js.map +0 -1
  589. package/dist/scripts/chart_command.d.ts.map +0 -1
  590. package/dist/scripts/chart_command.js.map +0 -1
  591. package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
  592. package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
  593. package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
  594. package/dist/scripts/diagnose-pool-history.js.map +0 -1
  595. package/dist/scripts/divergence-calc.d.ts.map +0 -1
  596. package/dist/scripts/divergence-calc.js.map +0 -1
  597. package/dist/scripts/dw.d.ts.map +0 -1
  598. package/dist/scripts/dw.js.map +0 -1
  599. package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
  600. package/dist/scripts/generate_lp_chart.js.map +0 -1
  601. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
  602. package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
  603. package/dist/scripts/native_release_gates.d.ts.map +0 -1
  604. package/dist/scripts/native_release_gates.js.map +0 -1
  605. package/dist/scripts/print_grid.d.ts.map +0 -1
  606. package/dist/scripts/print_grid.js.map +0 -1
  607. package/dist/scripts/run-tests.d.ts.map +0 -1
  608. package/dist/scripts/run-tests.js.map +0 -1
  609. package/dist/scripts/runner.d.ts.map +0 -1
  610. package/dist/scripts/runner.js.map +0 -1
  611. package/dist/scripts/sync-version.d.ts.map +0 -1
  612. package/dist/scripts/sync-version.js.map +0 -1
  613. package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
  614. package/dist/scripts/test-credit-renewal.js.map +0 -1
  615. package/dist/scripts/tv.d.ts.map +0 -1
  616. package/dist/scripts/tv.js.map +0 -1
  617. package/dist/scripts/update.d.ts.map +0 -1
  618. package/dist/scripts/update.js.map +0 -1
  619. package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
  620. package/dist/scripts/update_dist_freshness.js.map +0 -1
  621. package/dist/scripts/validate_bots.d.ts.map +0 -1
  622. package/dist/scripts/validate_bots.js.map +0 -1
  623. package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
  624. package/dist/scripts/verify-browser-bundle.js.map +0 -1
  625. package/dist/unlock.d.ts.map +0 -1
  626. 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,10 +62,10 @@
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
  * ===============================================================================
@@ -77,6 +76,7 @@ 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.
@@ -844,22 +772,40 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
844
772
  return { corrected, failed, unresolved };
845
773
  }
846
774
  /**
847
- * Resolve the per-cycle sequential price-update budget for
775
+ * Resolve the wall-clock budget for the sequential price-update drain in
848
776
  * correctAllPriceMismatches. Cancel-class entries are never budgeted; only
849
- * the SYNC_DELAY_MS-spaced update loop is bounded so an unbounded backlog
777
+ * the SYNC_DELAY_MS-spaced update loop is bounded, so an unbounded backlog
850
778
  * cannot hold _gridLock (no acquisition timeout) for minutes. Reads the bot
851
- * config override first, then the frozen default. Non-finite falls back to
852
- * the default; a value of 0 intentionally drains no updates this cycle.
779
+ * config override first, then the frozen default. Non-finite/non-positive
780
+ * falls back to the frozen default, then to 4000ms.
853
781
  * @param {any} manager
854
- * @returns {number}
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
855
799
  */
856
- function resolveCorrectionUpdateBudget(manager) {
800
+ function resolveCorrectionMaxUpdates(manager) {
857
801
  const raw = manager?.config?.fillProcessing?.CORRECTION_MAX_UPDATES_PER_CYCLE
858
802
  ?? FILL_PROCESSING?.CORRECTION_MAX_UPDATES_PER_CYCLE;
803
+ if (raw == null)
804
+ return Infinity;
859
805
  const n = Number(raw);
860
806
  if (Number.isFinite(n) && n >= 0)
861
807
  return Math.floor(n);
862
- return 5;
808
+ return Infinity;
863
809
  }
864
810
  /**
865
811
  * Resolve the correction-backlog warn threshold (see
@@ -982,28 +928,50 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
982
928
  // durably and re-drains next cycle.
983
929
  const cancelEntries = liveEntries.filter((c) => c.cancelOnly === true || c.isSurplus === true);
984
930
  const updateEntries = liveEntries.filter((c) => !(c.cancelOnly === true || c.isSurplus === true));
985
- const updateBudget = resolveCorrectionUpdateBudget(manager);
986
- const budgetedUpdates = updateEntries.slice(0, updateBudget);
987
- const deferredUpdates = updateEntries.length - budgetedUpdates.length;
988
931
  const canBatch = cancelEntries.length > 1
989
932
  && typeof accountOrders?.buildCancelOrderOp === 'function'
990
933
  && typeof accountOrders?.executeBatch === 'function';
991
- let serialEntries = [...cancelEntries, ...budgetedUpdates];
934
+ let serialCancels = cancelEntries;
992
935
  if (canBatch) {
993
936
  const batchOutcome = await _batchCancelCorrections(manager, cancelEntries, accountName, privateKey, accountOrders);
994
937
  corrected += batchOutcome.corrected;
995
938
  failed += batchOutcome.failed;
996
- // Unresolved cancels still serialize (they must not be dropped);
997
- // budgeted updates follow.
998
- serialEntries = [...batchOutcome.unresolved, ...budgetedUpdates];
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);
999
950
  }
1000
- 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
+ }
1001
968
  const result = await correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders);
1002
969
  results.push({ ...correctionInfo, result });
1003
970
  if (result && result.success)
1004
971
  corrected++;
1005
972
  else
1006
973
  failed++;
974
+ updatesProcessed++;
1007
975
  await sleep(TIMING.SYNC_DELAY_MS);
1008
976
  }
1009
977
  // Persist master grid mutations from surplus-type-mismatch cancellations.
@@ -1018,7 +986,8 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
1018
986
  ? manager.ordersNeedingPriceCorrection.length
1019
987
  : 0;
1020
988
  manager?.logger?.log?.(`[CORRECTION] Deferred ${deferredUpdates} price update(s) to the next cycle ` +
1021
- `(budget ${updateBudget}/cycle, ${queuedAfter} still queued)`, 'info');
989
+ `(hold budget ${holdBudgetMs}ms${Number.isFinite(maxUpdates) ? `, cap ${maxUpdates}` : ''}, ` +
990
+ `${queuedAfter} still queued)`, 'info');
1022
991
  }
1023
992
  return { corrected, failed, results, staleDropped, deferredUpdates };
1024
993
  });
@@ -1602,6 +1571,8 @@ function isNonBlockingUnmatchedOrder(order) {
1602
1571
  * - `boundary-unknown-deferred`: gap geometry is unknown pre-boundary; the
1603
1572
  * comment at sync_engine.ts names the accepted cost as one sync cycle
1604
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.
1605
1576
  *
1606
1577
  * Anything not listed is treated as NOT escalatable, so a future transient
1607
1578
  * reason is excluded by default rather than silently becoming a resync
@@ -1610,6 +1581,9 @@ function isNonBlockingUnmatchedOrder(order) {
1610
1581
  const STRANDED_HOLD_REASONS = new Set([
1611
1582
  'out-of-rail-deferred',
1612
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',
1613
1587
  ]);
1614
1588
  /**
1615
1589
  * @param {Object} order - Unmatched chain order entry.
@@ -1865,6 +1839,23 @@ function checkSizeThreshold(sizes, threshold, precision, includeNonFinite = fals
1865
1839
  function checkSizesBeforeMinimum(sizes, minSize, precision) {
1866
1840
  return checkSizeThreshold(sizes, minSize, precision, true);
1867
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
+ }
1868
1859
  /**
1869
1860
  * Calculate ideal grid boundary based on reference price.
1870
1861
  * Places boundary near reference price with gap spacing in mind.
@@ -1885,8 +1876,7 @@ function calculateIdealBoundary(allSlots, referencePrice, gapSlots) {
1885
1876
  if (!allSlots || allSlots.length === 0)
1886
1877
  return -1;
1887
1878
  if (!Number.isFinite(Number(referencePrice))) {
1888
- const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
1889
- return Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
1879
+ return railCenterIndex(allSlots.length, gapSlots);
1890
1880
  }
1891
1881
  let splitIdx = allSlots.findIndex((s) => s.price >= referencePrice);
1892
1882
  if (splitIdx === -1)
@@ -2304,8 +2294,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2304
2294
  // never a rail-edge fabrication. The next fill batch re-anchors
2305
2295
  // from live prices via Tier 1.
2306
2296
  if (referencePrice === null && Array.isArray(allSlots) && allSlots.length > 0) {
2307
- const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
2308
- const centerIdx = Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
2297
+ const centerIdx = railCenterIndex(allSlots.length, gapSlots);
2309
2298
  const centerPrice = Number(allSlots[centerIdx]?.price);
2310
2299
  if (Number.isFinite(centerPrice))
2311
2300
  referencePrice = centerPrice;
@@ -2332,8 +2321,19 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
2332
2321
  // `edgeAnchors` (resolveLiveReserveEdgeAnchorPrice) is the same anchor the
2333
2322
  // placement sites use; without it the classification falls back to the
2334
2323
  // config-bound anchor, which can disagree with the slots actually placed.
2335
- const reserveBuyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null);
2336
- 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);
2337
2337
  // Pending crawls: fills recorded by earlier batches whose derivation
2338
2338
  // never committed (refused broadcast, P4 abort, or pre-restart loss —
2339
2339
  // the Sep-10 case: 4 fills consumed under a null boundary, crawl lost,
@@ -2461,8 +2461,13 @@ export function consumePendingFillCrawls(manager) {
2461
2461
  // two disagree: the config-bound fallback is null for mode-string/relative
2462
2462
  // bounds, so a restart would rank a stale below-rail slot as a reserve and
2463
2463
  // silently drop a crawl the live run recorded as ordinary market movement.
2464
- const reserveBuyIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.BUY, resolveLiveReserveEdgeAnchorPrice(manager, 'buy'));
2465
- 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);
2466
2471
  let netShift = 0;
2467
2472
  let count = 0;
2468
2473
  for (const e of pending) {
@@ -2524,13 +2529,25 @@ export function consumePendingFillCrawls(manager) {
2524
2529
  * Buy reserves pin at the grid floor, sell reserves at the grid ceiling.
2525
2530
  * Non-finite/non-integer/negative values disable (0).
2526
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
+ *
2527
2537
  * @param {Object} config - Bot configuration
2528
2538
  * @param {string} side - 'buy' or 'sell'
2529
2539
  * @returns {number} Reserve count for the side (>= 0 integer)
2530
2540
  */
2531
2541
  function resolveReserveCount(config, side) {
2532
2542
  const key = side === 'sell' ? 'sell' : 'buy';
2533
- 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);
2534
2551
  if (!Number.isInteger(raw) || raw < 0)
2535
2552
  return 0;
2536
2553
  return raw;
@@ -2596,41 +2613,47 @@ function reserveEdgeIdSet(allSlots, config, orderType, anchorPrice = null, exclu
2596
2613
  return ids;
2597
2614
  }
2598
2615
  /**
2599
- * Window member ids for one side, mirroring the window every placement
2600
- * picker excludes from its reserve pick: in-rail slots of the side (geometry
2601
- * via resolveGapBand/isSlotInRail — the same source the reconcile pickers
2602
- * use), ordered closest to market first (buys: highest price first; sells:
2603
- * lowest first), sliced to the configured activeOrders count. The slice runs
2604
- * over the FULL master rail, not just live orders — window membership is
2605
- * geometric (a virtual hole inside the window still blocks the reserve pick
2606
- * there), so live-only slices would misclassify live reserves as window
2607
- * members whenever the window itself is under-filled.
2616
+ * Window member ids for one side from an explicit slot list and geometry.
2608
2617
  *
2609
- * Returns null when the boundary geometry is unknown: the pickers cannot
2610
- * place reserves without it either, so callers fail open (no exclusion)
2611
- * 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.
2612
2626
  *
2613
- * @param {any} manager - OrderManager (orders Map, config, boundaryIdx)
2614
- * @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
2615
2636
  * @returns {Set<string>|null} Window slot ids, or null when geometry unknown
2616
2637
  */
2617
- function liveWindowIdSet(manager, orderType) {
2638
+ function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots) {
2618
2639
  try {
2619
2640
  const isSell = orderType === ORDER_TYPES.SELL;
2620
2641
  const type = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
2621
2642
  const side = isSell ? 'sell' : 'buy';
2622
- const count = Math.max(0, Math.floor(Number(manager?.config?.activeOrders?.[side])) || 0);
2623
- 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))
2624
2645
  return new Set();
2625
- const resolved = MathUtils.resolveGapBand(manager);
2626
- 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)))
2627
2649
  return null;
2628
- 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);
2629
2652
  // Same type filter as the window pickers with known geometry: the
2630
2653
  // side's concrete type plus SPREAD placeholders (normalized empties
2631
2654
  // sitting in this side's rail).
2632
2655
  const typeFilter = (o) => o && o.id != null && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD);
2633
- const ids = Array.from(manager.orders.values())
2656
+ const ids = allSlots
2634
2657
  .filter(typeFilter)
2635
2658
  .filter(inRail)
2636
2659
  .sort((a, b) => isSell ? Number(a.price) - Number(b.price) : Number(b.price) - Number(a.price))
@@ -2642,6 +2665,28 @@ function liveWindowIdSet(manager, orderType) {
2642
2665
  return null;
2643
2666
  }
2644
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
+ }
2645
2690
  /**
2646
2691
  * Refill-slot wire for the COW boundary hold (single source for both plan
2647
2692
  * producers: the fill-driven COW engine and the divergence fold).
@@ -2670,10 +2715,13 @@ function liveWindowIdSet(manager, orderType) {
2670
2715
  * @param {Iterable<Object>} [options.slots] - Master slots (reserve classification)
2671
2716
  * @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
2672
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)
2673
2721
  * @returns {string[]} Refill slot ids (CREATE ids minus reserve edge ids)
2674
2722
  */
2675
2723
  function collectRefillSlotIds(actions, options = {}) {
2676
- const { config = null, slots = null, edgeAnchors = null } = options;
2724
+ const { config = null, slots = null, edgeAnchors = null, manager = null } = options;
2677
2725
  const out = [];
2678
2726
  if (!Array.isArray(actions))
2679
2727
  return out;
@@ -2693,8 +2741,15 @@ function collectRefillSlotIds(actions, options = {}) {
2693
2741
  : (typeof slots?.values === 'function'
2694
2742
  ? Array.from(slots.values())
2695
2743
  : Array.from(slots));
2696
- const buyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null);
2697
- 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);
2698
2753
  if (buyIds || sellIds)
2699
2754
  reserveIds = new Set([...(buyIds ?? []), ...(sellIds ?? [])]);
2700
2755
  }
@@ -2720,8 +2775,10 @@ function collectRefillSlotIds(actions, options = {}) {
2720
2775
  *
2721
2776
  * Known limit: this is the statically resolved config bound, not the
2722
2777
  * gridPrice/AMA-referenced live rail bound. Placement call sites should use
2723
- * resolveLiveReserveEdgeAnchorPrice(manager, side), which prefers the live
2724
- * 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.
2725
2782
  *
2726
2783
  * @param {Object} config - Bot configuration
2727
2784
  * @param {string} side - 'buy' or 'sell'
@@ -2745,72 +2802,38 @@ function resolveReserveEdgeAnchorPrice(config, side) {
2745
2802
  *
2746
2803
  * The anchor must come from the geometry the bot is actually trading, never
2747
2804
  * from a config value that can be a mode string ("pool"/"book"), a relative
2748
- * multiplier, or a stale bound. Tiers, strongest first:
2749
- *
2750
- * 1. Genesis ladder extreme — `_genesis.priceLevels` is the exact ladder the
2751
- * loaded grid was built from: sorted ascending, index-aligned with
2752
- * `slot-<idx>` (assertSlotPriceInvariant), refreshed by initializeGrid,
2753
- * persisted with the grid, and unaffected by the raw-profile re-merge a
2754
- * resync performs. Slot 0 is always on the buy rail and the last level
2755
- * always on the sell rail, so the ladder extremes are the live rail
2756
- * bounds.
2757
- * 2. Live in-rail extreme of the master grid — geometry-only rail
2758
- * membership (resolveGapBand + isSlotInRail, the same predicate the
2759
- * selectors use) for snapshots without a genesis.
2760
- * 3. Config bound (resolveReserveEdgeAnchorPrice) — the previous behavior,
2761
- * kept as the last resolved tier.
2762
- * 4. null — callers keep the legacy rank-based selection.
2763
- *
2764
- * @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)
2765
2825
  * @param {string} side - 'buy' or 'sell'
2766
2826
  * @returns {number|null} Finite anchor price, or null
2767
2827
  */
2768
2828
  function resolveLiveReserveEdgeAnchorPrice(manager, side) {
2769
2829
  const isSell = side === 'sell';
2770
- // Tier 1 — the ladder the loaded grid was generated from.
2771
2830
  const levels = manager?._genesis?.priceLevels;
2772
2831
  if (Array.isArray(levels) && levels.length > 0) {
2773
2832
  const extreme = Number(isSell ? levels[levels.length - 1] : levels[0]);
2774
2833
  if (Number.isFinite(extreme) && extreme > 0)
2775
2834
  return extreme;
2776
2835
  }
2777
- // Tier 2 — live in-rail extreme of the master grid.
2778
- const sideType = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
2779
- if (manager?.orders && typeof manager.orders.values === 'function') {
2780
- let best = null;
2781
- try {
2782
- const band = MathUtils.resolveGapBand(manager);
2783
- for (const entry of manager.orders.values()) {
2784
- if (!entry || typeof entry !== 'object')
2785
- continue;
2786
- if (!('type' in entry) || !('price' in entry))
2787
- continue;
2788
- if (entry.type !== sideType)
2789
- continue;
2790
- // Shelf/manual ids (e.g. fork-kept deep-* orders below the rail)
2791
- // are never rail geometry: isSlotInRail is fail-open for
2792
- // unparseable ids, so without this gate a cheap shelf order drags
2793
- // the anchor down to itself and then qualifies as the reserve edge
2794
- // (issue #27 follow-up). No-op upstream (grids only mint slot-N).
2795
- if (parseSlotIndex(entry?.id) === null)
2796
- continue;
2797
- if (!MathUtils.isSlotInRail(band.boundaryIdx, band.gapSlots, sideType, entry))
2798
- continue;
2799
- const price = Number(entry.price);
2800
- if (!Number.isFinite(price) || price <= 0)
2801
- continue;
2802
- if (best === null || (isSell ? price > best : price < best))
2803
- best = price;
2804
- }
2805
- }
2806
- catch (e) {
2807
- best = null;
2808
- }
2809
- if (best !== null)
2810
- return best;
2811
- }
2812
- // Tier 3 — configured/resolved bound.
2813
- return resolveReserveEdgeAnchorPrice(manager?.config, side);
2836
+ return null;
2814
2837
  }
2815
2838
  /**
2816
2839
  * Shared anchored edge comparator for reserve selection (single source).
@@ -3140,6 +3163,6 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
3140
3163
  const all = new Set([...masterIds, ...createIds]);
3141
3164
  return { masterIds: [...masterIds], createIds: [...createIds], all: [...all] };
3142
3165
  }
3143
- 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 };
3144
3167
  export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds };
3145
3168
  //# sourceMappingURL=order.js.map