dexbot 1.4.11 → 1.4.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/README.md +4 -4
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +9 -18
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +6 -16
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +31 -38
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +7 -10
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +10 -14
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +10 -15
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -10
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +4 -12
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts +0 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +3 -123
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts +0 -87
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +11 -14
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -9
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.js +1 -7
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +1 -4
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +5 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +8 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +7 -13
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +6 -12
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +92 -102
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +5 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +21 -24
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +3 -5
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +4 -6
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +15 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +23 -23
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +24 -82
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +59 -98
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +11 -17
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.js +1 -2
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.js +1 -7
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +20 -22
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +41 -57
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +30 -34
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +2 -2
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +157 -221
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -18
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.js +3 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +7 -16
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +3 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +9 -17
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +8 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +11 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +14 -19
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.js +8 -14
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.js +3 -6
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -1
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +90 -97
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +0 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +26 -121
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.js +12 -18
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +16 -21
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +12 -72
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -40
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -6
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +8 -8
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +11 -68
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +3 -6
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +9 -11
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +3 -28
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +4 -4
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +5 -46
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +98 -98
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +372 -473
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +3 -8
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +9 -74
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +11 -48
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +24 -27
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +14 -26
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +29 -72
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +12 -21
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +21 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +32 -86
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +30 -49
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +5 -13
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/broadcast_failure.js +1 -3
- package/dist/modules/broadcast_failure.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +4 -9
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +77 -182
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +2 -2
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +81 -144
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +23 -28
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +2 -9
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +38 -73
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.js +15 -26
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +3 -6
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +62 -153
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +1 -1
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +34 -41
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +1 -1
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +5 -42
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +126 -162
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.d.ts +1 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -1
- package/dist/modules/crypto/browser_provider.js +7 -11
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts +6 -6
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +12 -30
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/node_provider.d.ts +1 -1
- package/dist/modules/crypto/node_provider.d.ts.map +1 -1
- package/dist/modules/crypto/node_provider.js +3 -5
- package/dist/modules/crypto/node_provider.js.map +1 -1
- package/dist/modules/crypto/provider.js +1 -2
- package/dist/modules/crypto/pure_ripemd160.js +1 -3
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -1
- package/dist/modules/crypto/pure_scrypt.js +1 -4
- package/dist/modules/crypto/pure_scrypt.js.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.js +1 -16
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
- package/dist/modules/crypto/sync.d.ts.map +1 -1
- package/dist/modules/crypto/sync.js +16 -17
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/daemon_node_health.js +14 -16
- package/dist/modules/daemon_node_health.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +19 -14
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +127 -164
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +28 -27
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +55 -45
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_credential_client.d.ts +6 -2
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +21 -31
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +23 -23
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +119 -77
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -38
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +81 -81
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +3 -3
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +43 -81
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +11 -11
- package/dist/modules/dexbot_state_recovery.js +32 -78
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/env.js +3 -7
- package/dist/modules/env.js.map +1 -1
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +12 -24
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.js +10 -16
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +12 -19
- package/dist/modules/graceful_shutdown.js.map +1 -1
- package/dist/modules/key_store.d.ts.map +1 -1
- package/dist/modules/key_store.js +27 -65
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +89 -118
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.js +1 -5
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +22 -31
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +37 -75
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.js +2 -37
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -31
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.js +10 -12
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.js +3 -9
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +25 -35
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -45
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +67 -138
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +1 -11
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +12 -15
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +15 -36
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +4 -9
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +1 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +3 -38
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +9 -18
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_failure_ledger.js +1 -3
- package/dist/modules/node_failure_ledger.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +15 -25
- package/dist/modules/node_health_cache.js.map +1 -1
- package/dist/modules/node_manager.d.ts +1 -1
- package/dist/modules/node_manager.d.ts.map +1 -1
- package/dist/modules/node_manager.js +44 -43
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +102 -118
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +3 -15
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +6 -26
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.js +34 -75
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +1 -3
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +4 -24
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +3 -3
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +206 -262
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +77 -94
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +117 -149
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +11 -45
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.js +28 -69
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -4
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +10 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +131 -151
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.js +2 -7
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.js +23 -25
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +27 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +232 -181
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +1 -25
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +49 -172
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +46 -2
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +165 -143
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +3 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +152 -211
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/timeout.js +1 -4
- package/dist/modules/order/utils/timeout.js.map +1 -1
- package/dist/modules/order/utils/validate.js +91 -142
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/utils/withPoolRef.js +21 -61
- package/dist/modules/order/utils/withPoolRef.js.map +1 -1
- package/dist/modules/order/working_grid.js +6 -9
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.d.ts.map +1 -1
- package/dist/modules/path_api.js +8 -11
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +61 -67
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.js +13 -21
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.js +7 -11
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +14 -16
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.js +1 -3
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/socket_json_client.js +3 -5
- package/dist/modules/socket_json_client.js.map +1 -1
- package/dist/modules/storage/browser_adapter.js +1 -4
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +3 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +5 -8
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -4
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +12 -16
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.js +1 -2
- package/dist/modules/types.d.ts +0 -6
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/types.js +1 -2
- package/dist/modules/types.js.map +1 -1
- package/dist/modules/utils/base58check.js +8 -15
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.js +3 -7
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.js +1 -5
- package/dist/modules/utils/errors.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +1 -1
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +2 -7
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +18 -25
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +4 -70
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +106 -132
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.js +13 -17
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +48 -63
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.js +2 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +2 -1
- package/dist/scripts/diagnose-pool-history.js.map +1 -1
- package/dist/scripts/divergence-calc.d.ts.map +1 -1
- package/dist/scripts/divergence-calc.js +2 -2
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.js +17 -22
- package/dist/scripts/fix-err-message.js.map +1 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +7 -15
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +3 -2
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +18 -24
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/native_release_gates.js +15 -19
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.d.ts.map +1 -1
- package/dist/scripts/print_grid.js +2 -2
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +12 -17
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +18 -20
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/sync-version.js +2 -2
- package/dist/scripts/sync-version.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +4 -3
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.js +77 -89
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/validate_bots.d.ts.map +1 -1
- package/dist/scripts/validate_bots.js +2 -2
- package/dist/scripts/validate_bots.js.map +1 -1
- package/dist/scripts/verify-browser-bundle.js +12 -17
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +0 -30
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +95 -143
- package/dist/unlock.js.map +1 -1
- package/package.json +5 -8
- package/scripts/README.md +1 -1
- package/scripts/create-bot-symlinks.sh +2 -2
- package/dist/modules/utils/fs_utils.d.ts +0 -18
- package/dist/modules/utils/fs_utils.d.ts.map +0 -1
- package/dist/modules/utils/fs_utils.js +0 -32
- package/dist/modules/utils/fs_utils.js.map +0 -1
- package/dist/scripts/migrate_bot_keys.d.ts +0 -3
- package/dist/scripts/migrate_bot_keys.d.ts.map +0 -1
- package/dist/scripts/migrate_bot_keys.js +0 -225
- package/dist/scripts/migrate_bot_keys.js.map +0 -1
|
@@ -1,67 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const path_api_1 = require("./path_api");
|
|
37
|
-
const storage_1 = require("./storage");
|
|
38
|
-
const client = __importStar(require("./bitshares_client"));
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { path } from './path_api.js';
|
|
4
|
+
import { getStorage } from './storage/index.js';
|
|
5
|
+
import * as client from './bitshares_client.js';
|
|
39
6
|
const { BitShares, waitForConnected } = client;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const _sysUtils = require("./order/utils/system");
|
|
51
|
-
const { deriveLiquidityPoolTokenValue, ensureDir: ensureDirSync } = _sysUtils;
|
|
7
|
+
import * as chainOrders from './chain_orders.js';
|
|
8
|
+
import { blockchainToFloat, floatToBlockchainInt, resolveConfigValue } from './order/utils/math.js';
|
|
9
|
+
import { toFiniteNumber } from './order/format.js';
|
|
10
|
+
import { createBotKey } from './account_orders.js';
|
|
11
|
+
import * as fundRegistry from './fund_registry.js';
|
|
12
|
+
import { writeJsonFileAtomic } from './bots_file_lock.js';
|
|
13
|
+
import { FEE_PARAMETERS, DEFAULT_TARGET_CR, TIMING, NATIVE_CLIENT } from './constants.js';
|
|
14
|
+
import { roundToDecimals } from './order/utils/math.js';
|
|
15
|
+
import { PATHS } from './paths.js';
|
|
16
|
+
import { deriveLiquidityPoolTokenValue, ensureDir as ensureDirSync, } from './order/utils/system.js';
|
|
52
17
|
'use strict';
|
|
53
|
-
const storage =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const CREDIT_FEE_RATE_DENOM =
|
|
57
|
-
const ZERO_ASSET_ID =
|
|
58
|
-
const DEFAULT_STATE_DIR =
|
|
59
|
-
const GRAPHENE_COLLATERAL_RATIO_DENOM =
|
|
18
|
+
const storage = getStorage();
|
|
19
|
+
import { buildCollateralFallbackPlan, buildDebtFirstCrPlan, resolveMinCollateralIncreaseThreshold, resolveTargetCollateralRatio, } from './cr_planner.js';
|
|
20
|
+
import { getErrorMessage } from './utils/errors.js';
|
|
21
|
+
const CREDIT_FEE_RATE_DENOM = FEE_PARAMETERS.GRAPHENE_FEE_RATE_DENOM;
|
|
22
|
+
const ZERO_ASSET_ID = NATIVE_CLIENT.CHAIN.CORE_ASSET_ID;
|
|
23
|
+
const DEFAULT_STATE_DIR = PATHS.CREDIT_RUNTIME_DIR;
|
|
24
|
+
const GRAPHENE_COLLATERAL_RATIO_DENOM = FEE_PARAMETERS.GRAPHENE_COLLATERAL_RATIO_DENOM;
|
|
60
25
|
function deepClone(value) {
|
|
61
26
|
return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
62
27
|
}
|
|
63
28
|
function positiveOrNull(value) {
|
|
64
|
-
const num =
|
|
29
|
+
const num = toFiniteNumber(value, undefined);
|
|
65
30
|
return Number.isFinite(num) && num > 0 ? num : null;
|
|
66
31
|
}
|
|
67
32
|
function normalizeResolvedPriceResult(value, liveSource, missingSource) {
|
|
@@ -128,9 +93,9 @@ function toAmountObject(amount, assetId) {
|
|
|
128
93
|
}
|
|
129
94
|
function getChainAmountValue(value) {
|
|
130
95
|
if (value && typeof value === 'object' && value.amount !== undefined) {
|
|
131
|
-
return
|
|
96
|
+
return toFiniteNumber(value.amount, undefined);
|
|
132
97
|
}
|
|
133
|
-
return
|
|
98
|
+
return toFiniteNumber(value, undefined);
|
|
134
99
|
}
|
|
135
100
|
function getAssetPrecision(asset) {
|
|
136
101
|
const precision = Number(asset?.precision);
|
|
@@ -142,10 +107,10 @@ function blockchainAmountToFloat(value, asset) {
|
|
|
142
107
|
if (!Number.isFinite(amount) || precision === null) {
|
|
143
108
|
return null;
|
|
144
109
|
}
|
|
145
|
-
return
|
|
110
|
+
return blockchainToFloat(amount, precision);
|
|
146
111
|
}
|
|
147
112
|
function isDeterministicMpaDebtBalanceError(err, plan) {
|
|
148
|
-
const debtDelta =
|
|
113
|
+
const debtDelta = toFiniteNumber(plan?.debtDelta, 0);
|
|
149
114
|
if (!Number.isFinite(debtDelta) || debtDelta >= 0) {
|
|
150
115
|
return false;
|
|
151
116
|
}
|
|
@@ -243,12 +208,12 @@ function parseDealSummary(deal) {
|
|
|
243
208
|
offerId: deal.offerId || deal.offer_id || null,
|
|
244
209
|
offerOwner: deal.offerOwner || deal.offer_owner || null,
|
|
245
210
|
debtAssetId: deal.debtAssetId || deal.debt_asset || null,
|
|
246
|
-
debtAmount:
|
|
211
|
+
debtAmount: toFiniteNumber(deal.debtAmount ?? deal.debt_amount, 0) || 0,
|
|
247
212
|
collateralAssetId: deal.collateralAssetId || deal.collateral_asset || null,
|
|
248
|
-
collateralAmount:
|
|
249
|
-
feeRate:
|
|
213
|
+
collateralAmount: toFiniteNumber(deal.collateralAmount ?? deal.collateral_amount, 0) || 0,
|
|
214
|
+
feeRate: toFiniteNumber(deal.feeRate ?? deal.fee_rate, 0) || 0,
|
|
250
215
|
latestRepayTime: deal.latestRepayTime || deal.latest_repay_time || null,
|
|
251
|
-
autoRepay:
|
|
216
|
+
autoRepay: toFiniteNumber(deal.autoRepay ?? deal.auto_repay, 0) || 0,
|
|
252
217
|
};
|
|
253
218
|
}
|
|
254
219
|
function parseCallOrderSummary(order) {
|
|
@@ -258,9 +223,9 @@ function parseCallOrderSummary(order) {
|
|
|
258
223
|
id: order.id || null,
|
|
259
224
|
borrower: order.borrower || null,
|
|
260
225
|
debtAssetId: order.debtAssetId || order.call_price?.quote?.asset_id || null,
|
|
261
|
-
debtAmount:
|
|
226
|
+
debtAmount: toFiniteNumber(order.debt?.amount ?? order.debtAmount, 0) || 0,
|
|
262
227
|
collateralAssetId: order.collateralAssetId || order.call_price?.base?.asset_id || null,
|
|
263
|
-
collateralAmount:
|
|
228
|
+
collateralAmount: toFiniteNumber(order.collateral?.amount ?? order.collateralAmount, 0) || 0,
|
|
264
229
|
debt: order.debt || null,
|
|
265
230
|
collateral: order.collateral || null,
|
|
266
231
|
call_price: order.call_price || null,
|
|
@@ -273,11 +238,11 @@ function parseCreditOfferSummary(offer) {
|
|
|
273
238
|
id: offer.id || null,
|
|
274
239
|
ownerAccount: offer.owner_account || offer.ownerAccount || null,
|
|
275
240
|
assetType: offer.asset_type || offer.assetType || null,
|
|
276
|
-
totalBalance:
|
|
277
|
-
currentBalance:
|
|
278
|
-
feeRate:
|
|
279
|
-
maxDurationSeconds:
|
|
280
|
-
minDealAmount:
|
|
241
|
+
totalBalance: toFiniteNumber(offer.total_balance ?? offer.totalBalance, 0) || 0,
|
|
242
|
+
currentBalance: toFiniteNumber(offer.current_balance ?? offer.currentBalance, 0) || 0,
|
|
243
|
+
feeRate: toFiniteNumber(offer.fee_rate ?? offer.feeRate, 0) || 0,
|
|
244
|
+
maxDurationSeconds: toFiniteNumber(offer.max_duration_seconds ?? offer.maxDurationSeconds, 0) || 0,
|
|
245
|
+
minDealAmount: toFiniteNumber(offer.min_deal_amount ?? offer.minDealAmount, 0) || 0,
|
|
281
246
|
enabled: !!offer.enabled,
|
|
282
247
|
acceptableCollateral: offer.acceptable_collateral || offer.acceptableCollateral || null,
|
|
283
248
|
};
|
|
@@ -308,9 +273,9 @@ class CreditRuntime {
|
|
|
308
273
|
this.log = typeof this.bot._log === 'function' ? this.bot._log.bind(this.bot) : console.log.bind(console);
|
|
309
274
|
this.warn = typeof this.bot._warn === 'function' ? this.bot._warn.bind(this.bot) : console.warn.bind(console);
|
|
310
275
|
this.botKey = this.config.botKey
|
|
311
|
-
||
|
|
276
|
+
|| createBotKey(this.config, this.config.botIndex ?? 0);
|
|
312
277
|
this.stateDir = this.options.stateDir || DEFAULT_STATE_DIR;
|
|
313
|
-
this.statePath =
|
|
278
|
+
this.statePath = path.join(this.stateDir, `${this.botKey}.json`);
|
|
314
279
|
this._assetCache = new Map();
|
|
315
280
|
this._objectCache = new Map();
|
|
316
281
|
this._fullAccountCache = null;
|
|
@@ -403,11 +368,11 @@ class CreditRuntime {
|
|
|
403
368
|
return this.state;
|
|
404
369
|
}
|
|
405
370
|
try {
|
|
406
|
-
const parsed =
|
|
371
|
+
const parsed = storage.readJSON(this.statePath);
|
|
407
372
|
this.state = this._stateWithDefaults(parsed);
|
|
408
373
|
}
|
|
409
374
|
catch (err) {
|
|
410
|
-
this.warn(`credit runtime: failed to load ${this.statePath}: ${
|
|
375
|
+
this.warn(`credit runtime: failed to load ${this.statePath}: ${getErrorMessage(err)}`);
|
|
411
376
|
this.state = this._stateWithDefaults();
|
|
412
377
|
}
|
|
413
378
|
this._loaded = true;
|
|
@@ -421,7 +386,7 @@ class CreditRuntime {
|
|
|
421
386
|
// Atomic write: see writeJsonFileAtomic in bots_file_lock.ts. A plain
|
|
422
387
|
// writeFileSync here could leave a truncated state file on crash and
|
|
423
388
|
// cause the next process startup to lose all credit/MPA tracking.
|
|
424
|
-
|
|
389
|
+
writeJsonFileAtomic(this.statePath, this.state);
|
|
425
390
|
if (reason) {
|
|
426
391
|
this.log(`credit runtime: persisted ${this.botKey} state (${reason})`);
|
|
427
392
|
}
|
|
@@ -597,7 +562,7 @@ class CreditRuntime {
|
|
|
597
562
|
}
|
|
598
563
|
const balances = await chainOrders.getOnChainAssetBalances(accountRef, [asset.id]);
|
|
599
564
|
const balance = balances?.[String(asset.id)] || balances?.[String(asset.symbol)] || null;
|
|
600
|
-
total =
|
|
565
|
+
total = toFiniteNumber(balance?.[balanceField], undefined);
|
|
601
566
|
if (!Number.isFinite(total) || total < 0) {
|
|
602
567
|
throw new Error(`Unable to resolve ${referenceLabel} for ${asset.id}`);
|
|
603
568
|
}
|
|
@@ -606,14 +571,14 @@ class CreditRuntime {
|
|
|
606
571
|
throw new Error(`Unable to resolve account for percentage amount on ${asset.id}`);
|
|
607
572
|
}
|
|
608
573
|
}
|
|
609
|
-
const resolved =
|
|
574
|
+
const resolved = resolveConfigValue(normalized.amount, total);
|
|
610
575
|
if (!Number.isFinite(resolved) || resolved <= 0) {
|
|
611
576
|
return null;
|
|
612
577
|
}
|
|
613
578
|
if (isPercent && total !== null && resolved > total) {
|
|
614
579
|
throw new Error(`Requested amount ${resolved} exceeds available ${balanceField} balance ${total} for ${asset.id}`);
|
|
615
580
|
}
|
|
616
|
-
const intValue =
|
|
581
|
+
const intValue = floatToBlockchainInt(resolved, asset.precision);
|
|
617
582
|
if (!Number.isFinite(intValue) || intValue <= 0) {
|
|
618
583
|
return null;
|
|
619
584
|
}
|
|
@@ -706,7 +671,7 @@ class CreditRuntime {
|
|
|
706
671
|
const debtAssetForPool = await this._resolveAsset(debtAssetId);
|
|
707
672
|
if (collateralAssetForPool?.for_liquidity_pool && debtAssetForPool?.id) {
|
|
708
673
|
const poolRate = await deriveLiquidityPoolTokenValue(BitShares, collateralAssetForPool.id, debtAssetForPool.id).catch((e) => {
|
|
709
|
-
this.log(`credit runtime: pool token rate derivation failed for ${collateralAssetForPool.id}/${debtAssetForPool.id}: ${
|
|
674
|
+
this.log(`credit runtime: pool token rate derivation failed for ${collateralAssetForPool.id}/${debtAssetForPool.id}: ${getErrorMessage(e)}`);
|
|
710
675
|
return null;
|
|
711
676
|
});
|
|
712
677
|
if (poolRate != null && Number.isFinite(poolRate) && poolRate > 0) {
|
|
@@ -823,17 +788,17 @@ class CreditRuntime {
|
|
|
823
788
|
if (!collateralAsset)
|
|
824
789
|
continue;
|
|
825
790
|
const totalCollateralAvailable = await this._getCollateralPercentageBase(accountRef, collateralAsset.id);
|
|
826
|
-
const totalMaxCollateral =
|
|
791
|
+
const totalMaxCollateral = resolveConfigValue(dp.maxCollateralAmount ?? '100%', totalCollateralAvailable);
|
|
827
792
|
const C_total = Math.min(totalCollateralAvailable, totalMaxCollateral);
|
|
828
793
|
let groupHasNoUsablePrice = false;
|
|
829
794
|
const weightEntries = await Promise.all(items.map(async (item) => {
|
|
830
|
-
const ratio = item.outputWeight ??
|
|
795
|
+
const ratio = item.outputWeight ?? 1;
|
|
831
796
|
const resolvedAsset = await this._resolveAsset(item.asset);
|
|
832
797
|
const assetId = resolvedAsset?.id ? String(resolvedAsset.id) : null;
|
|
833
798
|
let targetCr = 1.0;
|
|
834
799
|
let weight = 0;
|
|
835
800
|
if (item.type === 'mpa') {
|
|
836
|
-
targetCr =
|
|
801
|
+
targetCr = resolveTargetCollateralRatio(item) ?? DEFAULT_TARGET_CR;
|
|
837
802
|
const resolvedFeedPrice = assetId
|
|
838
803
|
? normalizeResolvedPriceResult(await this._resolveMpaFeedPrice(assetId, collateralAsset.id, { includeSource: true }), 'live-feed', 'missing-feed')
|
|
839
804
|
: { price: null, source: 'missing-feed' };
|
|
@@ -851,7 +816,7 @@ class CreditRuntime {
|
|
|
851
816
|
}
|
|
852
817
|
}
|
|
853
818
|
else if (item.type === 'creditOffer') {
|
|
854
|
-
targetCr =
|
|
819
|
+
targetCr = toFiniteNumber(item.maxCollateralRatio, 2.0);
|
|
855
820
|
const resolvedConversionRate = assetId
|
|
856
821
|
? normalizeResolvedPriceResult(await this._resolveCreditConversionRate(item, assetId, collateralAsset.id, { includeSource: true }), 'live-offer', 'missing-offer')
|
|
857
822
|
: { price: null, source: 'missing-offer' };
|
|
@@ -933,8 +898,8 @@ class CreditRuntime {
|
|
|
933
898
|
return rate;
|
|
934
899
|
}
|
|
935
900
|
_calculateBorrowAmountFromCollateral(collateralAmountInt, collateralPrice, debtAsset = null, collateralAsset = null) {
|
|
936
|
-
const baseAmount =
|
|
937
|
-
const quoteAmount =
|
|
901
|
+
const baseAmount = toFiniteNumber(collateralPrice?.base?.amount, undefined);
|
|
902
|
+
const quoteAmount = toFiniteNumber(collateralPrice?.quote?.amount, undefined);
|
|
938
903
|
if (!Number.isFinite(baseAmount) || !Number.isFinite(quoteAmount) || baseAmount <= 0 || quoteAmount <= 0) {
|
|
939
904
|
return null;
|
|
940
905
|
}
|
|
@@ -947,7 +912,7 @@ class CreditRuntime {
|
|
|
947
912
|
const maxBorrowAmountValue = positiveOrNull(policy?.maxBorrowAmount);
|
|
948
913
|
if (maxBorrowAmountValue === null)
|
|
949
914
|
return;
|
|
950
|
-
const borrowFloat =
|
|
915
|
+
const borrowFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
951
916
|
if (!Number.isFinite(borrowFloat))
|
|
952
917
|
return;
|
|
953
918
|
const currentTotal = this._getCreditDebtForAsset(debtAsset);
|
|
@@ -988,7 +953,7 @@ class CreditRuntime {
|
|
|
988
953
|
this._fetchBorrowerDeals().catch(() => []),
|
|
989
954
|
]);
|
|
990
955
|
const balance = balances?.[String(assetId)] || balances?.[String(asset.symbol)] || null;
|
|
991
|
-
const onChainTotal =
|
|
956
|
+
const onChainTotal = toFiniteNumber(balance?.total, undefined);
|
|
992
957
|
if (!Number.isFinite(onChainTotal)) {
|
|
993
958
|
return null;
|
|
994
959
|
}
|
|
@@ -1029,11 +994,11 @@ class CreditRuntime {
|
|
|
1029
994
|
if (!Number.isFinite(referenceAmount)) {
|
|
1030
995
|
throw new Error(`Unable to resolve collateral percentage base for ${collateralAsset.id}`);
|
|
1031
996
|
}
|
|
1032
|
-
limitFloat =
|
|
997
|
+
limitFloat = resolveConfigValue(maxCollateralAmountValue, referenceAmount);
|
|
1033
998
|
}
|
|
1034
999
|
if (!Number.isFinite(limitFloat) || limitFloat < 0)
|
|
1035
1000
|
return;
|
|
1036
|
-
const collateralFloat =
|
|
1001
|
+
const collateralFloat = blockchainToFloat(collateralInt, collateralAsset.precision);
|
|
1037
1002
|
if (!Number.isFinite(collateralFloat))
|
|
1038
1003
|
return;
|
|
1039
1004
|
const currentTotal = this._getCreditCollateralForAsset(collateralAsset);
|
|
@@ -1043,17 +1008,17 @@ class CreditRuntime {
|
|
|
1043
1008
|
}
|
|
1044
1009
|
}
|
|
1045
1010
|
_calculateDailyFeeRate(offer) {
|
|
1046
|
-
const feeRate =
|
|
1047
|
-
const maxDurationSeconds =
|
|
1011
|
+
const feeRate = toFiniteNumber(offer?.fee_rate, 0) || 0;
|
|
1012
|
+
const maxDurationSeconds = toFiniteNumber(offer?.max_duration_seconds, 0) || 0;
|
|
1048
1013
|
if (feeRate <= 0 || maxDurationSeconds <= 0)
|
|
1049
1014
|
return 0;
|
|
1050
|
-
const feeRateDenom = this.bot?.config?.feeParams?.GRAPHENE_FEE_RATE_DENOM ??
|
|
1015
|
+
const feeRateDenom = this.bot?.config?.feeParams?.GRAPHENE_FEE_RATE_DENOM ?? FEE_PARAMETERS.GRAPHENE_FEE_RATE_DENOM;
|
|
1051
1016
|
const flatFeePercent = feeRate / feeRateDenom;
|
|
1052
1017
|
const durationDays = maxDurationSeconds / 86400;
|
|
1053
1018
|
return flatFeePercent / durationDays;
|
|
1054
1019
|
}
|
|
1055
1020
|
_getDefaultMaxFeeRatePerDay() {
|
|
1056
|
-
return this.bot?.config?.feeParams?.DEFAULT_MAX_FEE_RATE_PER_DAY ??
|
|
1021
|
+
return this.bot?.config?.feeParams?.DEFAULT_MAX_FEE_RATE_PER_DAY ?? FEE_PARAMETERS.DEFAULT_MAX_FEE_RATE_PER_DAY;
|
|
1057
1022
|
}
|
|
1058
1023
|
_validateCreditPolicy(policy, offer, deal = null) {
|
|
1059
1024
|
if (!policy || typeof policy !== 'object')
|
|
@@ -1087,7 +1052,7 @@ class CreditRuntime {
|
|
|
1087
1052
|
return { allow: true, reason: null };
|
|
1088
1053
|
}
|
|
1089
1054
|
async _calculateCollateralValueInDebtAsset(collateralAmountInt, collateralAsset, debtAsset, collateralPrice) {
|
|
1090
|
-
const collateralAmountFloat =
|
|
1055
|
+
const collateralAmountFloat = blockchainToFloat(collateralAmountInt, collateralAsset.precision);
|
|
1091
1056
|
if (!Number.isFinite(collateralAmountFloat) || collateralAmountFloat <= 0) {
|
|
1092
1057
|
return null;
|
|
1093
1058
|
}
|
|
@@ -1110,7 +1075,7 @@ class CreditRuntime {
|
|
|
1110
1075
|
return (collateralAmountFloat * baseAmountFloat) / quoteAmountFloat;
|
|
1111
1076
|
}
|
|
1112
1077
|
_calculateCreditOfferCollateralValueInDebtAsset(collateralAmountInt, collateralAsset, debtAsset, collateralPrice) {
|
|
1113
|
-
const collateralAmountFloat =
|
|
1078
|
+
const collateralAmountFloat = blockchainToFloat(collateralAmountInt, collateralAsset.precision);
|
|
1114
1079
|
if (!Number.isFinite(collateralAmountFloat) || collateralAmountFloat <= 0) {
|
|
1115
1080
|
return null;
|
|
1116
1081
|
}
|
|
@@ -1227,7 +1192,7 @@ class CreditRuntime {
|
|
|
1227
1192
|
currentCollateralFundsTotal: null,
|
|
1228
1193
|
currentCollateralRatio: null,
|
|
1229
1194
|
feedPrice: null,
|
|
1230
|
-
targetCollateralRatio:
|
|
1195
|
+
targetCollateralRatio: resolveTargetCollateralRatio(lendingItem),
|
|
1231
1196
|
minCollateralRatio: positiveOrNull(lendingItem.minCollateralRatio),
|
|
1232
1197
|
maxCollateralRatio: positiveOrNull(lendingItem.maxCollateralRatio),
|
|
1233
1198
|
};
|
|
@@ -1255,7 +1220,7 @@ class CreditRuntime {
|
|
|
1255
1220
|
const collateralAmount = blockchainAmountToFloat(callOrder?.collateral, collateralAsset) || 0;
|
|
1256
1221
|
const collateralBalances = callOrderCollateralAssetId ? await chainOrders.getOnChainAssetBalances(accountRef, [callOrderCollateralAssetId]) : {};
|
|
1257
1222
|
const collateralBalance = callOrderCollateralAssetId ? (collateralBalances?.[String(callOrderCollateralAssetId)] || collateralBalances?.[String(collateralAsset?.symbol)] || null) : null;
|
|
1258
|
-
let currentCollateralFundsTotal =
|
|
1223
|
+
let currentCollateralFundsTotal = toFiniteNumber(collateralBalance?.total, undefined);
|
|
1259
1224
|
// Apply registry proportional split for shared-account credit bots
|
|
1260
1225
|
if (currentCollateralFundsTotal !== null && callOrderCollateralAssetId) {
|
|
1261
1226
|
const accountName = getAccountName(this.bot);
|
|
@@ -1284,7 +1249,7 @@ class CreditRuntime {
|
|
|
1284
1249
|
currentCollateralFundsTotal,
|
|
1285
1250
|
currentCollateralRatio,
|
|
1286
1251
|
feedPrice,
|
|
1287
|
-
targetCollateralRatio:
|
|
1252
|
+
targetCollateralRatio: resolveTargetCollateralRatio(lendingItem),
|
|
1288
1253
|
minCollateralRatio: positiveOrNull(lendingItem.minCollateralRatio),
|
|
1289
1254
|
maxCollateralRatio: positiveOrNull(lendingItem.maxCollateralRatio),
|
|
1290
1255
|
mpaSelectionConflict: null,
|
|
@@ -1393,8 +1358,8 @@ class CreditRuntime {
|
|
|
1393
1358
|
activeDeals.push({
|
|
1394
1359
|
...deal,
|
|
1395
1360
|
offerEnabled: !!offer?.enabled,
|
|
1396
|
-
offerFeeRate:
|
|
1397
|
-
offerMaxDurationSeconds:
|
|
1361
|
+
offerFeeRate: toFiniteNumber(offer?.fee_rate, deal.feeRate) || deal.feeRate,
|
|
1362
|
+
offerMaxDurationSeconds: toFiniteNumber(offer?.max_duration_seconds, undefined),
|
|
1398
1363
|
canReborrow: !!offer?.enabled,
|
|
1399
1364
|
});
|
|
1400
1365
|
}
|
|
@@ -1454,7 +1419,7 @@ class CreditRuntime {
|
|
|
1454
1419
|
if (posState.mpaSelectionConflict) {
|
|
1455
1420
|
return { blocked: true, reason: posState.mpaSelectionConflict };
|
|
1456
1421
|
}
|
|
1457
|
-
const plan =
|
|
1422
|
+
const plan = buildDebtFirstCrPlan({
|
|
1458
1423
|
currentCollateralAmount: posState.currentCollateralAmount,
|
|
1459
1424
|
currentDebtAmount: posState.currentDebtAmount,
|
|
1460
1425
|
feedPrice: posState.feedPrice,
|
|
@@ -1508,8 +1473,8 @@ class CreditRuntime {
|
|
|
1508
1473
|
}
|
|
1509
1474
|
const debtDelta = leg === 'collateral' ? 0 : plan.debtDelta;
|
|
1510
1475
|
const collateralDelta = leg === 'debt' ? 0 : plan.collateralDelta;
|
|
1511
|
-
const debtInt =
|
|
1512
|
-
const collateralInt =
|
|
1476
|
+
const debtInt = floatToBlockchainInt(debtDelta, debtAsset.precision);
|
|
1477
|
+
const collateralInt = floatToBlockchainInt(collateralDelta, callOrderCollateralAsset.precision);
|
|
1513
1478
|
if (debtInt === 0 && collateralInt === 0) {
|
|
1514
1479
|
return null;
|
|
1515
1480
|
}
|
|
@@ -1609,7 +1574,7 @@ class CreditRuntime {
|
|
|
1609
1574
|
throw new Error('borrowAmount must be positive');
|
|
1610
1575
|
}
|
|
1611
1576
|
if (requestedBorrowAmount !== null) {
|
|
1612
|
-
borrowInt =
|
|
1577
|
+
borrowInt = floatToBlockchainInt(requestedBorrowAmount, debtAsset.precision);
|
|
1613
1578
|
if (!Number.isFinite(borrowInt) || borrowInt <= 0) {
|
|
1614
1579
|
throw new Error('borrowAmount must be positive');
|
|
1615
1580
|
}
|
|
@@ -1638,7 +1603,7 @@ class CreditRuntime {
|
|
|
1638
1603
|
// Enforce per-operation borrow limit
|
|
1639
1604
|
const maxPerOp = positiveOrNull(policy?.maxBorrowAmountPerOperation);
|
|
1640
1605
|
if (maxPerOp !== null && borrowInt != null && borrowInt > 0) {
|
|
1641
|
-
const borrowFloat =
|
|
1606
|
+
const borrowFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
1642
1607
|
if (Number.isFinite(borrowFloat) && borrowFloat > maxPerOp) {
|
|
1643
1608
|
throw new Error(`borrowAmount ${borrowFloat} exceeds maxBorrowAmountPerOperation ${maxPerOp}`);
|
|
1644
1609
|
}
|
|
@@ -1652,7 +1617,7 @@ class CreditRuntime {
|
|
|
1652
1617
|
await this._enforceMaxCollateralAmount(policy, requiredCollateralInt, collateralAsset, accountId, {
|
|
1653
1618
|
pendingReleaseCollateralAmount,
|
|
1654
1619
|
});
|
|
1655
|
-
const minDealAmount =
|
|
1620
|
+
const minDealAmount = toFiniteNumber(offerObj?.min_deal_amount, undefined);
|
|
1656
1621
|
if (minDealAmount !== null && borrowInt < minDealAmount) {
|
|
1657
1622
|
throw new Error(`borrowAmount ${borrowInt} is below min_deal_amount ${minDealAmount}`);
|
|
1658
1623
|
}
|
|
@@ -1661,7 +1626,7 @@ class CreditRuntime {
|
|
|
1661
1626
|
if (dailyRate > maxFeeRatePerDayValue) {
|
|
1662
1627
|
throw new Error(`offer daily fee rate ${dailyRate.toFixed(6)} exceeds maxFeeRatePerDay ${maxFeeRatePerDayValue}`);
|
|
1663
1628
|
}
|
|
1664
|
-
const offerFeeRate =
|
|
1629
|
+
const offerFeeRate = toFiniteNumber(offerObj?.fee_rate, 0) || 0;
|
|
1665
1630
|
if (offerObj?.enabled === false) {
|
|
1666
1631
|
throw new Error(`credit offer ${offerId} is disabled`);
|
|
1667
1632
|
}
|
|
@@ -1678,7 +1643,7 @@ class CreditRuntime {
|
|
|
1678
1643
|
if (maxCollateralRatioValue === null) {
|
|
1679
1644
|
throw new Error('creditOffer maxCollateralRatio is required');
|
|
1680
1645
|
}
|
|
1681
|
-
const borrowAmountFloat =
|
|
1646
|
+
const borrowAmountFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
1682
1647
|
const collateralValueInDebtAsset = await this._calculateCollateralValueInDebtAsset(requiredCollateralInt, collateralAsset, debtAsset, collateralPrice);
|
|
1683
1648
|
const offerCollateralValueInDebtAsset = this._calculateCreditOfferCollateralValueInDebtAsset(requiredCollateralInt, collateralAsset, debtAsset, collateralPrice);
|
|
1684
1649
|
if (collateralValueInDebtAsset == null || offerCollateralValueInDebtAsset == null || borrowAmountFloat <= 0 || collateralValueInDebtAsset <= 0 || offerCollateralValueInDebtAsset <= 0) {
|
|
@@ -1720,8 +1685,8 @@ class CreditRuntime {
|
|
|
1720
1685
|
return op;
|
|
1721
1686
|
}
|
|
1722
1687
|
_calculateRequiredCollateral(borrowAmountInt, collateralPrice, debtAsset = null, collateralAsset = null) {
|
|
1723
|
-
const baseAmount =
|
|
1724
|
-
const quoteAmount =
|
|
1688
|
+
const baseAmount = toFiniteNumber(collateralPrice?.base?.amount, undefined);
|
|
1689
|
+
const quoteAmount = toFiniteNumber(collateralPrice?.quote?.amount, undefined);
|
|
1725
1690
|
if (!Number.isFinite(baseAmount) || !Number.isFinite(quoteAmount) || baseAmount <= 0 || quoteAmount <= 0) {
|
|
1726
1691
|
return null;
|
|
1727
1692
|
}
|
|
@@ -1751,7 +1716,7 @@ class CreditRuntime {
|
|
|
1751
1716
|
if (!debtAsset) {
|
|
1752
1717
|
throw new Error('Unable to resolve debt asset metadata for credit repay');
|
|
1753
1718
|
}
|
|
1754
|
-
const repayInt =
|
|
1719
|
+
const repayInt = floatToBlockchainInt(repayAmount, debtAsset.precision);
|
|
1755
1720
|
if (!Number.isFinite(repayInt) || repayInt <= 0) {
|
|
1756
1721
|
throw new Error('repayAmount must be positive');
|
|
1757
1722
|
}
|
|
@@ -1823,14 +1788,14 @@ class CreditRuntime {
|
|
|
1823
1788
|
});
|
|
1824
1789
|
};
|
|
1825
1790
|
try {
|
|
1826
|
-
if (!lock || typeof lock.acquire !== 'function'
|
|
1791
|
+
if (!lock || typeof lock.acquire !== 'function') {
|
|
1827
1792
|
return await runCheck();
|
|
1828
1793
|
}
|
|
1829
1794
|
return await lock.acquire(runCheck);
|
|
1830
1795
|
}
|
|
1831
1796
|
catch (err) {
|
|
1832
|
-
this.warn(`credit runtime: post-credit grid maintenance failed during ${context}: ${
|
|
1833
|
-
return { skipped: false, error:
|
|
1797
|
+
this.warn(`credit runtime: post-credit grid maintenance failed during ${context}: ${getErrorMessage(err)}`);
|
|
1798
|
+
return { skipped: false, error: getErrorMessage(err) };
|
|
1834
1799
|
}
|
|
1835
1800
|
}
|
|
1836
1801
|
async openCreditPosition({ offer, borrowAmount, collateralAmount, autoRepay = false, reason = 'credit borrow' } = {}) {
|
|
@@ -1942,7 +1907,7 @@ class CreditRuntime {
|
|
|
1942
1907
|
excludeOfferId: dealSummary.offerId,
|
|
1943
1908
|
});
|
|
1944
1909
|
if (fallback) {
|
|
1945
|
-
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected after original offer ${dealSummary.offerId} failed: ${
|
|
1910
|
+
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected after original offer ${dealSummary.offerId} failed: ${getErrorMessage(err)}`);
|
|
1946
1911
|
operations.push(fallback.op);
|
|
1947
1912
|
inlineReborrowPlanned = true;
|
|
1948
1913
|
}
|
|
@@ -1957,7 +1922,7 @@ class CreditRuntime {
|
|
|
1957
1922
|
pendingRepayAmount: repayAmount,
|
|
1958
1923
|
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1959
1924
|
requestedAt: new Date().toISOString(),
|
|
1960
|
-
reason:
|
|
1925
|
+
reason: getErrorMessage(err),
|
|
1961
1926
|
};
|
|
1962
1927
|
}
|
|
1963
1928
|
}
|
|
@@ -2037,7 +2002,7 @@ class CreditRuntime {
|
|
|
2037
2002
|
catch (err) {
|
|
2038
2003
|
this.queueReborrow({
|
|
2039
2004
|
...reborrowRequest,
|
|
2040
|
-
reason:
|
|
2005
|
+
reason: getErrorMessage(err),
|
|
2041
2006
|
});
|
|
2042
2007
|
}
|
|
2043
2008
|
}
|
|
@@ -2139,7 +2104,7 @@ class CreditRuntime {
|
|
|
2139
2104
|
return offers;
|
|
2140
2105
|
}
|
|
2141
2106
|
catch (err) {
|
|
2142
|
-
this.warn(`credit runtime: unable to fetch fallback credit offers for ${assetId}: ${
|
|
2107
|
+
this.warn(`credit runtime: unable to fetch fallback credit offers for ${assetId}: ${getErrorMessage(err)}`);
|
|
2143
2108
|
return [];
|
|
2144
2109
|
}
|
|
2145
2110
|
}
|
|
@@ -2187,9 +2152,9 @@ class CreditRuntime {
|
|
|
2187
2152
|
offer,
|
|
2188
2153
|
op,
|
|
2189
2154
|
dailyRate: this._calculateDailyFeeRate(offer),
|
|
2190
|
-
feeRate:
|
|
2191
|
-
balance:
|
|
2192
|
-
duration:
|
|
2155
|
+
feeRate: toFiniteNumber(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2156
|
+
balance: toFiniteNumber(offer.current_balance, 0),
|
|
2157
|
+
duration: toFiniteNumber(offer.max_duration_seconds, 0),
|
|
2193
2158
|
});
|
|
2194
2159
|
}
|
|
2195
2160
|
catch (_) {
|
|
@@ -2266,7 +2231,7 @@ class CreditRuntime {
|
|
|
2266
2231
|
referenceLabel: 'total collateral balance',
|
|
2267
2232
|
});
|
|
2268
2233
|
const desiredBorrowInt = this._calculateBorrowAmountFromCollateral(requestedCollateralInt, collateralPrice, debtAsset, collateralAsset);
|
|
2269
|
-
const desiredBorrowAmount =
|
|
2234
|
+
const desiredBorrowAmount = blockchainToFloat(desiredBorrowInt, debtAsset.precision);
|
|
2270
2235
|
if (Number.isFinite(desiredBorrowAmount) && desiredBorrowAmount > effectiveBorrowCapacity) {
|
|
2271
2236
|
acceptArgs = {
|
|
2272
2237
|
offer,
|
|
@@ -2301,7 +2266,7 @@ class CreditRuntime {
|
|
|
2301
2266
|
if (opBorrowAmount == null || opCollateralAmount == null || opBorrowAmount <= 0 || opCollateralAmount <= 0) {
|
|
2302
2267
|
continue;
|
|
2303
2268
|
}
|
|
2304
|
-
const capped = opCollateralAmount <
|
|
2269
|
+
const capped = opCollateralAmount < toFiniteNumber(collateralAmount?.amount ?? collateralAmount, 0);
|
|
2305
2270
|
if (capped && opCollateralAmount < minCollateralIncrease) {
|
|
2306
2271
|
continue;
|
|
2307
2272
|
}
|
|
@@ -2312,9 +2277,9 @@ class CreditRuntime {
|
|
|
2312
2277
|
collateralAmount: opCollateralAmount,
|
|
2313
2278
|
capped,
|
|
2314
2279
|
dailyRate: this._calculateDailyFeeRate(offer),
|
|
2315
|
-
feeRate:
|
|
2316
|
-
balance:
|
|
2317
|
-
duration:
|
|
2280
|
+
feeRate: toFiniteNumber(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2281
|
+
balance: toFiniteNumber(offer.current_balance, 0),
|
|
2282
|
+
duration: toFiniteNumber(offer.max_duration_seconds, 0),
|
|
2318
2283
|
});
|
|
2319
2284
|
}
|
|
2320
2285
|
catch (_) {
|
|
@@ -2334,7 +2299,7 @@ class CreditRuntime {
|
|
|
2334
2299
|
const assignedCollateralBudget = positiveOrNull(posState?.assignedCollateralBudget);
|
|
2335
2300
|
if (assignedCollateralBudget === null)
|
|
2336
2301
|
return null;
|
|
2337
|
-
const minCollateralIncrease =
|
|
2302
|
+
const minCollateralIncrease = resolveMinCollateralIncreaseThreshold(lendingItem.minCollateralIncreaseThreshold, assignedCollateralBudget);
|
|
2338
2303
|
if (minCollateralIncrease === null)
|
|
2339
2304
|
return null;
|
|
2340
2305
|
const debtAsset = await this._resolveAsset(assetId);
|
|
@@ -2362,13 +2327,13 @@ class CreditRuntime {
|
|
|
2362
2327
|
}
|
|
2363
2328
|
return {
|
|
2364
2329
|
action: 'increase_credit_debt',
|
|
2365
|
-
currentCollateralAmount:
|
|
2366
|
-
collateralIncreaseAmount:
|
|
2367
|
-
minCollateralIncrease:
|
|
2368
|
-
currentDebtAmount:
|
|
2369
|
-
maxBorrowAmount: maxBorrowAmount !== null ?
|
|
2370
|
-
remainingBorrowCapacity: remainingBorrowCapacity !== null ?
|
|
2371
|
-
assignedCollateralBudget:
|
|
2330
|
+
currentCollateralAmount: roundToDecimals(currentCollateralAmount, 8),
|
|
2331
|
+
collateralIncreaseAmount: roundToDecimals(collateralIncreaseAmount, 8),
|
|
2332
|
+
minCollateralIncrease: roundToDecimals(minCollateralIncrease, 8),
|
|
2333
|
+
currentDebtAmount: roundToDecimals(currentDebtAmount, 8),
|
|
2334
|
+
maxBorrowAmount: maxBorrowAmount !== null ? roundToDecimals(maxBorrowAmount, 8) : null,
|
|
2335
|
+
remainingBorrowCapacity: remainingBorrowCapacity !== null ? roundToDecimals(remainingBorrowCapacity, 8) : null,
|
|
2336
|
+
assignedCollateralBudget: roundToDecimals(assignedCollateralBudget, 8),
|
|
2372
2337
|
};
|
|
2373
2338
|
}
|
|
2374
2339
|
async _splitOversizedCreditDeals(lendingItem, assetId, posState, runtimeContext = {}) {
|
|
@@ -2402,12 +2367,12 @@ class CreditRuntime {
|
|
|
2402
2367
|
if (oversized.length === 0)
|
|
2403
2368
|
return null;
|
|
2404
2369
|
// T3: Use canonical settle-delay resolution matching dexbot_maintenance_runtime.ts
|
|
2405
|
-
const settleDelay = Number.isFinite(
|
|
2406
|
-
? Math.max(0,
|
|
2370
|
+
const settleDelay = Number.isFinite(TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2371
|
+
? Math.max(0, TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2407
2372
|
: 6_000;
|
|
2408
2373
|
// T4: Hard cap on pieces per cycle so the watchdog interval is never exceeded
|
|
2409
|
-
const MAX_PIECES_PER_CYCLE = Number.isFinite(
|
|
2410
|
-
? Math.max(0,
|
|
2374
|
+
const MAX_PIECES_PER_CYCLE = Number.isFinite(TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2375
|
+
? Math.max(0, TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2411
2376
|
: 48;
|
|
2412
2377
|
const configuredCollateralAssetId = collateralAsset.id;
|
|
2413
2378
|
const posKey = configuredCollateralAssetId
|
|
@@ -2426,11 +2391,11 @@ class CreditRuntime {
|
|
|
2426
2391
|
// offer's min_deal_amount changes on-chain mid-split, the guard uses the
|
|
2427
2392
|
// stale cached value. Risk is low in practice (offers rarely change this).
|
|
2428
2393
|
const dealOffer = await this._getOfferById(parseDealSummary(currentDeal)?.offerId);
|
|
2429
|
-
const minDealAmount =
|
|
2394
|
+
const minDealAmount = toFiniteNumber(dealOffer?.min_deal_amount, undefined);
|
|
2430
2395
|
const numPieces = Math.ceil(dealDebt / maxPerOp);
|
|
2431
|
-
const pieceAmount =
|
|
2432
|
-
if (minDealAmount !== null && pieceAmount <
|
|
2433
|
-
this.warn(`credit runtime: cannot split deal ${dealId} — piece amount ${pieceAmount} below min_deal_amount ${
|
|
2396
|
+
const pieceAmount = roundToDecimals(dealDebt / numPieces, debtAsset.precision);
|
|
2397
|
+
if (minDealAmount !== null && pieceAmount < blockchainToFloat(minDealAmount, debtAsset.precision)) {
|
|
2398
|
+
this.warn(`credit runtime: cannot split deal ${dealId} — piece amount ${pieceAmount} below min_deal_amount ${blockchainToFloat(minDealAmount, debtAsset.precision)} for offer ${dealOffer?.id}`);
|
|
2434
2399
|
continue;
|
|
2435
2400
|
}
|
|
2436
2401
|
const dealPieces = Math.min(numPieces - 1, MAX_PIECES_PER_CYCLE - totalPiecesThisCycle);
|
|
@@ -2590,8 +2555,8 @@ class CreditRuntime {
|
|
|
2590
2555
|
processed++;
|
|
2591
2556
|
}
|
|
2592
2557
|
catch (err) {
|
|
2593
|
-
this.warn(`credit runtime: fallback reborrow for offer ${request.offerId} failed: ${
|
|
2594
|
-
nextQueue.push({ ...request, reason:
|
|
2558
|
+
this.warn(`credit runtime: fallback reborrow for offer ${request.offerId} failed: ${getErrorMessage(err)}`);
|
|
2559
|
+
nextQueue.push({ ...request, reason: getErrorMessage(err) });
|
|
2595
2560
|
}
|
|
2596
2561
|
}
|
|
2597
2562
|
else {
|
|
@@ -2614,8 +2579,8 @@ class CreditRuntime {
|
|
|
2614
2579
|
processed++;
|
|
2615
2580
|
}
|
|
2616
2581
|
catch (err) {
|
|
2617
|
-
this.warn(`credit runtime: pending reborrow for offer ${request.offerId} failed: ${
|
|
2618
|
-
nextQueue.push({ ...request, reason:
|
|
2582
|
+
this.warn(`credit runtime: pending reborrow for offer ${request.offerId} failed: ${getErrorMessage(err)}`);
|
|
2583
|
+
nextQueue.push({ ...request, reason: getErrorMessage(err) });
|
|
2619
2584
|
}
|
|
2620
2585
|
}
|
|
2621
2586
|
this.state.pendingReborrows = nextQueue;
|
|
@@ -2660,7 +2625,7 @@ class CreditRuntime {
|
|
|
2660
2625
|
if (!isDeterministicMpaDebtBalanceError(err, plan)) {
|
|
2661
2626
|
throw err;
|
|
2662
2627
|
}
|
|
2663
|
-
this.warn(`credit runtime: MPA combined operation failed; attempting collateral fallback: ${
|
|
2628
|
+
this.warn(`credit runtime: MPA combined operation failed; attempting collateral fallback: ${getErrorMessage(err)}`);
|
|
2664
2629
|
await this.refreshMpaState(lendingItem);
|
|
2665
2630
|
if (lendingItem.debtOnly) {
|
|
2666
2631
|
throw err;
|
|
@@ -2671,7 +2636,7 @@ class CreditRuntime {
|
|
|
2671
2636
|
const configuredCollateralAssetId = configuredCollateralAsset?.id;
|
|
2672
2637
|
const posKey = configuredCollateralAssetId ? this._positionKey(assetId, configuredCollateralAssetId) : assetId;
|
|
2673
2638
|
const posState = this.state.positions[posKey];
|
|
2674
|
-
const collateralPlan =
|
|
2639
|
+
const collateralPlan = buildCollateralFallbackPlan({
|
|
2675
2640
|
currentCollateralAmount: posState?.currentCollateralAmount,
|
|
2676
2641
|
currentDebtAmount: posState?.currentDebtAmount,
|
|
2677
2642
|
feedPrice: posState?.feedPrice,
|
|
@@ -2718,8 +2683,8 @@ class CreditRuntime {
|
|
|
2718
2683
|
return { plan, executed, resetResult };
|
|
2719
2684
|
}
|
|
2720
2685
|
catch (err) {
|
|
2721
|
-
this.warn(`credit runtime: grid reset after CR adjustment failed: ${
|
|
2722
|
-
return { plan, executed, resetError:
|
|
2686
|
+
this.warn(`credit runtime: grid reset after CR adjustment failed: ${getErrorMessage(err)}`);
|
|
2687
|
+
return { plan, executed, resetError: getErrorMessage(err) };
|
|
2723
2688
|
}
|
|
2724
2689
|
}
|
|
2725
2690
|
return { plan, executed };
|
|
@@ -2750,7 +2715,7 @@ class CreditRuntime {
|
|
|
2750
2715
|
}
|
|
2751
2716
|
}
|
|
2752
2717
|
catch (err) {
|
|
2753
|
-
this.warn(`credit runtime: deal restructuring failed: ${
|
|
2718
|
+
this.warn(`credit runtime: deal restructuring failed: ${getErrorMessage(err)}`);
|
|
2754
2719
|
}
|
|
2755
2720
|
let activeDealIds = new Set((posState.creditDeals || []).map((d) => String(d?.id)).filter(Boolean));
|
|
2756
2721
|
for (const deal of (posState.creditDeals || [])) {
|
|
@@ -2773,7 +2738,7 @@ class CreditRuntime {
|
|
|
2773
2738
|
const accountRef = getAccountRef(this.bot);
|
|
2774
2739
|
const balances = await chainOrders.getOnChainAssetBalances(accountRef, [configuredCollateralAssetId]);
|
|
2775
2740
|
const balance = balances?.[String(configuredCollateralAssetId)] || balances?.[String(configuredCollateralAsset?.symbol)] || null;
|
|
2776
|
-
const available =
|
|
2741
|
+
const available = toFiniteNumber(balance?.total, undefined);
|
|
2777
2742
|
if (!Number.isFinite(available) || available <= 0) {
|
|
2778
2743
|
this.warn(`credit runtime: skipping collateral switch for deal ${deal.id} — no balance of new collateral ${configuredCollateralAssetId}`);
|
|
2779
2744
|
continue;
|
|
@@ -2824,7 +2789,7 @@ class CreditRuntime {
|
|
|
2824
2789
|
}
|
|
2825
2790
|
}
|
|
2826
2791
|
catch (err) {
|
|
2827
|
-
this.warn(`credit runtime: proactive repay/reborrow for deal ${deal.id} failed: ${
|
|
2792
|
+
this.warn(`credit runtime: proactive repay/reborrow for deal ${deal.id} failed: ${getErrorMessage(err)}`);
|
|
2828
2793
|
}
|
|
2829
2794
|
}
|
|
2830
2795
|
}
|
|
@@ -2841,7 +2806,7 @@ class CreditRuntime {
|
|
|
2841
2806
|
deal.autoRepay = policyAutoRepay;
|
|
2842
2807
|
}
|
|
2843
2808
|
catch (err) {
|
|
2844
|
-
this.warn(`credit runtime: failed to update auto_repay on deal ${deal.id}: ${
|
|
2809
|
+
this.warn(`credit runtime: failed to update auto_repay on deal ${deal.id}: ${getErrorMessage(err)}`);
|
|
2845
2810
|
}
|
|
2846
2811
|
}
|
|
2847
2812
|
}
|
|
@@ -2965,8 +2930,8 @@ class CreditRuntime {
|
|
|
2965
2930
|
};
|
|
2966
2931
|
}
|
|
2967
2932
|
catch (err) {
|
|
2968
|
-
this.warn(`credit runtime: watchdog error: ${
|
|
2969
|
-
return { skipped: true, reason:
|
|
2933
|
+
this.warn(`credit runtime: watchdog error: ${getErrorMessage(err)}`);
|
|
2934
|
+
return { skipped: true, reason: getErrorMessage(err) };
|
|
2970
2935
|
}
|
|
2971
2936
|
finally {
|
|
2972
2937
|
this._watchdogInFlight = false;
|
|
@@ -2983,7 +2948,7 @@ class CreditRuntime {
|
|
|
2983
2948
|
for (const assetId of assetIds) {
|
|
2984
2949
|
const key = String(assetId);
|
|
2985
2950
|
const entry = snapshot[key];
|
|
2986
|
-
result[key] =
|
|
2951
|
+
result[key] = toFiniteNumber(entry?.totalCollateral, 0);
|
|
2987
2952
|
}
|
|
2988
2953
|
return result;
|
|
2989
2954
|
}
|
|
@@ -2991,6 +2956,5 @@ class CreditRuntime {
|
|
|
2991
2956
|
return deepClone(this.state);
|
|
2992
2957
|
}
|
|
2993
2958
|
}
|
|
2994
|
-
|
|
2995
|
-
module.exports = CreditRuntime;
|
|
2959
|
+
export default CreditRuntime;
|
|
2996
2960
|
//# sourceMappingURL=credit_runtime.js.map
|