Skip to content

Add decimal-precision validation to the token formatting helpers in src/utils/token.ts #173

Description

@Jagadeeshftw

📌 Description

src/utils/token.ts formats token amounts using each token's decimals; if a token reports an unexpected decimals value (e.g. 0, negative, or absurdly large), formatting can silently produce a wrong or misleading amount.

🧩 Requirements and context

  • Validate that decimals is a non-negative integer within a sane bound (e.g. 0-30) before using it in formatting.
  • Throw or return a clear error for out-of-bound decimals rather than silently producing a malformed string.
  • Add regression tests for 0 decimals, very large decimals, and negative decimals.

🛠️ Suggested execution

  1. Add a decimals-bounds check at the top of the relevant formatting function(s) in src/utils/token.ts.
  2. Add/extend src/utils/token.test.ts for the new edge cases.

✅ Acceptance criteria

  • Out-of-bound decimals values raise a clear, typed error instead of producing a silently wrong formatted amount.
  • Valid decimals values (including 0) format correctly.

🔒 Security notes

Prevents a malicious/malformed token contract from causing a misleading displayed amount downstream.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueStellar WaveIssues in the Stellar wave programbackendBackend / API workbugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions