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
@@ -16,10 +16,10 @@
16
16
  * 1. AccountOrders(options) - Class for per-bot order persistence
17
17
  * Constructor options: { botKey, ordersDir?, profilesPath? } (botKey required, throws if missing)
18
18
  * Methods:
19
- * syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls)
19
+ * syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls, lastFillPivot)
20
20
  * loadGrid(forceReload), loadRecentFillKeys(forceReload), loadPersistedAssets(forceReload), loadPendingFillCrawls(forceReload)
21
- * loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload)
22
- * clearGrid()
21
+ * loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload), loadLastFillPivot(forceReload)
22
+ * clearGrid(), clearPersistedBoundary(), clearPersistedLastFillPivot()
23
23
  * loadProcessedFills(options), updateProcessedFillsBatch(fills), cleanOldProcessedFills(olderThanMs)
24
24
  * getAssetBalances(forceReload)
25
25
  *
@@ -165,7 +165,7 @@ declare class AccountOrders {
165
165
  * @param {Object|null} recentFillKeys - Optional fill key dedup snapshot for crash recovery
166
166
  * @param {Object|null} genesis - Optional frozen genesis (priceLevels etc)
167
167
  */
168
- storeMasterGrid(orders?: any[], btsFeesOwed?: any, boundaryIdx?: any, assets?: any, debugInputs?: any, recentFillKeys?: any, genesis?: any, gapEvacStreaks?: any, pendingFillCrawls?: any): Promise<void>;
168
+ storeMasterGrid(orders?: any[], btsFeesOwed?: any, boundaryIdx?: any, assets?: any, debugInputs?: any, recentFillKeys?: any, genesis?: any, gapEvacStreaks?: any, pendingFillCrawls?: any, lastFillPivot?: any): Promise<void>;
169
169
  /**
170
170
  * Erase a poisoned persisted boundary after GRID-LOAD rejects it with no
171
171
  * safe re-derivation. storeMasterGrid deliberately never writes a null
@@ -177,19 +177,59 @@ declare class AccountOrders {
177
177
  * fills mutate state) but do NOT invoke later in the lifecycle.
178
178
  */
179
179
  clearPersistedBoundary(): Promise<void>;
180
+ /**
181
+ * Erase a persisted LAST-FILL-GUARD pivot that restoreLastFillPivot
182
+ * rejected (genesis mismatch / TTL expiry / off-ladder). storeMasterGrid
183
+ * deliberately keeps an untouched row for legacy `undefined` callers, so
184
+ * without this explicit erase a rejected value would re-arm the rejection
185
+ * on every restart. Load-time only: this reloads from disk inside the
186
+ * lock, discarding any unsaved in-memory mutations — safe at the
187
+ * loadGrid/restore call site (startup load and recovery reload, both
188
+ * before fills mutate state) but do NOT invoke from an arbitrary runtime
189
+ * path.
190
+ */
191
+ clearPersistedLastFillPivot(): Promise<void>;
180
192
  /**
181
193
  * Load the persisted order grid for this bot.
182
194
  * @param {boolean} forceReload - If true, reload from disk to ensure fresh data
183
195
  * @returns {Array|null} Order grid array or null if not found
184
196
  */
185
197
  loadGrid(forceReload?: boolean): any;
198
+ /**
199
+ * Load the persisted price-ladder (genesis) for this bot.
200
+ *
201
+ * SCHEMA GATE (docs/GRID_PRICE_INVARIANT.md, "Schema"): a usable ladder needs a
202
+ * NON-EMPTY `priceLevels` array. A row without one is not a ladder --
203
+ * accepting it would hand `loadGrid` a genesis it cannot validate against
204
+ * (and, for an empty array, silently disable every genesis-derived consumer).
205
+ * Refusing it here means the caller takes the missing-genesis path once, at
206
+ * the source, instead of at every consumer.
207
+ *
208
+ * The hash is deliberately NOT required here: a present-but-tampered hash is
209
+ * still returned, because the hash-mismatch warning belongs to `loadGrid`,
210
+ * which can say what it compared against (`hasGenesisLadder` in
211
+ * modules/order/genesis_policy.ts draws the same distinction).
212
+ * @param {boolean} forceReload - If true, reload from disk
213
+ * @returns {Object|null} The genesis object, or null when absent/invalid
214
+ */
186
215
  loadGenesis(forceReload?: boolean): any;
216
+ /**
217
+ * Record why a persisted genesis row was refused (observability for the
218
+ * schema gate above; loadGrid cannot report a row it never receives).
219
+ */
220
+ private _noteRejectedGenesis;
187
221
  /**
188
222
  * Load the persisted gap-evacuation streaks (per-slot in-band cycle counts).
189
223
  * @param {boolean} forceReload - If true, reload from disk
190
224
  * @returns {Object|null} {slotId: count} map or null when absent
191
225
  */
192
226
  loadGapEvacStreaks(forceReload?: boolean): any;
227
+ loadLastFillPivot(forceReload?: boolean): {
228
+ price: number;
229
+ type: string;
230
+ fillsAt: number;
231
+ genesisHash: string;
232
+ } | null;
193
233
  /**
194
234
  * Load persisted pending fill crawls for this bot.
195
235
  * @param {boolean} forceReload - If true, reload from disk
@@ -16,10 +16,10 @@
16
16
  * 1. AccountOrders(options) - Class for per-bot order persistence
17
17
  * Constructor options: { botKey, ordersDir?, profilesPath? } (botKey required, throws if missing)
18
18
  * Methods:
19
- * syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls)
19
+ * syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls, lastFillPivot)
20
20
  * loadGrid(forceReload), loadRecentFillKeys(forceReload), loadPersistedAssets(forceReload), loadPendingFillCrawls(forceReload)
21
- * loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload)
22
- * clearGrid()
21
+ * loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload), loadLastFillPivot(forceReload)
22
+ * clearGrid(), clearPersistedBoundary(), clearPersistedLastFillPivot()
23
23
  * loadProcessedFills(options), updateProcessedFillsBatch(fills), cleanOldProcessedFills(olderThanMs)
24
24
  * getAssetBalances(forceReload)
25
25
  *
@@ -64,8 +64,9 @@ import { ORDER_TYPES, ORDER_STATES } from './constants.js';
64
64
  import { PATHS } from './paths.js';
65
65
  import AsyncLock from './order/async_lock.js';
66
66
  import { isPhantomOrder } from './order/utils/order.js';
67
+ import { hasGenesisLadder } from './order/genesis_policy.js';
67
68
  import * as Format from './order/format.js';
68
- import { ensureDir, nowIso } from './order/utils/system.js';
69
+ import { ensureDir, nowIso, normalizeLastFillPivot } from './order/utils/system.js';
69
70
  import Logger from './order/logger.js';
70
71
  import { getErrorMessage } from './utils/errors.js';
71
72
  import { sanitizeKey } from './utils/sanitize_key.js';
@@ -317,7 +318,7 @@ class AccountOrders {
317
318
  * @param {Object|null} recentFillKeys - Optional fill key dedup snapshot for crash recovery
318
319
  * @param {Object|null} genesis - Optional frozen genesis (priceLevels etc)
319
320
  */
320
- async storeMasterGrid(orders = [], btsFeesOwed = null, boundaryIdx = null, assets = null, debugInputs = null, recentFillKeys = null, genesis = null, gapEvacStreaks = undefined, pendingFillCrawls = undefined) {
321
+ async storeMasterGrid(orders = [], btsFeesOwed = null, boundaryIdx = null, assets = null, debugInputs = null, recentFillKeys = null, genesis = null, gapEvacStreaks = undefined, pendingFillCrawls = undefined, lastFillPivot = undefined) {
321
322
  // Use AsyncLock to serialize read-modify-write operations
322
323
  await this._persistenceLock.acquire(async () => {
323
324
  // Reload from disk before writing to prevent race conditions
@@ -395,6 +396,35 @@ class AccountOrders {
395
396
  delete this.data.pendingFillCrawls;
396
397
  }
397
398
  }
399
+ if (lastFillPivot !== undefined) {
400
+ // Only a fill-derived, validated-on-grid pivot survives (provenance
401
+ // gate: a book-derived or unvalidated heuristic is never written as
402
+ // if it were market truth). genesisHash binds it to the snapshot the
403
+ // boundary lives in: a persisted pivot from an old genesis is not
404
+ // valid after a grid regeneration/re-derive, and the restore helper
405
+ // refuses it on mismatch (same lockstep contract as pendingFillCrawls).
406
+ // null clears any previously stored row on every live-grid persist so
407
+ // a consumed pivot never resurrects; undefined (legacy callers) is a
408
+ // no-op; any other malformed shape is treated as an explicit clear
409
+ // (never store, never leave a stale row behind). Row validation is
410
+ // the shared normalizeLastFillPivot gate — the loader enforces the
411
+ // exact same shape, so the two gates cannot drift.
412
+ if (lastFillPivot === undefined) {
413
+ // Legacy no-op (backward-compatible callers), mirror gapEvacStreaks.
414
+ }
415
+ else if (lastFillPivot === null) {
416
+ delete this.data.lastFillPivot;
417
+ }
418
+ else {
419
+ const normalized = normalizeLastFillPivot(lastFillPivot);
420
+ if (normalized) {
421
+ this.data.lastFillPivot = normalized;
422
+ }
423
+ else {
424
+ delete this.data.lastFillPivot;
425
+ }
426
+ }
427
+ }
398
428
  const timestamp = nowIso();
399
429
  this.data.lastUpdated = timestamp;
400
430
  if (this.data.meta)
@@ -419,6 +449,25 @@ class AccountOrders {
419
449
  this._persist();
420
450
  });
421
451
  }
452
+ /**
453
+ * Erase a persisted LAST-FILL-GUARD pivot that restoreLastFillPivot
454
+ * rejected (genesis mismatch / TTL expiry / off-ladder). storeMasterGrid
455
+ * deliberately keeps an untouched row for legacy `undefined` callers, so
456
+ * without this explicit erase a rejected value would re-arm the rejection
457
+ * on every restart. Load-time only: this reloads from disk inside the
458
+ * lock, discarding any unsaved in-memory mutations — safe at the
459
+ * loadGrid/restore call site (startup load and recovery reload, both
460
+ * before fills mutate state) but do NOT invoke from an arbitrary runtime
461
+ * path.
462
+ */
463
+ async clearPersistedLastFillPivot() {
464
+ await this._persistenceLock.acquire(async () => {
465
+ this.data = this._loadData() || emptyData();
466
+ delete this.data.lastFillPivot;
467
+ this.data.lastUpdated = nowIso();
468
+ this._persist();
469
+ });
470
+ }
422
471
  /**
423
472
  * Load the persisted order grid for this bot.
424
473
  * @param {boolean} forceReload - If true, reload from disk to ensure fresh data
@@ -430,15 +479,51 @@ class AccountOrders {
430
479
  }
431
480
  return (this.data && Array.isArray(this.data.grid)) ? this.data.grid : null;
432
481
  }
482
+ /**
483
+ * Load the persisted price-ladder (genesis) for this bot.
484
+ *
485
+ * SCHEMA GATE (docs/GRID_PRICE_INVARIANT.md, "Schema"): a usable ladder needs a
486
+ * NON-EMPTY `priceLevels` array. A row without one is not a ladder --
487
+ * accepting it would hand `loadGrid` a genesis it cannot validate against
488
+ * (and, for an empty array, silently disable every genesis-derived consumer).
489
+ * Refusing it here means the caller takes the missing-genesis path once, at
490
+ * the source, instead of at every consumer.
491
+ *
492
+ * The hash is deliberately NOT required here: a present-but-tampered hash is
493
+ * still returned, because the hash-mismatch warning belongs to `loadGrid`,
494
+ * which can say what it compared against (`hasGenesisLadder` in
495
+ * modules/order/genesis_policy.ts draws the same distinction).
496
+ * @param {boolean} forceReload - If true, reload from disk
497
+ * @returns {Object|null} The genesis object, or null when absent/invalid
498
+ */
433
499
  loadGenesis(forceReload = false) {
434
500
  if (forceReload) {
435
501
  this.data = this._loadData() || emptyData();
436
502
  }
437
- if (this.data && this.data.genesis && Array.isArray(this.data.genesis.priceLevels)) {
438
- return this.data.genesis;
503
+ const genesis = this.data?.genesis;
504
+ // Same predicate as loadGrid/genesis_policy: one definition of "usable
505
+ // ladder", so the schema gate cannot diverge from the load-time gate.
506
+ if (hasGenesisLadder(genesis)) {
507
+ return genesis;
508
+ }
509
+ if (genesis) {
510
+ this._noteRejectedGenesis(genesis);
439
511
  }
440
512
  return null;
441
513
  }
514
+ /**
515
+ * Record why a persisted genesis row was refused (observability for the
516
+ * schema gate above; loadGrid cannot report a row it never receives).
517
+ */
518
+ _noteRejectedGenesis(genesis) {
519
+ try {
520
+ const reason = !Array.isArray(genesis?.priceLevels)
521
+ ? 'priceLevels is not an array'
522
+ : (genesis?.priceLevels?.length === 0 ? 'priceLevels is empty' : 'malformed');
523
+ this._rejectedGenesis = { reason, at: Date.now() };
524
+ }
525
+ catch { /* never fail a load for telemetry */ }
526
+ }
442
527
  /**
443
528
  * Load the persisted gap-evacuation streaks (per-slot in-band cycle counts).
444
529
  * @param {boolean} forceReload - If true, reload from disk
@@ -453,6 +538,14 @@ class AccountOrders {
453
538
  }
454
539
  return null;
455
540
  }
541
+ loadLastFillPivot(forceReload = false) {
542
+ if (forceReload) {
543
+ this.data = this._loadData() || emptyData();
544
+ }
545
+ // Shared row gate (normalizeLastFillPivot): identical validation to the
546
+ // storeMasterGrid sanitizer, one shape contract for the whole ledger.
547
+ return normalizeLastFillPivot(this.data && this.data.lastFillPivot);
548
+ }
456
549
  /**
457
550
  * Load persisted pending fill crawls for this bot.
458
551
  * @param {boolean} forceReload - If true, reload from disk
@@ -566,6 +659,10 @@ class AccountOrders {
566
659
  // are relative deltas against the deleted boundary/grid, so a rebuilt
567
660
  // generation must not inherit them (the rebuild re-anchors absolutely).
568
661
  delete this.data.pendingFillCrawls;
662
+ // The persisted LAST-FILL-GUARD pivot belongs to the deleted snapshot's
663
+ // generation (its slot ids and genesis): a rebuilt grid must re-arm on
664
+ // a fresh fill, not inherit a pivot validated against wiped geometry.
665
+ delete this.data.lastFillPivot;
569
666
  this.data.lastUpdated = nowIso();
570
667
  this._persist();
571
668
  return true;
@@ -13,6 +13,15 @@ interface ChainClientConfig {
13
13
  validateChainId?: boolean;
14
14
  expectedChainId?: string;
15
15
  }
16
+ /**
17
+ * Outcome of a forced-reconnect request.
18
+ * - `issued` a fresh teardown/reconnect was started by this call.
19
+ * - `coalesced` a forced reconnect was already issued within the cooldown (by
20
+ * this or another escalation source); nothing was torn down
21
+ * again, but a recovery attempt is in flight/recent.
22
+ * - `unavailable` no live socket to tear down, so no recovery attempt exists.
23
+ */
24
+ export type ForcedReconnectOutcome = 'issued' | 'coalesced' | 'unavailable';
16
25
  declare function createChainClient(config?: ChainClientConfig): any;
17
26
  interface ReadOnlyClientConfig {
18
27
  nodes?: string[];
@@ -24,6 +33,7 @@ interface ReadOnlyClientConfig {
24
33
  declare function createReadOnlyClient(config?: ReadOnlyClientConfig): {
25
34
  connect: (servers?: string[]) => Promise<void>;
26
35
  disconnect: () => void;
36
+ forceReconnect: (reason?: string) => ForcedReconnectOutcome;
27
37
  db: (method: string, args?: any[]) => Promise<any>;
28
38
  history: (method: string, args?: any[]) => Promise<any>;
29
39
  setNodes: (servers: string[]) => void;
@@ -3,7 +3,7 @@ import { createTransport, ConnectionError } from './transport.js';
3
3
  import { GRAPHENE_CHAIN_ID, GRAPHENE_ADDRESS_PREFIX } from './serial/chain_constants.js';
4
4
  import { NATIVE_CLIENT } from '../constants.js';
5
5
  import { getErrorMessage } from '../utils/errors.js';
6
- const { CHAIN } = NATIVE_CLIENT;
6
+ const { CHAIN, TRANSPORT } = NATIVE_CLIENT;
7
7
  class ChainConfigError extends Error {
8
8
  code;
9
9
  constructor(message) {
@@ -14,13 +14,60 @@ class ChainConfigError extends Error {
14
14
  function toRpcMethodName(method) {
15
15
  return String(method).replace(/([A-Z])/g, (_, ch) => `_${ch.toLowerCase()}`);
16
16
  }
17
+ /**
18
+ * True when an RPC error means the api_id we sent is not registered on the
19
+ * current websocket login session. bitshares-core returns:
20
+ * Execution error: Assert Exception: _local_apis.size() > api_id:
21
+ * A cached api id can outlive its session when a reconnect swaps the socket
22
+ * without a status 'closed' event, or when the node drops the login session
23
+ * server-side; the id then points past the new session's _local_apis map.
24
+ */
25
+ function isStaleApiIdError(err) {
26
+ const message = err && err.message ? String(err.message) : String(err ?? '');
27
+ if (!message)
28
+ return false;
29
+ return message.includes('_local_apis') || (message.includes('api_id') && message.includes('Assert Exception'));
30
+ }
31
+ /**
32
+ * Build the per-client forced-reconnect gate shared by the main and read-only
33
+ * clients, and transitively by the stale-api window and the subscriptions
34
+ * fill-channel watchdog. One cooldown per client stops a wedged session from
35
+ * stacking concurrent reconnects; the outcome lets a caller distinguish a
36
+ * genuinely new teardown from one coalesced onto another source's, so
37
+ * escalation accounting is not starved when the cooldown is already spent.
38
+ */
39
+ function createForcedReconnectGate(transport) {
40
+ const cooldownMs = Number.isFinite(TRANSPORT.FORCED_RECONNECT_COOLDOWN_MS)
41
+ ? Math.max(0, TRANSPORT.FORCED_RECONNECT_COOLDOWN_MS)
42
+ : 30000;
43
+ let lastForcedReconnectAt = 0;
44
+ return function forceReconnect(reason = 'forced') {
45
+ const now = Date.now();
46
+ // Coalesce is checked before connectivity: immediately after a teardown
47
+ // the socket is null while the reconnect is in flight, and that must
48
+ // still read as `coalesced`, not `unavailable`.
49
+ if (now - lastForcedReconnectAt < cooldownMs)
50
+ return 'coalesced';
51
+ // No live socket: there is nothing to tear down, so this is not a
52
+ // recovery attempt. Reporting it as `issued` would let callers count a
53
+ // no-op as a cycle and burn the cooldown.
54
+ if (typeof transport?.isConnected === 'function' && !transport.isConnected())
55
+ return 'unavailable';
56
+ lastForcedReconnectAt = now;
57
+ try {
58
+ transport.forceReconnect(reason);
59
+ }
60
+ catch (_) {
61
+ // Keep the stamp: a throwing recovery must not become a tight loop.
62
+ }
63
+ return 'issued';
64
+ };
65
+ }
17
66
  function createChainClient(config = {}) {
18
67
  const { nodes = [], onStatusChange = null, onNodeFailure = null, shouldSkipNode = null, rpcTimeoutMs, connectTimeoutMs, autoreconnect = true, validateChainId = true, expectedChainId = GRAPHENE_CHAIN_ID, } = config;
19
68
  const wrappedOnStatusChange = (status, nodeUrl) => {
20
69
  if (status === 'closed') {
21
- _dbApiId = null;
22
- _historyApiId = null;
23
- _broadcastApiId = null;
70
+ resetApiIds();
24
71
  _chainConfig = null;
25
72
  }
26
73
  if (onStatusChange)
@@ -45,8 +92,30 @@ function createChainClient(config = {}) {
45
92
  let _historyApiId = null;
46
93
  let _broadcastApiId = null;
47
94
  let _chainConfig = null;
95
+ function resetApiIds() {
96
+ _dbApiId = null;
97
+ _historyApiId = null;
98
+ _broadcastApiId = null;
99
+ }
48
100
  let _loginPromise = null;
49
101
  let _apiLimitGetAccountHistory = null;
102
+ // Escalation state for a login session that keeps rejecting cached api ids.
103
+ // A single stale error is handled in place (re-register + retry once); a
104
+ // sustained run means the session is wedged and only a fresh socket (on a
105
+ // different node) clears it.
106
+ let _staleApiErrorCount = 0;
107
+ let _staleApiWindowStartedAt = 0;
108
+ // Shared forced-reconnect debounce. Both escalation sources — the stale
109
+ // api_id window below and the subscriptions fill-channel watchdog — call
110
+ // forceReconnect(), so the cooldown lives here, once per client, instead of
111
+ // being duplicated (and independently tuned) at each call site. A wedged
112
+ // session trips both counters in the same tick; without this they would
113
+ // stack two reconnects on top of each other.
114
+ //
115
+ // Public entry point for higher layers (subscriptions watchdog) to recover
116
+ // a session that is nominally connected but rejecting every call.
117
+ // @returns the {@link ForcedReconnectOutcome} of the request.
118
+ const forceReconnect = createForcedReconnectGate(transport);
50
119
  if (Array.isArray(nodes) && nodes.length > 0) {
51
120
  transport._setNodes(nodes);
52
121
  }
@@ -54,6 +123,15 @@ function createChainClient(config = {}) {
54
123
  if (_loginPromise)
55
124
  return _loginPromise;
56
125
  _loginPromise = (async () => {
126
+ // validateNode() runs login() on every (re)connect. A new websocket
127
+ // session starts with an empty _local_apis map, so api ids cached
128
+ // from the previous session are no longer addressable — the node
129
+ // rejects them with "Assert Exception: _local_apis.size() > api_id".
130
+ // Drop them so every accessor re-registers against this session.
131
+ resetApiIds();
132
+ // A fresh login session is a clean slate for the stale-id escalation.
133
+ _staleApiErrorCount = 0;
134
+ _staleApiWindowStartedAt = 0;
57
135
  const result = await transport.call('call', [1, 'login', ['', '']]);
58
136
  if (!result) {
59
137
  throw new ConnectionError('Login error');
@@ -118,23 +196,66 @@ function createChainClient(config = {}) {
118
196
  const apiId = await transport.call('call', [1, apiName, []]);
119
197
  return apiId;
120
198
  }
121
- async function dbCall(method, args) {
122
- if (_dbApiId == null) {
123
- _dbApiId = await registerApi('database');
199
+ /**
200
+ * Invoke a login_api-registered RPC namespace, transparently recovering
201
+ * from a stale api id. If the node rejects the call because the id is not
202
+ * registered on the current session, drop the cached id, re-register the
203
+ * namespace on this session, and retry once. This is what keeps the fill
204
+ * history channel alive across a node failover without a process restart.
205
+ */
206
+ async function callWithApiRecovery(apiName, method, args, getApiId, setApiId) {
207
+ let apiId = getApiId();
208
+ if (apiId == null) {
209
+ apiId = await registerApi(apiName);
210
+ setApiId(apiId);
211
+ }
212
+ try {
213
+ return await transport.call('call', [apiId, method, args]);
214
+ }
215
+ catch (err) {
216
+ if (!isStaleApiIdError(err))
217
+ throw err;
218
+ noteStaleApiError(apiName);
219
+ setApiId(null);
220
+ const freshId = await registerApi(apiName);
221
+ setApiId(freshId);
222
+ return transport.call('call', [freshId, method, args]);
124
223
  }
125
- return transport.call('call', [_dbApiId, toRpcMethodName(method), args || []]);
126
224
  }
127
- async function historyCall(method, args) {
128
- if (_historyApiId == null) {
129
- _historyApiId = await registerApi('history');
225
+ /**
226
+ * Record a stale-api error and escalate to a forced reconnect when the
227
+ * session keeps rejecting ids. Counting is windowed: a rare stale id (the
228
+ * normal reconnect-race case) never trips the escalation, while a session
229
+ * that fails every call trips it within a few RPCs. The forced reconnect
230
+ * marks the active node failed, so the transport prefers another node.
231
+ */
232
+ function noteStaleApiError(apiName) {
233
+ const now = Date.now();
234
+ const windowMs = Number.isFinite(TRANSPORT.STALE_API_WINDOW_MS) ? TRANSPORT.STALE_API_WINDOW_MS : 60000;
235
+ const threshold = Number.isFinite(TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER)
236
+ ? TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER
237
+ : 3;
238
+ if (now - _staleApiWindowStartedAt > windowMs) {
239
+ _staleApiWindowStartedAt = now;
240
+ _staleApiErrorCount = 0;
130
241
  }
131
- return transport.call('call', [_historyApiId, toRpcMethodName(method), args || []]);
242
+ _staleApiErrorCount++;
243
+ if (_staleApiErrorCount < threshold)
244
+ return;
245
+ _staleApiErrorCount = 0;
246
+ _staleApiWindowStartedAt = now;
247
+ // Go through the local wrapper so this escalation shares the one
248
+ // per-client cooldown with the subscriptions watchdog.
249
+ forceReconnect(`repeated stale api_id for ${apiName} (${threshold}x)`);
250
+ }
251
+ async function dbCall(method, args) {
252
+ return callWithApiRecovery('database', toRpcMethodName(method), args || [], () => _dbApiId, (id) => { _dbApiId = id; });
253
+ }
254
+ async function historyCall(method, args) {
255
+ return callWithApiRecovery('history', toRpcMethodName(method), args || [], () => _historyApiId, (id) => { _historyApiId = id; });
132
256
  }
133
257
  async function broadcastCall(method, args) {
134
- if (_broadcastApiId == null) {
135
- _broadcastApiId = await registerApi('network_broadcast');
136
- }
137
- return transport.call('call', [_broadcastApiId, method, args || []]);
258
+ return callWithApiRecovery('network_broadcast', method, args || [], () => _broadcastApiId, (id) => { _broadcastApiId = id; });
138
259
  }
139
260
  async function broadcastTx(signedTx) {
140
261
  return broadcastCall('broadcast_transaction', [signedTx]);
@@ -149,9 +270,7 @@ function createChainClient(config = {}) {
149
270
  await transport.connect(undefined, autoreconnect);
150
271
  }
151
272
  function disconnect() {
152
- _dbApiId = null;
153
- _historyApiId = null;
154
- _broadcastApiId = null;
273
+ resetApiIds();
155
274
  _chainConfig = null;
156
275
  transport.disconnect();
157
276
  }
@@ -198,6 +317,7 @@ function createChainClient(config = {}) {
198
317
  transport,
199
318
  connect,
200
319
  disconnect,
320
+ forceReconnect,
201
321
  setNodes,
202
322
  getNodes,
203
323
  getStatus,
@@ -217,6 +337,9 @@ function createReadOnlyClient(config = {}) {
217
337
  let _dbApiId = null;
218
338
  let _historyApiId = null;
219
339
  let _recoverPromise = null;
340
+ // Windowed escalation for a read channel whose session keeps rejecting ids.
341
+ let _staleApiErrorCount = 0;
342
+ let _staleApiWindowStartedAt = 0;
220
343
  function resetApiIds() {
221
344
  _dbApiId = null;
222
345
  _historyApiId = null;
@@ -229,6 +352,10 @@ function createReadOnlyClient(config = {}) {
229
352
  resetApiIds();
230
353
  },
231
354
  });
355
+ // Shared forced-reconnect debounce for the read channel, mirroring the main
356
+ // client: one cooldown and one outcome for every forced reconnect raised on
357
+ // this client (stale api_id escalation today).
358
+ const forceReconnect = createForcedReconnectGate(transport);
232
359
  async function connect(servers) {
233
360
  const effectiveNodes = Array.isArray(servers) && servers.length > 0
234
361
  ? servers
@@ -285,23 +412,64 @@ function createReadOnlyClient(config = {}) {
285
412
  resetApiIds();
286
413
  transport.disconnect();
287
414
  }
288
- async function db(method, args) {
289
- if (_dbApiId == null) {
415
+ /**
416
+ * Invoke a read-only RPC namespace, recovering from a stale api id by
417
+ * re-registering on the current session and retrying once. Mirrors the
418
+ * main client's callWithApiRecovery so a missed 'closed' event cannot
419
+ * permanently wedge the read channel.
420
+ */
421
+ async function callWithRecovery(method, args, getApiId, setApiId) {
422
+ if (getApiId() == null) {
290
423
  await recoverApis();
291
424
  const err = await validateChain();
292
425
  if (err)
293
426
  throw err;
294
427
  }
295
- return transport.call('call', [_dbApiId, toRpcMethodName(method), args || []]);
296
- }
297
- async function history(method, args) {
298
- if (_historyApiId == null) {
428
+ const apiId = getApiId();
429
+ try {
430
+ return await transport.call('call', [apiId, method, args]);
431
+ }
432
+ catch (err) {
433
+ if (!isStaleApiIdError(err))
434
+ throw err;
435
+ noteStaleApiError();
436
+ setApiId(null);
299
437
  await recoverApis();
300
- const err = await validateChain();
301
- if (err)
438
+ const freshId = getApiId();
439
+ if (freshId == null)
302
440
  throw err;
441
+ return transport.call('call', [freshId, method, args]);
303
442
  }
304
- return transport.call('call', [_historyApiId, toRpcMethodName(method), args || []]);
443
+ }
444
+ /**
445
+ * Windowed stale-id escalation for the read channel. Mirrors the main
446
+ * client: a rare reconnect-race stale id recovers in place, a sustained
447
+ * run forces a fresh connection on another node.
448
+ */
449
+ function noteStaleApiError() {
450
+ const now = Date.now();
451
+ const windowMs = Number.isFinite(TRANSPORT.STALE_API_WINDOW_MS) ? TRANSPORT.STALE_API_WINDOW_MS : 60000;
452
+ const threshold = Number.isFinite(TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER)
453
+ ? TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER
454
+ : 3;
455
+ if (now - _staleApiWindowStartedAt > windowMs) {
456
+ _staleApiWindowStartedAt = now;
457
+ _staleApiErrorCount = 0;
458
+ }
459
+ _staleApiErrorCount++;
460
+ if (_staleApiErrorCount < threshold)
461
+ return;
462
+ _staleApiErrorCount = 0;
463
+ _staleApiWindowStartedAt = now;
464
+ // Route through the shared wrapper so both stale-id escalations on this
465
+ // client obey one cooldown.
466
+ forceReconnect(`repeated stale api_id on read channel (${threshold}x)`);
467
+ }
468
+ async function db(method, args) {
469
+ return callWithRecovery(toRpcMethodName(method), args || [], () => _dbApiId, (id) => { _dbApiId = id; });
470
+ }
471
+ async function history(method, args) {
472
+ return callWithRecovery(toRpcMethodName(method), args || [], () => _historyApiId, (id) => { _historyApiId = id; });
305
473
  }
306
474
  function setNodes(servers) {
307
475
  transport._setNodes(servers);
@@ -312,6 +480,7 @@ function createReadOnlyClient(config = {}) {
312
480
  return {
313
481
  connect,
314
482
  disconnect,
483
+ forceReconnect,
315
484
  db,
316
485
  history,
317
486
  setNodes,