LoanManager — No Liquidation Mechanism for Under-Collateralized Loans#512
LoanManager — No Liquidation Mechanism for Under-Collateralized Loans#512nonso7 wants to merge 3 commits intoLabsCrypt:mainfrom
Conversation
|
The contracts CI is failing on the rustfmt format check. This isn't a logic issue, just formatting. Run this in the contracts directory and push: cd contracts
cargo fmtThen commit and push the formatting changes. The CI should pass after that. |
ogazboiz
left a comment
There was a problem hiding this comment.
Contracts CI is failing under 30 seconds, which is almost always a cargo fmt check. Run this from the contracts/ directory and commit the result:
cd contracts
cargo fmt
git add -A
git commit -m 'style: apply cargo fmt'
git push|
The codebase issues on main have been resolved and all CI checks are passing now. Please rebase your branch to pull in the latest changes before continuing. Thanks for your patience. |
ogazboiz
left a comment
There was a problem hiding this comment.
The liquidation mechanism design is solid and test coverage is good. Several issues to fix:
Must fix:
- Run `cargo fmt` to pass CI
- Resolve merge conflicts by rebasing onto latest main
- Replace `unwrap_or(0)` with proper error returns in `liquidate()`. If `checked_mul` overflows, the ratio becomes 0, which incorrectly flags any loan as liquidatable. This is a security issue.
- The `as u32` cast on `collateral_ratio_bps` will silently wrap around for massively over-collateralized loans. Use `try_into()` with error handling.
Should address:
5. The collateral ratio calculation assumes collateral and loan are the same token (divides amounts directly with no price oracle). If that's always true in this protocol, add a comment. If not, you need a price feed.
6. Outstanding debt is never cleared on liquidation. The loan moves to Liquidated status but the borrowed amount stays on the books. Decide if debt should be written off.
7. Move auth check before input validation in `set_liquidation_threshold` and `set_liquidation_bonus`.
Nice to have:
8. Add a test for liquidation when the contract is paused
9. Consider a credit score penalty for liquidated borrowers
|
Friendly reminder to rebase your branch onto the latest main and address the review feedback when you get a chance. The codebase had some fixes recently so a rebase is needed before we can move forward. Let me know if you need help. |
|
heads up, a few important changes just landed on main that affect your PR:
please rebase on latest main: git fetch upstream
git rebase upstream/main
git push --force-with-lease |
Closes #356