Skip to content

feat(SC-007): 75% LTV cap, 8% liquidation discount, HF>=1.0 rejection + interest/liquidation modules - #1712

Open
esthertitilayo-dev wants to merge 1 commit into
StellarDevHub:mainfrom
esthertitilayo-dev:fix/1628-lending-ltv-liquidation
Open

esthertitilayo-dev wants to merge 1 commit into
StellarDevHub:mainfrom
esthertitilayo-dev:fix/1628-lending-ltv-liquidation

Conversation

@esthertitilayo-dev

Copy link
Copy Markdown
Contributor

Closes #1628

Summary

  • New spec key files: contracts/lending_pool/src/interest.rs (pure next_index / accrued_principal per-second compounding math, unit-tested) and contracts/lending_pool/src/liquidation.rs (pure seize_amount liquidator-discount math, unit-tested). lib.rs accrue, accrue_user, and liquidate now delegate to them with identical arithmetic and typed-error mapping.
  • AC1 — 75% LTV cap: borrow_at_exactly_75pct_ltv_is_allowed / borrow_above_75pct_ltv_is_rejected (#6) under a pool configured with a hard 75% cap (collateral factor 7_500 BPS per the add_asset doc "Max LTV in BPS", HF boundary mcr = 10_000 → effective cap = exactly 75%).
  • AC2 — 8% liquidation discount: liquidate_seizes_collateral_with_8pct_discount runs a real SAC token (so balances are observable, unlike the no-op MockToken): liquidator repays 1_000 of underwater debt and receives exactly 1_080 collateral (1_000 × 1.08, liq_bonus = 800 BPS); borrower debt 20_000 → 19_000, collateral −1_080, pool balance reconciles to the unit.
  • AC3 — reject HF ≥ 1.0: liquidate_rejected_when_health_factor_exactly_one builds a position at the exact boundary (adj_coll == req_coll == 15_000) and liquidate_rejected_when_position_is_healthy for HF ≫ 1 — both revert with PositionHealthy (#8).
  • Bonus: wired the previously dead contracts/lending_pool/src/test.rs (was never declared as a module and wouldn't compile — referenced a nonexistent LOCK); fixed it to use the temporary RG_KEY guard, enabling 18 additional tests (deposit/repay/withdraw rejections, reentrancy, interest accrual, index-preservation).

Test plan

  • cargo test -p lending-pool — 40 lib tests + 2 fuzz tests pass (was 17 + 2 before this PR).
  • rustfmt --check clean on lib.rs, interest.rs, liquidation.rs, test.rs.

…StellarDevHub#1628)

- Add contracts/lending_pool/src/interest.rs (spec key file): pure
  next_index / accrued_principal index math with unit tests; accrue and
  accrue_user now delegate to it
- Add contracts/lending_pool/src/liquidation.rs (spec key file): pure
  seize_amount discount-bonus math with unit tests; liquidate delegates to it
- AC1: borrow-at-exactly-75% allowed and 75.01% rejected (#6) under a pool
  configured with a hard 75% LTV cap (coll factor 7_500, HF boundary 10_000)
- AC2: third-party liquidation seizes exactly repay x 1.08 with the 8%
  bonus (liq_bonus 800), asserted on a real SAC token for observable balances
- AC3: liquidation rejected (#8) at health factor exactly 1.0 and when HF > 1
- Wire previously dead contracts/lending_pool/src/test.rs (fixes its broken
  LOCK reference to use the temporary RG_KEY guard), enabling 18 more tests
@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

@esthertitilayo-dev is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@esthertitilayo-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SC-007] Over-Collateralized Lending Pool with Dynamic Health Factor & Liquidation Engine

1 participant