Skip to content

feat: implement interest accrual and last_update_timestamp#92

Open
Mrwicks00 wants to merge 1 commit intoCreditra:mainfrom
Mrwicks00:feature/interest-accrual
Open

feat: implement interest accrual and last_update_timestamp#92
Mrwicks00 wants to merge 1 commit intoCreditra:mainfrom
Mrwicks00:feature/interest-accrual

Conversation

@Mrwicks00
Copy link

Pull Request: Implement interest accrual logic and last_update_timestamp

Title: feat: implement interest accrual and last_update_timestamp
Branch: feature/interest-accrual
Base: main

Description

This PR implements the interest accrual logic for Soroban credit lines as specified in issue #8. Utilized debt now grows over time based on the interest_rate_bps and the time elapsed since the last_update_timestamp.

Closes #8

Changes Made

  • Data Model: Added last_update_timestamp to CreditLineData.
  • Accrual Logic: Implemented compute_accrued_interest helper to calculate interest using overflow-safe arithmetic (i128) and a simple interest model (linear in time).
  • Accrual Helper: Implemented update_accrued_interest to dynamically add interest to utilized_amount and update the last_update_timestamp.
  • Integration: Integrated the update_accrued_interest helper before relevant storage accesses in:
    • draw_credit
    • repay_credit
    • update_risk_parameters
  • Read Operations: Integrated compute_accrued_interest into get_credit_line so queries reflect real-time effective debt.
  • Testing:
    • Validated backwards compatibility with all existing contract flows.
    • Added new comprehensive tests specifically simulating linear time passage for interest accrual:
      • test_interest_accrual
      • test_interest_accrual_zero_rate
      • test_interest_accrual_large_time (tests 10-year span of simple interest calculation).
  • Maintained minimum 95% test coverage.

Verification

Tests have been run locally using cargo test -p creditra-credit. All tests passed successfully.

@Mrwicks00
Copy link
Author

@greatest0fallt1me please check

@greatest0fallt1me
Copy link
Contributor

resolve the conflict

@greatest0fallt1me
Copy link
Contributor

@Mrwicks00

@greatest0fallt1me
Copy link
Contributor

@Mrwicks00 please resolve the conflicts

@greatest0fallt1me
Copy link
Contributor

@Mrwicks00 Can you resolve the conflicts?

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.

Implement interest accrual logic and last_update_timestamp

2 participants