Skip to content

Commit 0144e95

Browse files
dan437cursoragent
andauthored
feat(confirmations): support Money Account withdrawals to hardware wallet recipients (#47111)
<!-- CURSOR_AGENT_PR_BODY_BEGIN --> ## **Description** This lets users withdraw from a Money Account to any hardware wallet account (Ledger, Trezor, Lattice, QR, OneKey), including withdrawals that need a quote to another token or chain. The Money Account signs everything and the recipient only receives the funds, so the device never needs to be connected, unlocked, or asked to sign. `@metamask/transaction-pay-controller` is now bumped to `^31.0.0`, which ships [MetaMask/core#10992](MetaMask/core#10992): post-quote withdrawals are quoted and submitted from the transaction's own `from` (the Money Account), and `accountOverride` only receives the output. To match, a quoted withdrawal keeps the mUSD on the Money Account, while same-chain mUSD still pays the recipient directly. Its success toast says "your account", and the withdraw E2E mocks a gasless Relay execute quote, which is how the Money Account submits. Checked for the bump from 30.3.1 to 31.0.0: - Withdraw call sites match the BREAKING change: the nested transfer (re-encoded when the token or recipient changes), the confirm-time re-encode, and the paying account all use `from`, and `accountOverride` is only the recipient. - No new required options or external messenger actions. The new optional `clientId` is left unset. - `transaction-controller` stays on the repo's `72.3.0` resolution, and the pay controller calls the same transaction controller actions as 30.3.1. `gas-fee-controller` dedupes to 27.1.0, so the LavaMoat policies pick up its newer `uuid`. ## **Changelog** CHANGELOG entry: Added support for withdrawing from a Money Account to hardware wallet accounts ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/CONF-2087 ## **Manual testing steps** 1. Run the extension with Money Account enabled and a funded Money Account. 2. Add a hardware wallet account (for example Ledger or QR), then disconnect or lock the device. 3. Select the hardware account, go to Money home, and click Send. 4. Check that the hardware account is the recipient, is listed in "Withdraw to", and the screen looks like a normal withdrawal. 5. Pick the Money Account token on its own chain, enter an amount, and confirm. Check that no hardware wallet prompt appears and the funds arrive at the hardware account. 6. Start another withdraw, pick a token on another chain (for example USDC on Ethereum), enter an amount, and confirm. Check that no hardware wallet prompt appears and the funds arrive at the hardware account. 7. Start a withdraw to the hardware account, switch the recipient to a regular account, and confirm. Check that the funds arrive at the regular account. 8. Withdraw to a regular account with a token on another chain, then run a deposit. Check that both still work and the regular account is not asked to sign the withdrawal. <!-- ## **Screenshots/Recordings** ### **Before** ### **After** --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_AGENT_PR_BODY_END --> <div><a href="https://cursor.com/agents/bc-d824f3b1-ec17-502f-bc13-b24184a7e741?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-d824f3b1-ec17-502f-bc13-b24184a7e741&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > Changes withdrawal calldata, Pay quote routing, and confirm approval guards—incorrect transfer targets or reuse logic could send funds to the wrong address or approve stale batches. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 921d970. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Daniel <dan437@users.noreply.github.com>
1 parent 6c87b8d commit 0144e95

35 files changed

Lines changed: 1653 additions & 233 deletions

‎app/scripts/lib/money/pay/amount-commit.ts‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import type { MoneyPayMessenger } from './pay-context';
1111

1212
const MUSD_UNIT = 10 ** MUSD_DECIMALS;
1313

14-
const latestIntentByTransactionId = new Map<string, number>();
14+
const latestIntentByTransactionId = new Map<
15+
string,
16+
{ intent: number; amountRaw?: bigint }
17+
>();
1518

1619
/**
1720
* Parses a human-readable mUSD amount into base units. Returns `undefined`
@@ -66,12 +69,32 @@ export function toMusdAmountHex(amount: bigint): Hex {
6669
* `isCurrent()` is false once a newer intent has started for the same id.
6770
*
6871
* @param transactionId - Id of the transaction being updated.
72+
* @param amountRaw - Raw amount this intent commits, if known.
6973
* @returns A function that is true only while this intent is still latest.
7074
*/
71-
export function beginAmountCommit(transactionId: string): () => boolean {
72-
const intent = (latestIntentByTransactionId.get(transactionId) ?? 0) + 1;
73-
latestIntentByTransactionId.set(transactionId, intent);
74-
return () => latestIntentByTransactionId.get(transactionId) === intent;
75+
export function beginAmountCommit(
76+
transactionId: string,
77+
amountRaw?: bigint,
78+
): () => boolean {
79+
const intent =
80+
(latestIntentByTransactionId.get(transactionId)?.intent ?? 0) + 1;
81+
latestIntentByTransactionId.set(transactionId, { intent, amountRaw });
82+
return () =>
83+
latestIntentByTransactionId.get(transactionId)?.intent === intent;
84+
}
85+
86+
/**
87+
* Returns whether an amount commit is in flight for a transaction, and the
88+
* raw amount it commits when known.
89+
*
90+
* @param transactionId - Id of the transaction being updated.
91+
* @returns The in-flight commit, or `undefined` when none is pending.
92+
*/
93+
export function getPendingAmountCommit(
94+
transactionId: string,
95+
): { amountRaw?: bigint } | undefined {
96+
const pending = latestIntentByTransactionId.get(transactionId);
97+
return pending ? { amountRaw: pending.amountRaw } : undefined;
7598
}
7699

77100
/**

0 commit comments

Comments
 (0)