You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add maxBorrowAmountPerOperation and oversized-deal splitter
Adds a per-operation borrow cap to prevent single-credit-accept operations
from consuming too much of the total maxBorrowAmount at once, making
repay/reborrow cycles easier with less liquidity per operation.
## maxBorrowAmountPerOperation (new config field)
File: modules/types.ts
- New optional field on LendingEntryBase (shared by MPA and creditOffer).
- Enforced in buildCreditOfferAcceptOperation: any single borrow exceeding
the limit is rejected with a descriptive error.
- isMaxBorrowAmountError widened to match both ceiling and per-op patterns.
File: modules/bot_settings.ts
- Validation: must be a positive number.
## MPA planner capping
File: modules/cr_planner.ts
- buildDebtFirstCrPlan clamps debtDelta by maxBorrowAmountPerOperation
on top of the total maxBorrowAmount cap.
## _splitOversizedCreditDeals (new feature)
File: modules/credit_runtime.ts
- Phase 0 of _runCreditMaintenance: scans creditOffer deals where
individual debt exceeds maxBorrowAmountPerOperation.
- Splits oversized deals into N equal pieces via atomic repay+reborrow
transactions, keeping total debt unchanged.
- min_deal_amount guard: skips deals where a piece would be below the
offer's minimum deal size.
- MAX_PIECES_PER_CYCLE (48, from TIMING constant) prevents unbounded
cycles that would exceed the watchdog interval.
- 6s settle delay between pieces with shutdown abort (T1).
- _splitInFlight concurrency guard (T2) prevents runMaintenance /
runCreditWatchdog collisions.
- Canonical settle-delay resolution matching dexbot_maintenance_runtime.ts
(T3). Note: per-bot TIMING.BLOCKCHAIN_SETTLE_DELAY_MS in bots.json is
no longer honoured for split pacing.
File: tests/test_credit_runtime.ts
- 6 new tests: per-op rejection, offer-selection capping, correct
split arithmetic, within-limit skip, no-limit skip, error-pattern match.
## Risk/edge-case notes
- T3 settleDelay resolution changed from bot.config.TIMING to the imported
TIMING constant — see CHANGELOG.
- Offer min_deal_amount is cached; stale values are possible if the offer
is edited on-chain mid-split (rare).
- T1 shutdown check fires once at the start of each 6s wait; worst case
is one extra piece of post-shutdown activity (matches existing pattern).
## Validation
- npm run typecheck: clean
- npm test: all 38 credit runtime tests pass, full suite clean
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
9
9
-**Fix**: correct AMA4 slowPeriod from 107.4 to 102.4 — aligns AMA4 with the same λ=0.0025 refit applied to AMA1-3 in v1.1.3. Fixes stale slowPeriod references in market_adapter/README.md, test fixtures, and TradingView chart generator (`modules/constants.ts`, `market_adapter/README.md`, `tests/test_market_adapter_log_format.ts`, `tests/test_market_adapter_logic.ts`, `analysis/tradingview/tradingview_uplot_chart_generator.ts`).
10
10
-**Feat**: narrow optimizer slow search range from 50-200 to 40-160 — focuses the geometric grid on the range where fitted winners consistently land, reducing wasted evaluations at uncompetitive extremes (`analysis/ama_fitting/optimizer_high_resolution.ts`).
11
11
-**Docs**: sync v1.1.3 release notes with amaS% retune (0.085→0.08), update DYNAMIC_WEIGHT_RESEARCH.md knob table, correct EVOLUTION.md commit count for v1.1.3 (2→4) and summary to include the amaS% retune (`CHANGELOG.md`, `analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md`, `docs/EVOLUTION.md`).
12
+
-**Feat**: add `maxBorrowAmountPerOperation` config field and `_splitOversizedCreditDeals` — when a credit deal exceeds `maxBorrowAmountPerOperation`, maintenance splits it into equal pieces via repay+reborrow cycles with 6s spacing (`modules/types.ts`, `modules/bot_settings.ts`, `modules/credit_runtime.ts`, `modules/cr_planner.ts`).
13
+
-**Fix**: settle-delay resolution for credit splits now reads from the `TIMING` constant instead of `bot.config.TIMING.BLOCKCHAIN_SETTLE_DELAY_MS` — consistent with `dexbot_maintenance_runtime.ts`. Any per-bot `TIMING.BLOCKCHAIN_SETTLE_DELAY_MS` override in `bots.json` is no longer honoured for split pacing (`modules/credit_runtime.ts`).
0 commit comments