dexbot 1.1.10
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/LICENSE +21 -0
- package/README.md +287 -0
- package/claw/README.md +513 -0
- package/claw/scripts/memu_runner.py +385 -0
- package/claw/skills/bitshares-guide/SKILL.md +14 -0
- package/claw/skills/bitshares-guide/references/example-skill-shells.md +18 -0
- package/claw/skills/bitshares-guide/references/presentation-patterns.md +19 -0
- package/claw/skills/bitshares-guide/references/scope-guardrails.md +9 -0
- package/claw/skills/launcher-ops/SKILL.md +18 -0
- package/claw/skills/launcher-ops/references/launcher-workflow.md +23 -0
- package/claw/skills/margin-trading/SKILL.md +23 -0
- package/claw/skills/margin-trading/references/honest-asset-list.md +74 -0
- package/claw/skills/margin-trading/references/honest-assets.md +44 -0
- package/claw/skills/margin-trading/references/position-management.md +203 -0
- package/claw/skills/margin-trading/references/trading-concepts.md +80 -0
- package/claw/skills/memu-memory/SKILL.md +218 -0
- package/claw/skills/shared/references/js-automation-overview.md +24 -0
- package/claw/skills/shared/references/safety-and-staleness.md +11 -0
- package/claw/skills/shared/references/skill-boundaries.md +17 -0
- package/claw/skills/trend-detection/SKILL.md +33 -0
- package/claw/skills/trend-detection/agents/openai.yaml +3 -0
- package/claw/skills/trend-detection/references/service.md +45 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +149 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +387 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +212 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +31 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +249 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +2 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
- package/dist/analysis/analyze_derivatives.d.ts +95 -0
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
- package/dist/analysis/analyze_derivatives.js +295 -0
- package/dist/analysis/analyze_derivatives.js.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.js +208 -0
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
- package/dist/analysis/analyze_kalman.d.ts +13 -0
- package/dist/analysis/analyze_kalman.d.ts.map +1 -0
- package/dist/analysis/analyze_kalman.js +123 -0
- package/dist/analysis/analyze_kalman.js.map +1 -0
- package/dist/analysis/analyze_regime.d.ts +20 -0
- package/dist/analysis/analyze_regime.d.ts.map +1 -0
- package/dist/analysis/analyze_regime.js +139 -0
- package/dist/analysis/analyze_regime.js.map +1 -0
- package/dist/analysis/analyze_regime_windows.d.ts +19 -0
- package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
- package/dist/analysis/analyze_regime_windows.js +413 -0
- package/dist/analysis/analyze_regime_windows.js.map +1 -0
- package/dist/analysis/analyze_risk_profile.d.ts +3 -0
- package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
- package/dist/analysis/analyze_risk_profile.js +159 -0
- package/dist/analysis/analyze_risk_profile.js.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.js +367 -0
- package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
- package/dist/analysis/analyze_volatility.d.ts +22 -0
- package/dist/analysis/analyze_volatility.d.ts.map +1 -0
- package/dist/analysis/analyze_volatility.js +172 -0
- package/dist/analysis/analyze_volatility.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +99 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +804 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +347 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +15 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.js +48 -0
- package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
- package/dist/analysis/bot_key_utils.d.ts +16 -0
- package/dist/analysis/bot_key_utils.d.ts.map +1 -0
- package/dist/analysis/bot_key_utils.js +61 -0
- package/dist/analysis/bot_key_utils.js.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js +498 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +546 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js +427 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
- package/dist/analysis/chart_utils.d.ts +13 -0
- package/dist/analysis/chart_utils.d.ts.map +1 -0
- package/dist/analysis/chart_utils.js +142 -0
- package/dist/analysis/chart_utils.js.map +1 -0
- package/dist/analysis/derivative_chart_generator.d.ts +18 -0
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
- package/dist/analysis/derivative_chart_generator.js +896 -0
- package/dist/analysis/derivative_chart_generator.js.map +1 -0
- package/dist/analysis/math_utils.d.ts +35 -0
- package/dist/analysis/math_utils.d.ts.map +1 -0
- package/dist/analysis/math_utils.js +121 -0
- package/dist/analysis/math_utils.js.map +1 -0
- package/dist/analysis/price_sources.d.ts +34 -0
- package/dist/analysis/price_sources.d.ts.map +1 -0
- package/dist/analysis/price_sources.js +103 -0
- package/dist/analysis/price_sources.js.map +1 -0
- package/dist/analysis/trade_profitability.d.ts +115 -0
- package/dist/analysis/trade_profitability.d.ts.map +1 -0
- package/dist/analysis/trade_profitability.js +1247 -0
- package/dist/analysis/trade_profitability.js.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +38 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +212 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +9 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1717 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +250 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js +903 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1449 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +42 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js +159 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js +408 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +103 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +229 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +34 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +89 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +39 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +132 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +345 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +130 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +38 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js +732 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
- package/dist/bot.d.ts +49 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +221 -0
- package/dist/bot.js.map +1 -0
- package/dist/credential-daemon.d.ts +64 -0
- package/dist/credential-daemon.d.ts.map +1 -0
- package/dist/credential-daemon.js +987 -0
- package/dist/credential-daemon.js.map +1 -0
- package/dist/dexbot.d.ts +87 -0
- package/dist/dexbot.d.ts.map +1 -0
- package/dist/dexbot.js +1222 -0
- package/dist/dexbot.js.map +1 -0
- package/dist/market_adapter/ama_signal_runner.d.ts +3 -0
- package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -0
- package/dist/market_adapter/ama_signal_runner.js +175 -0
- package/dist/market_adapter/ama_signal_runner.js.map +1 -0
- package/dist/market_adapter/candle_utils.d.ts +57 -0
- package/dist/market_adapter/candle_utils.d.ts.map +1 -0
- package/dist/market_adapter/candle_utils.js +252 -0
- package/dist/market_adapter/candle_utils.js.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +20 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.js +88 -0
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -0
- package/dist/market_adapter/core/config_normalizers.d.ts +10 -0
- package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -0
- package/dist/market_adapter/core/config_normalizers.js +24 -0
- package/dist/market_adapter/core/config_normalizers.js.map +1 -0
- package/dist/market_adapter/core/kibana_candles.d.ts +74 -0
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_candles.js +249 -0
- package/dist/market_adapter/core/kibana_candles.js.map +1 -0
- package/dist/market_adapter/core/kibana_client.d.ts +27 -0
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_client.js +120 -0
- package/dist/market_adapter/core/kibana_client.js.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts +143 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.js +170 -0
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts +210 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.js +2328 -0
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama.d.ts +2 -0
- package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama.js +138 -0
- package/dist/market_adapter/core/strategies/ama.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +50 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js +143 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +12 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js +47 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +32 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js +68 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +66 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.js +189 -0
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -0
- package/dist/market_adapter/index.d.ts +10 -0
- package/dist/market_adapter/index.d.ts.map +1 -0
- package/dist/market_adapter/index.js +71 -0
- package/dist/market_adapter/index.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts +3 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1165 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +54 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js +743 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts +68 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.js +143 -0
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -0
- package/dist/market_adapter/interval_utils.d.ts +6 -0
- package/dist/market_adapter/interval_utils.d.ts.map +1 -0
- package/dist/market_adapter/interval_utils.js +14 -0
- package/dist/market_adapter/interval_utils.js.map +1 -0
- package/dist/market_adapter/log_format.d.ts +16 -0
- package/dist/market_adapter/log_format.d.ts.map +1 -0
- package/dist/market_adapter/log_format.js +72 -0
- package/dist/market_adapter/log_format.js.map +1 -0
- package/dist/market_adapter/lp_chart_core.d.ts +6 -0
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_core.js +874 -0
- package/dist/market_adapter/lp_chart_core.js.map +1 -0
- package/dist/market_adapter/lp_chart_runner.d.ts +135 -0
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_runner.js +337 -0
- package/dist/market_adapter/lp_chart_runner.js.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +23 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js +169 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -0
- package/dist/market_adapter/market_adapter.d.ts +133 -0
- package/dist/market_adapter/market_adapter.d.ts.map +1 -0
- package/dist/market_adapter/market_adapter.js +1331 -0
- package/dist/market_adapter/market_adapter.js.map +1 -0
- package/dist/market_adapter/merge_lp_data.d.ts +3 -0
- package/dist/market_adapter/merge_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/merge_lp_data.js +125 -0
- package/dist/market_adapter/merge_lp_data.js.map +1 -0
- package/dist/market_adapter/test_helpers.d.ts +14 -0
- package/dist/market_adapter/test_helpers.d.ts.map +1 -0
- package/dist/market_adapter/test_helpers.js +22 -0
- package/dist/market_adapter/test_helpers.js.map +1 -0
- package/dist/market_adapter/utils/adapter_client.d.ts +20 -0
- package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -0
- package/dist/market_adapter/utils/adapter_client.js +88 -0
- package/dist/market_adapter/utils/adapter_client.js.map +1 -0
- package/dist/market_adapter/utils/atomic_write.d.ts +9 -0
- package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -0
- package/dist/market_adapter/utils/atomic_write.js +13 -0
- package/dist/market_adapter/utils/atomic_write.js.map +1 -0
- package/dist/market_adapter/utils/chain.d.ts +50 -0
- package/dist/market_adapter/utils/chain.d.ts.map +1 -0
- package/dist/market_adapter/utils/chain.js +196 -0
- package/dist/market_adapter/utils/chain.js.map +1 -0
- package/dist/market_adapter/utils/data_discovery.d.ts +6 -0
- package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -0
- package/dist/market_adapter/utils/data_discovery.js +35 -0
- package/dist/market_adapter/utils/data_discovery.js.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +15 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +60 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -0
- package/dist/market_adapter/utils/file_lock.d.ts +19 -0
- package/dist/market_adapter/utils/file_lock.d.ts.map +1 -0
- package/dist/market_adapter/utils/file_lock.js +191 -0
- package/dist/market_adapter/utils/file_lock.js.map +1 -0
- package/dist/market_adapter/utils/native_history.d.ts +19 -0
- package/dist/market_adapter/utils/native_history.d.ts.map +1 -0
- package/dist/market_adapter/utils/native_history.js +172 -0
- package/dist/market_adapter/utils/native_history.js.map +1 -0
- package/dist/market_adapter/utils/paths.d.ts +5 -0
- package/dist/market_adapter/utils/paths.d.ts.map +1 -0
- package/dist/market_adapter/utils/paths.js +7 -0
- package/dist/market_adapter/utils/paths.js.map +1 -0
- package/dist/modules/account_bots.d.ts +112 -0
- package/dist/modules/account_bots.d.ts.map +1 -0
- package/dist/modules/account_bots.js +1259 -0
- package/dist/modules/account_bots.js.map +1 -0
- package/dist/modules/account_orders.d.ts +273 -0
- package/dist/modules/account_orders.d.ts.map +1 -0
- package/dist/modules/account_orders.js +662 -0
- package/dist/modules/account_orders.js.map +1 -0
- package/dist/modules/authority_resolver.d.ts +2 -0
- package/dist/modules/authority_resolver.d.ts.map +1 -0
- package/dist/modules/authority_resolver.js +231 -0
- package/dist/modules/authority_resolver.js.map +1 -0
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -0
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/chain_client.js +322 -0
- package/dist/modules/bitshares-native/chain_client.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +59 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +456 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts +66 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.js +557 -0
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +20 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -0
- package/dist/modules/bitshares-native/index.d.ts +3 -0
- package/dist/modules/bitshares-native/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/index.js +32 -0
- package/dist/modules/bitshares-native/index.js.map +1 -0
- package/dist/modules/bitshares-native/resolvers.d.ts +40 -0
- package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -0
- package/dist/modules/bitshares-native/resolvers.js +161 -0
- package/dist/modules/bitshares-native/resolvers.js.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +56 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js +92 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -0
- package/dist/modules/bitshares-native/serial/index.d.ts +10 -0
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/index.js +14 -0
- package/dist/modules/bitshares-native/serial/index.js.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +102 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.js +615 -0
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts +64 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.js +252 -0
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -0
- package/dist/modules/bitshares-native/serial/types.d.ts +120 -0
- package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/types.js +837 -0
- package/dist/modules/bitshares-native/serial/types.js.map +1 -0
- package/dist/modules/bitshares-native/signing_client.d.ts +6 -0
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/signing_client.js +141 -0
- package/dist/modules/bitshares-native/signing_client.js.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts +6 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.js +865 -0
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -0
- package/dist/modules/bitshares-native/transport.d.ts +51 -0
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -0
- package/dist/modules/bitshares-native/transport.js +447 -0
- package/dist/modules/bitshares-native/transport.js.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts +30 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.js +262 -0
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -0
- package/dist/modules/bitshares_client.d.ts +129 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -0
- package/dist/modules/bitshares_client.js +627 -0
- package/dist/modules/bitshares_client.js.map +1 -0
- package/dist/modules/bot_settings.d.ts +33 -0
- package/dist/modules/bot_settings.d.ts.map +1 -0
- package/dist/modules/bot_settings.js +328 -0
- package/dist/modules/bot_settings.js.map +1 -0
- package/dist/modules/bots_file_lock.d.ts +88 -0
- package/dist/modules/bots_file_lock.d.ts.map +1 -0
- package/dist/modules/bots_file_lock.js +161 -0
- package/dist/modules/bots_file_lock.js.map +1 -0
- package/dist/modules/chain_keys.d.ts +302 -0
- package/dist/modules/chain_keys.d.ts.map +1 -0
- package/dist/modules/chain_keys.js +1095 -0
- package/dist/modules/chain_keys.js.map +1 -0
- package/dist/modules/chain_orders.d.ts +423 -0
- package/dist/modules/chain_orders.d.ts.map +1 -0
- package/dist/modules/chain_orders.js +1201 -0
- package/dist/modules/chain_orders.js.map +1 -0
- package/dist/modules/cli_whitelist_args.d.ts +6 -0
- package/dist/modules/cli_whitelist_args.d.ts.map +1 -0
- package/dist/modules/cli_whitelist_args.js +13 -0
- package/dist/modules/cli_whitelist_args.js.map +1 -0
- package/dist/modules/config.d.ts +57 -0
- package/dist/modules/config.d.ts.map +1 -0
- package/dist/modules/config.js +107 -0
- package/dist/modules/config.js.map +1 -0
- package/dist/modules/constants.d.ts +635 -0
- package/dist/modules/constants.d.ts.map +1 -0
- package/dist/modules/constants.js +1464 -0
- package/dist/modules/constants.js.map +1 -0
- package/dist/modules/cr_planner.d.ts +51 -0
- package/dist/modules/cr_planner.d.ts.map +1 -0
- package/dist/modules/cr_planner.js +299 -0
- package/dist/modules/cr_planner.js.map +1 -0
- package/dist/modules/credential_policy.d.ts +188 -0
- package/dist/modules/credential_policy.d.ts.map +1 -0
- package/dist/modules/credential_policy.js +1452 -0
- package/dist/modules/credential_policy.js.map +1 -0
- package/dist/modules/credential_runtime.d.ts +42 -0
- package/dist/modules/credential_runtime.d.ts.map +1 -0
- package/dist/modules/credential_runtime.js +148 -0
- package/dist/modules/credential_runtime.js.map +1 -0
- package/dist/modules/credential_session_cache.d.ts +36 -0
- package/dist/modules/credential_session_cache.d.ts.map +1 -0
- package/dist/modules/credential_session_cache.js +106 -0
- package/dist/modules/credential_session_cache.js.map +1 -0
- package/dist/modules/credit_runtime.d.ts +412 -0
- package/dist/modules/credit_runtime.d.ts.map +1 -0
- package/dist/modules/credit_runtime.js +2866 -0
- package/dist/modules/credit_runtime.js.map +1 -0
- package/dist/modules/crypto/browser_provider.d.ts +15 -0
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -0
- package/dist/modules/crypto/browser_provider.js +113 -0
- package/dist/modules/crypto/browser_provider.js.map +1 -0
- package/dist/modules/crypto/index.d.ts +9 -0
- package/dist/modules/crypto/index.d.ts.map +1 -0
- package/dist/modules/crypto/index.js +44 -0
- package/dist/modules/crypto/index.js.map +1 -0
- package/dist/modules/crypto/node_provider.d.ts +15 -0
- package/dist/modules/crypto/node_provider.d.ts.map +1 -0
- package/dist/modules/crypto/node_provider.js +74 -0
- package/dist/modules/crypto/node_provider.js.map +1 -0
- package/dist/modules/crypto/provider.d.ts +34 -0
- package/dist/modules/crypto/provider.d.ts.map +1 -0
- package/dist/modules/crypto/provider.js +3 -0
- package/dist/modules/crypto/provider.js.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts +8 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.js +142 -0
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -0
- package/dist/modules/crypto/pure_scrypt.d.ts +23 -0
- package/dist/modules/crypto/pure_scrypt.d.ts.map +1 -0
- package/dist/modules/crypto/pure_scrypt.js +161 -0
- package/dist/modules/crypto/pure_scrypt.js.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts +29 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.js +195 -0
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -0
- package/dist/modules/crypto/sync.d.ts +13 -0
- package/dist/modules/crypto/sync.d.ts.map +1 -0
- package/dist/modules/crypto/sync.js +37 -0
- package/dist/modules/crypto/sync.js.map +1 -0
- package/dist/modules/dexbot_class.d.ts +1074 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -0
- package/dist/modules/dexbot_class.js +4613 -0
- package/dist/modules/dexbot_class.js.map +1 -0
- package/dist/modules/dexbot_credential_client.d.ts +71 -0
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -0
- package/dist/modules/dexbot_credential_client.js +224 -0
- package/dist/modules/dexbot_credential_client.js.map +1 -0
- package/dist/modules/dexbot_fill_runtime.d.ts +173 -0
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_fill_runtime.js +217 -0
- package/dist/modules/dexbot_fill_runtime.js.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts +279 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.js +1613 -0
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -0
- package/dist/modules/env.d.ts +12 -0
- package/dist/modules/env.d.ts.map +1 -0
- package/dist/modules/env.js +57 -0
- package/dist/modules/env.js.map +1 -0
- package/dist/modules/fund_registry.d.ts +96 -0
- package/dist/modules/fund_registry.d.ts.map +1 -0
- package/dist/modules/fund_registry.js +261 -0
- package/dist/modules/fund_registry.js.map +1 -0
- package/dist/modules/general_settings.d.ts +36 -0
- package/dist/modules/general_settings.d.ts.map +1 -0
- package/dist/modules/general_settings.js +63 -0
- package/dist/modules/general_settings.js.map +1 -0
- package/dist/modules/graceful_shutdown.d.ts +86 -0
- package/dist/modules/graceful_shutdown.d.ts.map +1 -0
- package/dist/modules/graceful_shutdown.js +164 -0
- package/dist/modules/graceful_shutdown.js.map +1 -0
- package/dist/modules/key_store.d.ts +60 -0
- package/dist/modules/key_store.d.ts.map +1 -0
- package/dist/modules/key_store.js +215 -0
- package/dist/modules/key_store.js.map +1 -0
- package/dist/modules/launcher/bot_supervisor.d.ts +84 -0
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -0
- package/dist/modules/launcher/bot_supervisor.js +1067 -0
- package/dist/modules/launcher/bot_supervisor.js.map +1 -0
- package/dist/modules/launcher/child_env.d.ts +9 -0
- package/dist/modules/launcher/child_env.d.ts.map +1 -0
- package/dist/modules/launcher/child_env.js +78 -0
- package/dist/modules/launcher/child_env.js.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts +22 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.js +303 -0
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -0
- package/dist/modules/launcher/credential_daemon.d.ts +32 -0
- package/dist/modules/launcher/credential_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/credential_daemon.js +173 -0
- package/dist/modules/launcher/credential_daemon.js.map +1 -0
- package/dist/modules/launcher/credential_secret.d.ts +6 -0
- package/dist/modules/launcher/credential_secret.d.ts.map +1 -0
- package/dist/modules/launcher/credential_secret.js +15 -0
- package/dist/modules/launcher/credential_secret.js.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.js +166 -0
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -0
- package/dist/modules/launcher/headless_password.d.ts +8 -0
- package/dist/modules/launcher/headless_password.d.ts.map +1 -0
- package/dist/modules/launcher/headless_password.js +33 -0
- package/dist/modules/launcher/headless_password.js.map +1 -0
- package/dist/modules/launcher/launch_modes.d.ts +36 -0
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -0
- package/dist/modules/launcher/launch_modes.js +129 -0
- package/dist/modules/launcher/launch_modes.js.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts +43 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.js +217 -0
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +26 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.js +214 -0
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +89 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.js +425 -0
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -0
- package/dist/modules/launcher/runtime_entry.d.ts +26 -0
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -0
- package/dist/modules/launcher/runtime_entry.js +49 -0
- package/dist/modules/launcher/runtime_entry.js.map +1 -0
- package/dist/modules/launcher/status_reporting.d.ts +48 -0
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -0
- package/dist/modules/launcher/status_reporting.js +113 -0
- package/dist/modules/launcher/status_reporting.js.map +1 -0
- package/dist/modules/launcher/supervisor_control.d.ts +6 -0
- package/dist/modules/launcher/supervisor_control.d.ts.map +1 -0
- package/dist/modules/launcher/supervisor_control.js +59 -0
- package/dist/modules/launcher/supervisor_control.js.map +1 -0
- package/dist/modules/logger.d.ts +2 -0
- package/dist/modules/logger.d.ts.map +1 -0
- package/dist/modules/logger.js +71 -0
- package/dist/modules/logger.js.map +1 -0
- package/dist/modules/market_adapter_whitelist.d.ts +22 -0
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -0
- package/dist/modules/market_adapter_whitelist.js +82 -0
- package/dist/modules/market_adapter_whitelist.js.map +1 -0
- package/dist/modules/node_health_cache.d.ts +55 -0
- package/dist/modules/node_health_cache.d.ts.map +1 -0
- package/dist/modules/node_health_cache.js +134 -0
- package/dist/modules/node_health_cache.js.map +1 -0
- package/dist/modules/node_manager.d.ts +215 -0
- package/dist/modules/node_manager.d.ts.map +1 -0
- package/dist/modules/node_manager.js +628 -0
- package/dist/modules/node_manager.js.map +1 -0
- package/dist/modules/order/accounting.d.ts +349 -0
- package/dist/modules/order/accounting.d.ts.map +1 -0
- package/dist/modules/order/accounting.js +1191 -0
- package/dist/modules/order/accounting.js.map +1 -0
- package/dist/modules/order/async_lock.d.ts +126 -0
- package/dist/modules/order/async_lock.d.ts.map +1 -0
- package/dist/modules/order/async_lock.js +195 -0
- package/dist/modules/order/async_lock.js.map +1 -0
- package/dist/modules/order/export.d.ts +129 -0
- package/dist/modules/order/export.d.ts.map +1 -0
- package/dist/modules/order/export.js +316 -0
- package/dist/modules/order/export.js.map +1 -0
- package/dist/modules/order/format.d.ts +158 -0
- package/dist/modules/order/format.d.ts.map +1 -0
- package/dist/modules/order/format.js +232 -0
- package/dist/modules/order/format.js.map +1 -0
- package/dist/modules/order/grid.d.ts +549 -0
- package/dist/modules/order/grid.d.ts.map +1 -0
- package/dist/modules/order/grid.js +1746 -0
- package/dist/modules/order/grid.js.map +1 -0
- package/dist/modules/order/grid_reconcile.d.ts +154 -0
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -0
- package/dist/modules/order/grid_reconcile.js +1192 -0
- package/dist/modules/order/grid_reconcile.js.map +1 -0
- package/dist/modules/order/index.d.ts +55 -0
- package/dist/modules/order/index.d.ts.map +1 -0
- package/dist/modules/order/index.js +79 -0
- package/dist/modules/order/index.js.map +1 -0
- package/dist/modules/order/logger.d.ts +136 -0
- package/dist/modules/order/logger.d.ts.map +1 -0
- package/dist/modules/order/logger.js +614 -0
- package/dist/modules/order/logger.js.map +1 -0
- package/dist/modules/order/logger_state.d.ts +133 -0
- package/dist/modules/order/logger_state.d.ts.map +1 -0
- package/dist/modules/order/logger_state.js +170 -0
- package/dist/modules/order/logger_state.js.map +1 -0
- package/dist/modules/order/manager.d.ts +413 -0
- package/dist/modules/order/manager.d.ts.map +1 -0
- package/dist/modules/order/manager.js +1605 -0
- package/dist/modules/order/manager.js.map +1 -0
- package/dist/modules/order/processed_fill_store.d.ts +135 -0
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -0
- package/dist/modules/order/processed_fill_store.js +288 -0
- package/dist/modules/order/processed_fill_store.js.map +1 -0
- package/dist/modules/order/runner.d.ts +70 -0
- package/dist/modules/order/runner.d.ts.map +1 -0
- package/dist/modules/order/runner.js +140 -0
- package/dist/modules/order/runner.js.map +1 -0
- package/dist/modules/order/strategy.d.ts +196 -0
- package/dist/modules/order/strategy.d.ts.map +1 -0
- package/dist/modules/order/strategy.js +398 -0
- package/dist/modules/order/strategy.js.map +1 -0
- package/dist/modules/order/sync_engine.d.ts +386 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -0
- package/dist/modules/order/sync_engine.js +1459 -0
- package/dist/modules/order/sync_engine.js.map +1 -0
- package/dist/modules/order/utils/math.d.ts +677 -0
- package/dist/modules/order/utils/math.d.ts.map +1 -0
- package/dist/modules/order/utils/math.js +1172 -0
- package/dist/modules/order/utils/math.js.map +1 -0
- package/dist/modules/order/utils/order.d.ts +572 -0
- package/dist/modules/order/utils/order.d.ts.map +1 -0
- package/dist/modules/order/utils/order.js +1145 -0
- package/dist/modules/order/utils/order.js.map +1 -0
- package/dist/modules/order/utils/system.d.ts +268 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -0
- package/dist/modules/order/utils/system.js +1261 -0
- package/dist/modules/order/utils/system.js.map +1 -0
- package/dist/modules/order/utils/validate.d.ts +280 -0
- package/dist/modules/order/utils/validate.d.ts.map +1 -0
- package/dist/modules/order/utils/validate.js +918 -0
- package/dist/modules/order/utils/validate.js.map +1 -0
- package/dist/modules/order/working_grid.d.ts +212 -0
- package/dist/modules/order/working_grid.d.ts.map +1 -0
- package/dist/modules/order/working_grid.js +279 -0
- package/dist/modules/order/working_grid.js.map +1 -0
- package/dist/modules/path_api.d.ts +32 -0
- package/dist/modules/path_api.d.ts.map +1 -0
- package/dist/modules/path_api.js +148 -0
- package/dist/modules/path_api.js.map +1 -0
- package/dist/modules/paths.d.ts +58 -0
- package/dist/modules/paths.d.ts.map +1 -0
- package/dist/modules/paths.js +82 -0
- package/dist/modules/paths.js.map +1 -0
- package/dist/modules/process_discovery.d.ts +58 -0
- package/dist/modules/process_discovery.d.ts.map +1 -0
- package/dist/modules/process_discovery.js +265 -0
- package/dist/modules/process_discovery.js.map +1 -0
- package/dist/modules/runtime.d.ts +34 -0
- package/dist/modules/runtime.d.ts.map +1 -0
- package/dist/modules/runtime.js +98 -0
- package/dist/modules/runtime.js.map +1 -0
- package/dist/modules/runtime_settings.d.ts +12 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -0
- package/dist/modules/runtime_settings.js +122 -0
- package/dist/modules/runtime_settings.js.map +1 -0
- package/dist/modules/settings_merge.d.ts +38 -0
- package/dist/modules/settings_merge.d.ts.map +1 -0
- package/dist/modules/settings_merge.js +246 -0
- package/dist/modules/settings_merge.js.map +1 -0
- package/dist/modules/storage/browser_adapter.d.ts +56 -0
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -0
- package/dist/modules/storage/browser_adapter.js +231 -0
- package/dist/modules/storage/browser_adapter.js.map +1 -0
- package/dist/modules/storage/index.d.ts +28 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +52 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/node_adapter.d.ts +49 -0
- package/dist/modules/storage/node_adapter.d.ts.map +1 -0
- package/dist/modules/storage/node_adapter.js +167 -0
- package/dist/modules/storage/node_adapter.js.map +1 -0
- package/dist/modules/storage/types.d.ts +92 -0
- package/dist/modules/storage/types.d.ts.map +1 -0
- package/dist/modules/storage/types.js +3 -0
- package/dist/modules/storage/types.js.map +1 -0
- package/dist/modules/types.d.ts +1382 -0
- package/dist/modules/types.d.ts.map +1 -0
- package/dist/modules/types.js +11 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/modules/utils/base58check.d.ts +12 -0
- package/dist/modules/utils/base58check.d.ts.map +1 -0
- package/dist/modules/utils/base58check.js +112 -0
- package/dist/modules/utils/base58check.js.map +1 -0
- package/dist/modules/utils/build_dir.d.ts +7 -0
- package/dist/modules/utils/build_dir.d.ts.map +1 -0
- package/dist/modules/utils/build_dir.js +8 -0
- package/dist/modules/utils/build_dir.js.map +1 -0
- package/dist/modules/utils/fs_utils.d.ts +25 -0
- package/dist/modules/utils/fs_utils.d.ts.map +1 -0
- package/dist/modules/utils/fs_utils.js +27 -0
- package/dist/modules/utils/fs_utils.js.map +1 -0
- package/dist/modules/utils/math_utils.d.ts +10 -0
- package/dist/modules/utils/math_utils.d.ts.map +1 -0
- package/dist/modules/utils/math_utils.js +17 -0
- package/dist/modules/utils/math_utils.js.map +1 -0
- package/dist/modules/validate_profiles.d.ts +37 -0
- package/dist/modules/validate_profiles.d.ts.map +1 -0
- package/dist/modules/validate_profiles.js +369 -0
- package/dist/modules/validate_profiles.js.map +1 -0
- package/dist/pm2.d.ts +167 -0
- package/dist/pm2.d.ts.map +1 -0
- package/dist/pm2.js +998 -0
- package/dist/pm2.js.map +1 -0
- package/dist/scripts/analyze-git.d.ts +11 -0
- package/dist/scripts/analyze-git.d.ts.map +1 -0
- package/dist/scripts/analyze-git.js +851 -0
- package/dist/scripts/analyze-git.js.map +1 -0
- package/dist/scripts/analyze-orders.d.ts +17 -0
- package/dist/scripts/analyze-orders.d.ts.map +1 -0
- package/dist/scripts/analyze-orders.js +1568 -0
- package/dist/scripts/analyze-orders.js.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts +3 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.js +82 -0
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -0
- package/dist/scripts/diagnose-pool-history.d.ts +3 -0
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -0
- package/dist/scripts/diagnose-pool-history.js +296 -0
- package/dist/scripts/diagnose-pool-history.js.map +1 -0
- package/dist/scripts/divergence-calc.d.ts +26 -0
- package/dist/scripts/divergence-calc.d.ts.map +1 -0
- package/dist/scripts/divergence-calc.js +119 -0
- package/dist/scripts/divergence-calc.js.map +1 -0
- package/dist/scripts/generate_lp_chart.d.ts +31 -0
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -0
- package/dist/scripts/generate_lp_chart.js +92 -0
- package/dist/scripts/generate_lp_chart.js.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts +24 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.js +237 -0
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +2 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.js +111 -0
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -0
- package/dist/scripts/migrate_bot_keys.d.ts +6 -0
- package/dist/scripts/migrate_bot_keys.d.ts.map +1 -0
- package/dist/scripts/migrate_bot_keys.js +301 -0
- package/dist/scripts/migrate_bot_keys.js.map +1 -0
- package/dist/scripts/native_release_gates.d.ts +3 -0
- package/dist/scripts/native_release_gates.d.ts.map +1 -0
- package/dist/scripts/native_release_gates.js +52 -0
- package/dist/scripts/native_release_gates.js.map +1 -0
- package/dist/scripts/print_grid.d.ts +16 -0
- package/dist/scripts/print_grid.d.ts.map +1 -0
- package/dist/scripts/print_grid.js +80 -0
- package/dist/scripts/print_grid.js.map +1 -0
- package/dist/scripts/run-tests.d.ts +2 -0
- package/dist/scripts/run-tests.d.ts.map +1 -0
- package/dist/scripts/run-tests.js +49 -0
- package/dist/scripts/run-tests.js.map +1 -0
- package/dist/scripts/sync-version.d.ts +14 -0
- package/dist/scripts/sync-version.d.ts.map +1 -0
- package/dist/scripts/sync-version.js +158 -0
- package/dist/scripts/sync-version.js.map +1 -0
- package/dist/scripts/test-credit-renewal.d.ts +2 -0
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -0
- package/dist/scripts/test-credit-renewal.js +329 -0
- package/dist/scripts/test-credit-renewal.js.map +1 -0
- package/dist/scripts/update.d.ts +24 -0
- package/dist/scripts/update.d.ts.map +1 -0
- package/dist/scripts/update.js +650 -0
- package/dist/scripts/update.js.map +1 -0
- package/dist/scripts/validate_bots.d.ts +16 -0
- package/dist/scripts/validate_bots.d.ts.map +1 -0
- package/dist/scripts/validate_bots.js +106 -0
- package/dist/scripts/validate_bots.js.map +1 -0
- package/dist/scripts/verify-browser-bundle.d.ts +22 -0
- package/dist/scripts/verify-browser-bundle.d.ts.map +1 -0
- package/dist/scripts/verify-browser-bundle.js +339 -0
- package/dist/scripts/verify-browser-bundle.js.map +1 -0
- package/dist/unlock.d.ts +48 -0
- package/dist/unlock.d.ts.map +1 -0
- package/dist/unlock.js +925 -0
- package/dist/unlock.js.map +1 -0
- package/package.json +112 -0
- package/scripts/README.md +356 -0
- package/scripts/clear-all.sh +195 -0
- package/scripts/clear-logs.sh +95 -0
- package/scripts/clear-market-adapter.sh +196 -0
- package/scripts/clear-orders.sh +113 -0
- package/scripts/create-bot-symlinks.sh +51 -0
- package/scripts/postinstall.js +9 -0
- package/scripts/reset-settings.sh +118 -0
|
@@ -0,0 +1,1067 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { path } = require('../path_api');
|
|
4
|
+
const net = require('net');
|
|
5
|
+
const { getStorage } = require('../storage');
|
|
6
|
+
const storage = getStorage();
|
|
7
|
+
const { spawn, execSync } = require('child_process');
|
|
8
|
+
const { buildScopedChildEnv } = require('./child_env');
|
|
9
|
+
const { buildRuntimeScriptPath, isDistCodeRoot, SCRIPTS_ROOT: CODE_ROOT } = require('./runtime_entry');
|
|
10
|
+
const { PATHS } = require('../paths');
|
|
11
|
+
const { normalizeBotEntries, resolveRawBotEntries, loadSettingsFile } = require('../bot_settings');
|
|
12
|
+
const { UPDATER, BUILD_DIR, LAUNCHER } = require('../constants');
|
|
13
|
+
const { ensureDir, readJSON, safeUnlink } = require('../utils/fs_utils');
|
|
14
|
+
const { Config } = require('../config');
|
|
15
|
+
const { getProcessDiscovery } = require('../process_discovery');
|
|
16
|
+
const { runtime } = require('../runtime');
|
|
17
|
+
const { sleep } = require('../order/utils/system');
|
|
18
|
+
const BOT_SCRIPT = buildRuntimeScriptPath(CODE_ROOT, ['bot']);
|
|
19
|
+
const SOCKET_PATH = Config.DEXBOT_SUPERVISOR_SOCKET || PATHS.PROFILES.SUPERVISOR_SOCK;
|
|
20
|
+
const { MAX_RESTARTS, MIN_UPTIME_MS, RESTART_DELAY_MS, SHUTDOWN_TIMEOUT_MS, STAGGER_DELAY_MS, MAX_MEMORY_MB, MEMORY_CHECK_INTERVAL_MS, STATUS_LOG_INTERVAL_MS, MAX_CRON_LOOKAHEAD_MINUTES, } = LAUNCHER.SUPERVISOR;
|
|
21
|
+
const MAX_MEMORY_BYTES = MAX_MEMORY_MB * 1024 * 1024;
|
|
22
|
+
const SUPERVISOR_PREFIX = '[supervisor]';
|
|
23
|
+
function usesAmaGridPrice(bot) {
|
|
24
|
+
const gridPrice = typeof bot?.gridPrice === 'string' ? bot.gridPrice.trim().toLowerCase() : '';
|
|
25
|
+
return /^ama(?:[1-4])?$/.test(gridPrice);
|
|
26
|
+
}
|
|
27
|
+
function needsMarketAdapter(bots) {
|
|
28
|
+
return (bots || []).some((bot) => usesAmaGridPrice(bot));
|
|
29
|
+
}
|
|
30
|
+
function isServiceApp(app) {
|
|
31
|
+
const name = String(app?.name || '');
|
|
32
|
+
return name === 'dexbot-update' || name === 'dexbot-adapter';
|
|
33
|
+
}
|
|
34
|
+
function ensureLogDir() {
|
|
35
|
+
if (!storage.exists(PATHS.LOGS_DIR)) {
|
|
36
|
+
ensureDir(PATHS.LOGS_DIR);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function loadActiveBots(explicitBots) {
|
|
40
|
+
if (explicitBots)
|
|
41
|
+
return explicitBots;
|
|
42
|
+
const { config } = loadSettingsFile(PATHS.PROFILES.BOTS_JSON);
|
|
43
|
+
const raw = resolveRawBotEntries(config);
|
|
44
|
+
return normalizeBotEntries(raw).filter((b) => b.active !== false);
|
|
45
|
+
}
|
|
46
|
+
function buildSupervisedApps(bots) {
|
|
47
|
+
const apps = (bots || []).map((bot, index) => {
|
|
48
|
+
const botName = bot.name || `bot-${index}`;
|
|
49
|
+
return {
|
|
50
|
+
kind: 'bot',
|
|
51
|
+
name: botName,
|
|
52
|
+
script: BOT_SCRIPT,
|
|
53
|
+
args: botName,
|
|
54
|
+
cwd: PATHS.PROJECT_ROOT,
|
|
55
|
+
max_memory_restart: '250M',
|
|
56
|
+
error_file: path.join(PATHS.LOGS_DIR, `${botName}-error.log`),
|
|
57
|
+
out_file: path.join(PATHS.LOGS_DIR, `${botName}.log`),
|
|
58
|
+
max_restarts: 13,
|
|
59
|
+
min_uptime: 86400000,
|
|
60
|
+
restart_delay: 3000,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
if (needsMarketAdapter(bots)) {
|
|
64
|
+
apps.unshift({
|
|
65
|
+
kind: 'service',
|
|
66
|
+
name: 'dexbot-adapter',
|
|
67
|
+
script: buildRuntimeScriptPath(CODE_ROOT, ['market_adapter', 'market_adapter']),
|
|
68
|
+
cwd: PATHS.PROJECT_ROOT,
|
|
69
|
+
max_memory_restart: '150M',
|
|
70
|
+
error_file: path.join(PATHS.LOGS_DIR, 'dexbot-adapter-error.log'),
|
|
71
|
+
out_file: path.join(PATHS.LOGS_DIR, 'dexbot-adapter.log'),
|
|
72
|
+
max_restarts: 13,
|
|
73
|
+
min_uptime: 60000,
|
|
74
|
+
restart_delay: 3000,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (UPDATER.ACTIVE) {
|
|
78
|
+
apps.push({
|
|
79
|
+
kind: 'job',
|
|
80
|
+
name: 'dexbot-update',
|
|
81
|
+
script: buildRuntimeScriptPath(CODE_ROOT, ['scripts', 'update']),
|
|
82
|
+
cwd: PATHS.PROJECT_ROOT,
|
|
83
|
+
error_file: path.join(PATHS.LOGS_DIR, 'dexbot-update-error.log'),
|
|
84
|
+
out_file: path.join(PATHS.LOGS_DIR, 'dexbot-update.log'),
|
|
85
|
+
autorestart: false,
|
|
86
|
+
bulk_control: false,
|
|
87
|
+
cron_schedule: UPDATER.SCHEDULE,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return apps;
|
|
91
|
+
}
|
|
92
|
+
function parseCronField(field, min, max) {
|
|
93
|
+
const trimmed = String(field || '').trim();
|
|
94
|
+
if (!trimmed) {
|
|
95
|
+
throw new Error('empty cron field');
|
|
96
|
+
}
|
|
97
|
+
if (trimmed === '*') {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const values = new Set();
|
|
101
|
+
const parts = trimmed.split(',');
|
|
102
|
+
for (const part of parts) {
|
|
103
|
+
if (!part) {
|
|
104
|
+
throw new Error(`invalid cron field: ${field}`);
|
|
105
|
+
}
|
|
106
|
+
const stepMatch = part.match(/^(.+)\/(\d+)$/);
|
|
107
|
+
let base = part;
|
|
108
|
+
let step = 1;
|
|
109
|
+
if (stepMatch) {
|
|
110
|
+
base = stepMatch[1];
|
|
111
|
+
step = Number(stepMatch[2]);
|
|
112
|
+
if (!Number.isInteger(step) || step <= 0) {
|
|
113
|
+
throw new Error(`invalid cron step: ${part}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let rangeStart = min;
|
|
117
|
+
let rangeEnd = max;
|
|
118
|
+
if (base !== '*') {
|
|
119
|
+
const rangeMatch = base.match(/^(\d+)-(\d+)$/);
|
|
120
|
+
if (rangeMatch) {
|
|
121
|
+
rangeStart = Number(rangeMatch[1]);
|
|
122
|
+
rangeEnd = Number(rangeMatch[2]);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const exact = Number(base);
|
|
126
|
+
if (!Number.isInteger(exact)) {
|
|
127
|
+
throw new Error(`invalid cron value: ${part}`);
|
|
128
|
+
}
|
|
129
|
+
rangeStart = exact;
|
|
130
|
+
rangeEnd = exact;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (rangeStart < min || rangeEnd > max || rangeStart > rangeEnd) {
|
|
134
|
+
throw new Error(`cron value out of range: ${part}`);
|
|
135
|
+
}
|
|
136
|
+
for (let value = rangeStart; value <= rangeEnd; value += step) {
|
|
137
|
+
values.add(value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return values;
|
|
141
|
+
}
|
|
142
|
+
function parseCronExpression(expression) {
|
|
143
|
+
const parts = String(expression || '').trim().split(/\s+/);
|
|
144
|
+
if (parts.length !== 5) {
|
|
145
|
+
throw new Error(`invalid cron expression: ${expression}`);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
minute: parseCronField(parts[0], 0, 59),
|
|
149
|
+
hour: parseCronField(parts[1], 0, 23),
|
|
150
|
+
dayOfMonth: parseCronField(parts[2], 1, 31),
|
|
151
|
+
month: parseCronField(parts[3], 1, 12),
|
|
152
|
+
dayOfWeek: parseCronField(parts[4], 0, 6),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function cronFieldMatches(field, value) {
|
|
156
|
+
return field == null || field.has(value);
|
|
157
|
+
}
|
|
158
|
+
function cronMatchesDate(schedule, date) {
|
|
159
|
+
if (!schedule)
|
|
160
|
+
return false;
|
|
161
|
+
const minuteMatch = cronFieldMatches(schedule.minute, date.getMinutes());
|
|
162
|
+
const hourMatch = cronFieldMatches(schedule.hour, date.getHours());
|
|
163
|
+
const monthMatch = cronFieldMatches(schedule.month, date.getMonth() + 1);
|
|
164
|
+
const dayOfMonthMatch = cronFieldMatches(schedule.dayOfMonth, date.getDate());
|
|
165
|
+
const dayOfWeekMatch = cronFieldMatches(schedule.dayOfWeek, date.getDay());
|
|
166
|
+
const domRestricted = schedule.dayOfMonth != null;
|
|
167
|
+
const dowRestricted = schedule.dayOfWeek != null;
|
|
168
|
+
const dayMatch = domRestricted && dowRestricted
|
|
169
|
+
? (dayOfMonthMatch || dayOfWeekMatch)
|
|
170
|
+
: (dayOfMonthMatch && dayOfWeekMatch);
|
|
171
|
+
return minuteMatch && hourMatch && monthMatch && dayMatch;
|
|
172
|
+
}
|
|
173
|
+
function getNextCronDate(schedule, fromDate = new Date()) {
|
|
174
|
+
const cursor = new Date(fromDate.getTime());
|
|
175
|
+
cursor.setSeconds(0, 0);
|
|
176
|
+
cursor.setMinutes(cursor.getMinutes() + 1);
|
|
177
|
+
for (let i = 0; i < MAX_CRON_LOOKAHEAD_MINUTES; i++) {
|
|
178
|
+
if (cronMatchesDate(schedule, cursor)) {
|
|
179
|
+
return new Date(cursor.getTime());
|
|
180
|
+
}
|
|
181
|
+
cursor.setMinutes(cursor.getMinutes() + 1);
|
|
182
|
+
}
|
|
183
|
+
throw new Error('unable to resolve next cron run');
|
|
184
|
+
}
|
|
185
|
+
function parseMemoryLimitBytes(limit) {
|
|
186
|
+
if (!limit)
|
|
187
|
+
return null;
|
|
188
|
+
const match = String(limit || '').trim().match(/^(\d+(?:\.\d+)?)\s*([kmgt]?)(?:b)?$/i);
|
|
189
|
+
if (!match)
|
|
190
|
+
return null;
|
|
191
|
+
const value = Number(match[1]);
|
|
192
|
+
const unit = match[2].toLowerCase();
|
|
193
|
+
const factor = unit === 't' ? 1024 ** 4
|
|
194
|
+
: unit === 'g' ? 1024 ** 3
|
|
195
|
+
: unit === 'k' ? 1024
|
|
196
|
+
: 1024 ** 2;
|
|
197
|
+
return Math.floor(value * factor);
|
|
198
|
+
}
|
|
199
|
+
function normalizeAppArgs(args) {
|
|
200
|
+
if (args == null || args === '')
|
|
201
|
+
return [];
|
|
202
|
+
if (Array.isArray(args))
|
|
203
|
+
return args.map(String);
|
|
204
|
+
return [String(args)];
|
|
205
|
+
}
|
|
206
|
+
function forwardSignal(child, signal) {
|
|
207
|
+
if (!child || child.killed)
|
|
208
|
+
return;
|
|
209
|
+
try {
|
|
210
|
+
child.kill(signal);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
if (err.code !== 'ESRCH')
|
|
214
|
+
throw err;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function isPidAlive(pid) {
|
|
218
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
219
|
+
return false;
|
|
220
|
+
try {
|
|
221
|
+
return runtime.kill(pid, 0);
|
|
222
|
+
}
|
|
223
|
+
catch (_) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function waitForPidExit(pid, timeoutMs) {
|
|
228
|
+
const started = Date.now();
|
|
229
|
+
while (Date.now() - started < timeoutMs) {
|
|
230
|
+
if (!isPidAlive(pid))
|
|
231
|
+
return true;
|
|
232
|
+
await sleep(200);
|
|
233
|
+
}
|
|
234
|
+
return !isPidAlive(pid);
|
|
235
|
+
}
|
|
236
|
+
function readProcArgs(pid) {
|
|
237
|
+
return getProcessDiscovery().readArgs(pid);
|
|
238
|
+
}
|
|
239
|
+
function readProcCwd(pid) {
|
|
240
|
+
return getProcessDiscovery().readCwd(pid);
|
|
241
|
+
}
|
|
242
|
+
function normalizeProcScriptArg(arg, cwd) {
|
|
243
|
+
if (!arg || String(arg).startsWith('-'))
|
|
244
|
+
return '';
|
|
245
|
+
if (!/\.(?:[cm]?js|ts)$/i.test(String(arg)))
|
|
246
|
+
return '';
|
|
247
|
+
return path.isAbsolute(arg)
|
|
248
|
+
? path.normalize(arg)
|
|
249
|
+
: path.resolve(cwd || PATHS.PROJECT_ROOT, arg);
|
|
250
|
+
}
|
|
251
|
+
function scriptPathForRoot(root, scriptSegments, ext) {
|
|
252
|
+
const segments = [...scriptSegments];
|
|
253
|
+
const last = segments.pop();
|
|
254
|
+
segments.push(String(last).replace(/\.(?:[cm]?js|ts)$/i, '') + ext);
|
|
255
|
+
return path.join(root, ...segments);
|
|
256
|
+
}
|
|
257
|
+
function candidateRuntimeScriptPaths(scriptSegments) {
|
|
258
|
+
const candidates = new Set([
|
|
259
|
+
buildRuntimeScriptPath(CODE_ROOT, scriptSegments),
|
|
260
|
+
scriptPathForRoot(PATHS.PROJECT_ROOT, scriptSegments, '.ts'),
|
|
261
|
+
scriptPathForRoot(path.join(PATHS.PROJECT_ROOT, BUILD_DIR), scriptSegments, '.js'),
|
|
262
|
+
]);
|
|
263
|
+
if (scriptSegments.length === 1) {
|
|
264
|
+
candidates.add(scriptPathForRoot(PATHS.PROJECT_ROOT, scriptSegments, '.js'));
|
|
265
|
+
}
|
|
266
|
+
// Compatibility for wrappers already running from before the unlock-start -> unlock rename.
|
|
267
|
+
if (scriptSegments.length === 1 && scriptSegments[0] === 'unlock') {
|
|
268
|
+
candidates.add(scriptPathForRoot(PATHS.PROJECT_ROOT, ['unlock-start'], '.js'));
|
|
269
|
+
candidates.add(scriptPathForRoot(PATHS.PROJECT_ROOT, ['unlock-start'], '.ts'));
|
|
270
|
+
candidates.add(scriptPathForRoot(path.join(PATHS.PROJECT_ROOT, BUILD_DIR), ['unlock-start'], '.js'));
|
|
271
|
+
}
|
|
272
|
+
return candidates;
|
|
273
|
+
}
|
|
274
|
+
function pidMatchesScriptCandidates(pid, expectedPaths) {
|
|
275
|
+
if (!expectedPaths || expectedPaths.size === 0)
|
|
276
|
+
return false;
|
|
277
|
+
const args = readProcArgs(pid);
|
|
278
|
+
if (!args.some((arg) => path.basename(String(arg)).includes('node'))) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
const cwd = readProcCwd(pid);
|
|
282
|
+
for (const arg of args.slice(1)) {
|
|
283
|
+
const scriptPath = normalizeProcScriptArg(arg, cwd);
|
|
284
|
+
if (scriptPath && expectedPaths.has(scriptPath)) {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
function isNodeProcessWithExactScript(pid, scriptSegments) {
|
|
291
|
+
return pidMatchesScriptCandidates(pid, candidateRuntimeScriptPaths(scriptSegments));
|
|
292
|
+
}
|
|
293
|
+
function readMarketAdapterLockPid() {
|
|
294
|
+
try {
|
|
295
|
+
const info = readJSON(PATHS.MARKET_ADAPTER.LOCK_FILE);
|
|
296
|
+
const pid = Number(info.pid);
|
|
297
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
298
|
+
}
|
|
299
|
+
catch (_) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async function stopMarketAdapterFromLock(timeoutMs = 5000) {
|
|
304
|
+
const pid = readMarketAdapterLockPid();
|
|
305
|
+
if (!pid || !isNodeProcessWithExactScript(pid, ['market_adapter', 'market_adapter'])) {
|
|
306
|
+
return { pid, stopped: false };
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
runtime.kill(pid, 'SIGTERM');
|
|
310
|
+
let stopped = await waitForPidExit(pid, timeoutMs);
|
|
311
|
+
if (!stopped && isNodeProcessWithExactScript(pid, ['market_adapter', 'market_adapter'])) {
|
|
312
|
+
runtime.kill(pid, 'SIGKILL');
|
|
313
|
+
stopped = await waitForPidExit(pid, 2000);
|
|
314
|
+
}
|
|
315
|
+
return { pid, stopped };
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
if (err.code === 'ESRCH') {
|
|
319
|
+
return { pid, stopped: true };
|
|
320
|
+
}
|
|
321
|
+
throw err;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function getChildRSS(child) {
|
|
325
|
+
if (!child || !child.pid)
|
|
326
|
+
return -1;
|
|
327
|
+
try {
|
|
328
|
+
if (Config.PLATFORM === 'linux') {
|
|
329
|
+
const bytes = getProcessDiscovery().readRSSBytes(child.pid);
|
|
330
|
+
if (bytes > 0)
|
|
331
|
+
return bytes;
|
|
332
|
+
}
|
|
333
|
+
else if (Config.PLATFORM === 'darwin') {
|
|
334
|
+
const out = execSync(`ps -o rss= -p ${child.pid}`, { encoding: 'utf8', timeout: 3000 });
|
|
335
|
+
const rssKB = parseInt(out.trim(), 10);
|
|
336
|
+
if (rssKB > 0)
|
|
337
|
+
return rssKB * 1024;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (_) { }
|
|
341
|
+
return -1;
|
|
342
|
+
}
|
|
343
|
+
function waitForChildSpawn(child) {
|
|
344
|
+
return new Promise((resolve, reject) => {
|
|
345
|
+
let settled = false;
|
|
346
|
+
const handleSpawn = () => {
|
|
347
|
+
if (settled)
|
|
348
|
+
return;
|
|
349
|
+
settled = true;
|
|
350
|
+
cleanup();
|
|
351
|
+
resolve(undefined);
|
|
352
|
+
};
|
|
353
|
+
const handleError = (error) => {
|
|
354
|
+
if (settled)
|
|
355
|
+
return;
|
|
356
|
+
settled = true;
|
|
357
|
+
cleanup();
|
|
358
|
+
reject(error);
|
|
359
|
+
};
|
|
360
|
+
const cleanup = () => {
|
|
361
|
+
child.off('spawn', handleSpawn);
|
|
362
|
+
child.off('error', handleError);
|
|
363
|
+
};
|
|
364
|
+
child.once('spawn', handleSpawn);
|
|
365
|
+
child.once('error', handleError);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function formatUptime(ms) {
|
|
369
|
+
const s = Math.floor(ms / 1000);
|
|
370
|
+
const m = Math.floor(s / 60);
|
|
371
|
+
const h = Math.floor(m / 60);
|
|
372
|
+
const d = Math.floor(h / 24);
|
|
373
|
+
if (d > 0)
|
|
374
|
+
return `${d}d ${h % 24}h`;
|
|
375
|
+
if (h > 0)
|
|
376
|
+
return `${h}h ${m % 60}m`;
|
|
377
|
+
if (m > 0)
|
|
378
|
+
return `${m}m ${s % 60}s`;
|
|
379
|
+
return `${s}s`;
|
|
380
|
+
}
|
|
381
|
+
function createBotSupervisor({ bots = null, buildEnv = buildScopedChildEnv, spawnFn = spawn, log = (...args) => console.log(SUPERVISOR_PREFIX, ...args), logError = (...args) => console.error(SUPERVISOR_PREFIX, ...args), controlSocket = !Config.DEXBOT_DISABLE_SUPERVISOR_SOCKET, getChildRss = getChildRSS, memoryCheckIntervalMs = MEMORY_CHECK_INTERVAL_MS, statusLogIntervalMs = STATUS_LOG_INTERVAL_MS, setTimeoutFn = setTimeout, clearTimeoutFn = clearTimeout, nowFn = () => Date.now(), stopMarketAdapter = stopMarketAdapterFromLock, } = {}) {
|
|
382
|
+
const botStates = new Map();
|
|
383
|
+
let shuttingDown = false;
|
|
384
|
+
let shutdownResolve = null;
|
|
385
|
+
let memoryCheckTimer = null;
|
|
386
|
+
let statusLogTimer = null;
|
|
387
|
+
let socketServer = null;
|
|
388
|
+
let socketConnections = new Set();
|
|
389
|
+
let userStopped = false;
|
|
390
|
+
function allStopped() {
|
|
391
|
+
for (const [, state] of botStates) {
|
|
392
|
+
if (state.status === 'running' || state.status === 'restarting' || state.status === 'starting') {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
function checkAllStopped() {
|
|
399
|
+
if (allStopped() && shutdownResolve) {
|
|
400
|
+
shutdownResolve();
|
|
401
|
+
shutdownResolve = null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function printStatusSummary() {
|
|
405
|
+
if (shuttingDown)
|
|
406
|
+
return;
|
|
407
|
+
const lines = [];
|
|
408
|
+
for (const [name, state] of botStates) {
|
|
409
|
+
const pid = state.child?.pid || '-';
|
|
410
|
+
const uptime = state.lastStartTime && state.status === 'running'
|
|
411
|
+
? formatUptime(nowFn() - state.lastStartTime)
|
|
412
|
+
: '-';
|
|
413
|
+
let mem = '-';
|
|
414
|
+
if (state.status === 'running' && state.child) {
|
|
415
|
+
const rss = getChildRss(state.child);
|
|
416
|
+
if (rss > 0)
|
|
417
|
+
mem = `${Math.round(rss / 1024 / 1024)}MB`;
|
|
418
|
+
}
|
|
419
|
+
lines.push(`${name} | ${state.status} | pid ${pid} | uptime ${uptime} | rss ${mem}`);
|
|
420
|
+
}
|
|
421
|
+
if (lines.length === 0) {
|
|
422
|
+
log('Status: no bots');
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
log('Status:\n ' + lines.join('\n '));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function clearScheduledRun(state) {
|
|
429
|
+
if (state?.scheduledRunTimer) {
|
|
430
|
+
clearTimeoutFn(state.scheduledRunTimer);
|
|
431
|
+
state.scheduledRunTimer = null;
|
|
432
|
+
}
|
|
433
|
+
if (state) {
|
|
434
|
+
state.nextScheduledAt = 0;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function scheduleNextRun(state) {
|
|
438
|
+
clearScheduledRun(state);
|
|
439
|
+
if (shuttingDown || !state?.cronSchedule) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const nextRun = getNextCronDate(state.cronSchedule, new Date(nowFn()));
|
|
444
|
+
const delay = Math.max(nextRun.getTime() - nowFn(), 0);
|
|
445
|
+
state.nextScheduledAt = nextRun.getTime();
|
|
446
|
+
state.scheduledRunTimer = setTimeoutFn(async () => {
|
|
447
|
+
state.scheduledRunTimer = null;
|
|
448
|
+
state.nextScheduledAt = 0;
|
|
449
|
+
if (shuttingDown)
|
|
450
|
+
return;
|
|
451
|
+
if (state.status === 'running' || state.pendingRestart) {
|
|
452
|
+
log(`${state.name} scheduled run skipped because the previous run is still active.`);
|
|
453
|
+
scheduleNextRun(state);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
log(`Starting scheduled job: ${state.name}`);
|
|
457
|
+
try {
|
|
458
|
+
const child = spawnApp(state.appEntry);
|
|
459
|
+
if (child) {
|
|
460
|
+
await waitForChildSpawn(child);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (err) {
|
|
464
|
+
logError(`Failed to start scheduled job ${state.name}:`, err.message);
|
|
465
|
+
state.status = 'crashed';
|
|
466
|
+
}
|
|
467
|
+
finally {
|
|
468
|
+
scheduleNextRun(state);
|
|
469
|
+
}
|
|
470
|
+
}, delay);
|
|
471
|
+
if (state.scheduledRunTimer && typeof state.scheduledRunTimer.unref === 'function') {
|
|
472
|
+
state.scheduledRunTimer.unref();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
catch (err) {
|
|
476
|
+
logError(`Invalid cron schedule for ${state.name}: ${err.message}`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function runMemoryCheck() {
|
|
480
|
+
if (shuttingDown)
|
|
481
|
+
return;
|
|
482
|
+
for (const [name, state] of botStates) {
|
|
483
|
+
if (state.status !== 'running' || !state.child)
|
|
484
|
+
continue;
|
|
485
|
+
if (!state.memoryLimitBytes)
|
|
486
|
+
continue;
|
|
487
|
+
const rss = getChildRss(state.child);
|
|
488
|
+
if (rss <= 0)
|
|
489
|
+
continue;
|
|
490
|
+
const memoryLimitBytes = state.memoryLimitBytes || MAX_MEMORY_BYTES;
|
|
491
|
+
if (rss > memoryLimitBytes) {
|
|
492
|
+
const rssMB = Math.round(rss / 1024 / 1024);
|
|
493
|
+
const limitMB = Math.round(memoryLimitBytes / 1024 / 1024);
|
|
494
|
+
logError(`${name} exceeded memory limit (${rssMB}MB > ${limitMB}MB). Restarting...`);
|
|
495
|
+
state.pendingRestart = true;
|
|
496
|
+
try {
|
|
497
|
+
state.child.kill('SIGTERM');
|
|
498
|
+
}
|
|
499
|
+
catch (_) { }
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function spawnApp(app) {
|
|
504
|
+
const appName = app.name;
|
|
505
|
+
const state = botStates.get(appName);
|
|
506
|
+
if (!state)
|
|
507
|
+
return null;
|
|
508
|
+
if (shuttingDown) {
|
|
509
|
+
state.status = 'stopped';
|
|
510
|
+
checkAllStopped();
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
ensureLogDir();
|
|
514
|
+
const outFile = app.out_file || path.join(PATHS.LOGS_DIR, `${appName}.log`);
|
|
515
|
+
const errorFile = app.error_file || path.join(PATHS.LOGS_DIR, `${appName}-error.log`);
|
|
516
|
+
const outStream = fs.createWriteStream(outFile, { flags: 'a' });
|
|
517
|
+
const errStream = fs.createWriteStream(errorFile, { flags: 'a' });
|
|
518
|
+
const isBot = !isServiceApp(app);
|
|
519
|
+
const extraEnv = {
|
|
520
|
+
...(app.env || {}),
|
|
521
|
+
DEXBOT_LAUNCH_MODE: 'isolated',
|
|
522
|
+
...(isBot ? { LIVE_BOT_NAME: appName } : {}),
|
|
523
|
+
};
|
|
524
|
+
const runtimeArgs = isDistCodeRoot(CODE_ROOT)
|
|
525
|
+
? [app.script || BOT_SCRIPT, ...normalizeAppArgs(app.args)]
|
|
526
|
+
: ['--import', 'tsx', app.script || BOT_SCRIPT, ...normalizeAppArgs(app.args)];
|
|
527
|
+
const child = spawnFn(Config.EXEC_PATH, runtimeArgs, {
|
|
528
|
+
cwd: app.cwd || PATHS.PROJECT_ROOT,
|
|
529
|
+
env: buildEnv({ extra: extraEnv }),
|
|
530
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
531
|
+
});
|
|
532
|
+
child.stdout.pipe(outStream);
|
|
533
|
+
child.stdout.pipe(runtime.stdout);
|
|
534
|
+
child.stderr.pipe(errStream);
|
|
535
|
+
child.stderr.pipe(runtime.stderr);
|
|
536
|
+
child.stdout.on('error', () => { });
|
|
537
|
+
child.stderr.on('error', () => { });
|
|
538
|
+
outStream.on('error', () => { });
|
|
539
|
+
errStream.on('error', () => { });
|
|
540
|
+
state.child = child;
|
|
541
|
+
state.status = 'running';
|
|
542
|
+
state.stoppedByUser = false;
|
|
543
|
+
state.lastStartTime = nowFn();
|
|
544
|
+
child.once('close', (code, signal) => {
|
|
545
|
+
try {
|
|
546
|
+
outStream.end();
|
|
547
|
+
}
|
|
548
|
+
catch (_) { }
|
|
549
|
+
try {
|
|
550
|
+
errStream.end();
|
|
551
|
+
}
|
|
552
|
+
catch (_) { }
|
|
553
|
+
if (shuttingDown) {
|
|
554
|
+
state.status = 'stopped';
|
|
555
|
+
state.child = null;
|
|
556
|
+
checkAllStopped();
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (state.pendingRestart) {
|
|
560
|
+
state.pendingRestart = false;
|
|
561
|
+
state.child = null;
|
|
562
|
+
log(`${appName} restarting...`);
|
|
563
|
+
spawnApp(app);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (code === 0 || signal === 'SIGTERM' || signal === 'SIGINT') {
|
|
567
|
+
state.status = 'stopped';
|
|
568
|
+
state.child = null;
|
|
569
|
+
log(`${appName} stopped cleanly (exit ${code}${signal ? ', signal ' + signal : ''})`);
|
|
570
|
+
checkAllStopped();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
state.child = null;
|
|
574
|
+
const now = nowFn();
|
|
575
|
+
const uptime = now - state.lastStartTime;
|
|
576
|
+
if (state.autorestart === false) {
|
|
577
|
+
state.status = 'crashed';
|
|
578
|
+
logError(`${appName} exited unexpectedly (exit ${code}${signal ? ', signal ' + signal : ''}) and autorestart is disabled.`);
|
|
579
|
+
checkAllStopped();
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const minUptime = state.minUptimeMs || MIN_UPTIME_MS;
|
|
583
|
+
if (uptime < minUptime) {
|
|
584
|
+
state.restartCount++;
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
state.restartCount = 0;
|
|
588
|
+
}
|
|
589
|
+
const maxRestarts = state.maxRestarts || MAX_RESTARTS;
|
|
590
|
+
if (state.restartCount >= maxRestarts) {
|
|
591
|
+
logError(`${appName} exceeded max restarts (${maxRestarts}) without stable uptime. Stopping.`);
|
|
592
|
+
state.status = 'crashed';
|
|
593
|
+
checkAllStopped();
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const restartDelay = state.restartDelayMs || RESTART_DELAY_MS;
|
|
597
|
+
log(`${appName} crashed (exit ${code}${signal ? ', signal ' + signal : ''}), restarting in ${restartDelay / 1000}s (attempt ${state.restartCount}/${maxRestarts})...`);
|
|
598
|
+
state.status = 'restarting';
|
|
599
|
+
setTimeout(() => {
|
|
600
|
+
if (!shuttingDown) {
|
|
601
|
+
spawnApp(app);
|
|
602
|
+
}
|
|
603
|
+
}, restartDelay);
|
|
604
|
+
});
|
|
605
|
+
child.on('error', (err) => {
|
|
606
|
+
logError(`${appName} spawn error:`, err.message);
|
|
607
|
+
});
|
|
608
|
+
return child;
|
|
609
|
+
}
|
|
610
|
+
async function waitForStableStartup({ timeoutMs = 750, pollIntervalMs = 50 } = {}) {
|
|
611
|
+
const trackedStates = () => Array.from(botStates.values()).filter((state) => state.appEntry && state.appEntry.kind !== 'job');
|
|
612
|
+
if (timeoutMs <= 0 || trackedStates().length === 0) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const deadline = nowFn() + timeoutMs;
|
|
616
|
+
while (nowFn() < deadline) {
|
|
617
|
+
const states = trackedStates();
|
|
618
|
+
const failed = states.filter((state) => state.status === 'stopped' || state.status === 'crashed');
|
|
619
|
+
if (failed.length > 0) {
|
|
620
|
+
const details = failed.map((state) => `${state.name} (${state.status})`).join(', ');
|
|
621
|
+
throw new Error(`supervised startup failed: ${details}`);
|
|
622
|
+
}
|
|
623
|
+
const remainingMs = Math.max(deadline - nowFn(), 0);
|
|
624
|
+
await new Promise((resolve) => {
|
|
625
|
+
const timer = setTimeoutFn(resolve, Math.min(pollIntervalMs, remainingMs || pollIntervalMs));
|
|
626
|
+
if (timer && typeof timer.unref === 'function') {
|
|
627
|
+
timer.unref();
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
const states = trackedStates();
|
|
632
|
+
const notRunning = states.filter((state) => state.status !== 'running');
|
|
633
|
+
if (notRunning.length > 0) {
|
|
634
|
+
const details = notRunning.map((state) => `${state.name} (${state.status})`).join(', ');
|
|
635
|
+
throw new Error(`supervised startup failed: ${details}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
async function handleSocketCommand(cmd) {
|
|
639
|
+
try {
|
|
640
|
+
switch (cmd.cmd) {
|
|
641
|
+
case 'status': {
|
|
642
|
+
const status = getStatus();
|
|
643
|
+
return { ok: true, status };
|
|
644
|
+
}
|
|
645
|
+
case 'stop': {
|
|
646
|
+
if (!cmd.bot)
|
|
647
|
+
return { error: 'bot name required' };
|
|
648
|
+
const state = botStates.get(cmd.bot);
|
|
649
|
+
if (!state)
|
|
650
|
+
return { error: `bot '${cmd.bot}' not found` };
|
|
651
|
+
if (state.status !== 'running')
|
|
652
|
+
return { error: `bot '${cmd.bot}' is not running (${state.status})` };
|
|
653
|
+
state.pendingRestart = false;
|
|
654
|
+
state.stoppedByUser = true;
|
|
655
|
+
try {
|
|
656
|
+
state.child.kill('SIGTERM');
|
|
657
|
+
}
|
|
658
|
+
catch (_) { }
|
|
659
|
+
userStopped = true;
|
|
660
|
+
log(`stop: ${cmd.bot}`);
|
|
661
|
+
return { ok: true };
|
|
662
|
+
}
|
|
663
|
+
case 'restart': {
|
|
664
|
+
if (!cmd.bot)
|
|
665
|
+
return { error: 'bot name required' };
|
|
666
|
+
const state = botStates.get(cmd.bot);
|
|
667
|
+
if (!state)
|
|
668
|
+
return { error: `bot '${cmd.bot}' not found` };
|
|
669
|
+
if (state.status === 'running' && state.child) {
|
|
670
|
+
state.pendingRestart = true;
|
|
671
|
+
try {
|
|
672
|
+
state.child.kill('SIGTERM');
|
|
673
|
+
}
|
|
674
|
+
catch (_) { }
|
|
675
|
+
}
|
|
676
|
+
else if ((userStopped || state.stoppedByUser) && state.status === 'stopped' && state.appEntry) {
|
|
677
|
+
spawnApp(state.appEntry);
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
return { error: `bot '${cmd.bot}' is not running (${state.status})` };
|
|
681
|
+
}
|
|
682
|
+
log(`restart: ${cmd.bot}`);
|
|
683
|
+
return { ok: true };
|
|
684
|
+
}
|
|
685
|
+
case 'restart-running':
|
|
686
|
+
await restartRunning();
|
|
687
|
+
return { ok: true };
|
|
688
|
+
case 'stop-all':
|
|
689
|
+
stopAll();
|
|
690
|
+
return { ok: true };
|
|
691
|
+
case 'restart-all':
|
|
692
|
+
await restartAll();
|
|
693
|
+
return { ok: true };
|
|
694
|
+
case 'delete':
|
|
695
|
+
await shutdown({ preserveSockets: cmd.preserveSockets || [] });
|
|
696
|
+
return { ok: true };
|
|
697
|
+
default:
|
|
698
|
+
return { error: `unknown command: ${cmd.cmd}` };
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
catch (err) {
|
|
702
|
+
return { error: err.message };
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function startSocketServer() {
|
|
706
|
+
return new Promise((resolve, reject) => {
|
|
707
|
+
let settled = false;
|
|
708
|
+
const settle = (fn, value) => {
|
|
709
|
+
if (settled)
|
|
710
|
+
return;
|
|
711
|
+
settled = true;
|
|
712
|
+
fn(value);
|
|
713
|
+
};
|
|
714
|
+
const testSocket = net.createConnection(SOCKET_PATH);
|
|
715
|
+
testSocket.on('connect', () => {
|
|
716
|
+
testSocket.end();
|
|
717
|
+
settle(reject, new Error('Another supervisor instance is already running (socket exists). Stop it first or use a different profile.'));
|
|
718
|
+
});
|
|
719
|
+
testSocket.on('error', () => {
|
|
720
|
+
startSocketServerInternal().then(() => settle(resolve, undefined)).catch((err) => settle(reject, err));
|
|
721
|
+
});
|
|
722
|
+
testSocket.setTimeout(500, () => {
|
|
723
|
+
testSocket.destroy();
|
|
724
|
+
startSocketServerInternal().then(() => settle(resolve, undefined)).catch((err) => settle(reject, err));
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
function startSocketServerInternal() {
|
|
729
|
+
return new Promise((resolve, reject) => {
|
|
730
|
+
safeUnlink(SOCKET_PATH);
|
|
731
|
+
socketServer = net.createServer((socket) => {
|
|
732
|
+
socketConnections.add(socket);
|
|
733
|
+
let buffer = '';
|
|
734
|
+
let commandQueue = Promise.resolve();
|
|
735
|
+
let deleteQueued = false;
|
|
736
|
+
const enqueueSocketResponse = (handler) => {
|
|
737
|
+
commandQueue = commandQueue
|
|
738
|
+
.then(handler)
|
|
739
|
+
.catch((err) => {
|
|
740
|
+
try {
|
|
741
|
+
socket.write(JSON.stringify({ error: err.message }) + '\n');
|
|
742
|
+
}
|
|
743
|
+
catch (_) { }
|
|
744
|
+
});
|
|
745
|
+
return commandQueue;
|
|
746
|
+
};
|
|
747
|
+
socket.on('data', (data) => {
|
|
748
|
+
if (deleteQueued)
|
|
749
|
+
return;
|
|
750
|
+
buffer += data.toString();
|
|
751
|
+
const lines = buffer.split('\n');
|
|
752
|
+
buffer = lines.pop();
|
|
753
|
+
for (const line of lines) {
|
|
754
|
+
if (deleteQueued)
|
|
755
|
+
break;
|
|
756
|
+
if (!line.trim())
|
|
757
|
+
continue;
|
|
758
|
+
let cmd;
|
|
759
|
+
try {
|
|
760
|
+
cmd = JSON.parse(line);
|
|
761
|
+
}
|
|
762
|
+
catch (_) {
|
|
763
|
+
enqueueSocketResponse(() => new Promise((resolve) => {
|
|
764
|
+
socket.write(JSON.stringify({ error: 'invalid JSON' }) + '\n', resolve);
|
|
765
|
+
}));
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
if (cmd.cmd === 'delete') {
|
|
769
|
+
deleteQueued = true;
|
|
770
|
+
buffer = '';
|
|
771
|
+
}
|
|
772
|
+
enqueueSocketResponse(async () => {
|
|
773
|
+
const resp = await handleSocketCommand({ ...cmd, preserveSockets: [socket] });
|
|
774
|
+
await new Promise((resolve) => {
|
|
775
|
+
socket.write(JSON.stringify(resp) + '\n', resolve);
|
|
776
|
+
});
|
|
777
|
+
if (cmd.cmd === 'delete') {
|
|
778
|
+
socket.end();
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
socket.on('close', () => {
|
|
784
|
+
socketConnections.delete(socket);
|
|
785
|
+
});
|
|
786
|
+
socket.on('error', () => {
|
|
787
|
+
socketConnections.delete(socket);
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
const onError = (err) => {
|
|
791
|
+
logError(`Socket server error: ${err.message}`);
|
|
792
|
+
reject(err);
|
|
793
|
+
};
|
|
794
|
+
socketServer.once('error', onError);
|
|
795
|
+
socketServer.listen(SOCKET_PATH, () => {
|
|
796
|
+
socketServer.off('error', onError);
|
|
797
|
+
socketServer.on('error', (err) => {
|
|
798
|
+
logError(`Socket server error: ${err.message}`);
|
|
799
|
+
});
|
|
800
|
+
try {
|
|
801
|
+
storage.chmod(SOCKET_PATH, 0o600);
|
|
802
|
+
}
|
|
803
|
+
catch (_) { }
|
|
804
|
+
log(`Control socket: ${SOCKET_PATH}`);
|
|
805
|
+
resolve(undefined);
|
|
806
|
+
});
|
|
807
|
+
process.once('exit', () => {
|
|
808
|
+
safeUnlink(SOCKET_PATH);
|
|
809
|
+
});
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
function closeSocketServer({ preserveSockets = [] } = {}) {
|
|
813
|
+
const preserved = new Set(preserveSockets);
|
|
814
|
+
if (socketServer) {
|
|
815
|
+
try {
|
|
816
|
+
socketServer.close();
|
|
817
|
+
}
|
|
818
|
+
catch (_) { }
|
|
819
|
+
socketServer = null;
|
|
820
|
+
}
|
|
821
|
+
for (const sock of socketConnections) {
|
|
822
|
+
if (preserved.has(sock))
|
|
823
|
+
continue;
|
|
824
|
+
try {
|
|
825
|
+
sock.destroy();
|
|
826
|
+
}
|
|
827
|
+
catch (_) { }
|
|
828
|
+
}
|
|
829
|
+
socketConnections = new Set([...socketConnections].filter((sock) => preserved.has(sock)));
|
|
830
|
+
safeUnlink(SOCKET_PATH);
|
|
831
|
+
}
|
|
832
|
+
async function start() {
|
|
833
|
+
const activeBots = loadActiveBots(bots);
|
|
834
|
+
const activeApps = buildSupervisedApps(activeBots);
|
|
835
|
+
if (activeApps.length === 0) {
|
|
836
|
+
log('No active apps configured.');
|
|
837
|
+
return botStates;
|
|
838
|
+
}
|
|
839
|
+
if (controlSocket) {
|
|
840
|
+
await startSocketServer();
|
|
841
|
+
}
|
|
842
|
+
for (const app of activeApps) {
|
|
843
|
+
const appName = app.name;
|
|
844
|
+
botStates.set(appName, {
|
|
845
|
+
name: appName,
|
|
846
|
+
appEntry: app,
|
|
847
|
+
child: null,
|
|
848
|
+
restartCount: 0,
|
|
849
|
+
lastStartTime: 0,
|
|
850
|
+
status: 'starting',
|
|
851
|
+
pendingRestart: false,
|
|
852
|
+
bulkControl: app.bulk_control !== false,
|
|
853
|
+
cronExpression: app.cron_schedule || null,
|
|
854
|
+
cronSchedule: app.cron_schedule ? parseCronExpression(app.cron_schedule) : null,
|
|
855
|
+
nextScheduledAt: 0,
|
|
856
|
+
scheduledRunTimer: null,
|
|
857
|
+
autorestart: app.autorestart,
|
|
858
|
+
maxRestarts: app.max_restarts || MAX_RESTARTS,
|
|
859
|
+
minUptimeMs: app.min_uptime || MIN_UPTIME_MS,
|
|
860
|
+
restartDelayMs: app.restart_delay || RESTART_DELAY_MS,
|
|
861
|
+
memoryLimitBytes: parseMemoryLimitBytes(app.max_memory_restart),
|
|
862
|
+
stoppedByUser: false,
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
memoryCheckTimer = setInterval(runMemoryCheck, memoryCheckIntervalMs);
|
|
866
|
+
memoryCheckTimer.unref();
|
|
867
|
+
statusLogTimer = setInterval(printStatusSummary, statusLogIntervalMs);
|
|
868
|
+
statusLogTimer.unref();
|
|
869
|
+
log(`Memory limit: ${MAX_MEMORY_MB}MB per process`);
|
|
870
|
+
for (let i = 0; i < activeApps.length; i++) {
|
|
871
|
+
const app = activeApps[i];
|
|
872
|
+
log(`Starting ${app.name}...`);
|
|
873
|
+
try {
|
|
874
|
+
const child = spawnApp(app);
|
|
875
|
+
if (child) {
|
|
876
|
+
await waitForChildSpawn(child);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
catch (err) {
|
|
880
|
+
logError(`Failed to start ${app.name}:`, err.message);
|
|
881
|
+
const state = botStates.get(app.name);
|
|
882
|
+
if (state) {
|
|
883
|
+
state.status = 'crashed';
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (i < activeApps.length - 1) {
|
|
887
|
+
await sleep(STAGGER_DELAY_MS);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
for (const [, state] of botStates) {
|
|
891
|
+
if (state.cronSchedule) {
|
|
892
|
+
scheduleNextRun(state);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
printStatusSummary();
|
|
896
|
+
return botStates;
|
|
897
|
+
}
|
|
898
|
+
function clearTimers() {
|
|
899
|
+
if (memoryCheckTimer) {
|
|
900
|
+
clearInterval(memoryCheckTimer);
|
|
901
|
+
memoryCheckTimer = null;
|
|
902
|
+
}
|
|
903
|
+
if (statusLogTimer) {
|
|
904
|
+
clearInterval(statusLogTimer);
|
|
905
|
+
statusLogTimer = null;
|
|
906
|
+
}
|
|
907
|
+
for (const [, state] of botStates) {
|
|
908
|
+
clearScheduledRun(state);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
function shutdownSignalHandler(signal) {
|
|
912
|
+
for (const [, state] of botStates) {
|
|
913
|
+
forwardSignal(state.child, signal);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
async function shutdown({ preserveSockets = [] } = {}) {
|
|
917
|
+
shuttingDown = true;
|
|
918
|
+
userStopped = false;
|
|
919
|
+
clearTimers();
|
|
920
|
+
closeSocketServer({ preserveSockets });
|
|
921
|
+
shutdownSignalHandler('SIGTERM');
|
|
922
|
+
return new Promise((resolve) => {
|
|
923
|
+
const done = () => {
|
|
924
|
+
if (forceKillTimer)
|
|
925
|
+
clearTimeout(forceKillTimer);
|
|
926
|
+
if (forceResolveTimer)
|
|
927
|
+
clearTimeout(forceResolveTimer);
|
|
928
|
+
resolve(undefined);
|
|
929
|
+
};
|
|
930
|
+
shutdownResolve = () => {
|
|
931
|
+
if (allStopped()) {
|
|
932
|
+
done();
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
const forceKillTimer = setTimeout(() => {
|
|
936
|
+
for (const [, state] of botStates) {
|
|
937
|
+
if (state.child && state.child.exitCode == null && state.status !== 'stopped') {
|
|
938
|
+
try {
|
|
939
|
+
state.child.kill('SIGKILL');
|
|
940
|
+
}
|
|
941
|
+
catch (_) { }
|
|
942
|
+
state.status = 'stopped';
|
|
943
|
+
state.child = null;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
done();
|
|
947
|
+
}, SHUTDOWN_TIMEOUT_MS);
|
|
948
|
+
const forceResolveTimer = setTimeout(() => {
|
|
949
|
+
done();
|
|
950
|
+
}, SHUTDOWN_TIMEOUT_MS + 1000);
|
|
951
|
+
checkAllStopped();
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
function getStatus() {
|
|
955
|
+
const result = {};
|
|
956
|
+
for (const [name, state] of botStates) {
|
|
957
|
+
result[name] = {
|
|
958
|
+
status: state.status,
|
|
959
|
+
pid: state.child?.pid || null,
|
|
960
|
+
restarts: state.restartCount,
|
|
961
|
+
uptimeMs: state.lastStartTime ? nowFn() - state.lastStartTime : 0,
|
|
962
|
+
nextScheduledAt: state.nextScheduledAt || 0,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
function stopAll() {
|
|
968
|
+
userStopped = true;
|
|
969
|
+
for (const [, state] of botStates) {
|
|
970
|
+
if (!state.bulkControl)
|
|
971
|
+
continue;
|
|
972
|
+
state.pendingRestart = false;
|
|
973
|
+
if (state.status === 'running' && state.child) {
|
|
974
|
+
state.stoppedByUser = true;
|
|
975
|
+
try {
|
|
976
|
+
state.child.kill('SIGTERM');
|
|
977
|
+
}
|
|
978
|
+
catch (_) { }
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
log('stop-all');
|
|
982
|
+
}
|
|
983
|
+
async function restartRunning({ logAction = true } = {}) {
|
|
984
|
+
userStopped = false;
|
|
985
|
+
const runningStates = [];
|
|
986
|
+
for (const [, state] of botStates) {
|
|
987
|
+
if (!state.bulkControl)
|
|
988
|
+
continue;
|
|
989
|
+
if (state.status === 'running' && state.child) {
|
|
990
|
+
state.pendingRestart = true;
|
|
991
|
+
runningStates.push({
|
|
992
|
+
state,
|
|
993
|
+
child: state.child,
|
|
994
|
+
pid: state.child.pid || null,
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const adapterStop = await stopMarketAdapter();
|
|
999
|
+
for (const entry of runningStates) {
|
|
1000
|
+
if (adapterStop.pid && entry.pid === adapterStop.pid) {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (entry.state.child !== entry.child) {
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
try {
|
|
1007
|
+
entry.child.kill('SIGTERM');
|
|
1008
|
+
}
|
|
1009
|
+
catch (_) { }
|
|
1010
|
+
}
|
|
1011
|
+
if (adapterStop.stopped) {
|
|
1012
|
+
log(`restart-running: stopped market adapter PID ${adapterStop.pid}`);
|
|
1013
|
+
}
|
|
1014
|
+
if (logAction) {
|
|
1015
|
+
log('restart-running');
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
async function restartAll() {
|
|
1019
|
+
await restartRunning({ logAction: false });
|
|
1020
|
+
for (const [, state] of botStates) {
|
|
1021
|
+
if (!state.bulkControl)
|
|
1022
|
+
continue;
|
|
1023
|
+
if (state.status === 'stopped' && state.appEntry && state.stoppedByUser) {
|
|
1024
|
+
spawnApp(state.appEntry);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
log('restart-all');
|
|
1028
|
+
}
|
|
1029
|
+
function hasUserStopped() {
|
|
1030
|
+
return userStopped;
|
|
1031
|
+
}
|
|
1032
|
+
return {
|
|
1033
|
+
start,
|
|
1034
|
+
shutdown,
|
|
1035
|
+
shutdownSignalHandler,
|
|
1036
|
+
getStatus,
|
|
1037
|
+
printStatusSummary,
|
|
1038
|
+
restartAll,
|
|
1039
|
+
restartRunning,
|
|
1040
|
+
stopAll,
|
|
1041
|
+
hasUserStopped,
|
|
1042
|
+
waitForStableStartup,
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
module.exports = {
|
|
1046
|
+
createBotSupervisor,
|
|
1047
|
+
SOCKET_PATH,
|
|
1048
|
+
parseCronExpression,
|
|
1049
|
+
getNextCronDate,
|
|
1050
|
+
forwardSignal,
|
|
1051
|
+
isPidAlive,
|
|
1052
|
+
waitForPidExit,
|
|
1053
|
+
readProcArgs,
|
|
1054
|
+
readProcCwd,
|
|
1055
|
+
normalizeProcScriptArg,
|
|
1056
|
+
scriptPathForRoot,
|
|
1057
|
+
candidateRuntimeScriptPaths,
|
|
1058
|
+
pidMatchesScriptCandidates,
|
|
1059
|
+
isNodeProcessWithExactScript,
|
|
1060
|
+
readMarketAdapterLockPid,
|
|
1061
|
+
stopMarketAdapterFromLock,
|
|
1062
|
+
usesAmaGridPrice,
|
|
1063
|
+
waitForChildSpawn,
|
|
1064
|
+
getChildRSS,
|
|
1065
|
+
formatUptime,
|
|
1066
|
+
};
|
|
1067
|
+
//# sourceMappingURL=bot_supervisor.js.map
|