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
|
@@ -54,7 +54,7 @@ const HEADER_WIDTH = 11 + BAR_WIDTH;
|
|
|
54
54
|
*/
|
|
55
55
|
function createBotKey(bot, index) {
|
|
56
56
|
if (bot && bot.name) {
|
|
57
|
-
return sanitizeKey(bot.name);
|
|
57
|
+
return sanitizeKey(String(bot.name));
|
|
58
58
|
}
|
|
59
59
|
const identifier = bot && bot.assetA && bot.assetB
|
|
60
60
|
? `${bot.assetA}/${bot.assetB}`
|
|
@@ -64,9 +64,10 @@ function createBotKey(bot, index) {
|
|
|
64
64
|
return `${sanitizeKey(identifier)}-${index}`;
|
|
65
65
|
}
|
|
66
66
|
function hasOrderGrid(data) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
68
|
+
return false;
|
|
69
|
+
const d = data;
|
|
70
|
+
return Boolean(d.meta && typeof d.meta === 'object' && Array.isArray(d.grid));
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* isAmaGridPrice: Detect bots whose grid price follows the AMA (Kaufman) stream.
|
|
@@ -82,7 +83,8 @@ function isAmaGridPrice(config) {
|
|
|
82
83
|
function resolveAmaKey(config) {
|
|
83
84
|
if (!config || typeof config !== 'object')
|
|
84
85
|
return null;
|
|
85
|
-
const
|
|
86
|
+
const cfg = config;
|
|
87
|
+
const gridPrice = typeof cfg.gridPrice === 'string' ? cfg.gridPrice.trim().toLowerCase() : '';
|
|
86
88
|
if (!/^ama(?:[1-4])?$/.test(gridPrice))
|
|
87
89
|
return null;
|
|
88
90
|
if (gridPrice === 'ama')
|
|
@@ -158,8 +160,8 @@ function buildDynamicWeightInfo(botKey, config) {
|
|
|
158
160
|
let live = null;
|
|
159
161
|
let base = null;
|
|
160
162
|
if (hasDynamicWeightData) {
|
|
161
|
-
const effBuy = Number(dw.effectiveWeights
|
|
162
|
-
const effSell = Number(dw.effectiveWeights
|
|
163
|
+
const effBuy = Number(dw.effectiveWeights?.buy);
|
|
164
|
+
const effSell = Number(dw.effectiveWeights?.sell);
|
|
163
165
|
if (Number.isFinite(effBuy) && Number.isFinite(effSell)) {
|
|
164
166
|
const baseFromSnapshot = dw.baseWeights && typeof dw.baseWeights === 'object' ? dw.baseWeights : null;
|
|
165
167
|
const baseBuy = baseFromSnapshot && Number.isFinite(Number(baseFromSnapshot.buy))
|
|
@@ -223,14 +225,15 @@ function buildDynamicWeightInfo(botKey, config) {
|
|
|
223
225
|
function isRealGridOrder(order) {
|
|
224
226
|
if (!order || typeof order !== 'object')
|
|
225
227
|
return false;
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
const
|
|
228
|
+
const o = order;
|
|
229
|
+
const hasRealState = o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL;
|
|
230
|
+
const hasRealType = o.type === ORDER_TYPES.BUY || o.type === ORDER_TYPES.SELL;
|
|
231
|
+
const hasOrderId = typeof o.orderId === 'string' && o.orderId.trim().length > 0;
|
|
229
232
|
return hasRealState
|
|
230
233
|
&& hasRealType
|
|
231
234
|
&& hasOrderId
|
|
232
|
-
&& Number(
|
|
233
|
-
&& Number(
|
|
235
|
+
&& Number(o.price) > 0
|
|
236
|
+
&& Number(o.size) > 0;
|
|
234
237
|
}
|
|
235
238
|
function getRealGridOrders(botData) {
|
|
236
239
|
return Array.isArray(botData?.grid) ? botData.grid.filter(isRealGridOrder) : [];
|
|
@@ -269,7 +272,7 @@ function stripColorCodes(str) {
|
|
|
269
272
|
* @returns {string} Padded string with original colors preserved
|
|
270
273
|
*/
|
|
271
274
|
// Load bot configurations
|
|
272
|
-
const botsConfig = readJSON(BOTS_CONFIG).bots;
|
|
275
|
+
const botsConfig = readJSON(BOTS_CONFIG).bots ?? [];
|
|
273
276
|
/**
|
|
274
277
|
* formatBotFunds: Normalize a botFunds side value for display.
|
|
275
278
|
*
|
|
@@ -366,8 +369,8 @@ function getOrderFiles() {
|
|
|
366
369
|
* @returns {Object} Analysis result with spread, increment, funds, distribution
|
|
367
370
|
*/
|
|
368
371
|
function analyzeOrder(botData, config, botKey) {
|
|
369
|
-
const meta = botData.meta;
|
|
370
|
-
const grid = botData.grid;
|
|
372
|
+
const meta = botData.meta || {};
|
|
373
|
+
const grid = Array.isArray(botData.grid) ? botData.grid : [];
|
|
371
374
|
// Extract asset pair: prioritize assets object from order data, fall back to meta
|
|
372
375
|
let assetA = meta.assetA;
|
|
373
376
|
let assetB = meta.assetB;
|
|
@@ -383,9 +386,20 @@ function analyzeOrder(botData, config, botKey) {
|
|
|
383
386
|
* The grid contains buy slots (prices below market), sell slots (above market),
|
|
384
387
|
* and optional spread slots. Separation enables independent analysis.
|
|
385
388
|
*/
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
+
// A persisted boundary can be absent: GRID-LOAD erases a poisoned boundary
|
|
390
|
+
// (clearPersistedBoundary) and keeps running boundary-less until fills
|
|
391
|
+
// re-anchor. Index-based rail slicing then degenerates (null coerces to 0),
|
|
392
|
+
// hiding live rail orders. Detect it and classify by slot type so every live
|
|
393
|
+
// order stays visible in the report.
|
|
394
|
+
const hasBoundary = typeof botData.boundaryIdx === 'number' && Number.isFinite(botData.boundaryIdx);
|
|
395
|
+
const boundaryIdx = hasBoundary ? botData.boundaryIdx : 0;
|
|
396
|
+
const boundaryLess = !hasBoundary;
|
|
397
|
+
const buySlots = boundaryLess
|
|
398
|
+
? grid.filter((s) => s.type === ORDER_TYPES.BUY)
|
|
399
|
+
: grid.filter((s, i) => i <= boundaryIdx && s.type === ORDER_TYPES.BUY);
|
|
400
|
+
const sellSlots = boundaryLess
|
|
401
|
+
? grid.filter((s) => s.type === ORDER_TYPES.SELL)
|
|
402
|
+
: grid.filter((s, i) => i > boundaryIdx && s.type === ORDER_TYPES.SELL);
|
|
389
403
|
const spreadSlots = grid.filter((s) => s.type === ORDER_TYPES.SPREAD);
|
|
390
404
|
const activeBuySlots = buySlots.filter((s) => s.state === ORDER_STATES.ACTIVE || s.state === ORDER_STATES.PARTIAL);
|
|
391
405
|
const virtualBuySlots = buySlots.filter((s) => s.state === ORDER_STATES.VIRTUAL);
|
|
@@ -410,13 +424,15 @@ function analyzeOrder(botData, config, botKey) {
|
|
|
410
424
|
// design (a partially-placed grid IS partially masked); it is not a bug, but
|
|
411
425
|
// the output should be read with that caveat in mind.
|
|
412
426
|
const hasOrderId = (s) => !!(s && s.orderId);
|
|
413
|
-
const
|
|
414
|
-
const
|
|
415
|
-
const
|
|
416
|
-
const
|
|
427
|
+
const railBuys = boundaryLess ? grid.filter((s) => s.type === ORDER_TYPES.BUY) : grid.slice(0, boundaryIdx + 1);
|
|
428
|
+
const railSells = boundaryLess ? grid.filter((s) => s.type === ORDER_TYPES.SELL) : grid.slice(boundaryIdx + 1);
|
|
429
|
+
const placedBuys = railBuys.filter((s) => s.type === ORDER_TYPES.BUY && hasOrderId(s));
|
|
430
|
+
const placedSells = railSells.filter((s) => s.type === ORDER_TYPES.SELL && hasOrderId(s));
|
|
431
|
+
const geoBuy = railBuys.filter((s) => s.type === ORDER_TYPES.BUY);
|
|
432
|
+
const geoSell = railSells.filter((s) => s.type === ORDER_TYPES.SELL);
|
|
417
433
|
const bestBuySlot = placedBuys.length
|
|
418
434
|
? placedBuys.reduce((a, b) => (b.price > a.price ? b : a))
|
|
419
|
-
: (geoBuy.length ? geoBuy.reduce((a, b) => (b.price > a.price ? b : a)) : (grid[boundaryIdx] || null));
|
|
435
|
+
: (geoBuy.length ? geoBuy.reduce((a, b) => (b.price > a.price ? b : a)) : (boundaryLess ? null : (grid[boundaryIdx] || null)));
|
|
420
436
|
const bestSellSlot = placedSells.length
|
|
421
437
|
? placedSells.reduce((a, b) => (b.price < a.price ? b : a))
|
|
422
438
|
: (geoSell.length ? geoSell.reduce((a, b) => (b.price < a.price ? b : a)) : null);
|
|
@@ -437,9 +453,9 @@ function analyzeOrder(botData, config, botKey) {
|
|
|
437
453
|
*/
|
|
438
454
|
if (config) {
|
|
439
455
|
// Config exists - calculate variance from target
|
|
440
|
-
targetSpread = config.targetSpreadPercent / 100;
|
|
456
|
+
targetSpread = Number(config.targetSpreadPercent) / 100;
|
|
441
457
|
spreadDiff = realSpread - targetSpread;
|
|
442
|
-
incrementCheck = checkGeometricIncrement(grid, config.incrementPercent / 100);
|
|
458
|
+
incrementCheck = checkGeometricIncrement(grid, Number(config.incrementPercent) / 100);
|
|
443
459
|
}
|
|
444
460
|
else {
|
|
445
461
|
// No config - report actual values only
|
|
@@ -481,7 +497,7 @@ function analyzeOrder(botData, config, botKey) {
|
|
|
481
497
|
return {
|
|
482
498
|
pair: `${assetA}/${assetB}`,
|
|
483
499
|
botName: config?.name || botKey,
|
|
484
|
-
lastUpdated: new Date(meta.updatedAt || botData.lastUpdated),
|
|
500
|
+
lastUpdated: new Date(String(meta.updatedAt || botData.lastUpdated)),
|
|
485
501
|
gridMinPrice: gridMinPrice,
|
|
486
502
|
marketPrice: marketPrice,
|
|
487
503
|
gridMaxPrice: gridMaxPrice,
|
|
@@ -502,6 +518,9 @@ function analyzeOrder(botData, config, botKey) {
|
|
|
502
518
|
virtualFunds: virtualGridFunds,
|
|
503
519
|
// Slot vs fund distribution analysis
|
|
504
520
|
distribution: distribution,
|
|
521
|
+
// True when the snapshot carries no boundary (poisoned-boundary erasure):
|
|
522
|
+
// slot rows are classified by slot type, not rail geometry.
|
|
523
|
+
boundaryLess: boundaryLess,
|
|
505
524
|
// Slot counts for structure overview
|
|
506
525
|
slots: {
|
|
507
526
|
buy: buySlots.length,
|
|
@@ -548,11 +567,11 @@ function computeGridRangeScalingDisplay(config, dynamicWeight) {
|
|
|
548
567
|
if (!dynamicWeight || dynamicWeight.amaCenterPrice == null) {
|
|
549
568
|
return null;
|
|
550
569
|
}
|
|
551
|
-
const centerPrice = dynamicWeight.amaCenterPrice;
|
|
570
|
+
const centerPrice = Number(dynamicWeight.amaCenterPrice);
|
|
552
571
|
let minPrice, maxPrice;
|
|
553
572
|
try {
|
|
554
|
-
minPrice = resolveConfiguredPriceBound(config && config.minPrice, undefined, centerPrice, 'min');
|
|
555
|
-
maxPrice = resolveConfiguredPriceBound(config && config.maxPrice, undefined, centerPrice, 'max');
|
|
573
|
+
minPrice = resolveConfiguredPriceBound((config && config.minPrice), undefined, centerPrice, 'min');
|
|
574
|
+
maxPrice = resolveConfiguredPriceBound((config && config.maxPrice), undefined, centerPrice, 'max');
|
|
556
575
|
}
|
|
557
576
|
catch (_) {
|
|
558
577
|
return null;
|
|
@@ -564,7 +583,7 @@ function computeGridRangeScalingDisplay(config, dynamicWeight) {
|
|
|
564
583
|
let resolvedMinPrice = minPrice;
|
|
565
584
|
let resolvedMaxPrice = maxPrice;
|
|
566
585
|
if (hasAsym) {
|
|
567
|
-
const prices = computeAsymmetricBoundsPrices(centerPrice, minPrice, maxPrice, dynamicWeight.trend, dynamicWeight.appliedAsymmetryFactor);
|
|
586
|
+
const prices = computeAsymmetricBoundsPrices(centerPrice, minPrice, maxPrice, dynamicWeight.trend, Number(dynamicWeight.appliedAsymmetryFactor));
|
|
568
587
|
if (prices) {
|
|
569
588
|
resolvedMinPrice = prices.resolvedMinPrice;
|
|
570
589
|
resolvedMaxPrice = prices.resolvedMaxPrice;
|
|
@@ -971,13 +990,13 @@ function getRawWeightValues(weightDistribution, dynamicWeight) {
|
|
|
971
990
|
const useLive = !!(dynamicWeight
|
|
972
991
|
&& dynamicWeight.isRecent
|
|
973
992
|
&& dynamicWeight.live
|
|
974
|
-
&& Number.isFinite(Number(dynamicWeight.live
|
|
975
|
-
&& Number.isFinite(Number(dynamicWeight.live
|
|
993
|
+
&& Number.isFinite(Number(dynamicWeight.live?.buy))
|
|
994
|
+
&& Number.isFinite(Number(dynamicWeight.live?.sell)));
|
|
976
995
|
if (!useLive) {
|
|
977
996
|
return { buy: staticBuy.toFixed(2), sell: staticSell.toFixed(2) };
|
|
978
997
|
}
|
|
979
|
-
const liveBuy = Number(dynamicWeight.live
|
|
980
|
-
const liveSell = Number(dynamicWeight.live
|
|
998
|
+
const liveBuy = Number(dynamicWeight.live?.buy);
|
|
999
|
+
const liveSell = Number(dynamicWeight.live?.sell);
|
|
981
1000
|
return {
|
|
982
1001
|
buy: liveBuy.toFixed(2),
|
|
983
1002
|
sell: liveSell.toFixed(2)
|
|
@@ -1021,15 +1040,15 @@ function formatWeightLine(weightDistribution, dynamicWeight, maxBuyWidth, maxSel
|
|
|
1021
1040
|
const useLive = !!(dynamicWeight
|
|
1022
1041
|
&& dynamicWeight.isRecent
|
|
1023
1042
|
&& dynamicWeight.live
|
|
1024
|
-
&& Number.isFinite(Number(dynamicWeight.live
|
|
1025
|
-
&& Number.isFinite(Number(dynamicWeight.live
|
|
1043
|
+
&& Number.isFinite(Number(dynamicWeight.live?.buy))
|
|
1044
|
+
&& Number.isFinite(Number(dynamicWeight.live?.sell)));
|
|
1026
1045
|
if (!useLive) {
|
|
1027
1046
|
const buyVal = staticBuy.toFixed(2);
|
|
1028
1047
|
const sellVal = staticSell.toFixed(2);
|
|
1029
1048
|
return ` Weight: ${maxBuyWidth ? buyVal.padEnd(maxBuyWidth) : buyVal} ${colors.buy}buy${colors.reset} | ${maxSellWidth ? sellVal.padEnd(maxSellWidth) : sellVal} ${colors.sell}sell${colors.reset}`;
|
|
1030
1049
|
}
|
|
1031
|
-
const liveBuy = Number(dynamicWeight.live
|
|
1032
|
-
const liveSell = Number(dynamicWeight.live
|
|
1050
|
+
const liveBuy = Number(dynamicWeight.live?.buy);
|
|
1051
|
+
const liveSell = Number(dynamicWeight.live?.sell);
|
|
1033
1052
|
// Compare the two live weights, not their deltas: the side with the larger
|
|
1034
1053
|
// live weight is the one the bot is leaning on most heavily (the "losing"
|
|
1035
1054
|
// side for that asset). When the two live weights are equal, no side is
|
|
@@ -1089,11 +1108,17 @@ function formatWeightLine(weightDistribution, dynamicWeight, maxBuyWidth, maxSel
|
|
|
1089
1108
|
* @param {Object} analysis - Analysis result object from analyzeOrder()
|
|
1090
1109
|
* @returns {string} Formatted multi-line output ready for console.log
|
|
1091
1110
|
*/
|
|
1092
|
-
function formatAnalysis(
|
|
1111
|
+
function formatAnalysis(analysisInput) {
|
|
1112
|
+
const analysis = analysisInput;
|
|
1093
1113
|
const lines = [];
|
|
1094
1114
|
// Header: Trading pair name
|
|
1095
1115
|
lines.push(`\n${colors.cyan}📊 ${analysis.pair}${colors.reset} (${analysis.botName})`);
|
|
1096
1116
|
lines.push(` ${colors.gray}Update: ${analysis.lastUpdated.toLocaleString()}${colors.reset}`);
|
|
1117
|
+
// Boundary-less snapshot: say so out loud so geometry rows are read as
|
|
1118
|
+
// type-based counts, not rail positions.
|
|
1119
|
+
if (analysis.boundaryLess) {
|
|
1120
|
+
lines.push(` ${colors.gray}⚠️ boundary-less mode - slot rows by slot type (no rail geometry)${colors.reset}`);
|
|
1121
|
+
}
|
|
1097
1122
|
lines.push(``);
|
|
1098
1123
|
// Warning: No config available for comparison
|
|
1099
1124
|
if (!analysis.hasConfig) {
|
|
@@ -1106,7 +1131,7 @@ function formatAnalysis(analysis) {
|
|
|
1106
1131
|
* Direction: ↑ if above target, ↓ if below target
|
|
1107
1132
|
*/
|
|
1108
1133
|
if (analysis.hasConfig) {
|
|
1109
|
-
lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} (${formatPercent(analysis.spread.target)}) | Incr.:${formatPercent(analysis.increment.avg).padStart(6)} (${formatPercent(analysis.increment.target)})`);
|
|
1134
|
+
lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} (${formatPercent(Number(analysis.spread.target))}) | Incr.:${formatPercent(analysis.increment.avg).padStart(6)} (${formatPercent(Number(analysis.increment.target))})`);
|
|
1110
1135
|
}
|
|
1111
1136
|
else {
|
|
1112
1137
|
lines.push(` Spread:${formatPercent(analysis.spread.real).padStart(6)} | Incr.:${formatPercent(analysis.increment.avg).padStart(6)}`);
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
interface AssetMeta {
|
|
3
|
+
id?: string;
|
|
4
|
+
precision?: number;
|
|
5
|
+
symbol?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface ChainClientLike {
|
|
9
|
+
BitShares?: {
|
|
10
|
+
db?: Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface MpaBackingCtx {
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
mpa: AssetMeta;
|
|
16
|
+
backing: AssetMeta;
|
|
17
|
+
isPredictionMarket: boolean;
|
|
18
|
+
feedPublicationTime: string | null;
|
|
19
|
+
}
|
|
20
|
+
interface FeedCtx {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
kind: string;
|
|
23
|
+
legs: MpaBackingCtx[];
|
|
24
|
+
}
|
|
2
25
|
declare const FEED_STALE_WARN_AGE_MS: number;
|
|
3
26
|
/** Chart command identity: 'tv' → TradingView exporter, 'dw' → dynamic-weight research chart. */
|
|
4
27
|
type ChartCmd = 'tv' | 'dw';
|
|
@@ -13,27 +36,13 @@ interface ChartRenderer {
|
|
|
13
36
|
/** Lines printed directly under the `Usage:` line. */
|
|
14
37
|
usageBlurb: string[];
|
|
15
38
|
}
|
|
16
|
-
declare function resolveMpaBacking(mpaSymbol: string, bitsharesClient:
|
|
17
|
-
|
|
18
|
-
backing: any;
|
|
19
|
-
isPredictionMarket: boolean;
|
|
20
|
-
feedPublicationTime: string | null;
|
|
21
|
-
} | null>;
|
|
22
|
-
declare function pickFeedContext(symA: string, symB: string, source: string, bitsharesClient: any): Promise<{
|
|
23
|
-
kind: string;
|
|
24
|
-
legs: any[];
|
|
25
|
-
} | null>;
|
|
39
|
+
declare function resolveMpaBacking(mpaSymbol: string, bitsharesClient: ChainClientLike): Promise<MpaBackingCtx | null>;
|
|
40
|
+
declare function pickFeedContext(symA: string, symB: string, source: string, bitsharesClient: ChainClientLike): Promise<FeedCtx | null>;
|
|
26
41
|
declare function feedAgeMs(ctx: {
|
|
27
42
|
feedPublicationTime: string | null;
|
|
28
43
|
}, nowMs?: number): number | null;
|
|
29
|
-
declare function feedName(feedCtx:
|
|
30
|
-
|
|
31
|
-
legs: any[];
|
|
32
|
-
}): string;
|
|
33
|
-
declare function activateFeedIfCovered(symA: string, symB: string, assetA: any, assetB: any, source: string, bitsharesClient: any, label?: string): Promise<{
|
|
34
|
-
kind: string;
|
|
35
|
-
legs: any[];
|
|
36
|
-
} | null>;
|
|
44
|
+
declare function feedName(feedCtx: FeedCtx): string;
|
|
45
|
+
declare function activateFeedIfCovered(symA: string, symB: string, assetA: AssetMeta, assetB: AssetMeta, source: string, bitsharesClient: ChainClientLike, label?: string): Promise<FeedCtx | null>;
|
|
37
46
|
declare function parseArgs(argv: string[], cmd?: ChartCmd): {
|
|
38
47
|
target: string | null;
|
|
39
48
|
months: number;
|
|
@@ -38,7 +38,7 @@ import { fetchMarketCandlesSequentially } from '../market_adapter/inputs/fetch_b
|
|
|
38
38
|
import { fetchFeedCandlesSequentially } from '../market_adapter/inputs/kibana_feed_source.js';
|
|
39
39
|
import { muteChainLogs } from '../modules/utils/chain_logs.js';
|
|
40
40
|
import { isSameBotName, sanitizeKey } from '../modules/utils/sanitize_key.js';
|
|
41
|
-
import { slugPart } from '../market_adapter/interval_utils.js';
|
|
41
|
+
import { slugPart, parseChainTimeToMs } from '../market_adapter/interval_utils.js';
|
|
42
42
|
import { monthsToHours } from '../modules/utils/time_range.js';
|
|
43
43
|
const INTERVAL_SECONDS = 3600;
|
|
44
44
|
const DEFAULT_MONTHS = 3;
|
|
@@ -104,12 +104,12 @@ async function resolveMpaBacking(mpaSymbol, bitsharesClient) {
|
|
|
104
104
|
return null;
|
|
105
105
|
try {
|
|
106
106
|
const objs = await db.get_objects([mpa.bitasset_data_id]);
|
|
107
|
-
const bitasset = Array.isArray(objs) ? objs[0] : objs;
|
|
107
|
+
const bitasset = (Array.isArray(objs) ? objs[0] : objs);
|
|
108
108
|
const backingId = String(bitasset?.options?.short_backing_asset || '');
|
|
109
109
|
if (!backingId)
|
|
110
110
|
return null;
|
|
111
111
|
const metas = typeof db.get_assets === 'function' ? await db.get_assets([backingId]) : null;
|
|
112
|
-
const list = Array.isArray(metas) ? metas.flat(Infinity) : [];
|
|
112
|
+
const list = (Array.isArray(metas) ? metas.flat(Infinity) : []);
|
|
113
113
|
const backing = list.find((a) => String(a?.id) === backingId) || null;
|
|
114
114
|
if (!backing?.id || !Number.isFinite(Number(backing.precision)))
|
|
115
115
|
return null;
|
|
@@ -152,7 +152,7 @@ async function pickFeedContext(symA, symB, source, bitsharesClient) {
|
|
|
152
152
|
function feedAgeMs(ctx, nowMs = Date.now()) {
|
|
153
153
|
if (!ctx?.feedPublicationTime)
|
|
154
154
|
return null;
|
|
155
|
-
const ts =
|
|
155
|
+
const ts = parseChainTimeToMs(ctx.feedPublicationTime);
|
|
156
156
|
if (!Number.isFinite(ts))
|
|
157
157
|
return null;
|
|
158
158
|
return nowMs - ts;
|
|
@@ -160,7 +160,7 @@ function feedAgeMs(ctx, nowMs = Date.now()) {
|
|
|
160
160
|
function feedName(feedCtx) {
|
|
161
161
|
if (feedCtx.kind === 'cross')
|
|
162
162
|
return `${feedCtx.legs[0].mpa.symbol}/${feedCtx.legs[1].mpa.symbol}`;
|
|
163
|
-
return feedCtx.legs[0].mpa.symbol;
|
|
163
|
+
return String(feedCtx.legs[0].mpa.symbol ?? '');
|
|
164
164
|
}
|
|
165
165
|
async function activateFeedIfCovered(symA, symB, assetA, assetB, source, bitsharesClient, label = 'tv') {
|
|
166
166
|
const ctx = await pickFeedContext(symA, symB, source, bitsharesClient);
|
|
@@ -252,12 +252,12 @@ function findBotByTarget(target) {
|
|
|
252
252
|
if (!entry)
|
|
253
253
|
continue;
|
|
254
254
|
if (isSameBotName(entry.name, target))
|
|
255
|
-
return { botKey: computeBotKey(entry, i), meta: entry };
|
|
255
|
+
return { botKey: computeBotKey(entry, i) ?? '', meta: entry };
|
|
256
256
|
}
|
|
257
257
|
const meta = loadBotMeta(target);
|
|
258
258
|
if (meta) {
|
|
259
259
|
const idx = entries.indexOf(meta);
|
|
260
|
-
return { botKey: computeBotKey(meta, idx >= 0 ? idx : 0), meta };
|
|
260
|
+
return { botKey: computeBotKey(meta, idx >= 0 ? idx : 0) ?? '', meta };
|
|
261
261
|
}
|
|
262
262
|
return null;
|
|
263
263
|
}
|
|
@@ -271,13 +271,13 @@ async function resolvePoolAssets(poolId, bitsharesClient) {
|
|
|
271
271
|
if (db && typeof db.get_objects === 'function') {
|
|
272
272
|
try {
|
|
273
273
|
const objs = await db.get_objects([fullId]);
|
|
274
|
-
const pool = Array.isArray(objs) ? objs[0] : null;
|
|
274
|
+
const pool = (Array.isArray(objs) ? objs[0] : null);
|
|
275
275
|
const idA = pool?.asset_a || pool?.asset_ids?.[0];
|
|
276
276
|
const idB = pool?.asset_b || pool?.asset_ids?.[1];
|
|
277
277
|
if (idA && idB) {
|
|
278
278
|
const assets = typeof db.get_assets === 'function' ? await db.get_assets([String(idA), String(idB)]) : null;
|
|
279
279
|
// Tolerate both [..] and [[..]] result shapes.
|
|
280
|
-
const list = Array.isArray(assets) ? assets.flat(Infinity) : [];
|
|
280
|
+
const list = (Array.isArray(assets) ? assets.flat(Infinity) : []);
|
|
281
281
|
const metaA = list.find((a) => String(a?.id) === String(idA));
|
|
282
282
|
const metaB = list.find((a) => String(a?.id) === String(idB));
|
|
283
283
|
if (metaA && metaB) {
|
|
@@ -299,6 +299,8 @@ async function resolvePoolAssets(poolId, bitsharesClient) {
|
|
|
299
299
|
throw new Error(`Pool ${fullId}: expected exactly 2 assets, discovered [${(ids || []).join(', ')}]. Pass AssetA/AssetB instead.`);
|
|
300
300
|
}
|
|
301
301
|
const [idA, idB] = ids.map(String);
|
|
302
|
+
if (!db || typeof db.get_assets !== 'function')
|
|
303
|
+
throw new Error(`Pool ${fullId}: chain asset lookup unavailable`);
|
|
302
304
|
const assets = await db.get_assets([idA, idB]);
|
|
303
305
|
const metaA = (assets || []).find((a) => String(a?.id) === idA);
|
|
304
306
|
const metaB = (assets || []).find((a) => String(a?.id) === idB);
|
|
@@ -347,8 +349,8 @@ async function run(cmd) {
|
|
|
347
349
|
await waitForConnected();
|
|
348
350
|
let tmpFile = null;
|
|
349
351
|
try {
|
|
350
|
-
let assetA;
|
|
351
|
-
let assetB;
|
|
352
|
+
let assetA = {};
|
|
353
|
+
let assetB = {};
|
|
352
354
|
let poolId = null;
|
|
353
355
|
let feedCtx = null;
|
|
354
356
|
let sourceLabel = '';
|
|
@@ -373,7 +375,7 @@ async function run(cmd) {
|
|
|
373
375
|
}
|
|
374
376
|
else {
|
|
375
377
|
try {
|
|
376
|
-
poolId = (await findPoolByAssets(assetA.id, assetB.id, { bitsharesClient, sortBy: 'assetABalance' })).id;
|
|
378
|
+
poolId = (await findPoolByAssets(String(assetA.id), String(assetB.id), { bitsharesClient, sortBy: 'assetABalance' })).id ?? null;
|
|
377
379
|
}
|
|
378
380
|
catch (_) {
|
|
379
381
|
poolId = null;
|
|
@@ -401,7 +403,7 @@ async function run(cmd) {
|
|
|
401
403
|
}
|
|
402
404
|
else {
|
|
403
405
|
try {
|
|
404
|
-
poolId = (await findPoolByAssets(assetA.id, assetB.id, { bitsharesClient, sortBy: 'assetABalance' })).id;
|
|
406
|
+
poolId = (await findPoolByAssets(String(assetA.id), String(assetB.id), { bitsharesClient, sortBy: 'assetABalance' })).id ?? null;
|
|
405
407
|
}
|
|
406
408
|
catch (_) {
|
|
407
409
|
poolId = null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Explicit-`any` budget ratchet.
|
|
4
|
+
*
|
|
5
|
+
* DEXBot2 has ~5k explicit `any` occurrences. Removing them is a long program;
|
|
6
|
+
* this gate makes progress monotonic by failing when the code-line count rises
|
|
7
|
+
* above the committed budget in `any-budget.json`.
|
|
8
|
+
*
|
|
9
|
+
* The root scopes (`modules/`, `market_adapter/`, `analysis/`, `scripts/`) and
|
|
10
|
+
* the experimental `claw/` subtree are tracked with independent budgets so the
|
|
11
|
+
* now-clean root count is not inflated by claw, which is still being paid down.
|
|
12
|
+
*
|
|
13
|
+
* Counts `any` tokens on code lines only (comment / JSDoc lines are ignored so
|
|
14
|
+
* documentation cleanup is not double-counted).
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* node dist/scripts/check_any.js # compare against any-budget.json
|
|
18
|
+
* node dist/scripts/check_any.js --update # write the current count as budget
|
|
19
|
+
* node dist/scripts/check_any.js --list # print per-file counts
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=check_any.d.ts.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Explicit-`any` budget ratchet.
|
|
4
|
+
*
|
|
5
|
+
* DEXBot2 has ~5k explicit `any` occurrences. Removing them is a long program;
|
|
6
|
+
* this gate makes progress monotonic by failing when the code-line count rises
|
|
7
|
+
* above the committed budget in `any-budget.json`.
|
|
8
|
+
*
|
|
9
|
+
* The root scopes (`modules/`, `market_adapter/`, `analysis/`, `scripts/`) and
|
|
10
|
+
* the experimental `claw/` subtree are tracked with independent budgets so the
|
|
11
|
+
* now-clean root count is not inflated by claw, which is still being paid down.
|
|
12
|
+
*
|
|
13
|
+
* Counts `any` tokens on code lines only (comment / JSDoc lines are ignored so
|
|
14
|
+
* documentation cleanup is not double-counted).
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* node dist/scripts/check_any.js # compare against any-budget.json
|
|
18
|
+
* node dist/scripts/check_any.js --update # write the current count as budget
|
|
19
|
+
* node dist/scripts/check_any.js --list # print per-file counts
|
|
20
|
+
*/
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const { PATHS } = require('../modules/paths');
|
|
26
|
+
const ROOT = PATHS.PROJECT_ROOT;
|
|
27
|
+
const BUDGET_FILE = path.join(ROOT, 'any-budget.json');
|
|
28
|
+
const SCAN_DIRS = ['modules', 'market_adapter', 'analysis', 'scripts'];
|
|
29
|
+
const SCAN_ROOT_FILES = true;
|
|
30
|
+
const ROOT_SCOPE = 'root';
|
|
31
|
+
const CLAW_SCOPE = 'claw';
|
|
32
|
+
const CLAW_DIR = 'claw';
|
|
33
|
+
// `any` as an explicit type token only: not preceded by an identifier char or
|
|
34
|
+
// `.` (so the `Promise.any` built-in / member named `any` is not counted) and
|
|
35
|
+
// not inside a string or template literal (log/help prose is not counted).
|
|
36
|
+
const ANY_RE = new RegExp('(?<![\\w.])any\\b', 'g');
|
|
37
|
+
const COMMENT_LINE_RE = /^\s*(\/\/|\*|\/\*)/;
|
|
38
|
+
/** Blank out string and template-literal spans so their prose is not counted. */
|
|
39
|
+
function stripStrings(line) {
|
|
40
|
+
let out = '';
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < line.length) {
|
|
43
|
+
const ch = line[i];
|
|
44
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
45
|
+
i++;
|
|
46
|
+
while (i < line.length && line[i] !== ch) {
|
|
47
|
+
if (line[i] === '\\')
|
|
48
|
+
i++;
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
i++; // closing quote
|
|
52
|
+
out += ' ';
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
out += ch;
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function* walk(dir) {
|
|
61
|
+
if (!fs.existsSync(dir))
|
|
62
|
+
return;
|
|
63
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
64
|
+
const full = path.join(dir, entry.name);
|
|
65
|
+
if (entry.isDirectory()) {
|
|
66
|
+
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === 'tests')
|
|
67
|
+
continue;
|
|
68
|
+
yield* walk(full);
|
|
69
|
+
}
|
|
70
|
+
else if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
|
|
71
|
+
yield full;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function sourceFiles() {
|
|
76
|
+
const files = [];
|
|
77
|
+
for (const dir of SCAN_DIRS)
|
|
78
|
+
files.push(...walk(path.join(ROOT, dir)));
|
|
79
|
+
if (SCAN_ROOT_FILES) {
|
|
80
|
+
for (const entry of fs.readdirSync(ROOT, { withFileTypes: true })) {
|
|
81
|
+
if (entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts')) {
|
|
82
|
+
files.push(path.join(ROOT, entry.name));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return files;
|
|
87
|
+
}
|
|
88
|
+
function clawFiles() {
|
|
89
|
+
return [...walk(path.join(ROOT, CLAW_DIR))];
|
|
90
|
+
}
|
|
91
|
+
function countAny(file) {
|
|
92
|
+
const lines = fs.readFileSync(file, 'utf8').split(/\r?\n/);
|
|
93
|
+
let count = 0;
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
if (COMMENT_LINE_RE.test(line))
|
|
96
|
+
continue;
|
|
97
|
+
const matches = stripStrings(line).match(ANY_RE);
|
|
98
|
+
if (matches)
|
|
99
|
+
count += matches.length;
|
|
100
|
+
}
|
|
101
|
+
return count;
|
|
102
|
+
}
|
|
103
|
+
function countScope(scope, files) {
|
|
104
|
+
const fileCounts = files
|
|
105
|
+
.map((file) => ({ file: path.relative(ROOT, file), count: countAny(file) }))
|
|
106
|
+
.filter((entry) => entry.count > 0)
|
|
107
|
+
.sort((a, b) => b.count - a.count);
|
|
108
|
+
return { scope, files: fileCounts, total: fileCounts.reduce((sum, entry) => sum + entry.count, 0) };
|
|
109
|
+
}
|
|
110
|
+
const scopes = [
|
|
111
|
+
countScope(ROOT_SCOPE, sourceFiles()),
|
|
112
|
+
countScope(CLAW_SCOPE, clawFiles())
|
|
113
|
+
];
|
|
114
|
+
const listMode = process.argv.includes('--list');
|
|
115
|
+
const updateMode = process.argv.includes('--update');
|
|
116
|
+
if (listMode) {
|
|
117
|
+
for (const scope of scopes) {
|
|
118
|
+
for (const entry of scope.files)
|
|
119
|
+
console.log(`${String(entry.count).padStart(5)} ${entry.file}`);
|
|
120
|
+
console.log(`${String(scope.total).padStart(5)} ${scope.scope.toUpperCase()} SUBTOTAL (${scope.files.length} files)`);
|
|
121
|
+
}
|
|
122
|
+
process.exit(0);
|
|
123
|
+
}
|
|
124
|
+
if (updateMode) {
|
|
125
|
+
const next = {
|
|
126
|
+
root: scopes.find((scope) => scope.scope === ROOT_SCOPE).total,
|
|
127
|
+
claw: scopes.find((scope) => scope.scope === CLAW_SCOPE).total,
|
|
128
|
+
updated: new Date().toISOString().slice(0, 10)
|
|
129
|
+
};
|
|
130
|
+
fs.writeFileSync(BUDGET_FILE, `${JSON.stringify(next, null, 2)}\n`);
|
|
131
|
+
console.log(`budget file updated: root=${next.root} claw=${next.claw}`);
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
const fileBudget = fs.existsSync(BUDGET_FILE)
|
|
135
|
+
? JSON.parse(fs.readFileSync(BUDGET_FILE, 'utf8'))
|
|
136
|
+
: {};
|
|
137
|
+
let exceeded = false;
|
|
138
|
+
for (const scope of scopes) {
|
|
139
|
+
const committed = typeof fileBudget[scope.scope] === 'number'
|
|
140
|
+
? fileBudget[scope.scope]
|
|
141
|
+
// Backward compatibility with the original single-scope `{ total }` file.
|
|
142
|
+
: (scope.scope === ROOT_SCOPE && typeof fileBudget.total === 'number' ? fileBudget.total : Infinity);
|
|
143
|
+
if (scope.total > committed) {
|
|
144
|
+
console.error(`\u2716 explicit type budget exceeded [${scope.scope}]: ${scope.total} > ${committed}`);
|
|
145
|
+
exceeded = true;
|
|
146
|
+
}
|
|
147
|
+
else if (scope.total < committed) {
|
|
148
|
+
console.log(`\u2713 [${scope.scope}] explicit type count ${scope.total} is below budget ${committed}. Lower the budget file to ${scope.total} to lock in the gain.`);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.log(`\u2713 [${scope.scope}] explicit type count ${scope.total} is at budget ${committed}.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (exceeded) {
|
|
155
|
+
console.error(' Reduce usages, or run `node dist/scripts/check_any.js --update` only when lowering the budget.');
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=check_any.js.map
|
|
@@ -9,6 +9,7 @@ const require = createRequire(import.meta.url);
|
|
|
9
9
|
*/
|
|
10
10
|
const { BitShares, waitForConnected } = require('../modules/bitshares_client');
|
|
11
11
|
const { getErrorMessage } = require('../modules/utils/errors');
|
|
12
|
+
const { parseChainTimeToMs } = require('../market_adapter/interval_utils');
|
|
12
13
|
const POOL_ID = process.argv.includes('--pool')
|
|
13
14
|
? process.argv[process.argv.indexOf('--pool') + 1]
|
|
14
15
|
: '1.19.133';
|
|
@@ -30,20 +31,17 @@ function fmt(obj) {
|
|
|
30
31
|
return String(obj);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
function parseChainTimeToMs(timeStr) {
|
|
34
|
-
if (!timeStr)
|
|
35
|
-
return Number.NaN;
|
|
36
|
-
const s = String(timeStr);
|
|
37
|
-
return Date.parse(s.endsWith('Z') ? s : `${s}Z`);
|
|
38
|
-
}
|
|
39
34
|
function extractReceived(row) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
const r = row;
|
|
36
|
+
const resultPayload = Array.isArray(r?.op?.result) ? r.op.result[1] : null;
|
|
37
|
+
const rp = resultPayload;
|
|
38
|
+
return Array.isArray(rp?.received)
|
|
39
|
+
? rp.received[0]
|
|
40
|
+
: (rp?.received || null);
|
|
44
41
|
}
|
|
45
42
|
function rowHasTradePayload(row) {
|
|
46
|
-
const
|
|
43
|
+
const r = row;
|
|
44
|
+
const opPayload = Array.isArray(r?.op?.op) ? r.op.op[1] : null;
|
|
47
45
|
return !!(opPayload?.amount_to_sell && extractReceived(row));
|
|
48
46
|
}
|
|
49
47
|
async function collectRecentPoolHistory(poolId, sinceMs, limit, maxPages) {
|
|
@@ -59,7 +57,8 @@ async function collectRecentPoolHistory(poolId, sinceMs, limit, maxPages) {
|
|
|
59
57
|
if (!Array.isArray(page) || page.length === 0)
|
|
60
58
|
break;
|
|
61
59
|
pages++;
|
|
62
|
-
for (const
|
|
60
|
+
for (const raw of page) {
|
|
61
|
+
const row = raw;
|
|
63
62
|
const seq = Number(row?.sequence);
|
|
64
63
|
if (Number.isFinite(seq)) {
|
|
65
64
|
if (seenSequences.has(seq))
|
|
@@ -96,7 +95,8 @@ function summarizeRows(rows) {
|
|
|
96
95
|
}
|
|
97
96
|
const byHourMap = new Map();
|
|
98
97
|
let validTrades = 0;
|
|
99
|
-
for (const
|
|
98
|
+
for (const raw of rows) {
|
|
99
|
+
const row = raw;
|
|
100
100
|
if (rowHasTradePayload(row))
|
|
101
101
|
validTrades++;
|
|
102
102
|
const tsMs = parseChainTimeToMs(row?.time || row?.op?.block_time);
|
|
@@ -49,7 +49,6 @@ function printGridSample() {
|
|
|
49
49
|
// Generate order grid using the configuration
|
|
50
50
|
// createOrderGrid returns { orders, boundaryIdx, initialSpreadCount }
|
|
51
51
|
const { orders, initialSpreadCount: _initialSpreadCount } = createOrderGrid(config);
|
|
52
|
-
// Separate sell and buy orders, extracting just the prices
|
|
53
52
|
const sell = orders.filter((o) => o.type === 'sell').map((o) => o.price);
|
|
54
53
|
const buy = orders.filter((o) => o.type === 'buy').map((o) => o.price);
|
|
55
54
|
// Display sell levels from highest (top) down toward market price
|