Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • A Ahad Mobile
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • holatech
  • Ahad Mobile
  • Merge requests
  • !94

fix(lending): let repay-all clear a crypto loan when the wallet misses only dust

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Khanh Pham requested to merge fix/lending-repay-max-wallet-short into develop Oct 04, 2026
  • Overview 0
  • Commits 2
  • Pipelines 1
  • Changes 3

Problem

Found on staging while preparing the client test: borrow 0.001 ETH, then "Pay now / repay all" (max: true). Interest makes the debt 0.0010000003 while the wallet holds exactly 0.001, so the repay died with a raw 400 Lending journal would drive USER_CRYPTO(...) negative. A borrower who only holds the principal could never clear a crypto loan with repay-all.

Fix

  • Crypto max repay: when the wallet is short and capacity - round_down(wallet) < debtDust[symbol], repay the wallet balance; settlement's existing DUST write-off clears the remainder. Anything larger is refused (no use of the forgive cap, which could be farmed).
  • Crypto wallet-short failures now return 409 INSUFFICIENT_WALLET_BALANCE (already handled by the FE), like the fiat rail.
  • Wallet row read under lock via LendingJournalService.lockUserWalletBalance (same pair inversion as SupplyService.requestSupply).

Tests

repay.postgres.spec.ts 38/38, borrow.postgres.spec.ts 40/40 (throwaway DB), eslint + build clean, mutation-checked.

Review gate (Opus): PASS after 2 rounds (round 1 removed the forgive-cap branch).

🤖 Generated with Claude Code

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: fix/lending-repay-max-wallet-short