Repository navigation
fix(lending): prevent protocol fee collection from draining depositor collateral (#457) - #463
Open
huangji6693-max wants to merge 1 commit into
Conversation
|
@huangji6693-max is attempting to deploy a commit to the thisisouvik's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents
LendingContract::collect_feesfrom transferring depositor collateral to the treasury when the fee token is also a whitelisted collateral asset, and defers protocol fee accrual until loan repayment rather than booking unearned interest at loan request creation.Changes
contracts/lending/src/lib.rs:DataKey::TotalCollateral(Address)andget_total_collateral_for_asset(env, asset), updated indeposit_collateralandwithdraw_collateral.collect_feesto computeavailable_fees = token_client.balance(&contract_address).saturating_sub(collateral_total)and panic with"Insufficient unencumbered fee token balance to collect fees"ifavailable_fees < uncollected.UncollectedFeescrediting fromcreate_loan_requestand accruedloan.platform_feeinrecord_paymentwhen the loan reachesLoanStatus::Repaid.contracts/lending/src/test.rs:setup_fee_collectionto approve, activate, and repay the loan before collecting fees.test_collect_fees_cannot_drain_depositor_collateralandtest_collect_fees_succeeds_when_unencumbered_fee_tokens_cover_accrual.Verification
CARGO_BUILD_JOBS=2 cargo test --lib -- --test-threads=1incontracts/lending: 137 passedCloses #457