Per-position ltvBps was the only check on how much a vault could lend
out in aggregate -- a well-collateralized borrower (or several) could
grow totalDebtPrincipal arbitrarily large with nothing else gating it,
even though real risk management (oracle feed liquidity depth, how much
collateral could actually be sold to cover simultaneous liquidations)
bounds how large a single market can safely get. Adds an immutable
borrowCap (0 = unlimited, exact pre-existing behavior) that borrow()
checks against aggregate debt, same primitive Compound/Aave's per-market
borrow caps already ship.
- 5 new regression tests (sentinel disables feature, exact boundary,
aggregate across multiple borrowers, interest accrual never blocked):
57 -> 62/62 pass, zero regressions.
- New one-command scripts/borrow-cap-demo.sh proves the real boundary
against real deployed bytecode on a disposable anvil.
- Verified live on the persistent self-hosted demo chain
(http://130.61.180.42:8647) against a separate throwaway vault so the
public demo's own position was never touched: borrow() landing exactly
on a 1,000 TUSD cap succeeded (tx 0xc71dd5c4...), the next unit over
reverted with the real BorrowCapExceeded custom error.
- Redeployed the public demo with a real 100,000 TUSD cap and surfaced
it on /vault via a new "Borrow cap" stat, no wallet required.