dexbot 1.6.14 → 1.6.15
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 +34 -4
- package/analysis/README.md +6 -6
- package/analysis/tradingview/README.md +2 -1
- package/claw/README.md +7 -7
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +80 -6
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +36 -2
- package/dist/dexbot.js +23 -3
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +26 -11
- package/dist/modules/account_bots.d.ts +3 -0
- package/dist/modules/account_bots.js +3 -0
- package/dist/modules/bitshares-native/subscriptions.js +1 -1
- package/dist/modules/bot_defaults.d.ts +13 -2
- package/dist/modules/bot_defaults.js +31 -2
- package/dist/modules/bot_settings.js +3 -0
- package/dist/modules/constants.d.ts +6 -0
- package/dist/modules/constants.js +24 -0
- package/dist/modules/credit_runtime.d.ts +35 -5
- package/dist/modules/credit_runtime.js +219 -38
- package/dist/modules/dexbot_class.d.ts +19 -1
- package/dist/modules/dexbot_class.js +58 -20
- package/dist/modules/dexbot_cow_runtime.js +19 -18
- package/dist/modules/dexbot_fill_runtime.d.ts +1 -1
- package/dist/modules/dexbot_fill_runtime.js +4 -7
- package/dist/modules/dexbot_maintenance_runtime.d.ts +7 -2
- package/dist/modules/dexbot_maintenance_runtime.js +52 -7
- package/dist/modules/dexbot_startup_runtime.js +3 -2
- package/dist/modules/dexbot_state_recovery.js +1 -1
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/grid.d.ts +118 -1
- package/dist/modules/order/grid.js +292 -50
- package/dist/modules/order/grid_reconcile.js +4 -3
- package/dist/modules/order/grid_reconcile_internal.js +13 -18
- package/dist/modules/order/index.d.ts +3 -1
- package/dist/modules/order/manager.d.ts +1 -0
- package/dist/modules/order/manager.js +5 -14
- package/dist/modules/order/sync_engine.js +18 -9
- package/dist/modules/order/utils/math.d.ts +98 -26
- package/dist/modules/order/utils/math.js +177 -57
- package/dist/modules/order/utils/order.js +16 -4
- package/dist/modules/order/utils/system.js +2 -2
- package/dist/modules/order/utils/validate.d.ts +1 -1
- package/dist/modules/order/utils/validate.js +48 -58
- package/dist/modules/types.d.ts +7 -0
- package/dist/scripts/analyze-credit.js +44 -27
- package/dist/scripts/diagnose-pool-history.js +35 -30
- package/dist/scripts/pnl.js +1 -1
- package/dist/scripts/rich_list.d.ts +18 -0
- package/dist/scripts/rich_list.js +461 -0
- package/dist/scripts/run-tests.js +80 -4
- package/dist/unlock.d.ts +2 -1
- package/dist/unlock.js +4 -3
- package/docs/COW_INVARIANTS.md +6 -0
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +10 -9
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/LOGGING.md +16 -1
- package/docs/MPA_CREDIT_USAGE.md +10 -5
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +159 -9
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +56 -2
- package/docs/developer_guide.md +5 -1
- package/market_adapter/README.md +4 -4
- package/modules/README.md +1 -1
- package/package.json +2 -1
- package/scripts/README.md +59 -32
- package/tests/README.md +11 -2
|
@@ -79,14 +79,16 @@ function computeHuberWindowSlopePct(amaValues, index, lookbackBars, hub = AMA_SL
|
|
|
79
79
|
return null;
|
|
80
80
|
// Local linear fit needs the full window at both ends; reject non-positive
|
|
81
81
|
// values anywhere in the window (Number(null) is 0) before fitting.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
// The window is exactly [index - bars, index], so n is known up front and
|
|
83
|
+
// y can be pre-sized (no per-bar push growth).
|
|
84
|
+
const n = bars + 1;
|
|
85
|
+
const y = new Array(n);
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
const v = Number(amaValues[index - bars + i]);
|
|
85
88
|
if (!Number.isFinite(v) || v <= 0)
|
|
86
89
|
return null;
|
|
87
|
-
y
|
|
90
|
+
y[i] = Math.log(v);
|
|
88
91
|
}
|
|
89
|
-
const n = y.length;
|
|
90
92
|
// Fill any missing field from the canonical constant. Production never passes
|
|
91
93
|
// `hub` (the default is the constant), so this only guards a partial override
|
|
92
94
|
// from silently skipping the IRLS loop or injecting NaN weights.
|
|
@@ -116,18 +118,31 @@ function computeHuberWindowSlopePct(amaValues, index, lookbackBars, hub = AMA_SL
|
|
|
116
118
|
const a = sw === 0 ? 0 : (swy - b * swx) / sw;
|
|
117
119
|
return { a, b };
|
|
118
120
|
};
|
|
119
|
-
|
|
121
|
+
// Scratch buffers are reused across the IRLS passes instead of allocating a
|
|
122
|
+
// fresh resid/abs/w triple (plus the sort copy) every iteration. This is the
|
|
123
|
+
// per-bar hot path of the dynamic-weight series, so the allocations dominate
|
|
124
|
+
// the fit arithmetic at the 16-bar window. The loops keep the original
|
|
125
|
+
// operation order so the returned slope is bit-for-bit unchanged.
|
|
126
|
+
const ones = new Array(n).fill(1);
|
|
127
|
+
const resid = new Array(n);
|
|
128
|
+
const abs = new Array(n);
|
|
129
|
+
const w = new Array(n);
|
|
130
|
+
let fit = wls(ones); // OLS initialisation
|
|
120
131
|
for (let iter = 0; iter < hubIterations; iter++) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
132
|
+
for (let i = 0; i < n; i++)
|
|
133
|
+
resid[i] = y[i] - (fit.a + fit.b * (i - xMean));
|
|
134
|
+
for (let i = 0; i < n; i++)
|
|
135
|
+
abs[i] = Math.abs(resid[i]);
|
|
136
|
+
abs.sort((p, q) => p - q);
|
|
137
|
+
const mid = n >> 1;
|
|
138
|
+
const mad = n % 2 === 1 ? abs[mid] : (abs[mid - 1] + abs[mid]) / 2;
|
|
125
139
|
// Floor the robust scale. On piecewise-perfect data (a pure ramp, a
|
|
126
140
|
// constant series) the MAD can collapse to ~0, which makes the Huber
|
|
127
141
|
// weights degenerate and the weighted fit unstable; the floor is far
|
|
128
142
|
// below any real per-bar signal (the reset gate is ~7e-5 here).
|
|
129
143
|
const s = Math.max(1.4826 * mad, hubScaleFloor);
|
|
130
|
-
|
|
144
|
+
for (let i = 0; i < n; i++)
|
|
145
|
+
w[i] = Math.min(1, (hubC * s) / Math.max(Math.abs(resid[i]), 1e-12));
|
|
131
146
|
const next = wls(w);
|
|
132
147
|
const moved = Math.abs(next.b - fit.b);
|
|
133
148
|
fit = next;
|
|
@@ -157,6 +157,8 @@ declare function loadGeneralSettings(): {
|
|
|
157
157
|
FILL_TOTALS_RETRY_MAX_MS: number;
|
|
158
158
|
SPREAD_STALE_WARN_MS: number;
|
|
159
159
|
SPREAD_STALE_ESCALATE_MS: number;
|
|
160
|
+
SPREAD_CORRECTION_MAX_ATTEMPTS: number;
|
|
161
|
+
SPREAD_STALE_TRANSIENT_GRACE: number;
|
|
160
162
|
SPREAD_CORRECTION_SYNC_FRESH_MS: number;
|
|
161
163
|
SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
|
|
162
164
|
BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
|
|
@@ -393,6 +395,7 @@ declare function loadGeneralSettings(): {
|
|
|
393
395
|
FILL_PROCESSING: {
|
|
394
396
|
MODE: string;
|
|
395
397
|
OPERATION_TYPE: number;
|
|
398
|
+
COALESCE_BACKLOG_REPLAY: boolean;
|
|
396
399
|
MAX_CONSECUTIVE_CONSUMER_FAILURES: number;
|
|
397
400
|
CONSUMER_BACKOFF_INITIAL_MS: number;
|
|
398
401
|
CONSUMER_BACKOFF_MAX_MS: number;
|
|
@@ -1743,6 +1743,9 @@ async function main() {
|
|
|
1743
1743
|
saveBotsConfig(config, filePath);
|
|
1744
1744
|
result.commitAdapter?.();
|
|
1745
1745
|
console.log(`\nAdded bot '${result.data.name}' to ${path.basename(filePath)}.`);
|
|
1746
|
+
// Return to the Actions menu instead of immediately
|
|
1747
|
+
// opening another blank New Bot editor.
|
|
1748
|
+
break;
|
|
1746
1749
|
}
|
|
1747
1750
|
catch (err) {
|
|
1748
1751
|
console.log(`\n❌ Invalid input: ${getErrorMessage(err)}\n`);
|
|
@@ -1079,7 +1079,7 @@ function createSubscriptionManager(chainClient, overrides = {}) {
|
|
|
1079
1079
|
// already armed by handleNotice cursor advances and by
|
|
1080
1080
|
// resubscribeEntry/resubscribeAll on disconnects. Poll does NOT arm
|
|
1081
1081
|
// unconditionally — that would turn every 60s tick into a 40-page
|
|
1082
|
-
// re-fetch forever (~80 pages/min
|
|
1082
|
+
// re-fetch forever (~80 pages/min across several tracked accounts). If a gap-recovery
|
|
1083
1083
|
// fetch previously threw, _gapRecovery stays true and the next poll
|
|
1084
1084
|
// will run the lookback; otherwise this tick is just a plain >cursor
|
|
1085
1085
|
// scan with no lookback. Eager gap-recovery scheduled in handleNotice
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* Mode rules are pinned by tests/test_bot_defaults_characterization.ts and
|
|
19
19
|
* tests/test_bot_defaults_parity.ts — update them together with this file.
|
|
20
20
|
*/
|
|
21
|
-
import type { UnknownRecord } from './types.js';
|
|
21
|
+
import type { UnknownRecord, BotMetrics } from './types.js';
|
|
22
22
|
interface SeedOptions {
|
|
23
23
|
/** Defaults source; omit to use the merged DEFAULT_CONFIG. */
|
|
24
24
|
defaults?: UnknownRecord;
|
|
@@ -27,7 +27,9 @@ interface SeedOptions {
|
|
|
27
27
|
* DEFAULT_CONFIG keys the draft seed must NEVER add. Seeding these would change
|
|
28
28
|
* persisted bots.json bytes for existing bots and pre-satisfy
|
|
29
29
|
* `validateBotEntry`'s required-key check (assetA/assetB), hiding genuine
|
|
30
|
-
* configuration mistakes from the validator.
|
|
30
|
+
* configuration mistakes from the validator. `activeOrders`/`reserveOrders` are
|
|
31
|
+
* legacy aliases migrated to `coreOrders`/`edgeOrders`, kept here so an older
|
|
32
|
+
* general.settings.json that still carries them does not fail the parity guard.
|
|
31
33
|
*/
|
|
32
34
|
export declare const DRAFT_EXCLUDED_KEYS: string[];
|
|
33
35
|
/**
|
|
@@ -100,5 +102,14 @@ export declare function seedBotEntry<T extends UnknownRecord>(entry: T, options?
|
|
|
100
102
|
* (the historical shallow spread aliased every nested default object).
|
|
101
103
|
*/
|
|
102
104
|
export declare function seedBotRuntimeConfig(config?: UnknownRecord, options?: SeedOptions): UnknownRecord;
|
|
105
|
+
/**
|
|
106
|
+
* Fresh zeroed metrics for the bot and its order manager. Both layers used to
|
|
107
|
+
* declare the shared counters independently, so a new shared counter had to be
|
|
108
|
+
* added twice (and could drift). The manager spreads this base and adds its own
|
|
109
|
+
* runtime-only counters (lock stats, sync timing, start time); the bot uses it
|
|
110
|
+
* verbatim. Single source of truth for the shared `BotMetrics` defaults.
|
|
111
|
+
* @returns {Object} A new metrics object with every shared counter zeroed
|
|
112
|
+
*/
|
|
113
|
+
export declare function createDefaultBotMetrics(): BotMetrics;
|
|
103
114
|
export {};
|
|
104
115
|
//# sourceMappingURL=bot_defaults.d.ts.map
|
|
@@ -23,9 +23,11 @@ import { DEFAULT_CONFIG } from './constants.js';
|
|
|
23
23
|
* DEFAULT_CONFIG keys the draft seed must NEVER add. Seeding these would change
|
|
24
24
|
* persisted bots.json bytes for existing bots and pre-satisfy
|
|
25
25
|
* `validateBotEntry`'s required-key check (assetA/assetB), hiding genuine
|
|
26
|
-
* configuration mistakes from the validator.
|
|
26
|
+
* configuration mistakes from the validator. `activeOrders`/`reserveOrders` are
|
|
27
|
+
* legacy aliases migrated to `coreOrders`/`edgeOrders`, kept here so an older
|
|
28
|
+
* general.settings.json that still carries them does not fail the parity guard.
|
|
27
29
|
*/
|
|
28
|
-
export const DRAFT_EXCLUDED_KEYS = ['assetA', 'assetB', 'creditOnly', 'min_BTS_value'];
|
|
30
|
+
export const DRAFT_EXCLUDED_KEYS = ['assetA', 'assetB', 'creditOnly', 'min_BTS_value', 'activeOrders', 'reserveOrders'];
|
|
29
31
|
/**
|
|
30
32
|
* Draft seed order — kept identical to the historical if-chain so a freshly
|
|
31
33
|
* created bot's JSON key order does not change. Together with
|
|
@@ -188,4 +190,31 @@ export function seedBotRuntimeConfig(config = {}, options = {}) {
|
|
|
188
190
|
}
|
|
189
191
|
return out;
|
|
190
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Fresh zeroed metrics for the bot and its order manager. Both layers used to
|
|
195
|
+
* declare the shared counters independently, so a new shared counter had to be
|
|
196
|
+
* added twice (and could drift). The manager spreads this base and adds its own
|
|
197
|
+
* runtime-only counters (lock stats, sync timing, start time); the bot uses it
|
|
198
|
+
* verbatim. Single source of truth for the shared `BotMetrics` defaults.
|
|
199
|
+
* @returns {Object} A new metrics object with every shared counter zeroed
|
|
200
|
+
*/
|
|
201
|
+
export function createDefaultBotMetrics() {
|
|
202
|
+
return {
|
|
203
|
+
fillsProcessed: 0,
|
|
204
|
+
batchesExecuted: 0,
|
|
205
|
+
fillProcessingTimeMs: 0,
|
|
206
|
+
lockContentionEvents: 0,
|
|
207
|
+
maxQueueDepth: 0,
|
|
208
|
+
gridLockContention: 0,
|
|
209
|
+
fundRecalcCount: 0,
|
|
210
|
+
refusedCommitCount: 0,
|
|
211
|
+
orphanFillCreditedCount: 0,
|
|
212
|
+
restampBuyAboveAnchorCount: 0,
|
|
213
|
+
boundaryDriftExceedsWindowCount: 0,
|
|
214
|
+
gapBandPlacementShadowCount: 0,
|
|
215
|
+
spreadCorrectionRefusedCount: 0,
|
|
216
|
+
spreadCorrectionRefusalCauses: {},
|
|
217
|
+
spreadCorrectionRetryCount: 0
|
|
218
|
+
};
|
|
219
|
+
}
|
|
191
220
|
//# sourceMappingURL=bot_defaults.js.map
|
|
@@ -277,6 +277,9 @@ function validateBotEntry(b, i, src) {
|
|
|
277
277
|
if ('renewOnly' in item && typeof item.renewOnly !== 'boolean') {
|
|
278
278
|
problems.push(`debtPolicy.lending[${idx}].renewOnly must be a boolean`);
|
|
279
279
|
}
|
|
280
|
+
if ('useFreeCollateral' in item && typeof item.useFreeCollateral !== 'boolean') {
|
|
281
|
+
problems.push(`debtPolicy.lending[${idx}].useFreeCollateral must be a boolean`);
|
|
282
|
+
}
|
|
280
283
|
if ('allowedOfferIds' in item) {
|
|
281
284
|
if (!Array.isArray(item.allowedOfferIds)) {
|
|
282
285
|
problems.push(`debtPolicy.lending[${idx}].allowedOfferIds must be an array`);
|
|
@@ -225,6 +225,8 @@ declare let TIMING: {
|
|
|
225
225
|
FILL_TOTALS_RETRY_MAX_MS: number;
|
|
226
226
|
SPREAD_STALE_WARN_MS: number;
|
|
227
227
|
SPREAD_STALE_ESCALATE_MS: number;
|
|
228
|
+
SPREAD_CORRECTION_MAX_ATTEMPTS: number;
|
|
229
|
+
SPREAD_STALE_TRANSIENT_GRACE: number;
|
|
228
230
|
SPREAD_CORRECTION_SYNC_FRESH_MS: number;
|
|
229
231
|
SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
|
|
230
232
|
BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
|
|
@@ -332,6 +334,7 @@ declare let API_LIMITS: {
|
|
|
332
334
|
declare let FILL_PROCESSING: {
|
|
333
335
|
MODE: string;
|
|
334
336
|
OPERATION_TYPE: number;
|
|
337
|
+
COALESCE_BACKLOG_REPLAY: boolean;
|
|
335
338
|
MAX_CONSECUTIVE_CONSUMER_FAILURES: number;
|
|
336
339
|
CONSUMER_BACKOFF_INITIAL_MS: number;
|
|
337
340
|
CONSUMER_BACKOFF_MAX_MS: number;
|
|
@@ -765,6 +768,8 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
765
768
|
FILL_TOTALS_RETRY_MAX_MS: number;
|
|
766
769
|
SPREAD_STALE_WARN_MS: number;
|
|
767
770
|
SPREAD_STALE_ESCALATE_MS: number;
|
|
771
|
+
SPREAD_CORRECTION_MAX_ATTEMPTS: number;
|
|
772
|
+
SPREAD_STALE_TRANSIENT_GRACE: number;
|
|
768
773
|
SPREAD_CORRECTION_SYNC_FRESH_MS: number;
|
|
769
774
|
SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
|
|
770
775
|
BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
|
|
@@ -1001,6 +1006,7 @@ declare function buildDefaultGeneralSettings(): {
|
|
|
1001
1006
|
FILL_PROCESSING: {
|
|
1002
1007
|
MODE: string;
|
|
1003
1008
|
OPERATION_TYPE: number;
|
|
1009
|
+
COALESCE_BACKLOG_REPLAY: boolean;
|
|
1004
1010
|
MAX_CONSECUTIVE_CONSUMER_FAILURES: number;
|
|
1005
1011
|
CONSUMER_BACKOFF_INITIAL_MS: number;
|
|
1006
1012
|
CONSUMER_BACKOFF_MAX_MS: number;
|
|
@@ -330,6 +330,20 @@ let TIMING = {
|
|
|
330
330
|
// by moving the boundary). Time-based so it holds for any tick cadence.
|
|
331
331
|
SPREAD_STALE_WARN_MS: 10 * 60 * 1000, // 10 minutes
|
|
332
332
|
SPREAD_STALE_ESCALATE_MS: 30 * 60 * 1000, // 30 minutes
|
|
333
|
+
// SPREAD_CORRECTION_MAX_ATTEMPTS: bounded attempts for one spread-correction
|
|
334
|
+
// cycle (initial broadcast + fresh-master re-plan retries). Kept next to the
|
|
335
|
+
// other SPREAD_* tunables so the retry budget is centralized; a value < 1
|
|
336
|
+
// falls back to 2. Overridable per deployment under TIMING in
|
|
337
|
+
// profiles/general.settings.json (TIMING is a shallow-merged section).
|
|
338
|
+
SPREAD_CORRECTION_MAX_ATTEMPTS: 2,
|
|
339
|
+
// SPREAD_STALE_TRANSIENT_GRACE: consecutive TRANSIENT spread-correction
|
|
340
|
+
// refusals (stale plan / duplicate CREATE / unclassified non-execution)
|
|
341
|
+
// tolerated before the out-of-spread watchdog stops treating them as
|
|
342
|
+
// retryable and lets the persistent-stale clock escalate to a structural
|
|
343
|
+
// re-center. checkSpreadCondition's bounded re-plan heals most transient
|
|
344
|
+
// refusals in-cycle; the grace keeps a genuinely deadlocked transient from
|
|
345
|
+
// hiding behind the retry path forever.
|
|
346
|
+
SPREAD_STALE_TRANSIENT_GRACE: 3,
|
|
333
347
|
// SPREAD_CORRECTION_SYNC_FRESH_MS: how old the last completed open-orders
|
|
334
348
|
// sync may be before a spread-correction CREATE loses its LAST-FILL-GUARD
|
|
335
349
|
// bypass. A stale local snapshot (old sync or known-unmatched chain
|
|
@@ -863,6 +877,16 @@ let FILL_PROCESSING = {
|
|
|
863
877
|
// NOTE: fill/broadcast batch sizing is derived from the grid gap-slot
|
|
864
878
|
// count (DEXBot._getGapSlotBatchSize). There is deliberately no fixed
|
|
865
879
|
// fill-batch or ops-per-broadcast constant here.
|
|
880
|
+
// COALESCE_BACKLOG_REPLAY: when true, a fill backlog larger than the
|
|
881
|
+
// gap-slot batch size is planned as ONE reconcile instead of the default
|
|
882
|
+
// chunked replay (each chunk mutating the boundary before broadcasting).
|
|
883
|
+
// Reuses the existing unified-plan path; the boundary-shift budget and
|
|
884
|
+
// _getMaxOpsPerBroadcast still bound the shift and split the broadcast
|
|
885
|
+
// into gapSlots+1-op transactions, so this only removes the intermediate
|
|
886
|
+
// plan/broadcast cycles (Stale-Restart #5). Default OFF: opt-in rollout
|
|
887
|
+
// for the live boundary engine, overridable per bot via
|
|
888
|
+
// `fillProcessing.COALESCE_BACKLOG_REPLAY` in general settings.
|
|
889
|
+
COALESCE_BACKLOG_REPLAY: false,
|
|
866
890
|
// MAX_CONSECUTIVE_CONSUMER_FAILURES: Threshold for the _consumeFillQueue
|
|
867
891
|
// watchdog. Below this count, the consumer re-schedules on every failure
|
|
868
892
|
// via setImmediate. At or above this count, the consumer switches to
|
|
@@ -253,16 +253,46 @@ declare class CreditRuntime {
|
|
|
253
253
|
*/
|
|
254
254
|
_getFreeDebtAssetBalance(debtAssetId: unknown, debtAsset: UnknownRecord | null): Promise<number | null>;
|
|
255
255
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
256
|
+
* Read the chain-free balance of a collateral asset. Mirrors
|
|
257
|
+
* `_getFreeDebtAssetBalance`; returns null when it cannot be determined.
|
|
258
|
+
*/
|
|
259
|
+
_getFreeCollateralBalance(collateralAssetId: unknown, collateralAsset: UnknownRecord | null): Promise<number | null>;
|
|
260
|
+
/**
|
|
261
|
+
* Highest raw collateral this deal's position may hold, from the position's
|
|
262
|
+
* `assignedCollateralBudget`. The renewed deal is one member of the
|
|
263
|
+
* position, so its ceiling is the budget minus the collateral the position's
|
|
264
|
+
* other deals already hold. Returns null when no budget is known.
|
|
265
|
+
*/
|
|
266
|
+
_positionCollateralCapInt(dealSummary: DealSummary | UnknownRecord | null, collateralAsset: UnknownRecord | null, releasedInt: number): number | null;
|
|
267
|
+
/**
|
|
268
|
+
* Raw collateral available to a reborrow, as `{ released, budget }`:
|
|
269
|
+
* - `released` — the portion freed by this repay (the collateral floor),
|
|
270
|
+
* - `budget` — the ceiling the new accept may lock: the released portion
|
|
271
|
+
* plus the borrower's free balance of the same asset (when
|
|
272
|
+
* `useFreeCollateral` is on, the default), bounded by the
|
|
273
|
+
* position's `assignedCollateralBudget`.
|
|
274
|
+
* Precedence for `released`:
|
|
258
275
|
* 1. explicit raw `options.availableCollateralAmount` (collateral-switch flow),
|
|
259
276
|
* 2. exact on-chain `floor(repay * collateral / debt)` when the deal's own
|
|
260
277
|
* collateral asset is used,
|
|
261
278
|
* 3. explicit `options.pendingReleaseCollateralAmount` (float) as a fallback.
|
|
262
|
-
* Returns null when it cannot be determined, so
|
|
263
|
-
* legacy (unclamped) behaviour.
|
|
279
|
+
* Returns `{ released: null, budget: null }` when it cannot be determined, so
|
|
280
|
+
* the accept builder keeps the legacy (unclamped) behaviour.
|
|
281
|
+
*/
|
|
282
|
+
_computeCollateralBudget(dealSummary: DealSummary | UnknownRecord | null, repayAmount: unknown, options: UnknownRecord): Promise<{
|
|
283
|
+
released: number | null;
|
|
284
|
+
budget: number | null;
|
|
285
|
+
}>;
|
|
286
|
+
/**
|
|
287
|
+
* Recompute a persisted pending reborrow's collateral budget from its stored
|
|
288
|
+
* released base, the current free balance, and the current position budget —
|
|
289
|
+
* not the snapshot taken when it was queued. If the free balance shrank after
|
|
290
|
+
* deferral the ceiling drops (no over-lock / on-chain failure); if it grew the
|
|
291
|
+
* ceiling rises (no unnecessary clamp). Entries without a released base —
|
|
292
|
+
* legacy ones and the collateral-switch flow, whose budget is the new asset's
|
|
293
|
+
* total balance, not freed collateral — keep their stored budget unchanged.
|
|
264
294
|
*/
|
|
265
|
-
|
|
295
|
+
_refreshReborrowBudget(request: UnknownRecord | null): Promise<number | null>;
|
|
266
296
|
/**
|
|
267
297
|
* Decide how much of a maturing deal can actually be repaid and reborrowed
|
|
268
298
|
* with the currently free debt-asset balance. The repay leg is funded from
|