fix: type /quote 'amount' as string to preserve u64 precision#94
Open
serejke wants to merge 2 commits into
Open
fix: type /quote 'amount' as string to preserve u64 precision#94serejke wants to merge 2 commits into
serejke wants to merge 2 commits into
Conversation
The amount query parameter is a u64 in atomic units (raw amount before decimals), but was declared type: integer, format: uint64. openapi-generator maps every type: integer to a TS number (an IEEE-754 double), which is exact only up to 2^53-1. u64 amounts can reach ~1.84e19, so any quote whose atomic input exceeds 2^53-1 silently loses precision before hitting the wire. Type it as string, matching the response-side amounts (inAmount, outAmount, otherAmountThreshold) which are already strings for the same reason.
QuoteGetRequest.amount: number -> string. Generated with the pinned openapi-generator 7.3.0 (openapitools.json) via npm run openapi-gen.
d313343 to
048b3ba
Compare
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.
The bug
The
/quoteamountquery parameter is a u64 in atomic units ("raw amount before decimals"), but it is declaredtype: integer, format: uint64. openapi-generator maps everytype: integerto a TypeScriptnumber(it ignoresformat), and a JSnumberis an IEEE-754 double — exact only up toNumber.MAX_SAFE_INTEGER = 2^53−1 = 9_007_199_254_740_991. A u64 ranges up to18_446_744_073_709_551_615, so any quote whose atomic input exceeds2^53−1silently loses precision before it ever reaches the wire. This is reachable at realistic values — e.g. holding >~9M whole tokens of any 9-decimal SPL token, or BONK-class high-supply tokens.Proof
Consistency
The response side already does the right thing:
inAmount,outAmount,otherAmountThreshold, andPlatformFee.amountare alltype: string. This PR aligns the request side with that existing convention.The fix
swagger.yaml:AmountParameterschematype: integer / format: uint64→type: string(with a comment explaining why).typescript-fetchclient with the pinnedopenapi-generator7.3.0(openapitools.json) vianpm run openapi-gen. The only generated change isQuoteGetRequest.amount: number→string.Prior art
This is the same idea as #23 ("change amount type to string"), which was closed unmerged in Feb 2024. That attempt predated the v6→v1 API restructure and hand-edited the old generated
DefaultApi.ts+ bumped the version; this PR instead fixes it at the source (swagger.yaml) and regenerates, so the spec and client stay in sync. The bug is still present inmaintoday (amount: number).Callers currently passing a JS
numberwill need to pass astring. That is the point: anynumberabove2^53−1was already silently wrong. Strings ≤2^53−1and numeric-string inputs round-trip identically over the query string, so the fix is transparent for small amounts and correct for large ones. This likely warrants a major version bump — deferring to maintainer preference.