Skip to content

fix: stop normalizeMoneyAmount from silently truncating sub-cent Stellar amounts (Closes #439) - #464

Merged
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
s6pa1rta3n-lab:fix-issue-439
Sep 6, 2026
Merged

fix: stop normalizeMoneyAmount from silently truncating sub-cent Stellar amounts (Closes #439)#464
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
s6pa1rta3n-lab:fix-issue-439

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor

Summary

Fixes #439 by making normalizeMoneyAmount precision-aware instead of hard-coding 2 decimal places.

Key Changes

  • Preserves fractional digits up to 7 decimal places (Stellar stroops) by default, preventing sub-cent amounts like '0.0000001' and '0.0000009' from silently truncating to '0.00'.
  • Supports an explicit scale parameter (0-7) and NormalizeMoneyAmountOptions with optional round: boolean flag.
  • Strips leading zeros from the integer component (e.g., '0075.5' -> '75.50').
  • Validates target scale bounds and throws RangeError if scale < 0, scale > 7, or !Number.isInteger(scale).
  • Uses exact string and BigInt arithmetic to avoid IEEE-754 floating-point precision issues during rounding.
  • Comprehensive test coverage in tests/money-amount.test.ts for sub-cent amounts, custom scale, half-up rounding, RangeError boundaries, and compatibility with validateMoneyAmount.

Verification

  • npx vitest run tests/money-amount.test.ts tests/request-validation.test.ts: Passed (22/22 tests).
  • npx vitest run tests/models.test.ts tests/moneyamount-passthrough.test.ts tests/public-api-types.test.ts tests/validation.test.ts tests/payment-validation.test.ts: Passed (63/63 tests).
  • npx prettier --check src/models/common.ts tests/money-amount.test.ts: Passed.
  • npx eslint src/models/common.ts tests/money-amount.test.ts: Passed (0 errors, 0 warnings).
  • npx tsup: Build succeeded (ESM, CJS, and DTS bundles emitted).

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

@David-patrick-chuks-02
David-patrick-chuks-02 marked this pull request as ready for review September 6, 2026 09:30
@David-patrick-chuks-02
David-patrick-chuks-02 merged commit a836d1c into Lilly-Protocol:main Sep 6, 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.

[Bounty: $65] Stop normalizeMoneyAmount from silently truncating sub-cent Stellar amounts

3 participants