@metamask/money-account-upgrade-controller 2.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/MoneyAccountUpgradeController-method-action-types.cjs.map +1 -1
  3. package/dist/MoneyAccountUpgradeController-method-action-types.d.cts +3 -1
  4. package/dist/MoneyAccountUpgradeController-method-action-types.d.cts.map +1 -1
  5. package/dist/MoneyAccountUpgradeController-method-action-types.d.mts +3 -1
  6. package/dist/MoneyAccountUpgradeController-method-action-types.d.mts.map +1 -1
  7. package/dist/MoneyAccountUpgradeController-method-action-types.mjs.map +1 -1
  8. package/dist/MoneyAccountUpgradeController.cjs +14 -6
  9. package/dist/MoneyAccountUpgradeController.cjs.map +1 -1
  10. package/dist/MoneyAccountUpgradeController.d.cts +3 -1
  11. package/dist/MoneyAccountUpgradeController.d.cts.map +1 -1
  12. package/dist/MoneyAccountUpgradeController.d.mts +3 -1
  13. package/dist/MoneyAccountUpgradeController.d.mts.map +1 -1
  14. package/dist/MoneyAccountUpgradeController.mjs +14 -6
  15. package/dist/MoneyAccountUpgradeController.mjs.map +1 -1
  16. package/dist/errors.cjs +39 -0
  17. package/dist/errors.cjs.map +1 -0
  18. package/dist/errors.d.cts +28 -0
  19. package/dist/errors.d.cts.map +1 -0
  20. package/dist/errors.d.mts +28 -0
  21. package/dist/errors.d.mts.map +1 -0
  22. package/dist/errors.mjs +34 -0
  23. package/dist/errors.mjs.map +1 -0
  24. package/dist/index.cjs +4 -1
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +1 -0
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +1 -0
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +1 -0
  31. package/dist/index.mjs.map +1 -1
  32. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add `MoneyAccountUpgradeStepError` (and the `isMoneyAccountUpgradeStepError` type guard). `upgradeAccount` now wraps any error thrown by a step in this error, exposing the failing step's `name` as `step` and preserving the original error as `cause`, so consumers can attribute failures to a specific step when reporting to Sentry). ([#9204](https://github.com/MetaMask/core/pull/9204))
