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
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
// SECTION 1: EXTERNAL DEPENDENCIES
|
|
35
35
|
// ===============================================================================
|
|
36
36
|
import * as Format from '../format.js';
|
|
37
|
-
import { ORDER_STATES, ORDER_TYPES, COW_ACTIONS, GRID_LIMITS } from '../../constants.js';
|
|
37
|
+
import { ORDER_STATES, ORDER_TYPES, COW_ACTIONS, COW_ORIGINS, GRID_LIMITS } from '../../constants.js';
|
|
38
38
|
import { floatToBlockchainInt, blockchainToFloat, getPrecisionSlack, getPrecisionByOrderType, getDoubleDustThreshold, getSellStartIdx, isSlotIndexInGapBand, isEvacuationRotationAllowed, clamp, priceSlotEqual } from './math.js';
|
|
39
39
|
import { parseSlotIndex } from './slot.js';
|
|
40
40
|
import { isOrderOnChain, isPhantomOrder, convertToSpreadPlaceholder, detectGapEvacuationCandidates, updateGapEvacuationStreaks, isNonBlockingUnmatchedOrder } from './order.js';
|
|
@@ -55,7 +55,7 @@ const VALID_ORDER_TYPES = new Set(Object.values(ORDER_TYPES));
|
|
|
55
55
|
function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
56
56
|
const errors = [];
|
|
57
57
|
const warnings = [];
|
|
58
|
-
|
|
58
|
+
const normalizedOrder = { ...(oldOrder || {}), ...order };
|
|
59
59
|
if (!order || !order.id) {
|
|
60
60
|
errors.push({ code: 'MISSING_ID', message: 'Refusing to update order: missing ID' });
|
|
61
61
|
return { isValid: false, errors, warnings, normalizedOrder: null };
|
|
@@ -66,13 +66,13 @@ function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
|
66
66
|
normalizedOrder.type = ORDER_TYPES.SPREAD;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
if (!VALID_ORDER_STATES.has(normalizedOrder.state)) {
|
|
69
|
+
if (normalizedOrder.state === undefined || !VALID_ORDER_STATES.has(normalizedOrder.state)) {
|
|
70
70
|
errors.push({
|
|
71
71
|
code: 'INVALID_STATE',
|
|
72
72
|
message: `Refusing to update order ${order.id}: invalid state '${normalizedOrder.state}' (context: ${context})`
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
if (!VALID_ORDER_TYPES.has(normalizedOrder.type)) {
|
|
75
|
+
if (normalizedOrder.type === undefined || !VALID_ORDER_TYPES.has(normalizedOrder.type)) {
|
|
76
76
|
errors.push({
|
|
77
77
|
code: 'INVALID_TYPE',
|
|
78
78
|
message: `Refusing to update order ${order.id}: invalid type '${normalizedOrder.type}' (context: ${context})`
|
|
@@ -196,16 +196,17 @@ function validateWorkingGridFunds(workingGrid, projectedFunds, precisions = {},
|
|
|
196
196
|
const buyPrecision = precisions.buyPrecision ?? assets?.assetB?.precision;
|
|
197
197
|
const sellPrecision = precisions.sellPrecision ?? assets?.assetA?.precision;
|
|
198
198
|
const required = calculateRequiredFunds(workingGrid, { buyPrecision, sellPrecision });
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
199
|
+
const funds = projectedFunds ?? {};
|
|
200
|
+
const availableBuy = isValidNumber(funds.allocatedBuy)
|
|
201
|
+
? Number(funds.allocatedBuy)
|
|
202
|
+
: isValidNumber(funds.chainTotalBuy)
|
|
203
|
+
? Number(funds.chainTotalBuy)
|
|
204
|
+
: toFiniteNumber(funds.freeBuy ?? funds.chainFreeBuy);
|
|
205
|
+
const availableSell = isValidNumber(funds.allocatedSell)
|
|
206
|
+
? Number(funds.allocatedSell)
|
|
207
|
+
: isValidNumber(funds.chainTotalSell)
|
|
208
|
+
? Number(funds.chainTotalSell)
|
|
209
|
+
: toFiniteNumber(funds.freeSell ?? funds.chainFreeSell);
|
|
209
210
|
const shortfalls = [];
|
|
210
211
|
const availableBuyInt = floatToBlockchainInt(availableBuy, buyPrecision);
|
|
211
212
|
const availableSellInt = floatToBlockchainInt(availableSell, sellPrecision);
|
|
@@ -270,7 +271,7 @@ function checkFundDrift(orders, accountTotals, assets = null, gridLimits = null)
|
|
|
270
271
|
}
|
|
271
272
|
const precisionSlackBuy = getPrecisionSlack(buyPrecision);
|
|
272
273
|
const precisionSlackSell = getPrecisionSlack(sellPrecision);
|
|
273
|
-
const fundInvariantTolerance = gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE ?? GRID_LIMITS.FUND_INVARIANT_PERCENT_TOLERANCE;
|
|
274
|
+
const fundInvariantTolerance = toFiniteNumber(gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE ?? GRID_LIMITS.FUND_INVARIANT_PERCENT_TOLERANCE);
|
|
274
275
|
const percentTolerance = fundInvariantTolerance / 100;
|
|
275
276
|
const allowedDriftBuy = Math.max(precisionSlackBuy, actualBuy * percentTolerance);
|
|
276
277
|
const allowedDriftSell = Math.max(precisionSlackSell, actualSell * percentTolerance);
|
|
@@ -384,7 +385,7 @@ function stampGapEvacuationRotation(action, sourceMaster, destPrice, destSize, t
|
|
|
384
385
|
const check = isEvacuationRotationAllowed(sourceMaster?.price, sourceMaster?.size, destPrice, destSize, type, stampPrecision);
|
|
385
386
|
if (!check.allowed)
|
|
386
387
|
return action;
|
|
387
|
-
return { ...action, origin:
|
|
388
|
+
return { ...action, origin: COW_ORIGINS.GAP_EVACUATION, evacBoundary: b, evacGapSlots: Math.floor(g) };
|
|
388
389
|
}
|
|
389
390
|
/**
|
|
390
391
|
* Reconcile target grid against master state
|
|
@@ -681,7 +682,7 @@ function summarizeActions(actions) {
|
|
|
681
682
|
/**
|
|
682
683
|
* Check if a rebalance result has executable actions.
|
|
683
684
|
*
|
|
684
|
-
* @param {
|
|
685
|
+
* @param {unknown} rebalanceResult - Rebalance result to check
|
|
685
686
|
* @returns {boolean} True if actions array is non-empty
|
|
686
687
|
*/
|
|
687
688
|
function hasExecutableActions(rebalanceResult) {
|
|
@@ -704,7 +705,7 @@ function hasExecutableActions(rebalanceResult) {
|
|
|
704
705
|
* Returns violating target IDs alongside violations so the caller can skip
|
|
705
706
|
* individual violating CREATEs instead of aborting the entire batch.
|
|
706
707
|
*
|
|
707
|
-
* @param {Array<
|
|
708
|
+
* @param {Array<CowAction>} actions - List of COW actions
|
|
708
709
|
* @param {Map} orders - Current order grid
|
|
709
710
|
* @param {Object|null} [assets=null] - Asset metadata for tolerance calculation
|
|
710
711
|
* @param {Array<Object>} [chainOrderCandidates=[]] - Unmatched on-chain orders
|
|
@@ -996,7 +997,7 @@ function _isProjectionUnchanged(current, targetOrder, resultSize, resultState, r
|
|
|
996
997
|
}
|
|
997
998
|
/**
|
|
998
999
|
* Project target grid into working grid
|
|
999
|
-
* @param {
|
|
1000
|
+
* @param {unknown} workingGrid - Working grid to modify
|
|
1000
1001
|
* @param {Map} targetGrid - Target state
|
|
1001
1002
|
* @param {Object} [options] - Optional parameters
|
|
1002
1003
|
* @param {Array} [options.actions] - Pre-existing COW actions to consider
|
|
@@ -1075,7 +1076,7 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
1075
1076
|
function buildStateUpdates(actions, masterGrid) {
|
|
1076
1077
|
const stateUpdates = [];
|
|
1077
1078
|
for (const action of actions) {
|
|
1078
|
-
if (action.type === COW_ACTIONS.CREATE) {
|
|
1079
|
+
if (action.type === COW_ACTIONS.CREATE && action.order) {
|
|
1079
1080
|
stateUpdates.push({
|
|
1080
1081
|
...action.order,
|
|
1081
1082
|
state: ORDER_STATES.VIRTUAL,
|
|
@@ -1144,9 +1145,10 @@ function buildSuccessResult({ actions, stateUpdates, workingGrid, workingBoundar
|
|
|
1144
1145
|
* @returns {Object} Evaluation result
|
|
1145
1146
|
*/
|
|
1146
1147
|
function evaluateCommit(workingGrid, options = {}) {
|
|
1147
|
-
const
|
|
1148
|
-
const
|
|
1149
|
-
const
|
|
1148
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
1149
|
+
const hasLock = typeof options === 'boolean' ? options : !!opts.hasLock;
|
|
1150
|
+
const currentVersion = toFiniteNumber(opts.currentVersion, null);
|
|
1151
|
+
const masterGrid = opts.masterGrid ?? null;
|
|
1150
1152
|
if (!workingGrid) {
|
|
1151
1153
|
return {
|
|
1152
1154
|
canCommit: false,
|
|
@@ -1178,7 +1180,7 @@ function evaluateCommit(workingGrid, options = {}) {
|
|
|
1178
1180
|
}
|
|
1179
1181
|
if (masterGrid && typeof workingGrid.buildDelta === 'function') {
|
|
1180
1182
|
const delta = workingGrid.buildDelta(masterGrid, {
|
|
1181
|
-
precisions:
|
|
1183
|
+
precisions: opts.comparePrecisions || null
|
|
1182
1184
|
});
|
|
1183
1185
|
if (Array.isArray(delta) && delta.length === 0) {
|
|
1184
1186
|
return {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BitSharesClient } from './system.js';
|
|
2
|
+
interface PoolPriceOverrides {
|
|
2
3
|
derivePoolPrice(symA: string, symB: string): Promise<number | null>;
|
|
3
4
|
}
|
|
4
|
-
export declare function withPoolRef(BitShares:
|
|
5
|
+
export declare function withPoolRef(BitShares: BitSharesClient, poolRef: string | null | undefined): PoolPriceOverrides | null;
|
|
5
6
|
/**
|
|
6
7
|
* Resolve the price-derivation mode from a startPrice value. `startPrice` is
|
|
7
8
|
* the master price source: a string mode ("pool"/"book") governs it, while a
|
|
@@ -13,6 +14,7 @@ export declare function withPoolRef(BitShares: any, poolRef: string | null | und
|
|
|
13
14
|
* @param {string} [fallback='auto'] - Mode when startPrice is not a string.
|
|
14
15
|
* @returns {string} Lowercased mode.
|
|
15
16
|
*/
|
|
16
|
-
export declare function resolveStartPriceMode(startPrice:
|
|
17
|
-
export declare function derivePriceWithPoolRef(BitShares:
|
|
17
|
+
export declare function resolveStartPriceMode(startPrice: unknown, fallback?: string): string;
|
|
18
|
+
export declare function derivePriceWithPoolRef(BitShares: BitSharesClient, symA: string, symB: string, mode: string, poolRef: string | null | undefined): Promise<number | null>;
|
|
19
|
+
export {};
|
|
18
20
|
//# sourceMappingURL=withPoolRef.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getErrorMessage } from '../../utils/errors.js';
|
|
1
2
|
import { lookupAsset, derivePrice as systemDerivePrice, deriveMarketPrice as systemDeriveMarketPrice } from './system.js';
|
|
2
3
|
import { toFiniteNumber, isValidNumber } from '../format.js';
|
|
3
4
|
import * as MathUtils from './math.js';
|
|
@@ -12,7 +13,12 @@ export function withPoolRef(BitShares, poolRef) {
|
|
|
12
13
|
return {
|
|
13
14
|
derivePoolPrice: async (symA, symB) => {
|
|
14
15
|
try {
|
|
15
|
-
const
|
|
16
|
+
const db = BitShares.db;
|
|
17
|
+
if (!db?.get_objects) {
|
|
18
|
+
log.warn(`derivePoolPrice: pool db unavailable for ${pinnedId}`);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const [pool] = await db.get_objects([pinnedId]);
|
|
16
22
|
if (!pool) {
|
|
17
23
|
log.warn(`derivePoolPrice: pool ${pinnedId} not found`);
|
|
18
24
|
return null;
|
|
@@ -22,8 +28,8 @@ export function withPoolRef(BitShares, poolRef) {
|
|
|
22
28
|
let poolLabel = `${pinnedId}`;
|
|
23
29
|
if (isValidNumber(pool.balance_a) && isValidNumber(pool.balance_b)) {
|
|
24
30
|
const [poolAssetA, poolAssetB] = await Promise.all([
|
|
25
|
-
lookupAsset(BitShares, pool.asset_a),
|
|
26
|
-
lookupAsset(BitShares, pool.asset_b),
|
|
31
|
+
lookupAsset(BitShares, pool.asset_a ?? ''),
|
|
32
|
+
lookupAsset(BitShares, pool.asset_b ?? ''),
|
|
27
33
|
]);
|
|
28
34
|
if (!poolAssetA?.id || !poolAssetB?.id || poolAssetA.precision == null || poolAssetB.precision == null) {
|
|
29
35
|
log.warn(`derivePoolPrice(pinned=${pinnedId}): cannot resolve pool asset precisions`);
|
|
@@ -59,14 +65,14 @@ export function withPoolRef(BitShares, poolRef) {
|
|
|
59
65
|
if (invert) {
|
|
60
66
|
amtA = toFiniteNumber(pool.balance_b);
|
|
61
67
|
amtB = toFiniteNumber(pool.balance_a);
|
|
62
|
-
precA = poolAssetB.precision;
|
|
63
|
-
precB = poolAssetA.precision;
|
|
68
|
+
precA = poolAssetB.precision ?? null;
|
|
69
|
+
precB = poolAssetA.precision ?? null;
|
|
64
70
|
}
|
|
65
71
|
else {
|
|
66
72
|
amtA = toFiniteNumber(pool.balance_a);
|
|
67
73
|
amtB = toFiniteNumber(pool.balance_b);
|
|
68
|
-
precA = poolAssetA.precision;
|
|
69
|
-
precB = poolAssetB.precision;
|
|
74
|
+
precA = poolAssetA.precision ?? null;
|
|
75
|
+
precB = poolAssetB.precision ?? null;
|
|
70
76
|
}
|
|
71
77
|
poolLabel = `${poolAssetA.symbol || pool.asset_a}/${poolAssetB.symbol || pool.asset_b} (${pinnedId})`;
|
|
72
78
|
}
|
|
@@ -82,10 +88,10 @@ export function withPoolRef(BitShares, poolRef) {
|
|
|
82
88
|
const resA = pool.reserves.find((r) => String(r.asset_id) === String(aMeta.id));
|
|
83
89
|
const resB = pool.reserves.find((r) => String(r.asset_id) === String(bMeta.id));
|
|
84
90
|
if (resA && resB) {
|
|
85
|
-
amtA = resA.amount;
|
|
86
|
-
amtB = resB.amount;
|
|
87
|
-
precA = aMeta.precision;
|
|
88
|
-
precB = bMeta.precision;
|
|
91
|
+
amtA = Number(resA.amount);
|
|
92
|
+
amtB = Number(resB.amount);
|
|
93
|
+
precA = aMeta.precision ?? null;
|
|
94
|
+
precB = bMeta.precision ?? null;
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
if (!isValidNumber(amtA) || !isValidNumber(amtB) || toFiniteNumber(amtB) === 0 || precA == null || precB == null) {
|
|
@@ -101,7 +107,7 @@ export function withPoolRef(BitShares, poolRef) {
|
|
|
101
107
|
return price;
|
|
102
108
|
}
|
|
103
109
|
catch (err) {
|
|
104
|
-
log.warn(`derivePoolPrice(pinned=${pinnedId}) failed: ${err
|
|
110
|
+
log.warn(`derivePoolPrice(pinned=${pinnedId}) failed: ${getErrorMessage(err)}`);
|
|
105
111
|
return null;
|
|
106
112
|
}
|
|
107
113
|
},
|
|
@@ -70,10 +70,11 @@
|
|
|
70
70
|
*
|
|
71
71
|
* ===============================================================================
|
|
72
72
|
*/
|
|
73
|
+
import type { ManagedOrder, UnknownRecord } from '../types.js';
|
|
73
74
|
declare class WorkingGrid {
|
|
74
|
-
grid: Map<string,
|
|
75
|
+
grid: Map<string, ManagedOrder>;
|
|
75
76
|
modified: Set<string>;
|
|
76
|
-
_indexes:
|
|
77
|
+
_indexes: unknown;
|
|
77
78
|
baseVersion: number;
|
|
78
79
|
_stale: boolean;
|
|
79
80
|
_staleReason: string | null;
|
|
@@ -83,7 +84,7 @@ declare class WorkingGrid {
|
|
|
83
84
|
* @param {Object} [options] - Optional parameters
|
|
84
85
|
* @param {number} [options.baseVersion=0] - Base version number
|
|
85
86
|
*/
|
|
86
|
-
constructor(masterGrid: Map<string,
|
|
87
|
+
constructor(masterGrid: Map<string, ManagedOrder>, options?: {
|
|
87
88
|
baseVersion?: number;
|
|
88
89
|
});
|
|
89
90
|
/**
|
|
@@ -91,26 +92,26 @@ declare class WorkingGrid {
|
|
|
91
92
|
* @param {Map} source - Source map
|
|
92
93
|
* @returns {Map} - Cloned map
|
|
93
94
|
*/
|
|
94
|
-
_cloneGrid(source: Map<string,
|
|
95
|
+
_cloneGrid(source: Map<string, ManagedOrder>): Map<string, ManagedOrder>;
|
|
95
96
|
/**
|
|
96
97
|
* Clone a single order object
|
|
97
98
|
* @param {Object} order - Order to clone
|
|
98
99
|
* @returns {Object} - Cloned order
|
|
99
100
|
*/
|
|
100
|
-
_cloneOrder(order:
|
|
101
|
+
_cloneOrder(order: ManagedOrder): ManagedOrder;
|
|
101
102
|
/**
|
|
102
103
|
* Get order by ID
|
|
103
104
|
* @param {string} id - Order ID
|
|
104
105
|
* @returns {Object|undefined} Order object or undefined
|
|
105
106
|
*/
|
|
106
|
-
get(id: string):
|
|
107
|
+
get(id: string): ManagedOrder | undefined;
|
|
107
108
|
/**
|
|
108
109
|
* Set order and mark as modified
|
|
109
110
|
* @param {string} id - Order ID
|
|
110
111
|
* @param {Object} order - Order object
|
|
111
112
|
* @returns {void}
|
|
112
113
|
*/
|
|
113
|
-
set(id: string, order:
|
|
114
|
+
set(id: string, order: ManagedOrder): void;
|
|
114
115
|
/**
|
|
115
116
|
* Delete order and mark as modified
|
|
116
117
|
* @param {string} id - Order ID
|
|
@@ -127,12 +128,12 @@ declare class WorkingGrid {
|
|
|
127
128
|
* Iterate order values
|
|
128
129
|
* @returns {IterableIterator<Object>}
|
|
129
130
|
*/
|
|
130
|
-
values(): IterableIterator<
|
|
131
|
+
values(): IterableIterator<ManagedOrder>;
|
|
131
132
|
/**
|
|
132
133
|
* Iterate [id, order] pairs
|
|
133
134
|
* @returns {IterableIterator<[string, Object]>}
|
|
134
135
|
*/
|
|
135
|
-
entries(): IterableIterator<[string,
|
|
136
|
+
entries(): IterableIterator<[string, ManagedOrder]>;
|
|
136
137
|
/**
|
|
137
138
|
* Iterate order IDs
|
|
138
139
|
* @returns {IterableIterator<string>}
|
|
@@ -147,14 +148,14 @@ declare class WorkingGrid {
|
|
|
147
148
|
* Get indexes (builds if not cached)
|
|
148
149
|
* @returns {Object} - Grid indexes
|
|
149
150
|
*/
|
|
150
|
-
getIndexes():
|
|
151
|
+
getIndexes(): unknown;
|
|
151
152
|
/**
|
|
152
153
|
* Build delta actions from master grid
|
|
153
154
|
* @param {Map} masterGrid - Original master grid
|
|
154
155
|
* @param {Object} [options={}] - Delta options forwarded to ordersEqual
|
|
155
156
|
* @returns {Array} - Array of action objects
|
|
156
157
|
*/
|
|
157
|
-
buildDelta(masterGrid: Map<string,
|
|
158
|
+
buildDelta(masterGrid: Map<string, ManagedOrder>, options?: UnknownRecord): unknown[];
|
|
158
159
|
/**
|
|
159
160
|
* Check if any modifications were made
|
|
160
161
|
* @returns {boolean} - True if grid was modified
|
|
@@ -180,7 +181,7 @@ declare class WorkingGrid {
|
|
|
180
181
|
* Convert to plain Map (for commit)
|
|
181
182
|
* @returns {Map} - The internal grid map
|
|
182
183
|
*/
|
|
183
|
-
toMap(): Map<string,
|
|
184
|
+
toMap(): Map<string, ManagedOrder>;
|
|
184
185
|
/**
|
|
185
186
|
* Get memory usage estimate
|
|
186
187
|
* @returns {Object} - Memory stats
|
|
@@ -197,7 +198,7 @@ declare class WorkingGrid {
|
|
|
197
198
|
* @param {string} orderId - Order ID to sync
|
|
198
199
|
* @param {number} [masterVersion] - Current master grid version (updates baseVersion to stay in sync)
|
|
199
200
|
*/
|
|
200
|
-
syncFromMaster(masterGrid: Map<string,
|
|
201
|
+
syncFromMaster(masterGrid: Map<string, ManagedOrder>, orderId: string, masterVersion?: number): void;
|
|
201
202
|
}
|
|
202
203
|
export { WorkingGrid };
|
|
203
204
|
//# sourceMappingURL=working_grid.d.ts.map
|
package/dist/modules/paths.d.ts
CHANGED
|
@@ -7,10 +7,7 @@
|
|
|
7
7
|
* system prefixes may be read-only.
|
|
8
8
|
*/
|
|
9
9
|
declare function isGlobalNpmPackageDir(root: string): boolean;
|
|
10
|
-
declare function getHomeConfigDir(): string;
|
|
11
10
|
declare function getHomeProfilesDir(): string;
|
|
12
|
-
declare const HOME_CONFIG_DIR: string;
|
|
13
|
-
declare const HOME_PROFILES_DIR: string;
|
|
14
11
|
/**
|
|
15
12
|
* Resolve the profiles (user state) directory.
|
|
16
13
|
*
|
|
@@ -155,5 +152,5 @@ declare const PATHS: {
|
|
|
155
152
|
declare function getNodeBlacklistFile(stateDir?: string): string;
|
|
156
153
|
declare function getNodeHealthCacheFile(stateDir?: string): string;
|
|
157
154
|
declare function getRecalculateTriggerFile(botKey: string): string;
|
|
158
|
-
export { PATHS,
|
|
155
|
+
export { PATHS, getHomeProfilesDir, resolveProfilesDir, resolveMarketAdapterDirs, resolveClawDirs, resolveAnalysisDirs, isGlobalNpmPackageDir, getNodeBlacklistFile, getNodeHealthCacheFile, getRecalculateTriggerFile, computeRelocationNotices, printRelocationNotices };
|
|
159
156
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/modules/paths.js
CHANGED
|
@@ -83,12 +83,6 @@ function getHomeConfigDir() {
|
|
|
83
83
|
function getHomeProfilesDir() {
|
|
84
84
|
return path.join(getHomeConfigDir(), 'profiles');
|
|
85
85
|
}
|
|
86
|
-
// Snapshot constants — prefer getHomeConfigDir()/getHomeProfilesDir() for live values.
|
|
87
|
-
// ESM named imports capture the snapshot; CJS require() interop is patched below via
|
|
88
|
-
// Object.defineProperty to return live values (see bottom of file). Future ESM code
|
|
89
|
-
// should call getHome*() directly; HOME_* remains for backward compat only.
|
|
90
|
-
const HOME_CONFIG_DIR = getHomeConfigDir();
|
|
91
|
-
const HOME_PROFILES_DIR = getHomeProfilesDir();
|
|
92
86
|
/**
|
|
93
87
|
* Resolve the profiles (user state) directory.
|
|
94
88
|
*
|
|
@@ -149,6 +143,27 @@ function resolveProfilesDir(projectRoot = PROJECT_ROOT) {
|
|
|
149
143
|
return homeDir || repoDir;
|
|
150
144
|
}
|
|
151
145
|
const PROFILES_DIR = resolveProfilesDir();
|
|
146
|
+
/**
|
|
147
|
+
* Shared layout rule for bundled data dirs (market_adapter, claw, analysis):
|
|
148
|
+
* the source layout is used only when the profiles dir also resolves to the
|
|
149
|
+
* repo checkout (and, where required, the bundled dir exists); otherwise the
|
|
150
|
+
* root follows the relocated profiles dir. Env vars override both. `root()`
|
|
151
|
+
* resolves an env-overridable sub-root (e.g. `data`, `state`) under the chosen
|
|
152
|
+
* layout; `DIR` companions use `sourceDir`/`relocatedDir` directly.
|
|
153
|
+
*/
|
|
154
|
+
function resolveBundledLayout(name, profilesDir, projectRoot, requireExisting = false) {
|
|
155
|
+
const sourceDir = path.join(projectRoot, name);
|
|
156
|
+
const relocatedDir = path.join(profilesDir, name);
|
|
157
|
+
const useSourceLayout = profilesDir === path.join(projectRoot, 'profiles')
|
|
158
|
+
&& (!requireExisting || fs.existsSync(sourceDir));
|
|
159
|
+
const root = (envVar, sourceSub = '', relocatedSub = sourceSub) => {
|
|
160
|
+
const env = getEnvLive(envVar);
|
|
161
|
+
if (env)
|
|
162
|
+
return path.resolve(env);
|
|
163
|
+
return useSourceLayout ? path.join(sourceDir, sourceSub) : path.join(relocatedDir, relocatedSub);
|
|
164
|
+
};
|
|
165
|
+
return { sourceDir, relocatedDir, useSourceLayout, root };
|
|
166
|
+
}
|
|
152
167
|
/**
|
|
153
168
|
* Market adapter data/state dirs. State stays next to the code (source
|
|
154
169
|
* layout) only when the profiles dir also resolves to the repo layout —
|
|
@@ -158,22 +173,11 @@ const PROFILES_DIR = resolveProfilesDir();
|
|
|
158
173
|
* state across the repo and home. Env vars override both.
|
|
159
174
|
*/
|
|
160
175
|
function resolveMarketAdapterDirs(profilesDir = PROFILES_DIR, projectRoot = PROJECT_ROOT) {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const stateEnv = getEnvLive('DEXBOT_MARKET_ADAPTER_STATE_DIR');
|
|
165
|
-
const dataRoot = dataEnv
|
|
166
|
-
? path.resolve(dataEnv)
|
|
167
|
-
: useSourceLayout
|
|
168
|
-
? path.join(sourceDir, 'data')
|
|
169
|
-
: path.join(profilesDir, 'market_adapter', 'data');
|
|
170
|
-
const stateRoot = stateEnv
|
|
171
|
-
? path.resolve(stateEnv)
|
|
172
|
-
: useSourceLayout
|
|
173
|
-
? path.join(sourceDir, 'state')
|
|
174
|
-
: path.join(profilesDir, 'market_adapter', 'state');
|
|
176
|
+
const layout = resolveBundledLayout('market_adapter', profilesDir, projectRoot, true);
|
|
177
|
+
const dataRoot = layout.root('DEXBOT_MARKET_ADAPTER_DATA_DIR', 'data');
|
|
178
|
+
const stateRoot = layout.root('DEXBOT_MARKET_ADAPTER_STATE_DIR', 'state');
|
|
175
179
|
return {
|
|
176
|
-
DIR: useSourceLayout ? sourceDir :
|
|
180
|
+
DIR: layout.useSourceLayout ? layout.sourceDir : layout.relocatedDir,
|
|
177
181
|
DATA_DIR: dataRoot,
|
|
178
182
|
LP_DATA_DIR: path.join(dataRoot, 'lp'),
|
|
179
183
|
FEED_DATA_DIR: path.join(dataRoot, 'feed'),
|
|
@@ -194,22 +198,16 @@ const MARKET_ADAPTER = resolveMarketAdapterDirs(PROFILES_DIR, PROJECT_ROOT);
|
|
|
194
198
|
* overrides the data root.
|
|
195
199
|
*/
|
|
196
200
|
function resolveClawDirs(profilesDir = PROFILES_DIR, projectRoot = PROJECT_ROOT) {
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
const clawEnv = getEnvLive('DEXBOT_CLAW_DATA_DIR');
|
|
200
|
-
const dataRoot = clawEnv
|
|
201
|
-
? path.resolve(clawEnv)
|
|
202
|
-
: useSourceLayout
|
|
203
|
-
? path.join(sourceDir, 'data')
|
|
204
|
-
: path.join(profilesDir, 'claw', 'data');
|
|
201
|
+
const layout = resolveBundledLayout('claw', profilesDir, projectRoot);
|
|
202
|
+
const dataRoot = layout.root('DEXBOT_CLAW_DATA_DIR', 'data');
|
|
205
203
|
return {
|
|
206
|
-
DIR: sourceDir,
|
|
204
|
+
DIR: layout.sourceDir,
|
|
207
205
|
DATA_DIR: dataRoot,
|
|
208
206
|
STATE_DIR: path.join(dataRoot, 'state'),
|
|
209
207
|
POSITIONS_FILE: path.join(dataRoot, 'positions.json'),
|
|
210
208
|
WATCHER_HEALTH_FILE: path.join(dataRoot, 'watcher-health.json'),
|
|
211
209
|
MEMU_DIR: path.join(dataRoot, 'memu'),
|
|
212
|
-
MEMU_RUNNER_SCRIPT: path.join(sourceDir, 'scripts', 'memu_runner.py'),
|
|
210
|
+
MEMU_RUNNER_SCRIPT: path.join(layout.sourceDir, 'scripts', 'memu_runner.py'),
|
|
213
211
|
};
|
|
214
212
|
}
|
|
215
213
|
const CLAW = resolveClawDirs(PROFILES_DIR, PROJECT_ROOT);
|
|
@@ -222,14 +220,8 @@ const CLAW = resolveClawDirs(PROFILES_DIR, PROJECT_ROOT);
|
|
|
222
220
|
* DEXBOT_ANALYSIS_DIR overrides the root.
|
|
223
221
|
*/
|
|
224
222
|
function resolveAnalysisDirs(profilesDir = PROFILES_DIR, projectRoot = PROJECT_ROOT) {
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const analysisEnv = getEnvLive('DEXBOT_ANALYSIS_DIR');
|
|
228
|
-
const outRoot = analysisEnv
|
|
229
|
-
? path.resolve(analysisEnv)
|
|
230
|
-
: useSourceLayout
|
|
231
|
-
? sourceDir
|
|
232
|
-
: path.join(profilesDir, 'analysis');
|
|
223
|
+
const layout = resolveBundledLayout('analysis', profilesDir, projectRoot, true);
|
|
224
|
+
const outRoot = layout.root('DEXBOT_ANALYSIS_DIR');
|
|
233
225
|
return {
|
|
234
226
|
DIR: outRoot,
|
|
235
227
|
CHARTS_DIR: path.join(outRoot, 'charts'),
|
|
@@ -238,7 +230,7 @@ function resolveAnalysisDirs(profilesDir = PROFILES_DIR, projectRoot = PROJECT_R
|
|
|
238
230
|
CACHE_DIR: path.join(outRoot, 'cache'),
|
|
239
231
|
// Vendored read-only assets always live with the code (repo checkout
|
|
240
232
|
// or npm package), never under the relocated output root.
|
|
241
|
-
ASSETS_DIR: path.join(sourceDir, 'uplot'),
|
|
233
|
+
ASSETS_DIR: path.join(layout.sourceDir, 'uplot'),
|
|
242
234
|
};
|
|
243
235
|
}
|
|
244
236
|
const ANALYSIS = resolveAnalysisDirs(PROFILES_DIR, PROJECT_ROOT);
|
|
@@ -343,25 +335,5 @@ function getNodeHealthCacheFile(stateDir) {
|
|
|
343
335
|
function getRecalculateTriggerFile(botKey) {
|
|
344
336
|
return path.join(PATHS.PROFILES_DIR, `recalculate.${botKey}.trigger`);
|
|
345
337
|
}
|
|
346
|
-
export { PATHS,
|
|
347
|
-
// Live getters for CJS require() interop (ESM cache not invalidated via require.cache)
|
|
348
|
-
try {
|
|
349
|
-
// @ts-ignore - patch CJS wrapper if present
|
|
350
|
-
const g = globalThis;
|
|
351
|
-
if (g.module && g.module.exports) {
|
|
352
|
-
Object.defineProperty(g.module.exports, 'HOME_PROFILES_DIR', { get: getHomeProfilesDir, enumerable: true, configurable: true });
|
|
353
|
-
Object.defineProperty(g.module.exports, 'HOME_CONFIG_DIR', { get: getHomeConfigDir, enumerable: true, configurable: true });
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
catch { }
|
|
357
|
-
// Also patch this module's own exports object when loaded via require() interop (Node experimental require(esm))
|
|
358
|
-
try {
|
|
359
|
-
// @ts-ignore
|
|
360
|
-
const exp = typeof exports !== 'undefined' ? exports : undefined;
|
|
361
|
-
if (exp) {
|
|
362
|
-
Object.defineProperty(exp, 'HOME_PROFILES_DIR', { get: getHomeProfilesDir, enumerable: true, configurable: true });
|
|
363
|
-
Object.defineProperty(exp, 'HOME_CONFIG_DIR', { get: getHomeConfigDir, enumerable: true, configurable: true });
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
catch { }
|
|
338
|
+
export { PATHS, getHomeProfilesDir, resolveProfilesDir, resolveMarketAdapterDirs, resolveClawDirs, resolveAnalysisDirs, isGlobalNpmPackageDir, getNodeBlacklistFile, getNodeHealthCacheFile, getRecalculateTriggerFile, computeRelocationNotices, printRelocationNotices };
|
|
367
339
|
//# sourceMappingURL=paths.js.map
|
|
@@ -28,7 +28,7 @@ export declare class LinuxProcessDiscovery implements ProcessDiscovery {
|
|
|
28
28
|
readStat(pid: number): ProcessStat | null;
|
|
29
29
|
readMemMB(pid: number): string;
|
|
30
30
|
readCpuTime(pid: number): string;
|
|
31
|
-
readCpuPercent(pid: number, samples?:
|
|
31
|
+
readCpuPercent(pid: number, samples?: number, intervalMs?: number): Promise<string>;
|
|
32
32
|
readUptime(pid: number): string;
|
|
33
33
|
readSystemUptimeSec(): number;
|
|
34
34
|
readSocketInode(socketPath: string): number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
import { getErrorCode } from './utils/errors.js';
|
|
2
3
|
import { getStorage } from './storage/index.js';
|
|
3
4
|
import { runtime } from './runtime.js';
|
|
4
5
|
import { sleep } from './order/utils/system.js';
|
|
@@ -246,7 +247,7 @@ class FallbackProcessDiscovery extends NullProcessDiscovery {
|
|
|
246
247
|
return runtime.kill(pid, 0);
|
|
247
248
|
}
|
|
248
249
|
catch (err) {
|
|
249
|
-
if (err && err
|
|
250
|
+
if (err && getErrorCode(err) === 'EPERM')
|
|
250
251
|
return true;
|
|
251
252
|
return false;
|
|
252
253
|
}
|
|
@@ -3,8 +3,8 @@ export interface Runtime {
|
|
|
3
3
|
exitAfterStderrDrain(code: number): void;
|
|
4
4
|
exitCode: number | undefined;
|
|
5
5
|
kill(pid: number, signal?: string | number): boolean;
|
|
6
|
-
onSignal(signal: string, handler: (...args:
|
|
7
|
-
offSignal(signal: string, handler: (...args:
|
|
6
|
+
onSignal(signal: string, handler: (...args: unknown[]) => void): void;
|
|
7
|
+
offSignal(signal: string, handler: (...args: unknown[]) => void): void;
|
|
8
8
|
readonly pid: number;
|
|
9
9
|
readonly platform: string;
|
|
10
10
|
readonly stdout: {
|
|
@@ -17,10 +17,14 @@ export interface Runtime {
|
|
|
17
17
|
};
|
|
18
18
|
readonly stdin: {
|
|
19
19
|
isTTY?: boolean;
|
|
20
|
-
|
|
20
|
+
isRaw?: boolean;
|
|
21
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
22
|
+
removeListener(event: string, handler: (...args: unknown[]) => void): void;
|
|
21
23
|
resume(): void;
|
|
22
24
|
pause(): void;
|
|
23
25
|
destroy(): void;
|
|
26
|
+
setRawMode?(mode: boolean): void;
|
|
27
|
+
setEncoding?(encoding: string): void;
|
|
24
28
|
} | null;
|
|
25
29
|
readonly argv: string[];
|
|
26
30
|
cwd(): string;
|
package/dist/modules/runtime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
import { getErrorCode } from './utils/errors.js';
|
|
2
3
|
import { isBrowser } from './env.js';
|
|
3
4
|
class NodeRuntime {
|
|
4
5
|
exit(code) { process.exit(code); }
|
|
@@ -14,7 +15,7 @@ class NodeRuntime {
|
|
|
14
15
|
return true;
|
|
15
16
|
}
|
|
16
17
|
catch (e) {
|
|
17
|
-
if (e && e
|
|
18
|
+
if (e && getErrorCode(e) === 'ESRCH') {
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
21
|
throw e;
|
|
@@ -56,14 +57,14 @@ class BrowserRuntime {
|
|
|
56
57
|
kill(_pid, _signal) { return false; }
|
|
57
58
|
onSignal(signal, handler) {
|
|
58
59
|
if (signal === 'SIGINT' || signal === 'SIGTERM') {
|
|
59
|
-
if (isBrowser() && window
|
|
60
|
+
if (isBrowser() && window?.addEventListener) {
|
|
60
61
|
window.addEventListener('beforeunload', handler);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
offSignal(signal, handler) {
|
|
65
66
|
if (signal === 'SIGINT' || signal === 'SIGTERM') {
|
|
66
|
-
if (isBrowser() && window
|
|
67
|
+
if (isBrowser() && window?.removeEventListener) {
|
|
67
68
|
window.removeEventListener('beforeunload', handler);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { UnknownRecord } from './types.js';
|
|
2
|
+
import { GRID_LIMITS, FEE_PARAMETERS, INCREMENT_BOUNDS, TIMING, LOGGING_CONFIG, FILL_PROCESSING, PIPELINE_TIMING, API_LIMITS, COW_PERFORMANCE } from './constants.js';
|
|
3
|
+
interface BotRuntimeSettings {
|
|
4
|
+
gridLimits: typeof GRID_LIMITS;
|
|
5
|
+
feeParams: typeof FEE_PARAMETERS;
|
|
6
|
+
incrementBounds: typeof INCREMENT_BOUNDS;
|
|
7
|
+
timing: typeof TIMING;
|
|
8
|
+
fillProcessing: typeof FILL_PROCESSING;
|
|
9
|
+
cowPerformance: typeof COW_PERFORMANCE;
|
|
10
|
+
pipelineTiming: typeof PIPELINE_TIMING;
|
|
11
|
+
apiLimits: typeof API_LIMITS;
|
|
10
12
|
logging: {
|
|
11
13
|
level: string;
|
|
12
|
-
config:
|
|
14
|
+
config: typeof LOGGING_CONFIG;
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
export declare const RUNTIME_SETTINGS_KEYS: readonly string[];
|
|
@@ -26,5 +28,6 @@ export declare const RUNTIME_SETTINGS_KEYS: readonly string[];
|
|
|
26
28
|
* (re)starts the credit watchdog, removal stops it).
|
|
27
29
|
*/
|
|
28
30
|
export declare const BOT_LIVE_CONFIG_KEYS: readonly string[];
|
|
29
|
-
export declare function resolveBotRuntimeSettings(botConfig:
|
|
31
|
+
export declare function resolveBotRuntimeSettings(botConfig: UnknownRecord): BotRuntimeSettings;
|
|
32
|
+
export {};
|
|
30
33
|
//# sourceMappingURL=runtime_settings.d.ts.map
|