Skip to content

fix: use typed amount for Money Account max source calculations - #9707

Draft
jpuri wants to merge 1 commit into
mainfrom
fix/tpc-money-account-max-exact-input
Draft

fix: use typed amount for Money Account max source calculations#9707
jpuri wants to merge 1 commit into
mainfrom
fix/tpc-money-account-max-exact-input

Conversation

@jpuri

@jpuri jpuri commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Explanation

When isMaxAmount is true, calculateSourceAmount substitutes the pay token's on-chain balanceRaw as the quote source. For deposits funded from the Money account (e.g. Send to Perps), that balance is only un-vaulted mUSD, not the full withdrawable total (mUSD + vmUSD). Clients were forced to keep isMaxAmount=false to avoid collapsing Max, which also forced EXPECTED_OUTPUT quotes and caused Max amount + fees to exceed balance ("Insufficient funds" / "Add less or use a different payment method").

This change skips the on-chain balance substitution when paymentOverride === MoneyAccount, so Max continues to use the typed required amount (already set from the full withdrawable total). Clients can then set isMaxAmount=true again and get EXACT_INPUT fee-aware Max quotes.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Made with Cursor

@jpuri
jpuri requested review from a team as code owners July 30, 2026 11:22
@jpuri
jpuri temporarily deployed to default-branch July 30, 2026 11:22 — with GitHub Actions Inactive
jpuri added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 30, 2026
With MetaMask/core#9707, TPC uses the typed required amount for Money
Account max instead of bare on-chain mUSD. Re-enable isMaxAmount on Max
for deposits funded from the money account so quotes use EXACT_INPUT and
fees are taken from the full withdrawable balance.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jpuri
jpuri marked this pull request as draft July 30, 2026 11:33
isMaxAmount was substituting the pay token on-chain balance, which for
Money Account is only un-vaulted mUSD. Use the typed required amount
instead so Max deposits (e.g. Send to Perps) keep the full withdrawable
total and can use EXACT_INPUT.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jpuri
jpuri force-pushed the fix/tpc-money-account-max-exact-input branch from f2d6d1c to f37ea5d Compare July 30, 2026 11:45
jpuri added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 30, 2026
With MetaMask/core#9707, TPC uses the typed required amount for Money
Account max instead of bare on-chain mUSD. Set isMaxAmount on Max for
deposits funded from the money account so quotes use EXACT_INPUT and
fees are taken from the full withdrawable balance.

Co-authored-by: Cursor <cursoragent@cursor.com>
jpuri added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 30, 2026
With MetaMask/core#9707, TPC uses the typed required amount for Money
Account max instead of bare on-chain mUSD. Set isMaxAmount on Max for
deposits funded from the money account so quotes use EXACT_INPUT and
fees are taken from the full withdrawable balance.

Co-authored-by: Cursor <cursoragent@cursor.com>
@matthewwalsh0
matthewwalsh0 requested a review from dan437 July 30, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant