Skip to content

fix: use BigInt to prevent overflow when parsing large token amounts#305

Open
agentmila wants to merge 1 commit into
helius-labs:devfrom
agentmila:fix/token-amount-overflow
Open

fix: use BigInt to prevent overflow when parsing large token amounts#305
agentmila wants to merge 1 commit into
helius-labs:devfrom
agentmila:fix/token-amount-overflow

Conversation

@agentmila
Copy link
Copy Markdown

Bug

The token amount parser in account-data.ts uses parseInt() to parse raw token amounts. When token amounts exceed Number.MAX_SAFE_INTEGER (~9.0 × 10¹⁵), JavaScript loses precision, producing incorrect or negative values.

This causes the overflow issue reported in #280, where a minting transaction shows a negative amount instead of the correct minted value.

Root Cause

parseInt(tokenAmount) returns a JavaScript Number, which only has 53 bits of integer precision. Token amounts in lamports or with high decimals can easily exceed this.

Fix

Use BigInt() for intermediate arithmetic, converting to Number only after dividing to a safe range:

  • For 0-decimal tokens: Number(BigInt(tokenAmount))
  • For tokens with decimals: split into whole + remainder using BigInt division, then combine as Number

This preserves precision for large amounts while maintaining the existing number type interface.

Fixes #280

parseInt() on large token amounts (>2^53) causes JavaScript Number overflow,
resulting in incorrect or negative values. This affects tokens with large
supplies or high-precision decimals.

Use BigInt for intermediate arithmetic, converting to Number only after
dividing to a safe range. This preserves precision for amounts that exceed
Number.MAX_SAFE_INTEGER.

Fixes helius-labs#280
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 20, 2026

Someone is attempting to deploy a commit to the Helius Team on Vercel.

A member of the Team first needs to authorize it.

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.

🐛 [BUG] - Overflow Issue in Enhanced Xray/Webhooks Parsing for Specific Transaction

1 participant