Skip to content

fix: use bigint accumulator in native sell reduce#103

Merged
hzhu merged 2 commits into0xProject:mainfrom
mwelche:fix/bigint-reduce-accumulator
Mar 16, 2026
Merged

fix: use bigint accumulator in native sell reduce#103
hzhu merged 2 commits into0xProject:mainfrom
mwelche:fix/bigint-reduce-accumulator

Conversation

@mwelche
Copy link
Copy Markdown
Contributor

@mwelche mwelche commented Mar 10, 2026

Summary

  • Fixes SyntaxError: Cannot convert X to a BigInt when a native sell swap produces 2+ ERC-20 transfer logs to the same recipient (e.g., partial fills, rebates, multi-hop)
  • The reduce accumulator was round-tripping through formatUnitsBigInt, but BigInt() cannot parse decimal strings on the 2nd+ iteration
  • Aligns with the existing safe pattern at line 100-104 by tracking amountRaw as a bigint through the accumulator

Test plan

  • Existing test suite passes (npm test)
  • Verify with a transaction that produces multiple ERC-20 transfers to the taker during a native sell swap

Fixes #102

The reduce that aggregates multiple ERC-20 transfer logs for native sell
swaps was round-tripping through formatUnits → BigInt, causing a
SyntaxError on the 2nd+ iteration because BigInt() cannot parse decimal
strings. This aligns the pattern with the existing safe reduce at line
100-104 by tracking amountRaw as a bigint through the accumulator.

Fixes 0xProject#102
@mwelche mwelche requested a review from hzhu March 10, 2026 06:52
@mwelche mwelche self-assigned this Mar 16, 2026
Keep amountRaw internal to the reduce accumulator instead of
leaking it into the public response, consistent with all other
return paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@hzhu hzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 tests pass, coverage remains at 100%

Image

@hzhu hzhu merged commit e74ca40 into 0xProject:main Mar 16, 2026
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.

SyntaxError: Cannot convert decimal string to BigInt in reduce accumulator

2 participants