Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to undo repayments for fully repaid loans #69

Merged
merged 9 commits into from
Feb 17, 2025

Conversation

EvgeniiZaitsevCW
Copy link
Collaborator

@EvgeniiZaitsevCW EvgeniiZaitsevCW commented Feb 14, 2025

Main changes

  1. The ability to undo repayments of fully repaid loans has been added.
  2. The undoRepaymentFor() function can now accept unrounded repaymentAmount parameter values. This change has been introduce to properly undo final repayments of loans. The final repayment is one that caused closing of a loan.
  3. To properly undo a final repayment the caller must provide the tracked balance of the loan before the repayment instead of the final repayment amount. To get the right tracked balance the following steps should be used:
    • a. Determine the block of the final repayment: B.
    • b. Determine the timestamp of the B block: BT.
    • c. Determine the timestamp in the timezone of the lending contract: BTZ. E.g. for America/Sao_Paulo timezone: BTZ = BT - 3 * 60 * 60.
    • d. Call the getLoanPreview() function at the B-1 block with the BTZ timestamp: getLoanPreview(loanId, BTZ).
    • e. Use the trackedBalance field of the returned structure as the repaymentAmount parameter of the undoRepaymentFor() function to undo the final repayment.
  4. The recommended algorithm for selecting the value of parameter repaymentAmount of function undoRepaymentFor():
    • a. If the being undone repayment is NOT a final one use its repayment amount as the value.
    • b. Otherwise the repayment is a final one and so use the tracked balance of the loan before the repayment as the value. See the previous point for details.
  5. The new onBeforeLoanReopened() hook function has been added to the credit line smart contract. It is called when a final repayment is being undone to check the loan can be reopened according to the current borrowing policy. If the loan cannot be reopened (e.g. the maxBorrowedAmount limit of all loans of the borrower is reached) the function will be returned with an appropriate error and the whole blockchain transaction will be reverted as well.

Versioning

The smart contracts version has been updated to v1.12.0.

Test Coverage

The new changes have been fully covered by tests.

Test coverage details
File % Stmts % Branch % Funcs % Lines
contracts/ 100.00 100.00 100.00 100.00
├─ CreditLine.sol 100.00 100.00 100.00 100.00
├─ CreditLineStorage.sol 100.00 100.00 100.00 100.00
├─ LendingMarket.sol 100.00 100.00 100.00 100.00
├─ LendingMarketStorage.sol 100.00 100.00 100.00 100.00
├─ LiquidityPool.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolStorage.sol 100.00 100.00 100.00 100.00
contracts/base/ 100.00 100.00 100.00 100.00
├─ AccessControlExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ PausableExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ UUPSExtUpgradeable.sol 100.00 100.00 100.00 100.00
├─ Versionable.sol 100.00 100.00 100.00 100.00
contracts/interfaces/ 100.00 100.00 100.00 100.00
├─ ICreditLine.sol 100.00 100.00 100.00 100.00
├─ ICreditLineTypes.sol 100.00 100.00 100.00 100.00
├─ ILendingMarket.sol 100.00 100.00 100.00 100.00
├─ ILiquidityPool.sol 100.00 100.00 100.00 100.00
├─ IVersionable.sol 100.00 100.00 100.00 100.00
contracts/libraries/ 100.00 98.00 100.00 100.00
├─ ABDKMath64x64.sol 100.00 97.73 100.00 100.00
├─ Constants.sol 100.00 100.00 100.00 100.00
├─ Error.sol 100.00 100.00 100.00 100.00
├─ InterestMath.sol 100.00 100.00 100.00 100.00
├─ Loan.sol 100.00 100.00 100.00 100.00
├─ Rounding.sol 100.00 100.00 100.00 100.00
├─ SafeCast.sol 100.00 100.00 100.00 100.00
contracts/mocks/ 100.00 100.00 100.00 100.00
├─ ABDKMath64x64Mock.sol 100.00 100.00 100.00 100.00
├─ AccessControlExtUpgradeableMock.sol 100.00 100.00 100.00 100.00
├─ CreditLineMock.sol 100.00 100.00 100.00 100.00
├─ ERC20Mock.sol 100.00 100.00 100.00 100.00
├─ LendingMarketMock.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolMock.sol 100.00 100.00 100.00 100.00
├─ PausableExtUpgradeableMock.sol 100.00 100.00 100.00 100.00
├─ RoundingMock.sol 100.00 100.00 100.00 100.00
├─ UUPSExtUpgradableMock.sol 100.00 100.00 100.00 100.00
contracts/testables/ 100.00 100.00 100.00 100.00
├─ CreditLineTestable.sol 100.00 100.00 100.00 100.00
├─ LendingMarketTestable.sol 100.00 100.00 100.00 100.00
├─ LiquidityPoolTestable.sol 100.00 100.00 100.00 100.00
----------------------------------------- ---------- ---------- ---------- ----------
All files 100.00 99.80 100.00 100.00
----------------------------------------- ---------- ---------- ---------- ----------

@igorsenych-cw igorsenych-cw merged commit 81df40b into main Feb 17, 2025
7 checks passed
@igorsenych-cw igorsenych-cw deleted the undo-repayments-for-closed-loans branch February 17, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants