Skip to content

fix: use stroopsToUnits in positions.ts to prevent precision loss above MAX_SAFE_INTEGER - #294

Merged
collinsezedike merged 1 commit into
mainfrom
fix/stroops-to-units-precision-positions
Jun 30, 2026
Merged

collinsezedike merged 1 commit into
mainfrom
fix/stroops-to-units-precision-positions

Conversation

@collinsezedike

@collinsezedike collinsezedike commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • computePosition in packages/stellar-sdk-helpers/src/positions.ts converted bigint stroops to display units via Number(x) / STROOPS_PER_UNIT, which silently loses precision for values above Number.MAX_SAFE_INTEGER (~922 trillion stroops, ~92M USDC)
  • stroopsToUnits in defindex.ts already handles this correctly using integer-safe arithmetic (bigint division for the whole part, then adding the fractional remainder as a float)
  • Replaced all three conversions (shares, deposited, earned) with stroopsToUnits and removed the now-unused STROOPS_PER_UNIT import

Test plan

  • pnpm lint && pnpm typecheck && pnpm test pass locally

Closes #276

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
meridian Ready Ready Preview, Comment Jun 30, 2026 7:03am

@collinsezedike
collinsezedike merged commit 252c4cd into main Jun 30, 2026
5 checks passed
@collinsezedike
collinsezedike deleted the fix/stroops-to-units-precision-positions branch June 30, 2026 07:04

This branch was successfully deployed

1 active deployment
Preview — 8d71baed Deployed Jun 30, 2026 by vercel[bot]
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.

[Fix] Use stroopsToUnits instead of Number division in positions.ts to prevent precision loss

1 participant