dexbot 1.6.11 → 1.6.13
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 +67 -4
- package/README.md +2 -1
- package/analysis/README.md +11 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/launcher_mode_detector.ts +9 -2
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +2 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +3 -21
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +55 -45
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -8
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +45 -24
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +34 -78
- package/dist/analysis/analyze_args.d.ts +43 -0
- package/dist/analysis/analyze_args.js +61 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -17
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +221 -28
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +23 -103
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +32 -150
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +77 -9
- package/dist/analysis/bot_fitting/shared_utils.js +125 -9
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +7 -4
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +35 -3
- package/dist/analysis/chart_ui.js +43 -4
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +4 -24
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +33 -3
- package/dist/analysis/fills_source.js +83 -13
- package/dist/analysis/grid_correction_check.d.ts +2 -24
- package/dist/analysis/grid_correction_check.js +27 -69
- package/dist/analysis/math_utils.d.ts +91 -6
- package/dist/analysis/math_utils.js +119 -7
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +30 -9
- package/dist/analysis/price_sources.js +28 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +29 -2
- package/dist/analysis/trade_profitability.js +73 -147
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -8
- package/dist/analysis/tradingview/analyze_tradingview.js +7 -6
- package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
- package/dist/analysis/tradingview/grid_reset_config.js +23 -11
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
- package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -34
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +26 -84
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +16 -41
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
- package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +78 -59
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +29 -19
- package/dist/market_adapter/candle_utils.js +35 -21
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +56 -19
- package/dist/market_adapter/core/kibana_candles.js +12 -9
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +320 -153
- package/dist/market_adapter/core/market_adapter_service.js +228 -269
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +2 -4
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -2
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +160 -332
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +50 -8
- package/dist/market_adapter/inputs/fetch_lp_data.js +47 -22
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +26 -41
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +93 -156
- package/dist/market_adapter/inputs/window_cache.js +59 -184
- package/dist/market_adapter/interval_utils.d.ts +15 -5
- package/dist/market_adapter/interval_utils.js +16 -1
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -21
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +10 -7
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -32
- package/dist/market_adapter/market_adapter.js +94 -120
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +49 -2
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +578 -21
- package/dist/modules/account_bots.js +272 -267
- package/dist/modules/account_orders.d.ts +79 -30
- package/dist/modules/account_orders.js +60 -64
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +39 -4
- package/dist/modules/bitshares-native/chain_client.js +59 -59
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/resolvers.js +22 -25
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +73 -108
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +8 -16
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +4 -3
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +94 -60
- package/dist/modules/chain_orders.js +81 -118
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/constants.d.ts +534 -32
- package/dist/modules/constants.js +35 -48
- package/dist/modules/cr_planner.d.ts +41 -3
- package/dist/modules/cr_planner.js +1 -5
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +43 -6
- package/dist/modules/credit_pricing.js +70 -60
- package/dist/modules/credit_runtime.d.ts +283 -118
- package/dist/modules/credit_runtime.js +500 -231
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +213 -146
- package/dist/modules/dexbot_class.js +183 -86
- package/dist/modules/dexbot_cow_runtime.d.ts +160 -87
- package/dist/modules/dexbot_cow_runtime.js +302 -234
- package/dist/modules/dexbot_credential_client.d.ts +19 -18
- package/dist/modules/dexbot_credential_client.js +1 -2
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -49
- package/dist/modules/dexbot_fill_runtime.js +53 -47
- package/dist/modules/dexbot_maintenance_runtime.d.ts +127 -71
- package/dist/modules/dexbot_maintenance_runtime.js +187 -147
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -11
- package/dist/modules/dexbot_startup_runtime.js +56 -57
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +19 -13
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -7
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +16 -15
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +16 -7
- package/dist/modules/order/format.js +15 -3
- package/dist/modules/order/genesis_policy.d.ts +24 -21
- package/dist/modules/order/genesis_policy.js +17 -10
- package/dist/modules/order/grid.d.ts +144 -36
- package/dist/modules/order/grid.js +226 -145
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +264 -1
- package/dist/modules/order/logger.d.ts +46 -19
- package/dist/modules/order/logger.js +38 -49
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +232 -191
- package/dist/modules/order/manager.js +110 -130
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +84 -53
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +310 -110
- package/dist/modules/order/utils/order.js +153 -126
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +156 -26
- package/dist/modules/order/utils/system.js +103 -71
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +26 -24
- package/dist/modules/order/utils/withPoolRef.d.ts +6 -4
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +1 -4
- package/dist/modules/paths.js +33 -61
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +14 -11
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +9 -5
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1090 -6
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +24 -4
- package/dist/modules/utils/time_range.d.ts +1 -12
- package/dist/modules/utils/time_range.js +1 -1
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +23 -11
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +28 -27
- package/dist/pm2.js +61 -40
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-git.js +2 -15
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +65 -40
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +15 -13
- package/dist/scripts/check_any.d.ts +22 -0
- package/dist/scripts/check_any.js +158 -0
- package/dist/scripts/diagnose-pool-history.js +13 -13
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -8
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/sync-version.js +0 -10
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +63 -35
- package/docs/BITSHARES_ONBOARDING.md +10 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -2
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +4 -2
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +14 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +31 -19
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +12 -5
- package/modules/README.md +4 -1
- package/package.json +9 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +25 -10
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -61,13 +61,25 @@
|
|
|
61
61
|
*/
|
|
62
62
|
import Logger from './order/logger.js';
|
|
63
63
|
import { runtime } from './runtime.js';
|
|
64
|
-
import { getErrorMessage } from './utils/errors.js';
|
|
64
|
+
import { getErrorMessage, getErrorField } from './utils/errors.js';
|
|
65
65
|
import { withTimeout } from './order/utils/timeout.js';
|
|
66
66
|
const CLEANUP_HANDLER_TIMEOUT_MS = 10000;
|
|
67
67
|
let cleanupHandlers = [];
|
|
68
68
|
let shutdownInProgress = false;
|
|
69
69
|
const shutdownLogger = new Logger('Shutdown');
|
|
70
70
|
const exitWipeCallbacks = [];
|
|
71
|
+
/**
|
|
72
|
+
* Shared registration guard for the cleanup and exit-wipe lists. Both hold
|
|
73
|
+
* `{ name, handler }` records and reject non-function handlers, so the
|
|
74
|
+
* validation and push live in one place.
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
function registerHandler(list, name, handler, label) {
|
|
78
|
+
if (typeof handler !== 'function') {
|
|
79
|
+
throw new Error(`${label} for '${name}' must be a function`);
|
|
80
|
+
}
|
|
81
|
+
list.push({ name, handler });
|
|
82
|
+
}
|
|
71
83
|
/**
|
|
72
84
|
* Register a synchronous wipe callback that runs AFTER all LIFO cleanup
|
|
73
85
|
* handlers have completed, immediately before process exit. Unlike regular
|
|
@@ -79,10 +91,7 @@ const exitWipeCallbacks = [];
|
|
|
79
91
|
* @param {Function} wipeFn - Synchronous function to execute last
|
|
80
92
|
*/
|
|
81
93
|
function registerExitWipe(name, wipeFn) {
|
|
82
|
-
|
|
83
|
-
throw new Error(`Exit wipe callback for '${name}' must be a function`);
|
|
84
|
-
}
|
|
85
|
-
exitWipeCallbacks.push({ name, wipeFn });
|
|
94
|
+
registerHandler(exitWipeCallbacks, name, wipeFn, 'Exit wipe callback');
|
|
86
95
|
}
|
|
87
96
|
/**
|
|
88
97
|
* Register a cleanup function to be called on graceful shutdown
|
|
@@ -91,10 +100,7 @@ function registerExitWipe(name, wipeFn) {
|
|
|
91
100
|
* @param {Function} handler - Async or sync function to call on shutdown
|
|
92
101
|
*/
|
|
93
102
|
function registerCleanup(name, handler) {
|
|
94
|
-
|
|
95
|
-
throw new Error(`Cleanup handler for '${name}' must be a function`);
|
|
96
|
-
}
|
|
97
|
-
cleanupHandlers.push({ name, handler });
|
|
103
|
+
registerHandler(cleanupHandlers, name, handler, 'Cleanup handler');
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
100
106
|
* Remove a previously registered cleanup function.
|
|
@@ -155,9 +161,9 @@ async function executeCleanup() {
|
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
for (let i = 0; i < exitWipeCallbacks.length; i++) {
|
|
158
|
-
const { name,
|
|
164
|
+
const { name, handler } = exitWipeCallbacks[i];
|
|
159
165
|
try {
|
|
160
|
-
|
|
166
|
+
handler();
|
|
161
167
|
shutdownLogger.info(`✓ ${name} (exit wipe)`);
|
|
162
168
|
}
|
|
163
169
|
catch (err) {
|
|
@@ -186,7 +192,7 @@ function setupGracefulShutdown() {
|
|
|
186
192
|
runtime.onSignal('exit', () => {
|
|
187
193
|
for (let i = 0; i < exitWipeCallbacks.length; i++) {
|
|
188
194
|
try {
|
|
189
|
-
exitWipeCallbacks[i].
|
|
195
|
+
exitWipeCallbacks[i].handler();
|
|
190
196
|
}
|
|
191
197
|
catch (_) { }
|
|
192
198
|
}
|
|
@@ -200,7 +206,7 @@ function setupGracefulShutdown() {
|
|
|
200
206
|
});
|
|
201
207
|
// Handle unhandled rejections
|
|
202
208
|
runtime.onSignal('unhandledRejection', async (reason, promise) => {
|
|
203
|
-
shutdownLogger.error(`Unhandled rejection at: ${promise} reason: ${reason
|
|
209
|
+
shutdownLogger.error(`Unhandled rejection at: ${promise} reason: ${getErrorField(reason, 'stack') || reason}`);
|
|
204
210
|
await executeCleanup();
|
|
205
211
|
runtime.exitAfterStderrDrain(1);
|
|
206
212
|
});
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* @param {Object} bot - Bot configuration object
|
|
15
15
|
* @returns {boolean} True if gridPrice starts with 'ama' (ama, ama1..ama4)
|
|
16
16
|
*/
|
|
17
|
-
declare function usesAmaGridPrice(bot:
|
|
17
|
+
declare function usesAmaGridPrice(bot: Record<string, unknown> | null | undefined): boolean;
|
|
18
18
|
export { usesAmaGridPrice };
|
|
19
19
|
//# sourceMappingURL=grid_price_source.d.ts.map
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
+
/** One chain operation to sign/broadcast. */
|
|
2
|
+
interface ChainOrderOperation {
|
|
3
|
+
op_name: string;
|
|
4
|
+
op_data: unknown;
|
|
5
|
+
}
|
|
1
6
|
export interface SigningResult {
|
|
2
7
|
success: boolean;
|
|
3
|
-
raw?:
|
|
4
|
-
operation_results?:
|
|
8
|
+
raw?: unknown;
|
|
9
|
+
operation_results?: unknown[];
|
|
5
10
|
}
|
|
6
11
|
export interface KeyStore {
|
|
7
|
-
resolveSigningKey(accountName: string, vaultSecret?:
|
|
8
|
-
isDaemonSigningKey(key:
|
|
9
|
-
executeOperations(accountName: string, operations:
|
|
12
|
+
resolveSigningKey(accountName: string, vaultSecret?: unknown, chainClient?: unknown): Promise<unknown>;
|
|
13
|
+
isDaemonSigningKey(key: unknown): boolean;
|
|
14
|
+
executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
|
|
10
15
|
}
|
|
11
16
|
export declare class DaemonKeyStore implements KeyStore {
|
|
12
|
-
resolveSigningKey(accountName: string, vaultSecret?:
|
|
13
|
-
isDaemonSigningKey(key:
|
|
14
|
-
executeOperations(accountName: string, operations:
|
|
17
|
+
resolveSigningKey(accountName: string, vaultSecret?: unknown, chainClient?: unknown): Promise<unknown>;
|
|
18
|
+
isDaemonSigningKey(key: unknown): boolean;
|
|
19
|
+
executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
|
|
15
20
|
}
|
|
16
21
|
export declare function setKeyStore(impl: KeyStore | null): void;
|
|
17
22
|
export declare function resetKeyStore(): void;
|
|
18
23
|
export declare function getKeyStore(): KeyStore;
|
|
24
|
+
export {};
|
|
19
25
|
//# sourceMappingURL=key_store.d.ts.map
|
|
@@ -42,7 +42,6 @@ function buildDaemonBroadcastOptions(signingKey, extraOptions, sessionIdOverride
|
|
|
42
42
|
requestType: 'broadcast',
|
|
43
43
|
batchId: signingKey.batchId || null,
|
|
44
44
|
...(extraOptions.nodeUrl ? { nodeUrl: extraOptions.nodeUrl } : {}),
|
|
45
|
-
...(extraOptions.fallbackNodes ? { fallbackNodes: extraOptions.fallbackNodes } : {}),
|
|
46
45
|
...(typeof extraOptions.onNodeFailed === 'function' ? { onNodeFailed: extraOptions.onNodeFailed } : {}),
|
|
47
46
|
};
|
|
48
47
|
}
|
|
@@ -95,14 +94,15 @@ export class DaemonKeyStore {
|
|
|
95
94
|
return chainKeys.isDaemonSigningToken(key);
|
|
96
95
|
}
|
|
97
96
|
async executeOperations(accountName, operations, signingKey, extraOptions = {}) {
|
|
97
|
+
const daemonKey = signingKey;
|
|
98
98
|
if (this.isDaemonSigningKey(signingKey)) {
|
|
99
|
-
if (!
|
|
99
|
+
if (!daemonKey.botHmacSecret) {
|
|
100
100
|
keyStoreLogger.error(`Daemon signing token for ${accountName} has no botHmacSecret — the daemon will reject this request ` +
|
|
101
101
|
`(Strict Mode). This happens when a broadcast is attempted after the bot shut down or the token lost ` +
|
|
102
102
|
`its secret. Restarting the bot resolves it.`);
|
|
103
103
|
}
|
|
104
104
|
try {
|
|
105
|
-
const result = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(
|
|
105
|
+
const result = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(daemonKey, extraOptions));
|
|
106
106
|
return normalizeDaemonResult(result);
|
|
107
107
|
}
|
|
108
108
|
catch (err) {
|
|
@@ -123,19 +123,19 @@ export class DaemonKeyStore {
|
|
|
123
123
|
catch { }
|
|
124
124
|
}
|
|
125
125
|
const newSessionId = await chainKeys.probeAccountInDaemon(accountName);
|
|
126
|
-
|
|
126
|
+
daemonKey.sessionId = newSessionId;
|
|
127
127
|
if (isSourceAuthError) {
|
|
128
128
|
try {
|
|
129
129
|
const freshSecret = credentialPolicy.loadBotHmacSecret(accountName, PATHS.PROFILES.DAEMON_POLICIES_JSON, { quiet: true });
|
|
130
|
-
if (freshSecret && freshSecret !==
|
|
131
|
-
|
|
130
|
+
if (freshSecret && freshSecret !== daemonKey.botHmacSecret) {
|
|
131
|
+
daemonKey.botHmacSecret = freshSecret;
|
|
132
132
|
keyStoreLogger.warn(`Reloaded botHmacSecret from disk for ${accountName} before retry`);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
catch (_) { }
|
|
136
136
|
await sleep(500);
|
|
137
137
|
}
|
|
138
|
-
const retryResult = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(
|
|
138
|
+
const retryResult = await executeOperationsViaCredentialDaemon(accountName, operations, buildDaemonBroadcastOptions(daemonKey, extraOptions, daemonKey.sessionId ?? undefined));
|
|
139
139
|
return normalizeDaemonResult(retryResult);
|
|
140
140
|
}
|
|
141
141
|
throw err;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
interface AdapterBotConfig {
|
|
2
|
+
name?: string;
|
|
3
|
+
gridPrice?: unknown;
|
|
4
|
+
active?: boolean;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
1
7
|
/**
|
|
2
8
|
* Check whether the unlock wrapper owns the market adapter lifecycle.
|
|
3
9
|
* Bots skip their own adapter sync/poll when this is true.
|
|
4
10
|
* @param {NodeJS.ProcessEnv} [env=process.env] - Environment to inspect
|
|
5
11
|
* @returns {boolean} True when running as a wrapper-supervised bot child
|
|
6
12
|
*/
|
|
7
|
-
declare function isWrapperAdapterOwner(env?:
|
|
13
|
+
declare function isWrapperAdapterOwner(env?: Record<string, string | undefined>): boolean;
|
|
8
14
|
/**
|
|
9
15
|
* Build the semantic adapter fingerprint for an active-bot list.
|
|
10
16
|
* Only AMA-priced bots contribute; sorted so bot order is irrelevant.
|
|
11
|
-
* @param {
|
|
17
|
+
* @param {unknown[]} activeBots - Bots with active !== false
|
|
12
18
|
* @returns {string} Fingerprint ('' when no AMA bot is active)
|
|
13
19
|
*/
|
|
14
|
-
declare function buildAdapterFingerprint(activeBots:
|
|
20
|
+
declare function buildAdapterFingerprint(activeBots: AdapterBotConfig[]): string;
|
|
15
21
|
/**
|
|
16
22
|
* Read bots.json and summarize the market-adapter requirement.
|
|
17
23
|
* Never throws: missing/empty files report exists:false, unparseable files
|
|
@@ -24,8 +30,8 @@ declare function buildAdapterFingerprint(activeBots: any[]): string;
|
|
|
24
30
|
declare function readAdapterRequirement(botsFile?: string): {
|
|
25
31
|
exists: boolean;
|
|
26
32
|
fingerprint: string;
|
|
27
|
-
config:
|
|
28
|
-
activeBots:
|
|
33
|
+
config: unknown;
|
|
34
|
+
activeBots: AdapterBotConfig[];
|
|
29
35
|
needsMarketAdapter: boolean;
|
|
30
36
|
corrupt?: boolean;
|
|
31
37
|
readError?: boolean;
|
|
@@ -65,7 +65,7 @@ function normalizeGridPrice(value) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Build the semantic adapter fingerprint for an active-bot list.
|
|
67
67
|
* Only AMA-priced bots contribute; sorted so bot order is irrelevant.
|
|
68
|
-
* @param {
|
|
68
|
+
* @param {unknown[]} activeBots - Bots with active !== false
|
|
69
69
|
* @returns {string} Fingerprint ('' when no AMA bot is active)
|
|
70
70
|
*/
|
|
71
71
|
function buildAdapterFingerprint(activeBots) {
|
|
@@ -78,13 +78,13 @@ function buildAdapterFingerprint(activeBots) {
|
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Summarize parsed bots.json content for adapter decisions.
|
|
81
|
-
* @param {
|
|
81
|
+
* @param {unknown} parsed - Parsed bots.json object
|
|
82
82
|
* @returns {{activeBots: any[], needsMarketAdapter: boolean, fingerprint: string}}
|
|
83
83
|
*/
|
|
84
84
|
function summarizeBotsConfig(parsed) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const rec = parsed;
|
|
86
|
+
const rawBots = Array.isArray(rec?.bots) ? rec.bots : [];
|
|
87
|
+
const bots = rawBots.filter(Boolean);
|
|
88
88
|
const activeBots = bots.filter((bot) => bot && bot.active !== false);
|
|
89
89
|
return {
|
|
90
90
|
activeBots,
|
|
@@ -1,37 +1,119 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import type { ChildProcess, ChildProcessByStdio } from 'node:child_process';
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
4
|
+
import { buildScopedChildEnv } from './child_env.js';
|
|
5
|
+
import { type BotEntry } from '../bot_settings.js';
|
|
1
6
|
import { formatUptime } from '../process_discovery.js';
|
|
7
|
+
import type { Socket } from 'net';
|
|
2
8
|
import { usesAmaGridPrice } from '../grid_price_source.js';
|
|
3
9
|
declare const SOCKET_PATH: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
type SupervisedChild = ChildProcessByStdio<null, Readable, Readable>;
|
|
11
|
+
interface SupervisedApp {
|
|
12
|
+
kind: 'bot' | 'service' | 'job';
|
|
13
|
+
name: string;
|
|
14
|
+
script: string;
|
|
15
|
+
args?: string | string[];
|
|
16
|
+
cwd: string;
|
|
17
|
+
max_memory_restart?: string;
|
|
18
|
+
error_file?: string;
|
|
19
|
+
out_file?: string;
|
|
20
|
+
max_restarts?: number;
|
|
21
|
+
min_uptime?: number;
|
|
22
|
+
restart_delay?: number;
|
|
23
|
+
autorestart?: boolean;
|
|
24
|
+
bulk_control?: boolean;
|
|
25
|
+
cron_schedule?: string;
|
|
26
|
+
env?: Record<string, string>;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface CronSchedule {
|
|
30
|
+
minute: Set<number> | null;
|
|
31
|
+
hour: Set<number> | null;
|
|
32
|
+
dayOfMonth: Set<number> | null;
|
|
33
|
+
month: Set<number> | null;
|
|
34
|
+
dayOfWeek: Set<number> | null;
|
|
35
|
+
}
|
|
36
|
+
interface BotRuntimeState {
|
|
37
|
+
name: string;
|
|
38
|
+
appEntry: SupervisedApp | null;
|
|
39
|
+
child: SupervisedChild | null;
|
|
40
|
+
restartCount: number;
|
|
41
|
+
lastStartTime: number;
|
|
42
|
+
status: string;
|
|
43
|
+
pendingRestart: boolean;
|
|
44
|
+
bulkControl: boolean;
|
|
45
|
+
cronExpression: string | null;
|
|
46
|
+
cronSchedule: CronSchedule | null;
|
|
47
|
+
nextScheduledAt: number;
|
|
48
|
+
scheduledRunTimer: ReturnType<typeof setTimeout> | null;
|
|
49
|
+
autorestart?: boolean;
|
|
50
|
+
maxRestarts: number;
|
|
51
|
+
minUptimeMs: number;
|
|
52
|
+
restartDelayMs: number;
|
|
53
|
+
memoryLimitBytes: number | null;
|
|
54
|
+
stoppedByUser: boolean;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
interface SupervisorOptions {
|
|
58
|
+
bots?: BotEntry[] | null;
|
|
59
|
+
buildEnv?: typeof buildScopedChildEnv;
|
|
60
|
+
spawnFn?: typeof spawn;
|
|
61
|
+
log?: (...args: unknown[]) => void;
|
|
62
|
+
logError?: (...args: unknown[]) => void;
|
|
63
|
+
controlSocket?: boolean;
|
|
64
|
+
getChildRss?: (child: SupervisedChild) => number;
|
|
65
|
+
memoryCheckIntervalMs?: number;
|
|
66
|
+
statusLogIntervalMs?: number;
|
|
67
|
+
staggerDelayMs?: number;
|
|
68
|
+
setTimeoutFn?: typeof setTimeout;
|
|
69
|
+
clearTimeoutFn?: typeof clearTimeout;
|
|
70
|
+
nowFn?: () => number;
|
|
71
|
+
stopMarketAdapter?: () => Promise<{
|
|
72
|
+
pid: number | null;
|
|
73
|
+
stopped: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
updaterActive?: boolean;
|
|
76
|
+
}
|
|
77
|
+
declare function parseCronExpression(expression: unknown): CronSchedule;
|
|
78
|
+
declare function getNextCronDate(schedule: CronSchedule, fromDate?: Date): Date;
|
|
79
|
+
declare function forwardSignal(child: ChildProcess | null | undefined, signal: NodeJS.Signals): void;
|
|
80
|
+
declare function isPidAlive(pid: number): boolean;
|
|
81
|
+
declare function waitForPidExit(pid: number, timeoutMs: number): Promise<boolean>;
|
|
82
|
+
declare function candidateRuntimeScriptPaths(scriptSegments: string[]): Set<string>;
|
|
83
|
+
declare function pidMatchesScriptCandidates(pid: number, expectedPaths: Set<string> | null | undefined): boolean;
|
|
84
|
+
declare function isNodeProcessWithExactScript(pid: number, scriptSegments: string[]): boolean;
|
|
18
85
|
declare function readMarketAdapterLockPid(): number | null;
|
|
19
|
-
declare function stopMarketAdapterFromLock(timeoutMs?:
|
|
86
|
+
declare function stopMarketAdapterFromLock(timeoutMs?: number): Promise<{
|
|
20
87
|
pid: number | null;
|
|
21
88
|
stopped: boolean;
|
|
22
89
|
}>;
|
|
23
|
-
declare function waitForChildSpawn(child:
|
|
24
|
-
declare function createBotSupervisor({ bots, buildEnv, spawnFn, log, logError, controlSocket, getChildRss, memoryCheckIntervalMs, statusLogIntervalMs, staggerDelayMs, setTimeoutFn, clearTimeoutFn, nowFn, stopMarketAdapter, updaterActive, }?:
|
|
25
|
-
start: () => Promise<Map<
|
|
26
|
-
shutdown: ({ preserveSockets }?:
|
|
27
|
-
|
|
28
|
-
|
|
90
|
+
declare function waitForChildSpawn(child: ChildProcess): Promise<void>;
|
|
91
|
+
declare function createBotSupervisor({ bots, buildEnv, spawnFn, log, logError, controlSocket, getChildRss, memoryCheckIntervalMs, statusLogIntervalMs, staggerDelayMs, setTimeoutFn, clearTimeoutFn, nowFn, stopMarketAdapter, updaterActive, }?: SupervisorOptions): {
|
|
92
|
+
start: () => Promise<Map<string, BotRuntimeState>>;
|
|
93
|
+
shutdown: ({ preserveSockets }?: {
|
|
94
|
+
preserveSockets?: Socket[];
|
|
95
|
+
}) => Promise<void>;
|
|
96
|
+
shutdownSignalHandler: (signal: NodeJS.Signals) => void;
|
|
97
|
+
getStatus: () => Record<string, {
|
|
98
|
+
status: string;
|
|
99
|
+
pid: number | null;
|
|
100
|
+
restarts: number;
|
|
101
|
+
uptimeMs: number;
|
|
102
|
+
nextScheduledAt: number;
|
|
103
|
+
}>;
|
|
29
104
|
printStatusSummary: () => void;
|
|
30
|
-
restartAll: ({ logAction }?:
|
|
31
|
-
|
|
105
|
+
restartAll: ({ logAction }?: {
|
|
106
|
+
logAction?: string;
|
|
107
|
+
}) => Promise<void>;
|
|
108
|
+
restartRunning: ({ logAction }?: {
|
|
109
|
+
logAction?: boolean;
|
|
110
|
+
}) => Promise<void>;
|
|
32
111
|
stopAll: () => void;
|
|
33
112
|
hasUserStopped: () => boolean;
|
|
34
|
-
waitForStableStartup: ({ timeoutMs, pollIntervalMs }?:
|
|
113
|
+
waitForStableStartup: ({ timeoutMs, pollIntervalMs }?: {
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
pollIntervalMs?: number;
|
|
116
|
+
}) => Promise<void>;
|
|
35
117
|
};
|
|
36
118
|
export { createBotSupervisor, SOCKET_PATH, parseCronExpression, getNextCronDate, forwardSignal, isPidAlive, waitForPidExit, candidateRuntimeScriptPaths, pidMatchesScriptCandidates, isNodeProcessWithExactScript, readMarketAdapterLockPid, stopMarketAdapterFromLock, usesAmaGridPrice, waitForChildSpawn, formatUptime };
|
|
37
119
|
//# sourceMappingURL=bot_supervisor.d.ts.map
|
|
@@ -17,7 +17,7 @@ import { sleep } from '../order/utils/system.js';
|
|
|
17
17
|
const storage = getStorage();
|
|
18
18
|
const { ensureDir, readJSON, unlink: safeUnlink } = storage;
|
|
19
19
|
import { buildRuntimeScriptPath, SCRIPTS_ROOT as CODE_ROOT } from './runtime_entry.js';
|
|
20
|
-
import { getErrorMessage } from '../utils/errors.js';
|
|
20
|
+
import { getErrorMessage, getErrorCode } from '../utils/errors.js';
|
|
21
21
|
import { usesAmaGridPrice } from '../grid_price_source.js';
|
|
22
22
|
const BOT_SCRIPT = buildRuntimeScriptPath(CODE_ROOT, ['bot']);
|
|
23
23
|
const SOCKET_PATH = Config.DEXBOT_SUPERVISOR_SOCKET || PATHS.PROFILES.SUPERVISOR_SOCK;
|
|
@@ -209,7 +209,7 @@ function forwardSignal(child, signal) {
|
|
|
209
209
|
child.kill(signal);
|
|
210
210
|
}
|
|
211
211
|
catch (err) {
|
|
212
|
-
if (err
|
|
212
|
+
if (getErrorCode(err) !== 'ESRCH')
|
|
213
213
|
throw err;
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -232,13 +232,14 @@ function readProcCwd(pid) {
|
|
|
232
232
|
return getProcessDiscovery().readCwd(pid);
|
|
233
233
|
}
|
|
234
234
|
function normalizeProcScriptArg(arg, cwd) {
|
|
235
|
-
|
|
235
|
+
const argStr = arg == null ? '' : String(arg);
|
|
236
|
+
if (!argStr || argStr.startsWith('-'))
|
|
236
237
|
return '';
|
|
237
|
-
if (!/\.(?:[cm]?js|ts)$/i.test(
|
|
238
|
+
if (!/\.(?:[cm]?js|ts)$/i.test(argStr))
|
|
238
239
|
return '';
|
|
239
|
-
return path.isAbsolute(
|
|
240
|
-
? path.normalize(
|
|
241
|
-
: path.resolve(cwd || PATHS.PROJECT_ROOT,
|
|
240
|
+
return path.isAbsolute(argStr)
|
|
241
|
+
? path.normalize(argStr)
|
|
242
|
+
: path.resolve(cwd || PATHS.PROJECT_ROOT, argStr);
|
|
242
243
|
}
|
|
243
244
|
function scriptPathForRoot(root, scriptSegments, ext) {
|
|
244
245
|
const segments = [...scriptSegments];
|
|
@@ -421,7 +422,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
|
|
|
421
422
|
}
|
|
422
423
|
log(`Starting scheduled job: ${state.name}`);
|
|
423
424
|
try {
|
|
424
|
-
const child = spawnApp(state.appEntry);
|
|
425
|
+
const child = state.appEntry ? spawnApp(state.appEntry) : null;
|
|
425
426
|
if (child) {
|
|
426
427
|
await waitForChildSpawn(child);
|
|
427
428
|
}
|
|
@@ -612,7 +613,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
|
|
|
612
613
|
state.pendingRestart = false;
|
|
613
614
|
state.stoppedByUser = true;
|
|
614
615
|
try {
|
|
615
|
-
state.child
|
|
616
|
+
state.child?.kill('SIGTERM');
|
|
616
617
|
}
|
|
617
618
|
catch (_) { }
|
|
618
619
|
userStopped = true;
|
|
@@ -749,7 +750,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
|
|
|
749
750
|
}
|
|
750
751
|
catch (_) {
|
|
751
752
|
enqueueSocketResponse(() => new Promise((resolve) => {
|
|
752
|
-
socket.write(JSON.stringify({ error: 'invalid JSON' }) + '\n', resolve);
|
|
753
|
+
socket.write(JSON.stringify({ error: 'invalid JSON' }) + '\n', () => resolve());
|
|
753
754
|
}));
|
|
754
755
|
continue;
|
|
755
756
|
}
|
|
@@ -760,7 +761,7 @@ function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spaw
|
|
|
760
761
|
enqueueSocketResponse(async () => {
|
|
761
762
|
const resp = await handleSocketCommand({ ...cmd, preserveSockets: [socket] });
|
|
762
763
|
await new Promise((resolve) => {
|
|
763
|
-
socket.write(JSON.stringify(resp) + '\n', resolve);
|
|
764
|
+
socket.write(JSON.stringify(resp) + '\n', () => resolve());
|
|
764
765
|
});
|
|
765
766
|
if (cmd.cmd === 'delete') {
|
|
766
767
|
socket.end();
|
|
@@ -7,7 +7,7 @@ declare function fetchBootstrapPassword({ socketPath, timeoutMs, retries, }?: {
|
|
|
7
7
|
}): Promise<unknown>;
|
|
8
8
|
declare function createPasswordBootstrapServer({ password, secret, timeoutMs, }?: {
|
|
9
9
|
password?: string;
|
|
10
|
-
secret?:
|
|
10
|
+
secret?: unknown;
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
}): Promise<{
|
|
13
13
|
socketPath: string;
|
|
@@ -72,7 +72,7 @@ async function cleanupStaleBootstrapDirs() {
|
|
|
72
72
|
const socketPath = path.join(dirPath, 'bootstrap.sock');
|
|
73
73
|
try {
|
|
74
74
|
const socketStat = storage.stat(socketPath);
|
|
75
|
-
if (socketStat.isSocket()) {
|
|
75
|
+
if (socketStat.isSocket?.()) {
|
|
76
76
|
// Probe the socket with a short connect. If it succeeds the
|
|
77
77
|
// server is (or was very recently) listening — do not delete.
|
|
78
78
|
const probeResult = await probeBootstrapSocket(socketPath, 300);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StdioOptions } from 'child_process';
|
|
2
2
|
declare const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
3
|
-
declare function waitForExit(child:
|
|
3
|
+
declare function waitForExit(child: import('node:child_process').ChildProcess): Promise<number | null>;
|
|
4
4
|
declare function createCredentialDaemonController({ root, codeRoot, socketPath, readyFilePath, pollIntervalMs, }?: {
|
|
5
5
|
root?: string | undefined;
|
|
6
6
|
codeRoot?: string | undefined;
|
|
@@ -15,11 +15,11 @@ declare function createCredentialDaemonController({ root, codeRoot, socketPath,
|
|
|
15
15
|
passwordFile?: string | null;
|
|
16
16
|
}) => Promise<boolean>;
|
|
17
17
|
forwardSignal: (signal: string) => void;
|
|
18
|
-
getManagedDaemonPid: () =>
|
|
19
|
-
isDaemonReady: () => Promise<
|
|
18
|
+
getManagedDaemonPid: () => number | null;
|
|
19
|
+
isDaemonReady: () => Promise<boolean>;
|
|
20
20
|
releaseManagedDaemon: () => void;
|
|
21
21
|
stopManagedDaemon: () => Promise<void>;
|
|
22
|
-
waitForManagedDaemon: () => Promise<
|
|
22
|
+
waitForManagedDaemon: () => Promise<number | null>;
|
|
23
23
|
};
|
|
24
24
|
export { createCredentialDaemonController, DEFAULT_POLL_INTERVAL_MS, waitForExit };
|
|
25
25
|
//# sourceMappingURL=credential_daemon.d.ts.map
|
|
@@ -15,7 +15,7 @@ const storage = getStorage();
|
|
|
15
15
|
const { unlink: safeUnlink } = storage;
|
|
16
16
|
import { assertPrivatePathSecurity, ensureCredentialRuntimeDirSync, getCredentialReadyFilePath, getCredentialSocketPath, } from '../credential_runtime.js';
|
|
17
17
|
import { buildRuntimeScriptArgs, SCRIPTS_ROOT as DEFAULT_CODE_ROOT } from './runtime_entry.js';
|
|
18
|
-
import { getErrorMessage } from '../utils/errors.js';
|
|
18
|
+
import { getErrorMessage, getErrorCode } from '../utils/errors.js';
|
|
19
19
|
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
20
20
|
function waitForExit(child) {
|
|
21
21
|
return new Promise((resolve, reject) => {
|
|
@@ -58,7 +58,7 @@ function createCredentialDaemonController({ root = PATHS.PROJECT_ROOT, codeRoot
|
|
|
58
58
|
daemonProcess.kill(signal);
|
|
59
59
|
}
|
|
60
60
|
catch (err) {
|
|
61
|
-
if (err
|
|
61
|
+
if (getErrorCode(err) === 'ESRCH')
|
|
62
62
|
return;
|
|
63
63
|
throw err;
|
|
64
64
|
}
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* and lets the caller fall through to the normal "prompt for master
|
|
16
16
|
* password" path.
|
|
17
17
|
*/
|
|
18
|
-
declare function readCredentialSocketInode(socketPath:
|
|
19
|
-
declare function findCredentialSocketOwnerPid(socketPath:
|
|
18
|
+
declare function readCredentialSocketInode(socketPath: string): number;
|
|
19
|
+
declare function findCredentialSocketOwnerPid(socketPath: string, isLikelyProcess: ((pid: number) => boolean) | null | undefined): number;
|
|
20
20
|
/**
|
|
21
21
|
* Detect and clean up a credential daemon that is listening on our socket
|
|
22
22
|
* but was NOT started by the current unlock session.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildScopedChildEnv } from './child_env.js';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { isLikelyMarketAdapterProcess } from '../../market_adapter/utils/file_lock.js';
|
|
4
|
-
declare function loadLockInfo(lockPath: string):
|
|
4
|
+
declare function loadLockInfo(lockPath: string): Record<string, unknown>;
|
|
5
5
|
declare function isLockStale(lockPath?: string, _staleAfterMs?: number, isAdapterProcess?: typeof isLikelyMarketAdapterProcess): boolean;
|
|
6
6
|
declare function createMarketAdapterRuntime({ root, script, lockFile, spawnFn, buildEnv, }?: {
|
|
7
7
|
root?: string | undefined;
|
|
@@ -14,17 +14,72 @@ declare function createMarketAdapterRuntime({ root, script, lockFile, spawnFn, b
|
|
|
14
14
|
activeBotCount: number;
|
|
15
15
|
botIds: unknown[];
|
|
16
16
|
hasOwnedChild: boolean;
|
|
17
|
-
ownedPid:
|
|
17
|
+
ownedPid: number | null;
|
|
18
18
|
runningExternally: boolean;
|
|
19
|
-
lockInfo:
|
|
19
|
+
lockInfo: Record<string, unknown>;
|
|
20
20
|
};
|
|
21
|
-
releaseBot: (botId: string) => Promise<
|
|
21
|
+
releaseBot: (botId: string) => Promise<{
|
|
22
|
+
running: boolean;
|
|
23
|
+
stopped: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
running: boolean;
|
|
26
|
+
owned: boolean;
|
|
27
|
+
stopped: boolean;
|
|
28
|
+
}>;
|
|
22
29
|
shutdown: () => Promise<{
|
|
23
30
|
running: boolean;
|
|
24
31
|
stopped: boolean;
|
|
25
32
|
}>;
|
|
26
|
-
syncBot: (botId: string, shouldRun: boolean) => Promise<
|
|
33
|
+
syncBot: (botId: string, shouldRun: boolean) => Promise<{
|
|
34
|
+
running: boolean;
|
|
35
|
+
owned: boolean;
|
|
36
|
+
started: boolean;
|
|
37
|
+
external?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
running: boolean;
|
|
40
|
+
owned: boolean;
|
|
41
|
+
external: boolean;
|
|
42
|
+
started: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
running: boolean;
|
|
45
|
+
stopped: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
declare function getSharedMarketAdapterRuntime(options?: {}): {
|
|
49
|
+
getStatus: () => {
|
|
50
|
+
activeBotCount: number;
|
|
51
|
+
botIds: unknown[];
|
|
52
|
+
hasOwnedChild: boolean;
|
|
53
|
+
ownedPid: number | null;
|
|
54
|
+
runningExternally: boolean;
|
|
55
|
+
lockInfo: Record<string, unknown>;
|
|
56
|
+
};
|
|
57
|
+
releaseBot: (botId: string) => Promise<{
|
|
58
|
+
running: boolean;
|
|
59
|
+
stopped: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
running: boolean;
|
|
62
|
+
owned: boolean;
|
|
63
|
+
stopped: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
shutdown: () => Promise<{
|
|
66
|
+
running: boolean;
|
|
67
|
+
stopped: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
syncBot: (botId: string, shouldRun: boolean) => Promise<{
|
|
70
|
+
running: boolean;
|
|
71
|
+
owned: boolean;
|
|
72
|
+
started: boolean;
|
|
73
|
+
external?: undefined;
|
|
74
|
+
} | {
|
|
75
|
+
running: boolean;
|
|
76
|
+
owned: boolean;
|
|
77
|
+
external: boolean;
|
|
78
|
+
started: boolean;
|
|
79
|
+
} | {
|
|
80
|
+
running: boolean;
|
|
81
|
+
stopped: boolean;
|
|
82
|
+
}>;
|
|
27
83
|
};
|
|
28
|
-
declare function getSharedMarketAdapterRuntime(options?: {}): any;
|
|
29
84
|
export { createMarketAdapterRuntime, getSharedMarketAdapterRuntime, isLikelyMarketAdapterProcess, isLockStale, loadLockInfo };
|
|
30
85
|
//# sourceMappingURL=market_adapter_runtime.d.ts.map
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface WatchdogOptions {
|
|
2
|
+
codeRoot?: string;
|
|
3
|
+
root?: string;
|
|
4
|
+
lockFile?: string;
|
|
5
|
+
botsFile?: string;
|
|
6
|
+
logWarn?: (...args: unknown[]) => void;
|
|
7
|
+
logError?: (...args: unknown[]) => void;
|
|
8
|
+
}
|
|
9
|
+
declare function createMarketAdapterWatchdog({ codeRoot, root, lockFile, botsFile, logWarn, logError, }?: WatchdogOptions): {
|
|
10
|
+
schedule: (errorLog: string) => () => void;
|
|
3
11
|
stop: () => Promise<void>;
|
|
4
12
|
isLikelyRunning: () => boolean;
|
|
5
13
|
readAdapterStatus: () => {
|
|
@@ -58,6 +58,10 @@ function createMarketAdapterWatchdog({ codeRoot = DEFAULT_CODE_ROOT, root = PATH
|
|
|
58
58
|
}
|
|
59
59
|
catch (_) { }
|
|
60
60
|
const exited = await withTimeout(new Promise((resolve) => {
|
|
61
|
+
if (!_child) {
|
|
62
|
+
resolve(true);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
61
65
|
_child.once('close', () => resolve(true));
|
|
62
66
|
}), LAUNCHER.SUPERVISOR.SHUTDOWN_TIMEOUT_MS, { onTimeout: 'resolve', defaultValue: false });
|
|
63
67
|
if (!exited && _child && _child.exitCode == null) {
|