Skip to content

Commit 8b1785b

Browse files
committed
feat: add initial version of the money account upgrade controller
1 parent 687773c commit 8b1785b

11 files changed

Lines changed: 847 additions & 47 deletions

packages/money-account-upgrade-controller/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Add `MoneyAccountUpgradeController` with `upgradeAccount` method
12+
- Add `MoneyAccountUpgradeController` with multi-step `upgradeAccount` method that orchestrates address association, EIP-7702 authorization, delegation verification, and intent registration via CHOMP
1313

1414
[Unreleased]: https://github.com/MetaMask/core/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# MoneyAccountUpgradeController — Remaining Work
2+
3+
## Step 0: Associate address
4+
5+
- [ ] **Idempotency check**: `#associateAddress` currently always signs and submits. The CHOMP API returns 409 when already associated (which is handled as success), but we could skip the signing step entirely by checking state or querying CHOMP first.
6+
7+
## Step 1: Submit authorization
8+
9+
- [ ] **Fetch on-chain nonce**: The nonce is hardcoded to `0` (line 202). This needs to be replaced with an actual on-chain nonce fetch for the account — likely via an `eth_getTransactionCount` call or equivalent messenger action. CHOMP validates that the nonce matches.
10+
11+
## Step 2: Verify delegation
12+
13+
- [ ] **Caveat term encoding**: `#encodeCaveatTerms` does naive left-padded hex concatenation. Verify this matches the exact ABI encoding expected by the caveat enforcer contracts (may need proper ABI encoding via `@metamask/abi-utils` or similar).
14+
- [ ] **Use `@metamask/smart-accounts-kit`**: The description mentions using `createDelegation` from `@metamask/smart-accounts-kit` to build the delegation. This package is not yet in the repo — once it lands, the delegation construction in `#verifyDelegation` should use it instead of manual assembly.
15+
- [ ] **Import `ROOT_AUTHORITY` from `@metamask/delegation-controller`**: Currently defined locally as a constant. The delegation-controller has it but doesn't export it — once it's exported, import it instead.
16+
17+
## Step 3: Save delegation
18+
19+
- [ ] **Implement Authenticated User Storage save**: `#saveDelegation` is a stub (line 312-316). Needs the `@metamask/authenticated-user-storage` wrapper (PR currently open). Once available, save the signed delegation so CHOMP can read it at execution time via its internal VPC endpoint.
20+
21+
## Step 4: Register intents
22+
23+
- [ ] **Intent configuration**: The deposit/withdrawal intents are hardcoded with `mUSD` token symbol and `MAX_UINT256` allowance. These may need to come from config or be parameterised once requirements solidify.
24+
25+
## General
26+
27+
- [ ] **Resumability**: `upgradeAccount` runs all steps sequentially. If it fails mid-way and is retried, steps 0 and 2-4 will re-run from scratch. Consider checking persisted state at the start of each step to skip already-completed work (step 1 already does this via `getUpgrade`).
28+
- [ ] **`MoneyAccountController:getMoneyAccount`**: This action is declared in `AllowedActions` but not currently used. It was included anticipating the controller may need to look up account details. Remove if not needed, or use it to validate the address before starting.
29+
- [ ] **`#saveDelegation` unused `_chainId` parameter**: Will be needed once the stub is implemented — the storage call will likely need it.

packages/money-account-upgrade-controller/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@
5050
},
5151
"dependencies": {
5252
"@metamask/base-controller": "^9.0.1",
53-
"@metamask/messenger": "^1.1.1"
53+
"@metamask/chomp-api-service": "^0.0.0",
54+
"@metamask/delegation-controller": "^2.1.0",
55+
"@metamask/keyring-controller": "^25.2.0",
56+
"@metamask/messenger": "^1.1.1",
57+
"@metamask/money-account-controller": "^0.1.0"
5458
},
5559
"devDependencies": {
5660
"@metamask/auto-changelog": "^3.4.4",
61+
"@metamask/utils": "^11.9.0",
5762
"@ts-bridge/cli": "^0.6.4",
5863
"@types/jest": "^29.5.14",
5964
"deepmerge": "^4.2.2",

packages/money-account-upgrade-controller/src/MoneyAccountUpgradeController-method-action-types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import type { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';
77

88
/**
9-
* Upgrades a money account. This method iterates over a number of
10-
* steps to perform the upgrade.
9+
* Runs the full upgrade sequence for a Money Account.
1110
*
11+
* @param address - The Money Account address to upgrade.
12+
* @param chainId - The target chain for the upgrade.
1213
* @returns A promise that resolves when the upgrade is complete.
1314
*/
1415
export type MoneyAccountUpgradeControllerUpgradeAccountAction = {

0 commit comments

Comments
 (0)