Repository navigation
Conversation
Three places multiplied a UI amount by the scaled UI amount multiplier and did not round the product, so an 8-decimal mint showed 23 decimal places. They call toScaledUiAmount, which scales the raw amount as the token program does.
|
@askov is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
[Medium impact] The PR appears safe to merge; no new actionable defects were established. SummaryThis PR limits scaled token amounts to the mint’s decimals across transfers, transaction balances, and mint supply.
Reviews (4) · Last reviewed commit: "refactor(token): hold one raw amount in ..." · Reviewed by Greptile |
An account read adjusts uiAmountString for the mint extensions and a transaction does not. RawTokenBalance has no uiAmountString, so a read of it does not compile.
A row held the amount as a formatted string and as a raw amount, and AmountCell chose one of them. A row holds the raw amount, and AmountCell formats it.
askov
force-pushed
the
fix/scaled-ui-amount-decimals
branch
from
November 27, 2026 11:53
aa0c563 to
a19d38c
Compare
chrismoore3312-lang
approved these changes
Nov 27, 2026
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.
Description
Truncates a scaled UI amount to the decimals of the mint on the
Transferstab, the token balance rows and the supply row. A mint withscaledUiAmountConfigshowed up to 23 decimal places for an 8-decimal mint. The three places multiplied a UI amount by the multiplier and did not round the product.Changes
toScaledUiAmountto@entities/token-info, which scales a raw amount with the arithmetic of the token program: anf64product, truncated toward zero.toScaledUiAmounton theTransferstab, inTokenBalancesCardand on the supply row, and removestoScaledUiAmountString.balanceanddeltain agenerateTokenBalanceRowsrow withpreAmount,postAmountanddecimals, so a row holds raw amounts.RawTokenBalanceto@entities/token-amountas the input ofgenerateTokenBalanceRows, so a read ofuiAmountStringthere does not compile.Rounding
The RPC truncates a scaled amount, and it multiplies in
f64. The explorer does the same, so an amount matches theuiAmountStringthat the RPC returns for a token account.Checked on mainnet on 2026-11-27 against the SPYx mint (
XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W, multiplier1.007474126658766):uiAmountString23532095161237.0797702237.0797702237.079770211267365996091276.838450061276.838450061276.83845007337796612234.0321346834.0321346834.03213469Exact decimal arithmetic differs from the
f64product in 18 of 200,000 random amounts below1e13base units, and in 11,000 of 200,000 below4.4e15.Behavior Changes
Transferstab, on a token balance row and on the supply row now has at most the decimals of the mint.transferinstruction no longer renders asNaNfor a mint with a multiplier.0.000001now renders as a decimal, for example0.00000005, not5e-8.uiAmountString.transferinstruction on theTransferstab now renders as1234.5, not1,234.50000000, which is the format of atransferCheckedamount.Type of change
Testing
Bug fixes
Transferstab of the SPYx mint (localhost · production) and read theAmountcolumn. Expect at most 8 decimal places in every row. Production shows up to 23 decimal places.Cause: production multiplies the UI amount string by the multiplier as an exact decimal and prints every digit of the product.
Tokenscard. Expect at most 8 decimal places in each balance and each change. Production shows more than 8.Cause: the same unrounded product, on the balance and on the change.
Current Supplyrow. Expect at most 8 decimal places. Production shows more than 8.Cause: production multiplies the supply by the multiplier as a
Numberand prints up to 20 decimal places.Regression checks
Transferstab of USDC (localhost · production) and the USDC mint page (localhost · production). Expect the sameCurrent Supplyformat as production, and the same amounts in everytransferCheckedrow.Related Issues
Closes HOO-2953
Checklist
pnpm test,pnpm lint,pnpm typecheck)build:infoscript to update build information