dexbot 1.3.2 → 1.4.0
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/dist/analysis/chart_utils.d.ts +11 -9
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +21 -16
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts +4 -13
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +16 -18
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +3 -7
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +38 -34
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +1 -4
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +10 -7
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +6 -6
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +23 -15
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +12 -13
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +16 -16
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +1 -4
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +10 -7
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +6 -13
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +74 -35
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +16 -15
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.d.ts +1 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -20
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.d.ts +2 -10
- package/dist/market_adapter/candle_utils.d.ts.map +1 -1
- package/dist/market_adapter/candle_utils.js +7 -8
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +12 -7
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +4 -5
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.d.ts +4 -9
- package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +9 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.d.ts +16 -20
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +16 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.d.ts +8 -11
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +13 -11
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts +5 -12
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +12 -21
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts +75 -53
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +102 -98
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.d.ts +21 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +10 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +7 -11
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +23 -30
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +5 -4
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +5 -3
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +4 -7
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +5 -4
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +11 -19
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +22 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +24 -2
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +82 -56
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +26 -37
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +4 -12
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +100 -66
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts +4 -9
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +17 -18
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.d.ts +1 -4
- package/dist/market_adapter/interval_utils.d.ts.map +1 -1
- package/dist/market_adapter/interval_utils.js +2 -3
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.d.ts +1 -9
- package/dist/market_adapter/log_format.d.ts.map +1 -1
- package/dist/market_adapter/log_format.js +7 -8
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.d.ts +1 -4
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +22 -20
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +13 -24
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +58 -56
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +4 -17
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +36 -36
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +51 -72
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +227 -192
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -16
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.d.ts +9 -13
- package/dist/market_adapter/test_helpers.d.ts.map +1 -1
- package/dist/market_adapter/test_helpers.js +14 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.d.ts +6 -14
- package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +16 -15
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.d.ts +2 -5
- package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +5 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts +19 -21
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +15 -16
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.d.ts +1 -4
- package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +10 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +1 -6
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +14 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.d.ts +1 -7
- package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +21 -25
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.d.ts +12 -12
- package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
- package/dist/market_adapter/utils/native_history.js +15 -15
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.d.ts +2 -4
- package/dist/market_adapter/utils/paths.d.ts.map +1 -1
- package/dist/market_adapter/utils/paths.js +6 -5
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +7 -8
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +92 -114
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +5 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +69 -32
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.d.ts +32 -1
- package/dist/modules/authority_resolver.d.ts.map +1 -1
- package/dist/modules/authority_resolver.js +18 -12
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.d.ts +3 -8
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +21 -16
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +21 -29
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +72 -38
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts +9 -36
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +40 -83
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +14 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -3
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +10 -2
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +68 -31
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +1 -4
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +6 -3
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.d.ts +3 -6
- package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +11 -9
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +53 -55
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +28 -27
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +5 -9
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +46 -12
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +102 -100
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +473 -471
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +2 -7
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +8 -3
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.d.ts +26 -41
- package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +76 -42
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts +1 -5
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +49 -11
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts +1 -4
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +47 -84
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts +1 -8
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +22 -15
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts +3 -8
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +61 -23
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +1 -8
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +21 -17
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +12 -23
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +109 -56
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts +1 -13
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +34 -34
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts +3 -9
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +8 -9
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +7 -39
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +126 -90
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +46 -52
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +152 -104
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts +50 -57
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +28 -24
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +492 -492
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +79 -39
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.d.ts +1 -13
- package/dist/modules/cr_planner.d.ts.map +1 -1
- package/dist/modules/cr_planner.js +28 -28
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +18 -33
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +114 -87
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +11 -21
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +40 -40
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +8 -8
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +41 -8
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts +51 -316
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +257 -183
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.js +6 -6
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +2 -0
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/sync.js +3 -3
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +124 -73
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +198 -3577
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +322 -0
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_cow_runtime.js +1836 -0
- package/dist/modules/dexbot_cow_runtime.js.map +1 -0
- package/dist/modules/dexbot_credential_client.d.ts +5 -11
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +32 -30
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +47 -15
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +565 -22
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +79 -10
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +294 -55
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +26 -0
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_startup_runtime.js +575 -0
- package/dist/modules/dexbot_startup_runtime.js.map +1 -0
- package/dist/modules/dexbot_state_recovery.d.ts +115 -0
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -0
- package/dist/modules/dexbot_state_recovery.js +431 -0
- package/dist/modules/dexbot_state_recovery.js.map +1 -0
- package/dist/modules/fund_registry.d.ts +1 -13
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +23 -22
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.d.ts +3 -7
- package/dist/modules/general_settings.d.ts.map +1 -1
- package/dist/modules/general_settings.js +15 -15
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts +1 -6
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +19 -16
- 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 +53 -20
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +23 -66
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +115 -107
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.d.ts +2 -5
- package/dist/modules/launcher/child_env.d.ts.map +1 -1
- package/dist/modules/launcher/child_env.js +4 -4
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts +4 -8
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +30 -26
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +8 -15
- package/dist/modules/launcher/credential_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +72 -41
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.d.ts +1 -4
- package/dist/modules/launcher/credential_secret.d.ts.map +1 -1
- package/dist/modules/launcher/credential_secret.js +36 -4
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +32 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -28
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.d.ts +1 -4
- package/dist/modules/launcher/headless_password.d.ts.map +1 -1
- package/dist/modules/launcher/headless_password.js +11 -11
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.d.ts +15 -14
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +8 -8
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +10 -19
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +33 -34
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -17
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -39
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +28 -57
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +135 -108
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +5 -10
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +14 -14
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +17 -37
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +35 -34
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.d.ts +1 -4
- package/dist/modules/launcher/supervisor_control.d.ts.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +9 -4
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +3 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +38 -28
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.d.ts +2 -10
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +18 -16
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts +2 -12
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +24 -24
- 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 -38
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts +12 -12
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +111 -76
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +1 -2
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +4 -4
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.d.ts +8 -14
- package/dist/modules/order/export.d.ts.map +1 -1
- package/dist/modules/order/export.js +77 -42
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +17 -22
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +25 -31
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +18 -104
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +246 -188
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts +8 -8
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +24 -24
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts +224 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +145 -72
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +42 -7
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.d.ts +6 -16
- package/dist/modules/order/logger.d.ts.map +1 -1
- package/dist/modules/order/logger.js +76 -53
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -1
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +160 -37
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +166 -128
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.d.ts +6 -10
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
- package/dist/modules/order/processed_fill_store.js +10 -9
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.d.ts +3 -3
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +29 -27
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +9 -19
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +176 -126
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +55 -85
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +155 -88
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +27 -72
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +144 -105
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +74 -44
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +188 -149
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/validate.d.ts +21 -43
- package/dist/modules/order/utils/validate.d.ts.map +1 -1
- package/dist/modules/order/utils/validate.js +140 -110
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/working_grid.d.ts +1 -4
- package/dist/modules/order/working_grid.d.ts.map +1 -1
- package/dist/modules/order/working_grid.js +9 -7
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.js +2 -2
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts +51 -55
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +72 -52
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.d.ts.map +1 -1
- package/dist/modules/process_discovery.js +7 -7
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.d.ts +1 -1
- package/dist/modules/runtime.d.ts.map +1 -1
- package/dist/modules/runtime.js +4 -4
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts +1 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +15 -10
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.d.ts +1 -4
- package/dist/modules/settings_merge.d.ts.map +1 -1
- package/dist/modules/settings_merge.js +2 -1
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/storage/browser_adapter.d.ts +7 -3
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
- package/dist/modules/storage/browser_adapter.js +2 -0
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +2 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +2 -5
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -3
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +9 -7
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.d.ts +13 -10
- package/dist/modules/storage/types.d.ts.map +1 -1
- package/dist/modules/types.d.ts +0 -2
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/utils/base58check.d.ts +1 -9
- package/dist/modules/utils/base58check.d.ts.map +1 -1
- package/dist/modules/utils/base58check.js +14 -16
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.d.ts +2 -5
- package/dist/modules/utils/build_dir.d.ts.map +1 -1
- package/dist/modules/utils/build_dir.js +6 -3
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.d.ts +2 -0
- package/dist/modules/utils/errors.d.ts.map +1 -0
- package/dist/modules/utils/errors.js +12 -0
- package/dist/modules/utils/errors.js.map +1 -0
- package/dist/modules/utils/fs_utils.d.ts +1 -8
- package/dist/modules/utils/fs_utils.d.ts.map +1 -1
- package/dist/modules/utils/fs_utils.js +8 -3
- package/dist/modules/utils/fs_utils.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +2 -6
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +6 -2
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts +1 -11
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +25 -27
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +7 -6
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +132 -106
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.d.ts.map +1 -1
- package/dist/scripts/analyze-git.js +15 -11
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts +146 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +81 -105
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +9 -8
- 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 +11 -8
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.d.ts +3 -0
- package/dist/scripts/fix-err-message.d.ts.map +1 -0
- package/dist/scripts/fix-err-message.js +198 -0
- package/dist/scripts/fix-err-message.js.map +1 -0
- package/dist/scripts/generate_lp_chart.d.ts +2 -9
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +14 -10
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +4 -4
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +17 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +23 -20
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/migrate_bot_keys.d.ts +1 -4
- package/dist/scripts/migrate_bot_keys.d.ts.map +1 -1
- package/dist/scripts/migrate_bot_keys.js +48 -124
- package/dist/scripts/migrate_bot_keys.js.map +1 -1
- package/dist/scripts/native_release_gates.d.ts.map +1 -1
- package/dist/scripts/native_release_gates.js +18 -14
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.js +1 -1
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +1 -0
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts +1 -11
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +21 -19
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +2 -1
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.d.ts.map +1 -1
- package/dist/scripts/update.js +85 -79
- package/dist/scripts/update.js.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 +25 -1
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +4 -17
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +141 -108
- package/dist/unlock.js.map +1 -1
- package/package.json +7 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +0 -3
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +0 -149
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +0 -3
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +0 -387
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +0 -3
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -200
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +0 -3
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +0 -212
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +0 -31
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +0 -249
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +0 -2
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +0 -782
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_derivatives.d.ts +0 -95
- package/dist/analysis/analyze_derivatives.d.ts.map +0 -1
- package/dist/analysis/analyze_derivatives.js +0 -295
- package/dist/analysis/analyze_derivatives.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts +0 -14
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js +0 -207
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts +0 -13
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js +0 -123
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts +0 -20
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js +0 -139
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts +0 -19
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js +0 -413
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts +0 -3
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js +0 -159
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts +0 -3
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js +0 -367
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts +0 -22
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js +0 -172
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +0 -99
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +0 -804
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +0 -2
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +0 -347
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts +0 -15
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js +0 -48
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts +0 -22
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js +0 -162
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +0 -3
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js +0 -498
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +0 -546
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js +0 -427
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/derivative_chart_generator.d.ts +0 -18
- package/dist/analysis/derivative_chart_generator.d.ts.map +0 -1
- package/dist/analysis/derivative_chart_generator.js +0 -896
- package/dist/analysis/derivative_chart_generator.js.map +0 -1
- package/dist/analysis/price_sources.d.ts +0 -34
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js +0 -103
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts +0 -115
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js +0 -1247
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +0 -36
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +0 -172
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +0 -250
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.js +0 -903
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +0 -1450
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +0 -408
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +0 -345
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -130
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -38
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +0 -732
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
|
@@ -1,30 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
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"));
|
|
39
|
+
const { BitShares, waitForConnected } = client;
|
|
40
|
+
const chainOrders = __importStar(require("./chain_orders"));
|
|
41
|
+
const math_1 = require("./order/utils/math");
|
|
42
|
+
const format_1 = require("./order/format");
|
|
43
|
+
const account_orders_1 = require("./account_orders");
|
|
44
|
+
const fundRegistry = __importStar(require("./fund_registry"));
|
|
45
|
+
const bots_file_lock_1 = require("./bots_file_lock");
|
|
46
|
+
const constants_1 = require("./constants");
|
|
47
|
+
const math_2 = require("./order/utils/math");
|
|
48
|
+
const paths_1 = require("./paths");
|
|
49
|
+
const fs_utils_1 = require("./utils/fs_utils");
|
|
50
|
+
const _sysUtils = require("./order/utils/system");
|
|
51
|
+
const { deriveLiquidityPoolTokenValue, ensureDir: ensureDirSync } = _sysUtils;
|
|
1
52
|
'use strict';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const { BitShares, waitForConnected } = require('./bitshares_client');
|
|
6
|
-
const chainOrders = require('./chain_orders');
|
|
7
|
-
const { blockchainToFloat, floatToBlockchainInt, resolveConfigValue } = require('./order/utils/math');
|
|
8
|
-
const { deriveLiquidityPoolTokenValue } = require('./order/utils/system');
|
|
9
|
-
const { toFiniteNumber } = require('./order/format');
|
|
10
|
-
const { createBotKey } = require('./account_orders');
|
|
11
|
-
const fundRegistry = require('./fund_registry');
|
|
12
|
-
const { writeJsonFileAtomic } = require('./bots_file_lock');
|
|
13
|
-
const { buildCollateralFallbackPlan, buildDebtFirstCrPlan, resolveMinCollateralIncreaseThreshold, resolveTargetCollateralRatio, } = require('./cr_planner');
|
|
14
|
-
const { FEE_PARAMETERS, DEFAULT_TARGET_CR, TIMING } = require('./constants');
|
|
15
|
-
const { roundToDecimals } = require('./order/utils/math');
|
|
16
|
-
const { PATHS } = require('./paths');
|
|
17
|
-
const { readJSON } = require('./utils/fs_utils');
|
|
53
|
+
const storage = (0, storage_1.getStorage)();
|
|
54
|
+
const cr_planner_1 = require("./cr_planner");
|
|
55
|
+
const errors_1 = require("./utils/errors");
|
|
18
56
|
const CREDIT_FEE_RATE_DENOM = 1_000_000;
|
|
19
57
|
const ZERO_ASSET_ID = '1.3.0';
|
|
20
|
-
const DEFAULT_STATE_DIR = PATHS.CREDIT_RUNTIME_DIR;
|
|
21
|
-
const GRAPHENE_COLLATERAL_RATIO_DENOM = FEE_PARAMETERS.GRAPHENE_COLLATERAL_RATIO_DENOM;
|
|
22
|
-
const { ensureDir: ensureDirSync } = require('./order/utils/system');
|
|
58
|
+
const DEFAULT_STATE_DIR = paths_1.PATHS.CREDIT_RUNTIME_DIR;
|
|
59
|
+
const GRAPHENE_COLLATERAL_RATIO_DENOM = constants_1.FEE_PARAMETERS.GRAPHENE_COLLATERAL_RATIO_DENOM;
|
|
23
60
|
function deepClone(value) {
|
|
24
61
|
return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
25
62
|
}
|
|
26
63
|
function positiveOrNull(value) {
|
|
27
|
-
const num = toFiniteNumber(value,
|
|
64
|
+
const num = (0, format_1.toFiniteNumber)(value, undefined);
|
|
28
65
|
return Number.isFinite(num) && num > 0 ? num : null;
|
|
29
66
|
}
|
|
30
67
|
function normalizeResolvedPriceResult(value, liveSource, missingSource) {
|
|
@@ -80,9 +117,6 @@ function getMapEntries(value) {
|
|
|
80
117
|
return Object.entries(value);
|
|
81
118
|
return [];
|
|
82
119
|
}
|
|
83
|
-
function getPriceBaseAssetId(price) {
|
|
84
|
-
return price?.base?.asset_id || null;
|
|
85
|
-
}
|
|
86
120
|
function getPriceQuoteAssetId(price) {
|
|
87
121
|
return price?.quote?.asset_id || null;
|
|
88
122
|
}
|
|
@@ -94,9 +128,9 @@ function toAmountObject(amount, assetId) {
|
|
|
94
128
|
}
|
|
95
129
|
function getChainAmountValue(value) {
|
|
96
130
|
if (value && typeof value === 'object' && value.amount !== undefined) {
|
|
97
|
-
return toFiniteNumber(value.amount,
|
|
131
|
+
return (0, format_1.toFiniteNumber)(value.amount, undefined);
|
|
98
132
|
}
|
|
99
|
-
return toFiniteNumber(value,
|
|
133
|
+
return (0, format_1.toFiniteNumber)(value, undefined);
|
|
100
134
|
}
|
|
101
135
|
function getAssetPrecision(asset) {
|
|
102
136
|
const precision = Number(asset?.precision);
|
|
@@ -108,10 +142,10 @@ function blockchainAmountToFloat(value, asset) {
|
|
|
108
142
|
if (!Number.isFinite(amount) || precision === null) {
|
|
109
143
|
return null;
|
|
110
144
|
}
|
|
111
|
-
return blockchainToFloat(amount, precision);
|
|
145
|
+
return (0, math_1.blockchainToFloat)(amount, precision);
|
|
112
146
|
}
|
|
113
147
|
function isDeterministicMpaDebtBalanceError(err, plan) {
|
|
114
|
-
const debtDelta = toFiniteNumber(plan?.debtDelta, 0);
|
|
148
|
+
const debtDelta = (0, format_1.toFiniteNumber)(plan?.debtDelta, 0);
|
|
115
149
|
if (!Number.isFinite(debtDelta) || debtDelta >= 0) {
|
|
116
150
|
return false;
|
|
117
151
|
}
|
|
@@ -209,12 +243,12 @@ function parseDealSummary(deal) {
|
|
|
209
243
|
offerId: deal.offerId || deal.offer_id || null,
|
|
210
244
|
offerOwner: deal.offerOwner || deal.offer_owner || null,
|
|
211
245
|
debtAssetId: deal.debtAssetId || deal.debt_asset || null,
|
|
212
|
-
debtAmount: toFiniteNumber(deal.debtAmount ?? deal.debt_amount, 0) || 0,
|
|
246
|
+
debtAmount: (0, format_1.toFiniteNumber)(deal.debtAmount ?? deal.debt_amount, 0) || 0,
|
|
213
247
|
collateralAssetId: deal.collateralAssetId || deal.collateral_asset || null,
|
|
214
|
-
collateralAmount: toFiniteNumber(deal.collateralAmount ?? deal.collateral_amount, 0) || 0,
|
|
215
|
-
feeRate: toFiniteNumber(deal.feeRate ?? deal.fee_rate, 0) || 0,
|
|
248
|
+
collateralAmount: (0, format_1.toFiniteNumber)(deal.collateralAmount ?? deal.collateral_amount, 0) || 0,
|
|
249
|
+
feeRate: (0, format_1.toFiniteNumber)(deal.feeRate ?? deal.fee_rate, 0) || 0,
|
|
216
250
|
latestRepayTime: deal.latestRepayTime || deal.latest_repay_time || null,
|
|
217
|
-
autoRepay: toFiniteNumber(deal.autoRepay ?? deal.auto_repay, 0) || 0,
|
|
251
|
+
autoRepay: (0, format_1.toFiniteNumber)(deal.autoRepay ?? deal.auto_repay, 0) || 0,
|
|
218
252
|
};
|
|
219
253
|
}
|
|
220
254
|
function parseCallOrderSummary(order) {
|
|
@@ -224,9 +258,9 @@ function parseCallOrderSummary(order) {
|
|
|
224
258
|
id: order.id || null,
|
|
225
259
|
borrower: order.borrower || null,
|
|
226
260
|
debtAssetId: order.debtAssetId || order.call_price?.quote?.asset_id || null,
|
|
227
|
-
debtAmount: toFiniteNumber(order.debt?.amount ?? order.debtAmount, 0) || 0,
|
|
261
|
+
debtAmount: (0, format_1.toFiniteNumber)(order.debt?.amount ?? order.debtAmount, 0) || 0,
|
|
228
262
|
collateralAssetId: order.collateralAssetId || order.call_price?.base?.asset_id || null,
|
|
229
|
-
collateralAmount: toFiniteNumber(order.collateral?.amount ?? order.collateralAmount, 0) || 0,
|
|
263
|
+
collateralAmount: (0, format_1.toFiniteNumber)(order.collateral?.amount ?? order.collateralAmount, 0) || 0,
|
|
230
264
|
debt: order.debt || null,
|
|
231
265
|
collateral: order.collateral || null,
|
|
232
266
|
call_price: order.call_price || null,
|
|
@@ -239,11 +273,11 @@ function parseCreditOfferSummary(offer) {
|
|
|
239
273
|
id: offer.id || null,
|
|
240
274
|
ownerAccount: offer.owner_account || offer.ownerAccount || null,
|
|
241
275
|
assetType: offer.asset_type || offer.assetType || null,
|
|
242
|
-
totalBalance: toFiniteNumber(offer.total_balance ?? offer.totalBalance, 0) || 0,
|
|
243
|
-
currentBalance: toFiniteNumber(offer.current_balance ?? offer.currentBalance, 0) || 0,
|
|
244
|
-
feeRate: toFiniteNumber(offer.fee_rate ?? offer.feeRate, 0) || 0,
|
|
245
|
-
maxDurationSeconds: toFiniteNumber(offer.max_duration_seconds ?? offer.maxDurationSeconds, 0) || 0,
|
|
246
|
-
minDealAmount: toFiniteNumber(offer.min_deal_amount ?? offer.minDealAmount, 0) || 0,
|
|
276
|
+
totalBalance: (0, format_1.toFiniteNumber)(offer.total_balance ?? offer.totalBalance, 0) || 0,
|
|
277
|
+
currentBalance: (0, format_1.toFiniteNumber)(offer.current_balance ?? offer.currentBalance, 0) || 0,
|
|
278
|
+
feeRate: (0, format_1.toFiniteNumber)(offer.fee_rate ?? offer.feeRate, 0) || 0,
|
|
279
|
+
maxDurationSeconds: (0, format_1.toFiniteNumber)(offer.max_duration_seconds ?? offer.maxDurationSeconds, 0) || 0,
|
|
280
|
+
minDealAmount: (0, format_1.toFiniteNumber)(offer.min_deal_amount ?? offer.minDealAmount, 0) || 0,
|
|
247
281
|
enabled: !!offer.enabled,
|
|
248
282
|
acceptableCollateral: offer.acceptable_collateral || offer.acceptableCollateral || null,
|
|
249
283
|
};
|
|
@@ -274,9 +308,9 @@ class CreditRuntime {
|
|
|
274
308
|
this.log = typeof this.bot._log === 'function' ? this.bot._log.bind(this.bot) : console.log.bind(console);
|
|
275
309
|
this.warn = typeof this.bot._warn === 'function' ? this.bot._warn.bind(this.bot) : console.warn.bind(console);
|
|
276
310
|
this.botKey = this.config.botKey
|
|
277
|
-
|| createBotKey(this.config, this.config.botIndex ?? 0);
|
|
311
|
+
|| (0, account_orders_1.createBotKey)(this.config, this.config.botIndex ?? 0);
|
|
278
312
|
this.stateDir = this.options.stateDir || DEFAULT_STATE_DIR;
|
|
279
|
-
this.statePath = path.join(this.stateDir, `${this.botKey}.json`);
|
|
313
|
+
this.statePath = path_api_1.path.join(this.stateDir, `${this.botKey}.json`);
|
|
280
314
|
this._assetCache = new Map();
|
|
281
315
|
this._objectCache = new Map();
|
|
282
316
|
this._fullAccountCache = null;
|
|
@@ -369,11 +403,11 @@ class CreditRuntime {
|
|
|
369
403
|
return this.state;
|
|
370
404
|
}
|
|
371
405
|
try {
|
|
372
|
-
const parsed = readJSON(this.statePath);
|
|
406
|
+
const parsed = (0, fs_utils_1.readJSON)(this.statePath);
|
|
373
407
|
this.state = this._stateWithDefaults(parsed);
|
|
374
408
|
}
|
|
375
409
|
catch (err) {
|
|
376
|
-
this.warn(`credit runtime: failed to load ${this.statePath}: ${err
|
|
410
|
+
this.warn(`credit runtime: failed to load ${this.statePath}: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
377
411
|
this.state = this._stateWithDefaults();
|
|
378
412
|
}
|
|
379
413
|
this._loaded = true;
|
|
@@ -387,7 +421,7 @@ class CreditRuntime {
|
|
|
387
421
|
// Atomic write: see writeJsonFileAtomic in bots_file_lock.ts. A plain
|
|
388
422
|
// writeFileSync here could leave a truncated state file on crash and
|
|
389
423
|
// cause the next process startup to lose all credit/MPA tracking.
|
|
390
|
-
writeJsonFileAtomic(this.statePath, this.state);
|
|
424
|
+
(0, bots_file_lock_1.writeJsonFileAtomic)(this.statePath, this.state);
|
|
391
425
|
if (reason) {
|
|
392
426
|
this.log(`credit runtime: persisted ${this.botKey} state (${reason})`);
|
|
393
427
|
}
|
|
@@ -488,7 +522,7 @@ class CreditRuntime {
|
|
|
488
522
|
const quoteAsset = quote.asset_id === debtAsset.id ? debtAsset : backingAsset;
|
|
489
523
|
const baseAmount = blockchainAmountToFloat(base.amount, baseAsset);
|
|
490
524
|
const quoteAmount = blockchainAmountToFloat(quote.amount, quoteAsset);
|
|
491
|
-
if (
|
|
525
|
+
if (baseAmount == null || quoteAmount == null || baseAmount <= 0 || quoteAmount <= 0) {
|
|
492
526
|
return null;
|
|
493
527
|
}
|
|
494
528
|
if (base.asset_id === backingAsset.id && quote.asset_id === debtAsset.id) {
|
|
@@ -563,7 +597,7 @@ class CreditRuntime {
|
|
|
563
597
|
}
|
|
564
598
|
const balances = await chainOrders.getOnChainAssetBalances(accountRef, [asset.id]);
|
|
565
599
|
const balance = balances?.[String(asset.id)] || balances?.[String(asset.symbol)] || null;
|
|
566
|
-
total = toFiniteNumber(balance?.[balanceField],
|
|
600
|
+
total = (0, format_1.toFiniteNumber)(balance?.[balanceField], undefined);
|
|
567
601
|
if (!Number.isFinite(total) || total < 0) {
|
|
568
602
|
throw new Error(`Unable to resolve ${referenceLabel} for ${asset.id}`);
|
|
569
603
|
}
|
|
@@ -572,14 +606,14 @@ class CreditRuntime {
|
|
|
572
606
|
throw new Error(`Unable to resolve account for percentage amount on ${asset.id}`);
|
|
573
607
|
}
|
|
574
608
|
}
|
|
575
|
-
const resolved = resolveConfigValue(normalized.amount, total);
|
|
609
|
+
const resolved = (0, math_1.resolveConfigValue)(normalized.amount, total);
|
|
576
610
|
if (!Number.isFinite(resolved) || resolved <= 0) {
|
|
577
611
|
return null;
|
|
578
612
|
}
|
|
579
|
-
if (isPercent && resolved > total) {
|
|
613
|
+
if (isPercent && total !== null && resolved > total) {
|
|
580
614
|
throw new Error(`Requested amount ${resolved} exceeds available ${balanceField} balance ${total} for ${asset.id}`);
|
|
581
615
|
}
|
|
582
|
-
const intValue = floatToBlockchainInt(resolved, asset.precision);
|
|
616
|
+
const intValue = (0, math_1.floatToBlockchainInt)(resolved, asset.precision);
|
|
583
617
|
if (!Number.isFinite(intValue) || intValue <= 0) {
|
|
584
618
|
return null;
|
|
585
619
|
}
|
|
@@ -631,7 +665,7 @@ class CreditRuntime {
|
|
|
631
665
|
return cachedIsFresh ? cached : null;
|
|
632
666
|
}
|
|
633
667
|
const feedPrice = this._computeBtsPerDebt(bitassetData?.current_feed?.settlement_price, debtAsset, collateralAsset);
|
|
634
|
-
if (Number.isFinite(feedPrice) && feedPrice > 0) {
|
|
668
|
+
if (feedPrice != null && Number.isFinite(feedPrice) && feedPrice > 0) {
|
|
635
669
|
if (!this.state.positions[posKey])
|
|
636
670
|
this.state.positions[posKey] = {};
|
|
637
671
|
this.state.positions[posKey].mpaFeedPrice = feedPrice;
|
|
@@ -677,6 +711,27 @@ class CreditRuntime {
|
|
|
677
711
|
offerIds.add(String(id));
|
|
678
712
|
}
|
|
679
713
|
if (offerIds.size === 0) {
|
|
714
|
+
// Fallback: scan owned credit offers for pricing when no deal-based
|
|
715
|
+
// or allowed offer IDs are configured.
|
|
716
|
+
const ownedOffers = Array.isArray(this.state.ownedCreditOffers) ? this.state.ownedCreditOffers : [];
|
|
717
|
+
if (ownedOffers.length > 0 && debtAssetId && collateralAssetId) {
|
|
718
|
+
const debtAsset = await this._resolveAsset(debtAssetId);
|
|
719
|
+
const collateralAsset = await this._resolveAsset(collateralAssetId);
|
|
720
|
+
if (debtAsset && collateralAsset) {
|
|
721
|
+
const match = ownedOffers.find((o) => String(o.assetType) === String(debtAssetId) && o.enabled !== false);
|
|
722
|
+
if (match) {
|
|
723
|
+
const collateralMap = normalizeCollateralMap(match.acceptableCollateral);
|
|
724
|
+
const rate = this._extractRateFromCollateralMap(collateralMap, String(collateralAssetId), debtAsset, collateralAsset);
|
|
725
|
+
if (rate !== null) {
|
|
726
|
+
if (!this.state.positions[posKey])
|
|
727
|
+
this.state.positions[posKey] = {};
|
|
728
|
+
this.state.positions[posKey].creditConversionRate = rate;
|
|
729
|
+
this.state.positions[posKey].creditConversionRateAt = Date.now();
|
|
730
|
+
return options.includeSource ? { price: rate, source: 'owned-offer' } : rate;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
680
735
|
if (options.includeSource) {
|
|
681
736
|
return cachedIsFresh
|
|
682
737
|
? { price: cached, source: 'cached-offer' }
|
|
@@ -702,18 +757,8 @@ class CreditRuntime {
|
|
|
702
757
|
if (offer.enabled === false)
|
|
703
758
|
continue;
|
|
704
759
|
const collateralMap = normalizeCollateralMap(offer?.acceptable_collateral);
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
707
|
-
continue;
|
|
708
|
-
const orientation = this._creditPriceOrientation(price, debtAsset, collateralAsset);
|
|
709
|
-
const baseAmount = blockchainAmountToFloat(price?.base, orientation === 'legacy-reversed' ? collateralAsset : debtAsset);
|
|
710
|
-
const quoteAmount = blockchainAmountToFloat(price?.quote, orientation === 'legacy-reversed' ? debtAsset : collateralAsset);
|
|
711
|
-
if (!Number.isFinite(baseAmount) || !Number.isFinite(quoteAmount) || baseAmount <= 0)
|
|
712
|
-
continue;
|
|
713
|
-
const rate = orientation === 'legacy-reversed'
|
|
714
|
-
? quoteAmount / baseAmount
|
|
715
|
-
: baseAmount / quoteAmount;
|
|
716
|
-
if (!Number.isFinite(rate) || rate <= 0)
|
|
760
|
+
const rate = this._extractRateFromCollateralMap(collateralMap, String(collateralAssetId), debtAsset, collateralAsset);
|
|
761
|
+
if (rate === null)
|
|
717
762
|
continue;
|
|
718
763
|
if (!this.state.positions[posKey])
|
|
719
764
|
this.state.positions[posKey] = {};
|
|
@@ -752,7 +797,7 @@ class CreditRuntime {
|
|
|
752
797
|
if (!collateralAsset)
|
|
753
798
|
continue;
|
|
754
799
|
const totalCollateralAvailable = await this._getCollateralPercentageBase(accountRef, collateralAsset.id);
|
|
755
|
-
const totalMaxCollateral = resolveConfigValue(dp.maxCollateralAmount ?? '100%', totalCollateralAvailable);
|
|
800
|
+
const totalMaxCollateral = (0, math_1.resolveConfigValue)(dp.maxCollateralAmount ?? '100%', totalCollateralAvailable);
|
|
756
801
|
const C_total = Math.min(totalCollateralAvailable, totalMaxCollateral);
|
|
757
802
|
let groupHasNoUsablePrice = false;
|
|
758
803
|
const weightEntries = await Promise.all(items.map(async (item) => {
|
|
@@ -762,7 +807,7 @@ class CreditRuntime {
|
|
|
762
807
|
let targetCr = 1.0;
|
|
763
808
|
let weight = 0;
|
|
764
809
|
if (item.type === 'mpa') {
|
|
765
|
-
targetCr = resolveTargetCollateralRatio(item) ?? DEFAULT_TARGET_CR;
|
|
810
|
+
targetCr = (0, cr_planner_1.resolveTargetCollateralRatio)(item) ?? constants_1.DEFAULT_TARGET_CR;
|
|
766
811
|
const resolvedFeedPrice = assetId
|
|
767
812
|
? normalizeResolvedPriceResult(await this._resolveMpaFeedPrice(assetId, collateralAsset.id, { includeSource: true }), 'live-feed', 'missing-feed')
|
|
768
813
|
: { price: null, source: 'missing-feed' };
|
|
@@ -780,7 +825,7 @@ class CreditRuntime {
|
|
|
780
825
|
}
|
|
781
826
|
}
|
|
782
827
|
else if (item.type === 'creditOffer') {
|
|
783
|
-
targetCr = toFiniteNumber(item.maxCollateralRatio, 2.0);
|
|
828
|
+
targetCr = (0, format_1.toFiniteNumber)(item.maxCollateralRatio, 2.0);
|
|
784
829
|
const resolvedConversionRate = assetId
|
|
785
830
|
? normalizeResolvedPriceResult(await this._resolveCreditConversionRate(item, assetId, collateralAsset.id, { includeSource: true }), 'live-offer', 'missing-offer')
|
|
786
831
|
: { price: null, source: 'missing-offer' };
|
|
@@ -845,9 +890,25 @@ class CreditRuntime {
|
|
|
845
890
|
return 'legacy-reversed';
|
|
846
891
|
return 'core';
|
|
847
892
|
}
|
|
893
|
+
_extractRateFromCollateralMap(collateralMap, collateralAssetId, debtAsset, collateralAsset) {
|
|
894
|
+
const price = collateralMap.get(collateralAssetId);
|
|
895
|
+
if (!price)
|
|
896
|
+
return null;
|
|
897
|
+
const orientation = this._creditPriceOrientation(price, debtAsset, collateralAsset);
|
|
898
|
+
const baseAmount = blockchainAmountToFloat(price?.base, orientation === 'legacy-reversed' ? collateralAsset : debtAsset);
|
|
899
|
+
const quoteAmount = blockchainAmountToFloat(price?.quote, orientation === 'legacy-reversed' ? debtAsset : collateralAsset);
|
|
900
|
+
if (baseAmount == null || quoteAmount == null || baseAmount <= 0)
|
|
901
|
+
return null;
|
|
902
|
+
const rate = orientation === 'legacy-reversed'
|
|
903
|
+
? quoteAmount / baseAmount
|
|
904
|
+
: baseAmount / quoteAmount;
|
|
905
|
+
if (!Number.isFinite(rate) || rate <= 0)
|
|
906
|
+
return null;
|
|
907
|
+
return rate;
|
|
908
|
+
}
|
|
848
909
|
_calculateBorrowAmountFromCollateral(collateralAmountInt, collateralPrice, debtAsset = null, collateralAsset = null) {
|
|
849
|
-
const baseAmount = toFiniteNumber(collateralPrice?.base?.amount,
|
|
850
|
-
const quoteAmount = toFiniteNumber(collateralPrice?.quote?.amount,
|
|
910
|
+
const baseAmount = (0, format_1.toFiniteNumber)(collateralPrice?.base?.amount, undefined);
|
|
911
|
+
const quoteAmount = (0, format_1.toFiniteNumber)(collateralPrice?.quote?.amount, undefined);
|
|
851
912
|
if (!Number.isFinite(baseAmount) || !Number.isFinite(quoteAmount) || baseAmount <= 0 || quoteAmount <= 0) {
|
|
852
913
|
return null;
|
|
853
914
|
}
|
|
@@ -860,7 +921,7 @@ class CreditRuntime {
|
|
|
860
921
|
const maxBorrowAmountValue = positiveOrNull(policy?.maxBorrowAmount);
|
|
861
922
|
if (maxBorrowAmountValue === null)
|
|
862
923
|
return;
|
|
863
|
-
const borrowFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
924
|
+
const borrowFloat = (0, math_1.blockchainToFloat)(borrowInt, debtAsset.precision);
|
|
864
925
|
if (!Number.isFinite(borrowFloat))
|
|
865
926
|
return;
|
|
866
927
|
const currentTotal = this._getCreditDebtForAsset(debtAsset);
|
|
@@ -901,7 +962,7 @@ class CreditRuntime {
|
|
|
901
962
|
this._fetchBorrowerDeals().catch(() => []),
|
|
902
963
|
]);
|
|
903
964
|
const balance = balances?.[String(assetId)] || balances?.[String(asset.symbol)] || null;
|
|
904
|
-
const onChainTotal = toFiniteNumber(balance?.total,
|
|
965
|
+
const onChainTotal = (0, format_1.toFiniteNumber)(balance?.total, undefined);
|
|
905
966
|
if (!Number.isFinite(onChainTotal)) {
|
|
906
967
|
return null;
|
|
907
968
|
}
|
|
@@ -942,11 +1003,11 @@ class CreditRuntime {
|
|
|
942
1003
|
if (!Number.isFinite(referenceAmount)) {
|
|
943
1004
|
throw new Error(`Unable to resolve collateral percentage base for ${collateralAsset.id}`);
|
|
944
1005
|
}
|
|
945
|
-
limitFloat = resolveConfigValue(maxCollateralAmountValue, referenceAmount);
|
|
1006
|
+
limitFloat = (0, math_1.resolveConfigValue)(maxCollateralAmountValue, referenceAmount);
|
|
946
1007
|
}
|
|
947
1008
|
if (!Number.isFinite(limitFloat) || limitFloat < 0)
|
|
948
1009
|
return;
|
|
949
|
-
const collateralFloat = blockchainToFloat(collateralInt, collateralAsset.precision);
|
|
1010
|
+
const collateralFloat = (0, math_1.blockchainToFloat)(collateralInt, collateralAsset.precision);
|
|
950
1011
|
if (!Number.isFinite(collateralFloat))
|
|
951
1012
|
return;
|
|
952
1013
|
const currentTotal = this._getCreditCollateralForAsset(collateralAsset);
|
|
@@ -956,17 +1017,17 @@ class CreditRuntime {
|
|
|
956
1017
|
}
|
|
957
1018
|
}
|
|
958
1019
|
_calculateDailyFeeRate(offer) {
|
|
959
|
-
const feeRate = toFiniteNumber(offer?.fee_rate, 0) || 0;
|
|
960
|
-
const maxDurationSeconds = toFiniteNumber(offer?.max_duration_seconds, 0) || 0;
|
|
1020
|
+
const feeRate = (0, format_1.toFiniteNumber)(offer?.fee_rate, 0) || 0;
|
|
1021
|
+
const maxDurationSeconds = (0, format_1.toFiniteNumber)(offer?.max_duration_seconds, 0) || 0;
|
|
961
1022
|
if (feeRate <= 0 || maxDurationSeconds <= 0)
|
|
962
1023
|
return 0;
|
|
963
|
-
const feeRateDenom = this.bot?.config?.feeParams?.GRAPHENE_FEE_RATE_DENOM ?? FEE_PARAMETERS.GRAPHENE_FEE_RATE_DENOM;
|
|
1024
|
+
const feeRateDenom = this.bot?.config?.feeParams?.GRAPHENE_FEE_RATE_DENOM ?? constants_1.FEE_PARAMETERS.GRAPHENE_FEE_RATE_DENOM;
|
|
964
1025
|
const flatFeePercent = feeRate / feeRateDenom;
|
|
965
1026
|
const durationDays = maxDurationSeconds / 86400;
|
|
966
1027
|
return flatFeePercent / durationDays;
|
|
967
1028
|
}
|
|
968
1029
|
_getDefaultMaxFeeRatePerDay() {
|
|
969
|
-
return this.bot?.config?.feeParams?.DEFAULT_MAX_FEE_RATE_PER_DAY ?? FEE_PARAMETERS.DEFAULT_MAX_FEE_RATE_PER_DAY;
|
|
1030
|
+
return this.bot?.config?.feeParams?.DEFAULT_MAX_FEE_RATE_PER_DAY ?? constants_1.FEE_PARAMETERS.DEFAULT_MAX_FEE_RATE_PER_DAY;
|
|
970
1031
|
}
|
|
971
1032
|
_validateCreditPolicy(policy, offer, deal = null) {
|
|
972
1033
|
if (!policy || typeof policy !== 'object')
|
|
@@ -1000,13 +1061,13 @@ class CreditRuntime {
|
|
|
1000
1061
|
return { allow: true, reason: null };
|
|
1001
1062
|
}
|
|
1002
1063
|
async _calculateCollateralValueInDebtAsset(collateralAmountInt, collateralAsset, debtAsset, collateralPrice) {
|
|
1003
|
-
const collateralAmountFloat = blockchainToFloat(collateralAmountInt, collateralAsset.precision);
|
|
1064
|
+
const collateralAmountFloat = (0, math_1.blockchainToFloat)(collateralAmountInt, collateralAsset.precision);
|
|
1004
1065
|
if (!Number.isFinite(collateralAmountFloat) || collateralAmountFloat <= 0) {
|
|
1005
1066
|
return null;
|
|
1006
1067
|
}
|
|
1007
1068
|
if (collateralAsset?.for_liquidity_pool) {
|
|
1008
1069
|
const valuePerShare = await deriveLiquidityPoolTokenValue(BitShares, collateralAsset.id, debtAsset.id);
|
|
1009
|
-
if (!Number.isFinite(valuePerShare) || valuePerShare <= 0) {
|
|
1070
|
+
if (valuePerShare == null || !Number.isFinite(valuePerShare) || valuePerShare <= 0) {
|
|
1010
1071
|
return null;
|
|
1011
1072
|
}
|
|
1012
1073
|
return collateralAmountFloat * valuePerShare;
|
|
@@ -1014,7 +1075,7 @@ class CreditRuntime {
|
|
|
1014
1075
|
const orientation = this._creditPriceOrientation(collateralPrice, debtAsset, collateralAsset);
|
|
1015
1076
|
const baseAmountFloat = blockchainAmountToFloat(collateralPrice?.base, orientation === 'legacy-reversed' ? collateralAsset : debtAsset);
|
|
1016
1077
|
const quoteAmountFloat = blockchainAmountToFloat(collateralPrice?.quote, orientation === 'legacy-reversed' ? debtAsset : collateralAsset);
|
|
1017
|
-
if (
|
|
1078
|
+
if (baseAmountFloat == null || quoteAmountFloat == null || baseAmountFloat <= 0 || quoteAmountFloat <= 0) {
|
|
1018
1079
|
return null;
|
|
1019
1080
|
}
|
|
1020
1081
|
if (orientation === 'legacy-reversed') {
|
|
@@ -1023,14 +1084,14 @@ class CreditRuntime {
|
|
|
1023
1084
|
return (collateralAmountFloat * baseAmountFloat) / quoteAmountFloat;
|
|
1024
1085
|
}
|
|
1025
1086
|
_calculateCreditOfferCollateralValueInDebtAsset(collateralAmountInt, collateralAsset, debtAsset, collateralPrice) {
|
|
1026
|
-
const collateralAmountFloat = blockchainToFloat(collateralAmountInt, collateralAsset.precision);
|
|
1087
|
+
const collateralAmountFloat = (0, math_1.blockchainToFloat)(collateralAmountInt, collateralAsset.precision);
|
|
1027
1088
|
if (!Number.isFinite(collateralAmountFloat) || collateralAmountFloat <= 0) {
|
|
1028
1089
|
return null;
|
|
1029
1090
|
}
|
|
1030
1091
|
const orientation = this._creditPriceOrientation(collateralPrice, debtAsset, collateralAsset);
|
|
1031
1092
|
const baseAmountFloat = blockchainAmountToFloat(collateralPrice?.base, orientation === 'legacy-reversed' ? collateralAsset : debtAsset);
|
|
1032
1093
|
const quoteAmountFloat = blockchainAmountToFloat(collateralPrice?.quote, orientation === 'legacy-reversed' ? debtAsset : collateralAsset);
|
|
1033
|
-
if (
|
|
1094
|
+
if (baseAmountFloat == null || quoteAmountFloat == null || baseAmountFloat <= 0 || quoteAmountFloat <= 0) {
|
|
1034
1095
|
return null;
|
|
1035
1096
|
}
|
|
1036
1097
|
if (orientation === 'legacy-reversed') {
|
|
@@ -1140,7 +1201,7 @@ class CreditRuntime {
|
|
|
1140
1201
|
currentCollateralFundsTotal: null,
|
|
1141
1202
|
currentCollateralRatio: null,
|
|
1142
1203
|
feedPrice: null,
|
|
1143
|
-
targetCollateralRatio: resolveTargetCollateralRatio(lendingItem),
|
|
1204
|
+
targetCollateralRatio: (0, cr_planner_1.resolveTargetCollateralRatio)(lendingItem),
|
|
1144
1205
|
minCollateralRatio: positiveOrNull(lendingItem.minCollateralRatio),
|
|
1145
1206
|
maxCollateralRatio: positiveOrNull(lendingItem.maxCollateralRatio),
|
|
1146
1207
|
};
|
|
@@ -1168,7 +1229,7 @@ class CreditRuntime {
|
|
|
1168
1229
|
const collateralAmount = blockchainAmountToFloat(callOrder?.collateral, collateralAsset) || 0;
|
|
1169
1230
|
const collateralBalances = callOrderCollateralAssetId ? await chainOrders.getOnChainAssetBalances(accountRef, [callOrderCollateralAssetId]) : {};
|
|
1170
1231
|
const collateralBalance = callOrderCollateralAssetId ? (collateralBalances?.[String(callOrderCollateralAssetId)] || collateralBalances?.[String(collateralAsset?.symbol)] || null) : null;
|
|
1171
|
-
let currentCollateralFundsTotal = toFiniteNumber(collateralBalance?.total,
|
|
1232
|
+
let currentCollateralFundsTotal = (0, format_1.toFiniteNumber)(collateralBalance?.total, undefined);
|
|
1172
1233
|
// Apply registry proportional split for shared-account credit bots
|
|
1173
1234
|
if (currentCollateralFundsTotal !== null && callOrderCollateralAssetId) {
|
|
1174
1235
|
const accountName = getAccountName(this.bot);
|
|
@@ -1180,12 +1241,12 @@ class CreditRuntime {
|
|
|
1180
1241
|
}
|
|
1181
1242
|
}
|
|
1182
1243
|
const feedPrice = this._computeBtsPerDebt(bitassetData?.current_feed?.settlement_price, debtAsset, collateralAsset);
|
|
1183
|
-
if (Number.isFinite(feedPrice) && feedPrice > 0) {
|
|
1244
|
+
if (feedPrice != null && Number.isFinite(feedPrice) && feedPrice > 0) {
|
|
1184
1245
|
if (!this.state.positions[posKey])
|
|
1185
1246
|
this.state.positions[posKey] = {};
|
|
1186
1247
|
this.state.positions[posKey].mpaFeedPrice = feedPrice;
|
|
1187
1248
|
}
|
|
1188
|
-
const currentCollateralRatio = debtAmount > 0 && feedPrice > 0
|
|
1249
|
+
const currentCollateralRatio = debtAmount > 0 && feedPrice != null && feedPrice > 0
|
|
1189
1250
|
? collateralAmount / (debtAmount * feedPrice)
|
|
1190
1251
|
: null;
|
|
1191
1252
|
const posState = {
|
|
@@ -1197,7 +1258,7 @@ class CreditRuntime {
|
|
|
1197
1258
|
currentCollateralFundsTotal,
|
|
1198
1259
|
currentCollateralRatio,
|
|
1199
1260
|
feedPrice,
|
|
1200
|
-
targetCollateralRatio: resolveTargetCollateralRatio(lendingItem),
|
|
1261
|
+
targetCollateralRatio: (0, cr_planner_1.resolveTargetCollateralRatio)(lendingItem),
|
|
1201
1262
|
minCollateralRatio: positiveOrNull(lendingItem.minCollateralRatio),
|
|
1202
1263
|
maxCollateralRatio: positiveOrNull(lendingItem.maxCollateralRatio),
|
|
1203
1264
|
mpaSelectionConflict: null,
|
|
@@ -1243,32 +1304,44 @@ class CreditRuntime {
|
|
|
1243
1304
|
// This is a price for the debt+collateral asset pair, not for a specific offer id.
|
|
1244
1305
|
// In practice, offers for the same pair should expose interchangeable acceptable-collateral pricing.
|
|
1245
1306
|
if (expectedCollateralId) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
if (!this.state.positions[posKey])
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1307
|
+
const debtAssetResolved = await this._resolveAsset(assetId);
|
|
1308
|
+
const collateralAssetResolved = await this._resolveAsset(expectedCollateralId);
|
|
1309
|
+
if (debtAssetResolved && collateralAssetResolved) {
|
|
1310
|
+
for (const offer of trackedOffers.values()) {
|
|
1311
|
+
if (String(offer?.asset_type) !== assetId)
|
|
1312
|
+
continue;
|
|
1313
|
+
if (offer?.enabled === false)
|
|
1314
|
+
continue;
|
|
1315
|
+
const collateralMap = normalizeCollateralMap(offer?.acceptable_collateral);
|
|
1316
|
+
const rate = this._extractRateFromCollateralMap(collateralMap, expectedCollateralId, debtAssetResolved, collateralAssetResolved);
|
|
1317
|
+
if (rate === null)
|
|
1318
|
+
continue;
|
|
1319
|
+
if (!this.state.positions[posKey])
|
|
1320
|
+
this.state.positions[posKey] = {};
|
|
1321
|
+
this.state.positions[posKey].creditConversionRate = rate;
|
|
1322
|
+
this.state.positions[posKey].creditConversionRateAt = Date.now();
|
|
1323
|
+
break;
|
|
1324
|
+
}
|
|
1325
|
+
// Fallback: cache conversion rate from owned credit offers.
|
|
1326
|
+
// This ensures pricing is available even when there are no active
|
|
1327
|
+
// borrowing deals and allowedOfferIds is empty.
|
|
1328
|
+
if (!this.state.positions[posKey]?.creditConversionRate) {
|
|
1329
|
+
for (const offer of ownedCreditOffers) {
|
|
1330
|
+
if (String(offer.assetType) !== assetId)
|
|
1331
|
+
continue;
|
|
1332
|
+
if (offer.enabled === false)
|
|
1333
|
+
continue;
|
|
1334
|
+
const collateralMap = normalizeCollateralMap(offer.acceptableCollateral);
|
|
1335
|
+
const rate = this._extractRateFromCollateralMap(collateralMap, expectedCollateralId, debtAssetResolved, collateralAssetResolved);
|
|
1336
|
+
if (rate === null)
|
|
1337
|
+
continue;
|
|
1338
|
+
if (!this.state.positions[posKey])
|
|
1339
|
+
this.state.positions[posKey] = {};
|
|
1340
|
+
this.state.positions[posKey].creditConversionRate = rate;
|
|
1341
|
+
this.state.positions[posKey].creditConversionRateAt = Date.now();
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1272
1345
|
}
|
|
1273
1346
|
}
|
|
1274
1347
|
const activeDeals = [];
|
|
@@ -1294,8 +1367,8 @@ class CreditRuntime {
|
|
|
1294
1367
|
activeDeals.push({
|
|
1295
1368
|
...deal,
|
|
1296
1369
|
offerEnabled: !!offer?.enabled,
|
|
1297
|
-
offerFeeRate: toFiniteNumber(offer?.fee_rate, deal.feeRate) || deal.feeRate,
|
|
1298
|
-
offerMaxDurationSeconds: toFiniteNumber(offer?.max_duration_seconds,
|
|
1370
|
+
offerFeeRate: (0, format_1.toFiniteNumber)(offer?.fee_rate, deal.feeRate) || deal.feeRate,
|
|
1371
|
+
offerMaxDurationSeconds: (0, format_1.toFiniteNumber)(offer?.max_duration_seconds, undefined),
|
|
1299
1372
|
canReborrow: !!offer?.enabled,
|
|
1300
1373
|
});
|
|
1301
1374
|
}
|
|
@@ -1355,7 +1428,7 @@ class CreditRuntime {
|
|
|
1355
1428
|
if (posState.mpaSelectionConflict) {
|
|
1356
1429
|
return { blocked: true, reason: posState.mpaSelectionConflict };
|
|
1357
1430
|
}
|
|
1358
|
-
const plan = buildDebtFirstCrPlan({
|
|
1431
|
+
const plan = (0, cr_planner_1.buildDebtFirstCrPlan)({
|
|
1359
1432
|
currentCollateralAmount: posState.currentCollateralAmount,
|
|
1360
1433
|
currentDebtAmount: posState.currentDebtAmount,
|
|
1361
1434
|
feedPrice: posState.feedPrice,
|
|
@@ -1409,8 +1482,8 @@ class CreditRuntime {
|
|
|
1409
1482
|
}
|
|
1410
1483
|
const debtDelta = leg === 'collateral' ? 0 : plan.debtDelta;
|
|
1411
1484
|
const collateralDelta = leg === 'debt' ? 0 : plan.collateralDelta;
|
|
1412
|
-
const debtInt = floatToBlockchainInt(debtDelta, debtAsset.precision);
|
|
1413
|
-
const collateralInt = floatToBlockchainInt(collateralDelta, callOrderCollateralAsset.precision);
|
|
1485
|
+
const debtInt = (0, math_1.floatToBlockchainInt)(debtDelta, debtAsset.precision);
|
|
1486
|
+
const collateralInt = (0, math_1.floatToBlockchainInt)(collateralDelta, callOrderCollateralAsset.precision);
|
|
1414
1487
|
if (debtInt === 0 && collateralInt === 0) {
|
|
1415
1488
|
return null;
|
|
1416
1489
|
}
|
|
@@ -1510,7 +1583,7 @@ class CreditRuntime {
|
|
|
1510
1583
|
throw new Error('borrowAmount must be positive');
|
|
1511
1584
|
}
|
|
1512
1585
|
if (requestedBorrowAmount !== null) {
|
|
1513
|
-
borrowInt = floatToBlockchainInt(requestedBorrowAmount, debtAsset.precision);
|
|
1586
|
+
borrowInt = (0, math_1.floatToBlockchainInt)(requestedBorrowAmount, debtAsset.precision);
|
|
1514
1587
|
if (!Number.isFinite(borrowInt) || borrowInt <= 0) {
|
|
1515
1588
|
throw new Error('borrowAmount must be positive');
|
|
1516
1589
|
}
|
|
@@ -1522,7 +1595,7 @@ class CreditRuntime {
|
|
|
1522
1595
|
requiredCollateralInt = collateralSpec?.amount !== null && collateralSpec?.amount !== undefined
|
|
1523
1596
|
? await this._resolveAmountToBlockchainInt(collateralSpec, collateralAsset, accountId, { balanceField: 'total', referenceAmount: collateralReferenceAmount, referenceLabel: 'total collateral balance' })
|
|
1524
1597
|
: minimumCollateralInt;
|
|
1525
|
-
if (
|
|
1598
|
+
if (minimumCollateralInt != null && requiredCollateralInt != null && requiredCollateralInt < minimumCollateralInt) {
|
|
1526
1599
|
throw new Error(`collateral amount ${requiredCollateralInt} is below required collateral ${minimumCollateralInt}`);
|
|
1527
1600
|
}
|
|
1528
1601
|
}
|
|
@@ -1532,28 +1605,28 @@ class CreditRuntime {
|
|
|
1532
1605
|
: null;
|
|
1533
1606
|
requiredCollateralInt = await this._resolveAmountToBlockchainInt(collateralSpec, collateralAsset, accountId, { balanceField: 'total', referenceAmount: collateralReferenceAmount, referenceLabel: 'total collateral balance' });
|
|
1534
1607
|
borrowInt = this._calculateBorrowAmountFromCollateral(requiredCollateralInt, collateralPrice, debtAsset, collateralAsset);
|
|
1535
|
-
if (Number.isFinite(borrowInt) && borrowInt > 0) {
|
|
1608
|
+
if (borrowInt != null && Number.isFinite(borrowInt) && borrowInt > 0) {
|
|
1536
1609
|
this._enforceMaxBorrowAmount(policy, borrowInt, debtAsset, { pendingRepayAmount });
|
|
1537
1610
|
}
|
|
1538
1611
|
}
|
|
1539
1612
|
// Enforce per-operation borrow limit
|
|
1540
1613
|
const maxPerOp = positiveOrNull(policy?.maxBorrowAmountPerOperation);
|
|
1541
|
-
if (maxPerOp !== null &&
|
|
1542
|
-
const borrowFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
1614
|
+
if (maxPerOp !== null && borrowInt != null && borrowInt > 0) {
|
|
1615
|
+
const borrowFloat = (0, math_1.blockchainToFloat)(borrowInt, debtAsset.precision);
|
|
1543
1616
|
if (Number.isFinite(borrowFloat) && borrowFloat > maxPerOp) {
|
|
1544
1617
|
throw new Error(`borrowAmount ${borrowFloat} exceeds maxBorrowAmountPerOperation ${maxPerOp}`);
|
|
1545
1618
|
}
|
|
1546
1619
|
}
|
|
1547
|
-
if (
|
|
1620
|
+
if (requiredCollateralInt == null || requiredCollateralInt <= 0) {
|
|
1548
1621
|
throw new Error('Unable to determine collateral amount for credit offer');
|
|
1549
1622
|
}
|
|
1550
|
-
if (
|
|
1623
|
+
if (borrowInt == null || borrowInt <= 0) {
|
|
1551
1624
|
throw new Error('Unable to determine borrow amount from collateral amount');
|
|
1552
1625
|
}
|
|
1553
1626
|
await this._enforceMaxCollateralAmount(policy, requiredCollateralInt, collateralAsset, accountId, {
|
|
1554
1627
|
pendingReleaseCollateralAmount,
|
|
1555
1628
|
});
|
|
1556
|
-
const minDealAmount = toFiniteNumber(offerObj?.min_deal_amount,
|
|
1629
|
+
const minDealAmount = (0, format_1.toFiniteNumber)(offerObj?.min_deal_amount, undefined);
|
|
1557
1630
|
if (minDealAmount !== null && borrowInt < minDealAmount) {
|
|
1558
1631
|
throw new Error(`borrowAmount ${borrowInt} is below min_deal_amount ${minDealAmount}`);
|
|
1559
1632
|
}
|
|
@@ -1562,7 +1635,7 @@ class CreditRuntime {
|
|
|
1562
1635
|
if (dailyRate > maxFeeRatePerDayValue) {
|
|
1563
1636
|
throw new Error(`offer daily fee rate ${dailyRate.toFixed(6)} exceeds maxFeeRatePerDay ${maxFeeRatePerDayValue}`);
|
|
1564
1637
|
}
|
|
1565
|
-
const offerFeeRate = toFiniteNumber(offerObj?.fee_rate, 0) || 0;
|
|
1638
|
+
const offerFeeRate = (0, format_1.toFiniteNumber)(offerObj?.fee_rate, 0) || 0;
|
|
1566
1639
|
if (offerObj?.enabled === false) {
|
|
1567
1640
|
throw new Error(`credit offer ${offerId} is disabled`);
|
|
1568
1641
|
}
|
|
@@ -1579,10 +1652,10 @@ class CreditRuntime {
|
|
|
1579
1652
|
if (maxCollateralRatioValue === null) {
|
|
1580
1653
|
throw new Error('creditOffer maxCollateralRatio is required');
|
|
1581
1654
|
}
|
|
1582
|
-
const borrowAmountFloat = blockchainToFloat(borrowInt, debtAsset.precision);
|
|
1655
|
+
const borrowAmountFloat = (0, math_1.blockchainToFloat)(borrowInt, debtAsset.precision);
|
|
1583
1656
|
const collateralValueInDebtAsset = await this._calculateCollateralValueInDebtAsset(requiredCollateralInt, collateralAsset, debtAsset, collateralPrice);
|
|
1584
1657
|
const offerCollateralValueInDebtAsset = this._calculateCreditOfferCollateralValueInDebtAsset(requiredCollateralInt, collateralAsset, debtAsset, collateralPrice);
|
|
1585
|
-
if (
|
|
1658
|
+
if (collateralValueInDebtAsset == null || offerCollateralValueInDebtAsset == null || borrowAmountFloat <= 0 || collateralValueInDebtAsset <= 0 || offerCollateralValueInDebtAsset <= 0) {
|
|
1586
1659
|
throw new Error(collateralAsset?.for_liquidity_pool
|
|
1587
1660
|
? 'Unable to value liquidity pool collateral for credit offer'
|
|
1588
1661
|
: 'Unable to determine collateral value for credit offer');
|
|
@@ -1621,8 +1694,8 @@ class CreditRuntime {
|
|
|
1621
1694
|
return op;
|
|
1622
1695
|
}
|
|
1623
1696
|
_calculateRequiredCollateral(borrowAmountInt, collateralPrice, debtAsset = null, collateralAsset = null) {
|
|
1624
|
-
const baseAmount = toFiniteNumber(collateralPrice?.base?.amount,
|
|
1625
|
-
const quoteAmount = toFiniteNumber(collateralPrice?.quote?.amount,
|
|
1697
|
+
const baseAmount = (0, format_1.toFiniteNumber)(collateralPrice?.base?.amount, undefined);
|
|
1698
|
+
const quoteAmount = (0, format_1.toFiniteNumber)(collateralPrice?.quote?.amount, undefined);
|
|
1626
1699
|
if (!Number.isFinite(baseAmount) || !Number.isFinite(quoteAmount) || baseAmount <= 0 || quoteAmount <= 0) {
|
|
1627
1700
|
return null;
|
|
1628
1701
|
}
|
|
@@ -1652,7 +1725,7 @@ class CreditRuntime {
|
|
|
1652
1725
|
if (!debtAsset) {
|
|
1653
1726
|
throw new Error('Unable to resolve debt asset metadata for credit repay');
|
|
1654
1727
|
}
|
|
1655
|
-
const repayInt = floatToBlockchainInt(repayAmount, debtAsset.precision);
|
|
1728
|
+
const repayInt = (0, math_1.floatToBlockchainInt)(repayAmount, debtAsset.precision);
|
|
1656
1729
|
if (!Number.isFinite(repayInt) || repayInt <= 0) {
|
|
1657
1730
|
throw new Error('repayAmount must be positive');
|
|
1658
1731
|
}
|
|
@@ -1730,11 +1803,11 @@ class CreditRuntime {
|
|
|
1730
1803
|
return await lock.acquire(runCheck);
|
|
1731
1804
|
}
|
|
1732
1805
|
catch (err) {
|
|
1733
|
-
this.warn(`credit runtime: post-credit grid maintenance failed during ${context}: ${err
|
|
1734
|
-
return { skipped: false, error: err
|
|
1806
|
+
this.warn(`credit runtime: post-credit grid maintenance failed during ${context}: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
1807
|
+
return { skipped: false, error: (0, errors_1.getErrorMessage)(err) };
|
|
1735
1808
|
}
|
|
1736
1809
|
}
|
|
1737
|
-
async openCreditPosition({ offer, borrowAmount, collateralAmount, autoRepay = false, reason = 'credit borrow' }) {
|
|
1810
|
+
async openCreditPosition({ offer, borrowAmount, collateralAmount, autoRepay = false, reason = 'credit borrow' } = {}) {
|
|
1738
1811
|
const offerObj = typeof offer === 'object' ? offer : await this._getOfferById(offer);
|
|
1739
1812
|
let resolvedCollateral = collateralAmount;
|
|
1740
1813
|
if (resolvedCollateral !== null && resolvedCollateral !== undefined && offerObj) {
|
|
@@ -1843,7 +1916,7 @@ class CreditRuntime {
|
|
|
1843
1916
|
excludeOfferId: dealSummary.offerId,
|
|
1844
1917
|
});
|
|
1845
1918
|
if (fallback) {
|
|
1846
|
-
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected after original offer ${dealSummary.offerId} failed: ${err
|
|
1919
|
+
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected after original offer ${dealSummary.offerId} failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
1847
1920
|
operations.push(fallback.op);
|
|
1848
1921
|
inlineReborrowPlanned = true;
|
|
1849
1922
|
}
|
|
@@ -1858,7 +1931,7 @@ class CreditRuntime {
|
|
|
1858
1931
|
pendingRepayAmount: repayAmount,
|
|
1859
1932
|
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1860
1933
|
requestedAt: new Date().toISOString(),
|
|
1861
|
-
reason: err
|
|
1934
|
+
reason: (0, errors_1.getErrorMessage)(err),
|
|
1862
1935
|
};
|
|
1863
1936
|
}
|
|
1864
1937
|
}
|
|
@@ -1938,7 +2011,7 @@ class CreditRuntime {
|
|
|
1938
2011
|
catch (err) {
|
|
1939
2012
|
this.queueReborrow({
|
|
1940
2013
|
...reborrowRequest,
|
|
1941
|
-
reason: err
|
|
2014
|
+
reason: (0, errors_1.getErrorMessage)(err),
|
|
1942
2015
|
});
|
|
1943
2016
|
}
|
|
1944
2017
|
}
|
|
@@ -2040,7 +2113,7 @@ class CreditRuntime {
|
|
|
2040
2113
|
return offers;
|
|
2041
2114
|
}
|
|
2042
2115
|
catch (err) {
|
|
2043
|
-
this.warn(`credit runtime: unable to fetch fallback credit offers for ${assetId}: ${err
|
|
2116
|
+
this.warn(`credit runtime: unable to fetch fallback credit offers for ${assetId}: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2044
2117
|
return [];
|
|
2045
2118
|
}
|
|
2046
2119
|
}
|
|
@@ -2088,9 +2161,9 @@ class CreditRuntime {
|
|
|
2088
2161
|
offer,
|
|
2089
2162
|
op,
|
|
2090
2163
|
dailyRate: this._calculateDailyFeeRate(offer),
|
|
2091
|
-
feeRate: toFiniteNumber(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2092
|
-
balance: toFiniteNumber(offer.current_balance, 0),
|
|
2093
|
-
duration: toFiniteNumber(offer.max_duration_seconds, 0),
|
|
2164
|
+
feeRate: (0, format_1.toFiniteNumber)(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2165
|
+
balance: (0, format_1.toFiniteNumber)(offer.current_balance, 0),
|
|
2166
|
+
duration: (0, format_1.toFiniteNumber)(offer.max_duration_seconds, 0),
|
|
2094
2167
|
});
|
|
2095
2168
|
}
|
|
2096
2169
|
catch (_) {
|
|
@@ -2167,7 +2240,7 @@ class CreditRuntime {
|
|
|
2167
2240
|
referenceLabel: 'total collateral balance',
|
|
2168
2241
|
});
|
|
2169
2242
|
const desiredBorrowInt = this._calculateBorrowAmountFromCollateral(requestedCollateralInt, collateralPrice, debtAsset, collateralAsset);
|
|
2170
|
-
const desiredBorrowAmount = blockchainToFloat(desiredBorrowInt, debtAsset.precision);
|
|
2243
|
+
const desiredBorrowAmount = (0, math_1.blockchainToFloat)(desiredBorrowInt, debtAsset.precision);
|
|
2171
2244
|
if (Number.isFinite(desiredBorrowAmount) && desiredBorrowAmount > effectiveBorrowCapacity) {
|
|
2172
2245
|
acceptArgs = {
|
|
2173
2246
|
offer,
|
|
@@ -2199,10 +2272,10 @@ class CreditRuntime {
|
|
|
2199
2272
|
}
|
|
2200
2273
|
const opBorrowAmount = blockchainAmountToFloat(op?.op_data?.borrow_amount, await this._resolveAsset(debtAssetId));
|
|
2201
2274
|
const opCollateralAmount = blockchainAmountToFloat(op?.op_data?.collateral, await this._resolveAsset(collateralAssetId));
|
|
2202
|
-
if (
|
|
2275
|
+
if (opBorrowAmount == null || opCollateralAmount == null || opBorrowAmount <= 0 || opCollateralAmount <= 0) {
|
|
2203
2276
|
continue;
|
|
2204
2277
|
}
|
|
2205
|
-
const capped = opCollateralAmount < toFiniteNumber(collateralAmount?.amount ?? collateralAmount, 0);
|
|
2278
|
+
const capped = opCollateralAmount < (0, format_1.toFiniteNumber)(collateralAmount?.amount ?? collateralAmount, 0);
|
|
2206
2279
|
if (capped && opCollateralAmount < minCollateralIncrease) {
|
|
2207
2280
|
continue;
|
|
2208
2281
|
}
|
|
@@ -2213,9 +2286,9 @@ class CreditRuntime {
|
|
|
2213
2286
|
collateralAmount: opCollateralAmount,
|
|
2214
2287
|
capped,
|
|
2215
2288
|
dailyRate: this._calculateDailyFeeRate(offer),
|
|
2216
|
-
feeRate: toFiniteNumber(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2217
|
-
balance: toFiniteNumber(offer.current_balance, 0),
|
|
2218
|
-
duration: toFiniteNumber(offer.max_duration_seconds, 0),
|
|
2289
|
+
feeRate: (0, format_1.toFiniteNumber)(offer.fee_rate, Number.MAX_SAFE_INTEGER),
|
|
2290
|
+
balance: (0, format_1.toFiniteNumber)(offer.current_balance, 0),
|
|
2291
|
+
duration: (0, format_1.toFiniteNumber)(offer.max_duration_seconds, 0),
|
|
2219
2292
|
});
|
|
2220
2293
|
}
|
|
2221
2294
|
catch (_) {
|
|
@@ -2235,7 +2308,7 @@ class CreditRuntime {
|
|
|
2235
2308
|
const assignedCollateralBudget = positiveOrNull(posState?.assignedCollateralBudget);
|
|
2236
2309
|
if (assignedCollateralBudget === null)
|
|
2237
2310
|
return null;
|
|
2238
|
-
const minCollateralIncrease = resolveMinCollateralIncreaseThreshold(lendingItem.minCollateralIncreaseThreshold, assignedCollateralBudget);
|
|
2311
|
+
const minCollateralIncrease = (0, cr_planner_1.resolveMinCollateralIncreaseThreshold)(lendingItem.minCollateralIncreaseThreshold, assignedCollateralBudget);
|
|
2239
2312
|
if (minCollateralIncrease === null)
|
|
2240
2313
|
return null;
|
|
2241
2314
|
const debtAsset = await this._resolveAsset(assetId);
|
|
@@ -2263,13 +2336,13 @@ class CreditRuntime {
|
|
|
2263
2336
|
}
|
|
2264
2337
|
return {
|
|
2265
2338
|
action: 'increase_credit_debt',
|
|
2266
|
-
currentCollateralAmount: roundToDecimals(currentCollateralAmount, 8),
|
|
2267
|
-
collateralIncreaseAmount: roundToDecimals(collateralIncreaseAmount, 8),
|
|
2268
|
-
minCollateralIncrease: roundToDecimals(minCollateralIncrease, 8),
|
|
2269
|
-
currentDebtAmount: roundToDecimals(currentDebtAmount, 8),
|
|
2270
|
-
maxBorrowAmount: maxBorrowAmount !== null ? roundToDecimals(maxBorrowAmount, 8) : null,
|
|
2271
|
-
remainingBorrowCapacity: remainingBorrowCapacity !== null ? roundToDecimals(remainingBorrowCapacity, 8) : null,
|
|
2272
|
-
assignedCollateralBudget: roundToDecimals(assignedCollateralBudget, 8),
|
|
2339
|
+
currentCollateralAmount: (0, math_2.roundToDecimals)(currentCollateralAmount, 8),
|
|
2340
|
+
collateralIncreaseAmount: (0, math_2.roundToDecimals)(collateralIncreaseAmount, 8),
|
|
2341
|
+
minCollateralIncrease: (0, math_2.roundToDecimals)(minCollateralIncrease, 8),
|
|
2342
|
+
currentDebtAmount: (0, math_2.roundToDecimals)(currentDebtAmount, 8),
|
|
2343
|
+
maxBorrowAmount: maxBorrowAmount !== null ? (0, math_2.roundToDecimals)(maxBorrowAmount, 8) : null,
|
|
2344
|
+
remainingBorrowCapacity: remainingBorrowCapacity !== null ? (0, math_2.roundToDecimals)(remainingBorrowCapacity, 8) : null,
|
|
2345
|
+
assignedCollateralBudget: (0, math_2.roundToDecimals)(assignedCollateralBudget, 8),
|
|
2273
2346
|
};
|
|
2274
2347
|
}
|
|
2275
2348
|
async _splitOversizedCreditDeals(lendingItem, assetId, posState, runtimeContext = {}) {
|
|
@@ -2287,7 +2360,7 @@ class CreditRuntime {
|
|
|
2287
2360
|
this._splitInFlight = false;
|
|
2288
2361
|
}
|
|
2289
2362
|
}
|
|
2290
|
-
async _doSplitOversizedCreditDeals(lendingItem, assetId, posState,
|
|
2363
|
+
async _doSplitOversizedCreditDeals(lendingItem, assetId, posState, _runtimeContext = {}) {
|
|
2291
2364
|
const maxPerOp = positiveOrNull(lendingItem.maxBorrowAmountPerOperation);
|
|
2292
2365
|
if (maxPerOp === null)
|
|
2293
2366
|
return null;
|
|
@@ -2298,17 +2371,17 @@ class CreditRuntime {
|
|
|
2298
2371
|
const deals = Array.isArray(posState?.creditDeals) ? posState.creditDeals : [];
|
|
2299
2372
|
const oversized = deals.filter((d) => {
|
|
2300
2373
|
const debt = blockchainAmountToFloat(d?.debtAmount, debtAsset);
|
|
2301
|
-
return
|
|
2374
|
+
return debt != null && debt > maxPerOp;
|
|
2302
2375
|
});
|
|
2303
2376
|
if (oversized.length === 0)
|
|
2304
2377
|
return null;
|
|
2305
2378
|
// T3: Use canonical settle-delay resolution matching dexbot_maintenance_runtime.ts
|
|
2306
|
-
const settleDelay = Number.isFinite(TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2307
|
-
? Math.max(0, TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2379
|
+
const settleDelay = Number.isFinite(constants_1.TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2380
|
+
? Math.max(0, constants_1.TIMING.BLOCKCHAIN_SETTLE_DELAY_MS)
|
|
2308
2381
|
: 6_000;
|
|
2309
2382
|
// T4: Hard cap on pieces per cycle so the watchdog interval is never exceeded
|
|
2310
|
-
const MAX_PIECES_PER_CYCLE = Number.isFinite(TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2311
|
-
? Math.max(0, TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2383
|
+
const MAX_PIECES_PER_CYCLE = Number.isFinite(constants_1.TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2384
|
+
? Math.max(0, constants_1.TIMING.CREDIT_DEAL_SPLIT_MAX_PIECES)
|
|
2312
2385
|
: 48;
|
|
2313
2386
|
const configuredCollateralAssetId = collateralAsset.id;
|
|
2314
2387
|
const posKey = configuredCollateralAssetId
|
|
@@ -2320,18 +2393,18 @@ class CreditRuntime {
|
|
|
2320
2393
|
const dealId = String(deal.id);
|
|
2321
2394
|
let currentDeal = deal;
|
|
2322
2395
|
const dealDebt = blockchainAmountToFloat(currentDeal.debtAmount, debtAsset);
|
|
2323
|
-
if (
|
|
2396
|
+
if (dealDebt == null || dealDebt <= maxPerOp)
|
|
2324
2397
|
continue;
|
|
2325
2398
|
// Check min_deal_amount on the offer to avoid reborrows that would fail.
|
|
2326
2399
|
// Note: _getOfferById caches the offer for the runtime lifetime — if the
|
|
2327
2400
|
// offer's min_deal_amount changes on-chain mid-split, the guard uses the
|
|
2328
2401
|
// stale cached value. Risk is low in practice (offers rarely change this).
|
|
2329
2402
|
const dealOffer = await this._getOfferById(parseDealSummary(currentDeal)?.offerId);
|
|
2330
|
-
const minDealAmount = toFiniteNumber(dealOffer?.min_deal_amount,
|
|
2403
|
+
const minDealAmount = (0, format_1.toFiniteNumber)(dealOffer?.min_deal_amount, undefined);
|
|
2331
2404
|
const numPieces = Math.ceil(dealDebt / maxPerOp);
|
|
2332
|
-
const pieceAmount = roundToDecimals(dealDebt / numPieces, debtAsset.precision);
|
|
2333
|
-
if (minDealAmount !== null && pieceAmount < blockchainToFloat(minDealAmount, debtAsset.precision)) {
|
|
2334
|
-
this.warn(`credit runtime: cannot split deal ${dealId} — piece amount ${pieceAmount} below min_deal_amount ${blockchainToFloat(minDealAmount, debtAsset.precision)} for offer ${dealOffer?.id}`);
|
|
2405
|
+
const pieceAmount = (0, math_2.roundToDecimals)(dealDebt / numPieces, debtAsset.precision);
|
|
2406
|
+
if (minDealAmount !== null && pieceAmount < (0, math_1.blockchainToFloat)(minDealAmount, debtAsset.precision)) {
|
|
2407
|
+
this.warn(`credit runtime: cannot split deal ${dealId} — piece amount ${pieceAmount} below min_deal_amount ${(0, math_1.blockchainToFloat)(minDealAmount, debtAsset.precision)} for offer ${dealOffer?.id}`);
|
|
2335
2408
|
continue;
|
|
2336
2409
|
}
|
|
2337
2410
|
const dealPieces = Math.min(numPieces - 1, MAX_PIECES_PER_CYCLE - totalPiecesThisCycle);
|
|
@@ -2365,7 +2438,7 @@ class CreditRuntime {
|
|
|
2365
2438
|
}
|
|
2366
2439
|
currentDeal = refreshed;
|
|
2367
2440
|
const remaining = blockchainAmountToFloat(currentDeal.debtAmount, debtAsset);
|
|
2368
|
-
if (
|
|
2441
|
+
if (remaining == null || remaining <= maxPerOp)
|
|
2369
2442
|
break;
|
|
2370
2443
|
const currentPiece = Math.min(pieceAmount, remaining - maxPerOp);
|
|
2371
2444
|
if (currentPiece <= 0)
|
|
@@ -2491,8 +2564,8 @@ class CreditRuntime {
|
|
|
2491
2564
|
processed++;
|
|
2492
2565
|
}
|
|
2493
2566
|
catch (err) {
|
|
2494
|
-
this.warn(`credit runtime: fallback reborrow for offer ${request.offerId} failed: ${err
|
|
2495
|
-
nextQueue.push({ ...request, reason: err
|
|
2567
|
+
this.warn(`credit runtime: fallback reborrow for offer ${request.offerId} failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2568
|
+
nextQueue.push({ ...request, reason: (0, errors_1.getErrorMessage)(err) });
|
|
2496
2569
|
}
|
|
2497
2570
|
}
|
|
2498
2571
|
else {
|
|
@@ -2515,8 +2588,8 @@ class CreditRuntime {
|
|
|
2515
2588
|
processed++;
|
|
2516
2589
|
}
|
|
2517
2590
|
catch (err) {
|
|
2518
|
-
this.warn(`credit runtime: pending reborrow for offer ${request.offerId} failed: ${err
|
|
2519
|
-
nextQueue.push({ ...request, reason: err
|
|
2591
|
+
this.warn(`credit runtime: pending reborrow for offer ${request.offerId} failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2592
|
+
nextQueue.push({ ...request, reason: (0, errors_1.getErrorMessage)(err) });
|
|
2520
2593
|
}
|
|
2521
2594
|
}
|
|
2522
2595
|
this.state.pendingReborrows = nextQueue;
|
|
@@ -2533,7 +2606,7 @@ class CreditRuntime {
|
|
|
2533
2606
|
this._reborrowsInFlight = false;
|
|
2534
2607
|
}
|
|
2535
2608
|
}
|
|
2536
|
-
async _runMpaMaintenance(context,
|
|
2609
|
+
async _runMpaMaintenance(context, _options, lendingItem, assetId) {
|
|
2537
2610
|
if (!lendingItem || typeof lendingItem !== 'object') {
|
|
2538
2611
|
throw new Error('_runMpaMaintenance requires a lendingItem');
|
|
2539
2612
|
}
|
|
@@ -2561,7 +2634,7 @@ class CreditRuntime {
|
|
|
2561
2634
|
if (!isDeterministicMpaDebtBalanceError(err, plan)) {
|
|
2562
2635
|
throw err;
|
|
2563
2636
|
}
|
|
2564
|
-
this.warn(`credit runtime: MPA combined operation failed; attempting collateral fallback: ${err
|
|
2637
|
+
this.warn(`credit runtime: MPA combined operation failed; attempting collateral fallback: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2565
2638
|
await this.refreshMpaState(lendingItem);
|
|
2566
2639
|
if (lendingItem.debtOnly) {
|
|
2567
2640
|
throw err;
|
|
@@ -2572,7 +2645,7 @@ class CreditRuntime {
|
|
|
2572
2645
|
const configuredCollateralAssetId = configuredCollateralAsset?.id;
|
|
2573
2646
|
const posKey = configuredCollateralAssetId ? this._positionKey(assetId, configuredCollateralAssetId) : assetId;
|
|
2574
2647
|
const posState = this.state.positions[posKey];
|
|
2575
|
-
const collateralPlan = buildCollateralFallbackPlan({
|
|
2648
|
+
const collateralPlan = (0, cr_planner_1.buildCollateralFallbackPlan)({
|
|
2576
2649
|
currentCollateralAmount: posState?.currentCollateralAmount,
|
|
2577
2650
|
currentDebtAmount: posState?.currentDebtAmount,
|
|
2578
2651
|
feedPrice: posState?.feedPrice,
|
|
@@ -2619,8 +2692,8 @@ class CreditRuntime {
|
|
|
2619
2692
|
return { plan, executed, resetResult };
|
|
2620
2693
|
}
|
|
2621
2694
|
catch (err) {
|
|
2622
|
-
this.warn(`credit runtime: grid reset after CR adjustment failed: ${err
|
|
2623
|
-
return { plan, executed, resetError: err
|
|
2695
|
+
this.warn(`credit runtime: grid reset after CR adjustment failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2696
|
+
return { plan, executed, resetError: (0, errors_1.getErrorMessage)(err) };
|
|
2624
2697
|
}
|
|
2625
2698
|
}
|
|
2626
2699
|
return { plan, executed };
|
|
@@ -2651,7 +2724,7 @@ class CreditRuntime {
|
|
|
2651
2724
|
}
|
|
2652
2725
|
}
|
|
2653
2726
|
catch (err) {
|
|
2654
|
-
this.warn(`credit runtime: deal restructuring failed: ${err
|
|
2727
|
+
this.warn(`credit runtime: deal restructuring failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2655
2728
|
}
|
|
2656
2729
|
let activeDealIds = new Set((posState.creditDeals || []).map((d) => String(d?.id)).filter(Boolean));
|
|
2657
2730
|
for (const deal of (posState.creditDeals || [])) {
|
|
@@ -2665,7 +2738,7 @@ class CreditRuntime {
|
|
|
2665
2738
|
this.warn(`credit runtime: deal ${deal.id} expires in ${Math.round(timeLeft / 60000)}m; proactively repaying and reborrowing`);
|
|
2666
2739
|
const debtAsset = await this._resolveAsset(deal.debtAssetId);
|
|
2667
2740
|
const repayAmount = blockchainAmountToFloat(deal.debtAmount, debtAsset);
|
|
2668
|
-
if (
|
|
2741
|
+
if (repayAmount == null || repayAmount <= 0) {
|
|
2669
2742
|
throw new Error(`unable to convert deal ${deal.id} debt amount for repay`);
|
|
2670
2743
|
}
|
|
2671
2744
|
const isCollateralMismatch = deal.collateralMismatch === true;
|
|
@@ -2674,7 +2747,7 @@ class CreditRuntime {
|
|
|
2674
2747
|
const accountRef = getAccountRef(this.bot);
|
|
2675
2748
|
const balances = await chainOrders.getOnChainAssetBalances(accountRef, [configuredCollateralAssetId]);
|
|
2676
2749
|
const balance = balances?.[String(configuredCollateralAssetId)] || balances?.[String(configuredCollateralAsset?.symbol)] || null;
|
|
2677
|
-
const available = toFiniteNumber(balance?.total,
|
|
2750
|
+
const available = (0, format_1.toFiniteNumber)(balance?.total, undefined);
|
|
2678
2751
|
if (!Number.isFinite(available) || available <= 0) {
|
|
2679
2752
|
this.warn(`credit runtime: skipping collateral switch for deal ${deal.id} — no balance of new collateral ${configuredCollateralAssetId}`);
|
|
2680
2753
|
continue;
|
|
@@ -2683,7 +2756,7 @@ class CreditRuntime {
|
|
|
2683
2756
|
if (!isCollateralMismatch) {
|
|
2684
2757
|
const collateralAsset = await this._resolveAsset(deal.collateralAssetId);
|
|
2685
2758
|
existingCollateralAmount = blockchainAmountToFloat(deal.collateralAmount, collateralAsset);
|
|
2686
|
-
if (
|
|
2759
|
+
if (existingCollateralAmount == null || existingCollateralAmount <= 0) {
|
|
2687
2760
|
throw new Error(`unable to convert deal ${deal.id} collateral amount for release`);
|
|
2688
2761
|
}
|
|
2689
2762
|
}
|
|
@@ -2725,7 +2798,7 @@ class CreditRuntime {
|
|
|
2725
2798
|
}
|
|
2726
2799
|
}
|
|
2727
2800
|
catch (err) {
|
|
2728
|
-
this.warn(`credit runtime: proactive repay/reborrow for deal ${deal.id} failed: ${err
|
|
2801
|
+
this.warn(`credit runtime: proactive repay/reborrow for deal ${deal.id} failed: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2729
2802
|
}
|
|
2730
2803
|
}
|
|
2731
2804
|
}
|
|
@@ -2742,7 +2815,7 @@ class CreditRuntime {
|
|
|
2742
2815
|
deal.autoRepay = policyAutoRepay;
|
|
2743
2816
|
}
|
|
2744
2817
|
catch (err) {
|
|
2745
|
-
this.warn(`credit runtime: failed to update auto_repay on deal ${deal.id}: ${err
|
|
2818
|
+
this.warn(`credit runtime: failed to update auto_repay on deal ${deal.id}: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2746
2819
|
}
|
|
2747
2820
|
}
|
|
2748
2821
|
}
|
|
@@ -2866,8 +2939,8 @@ class CreditRuntime {
|
|
|
2866
2939
|
};
|
|
2867
2940
|
}
|
|
2868
2941
|
catch (err) {
|
|
2869
|
-
this.warn(`credit runtime: watchdog error: ${err
|
|
2870
|
-
return { skipped: true, reason: err
|
|
2942
|
+
this.warn(`credit runtime: watchdog error: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
2943
|
+
return { skipped: true, reason: (0, errors_1.getErrorMessage)(err) };
|
|
2871
2944
|
}
|
|
2872
2945
|
finally {
|
|
2873
2946
|
this._watchdogInFlight = false;
|
|
@@ -2884,7 +2957,7 @@ class CreditRuntime {
|
|
|
2884
2957
|
for (const assetId of assetIds) {
|
|
2885
2958
|
const key = String(assetId);
|
|
2886
2959
|
const entry = snapshot[key];
|
|
2887
|
-
result[key] = toFiniteNumber(entry?.totalCollateral, 0);
|
|
2960
|
+
result[key] = (0, format_1.toFiniteNumber)(entry?.totalCollateral, 0);
|
|
2888
2961
|
}
|
|
2889
2962
|
return result;
|
|
2890
2963
|
}
|
|
@@ -2892,5 +2965,6 @@ class CreditRuntime {
|
|
|
2892
2965
|
return deepClone(this.state);
|
|
2893
2966
|
}
|
|
2894
2967
|
}
|
|
2968
|
+
exports.default = CreditRuntime;
|
|
2895
2969
|
module.exports = CreditRuntime;
|
|
2896
2970
|
//# sourceMappingURL=credit_runtime.js.map
|