Skip to content

fix stroops conversion in creditline client amount encoding#89

Open
khaylebfortune wants to merge 1 commit into
StepFi-app:mainfrom
khaylebfortune:fix-stroop
Open

fix stroops conversion in creditline client amount encoding#89
khaylebfortune wants to merge 1 commit into
StepFi-app:mainfrom
khaylebfortune:fix-stroop

Conversation

@khaylebfortune

Copy link
Copy Markdown
Contributor

Description

Fixes a critical financial bug where toContractAmount() in creditline.client.ts used a 2-decimal multiplier (100) instead of the 7-decimal stroop multiplier (10,000,000) used by the rest of the codebase. This caused loan amounts in create_loan XDR to be 100,000x too small (e.g., a $1,000 loan was sent as 0.01 XLM instead of 1,000 XLM).

Root Cause

The toContractAmount private method at src/stellar/contracts/clients/creditline.client.ts:111-113 was implemented with BigInt(Math.round(value * 100)) — a 2-decimal multiplier. The liquidity client, sponsors service, event parser, and transaction checker all correctly use 10_000_000 (stroops).

Changes

File Change
src/stellar/contracts/clients/creditline.client.ts Changed multiplier from 100 to 10_000_000 in toContractAmount()
test/unit/stellar/contracts/clients/creditline.client.spec.ts New unit test with 6 cases covering known values

Verification

  • $1,000.00 → 10,000,000,000 stroops (previously 100,000)
  • $1.00 → 10,000,000 stroops
  • $0.01 → 100,000 stroops
  • Rounds to nearest stroop correctly
  • npm run build
  • npm test: 25 suites, 294 tests passed (up from 288)

Closes #61

The creditline client's toContractAmount() used a 2-decimal multiplier
(100) instead of the 7-decimal stroop multiplier (10,000,000) used
by the entire codebase, causing loan amounts in create_loan XDR to be
100,000x too small.

- Change multiplier from 100 to 10_000_000 in toContractAmount()
- Add unit test with 6 cases covering ,000, , /bin/bash.50, /bin/bash.01,
  rounding behavior, and zero

Closes StepFi-app#61
@khaylebfortune khaylebfortune changed the title fix: correct toContractAmount multiplier from 100 to 10,000,000 stroops fix stroops conversion in creditline client amount encoding Jul 18, 2026
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.

critical: fix stroops conversion in creditline client amount encoding

1 participant