dexbot 1.6.12 → 1.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -1
- 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 +2 -0
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/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 +2 -15
- 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 +1 -0
- package/dist/modules/account_bots.js +102 -121
- package/dist/modules/account_orders.d.ts +13 -0
- package/dist/modules/account_orders.js +38 -44
- 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/resolvers.js +22 -25
- 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 +2 -1
- package/dist/modules/bot_settings.d.ts +1 -1
- 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/constants.d.ts +7 -1
- package/dist/modules/constants.js +20 -1
- 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 +28 -17
- package/dist/modules/dexbot_class.js +105 -58
- package/dist/modules/dexbot_cow_runtime.d.ts +0 -7
- package/dist/modules/dexbot_cow_runtime.js +54 -28
- package/dist/modules/dexbot_credential_client.d.ts +0 -7
- package/dist/modules/dexbot_credential_client.js +1 -2
- package/dist/modules/dexbot_fill_runtime.d.ts +1 -2
- package/dist/modules/dexbot_fill_runtime.js +5 -6
- package/dist/modules/dexbot_maintenance_runtime.d.ts +20 -3
- package/dist/modules/dexbot_maintenance_runtime.js +84 -69
- package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
- package/dist/modules/dexbot_startup_runtime.js +13 -14
- package/dist/modules/general_settings.d.ts +1 -1
- package/dist/modules/graceful_shutdown.js +17 -11
- package/dist/modules/key_store.js +0 -1
- 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/format.d.ts +12 -3
- package/dist/modules/order/format.js +15 -3
- package/dist/modules/order/genesis_policy.d.ts +3 -3
- package/dist/modules/order/genesis_policy.js +5 -2
- package/dist/modules/order/grid.d.ts +4 -2
- package/dist/modules/order/grid.js +91 -35
- package/dist/modules/order/index.d.ts +1 -0
- package/dist/modules/order/logger.d.ts +1 -8
- package/dist/modules/order/logger.js +0 -9
- package/dist/modules/order/manager.d.ts +9 -13
- package/dist/modules/order/manager.js +33 -50
- package/dist/modules/order/utils/order.js +39 -35
- package/dist/modules/order/utils/system.d.ts +9 -29
- package/dist/modules/order/utils/system.js +17 -2
- package/dist/modules/order/utils/validate.js +2 -2
- package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
- package/dist/modules/paths.js +32 -34
- package/dist/modules/runtime_settings.d.ts +2 -4
- 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 +42 -27
- 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/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/run-tests.js +0 -1
- package/dist/scripts/sync-version.js +0 -10
- package/docs/BITSHARES_ONBOARDING.md +8 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +9 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +19 -10
- package/market_adapter/README.md +6 -4
- package/package.json +6 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +25 -10
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -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
|
|
@@ -67,8 +67,8 @@ import * as DexbotStartupRuntime from './dexbot_startup_runtime.js';
|
|
|
67
67
|
import cowRuntime from './dexbot_cow_runtime.js';
|
|
68
68
|
import type { ChainOrderLike, CowResult, OpPhase } from './dexbot_cow_runtime.js';
|
|
69
69
|
import { normalizeBotEntry } from './bot_settings.js';
|
|
70
|
-
import type { FillOpLike, FillLike,
|
|
71
|
-
import type { BotLike, AssetPair, IncomingFill,
|
|
70
|
+
import type { FillOpLike, FillLike, ReplaySafeFillAccountingOptions } from './dexbot_fill_runtime.js';
|
|
71
|
+
import type { BotLike, AssetPair, IncomingFill, UnknownRecord, GridConfig, OrderManagerLike, AccountOrdersLike, BotMetrics, ProcessedFillStoreLike, CreditRuntimeLike, FillBatchResult, SigningToken, SpreadCorrectionStall } from './types.js';
|
|
72
72
|
declare class DEXBot implements BotLike {
|
|
73
73
|
static normalizeBotEntry: typeof normalizeBotEntry;
|
|
74
74
|
config: GridConfig;
|
|
@@ -98,6 +98,7 @@ declare class DEXBot implements BotLike {
|
|
|
98
98
|
_credentialRecoveryNeeded: boolean;
|
|
99
99
|
_credentialRecoveryInFlight: boolean;
|
|
100
100
|
_credentialDaemonWatchdogInFlight: boolean;
|
|
101
|
+
_credentialDaemonConsecutiveFailures: number;
|
|
101
102
|
_staleCleanedOrderIds: Map<string, number>;
|
|
102
103
|
_staleCleanupRetentionMs: number;
|
|
103
104
|
_metrics: BotMetrics;
|
|
@@ -174,6 +175,7 @@ declare class DEXBot implements BotLike {
|
|
|
174
175
|
_postRecoveryRebalanceDefers: number;
|
|
175
176
|
_skipEmptyReadConfirmDelay: boolean;
|
|
176
177
|
_spreadFundsExhausted: boolean;
|
|
178
|
+
_spreadCorrectionStall: SpreadCorrectionStall | null;
|
|
177
179
|
_strandedHoldSince: Map<string, number>;
|
|
178
180
|
_structuralGridResyncDeferCount: number;
|
|
179
181
|
_structuralGridResyncDeferStartedAt: number;
|
|
@@ -404,12 +406,7 @@ declare class DEXBot implements BotLike {
|
|
|
404
406
|
* @param {string} [options.persistenceMode='batched']
|
|
405
407
|
* @returns {Promise<any>}
|
|
406
408
|
*/
|
|
407
|
-
_applyReplaySafeTrackedFillAccounting(fill: unknown, fillOp: FillOpLike,
|
|
408
|
-
context?: string;
|
|
409
|
-
logger?: Partial<ManagerLogger>;
|
|
410
|
-
replayMessage?: ReplayMessageFn;
|
|
411
|
-
persistenceMode?: string;
|
|
412
|
-
}): Promise<{
|
|
409
|
+
_applyReplaySafeTrackedFillAccounting(fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
|
|
413
410
|
status: string;
|
|
414
411
|
fillKey: any;
|
|
415
412
|
usedFallbackKey?: undefined;
|
|
@@ -436,12 +433,7 @@ declare class DEXBot implements BotLike {
|
|
|
436
433
|
* @param {string} [options.persistenceMode='batched']
|
|
437
434
|
* @returns {Promise<any>}
|
|
438
435
|
*/
|
|
439
|
-
_applyReplaySafeOrphanFillAccounting(fill: unknown, fillOp: FillOpLike,
|
|
440
|
-
context?: string;
|
|
441
|
-
logger?: Partial<ManagerLogger>;
|
|
442
|
-
replayMessage?: ReplayMessageFn;
|
|
443
|
-
persistenceMode?: string;
|
|
444
|
-
}): Promise<{
|
|
436
|
+
_applyReplaySafeOrphanFillAccounting(fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
|
|
445
437
|
status: string;
|
|
446
438
|
fillKey: any;
|
|
447
439
|
usedFallbackKey?: undefined;
|
|
@@ -803,6 +795,25 @@ declare class DEXBot implements BotLike {
|
|
|
803
795
|
* @returns {void}
|
|
804
796
|
*/
|
|
805
797
|
_setupCredentialDaemonWatchdogInterval(): void;
|
|
798
|
+
/**
|
|
799
|
+
* Consecutive failed watchdog probes required before the credential daemon
|
|
800
|
+
* is declared down. One-liner so the startup log and the probe decision
|
|
801
|
+
* can never disagree about the threshold.
|
|
802
|
+
* @returns {number} Positive integer threshold
|
|
803
|
+
*/
|
|
804
|
+
_credentialDaemonWatchdogFailureThreshold(): number;
|
|
805
|
+
/**
|
|
806
|
+
* Run a single credential-daemon watchdog health probe.
|
|
807
|
+
*
|
|
808
|
+
* A probe failure is only treated as a daemon outage after
|
|
809
|
+
* CREDENTIAL_DAEMON_WATCHDOG_FAILURE_THRESHOLD consecutive failures, so one
|
|
810
|
+
* transient timeout (daemon busy signing) never pauses writes or suspends
|
|
811
|
+
* grid persistence. A confirmed outage sets `_credentialRecoveryNeeded` so
|
|
812
|
+
* the successful-probe path CAN resume persistence — otherwise the
|
|
813
|
+
* suspension lasted until a process restart (production incident).
|
|
814
|
+
* @returns {Promise<void>}
|
|
815
|
+
*/
|
|
816
|
+
_runCredentialDaemonWatchdogProbe(): Promise<void>;
|
|
806
817
|
/**
|
|
807
818
|
* Stop the credential daemon watchdog interval.
|
|
808
819
|
* @returns {void}
|
|
@@ -964,9 +975,9 @@ declare class DEXBot implements BotLike {
|
|
|
964
975
|
* long region (e.g. the structural resync's Phase-2 placement) would
|
|
965
976
|
* starve indefinitely — which also keeps the maintenance idle gate shut
|
|
966
977
|
* forever (the queue-length check returns the full settle delay).
|
|
967
|
-
* Registered via addBroadcastRegionEndListener (fan-out)
|
|
968
|
-
*
|
|
969
|
-
*
|
|
978
|
+
* Registered via addBroadcastRegionEndListener (fan-out) so a second wirer
|
|
979
|
+
* can never silently displace the drain. Re-entry safe: the marker keeps
|
|
980
|
+
* repeated wiring idempotent.
|
|
970
981
|
*/
|
|
971
982
|
_wireBroadcastRegionEndDrain(): void;
|
|
972
983
|
/**
|