15
+
16
+ ### Changed
17
+
18
+ - Bump `@metamask/keyring-controller` from `^27.0.0` to `^27.1.0` ([#9129](https://github.com/MetaMask/core/pull/9129))
19
+ - Bump `@metamask/network-controller` from `^32.0.0` to `^33.0.0` ([#9218](https://github.com/MetaMask/core/pull/9218))
20
+
10
21
  ## [2.0.5]
11
22
 
12
23
  ### Changed
@@ -117,7 +128,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117
128
 
118
129
  - Add `MoneyAccountUpgradeController` with `upgradeAccount` method ([#8426](https://github.com/MetaMask/core/pull/8426))
119
130
 
120
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.5...HEAD
131
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.1.0...HEAD
132
+ [2.1.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.5...@metamask/money-account-upgrade-controller@2.1.0
121
133
  [2.0.5]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.4...@metamask/money-account-upgrade-controller@2.0.5
122
134
  [2.0.4]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.3...@metamask/money-account-upgrade-controller@2.0.4
123
135
  [2.0.3]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.2...@metamask/money-account-upgrade-controller@2.0.3
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\n\n/**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\nexport type MoneyAccountUpgradeControllerUpgradeAccountAction = {\n type: `MoneyAccountUpgradeController:upgradeAccount`;\n handler: MoneyAccountUpgradeController['upgradeAccount'];\n};\n\n/**\n * Union of all MoneyAccountUpgradeController action types.\n */\nexport type MoneyAccountUpgradeControllerMethodActions =\n MoneyAccountUpgradeControllerUpgradeAccountAction;\n"]}
1
+ {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\n\n/**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step halts the sequence and is re-thrown wrapped in a\n * {@link MoneyAccountUpgradeStepError} that records which step failed (the\n * original error is preserved as `cause`).\n *\n * @param address - The Money Account address to upgrade.\n */\nexport type MoneyAccountUpgradeControllerUpgradeAccountAction = {\n type: `MoneyAccountUpgradeController:upgradeAccount`;\n handler: MoneyAccountUpgradeController['upgradeAccount'];\n};\n\n/**\n * Union of all MoneyAccountUpgradeController action types.\n */\nexport type MoneyAccountUpgradeControllerMethodActions =\n MoneyAccountUpgradeControllerUpgradeAccountAction;\n"]}
@@ -7,7 +7,9 @@ import type { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeControl
7
7
  * Runs each step in the upgrade sequence in order. A step that reports
8
8
  * `'already-done'` is skipped without performing any action; a step that
9
9
  * reports `'completed'` has performed its action. An error thrown by any
10
- * step propagates and halts the sequence.
10
+ * step halts the sequence and is re-thrown wrapped in a
11
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
12
+ * original error is preserved as `cause`).
11
13
  *
12
14
  * @param address - The Money Account address to upgrade.
13
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,4CAAwC;AAErF;;;;;;;GAOG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0CAA0C,GACpD,iDAAiD,CAAC"}
1
+ {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,4CAAwC;AAErF;;;;;;;;;GASG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0CAA0C,GACpD,iDAAiD,CAAC"}
@@ -7,7 +7,9 @@ import type { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeControl
7
7
  * Runs each step in the upgrade sequence in order. A step that reports
8
8
  * `'already-done'` is skipped without performing any action; a step that
9
9
  * reports `'completed'` has performed its action. An error thrown by any
10
- * step propagates and halts the sequence.
10
+ * step halts the sequence and is re-thrown wrapped in a
11
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
12
+ * original error is preserved as `cause`).
11
13
  *
12
14
  * @param address - The Money Account address to upgrade.
13
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,4CAAwC;AAErF;;;;;;;GAOG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0CAA0C,GACpD,iDAAiD,CAAC"}
1
+ {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,6BAA6B,EAAE,4CAAwC;AAErF;;;;;;;;;GASG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0CAA0C,GACpD,iDAAiD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\n\n/**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\nexport type MoneyAccountUpgradeControllerUpgradeAccountAction = {\n type: `MoneyAccountUpgradeController:upgradeAccount`;\n handler: MoneyAccountUpgradeController['upgradeAccount'];\n};\n\n/**\n * Union of all MoneyAccountUpgradeController action types.\n */\nexport type MoneyAccountUpgradeControllerMethodActions =\n MoneyAccountUpgradeControllerUpgradeAccountAction;\n"]}
1
+ {"version":3,"file":"MoneyAccountUpgradeController-method-action-types.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\n\n/**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step halts the sequence and is re-thrown wrapped in a\n * {@link MoneyAccountUpgradeStepError} that records which step failed (the\n * original error is preserved as `cause`).\n *\n * @param address - The Money Account address to upgrade.\n */\nexport type MoneyAccountUpgradeControllerUpgradeAccountAction = {\n type: `MoneyAccountUpgradeController:upgradeAccount`;\n handler: MoneyAccountUpgradeController['upgradeAccount'];\n};\n\n/**\n * Union of all MoneyAccountUpgradeController action types.\n */\nexport type MoneyAccountUpgradeControllerMethodActions =\n MoneyAccountUpgradeControllerUpgradeAccountAction;\n"]}
@@ -16,6 +16,7 @@ exports.MoneyAccountUpgradeController = exports.controllerName = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
17
17
  const delegation_deployments_1 = require("@metamask/delegation-deployments");
18
18
  const utils_1 = require("@metamask/utils");
19
+ const errors_1 = require("./errors.cjs");
19
20
  const associate_address_1 = require("./steps/associate-address.cjs");
20
21
  const build_delegations_1 = require("./steps/build-delegations.cjs");
21
22
  const eip_7702_authorization_1 = require("./steps/eip-7702-authorization.cjs");
@@ -99,7 +100,9 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
99
100
  * Runs each step in the upgrade sequence in order. A step that reports
100
101
  * `'already-done'` is skipped without performing any action; a step that
101
102
  * reports `'completed'` has performed its action. An error thrown by any
102
- * step propagates and halts the sequence.
103
+ * step halts the sequence and is re-thrown wrapped in a
104
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
105
+ * original error is preserved as `cause`).
103
106
  *
104
107
  * @param address - The Money Account address to upgrade.
105
108
  */
@@ -108,11 +111,16 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
108
111
  throw new Error('MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called');
109
112
  }
110
113
  for (const step of __classPrivateFieldGet(this, _MoneyAccountUpgradeController_steps, "f")) {
111
- await step.run({
112
- messenger: this.messenger,
113
- address,
114
- ...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
115
- });
114
+ try {
115
+ await step.run({
116
+ messenger: this.messenger,
117
+ address,
118
+ ...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
119
+ });
120
+ }
121
+ catch (error) {
122
+ throw new errors_1.MoneyAccountUpgradeStepError(step.name, error);
123
+ }
116
124
  }
117
125
  }
118
126
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,+DAA2D;AAU3D,6EAAuE;AAUvE,2CAA8C;AAI9C,qEAAiE;AACjE,qEAAgE;AAChE,+EAA0E;AAC1E,mEAA+D;AAI/D;;;GAGG;AACH,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEhC,QAAA,cAAc,GAAG,+BAA+B,CAAC;AAI9D,MAAM,qCAAqC,GACzC,EAA8D,CAAC;AAEjE,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AA4C9D;;GAEG;AACH,MAAa,6BAA8B,SAAQ,gCAIlD;IAUC;;;;;OAKG;IACH,YAAY,EACV,SAAS,GAGV;QACC,KAAK,CAAC;Y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ACb,OAAO;YACP,eAAe,EAAE,KAAK,CAAC,mBAAmB;YAC1C,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,YAAY;YAC9D,kBAAkB;YAClB,uBAAuB,EAAE,YAAY,CAAC,cAAc;YACpD,oBAAoB,EAAE,SAAS,CAAC,6BAA6B;YAC7D,2BAA2B,EAAE,SAAS,CAAC,2BAA2B;YAClE,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;YAC5C,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;SAC7C,MAAA,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,IAAI,CAAC,uBAAA,IAAI,6CAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;QACJ,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,uBAAA,IAAI,4CAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,GAAG,CAAC;gBACb,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,OAAO;gBACP,GAAG,uBAAA,IAAI,6CAAQ;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA5HD,sEA4HC","sourcesContent":["import type {\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceListDelegationsAction,\n} from '@metamask/authenticated-user-storage';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceGetServiceDetailsAction,\n ChompApiServiceVerifyDelegationAction,\n} from '@metamask/chomp-api-service';\nimport type { DelegationControllerSignDelegationAction } from '@metamask/delegation-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { buildDelegationStep } from './steps/build-delegations';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport { registerIntentsStep } from './steps/register-intents';\nimport type { Step } from './steps/step';\nimport type { UpgradeConfig } from './types';\n\n/**\n * The Delegation Framework deployment version we resolve contract addresses\n * against in `@metamask/delegation-deployments`.\n */\nconst DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceListDelegationsAction\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceGetServiceDetailsAction\n | ChompApiServiceVerifyDelegationAction\n | DelegationControllerSignDelegationAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: UpgradeConfig & { chainId: Hex };\n\n readonly #steps: Step[] = [\n associateAddressStep,\n eip7702AuthorizationStep,\n buildDelegationStep,\n registerIntentsStep,\n ];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain. Resolves the Delegation Framework contract addresses for the\n * chain from `@metamask/delegation-deployments`.\n *\n * @param params - The parameters for initialization.\n * @param params.chainId - The chain to initialize for.\n * @param params.boringVaultAddress - The Veda boring vault contract\n * (vmUSD) for the given chain. Used as the withdrawal-side delegation\n * token. Supplied by the consumer until the CHOMP service-details API\n * exposes it.\n */\n async init({\n chainId,\n boringVaultAddress,\n }: {\n chainId: Hex;\n boringVaultAddress: Hex;\n }): Promise<void> {\n const contracts =\n DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)];\n if (!contracts) {\n throw new Error(\n `Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`,\n );\n }\n\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegateAddress: chain.autoDepositDelegate,\n musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,\n boringVaultAddress,\n vedaVaultAdapterAddress: vedaProtocol.adapterAddress,\n delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,\n erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,\n redeemerEnforcer: contracts.RedeemerEnforcer,\n valueLteEnforcer: contracts.ValueLteEnforcer,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,+DAA2D;AAU3D,6EAAuE;AAUvE,2CAA8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AAK,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlID,sEAkIC","sourcesContent":["import type {\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceListDelegationsAction,\n} from '@metamask/authenticated-user-storage';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceGetServiceDetailsAction,\n ChompApiServiceVerifyDelegationAction,\n} from '@metamask/chomp-api-service';\nimport type { DelegationControllerSignDelegationAction } from '@metamask/delegation-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { MoneyAccountUpgradeStepError } from './errors';\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { buildDelegationStep } from './steps/build-delegations';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport { registerIntentsStep } from './steps/register-intents';\nimport type { Step } from './steps/step';\nimport type { UpgradeConfig } from './types';\n\n/**\n * The Delegation Framework deployment version we resolve contract addresses\n * against in `@metamask/delegation-deployments`.\n */\nconst DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceListDelegationsAction\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceGetServiceDetailsAction\n | ChompApiServiceVerifyDelegationAction\n | DelegationControllerSignDelegationAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: UpgradeConfig & { chainId: Hex };\n\n readonly #steps: Step[] = [\n associateAddressStep,\n eip7702AuthorizationStep,\n buildDelegationStep,\n registerIntentsStep,\n ];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain. Resolves the Delegation Framework contract addresses for the\n * chain from `@metamask/delegation-deployments`.\n *\n * @param params - The parameters for initialization.\n * @param params.chainId - The chain to initialize for.\n * @param params.boringVaultAddress - The Veda boring vault contract\n * (vmUSD) for the given chain. Used as the withdrawal-side delegation\n * token. Supplied by the consumer until the CHOMP service-details API\n * exposes it.\n */\n async init({\n chainId,\n boringVaultAddress,\n }: {\n chainId: Hex;\n boringVaultAddress: Hex;\n }): Promise<void> {\n const contracts =\n DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)];\n if (!contracts) {\n throw new Error(\n `Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`,\n );\n }\n\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegateAddress: chain.autoDepositDelegate,\n musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,\n boringVaultAddress,\n vedaVaultAdapterAddress: vedaProtocol.adapterAddress,\n delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,\n erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,\n redeemerEnforcer: contracts.RedeemerEnforcer,\n valueLteEnforcer: contracts.ValueLteEnforcer,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step halts the sequence and is re-thrown wrapped in a\n * {@link MoneyAccountUpgradeStepError} that records which step failed (the\n * original error is preserved as `cause`).\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n try {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n } catch (error) {\n throw new MoneyAccountUpgradeStepError(step.name, error);\n }\n }\n }\n}\n"]}
@@ -51,7 +51,9 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
51
51
  * Runs each step in the upgrade sequence in order. A step that reports
52
52
  * `'already-done'` is skipped without performing any action; a step that
53
53
  * reports `'completed'` has performed its action. An error thrown by any
54
- * step propagates and halts the sequence.
54
+ * step halts the sequence and is re-thrown wrapped in a
55
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
56
+ * original error is preserved as `cause`).
55
57
  *
56
58
  * @param address - The Money Account address to upgrade.
57
59
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qDAAqD,EACrD,oDAAoD,EACrD,6CAA6C;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,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EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,EACT,OAAO,EACP,kBAAkB,GACnB,EAAE;QACD,OAAO,EAAE,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;OAOG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAelD"}
1
+ {"version":3,"file":"MoneyAccountUpgradeController.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qDAAqD,EACrD,oDAAoD,EACrD,6CAA6C;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,wCAAwC;AAEhG,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC5C,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AActH,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAOvE,MAAM,MAAM,2CAA2C,GACrD,wBAAwB,CACtB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,oCAAoC,GAC5C,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C,KAAK,cAAc,GACf,qDAAqD,GACrD,oDAAoD,GACpD,qCAAqC,GACrC,kCAAkC,GAClC,kCAAkC,GAClC,wCAAwC,GACxC,sCAAsC,GACtC,qCAAqC,GACrC,wCAAwC,GACxC,+CAA+C,GAC/C,0CAA0C,GAC1C,mDAAmD,GACnD,2CAA2C,CAAC;AAEhD,MAAM,MAAM,8CAA8C,GACxD,2BAA2B,CACzB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,mCAAmC,GAC7C,8CAA8C,CAAC;AAEjD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,cAAc,EACrB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAUC;;;;;OAKG;gBACS,EACV,SAAS,GACV,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,EACT,OAAO,EACP,kBAAkB,GACnB,EAAE;QACD,OAAO,EAAE,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBlD"}
@@ -51,7 +51,9 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
51
51
  * Runs each step in the upgrade sequence in order. A step that reports
52
52
  * `'already-done'` is skipped without performing any action; a step that
53
53
  * reports `'completed'` has performed its action. An error thrown by any
54
- * step propagates and halts the sequence.
54
+ * step halts the sequence and is re-thrown wrapped in a
55
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
56
+ * original error is preserved as `cause`).
55
57
  *
56
58
  * @param address - The Money Account address to upgrade.
57
59
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qDAAqD,EACrD,oDAAoD,EACrD,6CAA6C;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,wCAAwC;AAEhG,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC5C,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AActH,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAOvE,MAAM,MAAM,2CAA2C,GACrD,wBAAwB,CACtB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,oCAAoC,GAC5C,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C,KAAK,cAAc,GACf,qDAAqD,GACrD,oDAAoD,GACpD,qCAAqC,GACrC,kCAAkC,GAClC,kCAAkC,GAClC,wCAAwC,GACxC,sCAAsC,GACtC,qCAAqC,GACrC,wCAAwC,GACxC,+CAA+C,GAC/C,0CAA0C,GAC1C,mDAAmD,GACnD,2CAA2C,CAAC;AAEhD,MAAM,MAAM,8CAA8C,GACxD,2BAA2B,CACzB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,mCAAmC,GAC7C,8CAA8C,CAAC;AAEjD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,cAAc,EACrB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAUC;;;;;OAKG;gBACS,EACV,SAAS,GACV,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,EACT,OAAO,EACP,kBAAkB,GACnB,EAAE;QACD,OAAO,EAAE,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;OAOG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAelD"}
1
+ {"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qDAAqD,EACrD,oDAAoD,EACrD,6CAA6C;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,wCAAwC;AAEhG,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qC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ACnB,EAAE;QACD,OAAO,EAAE,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBlD"}
@@ -13,6 +13,7 @@ var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
13
13
  import { BaseController } from "@metamask/base-controller";
14
14
  import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
15
15
  import { hexToNumber } from "@metamask/utils";
16
+ import { MoneyAccountUpgradeStepError } from "./errors.mjs";
16
17
  import { associateAddressStep } from "./steps/associate-address.mjs";
17
18
  import { buildDelegationStep } from "./steps/build-delegations.mjs";
18
19
  import { eip7702AuthorizationStep } from "./steps/eip-7702-authorization.mjs";
@@ -96,7 +97,9 @@ export class MoneyAccountUpgradeController extends BaseController {
96
97
  * Runs each step in the upgrade sequence in order. A step that reports
97
98
  * `'already-done'` is skipped without performing any action; a step that
98
99
  * reports `'completed'` has performed its action. An error thrown by any
99
- * step propagates and halts the sequence.
100
+ * step halts the sequence and is re-thrown wrapped in a
101
+ * {@link MoneyAccountUpgradeStepError} that records which step failed (the
102
+ * original error is preserved as `cause`).
100
103
  *
101
104
  * @param address - The Money Account address to upgrade.
102
105
  */
@@ -105,11 +108,16 @@ export class MoneyAccountUpgradeController extends BaseController {
105
108
  throw new Error('MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called');
106
109
  }
107
110
  for (const step of __classPrivateFieldGet(this, _MoneyAccountUpgradeController_steps, "f")) {
108
- await step.run({
109
- messenger: this.messenger,
110
- address,
111
- ...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
112
- });
111
+ try {
112
+ await step.run({
113
+ messenger: this.messenger,
114
+ address,
115
+ ...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
116
+ });
117
+ }
118
+ catch (error) {
119
+ throw new MoneyAccountUpgradeStepError(step.name, error);
120
+ }
113
121
  }
114
122
  }
115
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAUvE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAI9C,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,mBAAmB,EAAE,sCAAkC;AAChE,OAAO,EAAE,wBAAwB,EAAE,2CAAuC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,qCAAiC;AAI/D;;;GAGG;AACH,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAI9D,MAAM,qCAAqC,GACzC,EAA8D,CAAC;AAEjE,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AA4C9D;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,cAIlD;IAUC;;;;;OAKG;IACH,YAAY,EACV,SAAS,GAGV;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,qCAAqC;YAC/C,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;QAzBL,wDAA2C;QAElC,+CAAiB;YACxB,oBAAoB;YACpB,wBAAwB;YACxB,mBAAmB;YACnB,mBAAmB;SACpB,EAAC;QAoBA,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CAAC,EACT,OAAO,EACP,kBAAkB,GAInB;QACC,MAAM,SAAS,GACb,mBAAmB,CAAC,4BAA4B,CAAC,CAAC,WAAW,CA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AI,6CAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;QACJ,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,uBAAA,IAAI,4CAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,GAAG,CAAC;gBACb,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,OAAO;gBACP,GAAG,uBAAA,IAAI,6CAAQ;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceListDelegationsAction,\n} from '@metamask/authenticated-user-storage';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceGetServiceDetailsAction,\n ChompApiServiceVerifyDelegationAction,\n} from '@metamask/chomp-api-service';\nimport type { DelegationControllerSignDelegationAction } from '@metamask/delegation-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { buildDelegationStep } from './steps/build-delegations';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport { registerIntentsStep } from './steps/register-intents';\nimport type { Step } from './steps/step';\nimport type { UpgradeConfig } from './types';\n\n/**\n * The Delegation Framework deployment version we resolve contract addresses\n * against in `@metamask/delegation-deployments`.\n */\nconst DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceListDelegationsAction\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceGetServiceDetailsAction\n | ChompApiServiceVerifyDelegationAction\n | DelegationControllerSignDelegationAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: UpgradeConfig & { chainId: Hex };\n\n readonly #steps: Step[] = [\n associateAddressStep,\n eip7702AuthorizationStep,\n buildDelegationStep,\n registerIntentsStep,\n ];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain. Resolves the Delegation Framework contract addresses for the\n * chain from `@metamask/delegation-deployments`.\n *\n * @param params - The parameters for initialization.\n * @param params.chainId - The chain to initialize for.\n * @param params.boringVaultAddress - The Veda boring vault contract\n * (vmUSD) for the given chain. Used as the withdrawal-side delegation\n * token. Supplied by the consumer until the CHOMP service-details API\n * exposes it.\n */\n async init({\n chainId,\n boringVaultAddress,\n }: {\n chainId: Hex;\n boringVaultAddress: Hex;\n }): Promise<void> {\n const contracts =\n DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)];\n if (!contracts) {\n throw new Error(\n `Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`,\n );\n }\n\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegateAddress: chain.autoDepositDelegate,\n musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,\n boringVaultAddress,\n vedaVaultAdapterAddress: vedaProtocol.adapterAddress,\n delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,\n erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,\n redeemerEnforcer: contracts.RedeemerEnforcer,\n valueLteEnforcer: contracts.ValueLteEnforcer,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAUvE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,4BAA4B,EAAE,qBAAiB;AAExD,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,mBAAmB,EAAE,sCAAkC;AAChE,OAAO,EAAE,wBAAwB,EAAE,2CAAuC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,qCAAiC;AAI/D;;;GAGG;AACH,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAI9D,MAAM,qCAAqC,GACzC,EAA8D,CAAC;AAEjE,MAAM,yBAAyB,GAAG,CAAC,gBAAg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AAK,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CACb,uDAAuD,OAAO,EAAE,CACjE,CAAC;QACJ,CAAC;QAED,uBAAA,IAAI,yCAAW;YACb,OAAO;YACP,eAAe,EAAE,KAAK,CAAC,mBAAmB;YAC1C,gBAAgB,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,YAAY;YAC9D,kBAAkB;YAClB,uBAAuB,EAAE,YAAY,CAAC,cAAc;YACpD,oBAAoB,EAAE,SAAS,CAAC,6BAA6B;YAC7D,2BAA2B,EAAE,SAAS,CAAC,2BAA2B;YAClE,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;YAC5C,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;SAC7C,MAAA,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,IAAI,CAAC,uBAAA,IAAI,6CAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;QACJ,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,uBAAA,IAAI,4CAAO,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,GAAG,CAAC;oBACb,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,OAAO;oBACP,GAAG,uBAAA,IAAI,6CAAQ;iBAChB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceListDelegationsAction,\n} from '@metamask/authenticated-user-storage';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateIntentsAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetIntentsByAddressAction,\n ChompApiServiceGetServiceDetailsAction,\n ChompApiServiceVerifyDelegationAction,\n} from '@metamask/chomp-api-service';\nimport type { DelegationControllerSignDelegationAction } from '@metamask/delegation-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { hexToNumber } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { MoneyAccountUpgradeStepError } from './errors';\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { buildDelegationStep } from './steps/build-delegations';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport { registerIntentsStep } from './steps/register-intents';\nimport type { Step } from './steps/step';\nimport type { UpgradeConfig } from './types';\n\n/**\n * The Delegation Framework deployment version we resolve contract addresses\n * against in `@metamask/delegation-deployments`.\n */\nconst DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceListDelegationsAction\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateIntentsAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetIntentsByAddressAction\n | ChompApiServiceGetServiceDetailsAction\n | ChompApiServiceVerifyDelegationAction\n | DelegationControllerSignDelegationAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: UpgradeConfig & { chainId: Hex };\n\n readonly #steps: Step[] = [\n associateAddressStep,\n eip7702AuthorizationStep,\n buildDelegationStep,\n registerIntentsStep,\n ];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain. Resolves the Delegation Framework contract addresses for the\n * chain from `@metamask/delegation-deployments`.\n *\n * @param params - The parameters for initialization.\n * @param params.chainId - The chain to initialize for.\n * @param params.boringVaultAddress - The Veda boring vault contract\n * (vmUSD) for the given chain. Used as the withdrawal-side delegation\n * token. Supplied by the consumer until the CHOMP service-details API\n * exposes it.\n */\n async init({\n chainId,\n boringVaultAddress,\n }: {\n chainId: Hex;\n boringVaultAddress: Hex;\n }): Promise<void> {\n const contracts =\n DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)];\n if (!contracts) {\n throw new Error(\n `Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`,\n );\n }\n\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegateAddress: chain.autoDepositDelegate,\n musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,\n boringVaultAddress,\n vedaVaultAdapterAddress: vedaProtocol.adapterAddress,\n delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,\n erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,\n redeemerEnforcer: contracts.RedeemerEnforcer,\n valueLteEnforcer: contracts.ValueLteEnforcer,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step halts the sequence and is re-thrown wrapped in a\n * {@link MoneyAccountUpgradeStepError} that records which step failed (the\n * original error is preserved as `cause`).\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n try {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n } catch (error) {\n throw new MoneyAccountUpgradeStepError(step.name, error);\n }\n }\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMoneyAccountUpgradeStepError = exports.MoneyAccountUpgradeStepError = void 0;
4
+ /**
5
+ * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of
6
+ * the upgrade steps fails.
7
+ *
8
+ * Wraps the underlying error (preserved as `cause`) and records the name of
9
+ * the step that was running, so consumers can attribute the failure to a
10
+ * specific step — e.g. when tagging an error report — without parsing the
11
+ * message.
12
+ */
13
+ class MoneyAccountUpgradeStepError extends Error {
14
+ constructor(step, cause) {
15
+ const causeMessage = cause instanceof Error ? cause.message : String(cause);
16
+ super(`Money Account upgrade failed at step "${step}": ${causeMessage}`);
17
+ this.name = 'MoneyAccountUpgradeStepError';
18
+ this.step = step;
19
+ this.cause = cause;
20
+ }
21
+ }
22
+ exports.MoneyAccountUpgradeStepError = MoneyAccountUpgradeStepError;
23
+ /**
24
+ * Type guard for {@link MoneyAccountUpgradeStepError}.
25
+ *
26
+ * Uses a structural check rather than `instanceof` so it holds across module
27
+ * realm boundaries — e.g. when the controller is consumed from a bundled host
28
+ * app where a duplicate copy of this class may exist.
29
+ *
30
+ * @param error - The value to test.
31
+ * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.
32
+ */
33
+ function isMoneyAccountUpgradeStepError(error) {
34
+ return (error instanceof Error &&
35
+ error.name === 'MoneyAccountUpgradeStepError' &&
36
+ typeof error.step === 'string');
37
+ }
38
+ exports.isMoneyAccountUpgradeStepError = isMoneyAccountUpgradeStepError;
39
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAOrD,YAAY,IAAY,EAAE,KAAc;QACtC,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,KAAK,CAAC,yCAAyC,IAAI,MAAM,YAAY,EAAE,CAAC,CAAC;QAEzE,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAfD,oEAeC;AAED;;;;;;;;;GASG;AACH,SAAgB,8BAA8B,CAC5C,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,KAAK,CAAC,IAAI,KAAK,8BAA8B;QAC7C,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CACvD,CAAC;AACJ,CAAC;AARD,wEAQC","sourcesContent":["/**\n * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of\n * the upgrade steps fails.\n *\n * Wraps the underlying error (preserved as `cause`) and records the name of\n * the step that was running, so consumers can attribute the failure to a\n * specific step — e.g. when tagging an error report — without parsing the\n * message.\n */\nexport class MoneyAccountUpgradeStepError extends Error {\n /** The name of the step that threw. */\n readonly step: string;\n\n /** The underlying error thrown by the step. */\n readonly cause: unknown;\n\n constructor(step: string, cause: unknown) {\n const causeMessage = cause instanceof Error ? cause.message : String(cause);\n super(`Money Account upgrade failed at step \"${step}\": ${causeMessage}`);\n\n this.name = 'MoneyAccountUpgradeStepError';\n this.step = step;\n this.cause = cause;\n }\n}\n\n/**\n * Type guard for {@link MoneyAccountUpgradeStepError}.\n *\n * Uses a structural check rather than `instanceof` so it holds across module\n * realm boundaries — e.g. when the controller is consumed from a bundled host\n * app where a duplicate copy of this class may exist.\n *\n * @param error - The value to test.\n * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.\n */\nexport function isMoneyAccountUpgradeStepError(\n error: unknown,\n): error is MoneyAccountUpgradeStepError {\n return (\n error instanceof Error &&\n error.name === 'MoneyAccountUpgradeStepError' &&\n typeof (error as { step?: unknown }).step === 'string'\n );\n}\n"]}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of
3
+ * the upgrade steps fails.
4
+ *
5
+ * Wraps the underlying error (preserved as `cause`) and records the name of
6
+ * the step that was running, so consumers can attribute the failure to a
7
+ * specific step — e.g. when tagging an error report — without parsing the
8
+ * message.
9
+ */
10
+ export declare class MoneyAccountUpgradeStepError extends Error {
11
+ /** The name of the step that threw. */
12
+ readonly step: string;
13
+ /** The underlying error thrown by the step. */
14
+ readonly cause: unknown;
15
+ constructor(step: string, cause: unknown);
16
+ }
17
+ /**
18
+ * Type guard for {@link MoneyAccountUpgradeStepError}.
19
+ *
20
+ * Uses a structural check rather than `instanceof` so it holds across module
21
+ * realm boundaries — e.g. when the controller is consumed from a bundled host
22
+ * app where a duplicate copy of this class may exist.
23
+ *
24
+ * @param error - The value to test.
25
+ * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.
26
+ */
27
+ export declare function isMoneyAccountUpgradeStepError(error: unknown): error is MoneyAccountUpgradeStepError;
28
+ //# sourceMappingURL=errors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAQzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,4BAA4B,CAMvC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of
3
+ * the upgrade steps fails.
4
+ *
5
+ * Wraps the underlying error (preserved as `cause`) and records the name of
6
+ * the step that was running, so consumers can attribute the failure to a
7
+ * specific step — e.g. when tagging an error report — without parsing the
8
+ * message.
9
+ */
10
+ export declare class MoneyAccountUpgradeStepError extends Error {
11
+ /** The name of the step that threw. */
12
+ readonly step: string;
13
+ /** The underlying error thrown by the step. */
14
+ readonly cause: unknown;
15
+ constructor(step: string, cause: unknown);
16
+ }
17
+ /**
18
+ * Type guard for {@link MoneyAccountUpgradeStepError}.
19
+ *
20
+ * Uses a structural check rather than `instanceof` so it holds across module
21
+ * realm boundaries — e.g. when the controller is consumed from a bundled host
22
+ * app where a duplicate copy of this class may exist.
23
+ *
24
+ * @param error - The value to test.
25
+ * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.
26
+ */
27
+ export declare function isMoneyAccountUpgradeStepError(error: unknown): error is MoneyAccountUpgradeStepError;
28
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAQzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,4BAA4B,CAMvC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of
3
+ * the upgrade steps fails.
4
+ *
5
+ * Wraps the underlying error (preserved as `cause`) and records the name of
6
+ * the step that was running, so consumers can attribute the failure to a
7
+ * specific step — e.g. when tagging an error report — without parsing the
8
+ * message.
9
+ */
10
+ export class MoneyAccountUpgradeStepError extends Error {
11
+ constructor(step, cause) {
12
+ const causeMessage = cause instanceof Error ? cause.message : String(cause);
13
+ super(`Money Account upgrade failed at step "${step}": ${causeMessage}`);
14
+ this.name = 'MoneyAccountUpgradeStepError';
15
+ this.step = step;
16
+ this.cause = cause;
17
+ }
18
+ }
19
+ /**
20
+ * Type guard for {@link MoneyAccountUpgradeStepError}.
21
+ *
22
+ * Uses a structural check rather than `instanceof` so it holds across module
23
+ * realm boundaries — e.g. when the controller is consumed from a bundled host
24
+ * app where a duplicate copy of this class may exist.
25
+ *
26
+ * @param error - The value to test.
27
+ * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.
28
+ */
29
+ export function isMoneyAccountUpgradeStepError(error) {
30
+ return (error instanceof Error &&
31
+ error.name === 'MoneyAccountUpgradeStepError' &&
32
+ typeof error.step === 'string');
33
+ }
34
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IAOrD,YAAY,IAAY,EAAE,KAAc;QACtC,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,KAAK,CAAC,yCAAyC,IAAI,MAAM,YAAY,EAAE,CAAC,CAAC;QAEzE,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,KAAK,CAAC,IAAI,KAAK,8BAA8B;QAC7C,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CACvD,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Error thrown by `MoneyAccountUpgradeController.upgradeAccount` when one of\n * the upgrade steps fails.\n *\n * Wraps the underlying error (preserved as `cause`) and records the name of\n * the step that was running, so consumers can attribute the failure to a\n * specific step — e.g. when tagging an error report — without parsing the\n * message.\n */\nexport class MoneyAccountUpgradeStepError extends Error {\n /** The name of the step that threw. */\n readonly step: string;\n\n /** The underlying error thrown by the step. */\n readonly cause: unknown;\n\n constructor(step: string, cause: unknown) {\n const causeMessage = cause instanceof Error ? cause.message : String(cause);\n super(`Money Account upgrade failed at step \"${step}\": ${causeMessage}`);\n\n this.name = 'MoneyAccountUpgradeStepError';\n this.step = step;\n this.cause = cause;\n }\n}\n\n/**\n * Type guard for {@link MoneyAccountUpgradeStepError}.\n *\n * Uses a structural check rather than `instanceof` so it holds across module\n * realm boundaries — e.g. when the controller is consumed from a bundled host\n * app where a duplicate copy of this class may exist.\n *\n * @param error - The value to test.\n * @returns Whether `error` is a `MoneyAccountUpgradeStepError`.\n */\nexport function isMoneyAccountUpgradeStepError(\n error: unknown,\n): error is MoneyAccountUpgradeStepError {\n return (\n error instanceof Error &&\n error.name === 'MoneyAccountUpgradeStepError' &&\n typeof (error as { step?: unknown }).step === 'string'\n );\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MoneyAccountUpgradeController = void 0;
3
+ exports.MoneyAccountUpgradeController = exports.isMoneyAccountUpgradeStepError = exports.MoneyAccountUpgradeStepError = void 0;
4
+ var errors_1 = require("./errors.cjs");
5
+ Object.defineProperty(exports, "MoneyAccountUpgradeStepError", { enumerable: true, get: function () { return errors_1.MoneyAccountUpgradeStepError; } });
6
+ Object.defineProperty(exports, "isMoneyAccountUpgradeStepError", { enumerable: true, get: function () { return errors_1.isMoneyAccountUpgradeStepError; } });
4
7
  var MoneyAccountUpgradeController_1 = require("./MoneyAccountUpgradeController.cjs");
5
8
  Object.defineProperty(exports, "MoneyAccountUpgradeController", { enumerable: true, get: function () { return MoneyAccountUpgradeController_1.MoneyAccountUpgradeController; } });
6
9
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qFAAgF;AAAvE,8IAAA,6BAA6B,OAAA","sourcesContent":["export type { UpgradeConfig } from './types';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,uCAGkB;AAFhB,sHAAA,4BAA4B,OAAA;AAC5B,wHAAA,8BAA8B,OAAA;AAEhC,qFAAgF;AAAvE,8IAAA,6BAA6B,OAAA","sourcesContent":["export type { UpgradeConfig } from './types';\nexport {\n MoneyAccountUpgradeStepError,\n isMoneyAccountUpgradeStepError,\n} from './errors';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { UpgradeConfig } from "./types.cjs";
2
+ export { MoneyAccountUpgradeStepError, isMoneyAccountUpgradeStepError, } from "./errors.cjs";
2
3
  export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.cjs";
3
4
  export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.cjs";
4
5
  export type { MoneyAccountUpgradeControllerUpgradeAccountAction } from "./MoneyAccountUpgradeController-method-action-types.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,qBAAiB;AAClB,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { UpgradeConfig } from "./types.mjs";
2
+ export { MoneyAccountUpgradeStepError, isMoneyAccountUpgradeStepError, } from "./errors.mjs";
2
3
  export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.mjs";
3
4
  export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.mjs";
4
5
  export type { MoneyAccountUpgradeControllerUpgradeAccountAction } from "./MoneyAccountUpgradeController-method-action-types.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,qBAAiB;AAClB,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,3 @@
1
+ export { MoneyAccountUpgradeStepError, isMoneyAccountUpgradeStepError } from "./errors.mjs";
1
2
  export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.mjs";
2
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,4CAAwC","sourcesContent":["export type { UpgradeConfig } from './types';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC/B,qBAAiB;AAClB,OAAO,EAAE,6BAA6B,EAAE,4CAAwC","sourcesContent":["export type { UpgradeConfig } from './types';\nexport {\n MoneyAccountUpgradeStepError,\n isMoneyAccountUpgradeStepError,\n} from './errors';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/money-account-upgrade-controller",
3
- "version": "2.0.5",
3
+ "version": "2.1.0",
4
4
  "description": "MetaMask Money account upgrade controller",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -59,9 +59,9 @@
59
59
  "@metamask/delegation-controller": "^3.0.2",
60
60
  "@metamask/delegation-core": "^2.2.1",
61
61
  "@metamask/delegation-deployments": "^1.4.0",
62
- "@metamask/keyring-controller": "^27.0.0",
62
+ "@metamask/keyring-controller": "^27.1.0",
63
63
  "@metamask/messenger": "^1.2.0",
64
- "@metamask/network-controller": "^32.0.0",
64
+ "@metamask/network-controller": "^33.0.0",
65
65
  "@metamask/utils": "^11.11.0"
66
66
  },
67
67
  "devDependencies": {