Skip to content

feat(contracts): implement dynamic liquidation bonding curve and bad debt socialization [SC-062] - #1992

Open
Anekenonso wants to merge 1 commit into
StellarDevHub:mainfrom
Anekenonso:feat/sc-062-lending-pool-bonding-curve-1859
Open

Anekenonso wants to merge 1 commit into
StellarDevHub:mainfrom
Anekenonso:feat/sc-062-lending-pool-bonding-curve-1859

Conversation

@Anekenonso

Copy link
Copy Markdown

Description

This PR implements [SC-062] Lending Pool Liquidation Incentive Bonding Curve & Bad Debt Socialization to eliminate delays in liquidating undercollateralized accounts during steep price declines and to safely socialize remaining deficits across protocol reserve funds when borrower collateral is depleted.

Key Changes

  1. Dynamic Liquidation Bonus Bonding Curve (contracts/lending_pool/src/liquidation.rs):

    • Implemented dynamic_liquidation_bonus(hf_bps) and dynamic_seize_amount(repay, debt_price, coll_price, hf_bps).
    • As health factor drops below 1.0 (10,000 BPS), the liquidation discount bonus scales along a linear bonding curve from 5% (500 BPS) up to 15% (1,500 BPS) when collateral is exhausted (HF <= 0).
    • Dynamic bonus calculation ensures liquidators are prioritized and incentivized to liquidate deeply underwater accounts rapidly.
  2. Protocol Reserves & Bad Debt Socialization (contracts/lending_pool/src/lib.rs):

    • Added protocol reserve tracking under Key::Reserves(token) and cumulative socialized debt under Key::TotalBadDebt(token).
    • Added deposit_reserves, reserves_of, and total_bad_debt entry points.
    • Added health_factor and current_liquidation_bonus views.
    • Automated bad debt socialization in liquidate(...): if a borrower position has zero collateral remaining after seizing (new_coll == 0) and outstanding debt remains (new_debt > 0), the deficit is absorbed by the protocol's reserve funds without touching user deposits.
    • Added a manual entry point socialize_bad_debt(...) allowing bad debt write-off against reserves for positions that have already reached 0 collateral.
  3. Property-Based Fuzz Testing (contracts/lending_pool/src/fuzz_lending_suite.rs & tests/fuzz_lending.rs):

    • Added multi-user continuous randomized fuzzing sequences covering deposits, borrows, repayments, withdrawals, dynamic liquidations, and reserve socialization.
    • Added proptest! invariants verifying total protocol assets (collateral + available reserves) strictly exceed total debt liabilities across randomized parameter spaces.

Verification

  • cargo fmt --check: Passed with 0 errors.
  • cargo test --lib: 52 tests passed, 0 failed.

Closes #1859

…debt socialization

- Implement dynamic liquidation bonus curve in liquidation.rs scaling from 5% to 15% as health factor drops below 1.0
- Add protocol reserve fund management and bad debt socialization across reserves
- Automatically socialize deficit when liquidating underwater positions with zero collateral
- Add property-based fuzz tests verifying total protocol assets >= total liabilities

Closes StellarDevHub#1859
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

@Anekenonso 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 Nov 25, 2026

Copy link
Copy Markdown

@Anekenonso 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-062] Lending Pool Liquidation Incentive Bonding Curve & Bad Debt Socialization

1 participant