Problem
The RepaymentInstallment struct in contracts/creditline-contract/src/types.rs carries no due_date, and repay_installment() does not penalize late payments. Borrowers can effectively pay months late with zero consequence, which breaks the reputation score's underlying assumption that on-time payment matters.
Context
Late fees are the protocol's only economic enforcement mechanism short of liquidation. Without them, sponsors price all risk into the base APR, hurting on-time learners. The fee must flow back into the liquidity pool so sponsors are made whole.
Before Starting
Read these context files first:
- context/architecture-context.md
- context/code-standards.md
- context/progress-tracker.md
- contracts/creditline-contract/src/types.rs
- contracts/creditline-contract/src/lib.rs
What To Build
- Add
pub due_date: u64 to RepaymentInstallment in types.rs. Populate at loan creation: due_date = approval_ts + (n+1) * installment_period_secs.
- Add
pub late_fee_bps: u32 to ProtocolParameters in types.rs, default 500 bps (5%).
- In
repay_installment(), compute now = env.ledger().timestamp(). If now > installment.due_date, compute late_fee = installment.amount * late_fee_bps / 10_000 and require the caller to transfer installment.amount + late_fee.
- Route the late fee to the liquidity pool via cross-contract call, not the borrower's loan balance.
- Emit a
LATEFEEPAID event with (loan_id, installment_index, fee_amount).
- Add 4 unit tests: on-time path (no fee), 1-day-late, exact-due-date boundary, custom-bps test.
Files To Touch
contracts/creditline-contract/src/types.rs
contracts/creditline-contract/src/lib.rs
contracts/creditline-contract/src/storage.rs
contracts/creditline-contract/src/events.rs
contracts/creditline-contract/src/tests.rs
Acceptance Criteria
Mandatory Checks Before PR
Problem
The
RepaymentInstallmentstruct incontracts/creditline-contract/src/types.rscarries nodue_date, andrepay_installment()does not penalize late payments. Borrowers can effectively pay months late with zero consequence, which breaks the reputation score's underlying assumption that on-time payment matters.Context
Late fees are the protocol's only economic enforcement mechanism short of liquidation. Without them, sponsors price all risk into the base APR, hurting on-time learners. The fee must flow back into the liquidity pool so sponsors are made whole.
Before Starting
Read these context files first:
What To Build
pub due_date: u64toRepaymentInstallmentintypes.rs. Populate at loan creation:due_date = approval_ts + (n+1) * installment_period_secs.pub late_fee_bps: u32toProtocolParametersintypes.rs, default 500 bps (5%).repay_installment(), computenow = env.ledger().timestamp(). Ifnow > installment.due_date, computelate_fee = installment.amount * late_fee_bps / 10_000and require the caller to transferinstallment.amount + late_fee.LATEFEEPAIDevent with(loan_id, installment_index, fee_amount).Files To Touch
contracts/creditline-contract/src/types.rscontracts/creditline-contract/src/lib.rscontracts/creditline-contract/src/storage.rscontracts/creditline-contract/src/events.rscontracts/creditline-contract/src/tests.rsAcceptance Criteria
due_dateis set on every installment at loan creationlate_fee_bpsis configurable and persisted inProtocolParametersnow == due_dateis on-time)due_dateare gracefully handled (assume 0 = on-time)Mandatory Checks Before PR