Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #257
A viem-backed SDK can round a decimal integer approval amount before ABI encoding. For example, approving 1000.01 tokens with 18 decimals authorizes 65,536 base units less than requested, and decimal
maxUint256rounds out of range and is rejected.Parse plain decimal integer strings directly with
BigIntbefore the existing numeric fallback. This preserves the requested amount, including signs, leading zeros, and surrounding whitespace. Other numeric formats keep their existing behavior; this change does not attempt to fix exponent or decimal-point notation.Add offline tests through the public SDK and the real viem encoder for swap/Delta/OTC approvals, unsafe integer boundaries,
maxUint256, signed arguments, and compatibility cases.Validation:
viemIntegerArgs,auctionAmounts,limitAmount,builderCode): 109 passed.maxUint256; all 100 selected amounts from 1000.00 through 1000.99 are now approved exactly.The local contract checks isolate approval and token spending. A live Velora-router swap and the external-RPC integration suite were not run.
Note
Medium Risk
Changes argument encoding for every viem transaction write, including token approvals where wrong amounts are user-visible and funds-related; behavior is localized and heavily regression-tested.
Overview
Fixes incorrect approval and contract-call amounts when the viem provider encodes string arguments: values above
Number.MAX_SAFE_INTEGER(and fullmaxUint256decimal strings) were routed throughNumberbeforeBigInt, which rounded or broke encoding.argsToViemArgsnow recognizes plain decimal integer strings (optional sign, surrounding whitespace) and converts them withBigInt(arg)before the existingNumberfallback. Hex-prefixed strings, scientific notation, and decimal-point forms still use the prior path; non-numeric strings, bytes, andbigintargs are unchanged.Adds an offline regression suite (
viemIntegerArgs.test.ts) that exercises swap, Delta, and OTC approval flows plus signedint256calls through the real viem encoder.Reviewed by Cursor Bugbot for commit af75146. Bugbot is set up for automated code reviews on this repo. Configure here.