Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
solToLamportsinclients/js-legacymultiplies the UI amount byLAMPORTS_PER_SOLbut never rounds the result to an integer. For amounts that aren't exactly representable in binary floating point, the product is fractional, e.g.1.005 * 1e9 === 1004999999.9999999. That breaks both callers:withdrawSol(..., 1.005)throwsRangeError: The number 1004999999.9999999 cannot be converted to a BigInt because it is not an integerfromcreateApproveInstruction, so the withdrawal can't be built at all.withdrawStake(..., 1.005)passes the value throughnew BN(...), which silently truncates it. The approve andWithdrawStakeinstructions then use1004999999pool tokens, one fewer than requested.This change rounds the product with
Math.round. For inputs with at most 9 decimals the float error is far below 0.5, so rounding always gives the intended base-unit amount.Tests: I added one test each for
withdrawSolandwithdrawStakethat call them with1.005and check the approve amount and the decodedpoolTokens. Both tests fail onmain(RangeError /1004999999n) and pass with the fix.pnpm test(28 passing),pnpm lintandpnpm formatare clean.I used an AI assistant (Claude) while preparing this. I reproduced the issue and checked the fix and tests myself.
🤖 Generated with Claude Code