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.
- package/CHANGELOG.md +89 -1
- package/README.md +8 -5
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +44 -15
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +20 -9
- package/dist/modules/account_orders.d.ts +44 -4
- package/dist/modules/account_orders.js +104 -7
- package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
- package/dist/modules/bitshares-native/chain_client.js +197 -28
- package/dist/modules/bitshares-native/subscriptions.js +312 -10
- package/dist/modules/bitshares-native/transport.d.ts +1 -0
- package/dist/modules/bitshares-native/transport.js +97 -3
- package/dist/modules/bitshares_client.d.ts +20 -0
- package/dist/modules/bitshares_client.js +29 -0
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/chain_keys.d.ts +37 -22
- package/dist/modules/chain_keys.js +145 -44
- package/dist/modules/cli_start_onboarding.d.ts +10 -0
- package/dist/modules/cli_start_onboarding.js +15 -0
- package/dist/modules/cli_start_output.d.ts +6 -0
- package/dist/modules/cli_start_output.js +8 -0
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +23 -2
- package/dist/modules/constants.js +196 -15
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +53 -96
- package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
- package/dist/modules/dexbot_fill_runtime.js +22 -3
- package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
- package/dist/modules/dexbot_maintenance_runtime.js +103 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +34 -1
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +109 -135
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +13 -2
- package/dist/modules/order/logger.d.ts +12 -2
- package/dist/modules/order/logger.js +29 -7
- package/dist/modules/order/manager.d.ts +53 -0
- package/dist/modules/order/manager.js +86 -25
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +302 -194
- package/dist/modules/order/utils/system.d.ts +97 -0
- package/dist/modules/order/utils/system.js +282 -3
- package/dist/modules/paths.d.ts +8 -1
- package/dist/modules/paths.js +11 -3
- package/dist/modules/utils/text_width.d.ts +19 -0
- package/dist/modules/utils/text_width.js +97 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +104 -18
- package/dist/scripts/update.js +62 -13
- package/dist/unlock.d.ts +14 -2
- package/dist/unlock.js +101 -4
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +11 -2
- package/docs/CREDENTIAL_SECURITY.md +26 -0
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -18
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +204 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/LOGGING.md +17 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +14 -6
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -7,8 +7,9 @@ import { ORDER_TYPES, TIMING } from './constants.js';
|
|
|
7
7
|
import * as Format from './order/format.js';
|
|
8
8
|
import * as grid from './order/grid.js';
|
|
9
9
|
import { convertToSpreadPlaceholder, parseChainOrder, isNonBlockingUnmatchedOrder } from './order/utils/order.js';
|
|
10
|
-
import { restoreGapEvacStreaks, applyPersistedPendingCrawls } from './order/utils/system.js';
|
|
10
|
+
import { restoreGapEvacStreaks, applyPersistedPendingCrawls, resetLastFillPivot } from './order/utils/system.js';
|
|
11
11
|
import { blockchainToFloat, calculateGapSlots, validatePersistedBoundary, isTransientInBandRejection } from './order/utils/math.js';
|
|
12
|
+
import { ON_MISSING_GENESIS, isMissingGenesisError } from './order/genesis_policy.js';
|
|
12
13
|
import { hasExecutableActions } from './order/utils/validate.js';
|
|
13
14
|
import { getErrorMessage } from './utils/errors.js';
|
|
14
15
|
const { isGridBloated } = grid;
|
|
@@ -455,6 +456,26 @@ async function recoverFromPersistedGrid(bot) {
|
|
|
455
456
|
return { success: true };
|
|
456
457
|
}
|
|
457
458
|
catch (err) {
|
|
459
|
+
if (isMissingGenesisError(err)) {
|
|
460
|
+
// Fail closed on the snapshot, not on the manager: `loadGrid`
|
|
461
|
+
// refused it before touching any state. What happens next is the
|
|
462
|
+
// configured missing-genesis policy (docs/GRID_PRICE_INVARIANT.md):
|
|
463
|
+
// 'rebuild' -> fail the reload; the caller runs the structural
|
|
464
|
+
// resync, which re-derives the ladder from live config.
|
|
465
|
+
// 'halt' -> do NOT auto-rebuild; the operator must run a manual
|
|
466
|
+
// grid reset. Signalled to the caller with
|
|
467
|
+
// `halt: true` so it skips the resync branch.
|
|
468
|
+
if (err.policy === ON_MISSING_GENESIS.HALT) {
|
|
469
|
+
bot.manager.logger.log(`[RECOVERY] Refusing the persisted snapshot — no usable price ladder ` +
|
|
470
|
+
`(${err.reason}: ${err.detail}); missing-genesis policy='halt', so the automatic ` +
|
|
471
|
+
`structural resync is suppressed. Run a manual grid reset for this bot (or set ` +
|
|
472
|
+
`gridLimits.MISSING_GENESIS_POLICY=rebuild to auto-rebuild instead).`, 'error');
|
|
473
|
+
return { success: false, reason: `missing price ladder (${err.reason})`, halt: true };
|
|
474
|
+
}
|
|
475
|
+
bot.manager.logger.log(`[RECOVERY] Refusing the persisted snapshot — no usable price ladder ` +
|
|
476
|
+
`(${err.reason}: ${err.detail}). Escalating to a structural resync, which re-derives the ladder.`, 'error');
|
|
477
|
+
return { success: false, reason: `missing price ladder (${err.reason})` };
|
|
478
|
+
}
|
|
458
479
|
bot.manager.logger.log(`[RECOVERY] Full grid reload from persisted snapshot failed: ${getErrorMessage(err)}`, 'error');
|
|
459
480
|
return { success: false, reason: getErrorMessage(err) };
|
|
460
481
|
}
|
|
@@ -589,6 +610,18 @@ async function rejectCorruptedGridSnapshot(bot, context) {
|
|
|
589
610
|
// wiped the persisted copy; drop the in-memory record (marks the grid
|
|
590
611
|
// dirty so the wipe reaches disk on the next flush too).
|
|
591
612
|
bot.manager._clearPendingFillCrawls?.('grid snapshot rejected');
|
|
613
|
+
// The LAST-FILL-GUARD pivot was armed against the rejected generation's
|
|
614
|
+
// geometry: drop it so the rebuild re-arms on a fresh fill instead of
|
|
615
|
+
// vetoing placements against a boundary that no longer exists.
|
|
616
|
+
try {
|
|
617
|
+
if (typeof bot.manager._resetLastFillPivot === 'function') {
|
|
618
|
+
bot.manager._resetLastFillPivot('grid snapshot rejected');
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
resetLastFillPivot(bot.manager, 'grid snapshot rejected');
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
catch { }
|
|
592
625
|
return true;
|
|
593
626
|
}
|
|
594
627
|
/**
|
|
@@ -102,6 +102,7 @@ declare class AsyncLock {
|
|
|
102
102
|
private _holding;
|
|
103
103
|
private _syncPrologue;
|
|
104
104
|
private _generation;
|
|
105
|
+
private _heldSince;
|
|
105
106
|
private _defaultTimeout;
|
|
106
107
|
private _onContention;
|
|
107
108
|
private readonly _lockId;
|
|
@@ -121,6 +122,13 @@ declare class AsyncLock {
|
|
|
121
122
|
* @private
|
|
122
123
|
*/
|
|
123
124
|
private _processQueue;
|
|
125
|
+
/**
|
|
126
|
+
* Duration the lock has been held by its current callback.
|
|
127
|
+
* Returns 0 when the lock is not held. Observability only: callers use
|
|
128
|
+
* this to detect an over-long critical section, not to preempt it.
|
|
129
|
+
* @returns {number} Milliseconds since the callback began, or 0
|
|
130
|
+
*/
|
|
131
|
+
heldForMs(): number;
|
|
124
132
|
/**
|
|
125
133
|
* Check if lock is currently acquired
|
|
126
134
|
* @returns {boolean}
|
|
@@ -111,6 +111,7 @@ class AsyncLock {
|
|
|
111
111
|
_holding;
|
|
112
112
|
_syncPrologue;
|
|
113
113
|
_generation;
|
|
114
|
+
_heldSince;
|
|
114
115
|
_defaultTimeout;
|
|
115
116
|
_onContention;
|
|
116
117
|
_lockId;
|
|
@@ -121,6 +122,7 @@ class AsyncLock {
|
|
|
121
122
|
this._holding = false;
|
|
122
123
|
this._syncPrologue = false;
|
|
123
124
|
this._generation = 0;
|
|
125
|
+
this._heldSince = 0;
|
|
124
126
|
this._defaultTimeout = options.timeout || null;
|
|
125
127
|
this._onContention = options.onContention || null;
|
|
126
128
|
this._lockId = Symbol('AsyncLock');
|
|
@@ -243,6 +245,7 @@ class AsyncLock {
|
|
|
243
245
|
}
|
|
244
246
|
const generation = ++this._generation;
|
|
245
247
|
this._holding = true;
|
|
248
|
+
this._heldSince = Date.now();
|
|
246
249
|
try {
|
|
247
250
|
// Execute the callback (guaranteed to be alone)
|
|
248
251
|
const result = await callback();
|
|
@@ -259,6 +262,7 @@ class AsyncLock {
|
|
|
259
262
|
// be using it). The stale callback exits silently.
|
|
260
263
|
if (generation === this._generation) {
|
|
261
264
|
this._locked = false;
|
|
265
|
+
this._heldSince = 0;
|
|
262
266
|
this._processQueue();
|
|
263
267
|
}
|
|
264
268
|
else if (this._orphaned) {
|
|
@@ -270,6 +274,7 @@ class AsyncLock {
|
|
|
270
274
|
// finishes, blocking any new acquirer.
|
|
271
275
|
this._orphaned = false;
|
|
272
276
|
this._locked = false;
|
|
277
|
+
this._heldSince = 0;
|
|
273
278
|
this._processQueue();
|
|
274
279
|
}
|
|
275
280
|
// After a callback completes, if there are still queued items
|
|
@@ -282,6 +287,15 @@ class AsyncLock {
|
|
|
282
287
|
}
|
|
283
288
|
}
|
|
284
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Duration the lock has been held by its current callback.
|
|
292
|
+
* Returns 0 when the lock is not held. Observability only: callers use
|
|
293
|
+
* this to detect an over-long critical section, not to preempt it.
|
|
294
|
+
* @returns {number} Milliseconds since the callback began, or 0
|
|
295
|
+
*/
|
|
296
|
+
heldForMs() {
|
|
297
|
+
return this._locked && this._heldSince ? Date.now() - this._heldSince : 0;
|
|
298
|
+
}
|
|
285
299
|
/**
|
|
286
300
|
* Check if lock is currently acquired
|
|
287
301
|
* @returns {boolean}
|
|
@@ -371,6 +385,7 @@ class AsyncLock {
|
|
|
371
385
|
}
|
|
372
386
|
else {
|
|
373
387
|
this._locked = false;
|
|
388
|
+
this._heldSince = 0;
|
|
374
389
|
}
|
|
375
390
|
return count;
|
|
376
391
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/order/genesis_policy.ts - Genesis (price-ladder) establishment policy
|
|
3
|
+
*
|
|
4
|
+
* The genesis ladder is the ONLY authoritative price for a slot
|
|
5
|
+
* (docs/GRID_PRICE_INVARIANT.md, INV-GRID-004). A grid whose genesis is
|
|
6
|
+
* missing is therefore not a degraded grid -- it is an undefined one: every
|
|
7
|
+
* consumer that reads `priceForSlot(idx, genesis)` has no authority for a
|
|
8
|
+
* slot's price (nearest-slot adoption, the materialize descriptor-price
|
|
9
|
+
* fallback, reserve-edge anchoring, the `isSlotInRail` fail-open), and that is
|
|
10
|
+
* precisely the state on which an off-grid price became grid evidence and got
|
|
11
|
+
* re-emitted. The tolerance matcher that used to cover it has been removed:
|
|
12
|
+
* E2 refuses to sync such a grid and asks for the resync that re-derives the
|
|
13
|
+
* ladder.
|
|
14
|
+
*
|
|
15
|
+
* This module owns the single decision "can this snapshot have a ladder?",
|
|
16
|
+
* used by:
|
|
17
|
+
* - `grid.loadGrid` (E1, source choke point)
|
|
18
|
+
* - `dexbot_startup_runtime` (E3, startup gate before the first sync)
|
|
19
|
+
* - `order/sync_engine` (E2, defence-in-depth at the sync entry)
|
|
20
|
+
*
|
|
21
|
+
* See docs/GRID_PRICE_INVARIANT.md for the trigger taxonomy (T1-T4) and the
|
|
22
|
+
* option analysis that produced the fail-closed policy implemented here.
|
|
23
|
+
*
|
|
24
|
+
* Policy (GRID_LIMITS.MISSING_GENESIS_POLICY, default 'rebuild'):
|
|
25
|
+
* 'rebuild' - refuse the genesis-less snapshot and rebuild a clean ladder
|
|
26
|
+
* through the existing resync machinery (initializeGrid /
|
|
27
|
+
* recalculateGrid, which re-derive prices and reconcile
|
|
28
|
+
* update-first so only true surplus is cancelled).
|
|
29
|
+
* 'halt' - refuse to start; a human must run a manual grid reset.
|
|
30
|
+
*
|
|
31
|
+
* Deliberately NOT implemented (rejected in the analysis): adopting the
|
|
32
|
+
* config-derived ladder despite a >50% slot mismatch. That mass-virtualizes
|
|
33
|
+
* live order tracking and persists a genesis the live grid does not match --
|
|
34
|
+
* Option D ("always accept") in the paper, rejected as corruption risk.
|
|
35
|
+
*/
|
|
36
|
+
/** Why no ladder could be attached to a snapshot (paper T2-T4). */
|
|
37
|
+
export declare const MISSING_GENESIS_REASON: {
|
|
38
|
+
/** T2: the config-derived rail disagrees with >MISSING_GENESIS_MISMATCH_RATIO of the slots. */
|
|
39
|
+
readonly SLOT_MISMATCH: "slot_mismatch";
|
|
40
|
+
/** T3: startPrice/minPrice/maxPrice/incrementPercent are not finite numbers. */
|
|
41
|
+
readonly NON_FINITE_CONFIG: "non_finite_config";
|
|
42
|
+
/** T4: the migration ladder build threw. */
|
|
43
|
+
readonly MIGRATION_FAILED: "migration_failed";
|
|
44
|
+
};
|
|
45
|
+
export type MissingGenesisReason = (typeof MISSING_GENESIS_REASON)[keyof typeof MISSING_GENESIS_REASON];
|
|
46
|
+
export declare const ON_MISSING_GENESIS: {
|
|
47
|
+
readonly REBUILD: "rebuild";
|
|
48
|
+
readonly HALT: "halt";
|
|
49
|
+
};
|
|
50
|
+
export type OnMissingGenesisPolicy = (typeof ON_MISSING_GENESIS)[keyof typeof ON_MISSING_GENESIS];
|
|
51
|
+
/**
|
|
52
|
+
* Thrown by `loadGrid` (and the startup gate) when a snapshot carries orders
|
|
53
|
+
* but no usable ladder. Carries the policy so each caller can route the same
|
|
54
|
+
* fault to the right response without re-deciding it:
|
|
55
|
+
* - 'rebuild' -> caller rebuilds (startup regenerates, recovery reload
|
|
56
|
+
* fails closed into the structural resync, price-match resume
|
|
57
|
+
* reports "not resumed" and the caller regenerates)
|
|
58
|
+
* - 'halt' -> caller aborts startup
|
|
59
|
+
*/
|
|
60
|
+
export declare class MissingGenesisError extends Error {
|
|
61
|
+
readonly reason: string;
|
|
62
|
+
readonly detail: string;
|
|
63
|
+
readonly policy: OnMissingGenesisPolicy;
|
|
64
|
+
readonly mismatchRatio: number | null;
|
|
65
|
+
constructor(reason: string, detail: string, policy: OnMissingGenesisPolicy, mismatchRatio?: number | null);
|
|
66
|
+
}
|
|
67
|
+
/** True for a MissingGenesisError, including across module/realm duplication. */
|
|
68
|
+
export declare function isMissingGenesisError(err: any): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* True when `genesis` is a usable ladder: a non-empty priceLevels array. The
|
|
71
|
+
* hash is deliberately not required here -- a tampered hash is warned about
|
|
72
|
+
* and the ladder is still used for validation (the pre-existing contract), and
|
|
73
|
+
* the persisted-row schema check lives at the source (`AccountOrders.loadGenesis`).
|
|
74
|
+
*/
|
|
75
|
+
export declare function hasGenesisLadder(genesis: any): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Resolve the configured missing-genesis policy.
|
|
78
|
+
* Unknown/absent values fall back to the default ('rebuild'); only an explicit
|
|
79
|
+
* 'halt' opts into manual intervention.
|
|
80
|
+
* @param {any} config - Bot/manager config (reads `gridLimits.MISSING_GENESIS_POLICY`).
|
|
81
|
+
* @returns {OnMissingGenesisPolicy}
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolveOnMissingGenesisPolicy(config: any): OnMissingGenesisPolicy;
|
|
84
|
+
/** Ratio of persisted slots above which a config-derived rail is refused. */
|
|
85
|
+
export declare function resolveMismatchRatioLimit(config: any): number;
|
|
86
|
+
/**
|
|
87
|
+
* Build the migration ladder from the LIVE geometric rail
|
|
88
|
+
* (startPrice/minPrice/maxPrice/incrementPercent). The geometry itself comes
|
|
89
|
+
* from `derivePriceLevels` (modules/order/utils/math.ts), the same function
|
|
90
|
+
* `createOrderGrid` uses, so a migrated ladder cannot drift from a fresh build
|
|
91
|
+
* of the same config.
|
|
92
|
+
*
|
|
93
|
+
* Persisted slot prices are deliberately NOT used as the source: a truncated
|
|
94
|
+
* persisted array would permanently shrink the ladder.
|
|
95
|
+
* @returns {{ok: true, genesis: any} | {ok: false, reason: string, detail: string}}
|
|
96
|
+
*/
|
|
97
|
+
export declare function buildGenesisFromLiveRail(config: any): {
|
|
98
|
+
ok: true;
|
|
99
|
+
genesis: any;
|
|
100
|
+
} | {
|
|
101
|
+
ok: false;
|
|
102
|
+
reason: string;
|
|
103
|
+
detail: string;
|
|
104
|
+
};
|
|
105
|
+
export type GenesisResolution = {
|
|
106
|
+
ok: true;
|
|
107
|
+
genesis: any;
|
|
108
|
+
source: 'persisted' | 'in_memory' | 'migration';
|
|
109
|
+
} | {
|
|
110
|
+
ok: false;
|
|
111
|
+
reason: string;
|
|
112
|
+
detail: string;
|
|
113
|
+
mismatchRatio: number | null;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The single "can this snapshot have a ladder?" decision.
|
|
117
|
+
*
|
|
118
|
+
* Resolution order:
|
|
119
|
+
* 1. explicit `genesisInput` (persisted snapshot row) -> T1 path
|
|
120
|
+
* 2. `managerGenesis` (an in-process rebuild) -> adopted as-is
|
|
121
|
+
* 3. migration: build from the live config rail, then CROSS-CHECK it
|
|
122
|
+
* against the persisted slots. Adopt only while the mismatch ratio stays
|
|
123
|
+
* at or below `MISSING_GENESIS_MISMATCH_RATIO` (T1); above it the config
|
|
124
|
+
* was edited since the snapshot and the derived rail is a different
|
|
125
|
+
* generation (T2) -> refused.
|
|
126
|
+
*
|
|
127
|
+
* Non-numeric config (T3) and a throwing build (T4) are refused too. Nothing
|
|
128
|
+
* here mutates the manager or the grid -- callers decide what to do with a
|
|
129
|
+
* refusal (log + throw), which is what lets the startup gate evaluate the same
|
|
130
|
+
* verdict before it commits to a resume.
|
|
131
|
+
*
|
|
132
|
+
* @param {Object} params
|
|
133
|
+
* @param {any} params.config - Live bot/manager config.
|
|
134
|
+
* @param {any[]} params.grid - Persisted grid array (may be empty).
|
|
135
|
+
* @param {any} [params.genesisInput] - Genesis supplied by the caller (snapshot row).
|
|
136
|
+
* @param {any} [params.managerGenesis] - In-memory `manager._genesis`.
|
|
137
|
+
* @param {(msg: string, level?: string) => void} [params.log] - Logger sink for the cross-check verdict.
|
|
138
|
+
* @param {string} [params.validationMode] - 'log' | 'enforce', for the warning text only.
|
|
139
|
+
* @returns {GenesisResolution}
|
|
140
|
+
*/
|
|
141
|
+
export declare function resolvePersistedGenesis({ config, grid, genesisInput, managerGenesis, log, validationMode }: {
|
|
142
|
+
config: any;
|
|
143
|
+
grid: any;
|
|
144
|
+
genesisInput?: any;
|
|
145
|
+
managerGenesis?: any;
|
|
146
|
+
log?: (msg: string, level?: string) => void;
|
|
147
|
+
validationMode?: string;
|
|
148
|
+
}): GenesisResolution;
|
|
149
|
+
/**
|
|
150
|
+
* Build the fault object for a refused snapshot, recording the policy and the
|
|
151
|
+
* reason on the manager for observability (the soft half of the enforcement:
|
|
152
|
+
* a counter/log is what tells an operator T2-T4 ever fire in the wild).
|
|
153
|
+
* @param {any} manager
|
|
154
|
+
* @param {{reason: string, detail: string, mismatchRatio: number | null}} fault
|
|
155
|
+
* @returns {MissingGenesisError}
|
|
156
|
+
*/
|
|
157
|
+
export declare function recordMissingGenesisFault(manager: any, fault: {
|
|
158
|
+
reason: string;
|
|
159
|
+
detail: string;
|
|
160
|
+
mismatchRatio: number | null;
|
|
161
|
+
}): MissingGenesisError;
|
|
162
|
+
//# sourceMappingURL=genesis_policy.d.ts.map
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/order/genesis_policy.ts - Genesis (price-ladder) establishment policy
|
|
3
|
+
*
|
|
4
|
+
* The genesis ladder is the ONLY authoritative price for a slot
|
|
5
|
+
* (docs/GRID_PRICE_INVARIANT.md, INV-GRID-004). A grid whose genesis is
|
|
6
|
+
* missing is therefore not a degraded grid -- it is an undefined one: every
|
|
7
|
+
* consumer that reads `priceForSlot(idx, genesis)` has no authority for a
|
|
8
|
+
* slot's price (nearest-slot adoption, the materialize descriptor-price
|
|
9
|
+
* fallback, reserve-edge anchoring, the `isSlotInRail` fail-open), and that is
|
|
10
|
+
* precisely the state on which an off-grid price became grid evidence and got
|
|
11
|
+
* re-emitted. The tolerance matcher that used to cover it has been removed:
|
|
12
|
+
* E2 refuses to sync such a grid and asks for the resync that re-derives the
|
|
13
|
+
* ladder.
|
|
14
|
+
*
|
|
15
|
+
* This module owns the single decision "can this snapshot have a ladder?",
|
|
16
|
+
* used by:
|
|
17
|
+
* - `grid.loadGrid` (E1, source choke point)
|
|
18
|
+
* - `dexbot_startup_runtime` (E3, startup gate before the first sync)
|
|
19
|
+
* - `order/sync_engine` (E2, defence-in-depth at the sync entry)
|
|
20
|
+
*
|
|
21
|
+
* See docs/GRID_PRICE_INVARIANT.md for the trigger taxonomy (T1-T4) and the
|
|
22
|
+
* option analysis that produced the fail-closed policy implemented here.
|
|
23
|
+
*
|
|
24
|
+
* Policy (GRID_LIMITS.MISSING_GENESIS_POLICY, default 'rebuild'):
|
|
25
|
+
* 'rebuild' - refuse the genesis-less snapshot and rebuild a clean ladder
|
|
26
|
+
* through the existing resync machinery (initializeGrid /
|
|
27
|
+
* recalculateGrid, which re-derive prices and reconcile
|
|
28
|
+
* update-first so only true surplus is cancelled).
|
|
29
|
+
* 'halt' - refuse to start; a human must run a manual grid reset.
|
|
30
|
+
*
|
|
31
|
+
* Deliberately NOT implemented (rejected in the analysis): adopting the
|
|
32
|
+
* config-derived ladder despite a >50% slot mismatch. That mass-virtualizes
|
|
33
|
+
* live order tracking and persists a genesis the live grid does not match --
|
|
34
|
+
* Option D ("always accept") in the paper, rejected as corruption risk.
|
|
35
|
+
*/
|
|
36
|
+
import { GRID_LIMITS } from '../constants.js';
|
|
37
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
38
|
+
import { assertSlotPriceInvariant, buildGenesisFromPriceLevels, calculateGapSlots, derivePriceLevels } from './utils/math.js';
|
|
39
|
+
/** Why no ladder could be attached to a snapshot (paper T2-T4). */
|
|
40
|
+
export const MISSING_GENESIS_REASON = {
|
|
41
|
+
/** T2: the config-derived rail disagrees with >MISSING_GENESIS_MISMATCH_RATIO of the slots. */
|
|
42
|
+
SLOT_MISMATCH: 'slot_mismatch',
|
|
43
|
+
/** T3: startPrice/minPrice/maxPrice/incrementPercent are not finite numbers. */
|
|
44
|
+
NON_FINITE_CONFIG: 'non_finite_config',
|
|
45
|
+
/** T4: the migration ladder build threw. */
|
|
46
|
+
MIGRATION_FAILED: 'migration_failed'
|
|
47
|
+
};
|
|
48
|
+
export const ON_MISSING_GENESIS = {
|
|
49
|
+
REBUILD: 'rebuild',
|
|
50
|
+
HALT: 'halt'
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Thrown by `loadGrid` (and the startup gate) when a snapshot carries orders
|
|
54
|
+
* but no usable ladder. Carries the policy so each caller can route the same
|
|
55
|
+
* fault to the right response without re-deciding it:
|
|
56
|
+
* - 'rebuild' -> caller rebuilds (startup regenerates, recovery reload
|
|
57
|
+
* fails closed into the structural resync, price-match resume
|
|
58
|
+
* reports "not resumed" and the caller regenerates)
|
|
59
|
+
* - 'halt' -> caller aborts startup
|
|
60
|
+
*/
|
|
61
|
+
export class MissingGenesisError extends Error {
|
|
62
|
+
reason;
|
|
63
|
+
detail;
|
|
64
|
+
policy;
|
|
65
|
+
mismatchRatio;
|
|
66
|
+
constructor(reason, detail, policy, mismatchRatio = null) {
|
|
67
|
+
super(`[GENESIS] Persisted grid has no usable price ladder (${reason}: ${detail}); ` +
|
|
68
|
+
`missing-genesis policy='${policy}'`);
|
|
69
|
+
this.name = 'MissingGenesisError';
|
|
70
|
+
this.reason = reason;
|
|
71
|
+
this.detail = detail;
|
|
72
|
+
this.policy = policy;
|
|
73
|
+
this.mismatchRatio = mismatchRatio;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** True for a MissingGenesisError, including across module/realm duplication. */
|
|
77
|
+
export function isMissingGenesisError(err) {
|
|
78
|
+
if (err instanceof MissingGenesisError)
|
|
79
|
+
return true;
|
|
80
|
+
return !!err && typeof err === 'object' && err.name === 'MissingGenesisError' && typeof err.reason === 'string';
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* True when `genesis` is a usable ladder: a non-empty priceLevels array. The
|
|
84
|
+
* hash is deliberately not required here -- a tampered hash is warned about
|
|
85
|
+
* and the ladder is still used for validation (the pre-existing contract), and
|
|
86
|
+
* the persisted-row schema check lives at the source (`AccountOrders.loadGenesis`).
|
|
87
|
+
*/
|
|
88
|
+
export function hasGenesisLadder(genesis) {
|
|
89
|
+
return !!genesis && Array.isArray(genesis.priceLevels) && genesis.priceLevels.length > 0;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the configured missing-genesis policy.
|
|
93
|
+
* Unknown/absent values fall back to the default ('rebuild'); only an explicit
|
|
94
|
+
* 'halt' opts into manual intervention.
|
|
95
|
+
* @param {any} config - Bot/manager config (reads `gridLimits.MISSING_GENESIS_POLICY`).
|
|
96
|
+
* @returns {OnMissingGenesisPolicy}
|
|
97
|
+
*/
|
|
98
|
+
export function resolveOnMissingGenesisPolicy(config) {
|
|
99
|
+
const raw = config?.gridLimits?.MISSING_GENESIS_POLICY ?? GRID_LIMITS.MISSING_GENESIS_POLICY;
|
|
100
|
+
const normalized = typeof raw === 'string' ? raw.trim().toLowerCase() : '';
|
|
101
|
+
return normalized === ON_MISSING_GENESIS.HALT ? ON_MISSING_GENESIS.HALT : ON_MISSING_GENESIS.REBUILD;
|
|
102
|
+
}
|
|
103
|
+
/** Ratio of persisted slots above which a config-derived rail is refused. */
|
|
104
|
+
export function resolveMismatchRatioLimit(config) {
|
|
105
|
+
const raw = Number(config?.gridLimits?.MISSING_GENESIS_MISMATCH_RATIO);
|
|
106
|
+
if (Number.isFinite(raw) && raw >= 0 && raw <= 1)
|
|
107
|
+
return raw;
|
|
108
|
+
return Number(GRID_LIMITS.MISSING_GENESIS_MISMATCH_RATIO);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build the migration ladder from the LIVE geometric rail
|
|
112
|
+
* (startPrice/minPrice/maxPrice/incrementPercent). The geometry itself comes
|
|
113
|
+
* from `derivePriceLevels` (modules/order/utils/math.ts), the same function
|
|
114
|
+
* `createOrderGrid` uses, so a migrated ladder cannot drift from a fresh build
|
|
115
|
+
* of the same config.
|
|
116
|
+
*
|
|
117
|
+
* Persisted slot prices are deliberately NOT used as the source: a truncated
|
|
118
|
+
* persisted array would permanently shrink the ladder.
|
|
119
|
+
* @returns {{ok: true, genesis: any} | {ok: false, reason: string, detail: string}}
|
|
120
|
+
*/
|
|
121
|
+
export function buildGenesisFromLiveRail(config) {
|
|
122
|
+
const startPrice = Number(config?.startPrice);
|
|
123
|
+
const minPrice = Number(config?.minPrice);
|
|
124
|
+
const maxPrice = Number(config?.maxPrice);
|
|
125
|
+
const incPct = Number(config?.incrementPercent);
|
|
126
|
+
const nonFinite = [
|
|
127
|
+
['startPrice', config?.startPrice],
|
|
128
|
+
['minPrice', config?.minPrice],
|
|
129
|
+
['maxPrice', config?.maxPrice],
|
|
130
|
+
['incrementPercent', config?.incrementPercent]
|
|
131
|
+
].filter(([, v]) => !Number.isFinite(Number(v)))
|
|
132
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
133
|
+
if (nonFinite.length > 0) {
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
reason: MISSING_GENESIS_REASON.NON_FINITE_CONFIG,
|
|
137
|
+
detail: `grid rail config is not numeric (${nonFinite.join(', ')}); ` +
|
|
138
|
+
`an unresolved price mode (e.g. "pool") must be derived by initializeGrid before a ladder can be built`
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
// Same geometry as createOrderGrid (one shared source), so the migrated
|
|
143
|
+
// ladder matches what a fresh build would produce for this config.
|
|
144
|
+
const priceLevels = derivePriceLevels(startPrice, minPrice, maxPrice, incPct);
|
|
145
|
+
const gapSlotsForGenesis = calculateGapSlots(incPct, config?.targetSpreadPercent, config?.gridLimits);
|
|
146
|
+
return { ok: true, genesis: buildGenesisFromPriceLevels(startPrice, incPct, gapSlotsForGenesis, priceLevels) };
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
reason: MISSING_GENESIS_REASON.MIGRATION_FAILED,
|
|
152
|
+
detail: `ladder build threw: ${getErrorMessage(e)}`
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The single "can this snapshot have a ladder?" decision.
|
|
158
|
+
*
|
|
159
|
+
* Resolution order:
|
|
160
|
+
* 1. explicit `genesisInput` (persisted snapshot row) -> T1 path
|
|
161
|
+
* 2. `managerGenesis` (an in-process rebuild) -> adopted as-is
|
|
162
|
+
* 3. migration: build from the live config rail, then CROSS-CHECK it
|
|
163
|
+
* against the persisted slots. Adopt only while the mismatch ratio stays
|
|
164
|
+
* at or below `MISSING_GENESIS_MISMATCH_RATIO` (T1); above it the config
|
|
165
|
+
* was edited since the snapshot and the derived rail is a different
|
|
166
|
+
* generation (T2) -> refused.
|
|
167
|
+
*
|
|
168
|
+
* Non-numeric config (T3) and a throwing build (T4) are refused too. Nothing
|
|
169
|
+
* here mutates the manager or the grid -- callers decide what to do with a
|
|
170
|
+
* refusal (log + throw), which is what lets the startup gate evaluate the same
|
|
171
|
+
* verdict before it commits to a resume.
|
|
172
|
+
*
|
|
173
|
+
* @param {Object} params
|
|
174
|
+
* @param {any} params.config - Live bot/manager config.
|
|
175
|
+
* @param {any[]} params.grid - Persisted grid array (may be empty).
|
|
176
|
+
* @param {any} [params.genesisInput] - Genesis supplied by the caller (snapshot row).
|
|
177
|
+
* @param {any} [params.managerGenesis] - In-memory `manager._genesis`.
|
|
178
|
+
* @param {(msg: string, level?: string) => void} [params.log] - Logger sink for the cross-check verdict.
|
|
179
|
+
* @param {string} [params.validationMode] - 'log' | 'enforce', for the warning text only.
|
|
180
|
+
* @returns {GenesisResolution}
|
|
181
|
+
*/
|
|
182
|
+
export function resolvePersistedGenesis({ config, grid, genesisInput = null, managerGenesis = null, log, validationMode = 'log' }) {
|
|
183
|
+
const slots = Array.isArray(grid) ? grid : [];
|
|
184
|
+
const emit = (msg, level = 'warn') => { try {
|
|
185
|
+
log?.(msg, level);
|
|
186
|
+
}
|
|
187
|
+
catch { /* logging must never fail the load */ } };
|
|
188
|
+
if (hasGenesisLadder(genesisInput)) {
|
|
189
|
+
return { ok: true, genesis: genesisInput, source: 'persisted' };
|
|
190
|
+
}
|
|
191
|
+
if (hasGenesisLadder(managerGenesis)) {
|
|
192
|
+
return { ok: true, genesis: managerGenesis, source: 'in_memory' };
|
|
193
|
+
}
|
|
194
|
+
// No orders on the snapshot: there is nothing to price-match, so a missing
|
|
195
|
+
// ladder is not a fault (the fresh grid build establishes it).
|
|
196
|
+
if (slots.length === 0) {
|
|
197
|
+
return { ok: true, genesis: null, source: 'migration' };
|
|
198
|
+
}
|
|
199
|
+
const built = buildGenesisFromLiveRail(config);
|
|
200
|
+
if (!built.ok) {
|
|
201
|
+
emit(`[GENESIS] Cannot migrate the persisted grid: ${built.detail} — ` +
|
|
202
|
+
`no ladder available, refusing to load the snapshot without one`, 'error');
|
|
203
|
+
return { ok: false, reason: built.reason, detail: built.detail, mismatchRatio: null };
|
|
204
|
+
}
|
|
205
|
+
// Cross-check the derived rail against the persisted slots. A user who
|
|
206
|
+
// edited startPrice/min/max/increment across restarts gets a rail the live
|
|
207
|
+
// grid does not match: adopting it would mass-virtualize tracking (enforce)
|
|
208
|
+
// or flood the log (log) and persist a mismatched genesis.
|
|
209
|
+
let mismatchCount = 0;
|
|
210
|
+
for (const slot of slots) {
|
|
211
|
+
try {
|
|
212
|
+
assertSlotPriceInvariant(slot, built.genesis);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
mismatchCount++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const mismatchRatio = slots.length > 0 ? mismatchCount / slots.length : 0;
|
|
219
|
+
const ratioLimit = resolveMismatchRatioLimit(config);
|
|
220
|
+
if (mismatchRatio > ratioLimit) {
|
|
221
|
+
emit(`[GENESIS] Migration: ${mismatchCount}/${slots.length} slots mismatch new-config rail ` +
|
|
222
|
+
`(ratio ${mismatchRatio.toFixed(2)} > ${ratioLimit}) — config may have changed since snapshot; ` +
|
|
223
|
+
`NOT adopting migration genesis (validation would ${validationMode === 'enforce' ? 'mass-virtualize' : 'be noisy'})`, 'warn');
|
|
224
|
+
return {
|
|
225
|
+
ok: false,
|
|
226
|
+
reason: MISSING_GENESIS_REASON.SLOT_MISMATCH,
|
|
227
|
+
detail: `${mismatchCount}/${slots.length} slots mismatch the config-derived rail ` +
|
|
228
|
+
`(ratio ${mismatchRatio.toFixed(2)} > ${ratioLimit}) — the config was edited since the snapshot, ` +
|
|
229
|
+
`so the derived rail is a different generation`,
|
|
230
|
+
mismatchRatio
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (mismatchCount > 0) {
|
|
234
|
+
emit(`[GENESIS] Migration: ${mismatchCount}/${slots.length} slots mismatch new-config rail — ` +
|
|
235
|
+
`will be logged${validationMode === 'enforce' ? '/virtualized' : ''} on next load`, 'warn');
|
|
236
|
+
}
|
|
237
|
+
return { ok: true, genesis: built.genesis, source: 'migration' };
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Build the fault object for a refused snapshot, recording the policy and the
|
|
241
|
+
* reason on the manager for observability (the soft half of the enforcement:
|
|
242
|
+
* a counter/log is what tells an operator T2-T4 ever fire in the wild).
|
|
243
|
+
* @param {any} manager
|
|
244
|
+
* @param {{reason: string, detail: string, mismatchRatio: number | null}} fault
|
|
245
|
+
* @returns {MissingGenesisError}
|
|
246
|
+
*/
|
|
247
|
+
export function recordMissingGenesisFault(manager, fault) {
|
|
248
|
+
const policy = resolveOnMissingGenesisPolicy(manager?.config);
|
|
249
|
+
try {
|
|
250
|
+
manager._missingGenesis = {
|
|
251
|
+
reason: fault.reason,
|
|
252
|
+
detail: fault.detail,
|
|
253
|
+
mismatchRatio: fault.mismatchRatio ?? null,
|
|
254
|
+
policy,
|
|
255
|
+
at: Date.now()
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
catch { /* frozen/absent manager field must not mask the refusal */ }
|
|
259
|
+
const guidance = policy === ON_MISSING_GENESIS.HALT
|
|
260
|
+
? 'refusing to load the snapshot — run a manual grid reset for this bot ' +
|
|
261
|
+
'(or set gridLimits.MISSING_GENESIS_POLICY=rebuild to auto-rebuild instead)'
|
|
262
|
+
: 'refusing to load the snapshot — the caller must rebuild a clean price ladder ' +
|
|
263
|
+
'from live config before syncing';
|
|
264
|
+
manager?.logger?.log?.(`[GENESIS] No usable price ladder for the persisted grid (${fault.reason}: ${fault.detail}); ${guidance}`, 'error');
|
|
265
|
+
return new MissingGenesisError(fault.reason, fault.detail, policy, fault.mismatchRatio ?? null);
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=genesis_policy.js.map
|