Skip to content

core: settle installment repayments to liquidity pool in creditline #57

Description

@EmeditWeb

Problem

repay_installment() in creditline-contract (lib.rs:755-813) marks
installments paid and decrements remaining_balance, but it never moves
any tokens and never calls the liquidity pool. Compare repay_loan()
(lib.rs:701-704) which correctly calls
lp_client.receive_repayment(principal, interest) and transfers USDC.

As a result a borrower can drive a loan all the way to LoanStatus::Paid
through installments without any USDC ever leaving their wallet, and
LPs earn zero yield on the installment repayment path. This is a
critical accounting and value-loss bug in the primary repayment flow.

Before Starting

Read ALL of these before writing any code:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md

What To Build

Make repay_installment() a real settlement operation, symmetric with
repay_loan():

  1. Pull the installment amount in USDC from the borrower into the
    contract (token transfer with require_auth).
  2. Split the paid amount into principal vs interest (see the
    repayment-waterfall issue) and forward it to the pool via
    LiquidityPoolContractClient::receive_repayment(principal, interest)
    so locked_liquidity is reduced and interest raises share price.
  3. Only transition to LoanStatus::Paid once real funds have settled.
  4. Keep all state effects before external calls (checks-effects-interactions)
    and inside the existing non-reentrant guard.

Files To Touch

  • contracts/creditline-contract/src/lib.rs (repay_installment)
  • contracts/creditline-contract/src/tests.rs

Acceptance Criteria

  • repay_installment() transfers USDC from borrower to contract
  • Interest portion routed to pool via receive_repayment
  • Pool locked_liquidity decreases by the principal repaid
  • Loan reaches Paid only after funds settle on-chain
  • Reentrancy guard and CEI ordering preserved
  • Tests assert token balances and pool share-price movement end to end

Mandatory Checks Before Opening PR

  • All context/ files read and understood
  • context/progress-tracker.md updated
  • cargo build passes with zero errors
  • cargo test passes — test count not decreased
  • require_auth() first in every mutating function
  • extend_ttl() after every persistent storage write
  • No .unwrap()/.expect() in user-facing paths
  • PR references this issue number

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions