fix stroops conversion in creditline client amount encoding#89
Open
khaylebfortune wants to merge 1 commit into
Open
fix stroops conversion in creditline client amount encoding#89khaylebfortune wants to merge 1 commit into
khaylebfortune wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a critical financial bug where
toContractAmount()increditline.client.tsused 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 increate_loanXDR 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
toContractAmountprivate method atsrc/stellar/contracts/clients/creditline.client.ts:111-113was implemented withBigInt(Math.round(value * 100))— a 2-decimal multiplier. The liquidity client, sponsors service, event parser, and transaction checker all correctly use10_000_000(stroops).Changes
src/stellar/contracts/clients/creditline.client.ts100to10_000_000intoContractAmount()test/unit/stellar/contracts/clients/creditline.client.spec.tsVerification
npm run build✅npm test: 25 suites, 294 tests passed (up from 288)Closes #61