caelum0x 53d8ece384 fix: stop credit-line term reset from shrinking by elapsed time on full repayment
AgentCreditPool.repay() reset the term window after a full repayment by
overwriting line.opened_at with the current time, then computing
due_timestamp as now + (due_timestamp - opened_at) — but opened_at had
already been overwritten by that point. The subtraction therefore used
the *new* opened_at instead of the original one, so the "fresh" term was
silently shrunk by however much of the old term had already elapsed
(e.g. repaying 10 days into a 30-day term produced a 20-day term instead
of a full fresh 30-day term). This undermines the stated behavior
("reset the term window after full repayment") and skews due_timestamp,
which feeds isOverdue()/liquidation timing.

Fix: capture the original term length (due_timestamp - opened_at) before
mutating opened_at, then apply it to the new opened_at.

Added test/agent_credit_pool.test.ts, which fails against the prior
code (asserts a 30-day term, prior code produced 20 days) and passes
with the fix. Full suite: 393/393 passing, tsc --noEmit clean.

This is the in-memory ledger simulation (lib/ledger/*), not the real
on-chain/x402 Algorand payment or signing path — no fund-moving or
key-handling logic was touched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-18 00:34:26 +03:00
..
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00