Skip to content

critical: fix stroops conversion in creditline client amount encoding #61

Description

@EmeditWeb

Problem

In creditline.client.ts (lines 111-113), toContractAmount() uses BigInt(Math.round(value * 100)) — a 2-decimal multiplier. The entire rest of the codebase uses 7 decimal places (stroops, multiplier=10,000,000). This means the create_loan XDR will have amounts that are 100,000x smaller than intended. A $1,000 loan would be sent as 0.01 XLM.

User impact: Loan amounts built by the API are 100,000x too small. Loans would be funded at fractions of a cent instead of the requested dollar amount. This is a critical financial bug.

Before Starting

Read: context/architecture-context.md, context/code-standards.md

Root Cause

The creditline client was implemented with the wrong decimal precision. The liquidity client, sponsors service, and transaction checker all use 10_000_000n (stroops) correctly.

What To Build

  1. Change multiplier from 100 to 10_000_000 in toContractAmount()
  2. Verify all callers of buildCreateLoanTransaction expect stroops
  3. Add a unit test for toContractAmount with known values
  4. Verify the event parser's stroops conversion matches

Files To Touch

  • src/modules/stellar/clients/creditline.client.ts — line 113 fix multiplier

Acceptance Criteria

  • toContractAmount uses 10,000,000 multiplier
  • $1,000.00 → 10,000,000,000 stroops
  • Build passes
  • Existing tests pass

Mandatory Checks

  • context/ files read
  • npm run build passes
  • npm test passes, count not decreased
  • PR references this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions