Problem
Financial calculations use JavaScript Number in amount validation, fee calculation, quote conversion, risk scoring, and daily-limit aggregation. Binary floating-point and mixed asset precision can create rounding errors or inconsistent policy decisions.
Outcome
All monetary calculations use explicit decimal arithmetic and asset-specific precision rules from input through settlement and reporting.
Scope
- Select one decimal representation/library and define rounding modes.
- Centralize asset precision and minimum/maximum amount rules.
- Replace Number-based fee, quote, total, and limit calculations.
- Reject values with excessive precision before side effects.
- Define database serialization and API response conventions.
- Reconcile any existing values that violate the new precision policy.
Relevant files
- apps/api/src/utils/validators.js
- apps/api/src/payment/payment.orchestrator.js
- apps/api/src/pricing/pricing.service.js
- apps/api/src/compliance/compliance.service.js
- apps/api/src/wallet/stellar.adapter.js
- apps/api/prisma/schema.prisma
Acceptance criteria
- Calculations are deterministic for XLM, USDC, and configured fiat currencies.
- Values such as 0.1 + 0.2 do not produce binary rounding artifacts.
- Unsupported precision is rejected before a transaction row or Stellar submission.
- Fees and compliance totals use the same rounding policy.
- Boundary, rounding, and high-value cases have automated tests.
Problem
Financial calculations use JavaScript Number in amount validation, fee calculation, quote conversion, risk scoring, and daily-limit aggregation. Binary floating-point and mixed asset precision can create rounding errors or inconsistent policy decisions.
Outcome
All monetary calculations use explicit decimal arithmetic and asset-specific precision rules from input through settlement and reporting.
Scope
Relevant files
Acceptance criteria