dexbot 1.6.11 → 1.6.12
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 +35 -4
- package/README.md +2 -1
- package/analysis/README.md +2 -0
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -2
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- 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 +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -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 +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +6 -5
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +11 -63
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- 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 +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +1 -1
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +14 -12
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/trade_profitability.d.ts +23 -2
- package/dist/analysis/trade_profitability.js +50 -50
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +6 -5
- 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 +18 -19
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -1
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +5 -5
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +5 -4
- 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/credential-daemon.js +34 -20
- package/dist/dexbot.js +11 -11
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- 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/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- 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 +284 -117
- package/dist/market_adapter/core/market_adapter_service.js +137 -113
- 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 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +96 -224
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- 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 +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- 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 +7 -7
- 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 +67 -48
- 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 +4 -1
- 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/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- 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 +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- 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/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 +55 -62
- 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 +6 -15
- 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 +2 -2
- 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 +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +527 -31
- package/dist/modules/constants.js +15 -47
- package/dist/modules/cr_planner.d.ts +40 -2
- 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 +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- 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/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +108 -83
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- 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 +2 -2
- 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 -6
- 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/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- 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 +4 -4
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- 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 +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +225 -180
- package/dist/modules/order/manager.js +80 -83
- 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 +122 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- 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 +1 -27
- 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 +15 -10
- 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 +7 -4
- 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 +1071 -2
- 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 +23 -1
- 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 +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- 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 +13 -11
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- 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 +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -9
- 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/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +6 -1
- package/modules/README.md +4 -1
- package/package.json +4 -1
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
* Includes GRID_COMPARISON sub-object for grid divergence metrics
|
|
50
50
|
*
|
|
51
51
|
* 6. INCREMENT_BOUNDS - Price increment percentage validation
|
|
52
|
-
* MIN_PERCENT, MAX_PERCENT
|
|
52
|
+
* MIN_PERCENT, MAX_PERCENT
|
|
53
53
|
*
|
|
54
54
|
* FEE CONFIGURATION:
|
|
55
55
|
* 7. FEE_PARAMETERS - Fee calculation and reservation parameters
|
|
@@ -364,6 +364,7 @@ let TIMING = {
|
|
|
364
364
|
CREDIT_DEAL_CHECK_INTERVAL_MIN: 60, // How often to check credit deal expiry (minutes)
|
|
365
365
|
CREDIT_DEAL_EXPIRY_THRESHOLD_HOURS: 12, // Proactively renew deals expiring within this window
|
|
366
366
|
CREDIT_DEAL_SPLIT_MAX_PIECES: 48, // Max pieces per _splitOversizedCreditDeals cycle (~4.8min at 6s/piece)
|
|
367
|
+
CREDIT_REBORROW_MAX_ATTEMPTS: 6, // Drop a deferred reborrow after this many failed build/broadcast attempts
|
|
367
368
|
// LOCK_REFRESH_MIN_MS: Minimum interval for refreshing order lock leases during long operations.
|
|
368
369
|
// Prevents lock expiration during extended reconciliations or batch operations.
|
|
369
370
|
// Default: 250ms (4 refreshes per second minimum during long operations).
|
|
@@ -703,11 +704,7 @@ let INCREMENT_BOUNDS = {
|
|
|
703
704
|
// Minimum increment percentage allowed (0.01%)
|
|
704
705
|
MIN_PERCENT: 0.01,
|
|
705
706
|
// Maximum increment percentage allowed (10%)
|
|
706
|
-
MAX_PERCENT: 10
|
|
707
|
-
// Minimum increment as decimal factor (0.01% = 0.0001)
|
|
708
|
-
MIN_FACTOR: 0.0001,
|
|
709
|
-
// Maximum increment as decimal factor (10% = 0.10)
|
|
710
|
-
MAX_FACTOR: 0.10
|
|
707
|
+
MAX_PERCENT: 10
|
|
711
708
|
};
|
|
712
709
|
// Fee-related parameters for order operations
|
|
713
710
|
let FEE_PARAMETERS = {
|
|
@@ -883,6 +880,13 @@ let FILL_PROCESSING = {
|
|
|
883
880
|
// 0 drains no price updates this cycle. Cancel-class entries are never
|
|
884
881
|
// budgeted by either knob.
|
|
885
882
|
CORRECTION_MAX_UPDATES_PER_CYCLE: null,
|
|
883
|
+
// CORRECTION_INTER_OP_DELAY_MS: spacing between successive correction
|
|
884
|
+
// broadcasts (one update/cancel RPC per iteration). Default null inherits
|
|
885
|
+
// TIMING.SYNC_DELAY_MS (500ms) — the production pacing that keeps a burst
|
|
886
|
+
// of corrections from looking like a flood to the node. Exposed as a
|
|
887
|
+
// config knob so tests can drive the drain at 0ms without wall-clock
|
|
888
|
+
// sleeps; 0 is honored verbatim.
|
|
889
|
+
CORRECTION_INTER_OP_DELAY_MS: null,
|
|
886
890
|
// CORRECTION_QUEUE_WARN_THRESHOLD: emit a rate-limited warn when the
|
|
887
891
|
// persisted correction queue reaches this size, so a growing backlog is
|
|
888
892
|
// surfaced instead of silently starving placements.
|
|
@@ -1111,7 +1115,7 @@ let MARKET_ADAPTER = {
|
|
|
1111
1115
|
// Lower values make the Kalman channel reach maximum influence more easily.
|
|
1112
1116
|
// Higher values require a stronger move before the Kalman branch reaches full effect.
|
|
1113
1117
|
// nob: kalS% (Kalman Max Slope %)
|
|
1114
|
-
DYNAMIC_WEIGHT_KALMAN_MAX_SLOPE_PCT: 1.
|
|
1118
|
+
DYNAMIC_WEIGHT_KALMAN_MAX_SLOPE_PCT: 1.2,
|
|
1115
1119
|
// DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT: Ignore small AMA moves around flat price action.
|
|
1116
1120
|
// Higher values create a larger neutral zone and reduce small trend reactions.
|
|
1117
1121
|
// Lower values make the AMA channel react to smaller moves.
|
|
@@ -1148,8 +1152,9 @@ let MARKET_ADAPTER = {
|
|
|
1148
1152
|
// confirming bars, filtering short-lived excursions. Enabled by default
|
|
1149
1153
|
// (was legacy fire-on-first-crossing): measured over the real 1h pools it
|
|
1150
1154
|
// cuts resets ~35% and whipsaw ~52%→~17%, leaving lag and range-tilt
|
|
1151
|
-
// unchanged. Per bot/market override via `amaSlope.persistBars`
|
|
1152
|
-
// `amaSlope.persistEnabled
|
|
1155
|
+
// unchanged. Per bot/market override via `amaSlope.persistBars` (>= 1 gate
|
|
1156
|
+
// length, 0 disables, 1 = legacy) or `amaSlope.persistEnabled: false`
|
|
1157
|
+
// (disables even while the global flag is on). See docs/AMA_SLOPE_WINDOW.md.
|
|
1153
1158
|
AMA_SLOPE_PERSIST_ENABLED: true,
|
|
1154
1159
|
// AMA_SLOPE_PERSIST_BARS: consecutive confirming bars required before the
|
|
1155
1160
|
// slope-delta grid reset (trigger B) fires once enabled. 1 = legacy behavior
|
|
@@ -1605,7 +1610,6 @@ let COW_PERFORMANCE = {
|
|
|
1605
1610
|
// Structure:
|
|
1606
1611
|
// NATIVE_CLIENT.CHAIN - Graphene chain parameters
|
|
1607
1612
|
// NATIVE_CLIENT.OPERATIONS - Operation type IDs
|
|
1608
|
-
// NATIVE_CLIENT.OBJECT_TYPES - Object space/type IDs
|
|
1609
1613
|
// NATIVE_CLIENT.TRANSACTION - Transaction builder limits
|
|
1610
1614
|
// NATIVE_CLIENT.TRANSPORT - WebSocket transport tuning
|
|
1611
1615
|
// NATIVE_CLIENT.SUBSCRIPTIONS - Fill-detection subscription settings
|
|
@@ -1613,7 +1617,7 @@ let COW_PERFORMANCE = {
|
|
|
1613
1617
|
// NATIVE_CLIENT.ECC - Cryptographic constants (reference only)
|
|
1614
1618
|
//
|
|
1615
1619
|
// Source files:
|
|
1616
|
-
// modules/bitshares-native/serial/chain_constants.ts (CHAIN, OPERATIONS
|
|
1620
|
+
// modules/bitshares-native/serial/chain_constants.ts (CHAIN, OPERATIONS)
|
|
1617
1621
|
// modules/bitshares-native/tx/builder.ts (TRANSACTION)
|
|
1618
1622
|
// modules/bitshares-native/transport.ts (TRANSPORT)
|
|
1619
1623
|
// modules/bitshares-native/subscriptions.ts (SUBSCRIPTIONS)
|
|
@@ -1664,36 +1668,6 @@ let NATIVE_CLIENT = {
|
|
|
1664
1668
|
LIQUIDITY_POOL_EXCHANGE: 63,
|
|
1665
1669
|
},
|
|
1666
1670
|
// -------------------------------------------------------------------------
|
|
1667
|
-
// OBJECT_TYPES — Graphene object space/type IDs
|
|
1668
|
-
// -------------------------------------------------------------------------
|
|
1669
|
-
// Space 1 (protocol), used for blockchain entity identification.
|
|
1670
|
-
// Object IDs follow the format "space.type.instance" (e.g. "1.2.12345" = account).
|
|
1671
|
-
OBJECT_TYPES: {
|
|
1672
|
-
NULL: 0,
|
|
1673
|
-
BASE: 1,
|
|
1674
|
-
ACCOUNT: 2,
|
|
1675
|
-
ASSET: 3,
|
|
1676
|
-
FORCE_SETTLEMENT: 4,
|
|
1677
|
-
COMMITTEE_MEMBER: 5,
|
|
1678
|
-
WITNESS: 6,
|
|
1679
|
-
LIMIT_ORDER: 7,
|
|
1680
|
-
CALL_ORDER: 8,
|
|
1681
|
-
CUSTOM: 9,
|
|
1682
|
-
PROPOSAL: 10,
|
|
1683
|
-
OPERATION_HISTORY: 11,
|
|
1684
|
-
WITHDRAW_PERMISSION: 12,
|
|
1685
|
-
VESTING_BALANCE: 13,
|
|
1686
|
-
WORKER: 14,
|
|
1687
|
-
BALANCE: 15,
|
|
1688
|
-
HTLC: 16,
|
|
1689
|
-
CUSTOM_AUTHORITY: 17,
|
|
1690
|
-
TICKET: 18,
|
|
1691
|
-
LIQUIDITY_POOL: 19,
|
|
1692
|
-
SAMET_FUND: 20,
|
|
1693
|
-
CREDIT_OFFER: 21,
|
|
1694
|
-
CREDIT_DEAL: 22,
|
|
1695
|
-
},
|
|
1696
|
-
// -------------------------------------------------------------------------
|
|
1697
1671
|
// TRANSACTION — Transaction builder limits (tx/builder.js)
|
|
1698
1672
|
// -------------------------------------------------------------------------
|
|
1699
1673
|
TRANSACTION: {
|
|
@@ -1761,11 +1735,6 @@ let NATIVE_CLIENT = {
|
|
|
1761
1735
|
// node failure. 1000 = normal closure, 1001 = going away (server
|
|
1762
1736
|
// shutdown/deploy). Any other code, or wasClean === false, is abnormal.
|
|
1763
1737
|
BENIGN_CLOSE_CODES: [1000, 1001],
|
|
1764
|
-
// NOTE: These constants are informational but not imported by transport.ts
|
|
1765
|
-
// Reconnection backoff parameters (ms).
|
|
1766
|
-
// Reconnect delay = min(base × 2^attempt + random(0..1000), max).
|
|
1767
|
-
RECONNECT_BASE_MS: 1000,
|
|
1768
|
-
RECONNECT_MAX_MS: 30000,
|
|
1769
1738
|
},
|
|
1770
1739
|
// -------------------------------------------------------------------------
|
|
1771
1740
|
// SUBSCRIPTIONS — Fill-detection subscription settings (subscriptions.js)
|
|
@@ -2021,7 +1990,6 @@ Object.freeze(COW_PERFORMANCE);
|
|
|
2021
1990
|
Object.freeze(LOGGING_CONFIG);
|
|
2022
1991
|
Object.freeze(NATIVE_CLIENT.CHAIN);
|
|
2023
1992
|
Object.freeze(NATIVE_CLIENT.OPERATIONS);
|
|
2024
|
-
Object.freeze(NATIVE_CLIENT.OBJECT_TYPES);
|
|
2025
1993
|
Object.freeze(NATIVE_CLIENT.TRANSACTION);
|
|
2026
1994
|
Object.freeze(NATIVE_CLIENT.TRANSPORT);
|
|
2027
1995
|
Object.freeze(NATIVE_CLIENT.SUBSCRIPTIONS);
|
|
@@ -28,7 +28,45 @@ interface CollateralFallbackPlanOptions {
|
|
|
28
28
|
declare function positiveOrNull(value: unknown): number | null;
|
|
29
29
|
declare function resolveMinCollateralIncreaseThreshold(value: unknown, referenceAmount?: unknown): number | null;
|
|
30
30
|
declare function resolveTargetCollateralRatio(policy?: CrPolicy): number | null;
|
|
31
|
-
declare function buildDebtFirstCrPlan({ currentCollateralAmount, currentDebtAmount, feedPrice, minCollateralRatio, maxCollateralRatio, targetCollateralRatio, maxBorrowAmount, maxBorrowAmountPerOperation, maxCollateralAmount, collateralLimitReferenceAmount, minCollateralIncreaseThreshold, debtOnly, }?: DebtFirstCrPlanOptions):
|
|
32
|
-
|
|
31
|
+
declare function buildDebtFirstCrPlan({ currentCollateralAmount, currentDebtAmount, feedPrice, minCollateralRatio, maxCollateralRatio, targetCollateralRatio, maxBorrowAmount, maxBorrowAmountPerOperation, maxCollateralAmount, collateralLimitReferenceAmount, minCollateralIncreaseThreshold, debtOnly, }?: DebtFirstCrPlanOptions): {
|
|
32
|
+
blocked: boolean;
|
|
33
|
+
reason: string;
|
|
34
|
+
action?: undefined;
|
|
35
|
+
fallbackAction?: undefined;
|
|
36
|
+
targetCollateralRatio?: undefined;
|
|
37
|
+
currentCollateralRatio?: undefined;
|
|
38
|
+
currentDebtAmount?: undefined;
|
|
39
|
+
currentCollateralAmount?: undefined;
|
|
40
|
+
feedPrice?: undefined;
|
|
41
|
+
debtDelta?: undefined;
|
|
42
|
+
collateralDelta?: undefined;
|
|
43
|
+
needsGridReset?: undefined;
|
|
44
|
+
resetReason?: undefined;
|
|
45
|
+
} | {
|
|
46
|
+
action: string;
|
|
47
|
+
fallbackAction: string | null;
|
|
48
|
+
targetCollateralRatio: number;
|
|
49
|
+
currentCollateralRatio: number;
|
|
50
|
+
currentDebtAmount: number | undefined;
|
|
51
|
+
currentCollateralAmount: number | undefined;
|
|
52
|
+
feedPrice: number | undefined;
|
|
53
|
+
debtDelta: number;
|
|
54
|
+
collateralDelta: number;
|
|
55
|
+
needsGridReset: boolean;
|
|
56
|
+
resetReason: string;
|
|
57
|
+
blocked?: undefined;
|
|
58
|
+
reason?: undefined;
|
|
59
|
+
} | null;
|
|
60
|
+
declare function buildCollateralFallbackPlan({ currentCollateralAmount, currentDebtAmount, feedPrice, targetCollateralRatio, maxCollateralAmount, collateralLimitReferenceAmount, }?: CollateralFallbackPlanOptions): {
|
|
61
|
+
action: string;
|
|
62
|
+
targetCollateralRatio: number;
|
|
63
|
+
currentCollateralRatio: number | null;
|
|
64
|
+
currentDebtAmount: number | undefined;
|
|
65
|
+
currentCollateralAmount: number | undefined;
|
|
66
|
+
feedPrice: number | undefined;
|
|
67
|
+
collateralDelta: number;
|
|
68
|
+
needsGridReset: boolean;
|
|
69
|
+
resetReason: string;
|
|
70
|
+
} | null;
|
|
33
71
|
export { buildCollateralFallbackPlan, buildDebtFirstCrPlan, positiveOrNull, resolveMinCollateralIncreaseThreshold, resolveTargetCollateralRatio };
|
|
34
72
|
//# sourceMappingURL=cr_planner.d.ts.map
|
|
@@ -7,17 +7,77 @@
|
|
|
7
7
|
* Default-deny on errors: validation failures, executable timeouts, etc.
|
|
8
8
|
*/
|
|
9
9
|
declare const POLICY_DENIED_PREFIX = "POLICY_DENIED: ";
|
|
10
|
+
interface AmountRef {
|
|
11
|
+
asset_id?: string;
|
|
12
|
+
amount?: number;
|
|
13
|
+
}
|
|
14
|
+
interface OpData {
|
|
15
|
+
to?: unknown;
|
|
16
|
+
amount?: AmountRef;
|
|
17
|
+
amount_to_sell?: AmountRef;
|
|
18
|
+
min_to_receive?: AmountRef;
|
|
19
|
+
delta_amount_to_sell?: AmountRef;
|
|
20
|
+
delta_collateral?: AmountRef;
|
|
21
|
+
delta_debt?: AmountRef;
|
|
22
|
+
new_price?: {
|
|
23
|
+
base?: AmountRef;
|
|
24
|
+
quote?: AmountRef;
|
|
25
|
+
};
|
|
26
|
+
fill_or_kill?: unknown;
|
|
27
|
+
extensions?: {
|
|
28
|
+
target_collateral_ratio?: unknown;
|
|
29
|
+
};
|
|
30
|
+
offer_id?: unknown;
|
|
31
|
+
collateral?: AmountRef;
|
|
32
|
+
borrow_amount?: AmountRef;
|
|
33
|
+
repay_amount?: AmountRef;
|
|
34
|
+
credit_fee?: AmountRef;
|
|
35
|
+
max_fee_rate?: unknown;
|
|
36
|
+
min_duration_seconds?: unknown;
|
|
37
|
+
auto_repay?: unknown;
|
|
38
|
+
pool?: unknown;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
interface PolicyOperation {
|
|
42
|
+
op_name?: string;
|
|
43
|
+
op_data?: OpData;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
10
46
|
interface PolicyContext {
|
|
11
47
|
accountName: string;
|
|
12
48
|
requestType: string;
|
|
13
49
|
sessionId: string | null;
|
|
14
50
|
timestamp: string;
|
|
15
|
-
operations:
|
|
51
|
+
operations: PolicyOperation[];
|
|
52
|
+
}
|
|
53
|
+
interface PolicyLayer {
|
|
54
|
+
sessionTtlMs?: number;
|
|
55
|
+
maxOpsPerBatch?: number;
|
|
56
|
+
allowedAssetIds?: string[] | null;
|
|
57
|
+
executable?: string | null;
|
|
58
|
+
botHmacSecret?: string;
|
|
59
|
+
allowedOps?: Record<string, Record<string, unknown>> | null;
|
|
60
|
+
[key: string]: unknown;
|
|
16
61
|
}
|
|
17
62
|
interface PolicyConfig {
|
|
18
63
|
sessionTtlMs?: number;
|
|
19
|
-
default?:
|
|
20
|
-
accounts?: Record<string,
|
|
64
|
+
default?: PolicyLayer;
|
|
65
|
+
accounts?: Record<string, PolicyLayer>;
|
|
66
|
+
}
|
|
67
|
+
interface MergedPolicy {
|
|
68
|
+
allowedOps: Record<string, Record<string, unknown>>;
|
|
69
|
+
maxOpsPerBatch?: number;
|
|
70
|
+
allowedAssetIds?: string[] | null;
|
|
71
|
+
executable?: string | null;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
interface PolicyRequest {
|
|
75
|
+
accountName: string;
|
|
76
|
+
type: string;
|
|
77
|
+
sessionId?: string | null;
|
|
78
|
+
operations?: PolicyOperation[];
|
|
79
|
+
hmac?: unknown;
|
|
80
|
+
[key: string]: unknown;
|
|
21
81
|
}
|
|
22
82
|
declare const BUILTIN_DEFAULT_POLICY: Readonly<{
|
|
23
83
|
allowedOps: Readonly<{
|
|
@@ -88,20 +148,20 @@ declare function loadRequiredPolicyConfig(filePath: string): PolicyConfig;
|
|
|
88
148
|
/**
|
|
89
149
|
* Validate raw policy config. Returns { valid: boolean, errors: string[] }.
|
|
90
150
|
*/
|
|
91
|
-
declare function validatePolicyConfig(raw:
|
|
151
|
+
declare function validatePolicyConfig(raw: unknown): {
|
|
92
152
|
valid: boolean;
|
|
93
153
|
errors: string[];
|
|
94
154
|
};
|
|
95
|
-
declare function resolveAccountPolicy(config:
|
|
155
|
+
declare function resolveAccountPolicy(config: PolicyConfig | null, accountName: string): MergedPolicy;
|
|
96
156
|
/**
|
|
97
157
|
* Build the PolicyContext passed to evaluatePolicy and to executable hooks.
|
|
98
158
|
*/
|
|
99
|
-
declare function buildPolicyContext(request:
|
|
159
|
+
declare function buildPolicyContext(request: PolicyRequest): PolicyContext;
|
|
100
160
|
/**
|
|
101
161
|
* Evaluate a policy against a context. AND semantics: short-circuit on first denial.
|
|
102
162
|
* Returns Promise<{ allow: boolean, reason: string|null, policyId: string|null }>
|
|
103
163
|
*/
|
|
104
|
-
declare function evaluatePolicy(policy:
|
|
164
|
+
declare function evaluatePolicy(policy: MergedPolicy, context: PolicyContext): Promise<{
|
|
105
165
|
allow: boolean;
|
|
106
166
|
reason: string | null;
|
|
107
167
|
policyId: string | null;
|
|
@@ -136,7 +196,7 @@ declare function loadBotHmacSecret(accountName: string, policyConfigPath: string
|
|
|
136
196
|
* @param {object|null} policyConfig - Loaded daemon-policies.json content
|
|
137
197
|
* @returns {{ valid: boolean, reason: string|null }}
|
|
138
198
|
*/
|
|
139
|
-
declare function verifySourceHmac(request:
|
|
199
|
+
declare function verifySourceHmac(request: PolicyRequest, policyConfig: PolicyConfig | null): {
|
|
140
200
|
valid: boolean;
|
|
141
201
|
reason: string | null;
|
|
142
202
|
};
|
|
@@ -86,7 +86,7 @@ async function resolveAssetRefToId(assetRef) {
|
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
catch
|
|
89
|
+
catch {
|
|
90
90
|
// fall through — native client may not be connected yet
|
|
91
91
|
}
|
|
92
92
|
// Don't cache null from external resolver; the native client may not
|
|
@@ -101,7 +101,7 @@ async function resolveAssetRefToId(assetRef) {
|
|
|
101
101
|
resolvedId = asset?.id ? String(asset.id) : null;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
catch
|
|
104
|
+
catch {
|
|
105
105
|
resolvedId = null;
|
|
106
106
|
}
|
|
107
107
|
if (resolvedId)
|
|
@@ -222,7 +222,7 @@ function ensurePolicyConfig(filePath) {
|
|
|
222
222
|
function loadPolicyConfig(filePath, options = {}) {
|
|
223
223
|
const forceReload = options.forceReload || false;
|
|
224
224
|
if (!forceReload && policyCache.has(filePath)) {
|
|
225
|
-
return policyCache.get(filePath);
|
|
225
|
+
return policyCache.get(filePath) ?? null;
|
|
226
226
|
}
|
|
227
227
|
const detailed = readPolicyConfigDetailed(filePath);
|
|
228
228
|
if (detailed.status !== 'ok') {
|
|
@@ -399,31 +399,32 @@ function validatePolicyConfig(raw) {
|
|
|
399
399
|
errors.push('root must be an object');
|
|
400
400
|
return { valid: false, errors };
|
|
401
401
|
}
|
|
402
|
+
const cfg = raw;
|
|
402
403
|
// sessionTtlMs: optional positive integer
|
|
403
|
-
if (
|
|
404
|
-
if (typeof
|
|
404
|
+
if (cfg.sessionTtlMs !== undefined) {
|
|
405
|
+
if (typeof cfg.sessionTtlMs !== 'number' || cfg.sessionTtlMs <= 0) {
|
|
405
406
|
errors.push('sessionTtlMs must be a positive integer');
|
|
406
407
|
}
|
|
407
408
|
}
|
|
408
409
|
// default: optional policy object
|
|
409
|
-
if (
|
|
410
|
-
if (typeof
|
|
410
|
+
if (cfg.default !== undefined) {
|
|
411
|
+
if (typeof cfg.default !== 'object' || cfg.default === null) {
|
|
411
412
|
errors.push('default must be an object');
|
|
412
413
|
}
|
|
413
414
|
else {
|
|
414
|
-
const { valid: validDefault, errors: defaultErrors } = validatePolicyObject(
|
|
415
|
+
const { valid: validDefault, errors: defaultErrors } = validatePolicyObject(cfg.default);
|
|
415
416
|
if (!validDefault) {
|
|
416
417
|
errors.push(`default: ${defaultErrors.join('; ')}`);
|
|
417
418
|
}
|
|
418
419
|
}
|
|
419
420
|
}
|
|
420
421
|
// accounts: optional object of policies
|
|
421
|
-
if (
|
|
422
|
-
if (typeof
|
|
422
|
+
if (cfg.accounts !== undefined) {
|
|
423
|
+
if (typeof cfg.accounts !== 'object' || Array.isArray(cfg.accounts)) {
|
|
423
424
|
errors.push('accounts must be an object');
|
|
424
425
|
}
|
|
425
426
|
else {
|
|
426
|
-
for (const [accountName, policy] of Object.entries(
|
|
427
|
+
for (const [accountName, policy] of Object.entries(cfg.accounts)) {
|
|
427
428
|
if (typeof policy !== 'object' || policy === null) {
|
|
428
429
|
errors.push(`accounts.${accountName} must be an object`);
|
|
429
430
|
}
|
|
@@ -441,8 +442,9 @@ function validatePolicyConfig(raw) {
|
|
|
441
442
|
/**
|
|
442
443
|
* Validate a single policy object (used by both default and per-account policies).
|
|
443
444
|
*/
|
|
444
|
-
function validatePolicyObject(
|
|
445
|
+
function validatePolicyObject(policyInput) {
|
|
445
446
|
const errors = [];
|
|
447
|
+
const policy = (policyInput && typeof policyInput === 'object' ? policyInput : {});
|
|
446
448
|
// maxOpsPerBatch: must be positive integer
|
|
447
449
|
if (policy.maxOpsPerBatch !== undefined) {
|
|
448
450
|
if (typeof policy.maxOpsPerBatch !== 'number' || policy.maxOpsPerBatch <= 0) {
|
|
@@ -584,10 +586,11 @@ function deriveDebtPolicyConstraints(accountName) {
|
|
|
584
586
|
function mergePolicyLayer(base, layer) {
|
|
585
587
|
if (!layer || typeof layer !== 'object')
|
|
586
588
|
return base;
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
589
|
+
const l = layer;
|
|
590
|
+
const merged = { ...base, ...l, allowedOps: { ...base.allowedOps } };
|
|
591
|
+
if (l.allowedOps && typeof l.allowedOps === 'object') {
|
|
592
|
+
const allowedOps = { ...base.allowedOps };
|
|
593
|
+
for (const [opName, constraints] of Object.entries(l.allowedOps)) {
|
|
591
594
|
if (opName === '__proto__' || opName === 'constructor' || opName === 'prototype')
|
|
592
595
|
continue;
|
|
593
596
|
allowedOps[opName] = { ...(allowedOps[opName] || {}), ...((constraints && typeof constraints === 'object') ? constraints : {}) };
|
|
@@ -650,11 +653,13 @@ function denyNotInList(opName, word, id, listName, list, requirePresent) {
|
|
|
650
653
|
return null;
|
|
651
654
|
}
|
|
652
655
|
function denyBoundExceeded(opName, label, compareValue, shownValue, boundLabel, bound, opts = {}) {
|
|
653
|
-
if (bound == null)
|
|
656
|
+
if (bound == null || compareValue == null)
|
|
654
657
|
return null;
|
|
655
|
-
|
|
658
|
+
const cmp = Number(compareValue);
|
|
659
|
+
const bnd = Number(bound);
|
|
660
|
+
if (!Number.isFinite(cmp) || !Number.isFinite(bnd))
|
|
656
661
|
return null;
|
|
657
|
-
const over = opts.lower ?
|
|
662
|
+
const over = opts.lower ? cmp < bnd : cmp > bnd;
|
|
658
663
|
if (!over)
|
|
659
664
|
return null;
|
|
660
665
|
const verb = opts.verb ?? (opts.lower ? 'below' : 'exceeds');
|
|
@@ -663,7 +668,7 @@ function denyBoundExceeded(opName, label, compareValue, shownValue, boundLabel,
|
|
|
663
668
|
async function denyAssetRefMismatch(opName, word, assetId, refs, refLabel, opts = {}) {
|
|
664
669
|
if (!opts.active)
|
|
665
670
|
return null;
|
|
666
|
-
const resolved = await resolveConfiguredAssetRefs(refs, refLabel);
|
|
671
|
+
const resolved = await resolveConfiguredAssetRefs(Array.isArray(refs) ? refs.map((r) => String(r)) : [], refLabel);
|
|
667
672
|
if (!resolved.ok)
|
|
668
673
|
return asDeny(`${opName}: ${resolved.reason}`);
|
|
669
674
|
if (assetId && resolved.values && !resolved.values.includes(String(assetId))) {
|
|
@@ -722,7 +727,7 @@ async function evaluateOpConstraints(opName, opData, constraints) {
|
|
|
722
727
|
if (receiveDenied)
|
|
723
728
|
return receiveDenied;
|
|
724
729
|
// maxDeltaSellAmount (abs value)
|
|
725
|
-
const maxDeltaSellDenied = denyBoundExceeded('limit_order_update', '|delta|', Math.abs(d.delta_amount_to_sell && d.delta_amount_to_sell.amount), Math.abs(d.delta_amount_to_sell && d.delta_amount_to_sell.amount), 'maxDeltaSellAmount', constraints.maxDeltaSellAmount);
|
|
730
|
+
const maxDeltaSellDenied = denyBoundExceeded('limit_order_update', '|delta|', Math.abs(Number(d.delta_amount_to_sell && d.delta_amount_to_sell.amount)), Math.abs(Number(d.delta_amount_to_sell && d.delta_amount_to_sell.amount)), 'maxDeltaSellAmount', constraints.maxDeltaSellAmount);
|
|
726
731
|
if (maxDeltaSellDenied)
|
|
727
732
|
return maxDeltaSellDenied;
|
|
728
733
|
}
|
|
@@ -741,14 +746,14 @@ async function evaluateOpConstraints(opName, opData, constraints) {
|
|
|
741
746
|
if (allowedCollateralDenied)
|
|
742
747
|
return allowedCollateralDenied;
|
|
743
748
|
// maxDeltaCollateral
|
|
744
|
-
const maxDeltaCollateralDenied = denyBoundExceeded('call_order_update', '|delta_collateral|', Math.abs(d.delta_collateral && d.delta_collateral.amount), Math.abs(d.delta_collateral && d.delta_collateral.amount), 'maxDeltaCollateral', constraints.maxDeltaCollateral);
|
|
749
|
+
const maxDeltaCollateralDenied = denyBoundExceeded('call_order_update', '|delta_collateral|', Math.abs(Number(d.delta_collateral && d.delta_collateral.amount)), Math.abs(Number(d.delta_collateral && d.delta_collateral.amount)), 'maxDeltaCollateral', constraints.maxDeltaCollateral);
|
|
745
750
|
if (maxDeltaCollateralDenied)
|
|
746
751
|
return maxDeltaCollateralDenied;
|
|
747
752
|
// maxDeltaDebt
|
|
748
|
-
const maxDeltaDebtDenied = denyBoundExceeded('call_order_update', '|delta_debt|', Math.abs(d.delta_debt && d.delta_debt.amount), Math.abs(d.delta_debt && d.delta_debt.amount), 'maxDeltaDebt', constraints.maxDeltaDebt);
|
|
753
|
+
const maxDeltaDebtDenied = denyBoundExceeded('call_order_update', '|delta_debt|', Math.abs(Number(d.delta_debt && d.delta_debt.amount)), Math.abs(Number(d.delta_debt && d.delta_debt.amount)), 'maxDeltaDebt', constraints.maxDeltaDebt);
|
|
749
754
|
if (maxDeltaDebtDenied)
|
|
750
755
|
return maxDeltaDebtDenied;
|
|
751
|
-
const targetCollateralRatio = d.extensions && d.extensions.target_collateral_ratio != null ? normalizeGrapheneCollateralRatio(d.extensions.target_collateral_ratio) : NaN;
|
|
756
|
+
const targetCollateralRatio = d.extensions && d.extensions.target_collateral_ratio != null ? normalizeGrapheneCollateralRatio(Number(d.extensions.target_collateral_ratio)) : NaN;
|
|
752
757
|
const minRatioDenied = denyBoundExceeded('call_order_update', 'target_collateral_ratio', targetCollateralRatio, targetCollateralRatio, 'minCollateralRatio', constraints.minCollateralRatio, { lower: true });
|
|
753
758
|
if (minRatioDenied)
|
|
754
759
|
return minRatioDenied;
|
|
@@ -834,8 +839,8 @@ async function evaluatePolicy(policy, context) {
|
|
|
834
839
|
};
|
|
835
840
|
}
|
|
836
841
|
// Get per-op constraints and evaluate
|
|
837
|
-
const constraints = policy.allowedOps[opName];
|
|
838
|
-
const result = await evaluateOpConstraints(opName, op.op_data, constraints);
|
|
842
|
+
const constraints = policy.allowedOps[String(opName)];
|
|
843
|
+
const result = await evaluateOpConstraints(String(opName), op.op_data, constraints);
|
|
839
844
|
if (!result.allow) {
|
|
840
845
|
return result;
|
|
841
846
|
}
|
|
@@ -1013,7 +1018,7 @@ function evaluateExecutable(exePath, context) {
|
|
|
1013
1018
|
}
|
|
1014
1019
|
resolve({
|
|
1015
1020
|
allow: result.allow,
|
|
1016
|
-
reason: result.allow ? null : (result.reason
|
|
1021
|
+
reason: result.allow ? null : (typeof result.reason === 'string' ? result.reason : 'denied by executable'),
|
|
1017
1022
|
});
|
|
1018
1023
|
}
|
|
1019
1024
|
catch (error) {
|
|
@@ -1118,17 +1123,18 @@ function loadBotHmacSecret(accountName, policyConfigPath, options = {}) {
|
|
|
1118
1123
|
}
|
|
1119
1124
|
}
|
|
1120
1125
|
catch (e) {
|
|
1121
|
-
|
|
1126
|
+
const err = e;
|
|
1127
|
+
if (err && err.code === 'ENOENT') {
|
|
1122
1128
|
info(`[policy] Ready file not present; daemon not running, SIGHUP skipped`);
|
|
1123
1129
|
}
|
|
1124
1130
|
else if (e instanceof SyntaxError) {
|
|
1125
1131
|
warn(`[policy] Ready file is malformed JSON (${getErrorMessage(e)}); SIGHUP skipped, fs.watch will pick up the change`);
|
|
1126
1132
|
}
|
|
1127
|
-
else if (
|
|
1128
|
-
warn(`[policy] SIGHUP to daemon failed (${
|
|
1133
|
+
else if (err && (err.code === 'ESRCH' || err.code === 'EPERM')) {
|
|
1134
|
+
warn(`[policy] SIGHUP to daemon failed (${err.code}: ${getErrorMessage(e)}); fs.watch will pick up the change`);
|
|
1129
1135
|
}
|
|
1130
1136
|
else {
|
|
1131
|
-
warn(`[policy] Unexpected error signalling daemon (${
|
|
1137
|
+
warn(`[policy] Unexpected error signalling daemon (${getErrorMessage(e)}); fs.watch will pick up the change`);
|
|
1132
1138
|
}
|
|
1133
1139
|
}
|
|
1134
1140
|
secret = newSecret;
|
|
@@ -11,7 +11,7 @@ interface BuildSessionCacheOptions {
|
|
|
11
11
|
}
|
|
12
12
|
interface LoadDaemonKeyOptions {
|
|
13
13
|
chainKeys?: typeof chainKeys;
|
|
14
|
-
chainClient?:
|
|
14
|
+
chainClient?: unknown;
|
|
15
15
|
}
|
|
16
16
|
interface SessionState {
|
|
17
17
|
vaultSecret?: string;
|
|
@@ -27,6 +27,6 @@ declare function buildSessionAccountCache(accountsData: AccountsData, masterSecr
|
|
|
27
27
|
vaultKeyHex: string;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
declare function loadDaemonPrivateKey(accountName: string, sessionState: SessionState, options?: LoadDaemonKeyOptions): Promise<
|
|
30
|
+
declare function loadDaemonPrivateKey(accountName: string, sessionState: SessionState, options?: LoadDaemonKeyOptions): Promise<string>;
|
|
31
31
|
export { buildSessionAccountCache, loadDaemonPrivateKey };
|
|
32
32
|
//# sourceMappingURL=credential_session_cache.d.ts.map
|
|
@@ -1,9 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/credit_pricing.ts — Canonical credit-pricing math (single source of truth).
|
|
3
|
+
*
|
|
4
|
+
* Pure functions only: no imports, no I/O, browser-safe. Both the live
|
|
5
|
+
* credit runtime (modules/credit_runtime.ts) and the offline analyzer
|
|
6
|
+
* (scripts/analyze-credit.ts) delegate to these helpers so offer-price
|
|
7
|
+
* orientation, conversion rates, and collateral-ratio math cannot drift
|
|
8
|
+
* apart between surfaces.
|
|
9
|
+
*
|
|
10
|
+
* Conventions (mirror the chain's credit_offer_object price layout):
|
|
11
|
+
* - A 'core' price has base == debt asset / quote == collateral asset and
|
|
12
|
+
* the conversion rate (debt per 1 collateral) is base / quote.
|
|
13
|
+
* - A 'legacy-reversed' price has base == collateral / quote == debt and
|
|
14
|
+
* the rate is quote / base. Unknown layouts default to 'core'.
|
|
15
|
+
* - Credit CR = collateralValueInDebt / debtAmount, where
|
|
16
|
+
* collateralValueInDebt = collateralAmount * conversionRate.
|
|
17
|
+
*/
|
|
18
|
+
interface PriceLeg {
|
|
19
|
+
amount?: unknown;
|
|
20
|
+
asset_id?: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface OfferPrice {
|
|
23
|
+
base?: PriceLeg;
|
|
24
|
+
quote?: PriceLeg;
|
|
25
|
+
}
|
|
1
26
|
/**
|
|
2
27
|
* Tolerantly normalize an offer's acceptable_collateral map, which arrives
|
|
3
28
|
* in different shapes depending on the API path (Map, [[id, price]] pairs,
|
|
4
29
|
* [{key, value}] entries, or a plain {assetId: price} object).
|
|
5
30
|
*/
|
|
6
|
-
declare function normalizeCollateralMap(raw: unknown): Map<string,
|
|
31
|
+
declare function normalizeCollateralMap(raw: unknown): Map<string, OfferPrice>;
|
|
7
32
|
declare function creditPriceOrientation(baseAssetId: string, quoteAssetId: string, debtAssetId: string, collateralAssetId: string): 'core' | 'legacy-reversed';
|
|
8
33
|
/**
|
|
9
34
|
* Extract the conversion rate (debt asset per 1 collateral unit) for a
|
|
@@ -20,17 +45,25 @@ declare function extractOfferConversionRate(offerCollateral: unknown, collateral
|
|
|
20
45
|
* Value collateral (raw int) in debt-asset units via an offer price.
|
|
21
46
|
* Pure offer-math leg of the runtime's pool-aware valuation.
|
|
22
47
|
*/
|
|
23
|
-
declare function collateralValueFromOfferPrice(collateralAmountInt: unknown, collateralPrecision: unknown, collateralPriceOrMap:
|
|
48
|
+
declare function collateralValueFromOfferPrice(collateralAmountInt: unknown, collateralPrecision: unknown, collateralPriceOrMap: unknown, debtAssetId: string, collateralAssetId: string, precisionOf: (assetId: string) => number | null): number | null;
|
|
24
49
|
/**
|
|
25
50
|
* Minimum raw collateral required to borrow a raw debt amount at a price.
|
|
26
51
|
* Integer ceil so the borrow is never under-collateralized by rounding.
|
|
27
52
|
*/
|
|
28
|
-
declare function requiredCollateralForBorrow(borrowAmountInt: unknown, collateralPrice:
|
|
53
|
+
declare function requiredCollateralForBorrow(borrowAmountInt: unknown, collateralPrice: OfferPrice | null | undefined, debtAssetId?: string | null, collateralAssetId?: string | null): number | null;
|
|
29
54
|
/**
|
|
30
55
|
* Raw debt yielded by raw collateral at a price. Integer floor so the
|
|
31
56
|
* borrow never exceeds what the collateral covers.
|
|
32
57
|
*/
|
|
33
|
-
declare function borrowAmountForCollateral(collateralAmountInt: unknown, collateralPrice:
|
|
58
|
+
declare function borrowAmountForCollateral(collateralAmountInt: unknown, collateralPrice: OfferPrice | null | undefined, debtAssetId?: string | null, collateralAssetId?: string | null): number | null;
|
|
59
|
+
/**
|
|
60
|
+
* Raw debt yielded by a raw collateral budget, never exceeding the requested
|
|
61
|
+
* raw debt. Returns `requestedBorrowInt` when no budget is supplied or the
|
|
62
|
+
* budget already covers it; `null` when a supplied budget cannot support any
|
|
63
|
+
* borrow at the offer price (caller should back off rather than emit a doomed
|
|
64
|
+
* accept op).
|
|
65
|
+
*/
|
|
66
|
+
declare function capBorrowToCollateral(requestedBorrowInt: unknown, availableCollateralInt: unknown, collateralPrice: OfferPrice | null | undefined, debtAssetId?: string | null, collateralAssetId?: string | null): number | null;
|
|
34
67
|
/**
|
|
35
68
|
* Per-deal CR from floats plus a conversion rate:
|
|
36
69
|
* (collateralFloat * rate) / debtFloat.
|
|
@@ -51,11 +84,14 @@ declare function averageCollateralRatio(entries: Array<{
|
|
|
51
84
|
* Returns 0 for missing/non-positive inputs (matches runtime gating, where
|
|
52
85
|
* a zero daily rate never exceeds maxFeeRatePerDay).
|
|
53
86
|
*/
|
|
54
|
-
declare function dailyOfferFeeRate(offer:
|
|
87
|
+
declare function dailyOfferFeeRate(offer: {
|
|
88
|
+
fee_rate?: unknown;
|
|
89
|
+
max_duration_seconds?: unknown;
|
|
90
|
+
} | null | undefined, feeDenom: unknown): number;
|
|
55
91
|
/**
|
|
56
92
|
* Credit-deal repay fee in raw debt units, rounded up (Graphene ceil):
|
|
57
93
|
* (repay * feeRate + denom - 1) / denom. Zero when nothing is owed.
|
|
58
94
|
*/
|
|
59
95
|
declare function creditDealFee(repayAmountInt: unknown, feeRate: unknown, feeDenom: unknown): number;
|
|
60
|
-
export { normalizeCollateralMap, creditPriceOrientation, extractOfferConversionRate, collateralValueFromOfferPrice, requiredCollateralForBorrow, borrowAmountForCollateral, creditDealCollateralRatio, averageCollateralRatio, dailyOfferFeeRate, creditDealFee, };
|
|
96
|
+
export { normalizeCollateralMap, creditPriceOrientation, extractOfferConversionRate, collateralValueFromOfferPrice, requiredCollateralForBorrow, borrowAmountForCollateral, capBorrowToCollateral, creditDealCollateralRatio, averageCollateralRatio, dailyOfferFeeRate, creditDealFee, };
|
|
61
97
|
//# sourceMappingURL=credit_pricing.d.ts.map
|