@metamask/money-account-upgrade-controller 2.0.4 → 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.
- package/CHANGELOG.md +24 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.cjs.map +1 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.d.cts +3 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.d.cts.map +1 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.d.mts +3 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.d.mts.map +1 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.mjs.map +1 -1
- package/dist/MoneyAccountUpgradeController.cjs +14 -6
- package/dist/MoneyAccountUpgradeController.cjs.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.cts +3 -1
- package/dist/MoneyAccountUpgradeController.d.cts.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.mts +3 -1
- package/dist/MoneyAccountUpgradeController.d.mts.map +1 -1
- package/dist/MoneyAccountUpgradeController.mjs +14 -6
- package/dist/MoneyAccountUpgradeController.mjs.map +1 -1
- package/dist/errors.cjs +39 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +28 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +28 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +34 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/steps/register-intents.cjs +4 -1
- package/dist/steps/register-intents.cjs.map +1 -1
- package/dist/steps/register-intents.d.cts.map +1 -1
- package/dist/steps/register-intents.d.mts.map +1 -1
- package/dist/steps/register-intents.mjs +4 -1
- package/dist/steps/register-intents.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,27 @@ 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
|
+
|
|
21
|
+
## [2.0.5]
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- Scope the `register-intents` step to the currently-configured token addresses (deposit mUSD / withdrawal vmUSD) so that stale delegations for previously-configured tokens are no longer registered as intents ([#9075](https://github.com/MetaMask/core/pull/9075))
|
|
30
|
+
|
|
10
31
|
## [2.0.4]
|
|
11
32
|
|
|
12
33
|
### Changed
|
|
@@ -107,7 +128,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
107
128
|
|
|
108
129
|
- Add `MoneyAccountUpgradeController` with `upgradeAccount` method ([#8426](https://github.com/MetaMask/core/pull/8426))
|
|
109
130
|
|
|
110
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0
|
|
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
|
|
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
|
|
111
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
|
|
112
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
|
|
113
136
|
[2.0.2]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.1...@metamask/money-account-upgrade-controller@2.0.2
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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,CAA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AC;QAED,IAAI,YAAY,CAAC,eAAe,CAAC,MAAM,KAAK,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;;;;;;;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,2CAA8C;AAG9C,yCAAwD;AAExD,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;YACJ,SAAS;YACT,QAAQ,EAAE,qCAAqC;YAC/C,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;QAzBL,wDAA2C;QAElC,+CAAiB;YACxB,wCAAoB;YACpB,iDAAwB;YACxB,uCAAmB;YACnB,sCAAmB;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,4CAAmB,CAAC,4BAA4B,CAAC,CAAC,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,wBAAwB,4BAA4B,6BAA6B,OAAO,EAAE,CAC3F,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACxC,mCAAm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CAAC,SAAS;oBACzB,OAAO;oBACP,GAAG,uBAAA,IAAI,6CAAQ;iBAChB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,qCAA4B,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,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
|
|
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,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;
|
|
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,CAA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ccountUpgradeController 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
|
|
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;
|
|
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;AACn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D,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"}
|
|
@@ -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
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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,S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BAAA,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;;;;;;;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","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,kCAA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AAI,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"]}
|
package/dist/errors.cjs
ADDED
|
@@ -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"}
|
package/dist/errors.mjs
ADDED
|
@@ -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
|
package/dist/index.cjs.map
CHANGED
|
@@ -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";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -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";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -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
package/dist/index.mjs.map
CHANGED
|
@@ -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"]}
|
|
@@ -33,7 +33,7 @@ function parseIntentMetadataType(type) {
|
|
|
33
33
|
*/
|
|
34
34
|
exports.registerIntentsStep = {
|
|
35
35
|
name: 'register-intents',
|
|
36
|
-
async run({ messenger, address, chainId, delegateAddress, redeemerEnforcer, vedaVaultAdapterAddress, }) {
|
|
36
|
+
async run({ messenger, address, chainId, boringVaultAddress, delegateAddress, musdTokenAddress, redeemerEnforcer, vedaVaultAdapterAddress, }) {
|
|
37
37
|
const [delegations, existingIntents] = await Promise.all([
|
|
38
38
|
messenger.call('AuthenticatedUserStorageService:listDelegations'),
|
|
39
39
|
messenger.call('ChompApiService:getIntentsByAddress', address),
|
|
@@ -42,9 +42,12 @@ exports.registerIntentsStep = {
|
|
|
42
42
|
.filter((intent) => intent.status === 'active')
|
|
43
43
|
.map((intent) => intent.delegationHash.toLowerCase()));
|
|
44
44
|
const hasVedaRedeemerCaveat = (0, delegation_matchers_1.makeHasVedaRedeemerCaveat)(redeemerEnforcer, vedaVaultAdapterAddress);
|
|
45
|
+
const configuredTokenAddresses = [musdTokenAddress, boringVaultAddress];
|
|
46
|
+
const matchesConfiguredToken = (entry) => configuredTokenAddresses.some((tokenAddress) => (0, delegation_matchers_1.equalsIgnoreCase)(entry.metadata.tokenAddress, tokenAddress));
|
|
45
47
|
const needsIntent = (entry) => (0, delegation_matchers_1.equalsIgnoreCase)(entry.signedDelegation.delegator, address) &&
|
|
46
48
|
(0, delegation_matchers_1.equalsIgnoreCase)(entry.signedDelegation.delegate, delegateAddress) &&
|
|
47
49
|
(0, delegation_matchers_1.equalsIgnoreCase)(entry.metadata.chainIdHex, chainId) &&
|
|
50
|
+
matchesConfiguredToken(entry) &&
|
|
48
51
|
hasVedaRedeemerCaveat(entry) &&
|
|
49
52
|
!activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());
|
|
50
53
|
const toIntent = (entry) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-intents.cjs","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":";;;AAMA,mEAG+B;AAK/B;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,iBAAiB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACU,QAAA,mBAAmB,GAAS;IACvC,IAAI,EAAE,kBAAkB;IACxB,KAAK,CAAC,GAAG,CAAC,EACR,SAAS,EACT,OAAO,EACP,OAAO,EACP,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB;QACC,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACvD,SAAS,CAAC,IAAI,CAAC,iDAAiD,CAAC;YACjE,SAAS,CAAC,IAAI,CAAC,qCAAqC,EAAE,OAAO,CAAC;SAC/D,CAAC,CAAC;QAEH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAChC,eAAe;aACZ,MAAM,CAAC,CAAC,MAAmB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC;aAC3D,GAAG,CAAC,CAAC,MAAmB,EAAE,EAAE,CAAC,MAA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AAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport type {\n IntentEntry,\n SendIntentParams,\n} from '@metamask/chomp-api-service';\n\nimport {\n equalsIgnoreCase,\n makeHasVedaRedeemerCaveat,\n} from './delegation-matchers';\nimport type { Step } from './step';\n\ntype IntentMetadataType = SendIntentParams['metadata']['type'];\n\n/**\n * Parses a delegation's metadata `type` field — typed as `string` in storage —\n * into the narrow set of CHOMP intent types. Throws if the field carries any\n * other value, since registering it as an intent would be a category error.\n *\n * @param type - The `type` field from `DelegationMetadata`.\n * @returns The same value, narrowed to `IntentMetadataType`.\n */\nfunction parseIntentMetadataType(type: string): IntentMetadataType {\n if (type !== 'cash-deposit' && type !== 'cash-withdrawal') {\n throw new Error(\n `Expected delegation type to be \"cash-deposit\" or \"cash-withdrawal\", got \"${type}\"`,\n );\n }\n return type;\n}\n\n/**\n * Registers CHOMP intents for the auto-deposit / auto-withdrawal delegations\n * persisted by the build-delegation step.\n *\n * For each stored delegation between this account and CHOMP's delegate on\n * this chain, the step builds an intent referencing the stored\n * `delegationHash` and submits the batch to `POST /v1/intent`. Delegations\n * whose `delegationHash` already has an active intent on CHOMP are skipped\n * (revoked intents are re-registered). Reports `'already-done'` when every\n * eligible delegation already has an active intent.\n *\n * Once registered, CHOMP re-fetches the delegation from Authenticated User\n * Storage, re-validates it, and adds the account to its monitoring list so\n * subsequent eligible operations can be picked up automatically.\n */\nexport const registerIntentsStep: Step = {\n name: 'register-intents',\n async run({\n messenger,\n address,\n chainId,\n delegateAddress,\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n }) {\n const [delegations, existingIntents] = await Promise.all([\n messenger.call('AuthenticatedUserStorageService:listDelegations'),\n messenger.call('ChompApiService:getIntentsByAddress', address),\n ]);\n\n const activeIntentHashes = new Set(\n existingIntents\n .filter((intent: IntentEntry) => intent.status === 'active')\n .map((intent: IntentEntry) => intent.delegationHash.toLowerCase()),\n );\n\n const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n );\n\n const needsIntent = (entry: DelegationResponse): boolean =>\n equalsIgnoreCase(entry.signedDelegation.delegator, address) &&\n equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&\n equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&\n hasVedaRedeemerCaveat(entry) &&\n !activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());\n\n const toIntent = (entry: DelegationResponse): SendIntentParams => ({\n account: address,\n delegationHash: entry.metadata.delegationHash,\n chainId,\n metadata: {\n allowance: entry.metadata.allowance,\n tokenSymbol: entry.metadata.tokenSymbol,\n tokenAddress: entry.metadata.tokenAddress,\n type: parseIntentMetadataType(entry.metadata.type),\n },\n });\n\n const intents = delegations.filter(needsIntent).map(toIntent);\n\n if (intents.length === 0) {\n return 'already-done';\n }\n\n await messenger.call('ChompApiService:createIntents', intents);\n return 'completed';\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"register-intents.cjs","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":";;;AAMA,mEAG+B;AAK/B;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,iBAAiB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACU,QAAA,mBAAmB,GAAS;IACvC,IAAI,EAAE,kBAAkB;IACxB,KAAK,CAAC,GAAG,CAAC,EACR,SAAS,EACT,OAAO,EACP,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,GACxB;QACC,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG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YACjE,OAAO,EAAE,OAAO;YAChB,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc;YAC7C,OAAO;YACP,QAAQ,EAAE;gBACR,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;gBACnC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW;gBACvC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;gBACzC,IAAI,EAAE,uBAAuB,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;aACnD;SACF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE9D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,MAAM,SAAS,CAAC,IAAI,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport type {\n IntentEntry,\n SendIntentParams,\n} from '@metamask/chomp-api-service';\n\nimport {\n equalsIgnoreCase,\n makeHasVedaRedeemerCaveat,\n} from './delegation-matchers';\nimport type { Step } from './step';\n\ntype IntentMetadataType = SendIntentParams['metadata']['type'];\n\n/**\n * Parses a delegation's metadata `type` field — typed as `string` in storage —\n * into the narrow set of CHOMP intent types. Throws if the field carries any\n * other value, since registering it as an intent would be a category error.\n *\n * @param type - The `type` field from `DelegationMetadata`.\n * @returns The same value, narrowed to `IntentMetadataType`.\n */\nfunction parseIntentMetadataType(type: string): IntentMetadataType {\n if (type !== 'cash-deposit' && type !== 'cash-withdrawal') {\n throw new Error(\n `Expected delegation type to be \"cash-deposit\" or \"cash-withdrawal\", got \"${type}\"`,\n );\n }\n return type;\n}\n\n/**\n * Registers CHOMP intents for the auto-deposit / auto-withdrawal delegations\n * persisted by the build-delegation step.\n *\n * For each stored delegation between this account and CHOMP's delegate on\n * this chain, the step builds an intent referencing the stored\n * `delegationHash` and submits the batch to `POST /v1/intent`. Delegations\n * whose `delegationHash` already has an active intent on CHOMP are skipped\n * (revoked intents are re-registered). Reports `'already-done'` when every\n * eligible delegation already has an active intent.\n *\n * Once registered, CHOMP re-fetches the delegation from Authenticated User\n * Storage, re-validates it, and adds the account to its monitoring list so\n * subsequent eligible operations can be picked up automatically.\n */\nexport const registerIntentsStep: Step = {\n name: 'register-intents',\n async run({\n messenger,\n address,\n chainId,\n boringVaultAddress,\n delegateAddress,\n musdTokenAddress,\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n }) {\n const [delegations, existingIntents] = await Promise.all([\n messenger.call('AuthenticatedUserStorageService:listDelegations'),\n messenger.call('ChompApiService:getIntentsByAddress', address),\n ]);\n\n const activeIntentHashes = new Set(\n existingIntents\n .filter((intent: IntentEntry) => intent.status === 'active')\n .map((intent: IntentEntry) => intent.delegationHash.toLowerCase()),\n );\n\n const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n );\n\n const configuredTokenAddresses = [musdTokenAddress, boringVaultAddress];\n const matchesConfiguredToken = (entry: DelegationResponse): boolean =>\n configuredTokenAddresses.some((tokenAddress) =>\n equalsIgnoreCase(entry.metadata.tokenAddress, tokenAddress),\n );\n\n const needsIntent = (entry: DelegationResponse): boolean =>\n equalsIgnoreCase(entry.signedDelegation.delegator, address) &&\n equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&\n equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&\n matchesConfiguredToken(entry) &&\n hasVedaRedeemerCaveat(entry) &&\n !activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());\n\n const toIntent = (entry: DelegationResponse): SendIntentParams => ({\n account: address,\n delegationHash: entry.metadata.delegationHash,\n chainId,\n metadata: {\n allowance: entry.metadata.allowance,\n tokenSymbol: entry.metadata.tokenSymbol,\n tokenAddress: entry.metadata.tokenAddress,\n type: parseIntentMetadataType(entry.metadata.type),\n },\n });\n\n const intents = delegations.filter(needsIntent).map(toIntent);\n\n if (intents.length === 0) {\n return 'already-done';\n }\n\n await messenger.call('ChompApiService:createIntents', intents);\n return 'completed';\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-intents.d.cts","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAqBnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"register-intents.d.cts","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAqBnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,EAAE,IA+DjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-intents.d.mts","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAqBnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"register-intents.d.mts","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAqBnC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,EAAE,IA+DjC,CAAC"}
|
|
@@ -30,7 +30,7 @@ function parseIntentMetadataType(type) {
|
|
|
30
30
|
*/
|
|
31
31
|
export const registerIntentsStep = {
|
|
32
32
|
name: 'register-intents',
|
|
33
|
-
async run({ messenger, address, chainId, delegateAddress, redeemerEnforcer, vedaVaultAdapterAddress, }) {
|
|
33
|
+
async run({ messenger, address, chainId, boringVaultAddress, delegateAddress, musdTokenAddress, redeemerEnforcer, vedaVaultAdapterAddress, }) {
|
|
34
34
|
const [delegations, existingIntents] = await Promise.all([
|
|
35
35
|
messenger.call('AuthenticatedUserStorageService:listDelegations'),
|
|
36
36
|
messenger.call('ChompApiService:getIntentsByAddress', address),
|
|
@@ -39,9 +39,12 @@ export const registerIntentsStep = {
|
|
|
39
39
|
.filter((intent) => intent.status === 'active')
|
|
40
40
|
.map((intent) => intent.delegationHash.toLowerCase()));
|
|
41
41
|
const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(redeemerEnforcer, vedaVaultAdapterAddress);
|
|
42
|
+
const configuredTokenAddresses = [musdTokenAddress, boringVaultAddress];
|
|
43
|
+
const matchesConfiguredToken = (entry) => configuredTokenAddresses.some((tokenAddress) => equalsIgnoreCase(entry.metadata.tokenAddress, tokenAddress));
|
|
42
44
|
const needsIntent = (entry) => equalsIgnoreCase(entry.signedDelegation.delegator, address) &&
|
|
43
45
|
equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&
|
|
44
46
|
equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&
|
|
47
|
+
matchesConfiguredToken(entry) &&
|
|
45
48
|
hasVedaRedeemerCaveat(entry) &&
|
|
46
49
|
!activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());
|
|
47
50
|
const toIntent = (entry) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-intents.mjs","sourceRoot":"","sources":["../../src/steps/register-intents.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EAC1B,kCAA8B;AAK/B;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,iBAAiB,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CACb,4EAA4E,IAAI,GAAG,CACpF,CAAC;IACJ,CAA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O;YAChB,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc;YAC7C,OAAO;YACP,QAAQ,EAAE;gBACR,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;gBACnC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW;gBACvC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;gBACzC,IAAI,EAAE,uBAAuB,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;aACnD;SACF,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE9D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,MAAM,SAAS,CAAC,IAAI,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport type {\n IntentEntry,\n SendIntentParams,\n} from '@metamask/chomp-api-service';\n\nimport {\n equalsIgnoreCase,\n makeHasVedaRedeemerCaveat,\n} from './delegation-matchers';\nimport type { Step } from './step';\n\ntype IntentMetadataType = SendIntentParams['metadata']['type'];\n\n/**\n * Parses a delegation's metadata `type` field — typed as `string` in storage —\n * into the narrow set of CHOMP intent types. Throws if the field carries any\n * other value, since registering it as an intent would be a category error.\n *\n * @param type - The `type` field from `DelegationMetadata`.\n * @returns The same value, narrowed to `IntentMetadataType`.\n */\nfunction parseIntentMetadataType(type: string): IntentMetadataType {\n if (type !== 'cash-deposit' && type !== 'cash-withdrawal') {\n throw new Error(\n `Expected delegation type to be \"cash-deposit\" or \"cash-withdrawal\", got \"${type}\"`,\n );\n }\n return type;\n}\n\n/**\n * Registers CHOMP intents for the auto-deposit / auto-withdrawal delegations\n * persisted by the build-delegation step.\n *\n * For each stored delegation between this account and CHOMP's delegate on\n * this chain, the step builds an intent referencing the stored\n * `delegationHash` and submits the batch to `POST /v1/intent`. Delegations\n * whose `delegationHash` already has an active intent on CHOMP are skipped\n * (revoked intents are re-registered). Reports `'already-done'` when every\n * eligible delegation already has an active intent.\n *\n * Once registered, CHOMP re-fetches the delegation from Authenticated User\n * Storage, re-validates it, and adds the account to its monitoring list so\n * subsequent eligible operations can be picked up automatically.\n */\nexport const registerIntentsStep: Step = {\n name: 'register-intents',\n async run({\n messenger,\n address,\n chainId,\n delegateAddress,\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n }) {\n const [delegations, existingIntents] = await Promise.all([\n messenger.call('AuthenticatedUserStorageService:listDelegations'),\n messenger.call('ChompApiService:getIntentsByAddress', address),\n ]);\n\n const activeIntentHashes = new Set(\n existingIntents\n .filter((intent: IntentEntry) => intent.status === 'active')\n .map((intent: IntentEntry) => intent.delegationHash.toLowerCase()),\n );\n\n const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n );\n\n const needsIntent = (entry: DelegationResponse): boolean =>\n equalsIgnoreCase(entry.signedDelegation.delegator, address) &&\n equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&\n equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&\n hasVedaRedeemerCaveat(entry) &&\n !activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());\n\n const toIntent = (entry: DelegationResponse): SendIntentParams => ({\n account: address,\n delegationHash: entry.metadata.delegationHash,\n chainId,\n metadata: {\n allowance: entry.metadata.allowance,\n tokenSymbol: entry.metadata.tokenSymbol,\n tokenAddress: entry.metadata.tokenAddress,\n type: parseIntentMetadataType(entry.metadata.type),\n },\n });\n\n const intents = delegations.filter(needsIntent).map(toIntent);\n\n if (intents.length === 0) {\n return 'already-done';\n }\n\n await messenger.call('ChompApiService:createIntents', intents);\n return 'completed';\n },\n};\n"]}
|
|
1
|
+
{"version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AAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport type {\n IntentEntry,\n SendIntentParams,\n} from '@metamask/chomp-api-service';\n\nimport {\n equalsIgnoreCase,\n makeHasVedaRedeemerCaveat,\n} from './delegation-matchers';\nimport type { Step } from './step';\n\ntype IntentMetadataType = SendIntentParams['metadata']['type'];\n\n/**\n * Parses a delegation's metadata `type` field — typed as `string` in storage —\n * into the narrow set of CHOMP intent types. Throws if the field carries any\n * other value, since registering it as an intent would be a category error.\n *\n * @param type - The `type` field from `DelegationMetadata`.\n * @returns The same value, narrowed to `IntentMetadataType`.\n */\nfunction parseIntentMetadataType(type: string): IntentMetadataType {\n if (type !== 'cash-deposit' && type !== 'cash-withdrawal') {\n throw new Error(\n `Expected delegation type to be \"cash-deposit\" or \"cash-withdrawal\", got \"${type}\"`,\n );\n }\n return type;\n}\n\n/**\n * Registers CHOMP intents for the auto-deposit / auto-withdrawal delegations\n * persisted by the build-delegation step.\n *\n * For each stored delegation between this account and CHOMP's delegate on\n * this chain, the step builds an intent referencing the stored\n * `delegationHash` and submits the batch to `POST /v1/intent`. Delegations\n * whose `delegationHash` already has an active intent on CHOMP are skipped\n * (revoked intents are re-registered). Reports `'already-done'` when every\n * eligible delegation already has an active intent.\n *\n * Once registered, CHOMP re-fetches the delegation from Authenticated User\n * Storage, re-validates it, and adds the account to its monitoring list so\n * subsequent eligible operations can be picked up automatically.\n */\nexport const registerIntentsStep: Step = {\n name: 'register-intents',\n async run({\n messenger,\n address,\n chainId,\n boringVaultAddress,\n delegateAddress,\n musdTokenAddress,\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n }) {\n const [delegations, existingIntents] = await Promise.all([\n messenger.call('AuthenticatedUserStorageService:listDelegations'),\n messenger.call('ChompApiService:getIntentsByAddress', address),\n ]);\n\n const activeIntentHashes = new Set(\n existingIntents\n .filter((intent: IntentEntry) => intent.status === 'active')\n .map((intent: IntentEntry) => intent.delegationHash.toLowerCase()),\n );\n\n const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n );\n\n const configuredTokenAddresses = [musdTokenAddress, boringVaultAddress];\n const matchesConfiguredToken = (entry: DelegationResponse): boolean =>\n configuredTokenAddresses.some((tokenAddress) =>\n equalsIgnoreCase(entry.metadata.tokenAddress, tokenAddress),\n );\n\n const needsIntent = (entry: DelegationResponse): boolean =>\n equalsIgnoreCase(entry.signedDelegation.delegator, address) &&\n equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&\n equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&\n matchesConfiguredToken(entry) &&\n hasVedaRedeemerCaveat(entry) &&\n !activeIntentHashes.has(entry.metadata.delegationHash.toLowerCase());\n\n const toIntent = (entry: DelegationResponse): SendIntentParams => ({\n account: address,\n delegationHash: entry.metadata.delegationHash,\n chainId,\n metadata: {\n allowance: entry.metadata.allowance,\n tokenSymbol: entry.metadata.tokenSymbol,\n tokenAddress: entry.metadata.tokenAddress,\n type: parseIntentMetadataType(entry.metadata.type),\n },\n });\n\n const intents = delegations.filter(needsIntent).map(toIntent);\n\n if (intents.length === 0) {\n return 'already-done';\n }\n\n await messenger.call('ChompApiService:createIntents', intents);\n return 'completed';\n },\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/money-account-upgrade-controller",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "MetaMask Money account upgrade controller",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -59,10 +59,10 @@
|
|
|
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.
|
|
62
|
+
"@metamask/keyring-controller": "^27.1.0",
|
|
63
63
|
"@metamask/messenger": "^1.2.0",
|
|
64
|
-
"@metamask/network-controller": "^
|
|
65
|
-
"@metamask/utils": "^11.
|
|
64
|
+
"@metamask/network-controller": "^33.0.0",
|
|
65
|
+
"@metamask/utils": "^11.11.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@metamask/auto-changelog": "^6.1.0",
|