Skip to content

Use exact decimal arithmetic for payments, fees, quotes, and limits #154

Description

@Gozirimdev

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.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaigncomplianceSendAm backlog: compliancecoreMoney-path code — maintainer-driven, extra reviewdifficulty: hardComplex work with security, architecture, migration, or cross-system riskpaymentsSendAm backlog: paymentspricingSendAm backlog: pricingpriority: criticalSendAm backlog: priority: critical

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions