The Money Account withdraw screen rejected the exact balance it displayed.
With a withdrawable balance of 0.499999 mUSD, "Available balance" rendered
as $0.50 because `moneyFormatUsd` rounds half-up. The amount input is
clamped to two decimals, so the smallest amount a user could type that
matched the label was 0.50 - a hundredth of a cent more than they held.
The client-side balance check then blocked the withdraw with "Insufficient
funds", leaving no typable amount that would work.
Add `moneyFormatUsdSpendable`, which rounds down to cents, and use it for
the withdrawable balance wherever that figure doubles as a spendable
target. Half-up rounding stays in place for read-only totals, so
`moneyFormatUsd` remains byte-identical with mobile's `moneyFormatFiat`.
`withdrawableFiatRaw` is left at full precision, so Max still withdraws the
whole vault balance.
The balance comparison and the calldata encoder are deliberately untouched.
The encoder rounds up (`musdHumanToRaw`), so relaxing the check to admit
0.50 would have encoded 500000 raw against a 499999 balance and reverted
on-chain - trading a client-side block for a failed transaction.
Description
The Money Account withdraw screen rejected the exact balance it displayed.
With a withdrawable balance of
0.499999mUSD, the "Available balance" label rendered as $0.50, becausemoneyFormatUsdformats viaIntl.NumberFormat, which rounds half-up. The amount input is clamped to two decimals (FIAT_INPUT_PATTERNincustom-amount.tsx), so the smallest amount a user could type that matched the label was0.50— a hundredth of a cent more than they actually held. The client-side balance check inuseInsufficientMoneyAccountBalanceAlertthen compared0.499999 < 0.50, raised a blocking alert, andsingle-action-footerrelabelled Send to "Insufficient funds".The result: no typable amount would work.
0.50was rejected and0.49was the only alternative. This reproduces for any balance in the[x.xx5, x.xx9999]range, not just$0.50.The underlying
499999figure comes from a$0.50USDC deposit losing one micro-unit to vault-share conversion rounding. That is service-side and out of scope here, but this fix makes it harmless.Solution: add
moneyFormatUsdSpendable, which rounds down to cents, and use it for the withdrawable balance wherever that figure doubles as a spendable target. The label now reads$0.49, which is typable, passes validation, and encodes cleanly.Key constraints respected:
withdrawableFiatRawkeeps full precision, so Max still withdraws the entire0.499999vault balance. Nothing is stranded.moneyFormatUsdis unchanged, so it stays byte-identical with mobile'smoneyFormatFiat, as pinned by the shared vectors informat.test.ts. Read-only totals (home page, activity, earnings projections) keep half-up rounding, which is correct for them.$0.00rather than rounding up.Why not relax the balance check instead?
Two alternatives were considered and rejected:
usePerpsWithdrawInsufficientBalanceAlertdoes) — gives0.49vs0.50, which still rejects. No improvement.0.50, butmusdHumanToRaw(money-account-withdraw.ts:155) encodes withROUND_UP, producing500000raw against a499999balance. That reverts on-chain, trading a client-side block for a failed transaction and wasted gas.The UI must never offer an amount it cannot encode, so the fix belongs in the display.
Changelog
CHANGELOG entry: Fixed a bug where withdrawing the full available balance from a Money Account was rejected as "Insufficient funds"
Related issues
Fixes: CONF-2196
Manual testing steps
0.499999mUSD (a$0.50USDC deposit produces this naturally).0.49into the amount field.$0.49is received.0.499999) and leaves a zero balance behind — the floor is display-only and must not strand funds.7.06), verify the label still reads$7.06and the full amount is typable and sendable.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes how withdrawable balances are shown in Money Account withdraw and confirmation flows; incorrect rounding could still mislead users or affect validation, though behavior is narrowly scoped and heavily tested.
Overview
Fixes CONF-2196, where half-up formatting of withdrawable balance (e.g.
0.499999→ $0.50) blocked full withdrawals because the two-decimal amount field could not match the displayed label.Adds
moneyFormatUsdSpendable, which floors to cents before formatting, and uses it forwithdrawableFiatFormattedinwithdrawable-balancehelpers,useMoneyAccountBalance, and (viaprojectWithdrawableFiat) confirmation flows usinguseMoneyAccountWithdrawableFiat.withdrawableFiatRawstays at full precision so Max still withdraws the entire vault balance;totalFiatFormattedstill usesmoneyFormatUsd(half-up) for read-only totals.Reviewed by Cursor Bugbot for commit 0ae95c1. Bugbot is set up for automated code reviews on this repo. Configure here.