dexbot 1.6.12 → 1.6.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -1
- package/README.md +2 -2
- package/analysis/README.md +9 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +3 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_catalog.ts +8 -4
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/dexbot_profiles.ts +59 -15
- package/claw/modules/types.ts +2 -1
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/skills/margin-trading/SKILL.md +1 -1
- package/claw/skills/margin-trading/references/position-management.md +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +1 -14
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +51 -41
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -24
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +36 -18
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +18 -66
- package/dist/analysis/analyze_args.d.ts +12 -0
- package/dist/analysis/analyze_args.js +20 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +1 -16
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +20 -101
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +26 -92
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +71 -3
- package/dist/analysis/bot_fitting/shared_utils.js +124 -8
- package/dist/analysis/chart_ui.d.ts +30 -1
- package/dist/analysis/chart_ui.js +37 -1
- package/dist/analysis/fills_cache.d.ts +3 -23
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +31 -1
- package/dist/analysis/fills_source.js +69 -1
- package/dist/analysis/grid_correction_check.d.ts +1 -23
- package/dist/analysis/grid_correction_check.js +15 -58
- package/dist/analysis/math_utils.d.ts +85 -1
- package/dist/analysis/math_utils.js +116 -1
- package/dist/analysis/price_sources.d.ts +22 -1
- package/dist/analysis/price_sources.js +23 -0
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +6 -0
- package/dist/analysis/trade_profitability.js +23 -97
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +1 -17
- package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +27 -40
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +22 -80
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +11 -37
- package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/dexbot.js +67 -48
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +7 -1
- package/dist/market_adapter/candle_utils.js +11 -1
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- package/dist/market_adapter/core/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +3 -1
- package/dist/market_adapter/core/kibana_candles.js +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +85 -85
- package/dist/market_adapter/core/market_adapter_service.js +93 -158
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- package/dist/market_adapter/inputs/fetch_book_data.js +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +63 -107
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +8 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +25 -7
- package/dist/market_adapter/inputs/kibana_feed_source.js +4 -26
- package/dist/market_adapter/inputs/window_cache.d.ts +4 -72
- package/dist/market_adapter/inputs/window_cache.js +52 -177
- package/dist/market_adapter/interval_utils.d.ts +11 -1
- package/dist/market_adapter/interval_utils.js +16 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +3 -0
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- package/dist/market_adapter/market_adapter.js +27 -72
- package/dist/market_adapter/utils/data_discovery.d.ts +45 -1
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- package/dist/market_adapter/utils/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- package/dist/modules/account_bots.d.ts +8 -6
- package/dist/modules/account_bots.js +112 -131
- package/dist/modules/account_orders.d.ts +49 -4
- package/dist/modules/account_orders.js +114 -49
- package/dist/modules/bitshares-native/chain_client.d.ts +1 -1
- package/dist/modules/bitshares-native/chain_client.js +14 -13
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
- package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
- package/dist/modules/bitshares-native/resolvers.js +22 -25
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
- package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
- package/dist/modules/bitshares-native/serial/types.js +22 -50
- package/dist/modules/bitshares-native/signing_client.d.ts +1 -1
- package/dist/modules/bot_defaults.d.ts +18 -3
- package/dist/modules/bot_defaults.js +34 -8
- package/dist/modules/bot_settings.d.ts +5 -1
- package/dist/modules/bot_settings.js +55 -21
- package/dist/modules/broadcast_failure.d.ts +2 -1
- package/dist/modules/chain_orders.d.ts +1 -1
- package/dist/modules/chain_orders.js +51 -96
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/config.js +6 -1
- package/dist/modules/constants.d.ts +14 -6
- package/dist/modules/constants.js +32 -6
- package/dist/modules/cr_planner.d.ts +1 -1
- package/dist/modules/cr_planner.js +1 -5
- package/dist/modules/credit_pricing.d.ts +2 -1
- package/dist/modules/credit_pricing.js +36 -40
- package/dist/modules/credit_runtime.d.ts +7 -0
- package/dist/modules/credit_runtime.js +45 -73
- package/dist/modules/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +33 -17
- package/dist/modules/dexbot_class.js +113 -61
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -181
- package/dist/modules/dexbot_cow_runtime.js +380 -69
- package/dist/modules/dexbot_credential_client.d.ts +1 -23
- package/dist/modules/dexbot_credential_client.js +2 -3
- package/dist/modules/dexbot_fill_runtime.d.ts +2 -3
- package/dist/modules/dexbot_fill_runtime.js +17 -7
- package/dist/modules/dexbot_maintenance_runtime.d.ts +36 -81
- package/dist/modules/dexbot_maintenance_runtime.js +137 -133
- package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
- package/dist/modules/dexbot_startup_runtime.js +25 -14
- package/dist/modules/dexbot_state_recovery.js +16 -0
- package/dist/modules/general_settings.d.ts +1 -1
- package/dist/modules/graceful_shutdown.js +17 -11
- package/dist/modules/key_store.d.ts +0 -5
- package/dist/modules/key_store.js +1 -2
- package/dist/modules/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- package/dist/modules/order/accounting.js +11 -11
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/format.d.ts +26 -3
- package/dist/modules/order/format.js +33 -3
- package/dist/modules/order/genesis_policy.d.ts +4 -4
- package/dist/modules/order/genesis_policy.js +6 -3
- package/dist/modules/order/grid.d.ts +26 -12
- package/dist/modules/order/grid.js +468 -80
- package/dist/modules/order/grid_reconcile.d.ts +1 -1
- package/dist/modules/order/grid_reconcile.js +5 -5
- package/dist/modules/order/grid_reconcile_internal.js +48 -40
- package/dist/modules/order/index.d.ts +35 -8
- package/dist/modules/order/logger.d.ts +1 -8
- package/dist/modules/order/logger.js +2 -11
- package/dist/modules/order/manager.d.ts +18 -15
- package/dist/modules/order/manager.js +91 -74
- package/dist/modules/order/strategy.d.ts +2 -2
- package/dist/modules/order/strategy.js +51 -21
- package/dist/modules/order/sync_engine.js +4 -0
- package/dist/modules/order/utils/math.d.ts +3 -3
- package/dist/modules/order/utils/math.js +38 -27
- package/dist/modules/order/utils/order.d.ts +58 -58
- package/dist/modules/order/utils/order.js +158 -137
- package/dist/modules/order/utils/system.d.ts +202 -35
- package/dist/modules/order/utils/system.js +409 -31
- package/dist/modules/order/utils/validate.js +28 -6
- package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
- package/dist/modules/paths.js +32 -34
- package/dist/modules/runtime_settings.d.ts +3 -5
- package/dist/modules/runtime_settings.js +3 -3
- package/dist/modules/settings_merge.d.ts +2 -2
- package/dist/modules/socket_json_client.d.ts +2 -1
- package/dist/modules/types.d.ts +89 -30
- package/dist/modules/utils/errors.js +1 -3
- package/dist/modules/version_notice.d.ts +11 -10
- package/dist/pm2.d.ts +0 -1
- package/dist/pm2.js +56 -35
- package/dist/scripts/analyze-git.js +2 -15
- package/dist/scripts/analyze-orders.d.ts +1 -1
- package/dist/scripts/analyze-orders.js +4 -4
- package/dist/scripts/chart_command.js +2 -2
- package/dist/scripts/check_any.d.ts +4 -0
- package/dist/scripts/check_any.js +53 -21
- package/dist/scripts/diagnose-pool-history.js +1 -6
- package/dist/scripts/divergence-calc.js +6 -6
- package/dist/scripts/run-tests.js +0 -1
- package/dist/scripts/sync-version.js +0 -10
- package/dist/scripts/validate_bots.d.ts +1 -1
- package/dist/scripts/validate_bots.js +3 -3
- package/dist/unlock.js +7 -2
- package/docs/BITSHARES_ONBOARDING.md +8 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -3
- package/docs/COW_INVARIANTS.md +6 -6
- package/docs/DEXBOT_COMPARISON.md +7 -7
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
- package/docs/GRID_PRICE_INVARIANT.md +3 -3
- package/docs/GRID_RECALCULATION.md +4 -1
- package/docs/GRID_RECONCILE.md +4 -4
- package/docs/LIFECYCLE.md +11 -11
- package/docs/LOGGING.md +14 -0
- package/docs/MPA_CREDIT_USAGE.md +1 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
- package/docs/README.md +3 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +25 -16
- package/docs/developer_guide.md +7 -2
- package/market_adapter/README.md +6 -4
- package/package.json +6 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +26 -11
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* Price: startPrice, minPrice, maxPrice, incrementPercent, targetSpreadPercent
|
|
29
29
|
* Control: active, dryRun
|
|
30
30
|
* Trading pair: assetA, assetB
|
|
31
|
-
* Allocation: weightDistribution, botFunds,
|
|
31
|
+
* Allocation: weightDistribution, botFunds, coreOrders
|
|
32
32
|
*
|
|
33
33
|
* TIMING PARAMETERS:
|
|
34
34
|
* 4. TIMING - Operational timing constants
|
|
@@ -149,6 +149,10 @@ declare const COW_ACTIONS: Readonly<{
|
|
|
149
149
|
CANCEL: "cancel";
|
|
150
150
|
UPDATE: "update";
|
|
151
151
|
}>;
|
|
152
|
+
declare const COW_ORIGINS: Readonly<{
|
|
153
|
+
SPREAD_CORRECTION: "spread-correction";
|
|
154
|
+
GAP_EVACUATION: "gap-evacuation";
|
|
155
|
+
}>;
|
|
152
156
|
declare let DEFAULT_CONFIG: {
|
|
153
157
|
startPrice: string;
|
|
154
158
|
minPrice: string;
|
|
@@ -169,11 +173,11 @@ declare let DEFAULT_CONFIG: {
|
|
|
169
173
|
sell: string;
|
|
170
174
|
buy: string;
|
|
171
175
|
};
|
|
172
|
-
|
|
176
|
+
coreOrders: {
|
|
173
177
|
sell: number;
|
|
174
178
|
buy: number;
|
|
175
179
|
};
|
|
176
|
-
|
|
180
|
+
edgeOrders: {
|
|
177
181
|
buy: number;
|
|
178
182
|
sell: number;
|
|
179
183
|
};
|
|
@@ -208,6 +212,7 @@ declare let TIMING: {
|
|
|
208
212
|
RETRY_BACKOFF_CAP_MS: number;
|
|
209
213
|
DAEMON_PING_TIMEOUT_MS: number;
|
|
210
214
|
CREDENTIAL_DAEMON_WATCHDOG_MS: number;
|
|
215
|
+
CREDENTIAL_DAEMON_WATCHDOG_FAILURE_THRESHOLD: number;
|
|
211
216
|
RUN_LOOP_DEFAULT_MS: number;
|
|
212
217
|
OPEN_ORDERS_SYNC_LOOP_ENABLED: boolean;
|
|
213
218
|
CHECK_INTERVAL_MS: number;
|
|
@@ -220,6 +225,7 @@ declare let TIMING: {
|
|
|
220
225
|
FILL_TOTALS_RETRY_MAX_MS: number;
|
|
221
226
|
SPREAD_STALE_WARN_MS: number;
|
|
222
227
|
SPREAD_STALE_ESCALATE_MS: number;
|
|
228
|
+
SPREAD_CORRECTION_SYNC_FRESH_MS: number;
|
|
223
229
|
SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
|
|
224
230
|
BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
|
|
225
231
|
BOUNDARY_HOLD_RESYNC_COOLDOWN_MS: number;
|
|
@@ -746,6 +752,7 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
746
752
|
RETRY_BACKOFF_CAP_MS: number;
|
|
747
753
|
DAEMON_PING_TIMEOUT_MS: number;
|
|
748
754
|
CREDENTIAL_DAEMON_WATCHDOG_MS: number;
|
|
755
|
+
CREDENTIAL_DAEMON_WATCHDOG_FAILURE_THRESHOLD: number;
|
|
749
756
|
RUN_LOOP_DEFAULT_MS: number;
|
|
750
757
|
OPEN_ORDERS_SYNC_LOOP_ENABLED: boolean;
|
|
751
758
|
CHECK_INTERVAL_MS: number;
|
|
@@ -758,6 +765,7 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
758
765
|
FILL_TOTALS_RETRY_MAX_MS: number;
|
|
759
766
|
SPREAD_STALE_WARN_MS: number;
|
|
760
767
|
SPREAD_STALE_ESCALATE_MS: number;
|
|
768
|
+
SPREAD_CORRECTION_SYNC_FRESH_MS: number;
|
|
761
769
|
SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
|
|
762
770
|
BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
|
|
763
771
|
BOUNDARY_HOLD_RESYNC_COOLDOWN_MS: number;
|
|
@@ -980,11 +988,11 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
980
988
|
sell: string;
|
|
981
989
|
buy: string;
|
|
982
990
|
};
|
|
983
|
-
|
|
991
|
+
coreOrders: {
|
|
984
992
|
sell: number;
|
|
985
993
|
buy: number;
|
|
986
994
|
};
|
|
987
|
-
|
|
995
|
+
edgeOrders: {
|
|
988
996
|
buy: number;
|
|
989
997
|
sell: number;
|
|
990
998
|
};
|
|
@@ -1222,5 +1230,5 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
1222
1230
|
};
|
|
1223
1231
|
NODES: import("./settings_merge.js").NodesView;
|
|
1224
1232
|
};
|
|
1225
|
-
export { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, COW_ACTIONS, DEFAULT_CONFIG, TIMING, RANGE_QUALITY, GRID_LIMITS, LOG_LEVEL, LOGGING_CONFIG, INCREMENT_BOUNDS, FEE_PARAMETERS, CR_ZONES, DEFAULT_TARGET_CR, API_LIMITS, FILL_PROCESSING, MAINTENANCE, NODE_MANAGEMENT, PIPELINE_TIMING, UPDATER, LAUNCHER, COW_PERFORMANCE, NATIVE_CLIENT, MARKET_ADAPTER, BUILD_DIR, BTS_PRECISION, DAEMON_ERRORS, DAEMON_CODES, CREDENTIAL_PROMPTS, buildDefaultGeneralSettings };
|
|
1233
|
+
export { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, COW_ACTIONS, COW_ORIGINS, DEFAULT_CONFIG, TIMING, RANGE_QUALITY, GRID_LIMITS, LOG_LEVEL, LOGGING_CONFIG, INCREMENT_BOUNDS, FEE_PARAMETERS, CR_ZONES, DEFAULT_TARGET_CR, API_LIMITS, FILL_PROCESSING, MAINTENANCE, NODE_MANAGEMENT, PIPELINE_TIMING, UPDATER, LAUNCHER, COW_PERFORMANCE, NATIVE_CLIENT, MARKET_ADAPTER, BUILD_DIR, BTS_PRECISION, DAEMON_ERRORS, DAEMON_CODES, CREDENTIAL_PROMPTS, buildDefaultGeneralSettings };
|
|
1226
1234
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* Price: startPrice, minPrice, maxPrice, incrementPercent, targetSpreadPercent
|
|
30
30
|
* Control: active, dryRun
|
|
31
31
|
* Trading pair: assetA, assetB
|
|
32
|
-
* Allocation: weightDistribution, botFunds,
|
|
32
|
+
* Allocation: weightDistribution, botFunds, coreOrders
|
|
33
33
|
*
|
|
34
34
|
* TIMING PARAMETERS:
|
|
35
35
|
* 4. TIMING - Operational timing constants
|
|
@@ -158,6 +158,19 @@ const COW_ACTIONS = Object.freeze({
|
|
|
158
158
|
CANCEL: 'cancel',
|
|
159
159
|
UPDATE: 'update'
|
|
160
160
|
});
|
|
161
|
+
// Canonical plan/action ORIGIN labels. A plan stamps `origin` so the execution
|
|
162
|
+
// guard can scope a bypass to one producer (never to the whole batch by
|
|
163
|
+
// accident). Kept here so the planner that writes the tag and the guard that
|
|
164
|
+
// reads it can never drift on the spelling.
|
|
165
|
+
// - SPREAD_CORRECTION: gap-repair creates (may close the spread on the
|
|
166
|
+
// market side); LAST-FILL-GUARD bypasses these CREATEs per-action.
|
|
167
|
+
// - GAP_EVACUATION: in-band rotation UPDATEs proven violation-reducing at
|
|
168
|
+
// plan-build (B-stamp) or re-proven live; LAST-FILL-GUARD bypasses only
|
|
169
|
+
// stamped/validated ones.
|
|
170
|
+
const COW_ORIGINS = Object.freeze({
|
|
171
|
+
SPREAD_CORRECTION: 'spread-correction',
|
|
172
|
+
GAP_EVACUATION: 'gap-evacuation'
|
|
173
|
+
});
|
|
161
174
|
// Defaults applied when instantiating an OrderManager with minimal configuration.
|
|
162
175
|
// These values are used when a parameter is not explicitly provided in the bot config.
|
|
163
176
|
let DEFAULT_CONFIG = {
|
|
@@ -183,10 +196,10 @@ let DEFAULT_CONFIG = {
|
|
|
183
196
|
// Fund allocation
|
|
184
197
|
weightDistribution: { sell: 1, buy: 1 }, // Geometric weight for order sizing (1 = ~1:2 center/outer split, 0.5 = linear)
|
|
185
198
|
botFunds: { sell: "100%", buy: "100%" }, // Percentage of wallet balance to allocate ("100%" or numeric value)
|
|
186
|
-
|
|
187
|
-
|
|
199
|
+
coreOrders: { sell: 20, buy: 20 }, // Number of window orders to maintain closest to market on each side
|
|
200
|
+
edgeOrders: { buy: 0, sell: 0 }, // Edge-pinned insurance orders resting live outside the window (buy: grid floor, sell: grid ceiling; 0 disables)
|
|
188
201
|
// BTS fee management for non-BTS pairs
|
|
189
|
-
min_BTS_value: null, // Minimum BTS balance to maintain (null = auto from
|
|
202
|
+
min_BTS_value: null, // Minimum BTS balance to maintain (null = auto from coreOrders × fees × multiplier)
|
|
190
203
|
};
|
|
191
204
|
// Range quality zones for price bounds (minPrice/maxPrice multipliers).
|
|
192
205
|
// Used for pre-entry legend in the bot editor (mountain-style).
|
|
@@ -256,6 +269,11 @@ let TIMING = {
|
|
|
256
269
|
RETRY_BACKOFF_CAP_MS: 30000, // 30 seconds - Max exponential backoff delay for connection retries
|
|
257
270
|
DAEMON_PING_TIMEOUT_MS: 5000, // 5 seconds - Private key daemon ping/healthcheck timeout
|
|
258
271
|
CREDENTIAL_DAEMON_WATCHDOG_MS: 60000, // 60 seconds - Credential daemon watchdog polling interval
|
|
272
|
+
// Consecutive failed watchdog probes before the daemon is declared down and
|
|
273
|
+
// grid persistence is suspended. 2 tolerates a single transient timeout
|
|
274
|
+
// (daemon busy signing a large batch) without pausing writes; a genuinely
|
|
275
|
+
// dead daemon still trips on the very next probe (~60s later).
|
|
276
|
+
CREDENTIAL_DAEMON_WATCHDOG_FAILURE_THRESHOLD: 2,
|
|
259
277
|
// Main loop and polling defaults
|
|
260
278
|
RUN_LOOP_DEFAULT_MS: 300000, // 5 minutes - default open-orders sync cycle delay (env override: OPEN_ORDERS_SYNC_LOOP_MS)
|
|
261
279
|
OPEN_ORDERS_SYNC_LOOP_ENABLED: false, // Preferred flag: continuous open-order watchdog sync loop (default false — react to fills only)
|
|
@@ -312,6 +330,13 @@ let TIMING = {
|
|
|
312
330
|
// by moving the boundary). Time-based so it holds for any tick cadence.
|
|
313
331
|
SPREAD_STALE_WARN_MS: 10 * 60 * 1000, // 10 minutes
|
|
314
332
|
SPREAD_STALE_ESCALATE_MS: 30 * 60 * 1000, // 30 minutes
|
|
333
|
+
// SPREAD_CORRECTION_SYNC_FRESH_MS: how old the last completed open-orders
|
|
334
|
+
// sync may be before a spread-correction CREATE loses its LAST-FILL-GUARD
|
|
335
|
+
// bypass. A stale local snapshot (old sync or known-unmatched chain
|
|
336
|
+
// orders) can hide the real window edge, so the bypass is withheld and the
|
|
337
|
+
// guard applies instead of trusting the stale anchor. Fail-open when no
|
|
338
|
+
// sync timestamp exists yet.
|
|
339
|
+
SPREAD_CORRECTION_SYNC_FRESH_MS: 10 * 60 * 1000, // 10 minutes
|
|
315
340
|
// Dedicated escalation cooldown for the spread-stale watchdog. Deliberately
|
|
316
341
|
// separate from BOUNDARY_HOLD_RESYNC_COOLDOWN_MS so tuning boundary-hold
|
|
317
342
|
// behavior never silently changes the spread watchdog cadence.
|
|
@@ -520,7 +545,7 @@ let GRID_LIMITS = {
|
|
|
520
545
|
// to a price ladder ("no genesis" -- the genesis-less state analysed in
|
|
521
546
|
// docs/GRID_PRICE_INVARIANT.md). A genesis-less grid is NOT repairable in
|
|
522
547
|
// place: every consumer (nearest-slot adoption, the materialize
|
|
523
|
-
// descriptor-price fallback,
|
|
548
|
+
// descriptor-price fallback, edge anchoring) has no authority for a
|
|
524
549
|
// slot's price, which is exactly how an off-grid price became grid evidence
|
|
525
550
|
// and was re-emitted. The load and sync gates refuse that state outright —
|
|
526
551
|
// no tolerance matcher remains.
|
|
@@ -1971,6 +1996,7 @@ Object.freeze(ORDER_TYPES);
|
|
|
1971
1996
|
Object.freeze(ORDER_STATES);
|
|
1972
1997
|
Object.freeze(REBALANCE_STATES);
|
|
1973
1998
|
Object.freeze(COW_ACTIONS);
|
|
1999
|
+
Object.freeze(COW_ORIGINS);
|
|
1974
2000
|
Object.freeze(TIMING);
|
|
1975
2001
|
Object.freeze(GRID_LIMITS);
|
|
1976
2002
|
Object.freeze(GRID_LIMITS.GRID_COMPARISON);
|
|
@@ -2005,5 +2031,5 @@ Object.freeze(MARKET_ADAPTER.AMAS.AMA4);
|
|
|
2005
2031
|
Object.freeze(MARKET_ADAPTER.AMAS);
|
|
2006
2032
|
Object.freeze(MARKET_ADAPTER);
|
|
2007
2033
|
Object.freeze(CREDENTIAL_PROMPTS);
|
|
2008
|
-
export { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, COW_ACTIONS, DEFAULT_CONFIG, TIMING, RANGE_QUALITY, GRID_LIMITS, LOG_LEVEL, LOGGING_CONFIG, INCREMENT_BOUNDS, FEE_PARAMETERS, CR_ZONES, DEFAULT_TARGET_CR, API_LIMITS, FILL_PROCESSING, MAINTENANCE, NODE_MANAGEMENT, PIPELINE_TIMING, UPDATER, LAUNCHER, COW_PERFORMANCE, NATIVE_CLIENT, MARKET_ADAPTER, BUILD_DIR, BTS_PRECISION, DAEMON_ERRORS, DAEMON_CODES, CREDENTIAL_PROMPTS, buildDefaultGeneralSettings };
|
|
2034
|
+
export { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, COW_ACTIONS, COW_ORIGINS, DEFAULT_CONFIG, TIMING, RANGE_QUALITY, GRID_LIMITS, LOG_LEVEL, LOGGING_CONFIG, INCREMENT_BOUNDS, FEE_PARAMETERS, CR_ZONES, DEFAULT_TARGET_CR, API_LIMITS, FILL_PROCESSING, MAINTENANCE, NODE_MANAGEMENT, PIPELINE_TIMING, UPDATER, LAUNCHER, COW_PERFORMANCE, NATIVE_CLIENT, MARKET_ADAPTER, BUILD_DIR, BTS_PRECISION, DAEMON_ERRORS, DAEMON_CODES, CREDENTIAL_PROMPTS, buildDefaultGeneralSettings };
|
|
2009
2035
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { positiveOrNull } from './order/format.js';
|
|
1
2
|
interface CrPolicy {
|
|
2
3
|
minCollateralRatio?: number;
|
|
3
4
|
maxCollateralRatio?: number;
|
|
@@ -25,7 +26,6 @@ interface CollateralFallbackPlanOptions {
|
|
|
25
26
|
maxCollateralAmount?: number | string;
|
|
26
27
|
collateralLimitReferenceAmount?: number;
|
|
27
28
|
}
|
|
28
|
-
declare function positiveOrNull(value: unknown): number | null;
|
|
29
29
|
declare function resolveMinCollateralIncreaseThreshold(value: unknown, referenceAmount?: unknown): number | null;
|
|
30
30
|
declare function resolveTargetCollateralRatio(policy?: CrPolicy): number | null;
|
|
31
31
|
declare function buildDebtFirstCrPlan({ currentCollateralAmount, currentDebtAmount, feedPrice, minCollateralRatio, maxCollateralRatio, targetCollateralRatio, maxBorrowAmount, maxBorrowAmountPerOperation, maxCollateralAmount, collateralLimitReferenceAmount, minCollateralIncreaseThreshold, debtOnly, }?: DebtFirstCrPlanOptions): {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
import {
|
|
2
|
+
import { positiveOrNull } from './order/format.js';
|
|
3
3
|
import { resolveConfigValue, isPercentageString, roundToDecimals } from './order/utils/math.js';
|
|
4
|
-
function positiveOrNull(value) {
|
|
5
|
-
const num = toFiniteNumber(value, undefined);
|
|
6
|
-
return Number.isFinite(num) && num > 0 ? num : null;
|
|
7
|
-
}
|
|
8
4
|
function resolveCollateralLimit(value, referenceAmount) {
|
|
9
5
|
const resolved = resolveConfigValue(value, referenceAmount);
|
|
10
6
|
if (!Number.isFinite(resolved))
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* modules/credit_pricing.ts — Canonical credit-pricing math (single source of truth).
|
|
3
3
|
*
|
|
4
|
-
* Pure functions only: no
|
|
4
|
+
* Pure functions only: no I/O, browser-safe; imports only the dependency-free
|
|
5
|
+
* order/format number helpers. Both the live
|
|
5
6
|
* credit runtime (modules/credit_runtime.ts) and the offline analyzer
|
|
6
7
|
* (scripts/analyze-credit.ts) delegate to these helpers so offer-price
|
|
7
8
|
* orientation, conversion rates, and collateral-ratio math cannot drift
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
const num = typeof value === 'string' && value.trim() !== '' ? Number(value) : Number(value);
|
|
4
|
-
return Number.isFinite(num) ? num : null;
|
|
5
|
-
}
|
|
6
|
-
function positiveOrNull(value) {
|
|
7
|
-
const num = toFiniteOrNull(value);
|
|
8
|
-
return num !== null && num > 0 ? num : null;
|
|
9
|
-
}
|
|
2
|
+
import { positiveOrNull, toFiniteNumber } from './order/format.js';
|
|
10
3
|
/**
|
|
11
4
|
* Tolerantly normalize an offer's acceptable_collateral map, which arrives
|
|
12
5
|
* in different shapes depending on the API path (Map, [[id, price]] pairs,
|
|
@@ -52,7 +45,7 @@ function creditPriceOrientation(baseAssetId, quoteAssetId, debtAssetId, collater
|
|
|
52
45
|
return 'core';
|
|
53
46
|
}
|
|
54
47
|
function priceLegToFloat(leg, precision) {
|
|
55
|
-
const raw =
|
|
48
|
+
const raw = toFiniteNumber(leg?.amount, null);
|
|
56
49
|
if (raw === null || raw <= 0 || precision === null || !Number.isFinite(precision) || precision < 0) {
|
|
57
50
|
return null;
|
|
58
51
|
}
|
|
@@ -105,8 +98,8 @@ function asOfferPrice(collateralPriceOrMap, collateralAssetId) {
|
|
|
105
98
|
* Pure offer-math leg of the runtime's pool-aware valuation.
|
|
106
99
|
*/
|
|
107
100
|
function collateralValueFromOfferPrice(collateralAmountInt, collateralPrecision, collateralPriceOrMap, debtAssetId, collateralAssetId, precisionOf) {
|
|
108
|
-
const collRaw =
|
|
109
|
-
const collPrec =
|
|
101
|
+
const collRaw = toFiniteNumber(collateralAmountInt, null);
|
|
102
|
+
const collPrec = toFiniteNumber(collateralPrecision, null);
|
|
110
103
|
if (collRaw === null || collRaw <= 0 || collPrec === null)
|
|
111
104
|
return null;
|
|
112
105
|
const collateralFloat = collRaw / Math.pow(10, collPrec);
|
|
@@ -127,8 +120,8 @@ function collateralValueFromOfferPrice(collateralAmountInt, collateralPrecision,
|
|
|
127
120
|
* factor applies. Null when the price is missing or unusable.
|
|
128
121
|
*/
|
|
129
122
|
function resolvePriceFactors(collateralPrice, debtAssetId, collateralAssetId) {
|
|
130
|
-
const baseAmount =
|
|
131
|
-
const quoteAmount =
|
|
123
|
+
const baseAmount = toFiniteNumber(collateralPrice?.base?.amount, null);
|
|
124
|
+
const quoteAmount = toFiniteNumber(collateralPrice?.quote?.amount, null);
|
|
132
125
|
if (baseAmount === null || quoteAmount === null || baseAmount <= 0 || quoteAmount <= 0) {
|
|
133
126
|
return null;
|
|
134
127
|
}
|
|
@@ -136,34 +129,37 @@ function resolvePriceFactors(collateralPrice, debtAssetId, collateralAssetId) {
|
|
|
136
129
|
return { baseAmount, quoteAmount, orientation };
|
|
137
130
|
}
|
|
138
131
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
132
|
+
* Convert a raw amount along the borrow<->collateral price ratio, applying the
|
|
133
|
+
* price orientation and integer rounding direction. Shared by the two
|
|
134
|
+
* conversions below so they cannot disagree on which factor applies; the two
|
|
135
|
+
* directions are reciprocal, so `direction` flips the numerator/denominator.
|
|
141
136
|
*/
|
|
142
|
-
function
|
|
143
|
-
const
|
|
137
|
+
function convertAtPrice(amountInt, direction, rounding, collateralPrice, debtAssetId, collateralAssetId) {
|
|
138
|
+
const amount = toFiniteNumber(amountInt, null);
|
|
144
139
|
const factors = resolvePriceFactors(collateralPrice, debtAssetId, collateralAssetId);
|
|
145
|
-
if (
|
|
140
|
+
if (amount === null || amount <= 0 || factors === null)
|
|
146
141
|
return null;
|
|
147
142
|
const { baseAmount, quoteAmount, orientation } = factors;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
const legacyNumerator = direction === 'debtToCollateral' ? baseAmount : quoteAmount;
|
|
144
|
+
const legacyDenominator = direction === 'debtToCollateral' ? quoteAmount : baseAmount;
|
|
145
|
+
const numerator = orientation === 'legacy-reversed' ? legacyNumerator : legacyDenominator;
|
|
146
|
+
const denominator = orientation === 'legacy-reversed' ? legacyDenominator : legacyNumerator;
|
|
147
|
+
const round = rounding === 'ceil' ? Math.ceil : Math.floor;
|
|
148
|
+
return round((Number(amountInt) * numerator) / denominator);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Minimum raw collateral required to borrow a raw debt amount at a price.
|
|
152
|
+
* Integer ceil so the borrow is never under-collateralized by rounding.
|
|
153
|
+
*/
|
|
154
|
+
function requiredCollateralForBorrow(borrowAmountInt, collateralPrice, debtAssetId = null, collateralAssetId = null) {
|
|
155
|
+
return convertAtPrice(borrowAmountInt, 'debtToCollateral', 'ceil', collateralPrice, debtAssetId, collateralAssetId);
|
|
152
156
|
}
|
|
153
157
|
/**
|
|
154
158
|
* Raw debt yielded by raw collateral at a price. Integer floor so the
|
|
155
159
|
* borrow never exceeds what the collateral covers.
|
|
156
160
|
*/
|
|
157
161
|
function borrowAmountForCollateral(collateralAmountInt, collateralPrice, debtAssetId = null, collateralAssetId = null) {
|
|
158
|
-
|
|
159
|
-
const factors = resolvePriceFactors(collateralPrice, debtAssetId, collateralAssetId);
|
|
160
|
-
if (collRaw === null || collRaw <= 0 || factors === null)
|
|
161
|
-
return null;
|
|
162
|
-
const { baseAmount, quoteAmount, orientation } = factors;
|
|
163
|
-
if (orientation === 'legacy-reversed') {
|
|
164
|
-
return Math.floor((Number(collateralAmountInt) * quoteAmount) / baseAmount);
|
|
165
|
-
}
|
|
166
|
-
return Math.floor((Number(collateralAmountInt) * baseAmount) / quoteAmount);
|
|
162
|
+
return convertAtPrice(collateralAmountInt, 'collateralToDebt', 'floor', collateralPrice, debtAssetId, collateralAssetId);
|
|
167
163
|
}
|
|
168
164
|
/**
|
|
169
165
|
* Raw debt yielded by a raw collateral budget, never exceeding the requested
|
|
@@ -173,7 +169,7 @@ function borrowAmountForCollateral(collateralAmountInt, collateralPrice, debtAss
|
|
|
173
169
|
* accept op).
|
|
174
170
|
*/
|
|
175
171
|
function capBorrowToCollateral(requestedBorrowInt, availableCollateralInt, collateralPrice, debtAssetId = null, collateralAssetId = null) {
|
|
176
|
-
const requested =
|
|
172
|
+
const requested = toFiniteNumber(requestedBorrowInt, null);
|
|
177
173
|
if (requested === null || requested <= 0)
|
|
178
174
|
return null;
|
|
179
175
|
if (availableCollateralInt === null || availableCollateralInt === undefined)
|
|
@@ -189,7 +185,7 @@ function capBorrowToCollateral(requestedBorrowInt, availableCollateralInt, colla
|
|
|
189
185
|
*/
|
|
190
186
|
function creditDealCollateralRatio(debtFloat, collateralFloat, rate) {
|
|
191
187
|
const debt = positiveOrNull(debtFloat);
|
|
192
|
-
const coll =
|
|
188
|
+
const coll = toFiniteNumber(collateralFloat, null);
|
|
193
189
|
const price = positiveOrNull(rate);
|
|
194
190
|
if (debt === null || coll === null || coll < 0 || price === null)
|
|
195
191
|
return null;
|
|
@@ -206,7 +202,7 @@ function averageCollateralRatio(entries) {
|
|
|
206
202
|
let valueSum = 0;
|
|
207
203
|
for (const entry of entries || []) {
|
|
208
204
|
const debt = positiveOrNull(entry?.debt);
|
|
209
|
-
const value =
|
|
205
|
+
const value = toFiniteNumber(entry?.value, null);
|
|
210
206
|
if (debt === null || value === null || value < 0)
|
|
211
207
|
continue;
|
|
212
208
|
debtSum += debt;
|
|
@@ -222,9 +218,9 @@ function averageCollateralRatio(entries) {
|
|
|
222
218
|
* a zero daily rate never exceeds maxFeeRatePerDay).
|
|
223
219
|
*/
|
|
224
220
|
function dailyOfferFeeRate(offer, feeDenom) {
|
|
225
|
-
const feeRate =
|
|
226
|
-
const maxDurationSeconds =
|
|
227
|
-
const denom =
|
|
221
|
+
const feeRate = toFiniteNumber(offer?.fee_rate, null);
|
|
222
|
+
const maxDurationSeconds = toFiniteNumber(offer?.max_duration_seconds, null);
|
|
223
|
+
const denom = toFiniteNumber(feeDenom, null);
|
|
228
224
|
if (feeRate === null || maxDurationSeconds === null || denom === null || feeRate <= 0 || maxDurationSeconds <= 0 || denom <= 0) {
|
|
229
225
|
return 0;
|
|
230
226
|
}
|
|
@@ -235,9 +231,9 @@ function dailyOfferFeeRate(offer, feeDenom) {
|
|
|
235
231
|
* (repay * feeRate + denom - 1) / denom. Zero when nothing is owed.
|
|
236
232
|
*/
|
|
237
233
|
function creditDealFee(repayAmountInt, feeRate, feeDenom) {
|
|
238
|
-
const repayRaw =
|
|
239
|
-
const rateRaw =
|
|
240
|
-
const denomRaw =
|
|
234
|
+
const repayRaw = toFiniteNumber(repayAmountInt, null);
|
|
235
|
+
const rateRaw = toFiniteNumber(feeRate, null);
|
|
236
|
+
const denomRaw = toFiniteNumber(feeDenom, null);
|
|
241
237
|
if (repayRaw === null || rateRaw === null || denomRaw === null || denomRaw <= 0)
|
|
242
238
|
return 0;
|
|
243
239
|
const repay = BigInt(Math.max(0, Math.trunc(repayRaw)));
|
|
@@ -198,6 +198,13 @@ declare class CreditRuntime {
|
|
|
198
198
|
_enforceMaxBorrowAmount(policy: UnknownRecord, borrowInt: unknown, debtAsset: UnknownRecord, options?: UnknownRecord): void;
|
|
199
199
|
_getCreditDebtForAsset(asset: unknown): number;
|
|
200
200
|
_getCreditCollateralForAsset(asset: unknown): number;
|
|
201
|
+
/**
|
|
202
|
+
* Sum a raw credit-deal amount across all deals matching `asset` on the
|
|
203
|
+
* given asset-id field, converted to float at the asset's precision.
|
|
204
|
+
* Shared by the debt and collateral totals (see _getCreditDebtForAsset and
|
|
205
|
+
* _getCreditCollateralForAsset).
|
|
206
|
+
*/
|
|
207
|
+
_sumCreditFieldForAsset(asset: unknown, assetField: string, amountField: string): number;
|
|
201
208
|
_getCollateralPercentageBase(accountId: unknown, assetId: unknown): Promise<number | null>;
|
|
202
209
|
_enforceMaxCollateralAmount(policy: UnknownRecord, collateralInt: unknown, collateralAsset: UnknownRecord, accountId: unknown, options?: UnknownRecord): Promise<void>;
|
|
203
210
|
_calculateDailyFeeRate(offer: UnknownRecord): number;
|
|
@@ -934,21 +934,23 @@ class CreditRuntime {
|
|
|
934
934
|
}
|
|
935
935
|
}
|
|
936
936
|
_getCreditDebtForAsset(asset) {
|
|
937
|
-
|
|
938
|
-
const deals = Array.isArray(this.state?.creditDeals) ? this.state.creditDeals : [];
|
|
939
|
-
return deals.reduce((sum, deal) => {
|
|
940
|
-
if (String(deal?.debtAssetId) === String(assetId)) {
|
|
941
|
-
return sum + (blockchainAmountToFloat(deal?.debtAmount, asset) || 0);
|
|
942
|
-
}
|
|
943
|
-
return sum;
|
|
944
|
-
}, 0);
|
|
937
|
+
return this._sumCreditFieldForAsset(asset, 'debtAssetId', 'debtAmount');
|
|
945
938
|
}
|
|
946
939
|
_getCreditCollateralForAsset(asset) {
|
|
940
|
+
return this._sumCreditFieldForAsset(asset, 'collateralAssetId', 'collateralAmount');
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Sum a raw credit-deal amount across all deals matching `asset` on the
|
|
944
|
+
* given asset-id field, converted to float at the asset's precision.
|
|
945
|
+
* Shared by the debt and collateral totals (see _getCreditDebtForAsset and
|
|
946
|
+
* _getCreditCollateralForAsset).
|
|
947
|
+
*/
|
|
948
|
+
_sumCreditFieldForAsset(asset, assetField, amountField) {
|
|
947
949
|
const assetId = asset?.id ?? asset;
|
|
948
950
|
const deals = Array.isArray(this.state?.creditDeals) ? this.state.creditDeals : [];
|
|
949
951
|
return deals.reduce((sum, deal) => {
|
|
950
|
-
if (String(deal?.
|
|
951
|
-
return sum + (blockchainAmountToFloat(deal?.
|
|
952
|
+
if (String(deal?.[assetField]) === String(assetId)) {
|
|
953
|
+
return sum + (blockchainAmountToFloat(deal?.[amountField], asset) || 0);
|
|
952
954
|
}
|
|
953
955
|
return sum;
|
|
954
956
|
}, 0);
|
|
@@ -1868,58 +1870,7 @@ class CreditRuntime {
|
|
|
1868
1870
|
? options.autoRepay
|
|
1869
1871
|
: (policyHasAutoRepay ? reborrowPolicy.autoRepay : (dealSummary.autoRepay ?? false)));
|
|
1870
1872
|
const offer = await this._getOfferById(dealSummary.offerId);
|
|
1871
|
-
|
|
1872
|
-
try {
|
|
1873
|
-
const acceptOp = await this.buildCreditOfferAcceptOperation({
|
|
1874
|
-
offer,
|
|
1875
|
-
borrowAmount: reborrowAmount,
|
|
1876
|
-
collateralAmount: reborrowCollateralAmount,
|
|
1877
|
-
autoRepay: autoRepaySetting,
|
|
1878
|
-
specificPolicy: options.specificPolicy,
|
|
1879
|
-
pendingRepayAmount: repayAmount,
|
|
1880
|
-
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1881
|
-
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1882
|
-
});
|
|
1883
|
-
operations.push(acceptOp);
|
|
1884
|
-
inlineReborrowPlanned = true;
|
|
1885
|
-
}
|
|
1886
|
-
catch (err) {
|
|
1887
|
-
const fallback = await this._selectFallbackCreditOffer({
|
|
1888
|
-
debtAssetId: dealSummary.debtAssetId,
|
|
1889
|
-
collateralAssetId: effectiveCollateralAssetId,
|
|
1890
|
-
policy: reborrowPolicy,
|
|
1891
|
-
borrowAmount: reborrowAmount,
|
|
1892
|
-
collateralAmount: reborrowCollateralAmount,
|
|
1893
|
-
autoRepay: autoRepaySetting,
|
|
1894
|
-
pendingRepayAmount: repayAmount,
|
|
1895
|
-
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1896
|
-
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1897
|
-
excludeOfferId: dealSummary.offerId,
|
|
1898
|
-
});
|
|
1899
|
-
if (fallback) {
|
|
1900
|
-
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected after original offer ${dealSummary.offerId} failed: ${getErrorMessage(err)}`);
|
|
1901
|
-
operations.push(fallback.op);
|
|
1902
|
-
inlineReborrowPlanned = true;
|
|
1903
|
-
}
|
|
1904
|
-
else {
|
|
1905
|
-
deferredReborrowRequest = {
|
|
1906
|
-
sourceDealId: dealSummary.id,
|
|
1907
|
-
offerId: dealSummary.offerId,
|
|
1908
|
-
borrowAmount: reborrowAmount,
|
|
1909
|
-
collateralAmount: reborrowCollateralAmount,
|
|
1910
|
-
autoRepay: autoRepaySetting,
|
|
1911
|
-
specificPolicy: reborrowPolicy,
|
|
1912
|
-
preRepayDealIds,
|
|
1913
|
-
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1914
|
-
pendingRepayAmount: repayAmount,
|
|
1915
|
-
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1916
|
-
requestedAt: nowIso(),
|
|
1917
|
-
reason: getErrorMessage(err),
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
else {
|
|
1873
|
+
const selectFallbackReborrow = async (deferReason, selectionNote) => {
|
|
1923
1874
|
const fallback = await this._selectFallbackCreditOffer({
|
|
1924
1875
|
debtAssetId: dealSummary.debtAssetId,
|
|
1925
1876
|
collateralAssetId: effectiveCollateralAssetId,
|
|
@@ -1933,26 +1884,47 @@ class CreditRuntime {
|
|
|
1933
1884
|
excludeOfferId: dealSummary.offerId,
|
|
1934
1885
|
});
|
|
1935
1886
|
if (fallback) {
|
|
1936
|
-
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected
|
|
1887
|
+
this.warn(`credit runtime: fallback reborrow offer ${fallback.offer.id} selected ${selectionNote}`);
|
|
1937
1888
|
operations.push(fallback.op);
|
|
1938
1889
|
inlineReborrowPlanned = true;
|
|
1890
|
+
return;
|
|
1939
1891
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1892
|
+
deferredReborrowRequest = {
|
|
1893
|
+
sourceDealId: dealSummary.id,
|
|
1894
|
+
offerId: dealSummary.offerId,
|
|
1895
|
+
borrowAmount: reborrowAmount,
|
|
1896
|
+
collateralAmount: reborrowCollateralAmount,
|
|
1897
|
+
autoRepay: autoRepaySetting,
|
|
1898
|
+
specificPolicy: reborrowPolicy,
|
|
1899
|
+
preRepayDealIds,
|
|
1900
|
+
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1901
|
+
pendingRepayAmount: repayAmount,
|
|
1902
|
+
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1903
|
+
requestedAt: nowIso(),
|
|
1904
|
+
reason: deferReason,
|
|
1905
|
+
};
|
|
1906
|
+
};
|
|
1907
|
+
if (offer) {
|
|
1908
|
+
try {
|
|
1909
|
+
const acceptOp = await this.buildCreditOfferAcceptOperation({
|
|
1910
|
+
offer,
|
|
1944
1911
|
borrowAmount: reborrowAmount,
|
|
1945
1912
|
collateralAmount: reborrowCollateralAmount,
|
|
1946
1913
|
autoRepay: autoRepaySetting,
|
|
1947
|
-
specificPolicy:
|
|
1948
|
-
preRepayDealIds,
|
|
1949
|
-
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1914
|
+
specificPolicy: options.specificPolicy,
|
|
1950
1915
|
pendingRepayAmount: repayAmount,
|
|
1951
1916
|
pendingReleaseCollateralAmount: options.pendingReleaseCollateralAmount,
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1917
|
+
availableCollateralAmount: availableReborrowCollateralInt,
|
|
1918
|
+
});
|
|
1919
|
+
operations.push(acceptOp);
|
|
1920
|
+
inlineReborrowPlanned = true;
|
|
1955
1921
|
}
|
|
1922
|
+
catch (err) {
|
|
1923
|
+
await selectFallbackReborrow(getErrorMessage(err), `after original offer ${dealSummary.offerId} failed: ${getErrorMessage(err)}`);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
else {
|
|
1927
|
+
await selectFallbackReborrow('offer unavailable', `because original offer ${dealSummary.offerId} is unavailable`);
|
|
1956
1928
|
}
|
|
1957
1929
|
}
|
|
1958
1930
|
const result = await this.executeOperations(operations, 'credit repay');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface NodeHealthLedgerEntry {
|
|
2
2
|
failureCount: number;
|
|
3
3
|
blacklistedUntil: number;
|
|
4
4
|
lastReportedAt: number;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
interface NodeHealthLedgerOptions {
|
|
7
7
|
/** Override the shared health-cache file (tests). Defaults to the shared cache. */
|
|
8
8
|
healthCacheFile?: string;
|
|
9
9
|
/** Override the failure threshold (tests). Defaults to NODE_MANAGEMENT.BLACKLIST_THRESHOLD. */
|
|
@@ -18,7 +18,7 @@ export interface NodeHealthLedgerOptions {
|
|
|
18
18
|
debug?: Function;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
interface NodeHealthLedger {
|
|
22
22
|
/** Whether the node is currently blacklisted (cooldown active). */
|
|
23
23
|
isBlacklisted(nodeUrl: string): boolean;
|
|
24
24
|
/** Report a failed node rotation; counts toward the blacklist threshold. */
|
|
@@ -29,4 +29,5 @@ export interface NodeHealthLedger {
|
|
|
29
29
|
clear(): void;
|
|
30
30
|
}
|
|
31
31
|
export declare function createNodeHealthLedger(options?: NodeHealthLedgerOptions): NodeHealthLedger;
|
|
32
|
+
export {};
|
|
32
33
|
//# sourceMappingURL=daemon_node_health.d.ts.map
|