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
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
*
|
|
59
59
|
* ===============================================================================
|
|
60
60
|
*/
|
|
61
|
+
import AsyncLock from './order/async_lock.js';
|
|
61
62
|
import { sanitizeKey } from './utils/sanitize_key.js';
|
|
62
63
|
/**
|
|
63
64
|
* Generate a unique key for identifying a bot in storage.
|
|
@@ -68,7 +69,47 @@ import { sanitizeKey } from './utils/sanitize_key.js';
|
|
|
68
69
|
* @param {number} index - Index in bots array (used for unnamed fallback)
|
|
69
70
|
* @returns {string} Sanitized key
|
|
70
71
|
*/
|
|
71
|
-
declare function createBotKey(bot:
|
|
72
|
+
declare function createBotKey(bot: Record<string, unknown> | null | undefined, index: number): string;
|
|
73
|
+
interface BotMeta {
|
|
74
|
+
key: string;
|
|
75
|
+
name: string | null;
|
|
76
|
+
assetA: string | null;
|
|
77
|
+
assetB: string | null;
|
|
78
|
+
active: boolean;
|
|
79
|
+
index: number;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
updatedAt: string;
|
|
82
|
+
}
|
|
83
|
+
interface SerializedOrder {
|
|
84
|
+
id: string | null;
|
|
85
|
+
type: string | null;
|
|
86
|
+
state: string | null;
|
|
87
|
+
price: number;
|
|
88
|
+
size: number;
|
|
89
|
+
orderId: string;
|
|
90
|
+
createUncertain?: boolean;
|
|
91
|
+
}
|
|
92
|
+
interface BotData {
|
|
93
|
+
meta: BotMeta | null;
|
|
94
|
+
grid: SerializedOrder[];
|
|
95
|
+
btsFeesOwed: number;
|
|
96
|
+
btsBalance: Record<string, unknown> | null;
|
|
97
|
+
boundaryIdx: number | null;
|
|
98
|
+
assets: Record<string, unknown> | null;
|
|
99
|
+
debugInputs: Record<string, unknown> | null;
|
|
100
|
+
processedFills: Record<string, number>;
|
|
101
|
+
recentFillKeys: Record<string, unknown>;
|
|
102
|
+
genesis: Record<string, unknown> | null;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
lastUpdated: string;
|
|
105
|
+
gapEvacStreaks?: Record<string, number>;
|
|
106
|
+
pendingFillCrawls?: {
|
|
107
|
+
slotId: string;
|
|
108
|
+
side: string;
|
|
109
|
+
ts: number;
|
|
110
|
+
}[];
|
|
111
|
+
lastFillPivot?: unknown;
|
|
112
|
+
}
|
|
72
113
|
/**
|
|
73
114
|
* AccountOrders class - manages order grid persistence
|
|
74
115
|
*
|
|
@@ -85,9 +126,13 @@ declare function createBotKey(bot: any, index: any): string;
|
|
|
85
126
|
declare class AccountOrders {
|
|
86
127
|
botKey: string;
|
|
87
128
|
profilesPath: string;
|
|
88
|
-
_persistenceLock:
|
|
129
|
+
_persistenceLock: AsyncLock;
|
|
89
130
|
_needsBootstrapSave: boolean;
|
|
90
|
-
data:
|
|
131
|
+
data: BotData;
|
|
132
|
+
_rejectedGenesis?: {
|
|
133
|
+
reason: string;
|
|
134
|
+
at: number;
|
|
135
|
+
};
|
|
91
136
|
/**
|
|
92
137
|
* Create an AccountOrders instance.
|
|
93
138
|
* @param {Object} options - Configuration options
|
|
@@ -105,14 +150,27 @@ declare class AccountOrders {
|
|
|
105
150
|
* @returns {Object|null} The loaded data or null if not found.
|
|
106
151
|
* @private
|
|
107
152
|
*/
|
|
108
|
-
_loadData():
|
|
153
|
+
_loadData(): BotData | null;
|
|
154
|
+
/**
|
|
155
|
+
* Reload `this.data` from disk, falling back to empty state on a miss.
|
|
156
|
+
* Single home for the read-modify-write preamble inside the persistence lock.
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
_reload(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Reload `this.data` from disk when `forceReload` is set. Shared preamble of
|
|
162
|
+
* every `loadX(forceReload)` accessor.
|
|
163
|
+
* @param {boolean} [forceReload=false]
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
_ensureLoaded(forceReload?: boolean): void;
|
|
109
167
|
/**
|
|
110
168
|
* Reads and parses a JSON file.
|
|
111
169
|
* @param {string} filePath - The path to the file.
|
|
112
170
|
* @returns {Object|null} The parsed object or null on failure.
|
|
113
171
|
* @private
|
|
114
172
|
*/
|
|
115
|
-
_readFile(filePath:
|
|
173
|
+
_readFile(filePath: string): BotData | null;
|
|
116
174
|
/**
|
|
117
175
|
* Persists the current data to the profile file.
|
|
118
176
|
* @private
|
|
@@ -124,7 +182,7 @@ declare class AccountOrders {
|
|
|
124
182
|
* meta in place if it has drifted. The grid and other state are not touched.
|
|
125
183
|
* @param {Object} botConfig - The bot config matching this.botKey
|
|
126
184
|
*/
|
|
127
|
-
syncMeta(botConfig:
|
|
185
|
+
syncMeta(botConfig: unknown): Promise<void>;
|
|
128
186
|
/**
|
|
129
187
|
* Checks whether two meta objects differ on the relevant fields.
|
|
130
188
|
* @param {Object} existing - The existing meta (possibly null).
|
|
@@ -132,7 +190,7 @@ declare class AccountOrders {
|
|
|
132
190
|
* @returns {boolean} True if meta has changed.
|
|
133
191
|
* @private
|
|
134
192
|
*/
|
|
135
|
-
_metaChanged(existing:
|
|
193
|
+
_metaChanged(existing: BotMeta | null, next: BotMeta): boolean;
|
|
136
194
|
/**
|
|
137
195
|
* Builds a metadata object for a bot.
|
|
138
196
|
* @param {Object} bot - The bot configuration.
|
|
@@ -142,18 +200,9 @@ declare class AccountOrders {
|
|
|
142
200
|
* @returns {Object} The new meta object.
|
|
143
201
|
* @private
|
|
144
202
|
*/
|
|
145
|
-
_buildMeta(bot:
|
|
203
|
+
_buildMeta(bot: unknown, key: string, index: number, existing?: {
|
|
146
204
|
createdAt?: string;
|
|
147
|
-
} | null):
|
|
148
|
-
key: string;
|
|
149
|
-
name: any;
|
|
150
|
-
assetA: any;
|
|
151
|
-
assetB: any;
|
|
152
|
-
active: boolean;
|
|
153
|
-
index: number;
|
|
154
|
-
createdAt: string;
|
|
155
|
-
updatedAt: string;
|
|
156
|
-
};
|
|
205
|
+
} | null): BotMeta;
|
|
157
206
|
/**
|
|
158
207
|
* Save the current order grid snapshot for this bot.
|
|
159
208
|
* Called after grid changes (initialization, fills, syncs).
|
|
@@ -165,7 +214,7 @@ declare class AccountOrders {
|
|
|
165
214
|
* @param {Object|null} recentFillKeys - Optional fill key dedup snapshot for crash recovery
|
|
166
215
|
* @param {Object|null} genesis - Optional frozen genesis (priceLevels etc)
|
|
167
216
|
*/
|
|
168
|
-
storeMasterGrid(orders?:
|
|
217
|
+
storeMasterGrid(orders?: unknown[], btsFeesOwed?: number | null, boundaryIdx?: number | null, assets?: Record<string, unknown> | null, debugInputs?: unknown, recentFillKeys?: Record<string, unknown> | null, genesis?: unknown, gapEvacStreaks?: unknown, pendingFillCrawls?: unknown, lastFillPivot?: unknown): Promise<void>;
|
|
169
218
|
/**
|
|
170
219
|
* Erase a poisoned persisted boundary after GRID-LOAD rejects it with no
|
|
171
220
|
* safe re-derivation. storeMasterGrid deliberately never writes a null
|
|
@@ -194,7 +243,7 @@ declare class AccountOrders {
|
|
|
194
243
|
* @param {boolean} forceReload - If true, reload from disk to ensure fresh data
|
|
195
244
|
* @returns {Array|null} Order grid array or null if not found
|
|
196
245
|
*/
|
|
197
|
-
loadGrid(forceReload?: boolean):
|
|
246
|
+
loadGrid(forceReload?: boolean): SerializedOrder[] | null;
|
|
198
247
|
/**
|
|
199
248
|
* Load the persisted price-ladder (genesis) for this bot.
|
|
200
249
|
*
|
|
@@ -212,7 +261,7 @@ declare class AccountOrders {
|
|
|
212
261
|
* @param {boolean} forceReload - If true, reload from disk
|
|
213
262
|
* @returns {Object|null} The genesis object, or null when absent/invalid
|
|
214
263
|
*/
|
|
215
|
-
loadGenesis(forceReload?: boolean):
|
|
264
|
+
loadGenesis(forceReload?: boolean): import("./order/utils/math.js").GridGenesis | null;
|
|
216
265
|
/**
|
|
217
266
|
* Record why a persisted genesis row was refused (observability for the
|
|
218
267
|
* schema gate above; loadGrid cannot report a row it never receives).
|
|
@@ -223,7 +272,7 @@ declare class AccountOrders {
|
|
|
223
272
|
* @param {boolean} forceReload - If true, reload from disk
|
|
224
273
|
* @returns {Object|null} {slotId: count} map or null when absent
|
|
225
274
|
*/
|
|
226
|
-
loadGapEvacStreaks(forceReload?: boolean):
|
|
275
|
+
loadGapEvacStreaks(forceReload?: boolean): Record<string, number> | null;
|
|
227
276
|
loadLastFillPivot(forceReload?: boolean): {
|
|
228
277
|
price: number;
|
|
229
278
|
type: string;
|
|
@@ -245,13 +294,13 @@ declare class AccountOrders {
|
|
|
245
294
|
* @param {boolean} forceReload - If true, reload from disk
|
|
246
295
|
* @returns {Object|null} Recent fill keys map or null if not found
|
|
247
296
|
*/
|
|
248
|
-
loadRecentFillKeys(forceReload?: boolean):
|
|
297
|
+
loadRecentFillKeys(forceReload?: boolean): Record<string, unknown> | null;
|
|
249
298
|
/**
|
|
250
299
|
* Load persisted asset metadata for this bot.
|
|
251
300
|
* @param {boolean} forceReload - If true, reload from disk
|
|
252
301
|
* @returns {Object|null} Asset metadata { assetA, assetB } or null if not found
|
|
253
302
|
*/
|
|
254
|
-
loadPersistedAssets(forceReload?: boolean):
|
|
303
|
+
loadPersistedAssets(forceReload?: boolean): Record<string, unknown> | null;
|
|
255
304
|
/**
|
|
256
305
|
* Load the master boundary index for this bot.
|
|
257
306
|
* @param {boolean} forceReload - If true, reload from disk
|
|
@@ -263,7 +312,7 @@ declare class AccountOrders {
|
|
|
263
312
|
* @param {boolean} forceReload - If true, reload from disk
|
|
264
313
|
* @returns {Object|null} BTS balance { free, total, locked } or null if not found
|
|
265
314
|
*/
|
|
266
|
-
loadBtsBalance(forceReload?: boolean):
|
|
315
|
+
loadBtsBalance(forceReload?: boolean): Record<string, unknown> | null;
|
|
267
316
|
/**
|
|
268
317
|
* Load BTS blockchain fees owed for this bot.
|
|
269
318
|
* BTS fees accumulate during fill processing and must persist across restarts
|
|
@@ -276,7 +325,7 @@ declare class AccountOrders {
|
|
|
276
325
|
* Clear the persisted grid for this bot.
|
|
277
326
|
* @returns {Promise<boolean>} true if cleared successfully
|
|
278
327
|
*/
|
|
279
|
-
clearGrid(): Promise<
|
|
328
|
+
clearGrid(): Promise<boolean>;
|
|
280
329
|
/**
|
|
281
330
|
* Load processed fill IDs for this bot to prevent reprocessing fills across
|
|
282
331
|
* restarts. Returns a Map of fillKey => timestamp for fills already processed.
|
|
@@ -315,9 +364,9 @@ declare class AccountOrders {
|
|
|
315
364
|
};
|
|
316
365
|
meta: {
|
|
317
366
|
key: string;
|
|
318
|
-
name:
|
|
319
|
-
assetA:
|
|
320
|
-
assetB:
|
|
367
|
+
name: string | null;
|
|
368
|
+
assetA: string | null;
|
|
369
|
+
assetB: string | null;
|
|
321
370
|
};
|
|
322
371
|
} | null;
|
|
323
372
|
/**
|
|
@@ -326,7 +375,7 @@ declare class AccountOrders {
|
|
|
326
375
|
* @returns {Object} The serialized order.
|
|
327
376
|
* @private
|
|
328
377
|
*/
|
|
329
|
-
_serializeOrder(order?:
|
|
378
|
+
_serializeOrder(order?: unknown): SerializedOrder;
|
|
330
379
|
}
|
|
331
380
|
export { AccountOrders, createBotKey, sanitizeKey };
|
|
332
381
|
//# sourceMappingURL=account_orders.d.ts.map
|
|
@@ -68,7 +68,7 @@ import { hasGenesisLadder } from './order/genesis_policy.js';
|
|
|
68
68
|
import * as Format from './order/format.js';
|
|
69
69
|
import { ensureDir, nowIso, normalizeLastFillPivot } from './order/utils/system.js';
|
|
70
70
|
import Logger from './order/logger.js';
|
|
71
|
-
import { getErrorMessage } from './utils/errors.js';
|
|
71
|
+
import { getErrorMessage, getErrorCode } from './utils/errors.js';
|
|
72
72
|
import { sanitizeKey } from './utils/sanitize_key.js';
|
|
73
73
|
const storage = getStorage();
|
|
74
74
|
const { toFiniteNumber } = Format;
|
|
@@ -176,6 +176,7 @@ class AccountOrders {
|
|
|
176
176
|
_persistenceLock;
|
|
177
177
|
_needsBootstrapSave;
|
|
178
178
|
data;
|
|
179
|
+
_rejectedGenesis;
|
|
179
180
|
/**
|
|
180
181
|
* Create an AccountOrders instance.
|
|
181
182
|
* @param {Object} options - Configuration options
|
|
@@ -193,7 +194,7 @@ class AccountOrders {
|
|
|
193
194
|
// AsyncLock prevents concurrent read-modify-write races on file I/O
|
|
194
195
|
this._persistenceLock = new AsyncLock();
|
|
195
196
|
this._needsBootstrapSave = !storage.exists(this.profilesPath);
|
|
196
|
-
this.
|
|
197
|
+
this._reload();
|
|
197
198
|
if (this._needsBootstrapSave) {
|
|
198
199
|
this._persist();
|
|
199
200
|
}
|
|
@@ -207,6 +208,24 @@ class AccountOrders {
|
|
|
207
208
|
// Load the file directly - per-bot files only contain their own bot's data
|
|
208
209
|
return this._readFile(this.profilesPath);
|
|
209
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Reload `this.data` from disk, falling back to empty state on a miss.
|
|
213
|
+
* Single home for the read-modify-write preamble inside the persistence lock.
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
_reload() {
|
|
217
|
+
this.data = this._loadData() || emptyData();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Reload `this.data` from disk when `forceReload` is set. Shared preamble of
|
|
221
|
+
* every `loadX(forceReload)` accessor.
|
|
222
|
+
* @param {boolean} [forceReload=false]
|
|
223
|
+
* @private
|
|
224
|
+
*/
|
|
225
|
+
_ensureLoaded(forceReload = false) {
|
|
226
|
+
if (forceReload)
|
|
227
|
+
this._reload();
|
|
228
|
+
}
|
|
210
229
|
/**
|
|
211
230
|
* Reads and parses a JSON file.
|
|
212
231
|
* @param {string} filePath - The path to the file.
|
|
@@ -220,7 +239,7 @@ class AccountOrders {
|
|
|
220
239
|
return parsed;
|
|
221
240
|
}
|
|
222
241
|
catch (err) {
|
|
223
|
-
if (err
|
|
242
|
+
if (getErrorCode(err) === 'ENOENT') {
|
|
224
243
|
return null;
|
|
225
244
|
}
|
|
226
245
|
if (err instanceof SyntaxError) {
|
|
@@ -251,8 +270,9 @@ class AccountOrders {
|
|
|
251
270
|
return;
|
|
252
271
|
await this._persistenceLock.acquire(async () => {
|
|
253
272
|
// Reload from disk to ensure we have the latest state
|
|
254
|
-
this.
|
|
255
|
-
const
|
|
273
|
+
this._reload();
|
|
274
|
+
const cfg = botConfig;
|
|
275
|
+
const newMeta = this._buildMeta(botConfig, this.botKey, typeof cfg.botIndex === 'number' ? cfg.botIndex : 0, this.data.meta);
|
|
256
276
|
const prevMeta = this.data.meta;
|
|
257
277
|
if (this._metaChanged(prevMeta, newMeta)) {
|
|
258
278
|
accountOrdersLogger.info(`Metadata changed for bot ${this.botKey}: updating from old metadata to new`);
|
|
@@ -296,12 +316,13 @@ class AccountOrders {
|
|
|
296
316
|
*/
|
|
297
317
|
_buildMeta(bot, key, index, existing = null) {
|
|
298
318
|
const timestamp = nowIso();
|
|
319
|
+
const b = bot;
|
|
299
320
|
return {
|
|
300
321
|
key,
|
|
301
|
-
name:
|
|
302
|
-
assetA:
|
|
303
|
-
assetB:
|
|
304
|
-
active: !!
|
|
322
|
+
name: b.name || null,
|
|
323
|
+
assetA: b.assetA || null,
|
|
324
|
+
assetB: b.assetB || null,
|
|
325
|
+
active: !!b.active,
|
|
305
326
|
index,
|
|
306
327
|
createdAt: (existing && existing.createdAt) || timestamp,
|
|
307
328
|
updatedAt: timestamp
|
|
@@ -322,7 +343,7 @@ class AccountOrders {
|
|
|
322
343
|
// Use AsyncLock to serialize read-modify-write operations
|
|
323
344
|
await this._persistenceLock.acquire(async () => {
|
|
324
345
|
// Reload from disk before writing to prevent race conditions
|
|
325
|
-
this.
|
|
346
|
+
this._reload();
|
|
326
347
|
const snapshot = Array.isArray(orders) ? orders.map((order) => this._serializeOrder(order)) : [];
|
|
327
348
|
const debugSnapshot = debugInputs ? cloneForDebug(debugInputs) : null;
|
|
328
349
|
this.data.grid = snapshot;
|
|
@@ -342,10 +363,6 @@ class AccountOrders {
|
|
|
342
363
|
if (debugSnapshot && debugSnapshot.btsBalance) {
|
|
343
364
|
this.data.btsBalance = debugSnapshot.btsBalance;
|
|
344
365
|
}
|
|
345
|
-
// Initialize processedFills if missing (backward compat)
|
|
346
|
-
if (!this.data.processedFills) {
|
|
347
|
-
this.data.processedFills = {};
|
|
348
|
-
}
|
|
349
366
|
// Persist recent fill keys for crash-durable dedup window
|
|
350
367
|
if (recentFillKeys) {
|
|
351
368
|
this.data.recentFillKeys = recentFillKeys;
|
|
@@ -444,7 +461,7 @@ class AccountOrders {
|
|
|
444
461
|
*/
|
|
445
462
|
async clearPersistedBoundary() {
|
|
446
463
|
await this._persistenceLock.acquire(async () => {
|
|
447
|
-
this.
|
|
464
|
+
this._reload();
|
|
448
465
|
this.data.boundaryIdx = null;
|
|
449
466
|
this._persist();
|
|
450
467
|
});
|
|
@@ -462,7 +479,7 @@ class AccountOrders {
|
|
|
462
479
|
*/
|
|
463
480
|
async clearPersistedLastFillPivot() {
|
|
464
481
|
await this._persistenceLock.acquire(async () => {
|
|
465
|
-
this.
|
|
482
|
+
this._reload();
|
|
466
483
|
delete this.data.lastFillPivot;
|
|
467
484
|
this.data.lastUpdated = nowIso();
|
|
468
485
|
this._persist();
|
|
@@ -474,9 +491,7 @@ class AccountOrders {
|
|
|
474
491
|
* @returns {Array|null} Order grid array or null if not found
|
|
475
492
|
*/
|
|
476
493
|
loadGrid(forceReload = false) {
|
|
477
|
-
|
|
478
|
-
this.data = this._loadData() || emptyData();
|
|
479
|
-
}
|
|
494
|
+
this._ensureLoaded(forceReload);
|
|
480
495
|
return (this.data && Array.isArray(this.data.grid)) ? this.data.grid : null;
|
|
481
496
|
}
|
|
482
497
|
/**
|
|
@@ -497,9 +512,7 @@ class AccountOrders {
|
|
|
497
512
|
* @returns {Object|null} The genesis object, or null when absent/invalid
|
|
498
513
|
*/
|
|
499
514
|
loadGenesis(forceReload = false) {
|
|
500
|
-
|
|
501
|
-
this.data = this._loadData() || emptyData();
|
|
502
|
-
}
|
|
515
|
+
this._ensureLoaded(forceReload);
|
|
503
516
|
const genesis = this.data?.genesis;
|
|
504
517
|
// Same predicate as loadGrid/genesis_policy: one definition of "usable
|
|
505
518
|
// ladder", so the schema gate cannot diverge from the load-time gate.
|
|
@@ -517,9 +530,11 @@ class AccountOrders {
|
|
|
517
530
|
*/
|
|
518
531
|
_noteRejectedGenesis(genesis) {
|
|
519
532
|
try {
|
|
520
|
-
const
|
|
533
|
+
const g = (genesis && typeof genesis === 'object') ? genesis : null;
|
|
534
|
+
const levels = g?.priceLevels;
|
|
535
|
+
const reason = !Array.isArray(levels)
|
|
521
536
|
? 'priceLevels is not an array'
|
|
522
|
-
: (
|
|
537
|
+
: (levels.length === 0 ? 'priceLevels is empty' : 'malformed');
|
|
523
538
|
this._rejectedGenesis = { reason, at: Date.now() };
|
|
524
539
|
}
|
|
525
540
|
catch { /* never fail a load for telemetry */ }
|
|
@@ -530,18 +545,14 @@ class AccountOrders {
|
|
|
530
545
|
* @returns {Object|null} {slotId: count} map or null when absent
|
|
531
546
|
*/
|
|
532
547
|
loadGapEvacStreaks(forceReload = false) {
|
|
533
|
-
|
|
534
|
-
this.data = this._loadData() || emptyData();
|
|
535
|
-
}
|
|
548
|
+
this._ensureLoaded(forceReload);
|
|
536
549
|
if (this.data && this.data.gapEvacStreaks && typeof this.data.gapEvacStreaks === 'object') {
|
|
537
550
|
return this.data.gapEvacStreaks;
|
|
538
551
|
}
|
|
539
552
|
return null;
|
|
540
553
|
}
|
|
541
554
|
loadLastFillPivot(forceReload = false) {
|
|
542
|
-
|
|
543
|
-
this.data = this._loadData() || emptyData();
|
|
544
|
-
}
|
|
555
|
+
this._ensureLoaded(forceReload);
|
|
545
556
|
// Shared row gate (normalizeLastFillPivot): identical validation to the
|
|
546
557
|
// storeMasterGrid sanitizer, one shape contract for the whole ledger.
|
|
547
558
|
return normalizeLastFillPivot(this.data && this.data.lastFillPivot);
|
|
@@ -552,9 +563,7 @@ class AccountOrders {
|
|
|
552
563
|
* @returns {Array} Sanitized pending crawl entries (possibly empty)
|
|
553
564
|
*/
|
|
554
565
|
loadPendingFillCrawls(forceReload = false) {
|
|
555
|
-
|
|
556
|
-
this.data = this._loadData() || emptyData();
|
|
557
|
-
}
|
|
566
|
+
this._ensureLoaded(forceReload);
|
|
558
567
|
const out = [];
|
|
559
568
|
const stored = this.data && this.data.pendingFillCrawls;
|
|
560
569
|
if (Array.isArray(stored)) {
|
|
@@ -573,9 +582,7 @@ class AccountOrders {
|
|
|
573
582
|
* @returns {Object|null} Recent fill keys map or null if not found
|
|
574
583
|
*/
|
|
575
584
|
loadRecentFillKeys(forceReload = false) {
|
|
576
|
-
|
|
577
|
-
this.data = this._loadData() || emptyData();
|
|
578
|
-
}
|
|
585
|
+
this._ensureLoaded(forceReload);
|
|
579
586
|
if (this.data && this.data.recentFillKeys) {
|
|
580
587
|
return this.data.recentFillKeys;
|
|
581
588
|
}
|
|
@@ -587,9 +594,7 @@ class AccountOrders {
|
|
|
587
594
|
* @returns {Object|null} Asset metadata { assetA, assetB } or null if not found
|
|
588
595
|
*/
|
|
589
596
|
loadPersistedAssets(forceReload = false) {
|
|
590
|
-
|
|
591
|
-
this.data = this._loadData() || emptyData();
|
|
592
|
-
}
|
|
597
|
+
this._ensureLoaded(forceReload);
|
|
593
598
|
if (this.data && this.data.assets) {
|
|
594
599
|
return this.data.assets;
|
|
595
600
|
}
|
|
@@ -601,9 +606,7 @@ class AccountOrders {
|
|
|
601
606
|
* @returns {number|null} Boundary index or null if not found
|
|
602
607
|
*/
|
|
603
608
|
loadBoundaryIdx(forceReload = false) {
|
|
604
|
-
|
|
605
|
-
this.data = this._loadData() || emptyData();
|
|
606
|
-
}
|
|
609
|
+
this._ensureLoaded(forceReload);
|
|
607
610
|
if (this.data) {
|
|
608
611
|
const idx = this.data.boundaryIdx;
|
|
609
612
|
if (typeof idx === 'number' && Number.isFinite(idx)) {
|
|
@@ -618,9 +621,7 @@ class AccountOrders {
|
|
|
618
621
|
* @returns {Object|null} BTS balance { free, total, locked } or null if not found
|
|
619
622
|
*/
|
|
620
623
|
loadBtsBalance(forceReload = false) {
|
|
621
|
-
|
|
622
|
-
this.data = this._loadData() || emptyData();
|
|
623
|
-
}
|
|
624
|
+
this._ensureLoaded(forceReload);
|
|
624
625
|
if (this.data && this.data.btsBalance && typeof this.data.btsBalance === 'object') {
|
|
625
626
|
return this.data.btsBalance;
|
|
626
627
|
}
|
|
@@ -634,9 +635,7 @@ class AccountOrders {
|
|
|
634
635
|
* @returns {number} BTS fees owed or 0 if not found
|
|
635
636
|
*/
|
|
636
637
|
loadBtsFeesOwed(forceReload = false) {
|
|
637
|
-
|
|
638
|
-
this.data = this._loadData() || emptyData();
|
|
639
|
-
}
|
|
638
|
+
this._ensureLoaded(forceReload);
|
|
640
639
|
if (this.data) {
|
|
641
640
|
const fees = this.data.btsFeesOwed;
|
|
642
641
|
if (typeof fees === 'number' && Number.isFinite(fees)) {
|
|
@@ -651,7 +650,7 @@ class AccountOrders {
|
|
|
651
650
|
*/
|
|
652
651
|
async clearGrid() {
|
|
653
652
|
return await this._persistenceLock.acquire(async () => {
|
|
654
|
-
this.
|
|
653
|
+
this._reload();
|
|
655
654
|
this.data.grid = [];
|
|
656
655
|
this.data.btsFeesOwed = 0;
|
|
657
656
|
this.data.boundaryIdx = null;
|
|
@@ -679,9 +678,7 @@ class AccountOrders {
|
|
|
679
678
|
const minTimestamp = typeof options === 'object' && options !== null && Number.isFinite(options.minTimestamp)
|
|
680
679
|
? options.minTimestamp
|
|
681
680
|
: null;
|
|
682
|
-
|
|
683
|
-
this.data = this._loadData() || emptyData();
|
|
684
|
-
}
|
|
681
|
+
this._ensureLoaded(forceReload);
|
|
685
682
|
if (this.data) {
|
|
686
683
|
const fills = this.data.processedFills || {};
|
|
687
684
|
const entries = Object.entries(fills).filter(([, timestamp]) => minTimestamp == null || (Number.isFinite(timestamp) && timestamp >= minTimestamp));
|
|
@@ -697,7 +694,7 @@ class AccountOrders {
|
|
|
697
694
|
if (!(fills instanceof Map) || fills.size === 0)
|
|
698
695
|
return;
|
|
699
696
|
await this._persistenceLock.acquire(async () => {
|
|
700
|
-
this.
|
|
697
|
+
this._reload();
|
|
701
698
|
if (!this.data.processedFills) {
|
|
702
699
|
this.data.processedFills = {};
|
|
703
700
|
}
|
|
@@ -724,7 +721,7 @@ class AccountOrders {
|
|
|
724
721
|
async cleanOldProcessedFills(olderThanMs = 3600000) {
|
|
725
722
|
// Default: 1 hour (3600000ms)
|
|
726
723
|
await this._persistenceLock.acquire(async () => {
|
|
727
|
-
this.
|
|
724
|
+
this._reload();
|
|
728
725
|
if (!this.data.processedFills) {
|
|
729
726
|
return;
|
|
730
727
|
}
|
|
@@ -750,9 +747,7 @@ class AccountOrders {
|
|
|
750
747
|
* @returns {Object|null} Balance summary or null if no data
|
|
751
748
|
*/
|
|
752
749
|
getAssetBalances(forceReload = false) {
|
|
753
|
-
|
|
754
|
-
this.data = this._loadData() || emptyData();
|
|
755
|
-
}
|
|
750
|
+
this._ensureLoaded(forceReload);
|
|
756
751
|
if (!this.data)
|
|
757
752
|
return null;
|
|
758
753
|
const meta = this.data.meta || {};
|
|
@@ -788,20 +783,21 @@ class AccountOrders {
|
|
|
788
783
|
* @private
|
|
789
784
|
*/
|
|
790
785
|
_serializeOrder(order = {}) {
|
|
791
|
-
const
|
|
792
|
-
const
|
|
786
|
+
const o = order;
|
|
787
|
+
const priceValue = toFiniteNumber(o.price);
|
|
788
|
+
const sizeValue = toFiniteNumber(o.size);
|
|
793
789
|
// SANITY CHECK: If order is ACTIVE/PARTIAL but has no orderId, it's corrupted.
|
|
794
790
|
// Downgrade to VIRTUAL to prevent persisting phantom active orders.
|
|
795
791
|
// This fixes the root cause of "Active No ID" state in JSON files.
|
|
796
|
-
let state =
|
|
797
|
-
let orderId =
|
|
792
|
+
let state = o.state || null;
|
|
793
|
+
let orderId = o.orderId || '';
|
|
798
794
|
if (isPhantomOrder(order)) {
|
|
799
795
|
state = ORDER_STATES.VIRTUAL;
|
|
800
796
|
orderId = '';
|
|
801
797
|
}
|
|
802
798
|
const serialized = {
|
|
803
|
-
id:
|
|
804
|
-
type:
|
|
799
|
+
id: o.id || null,
|
|
800
|
+
type: o.type || null,
|
|
805
801
|
state: state,
|
|
806
802
|
price: Number.isFinite(priceValue) ? priceValue : 0,
|
|
807
803
|
size: Number.isFinite(sizeValue) ? sizeValue : 0,
|
|
@@ -811,7 +807,7 @@ class AccountOrders {
|
|
|
811
807
|
// leaves the slot VIRTUAL with its planned size. Only that flagged state
|
|
812
808
|
// is a true sized-orphan candidate at load (grid.ts sanitizer) — plain
|
|
813
809
|
// sized VIRTUAL slots are the normal planned-but-unplaced grid state.
|
|
814
|
-
if (
|
|
810
|
+
if (o.createUncertain === true) {
|
|
815
811
|
serialized.createUncertain = true;
|
|
816
812
|
}
|
|
817
813
|
return serialized;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
interface ChainClientLike {
|
|
2
|
+
db: {
|
|
3
|
+
get_full_accounts(accounts: string[], subscribe: boolean): Promise<unknown>;
|
|
4
|
+
};
|
|
5
|
+
getConfig?(): {
|
|
6
|
+
addressPrefix?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
}
|
|
9
|
+
type TryGetKey = (name: string) => Promise<string | null>;
|
|
10
|
+
type ListNames = () => string[];
|
|
1
11
|
/**
|
|
2
12
|
* Resolve a signing key for an account by walking on-chain authority structures.
|
|
3
13
|
*
|
|
@@ -24,10 +34,10 @@
|
|
|
24
34
|
* @param {Map<string,string>} [pubKeyCache] - Per-call cache for derived public keys (internal)
|
|
25
35
|
* @returns {Promise<string>} Private key WIF string
|
|
26
36
|
*/
|
|
27
|
-
declare function resolvePrivateKey(accountName:
|
|
37
|
+
declare function resolvePrivateKey(accountName: string, chainClient: ChainClientLike, tryGetKey: TryGetKey, listNames: ListNames, depth?: number, pubKeyCache?: Map<string, string>): Promise<string>;
|
|
28
38
|
/**
|
|
29
39
|
* Resolve account ID (1.2.x) to account name via chain.
|
|
30
40
|
*/
|
|
31
|
-
declare function resolveAccountIdToName(chainClient:
|
|
41
|
+
declare function resolveAccountIdToName(chainClient: ChainClientLike, accountId: string | number): Promise<string>;
|
|
32
42
|
export { resolvePrivateKey, resolveAccountIdToName };
|
|
33
43
|
//# sourceMappingURL=authority_resolver.d.ts.map
|
|
@@ -49,10 +49,11 @@ async function resolvePrivateKey(accountName, chainClient, tryGetKey, listNames,
|
|
|
49
49
|
catch (e) {
|
|
50
50
|
throw new Error(`Failed to fetch account '${accountName}' from chain: ${getErrorMessage(e)}`);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
const fullRows = full;
|
|
53
|
+
if (!fullRows || !fullRows[0] || !fullRows[0][1] || !fullRows[0][1].account) {
|
|
53
54
|
throw new Error(`Account '${accountName}' not found on chain`);
|
|
54
55
|
}
|
|
55
|
-
const account =
|
|
56
|
+
const account = fullRows[0][1].account;
|
|
56
57
|
const active = account.active;
|
|
57
58
|
if (!active || typeof active.weight_threshold === 'undefined') {
|
|
58
59
|
throw new Error(`Account '${accountName}' has no active authority`);
|
|
@@ -130,7 +131,7 @@ function normalizeAuthMap(auth) {
|
|
|
130
131
|
return [];
|
|
131
132
|
if (Array.isArray(auth))
|
|
132
133
|
return auth;
|
|
133
|
-
return Object.entries(auth);
|
|
134
|
+
return Object.entries(auth).map(([k, v]) => [k, Number(v)]);
|
|
134
135
|
}
|
|
135
136
|
/**
|
|
136
137
|
* Resolve account ID (1.2.x) to account name via chain.
|
|
@@ -138,9 +139,10 @@ function normalizeAuthMap(auth) {
|
|
|
138
139
|
async function resolveAccountIdToName(chainClient, accountId) {
|
|
139
140
|
if (!/^1\.2\./.test(String(accountId)))
|
|
140
141
|
return String(accountId);
|
|
141
|
-
const full = await chainClient.db.get_full_accounts([accountId], false);
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
const full = await chainClient.db.get_full_accounts([String(accountId)], false);
|
|
143
|
+
const fullRows = full;
|
|
144
|
+
if (fullRows && fullRows[0] && fullRows[0][1] && fullRows[0][1].account && fullRows[0][1].account.name) {
|
|
145
|
+
return fullRows[0][1].account.name;
|
|
144
146
|
}
|
|
145
147
|
throw new Error(`Could not resolve account ID '${accountId}' to name`);
|
|
146
148
|
}
|
|
@@ -184,8 +186,13 @@ function matchKeyByPublicKey(targetPubKey, storedKeys, prefix, pubKeyCache) {
|
|
|
184
186
|
if (!pubKeyStr) {
|
|
185
187
|
const { privateKey } = ecc.wifDecode(wif);
|
|
186
188
|
const pubKeyBuf = ecc.privateKeyToPublicKey(privateKey);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
if (!pubKeyBuf)
|
|
190
|
+
continue;
|
|
191
|
+
const derived = ecc.publicKeyToString(pubKeyBuf, prefix);
|
|
192
|
+
if (!derived || typeof derived !== 'string')
|
|
193
|
+
continue;
|
|
194
|
+
pubKeyStr = derived;
|
|
195
|
+
pubKeyCache.set(wif, derived);
|
|
189
196
|
}
|
|
190
197
|
if (pubKeyStr === targetPubKey)
|
|
191
198
|
return wif;
|