@metamask-previews/money-account-upgrade-controller 3.0.2-preview-4f4c98e → 3.0.2-preview-eb263b0ee
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 +0 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.cjs +7 -0
- package/dist/MoneyAccountUpgradeController-method-action-types.cjs.map +1 -0
- package/dist/{MoneyAccountUpgradeController-method-action-types.d.ts → MoneyAccountUpgradeController-method-action-types.d.cts} +2 -2
- package/dist/MoneyAccountUpgradeController-method-action-types.d.cts.map +1 -0
- package/dist/MoneyAccountUpgradeController-method-action-types.d.mts +30 -0
- package/dist/MoneyAccountUpgradeController-method-action-types.d.mts.map +1 -0
- package/dist/{MoneyAccountUpgradeController-method-action-types.js → MoneyAccountUpgradeController-method-action-types.mjs} +1 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.mjs.map +1 -0
- package/dist/MoneyAccountUpgradeController.cjs +197 -0
- package/dist/MoneyAccountUpgradeController.cjs.map +1 -0
- package/dist/{MoneyAccountUpgradeController.d.ts → MoneyAccountUpgradeController.d.cts} +11 -11
- package/dist/MoneyAccountUpgradeController.d.cts.map +1 -0
- package/dist/MoneyAccountUpgradeController.d.mts +102 -0
- package/dist/MoneyAccountUpgradeController.d.mts.map +1 -0
- package/dist/{MoneyAccountUpgradeController.js → MoneyAccountUpgradeController.mjs} +9 -9
- package/dist/MoneyAccountUpgradeController.mjs.map +1 -0
- package/dist/errors.cjs +75 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{errors.d.ts → errors.d.cts} +1 -1
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +59 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/{errors.js → errors.mjs} +1 -1
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +6 -6
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/steps/associate-address.cjs +84 -0
- package/dist/steps/associate-address.cjs.map +1 -0
- package/dist/steps/{associate-address.d.ts → associate-address.d.cts} +2 -2
- package/dist/steps/associate-address.d.cts.map +1 -0
- package/dist/steps/associate-address.d.mts +28 -0
- package/dist/steps/associate-address.d.mts.map +1 -0
- package/dist/steps/{associate-address.js → associate-address.mjs} +4 -4
- package/dist/steps/associate-address.mjs.map +1 -0
- package/dist/steps/build-delegations.cjs +130 -0
- package/dist/steps/build-delegations.cjs.map +1 -0
- package/dist/steps/build-delegations.d.cts +3 -0
- package/dist/steps/build-delegations.d.cts.map +1 -0
- package/dist/steps/build-delegations.d.mts +3 -0
- package/dist/steps/build-delegations.d.mts.map +1 -0
- package/dist/steps/{build-delegations.js → build-delegations.mjs} +4 -4
- package/dist/steps/build-delegations.mjs.map +1 -0
- package/dist/steps/delegation-matchers.cjs +26 -0
- package/dist/steps/delegation-matchers.cjs.map +1 -0
- package/dist/steps/{delegation-matchers.d.ts → delegation-matchers.d.cts} +4 -4
- package/dist/steps/delegation-matchers.d.cts.map +1 -0
- package/dist/steps/delegation-matchers.d.mts +16 -0
- package/dist/steps/delegation-matchers.d.mts.map +1 -0
- package/dist/steps/{delegation-matchers.js → delegation-matchers.mjs} +2 -2
- package/dist/steps/delegation-matchers.mjs.map +1 -0
- package/dist/steps/eip-7702-authorization.cjs +175 -0
- package/dist/steps/eip-7702-authorization.cjs.map +1 -0
- package/dist/steps/{eip-7702-authorization.d.ts → eip-7702-authorization.d.cts} +2 -2
- package/dist/steps/eip-7702-authorization.d.cts.map +1 -0
- package/dist/steps/eip-7702-authorization.d.mts +21 -0
- package/dist/steps/eip-7702-authorization.d.mts.map +1 -0
- package/dist/steps/{eip-7702-authorization.js → eip-7702-authorization.mjs} +3 -3
- package/dist/steps/eip-7702-authorization.mjs.map +1 -0
- package/dist/steps/register-intents.cjs +72 -0
- package/dist/steps/register-intents.cjs.map +1 -0
- package/dist/steps/{register-intents.d.ts → register-intents.d.cts} +2 -2
- package/dist/steps/register-intents.d.cts.map +1 -0
- package/dist/steps/register-intents.d.mts +18 -0
- package/dist/steps/register-intents.d.mts.map +1 -0
- package/dist/steps/{register-intents.js → register-intents.mjs} +2 -2
- package/dist/steps/register-intents.mjs.map +1 -0
- package/dist/steps/step.cjs +3 -0
- package/dist/steps/step.cjs.map +1 -0
- package/dist/steps/{step.d.ts → step.d.cts} +3 -3
- package/dist/steps/step.d.cts.map +1 -0
- package/dist/steps/step.d.mts +38 -0
- package/dist/steps/step.d.mts.map +1 -0
- package/dist/steps/step.mjs +2 -0
- package/dist/steps/step.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +2 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +29 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +17 -12
- package/dist/MoneyAccountUpgradeController-method-action-types.d.ts.map +0 -1
- package/dist/MoneyAccountUpgradeController-method-action-types.js.map +0 -1
- package/dist/MoneyAccountUpgradeController.d.ts.map +0 -1
- package/dist/MoneyAccountUpgradeController.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/steps/associate-address.d.ts.map +0 -1
- package/dist/steps/associate-address.js.map +0 -1
- package/dist/steps/build-delegations.d.ts +0 -3
- package/dist/steps/build-delegations.d.ts.map +0 -1
- package/dist/steps/build-delegations.js.map +0 -1
- package/dist/steps/delegation-matchers.d.ts.map +0 -1
- package/dist/steps/delegation-matchers.js.map +0 -1
- package/dist/steps/eip-7702-authorization.d.ts.map +0 -1
- package/dist/steps/eip-7702-authorization.js.map +0 -1
- package/dist/steps/register-intents.d.ts.map +0 -1
- package/dist/steps/register-intents.js.map +0 -1
- package/dist/steps/step.d.ts.map +0 -1
- package/dist/steps/step.js +0 -2
- package/dist/steps/step.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
-
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
12
|
- Bump `@metamask/authenticated-user-storage` from `^3.0.1` to `^3.0.2` ([#9972](https://github.com/MetaMask/core/pull/9972))
|
|
14
13
|
- Bump `@metamask/chomp-api-service` from `^4.0.0` to `^4.0.1` ([#9972](https://github.com/MetaMask/core/pull/9972))
|
|
15
14
|
|
|
@@ -0,0 +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.js';\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 * A run that completes is recorded in state (keyed by lowercased address,\n * fingerprinted against the active config); subsequent calls for a\n * recorded account return immediately without running any steps. If the\n * active config no longer matches the recorded fingerprint, the sequence\n * re-runs.\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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { MoneyAccountUpgradeController } from
|
|
5
|
+
import type { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.cjs";
|
|
6
6
|
/**
|
|
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
|
|
@@ -27,4 +27,4 @@ export type MoneyAccountUpgradeControllerUpgradeAccountAction = {
|
|
|
27
27
|
* Union of all MoneyAccountUpgradeController action types.
|
|
28
28
|
*/
|
|
29
29
|
export type MoneyAccountUpgradeControllerMethodActions = MoneyAccountUpgradeControllerUpgradeAccountAction;
|
|
30
|
-
//# sourceMappingURL=MoneyAccountUpgradeController-method-action-types.d.
|
|
30
|
+
//# sourceMappingURL=MoneyAccountUpgradeController-method-action-types.d.cts.map
|
|
@@ -0,0 +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,4CAA2C;AAExF;;;;;;;;;;;;;;;GAeG;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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Runs each step in the upgrade sequence in order. A step that reports
|
|
8
|
+
* `'already-done'` is skipped without performing any action; a step that
|
|
9
|
+
* reports `'completed'` has performed its action. An error thrown by any
|
|
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`).
|
|
13
|
+
*
|
|
14
|
+
* A run that completes is recorded in state (keyed by lowercased address,
|
|
15
|
+
* fingerprinted against the active config); subsequent calls for a
|
|
16
|
+
* recorded account return immediately without running any steps. If the
|
|
17
|
+
* active config no longer matches the recorded fingerprint, the sequence
|
|
18
|
+
* re-runs.
|
|
19
|
+
*
|
|
20
|
+
* @param address - The Money Account address to upgrade.
|
|
21
|
+
*/
|
|
22
|
+
export type MoneyAccountUpgradeControllerUpgradeAccountAction = {
|
|
23
|
+
type: `MoneyAccountUpgradeController:upgradeAccount`;
|
|
24
|
+
handler: MoneyAccountUpgradeController['upgradeAccount'];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Union of all MoneyAccountUpgradeController action types.
|
|
28
|
+
*/
|
|
29
|
+
export type MoneyAccountUpgradeControllerMethodActions = MoneyAccountUpgradeControllerUpgradeAccountAction;
|
|
30
|
+
//# sourceMappingURL=MoneyAccountUpgradeController-method-action-types.d.mts.map
|
|
@@ -0,0 +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,4CAA2C;AAExF;;;;;;;;;;;;;;;GAeG;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"}
|
|
@@ -0,0 +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.js';\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 * A run that completes is recorded in state (keyed by lowercased address,\n * fingerprinted against the active config); subsequent calls for a\n * recorded account return immediately without running any steps. If the\n * active config no longer matches the recorded fingerprint, the sequence\n * re-runs.\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"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MoneyAccountUpgradeController = exports.getDefaultMoneyAccountUpgradeControllerState = exports.controllerName = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const delegation_deployments_1 = require("@metamask/delegation-deployments");
|
|
18
|
+
const utils_1 = require("@metamask/utils");
|
|
19
|
+
const errors_js_1 = require("./errors.cjs");
|
|
20
|
+
const associate_address_js_1 = require("./steps/associate-address.cjs");
|
|
21
|
+
const build_delegations_js_1 = require("./steps/build-delegations.cjs");
|
|
22
|
+
const eip_7702_authorization_js_1 = require("./steps/eip-7702-authorization.cjs");
|
|
23
|
+
const register_intents_js_1 = require("./steps/register-intents.cjs");
|
|
24
|
+
/**
|
|
25
|
+
* The Delegation Framework deployment version we resolve contract addresses
|
|
26
|
+
* against in `@metamask/delegation-deployments`.
|
|
27
|
+
*/
|
|
28
|
+
const DELEGATION_FRAMEWORK_VERSION = '1.3.0';
|
|
29
|
+
exports.controllerName = 'MoneyAccountUpgradeController';
|
|
30
|
+
const moneyAccountUpgradeControllerMetadata = {
|
|
31
|
+
upgradedAccounts: {
|
|
32
|
+
includeInDebugSnapshot: false,
|
|
33
|
+
includeInStateLogs: false,
|
|
34
|
+
persist: true,
|
|
35
|
+
usedInUi: false,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Constructs the default {@link MoneyAccountUpgradeController} state. This
|
|
40
|
+
* allows consumers to provide a partial state object when initializing the
|
|
41
|
+
* controller and also helps in constructing complete state objects for this
|
|
42
|
+
* controller in tests.
|
|
43
|
+
*
|
|
44
|
+
* @returns The default {@link MoneyAccountUpgradeController} state.
|
|
45
|
+
*/
|
|
46
|
+
function getDefaultMoneyAccountUpgradeControllerState() {
|
|
47
|
+
return {
|
|
48
|
+
upgradedAccounts: {},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.getDefaultMoneyAccountUpgradeControllerState = getDefaultMoneyAccountUpgradeControllerState;
|
|
52
|
+
const MESSENGER_EXPOSED_METHODS = ['upgradeAccount'];
|
|
53
|
+
/**
|
|
54
|
+
* Controller that orchestrates the Money Account upgrade sequence.
|
|
55
|
+
*/
|
|
56
|
+
class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
57
|
+
/**
|
|
58
|
+
* Constructor for the MoneyAccountUpgradeController.
|
|
59
|
+
*
|
|
60
|
+
* @param options - The options for constructing the controller.
|
|
61
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
62
|
+
* @param options.state - The initial state, merged with the defaults.
|
|
63
|
+
*/
|
|
64
|
+
constructor({ messenger, state, }) {
|
|
65
|
+
super({
|
|
66
|
+
messenger,
|
|
67
|
+
metadata: moneyAccountUpgradeControllerMetadata,
|
|
68
|
+
name: exports.controllerName,
|
|
69
|
+
state: {
|
|
70
|
+
...getDefaultMoneyAccountUpgradeControllerState(),
|
|
71
|
+
...state,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
_MoneyAccountUpgradeController_config.set(this, void 0);
|
|
75
|
+
_MoneyAccountUpgradeController_steps.set(this, [
|
|
76
|
+
associate_address_js_1.associateAddressStep,
|
|
77
|
+
eip_7702_authorization_js_1.eip7702AuthorizationStep,
|
|
78
|
+
build_delegations_js_1.buildDelegationStep,
|
|
79
|
+
register_intents_js_1.registerIntentsStep,
|
|
80
|
+
]);
|
|
81
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Fetches service details and validates the controller can operate on the
|
|
85
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
86
|
+
* chain from `@metamask/delegation-deployments`.
|
|
87
|
+
*
|
|
88
|
+
* @param params - The parameters for initialization.
|
|
89
|
+
* @param params.chainId - The chain to initialize for.
|
|
90
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
91
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
92
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
93
|
+
* exposes it.
|
|
94
|
+
*/
|
|
95
|
+
async init({ chainId, boringVaultAddress, }) {
|
|
96
|
+
const contracts = delegation_deployments_1.DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][(0, utils_1.hexToNumber)(chainId)];
|
|
97
|
+
if (!contracts) {
|
|
98
|
+
throw new Error(`Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`);
|
|
99
|
+
}
|
|
100
|
+
const response = await this.messenger.call('ChompApiService:getServiceDetails', [chainId]);
|
|
101
|
+
const chain = response.chains[chainId];
|
|
102
|
+
if (!chain) {
|
|
103
|
+
throw new Error(`Chain ${chainId} not found in service details response`);
|
|
104
|
+
}
|
|
105
|
+
const { vedaProtocol } = chain.protocol;
|
|
106
|
+
if (!vedaProtocol) {
|
|
107
|
+
throw new Error(`vedaProtocol not found for chain ${chainId} in service details response`);
|
|
108
|
+
}
|
|
109
|
+
if (vedaProtocol.supportedTokens.length === 0) {
|
|
110
|
+
throw new Error(`No supported tokens found for vedaProtocol on chain ${chainId}`);
|
|
111
|
+
}
|
|
112
|
+
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_config, {
|
|
113
|
+
chainId,
|
|
114
|
+
delegateAddress: chain.autoDepositDelegate,
|
|
115
|
+
musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,
|
|
116
|
+
boringVaultAddress,
|
|
117
|
+
vedaVaultAdapterAddress: vedaProtocol.adapterAddress,
|
|
118
|
+
delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,
|
|
119
|
+
erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,
|
|
120
|
+
redeemerEnforcer: contracts.RedeemerEnforcer,
|
|
121
|
+
valueLteEnforcer: contracts.ValueLteEnforcer,
|
|
122
|
+
}, "f");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Runs each step in the upgrade sequence in order. A step that reports
|
|
126
|
+
* `'already-done'` is skipped without performing any action; a step that
|
|
127
|
+
* reports `'completed'` has performed its action. An error thrown by any
|
|
128
|
+
* step halts the sequence and is re-thrown wrapped in a
|
|
129
|
+
* {@link MoneyAccountUpgradeStepError} that records which step failed (the
|
|
130
|
+
* original error is preserved as `cause`).
|
|
131
|
+
*
|
|
132
|
+
* A run that completes is recorded in state (keyed by lowercased address,
|
|
133
|
+
* fingerprinted against the active config); subsequent calls for a
|
|
134
|
+
* recorded account return immediately without running any steps. If the
|
|
135
|
+
* active config no longer matches the recorded fingerprint, the sequence
|
|
136
|
+
* re-runs.
|
|
137
|
+
*
|
|
138
|
+
* @param address - The Money Account address to upgrade.
|
|
139
|
+
*/
|
|
140
|
+
async upgradeAccount(address) {
|
|
141
|
+
if (!__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f")) {
|
|
142
|
+
throw new Error('MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called');
|
|
143
|
+
}
|
|
144
|
+
const config = __classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f");
|
|
145
|
+
const accountKey = address.toLowerCase();
|
|
146
|
+
const configFingerprint = computeConfigFingerprint(config);
|
|
147
|
+
if (this.state.upgradedAccounts[accountKey]?.configFingerprint ===
|
|
148
|
+
configFingerprint) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
for (const step of __classPrivateFieldGet(this, _MoneyAccountUpgradeController_steps, "f")) {
|
|
152
|
+
try {
|
|
153
|
+
await step.run({
|
|
154
|
+
messenger: this.messenger,
|
|
155
|
+
address,
|
|
156
|
+
...config,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
throw new errors_js_1.MoneyAccountUpgradeStepError(step.name, error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
this.update((state) => {
|
|
164
|
+
state.upgradedAccounts[accountKey] = {
|
|
165
|
+
configFingerprint,
|
|
166
|
+
completedAt: Date.now(),
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.MoneyAccountUpgradeController = MoneyAccountUpgradeController;
|
|
172
|
+
_MoneyAccountUpgradeController_config = new WeakMap(), _MoneyAccountUpgradeController_steps = new WeakMap();
|
|
173
|
+
/**
|
|
174
|
+
* Derives a stable fingerprint of the config fields that define what
|
|
175
|
+
* "upgraded" means for an account. A recorded upgrade is only trusted while
|
|
176
|
+
* the active config produces the same fingerprint.
|
|
177
|
+
*
|
|
178
|
+
* @param config - The active upgrade config.
|
|
179
|
+
* @returns A canonical string over the config's identifying fields.
|
|
180
|
+
*/
|
|
181
|
+
function computeConfigFingerprint(config) {
|
|
182
|
+
return [
|
|
183
|
+
DELEGATION_FRAMEWORK_VERSION,
|
|
184
|
+
config.chainId,
|
|
185
|
+
config.delegateAddress,
|
|
186
|
+
config.musdTokenAddress,
|
|
187
|
+
config.boringVaultAddress,
|
|
188
|
+
config.vedaVaultAdapterAddress,
|
|
189
|
+
config.delegatorImplAddress,
|
|
190
|
+
config.erc20TransferAmountEnforcer,
|
|
191
|
+
config.redeemerEnforcer,
|
|
192
|
+
config.valueLteEnforcer,
|
|
193
|
+
]
|
|
194
|
+
.map((value) => value.toLowerCase())
|
|
195
|
+
.join('|');
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=MoneyAccountUpgradeController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,+DAA2D;AAW3D,6EAAuE;AAUvE,2CAA8C;AAG9C,4CAA2D;AAE3D,wEAAoE;AACpE,wEAAmE;AACnE,kFAA6E;AAC7E,sEAAkE;AAIlE;;;GAGG;AACH,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEhC,QAAA,cAAc,GAAG,+BAA+B,CAAC;AAyB9D,MAAM,qCAAqC,GAAG;IAC5C,gBAAgB,EAAE;QAChB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;KAChB;CAC0D,CAAC;AAE9D;;;;;;;GAOG;AACH,SAAgB,4CAA4C;IAC1D,OAAO;QACL,gBAAgB,EAAE,EAAE;KACrB,CAAC;AACJ,CAAC;AAJD,oGAIC;AAED,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AA6C9D;;GAEG;AACH,MAAa,6BAA8B,SAAQ,gCAIlD;IAUC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,qCAAqC;YAC/C,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,4CAA4C,EAAE;gBACjD,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QA/BL,wDAA2C;QAElC,+CAAiB;YACxB,2CAAoB;YACpB,oDAAwB;YACxB,0CAAmB;YACnB,yCAAmB;SACpB,EAAC;QA0BA,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;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,CAAC,gBAAgB;QACvB,MAAM,CAAC,kBAAkB;QACzB,MAAM,CAAC,uBAAuB;QAC9B,MAAM,CAAC,oBAAoB;QAC3B,MAAM,CAAC,2BAA2B;QAClC,MAAM,CAAC,gBAAgB;QACvB,MAAM,CAAC,gBAAgB;KACxB;SACE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACnC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","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 ChompApiServiceGetAssociatedAddressesAction,\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.js';\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types.js';\nimport { associateAddressStep } from './steps/associate-address.js';\nimport { buildDelegationStep } from './steps/build-delegations.js';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization.js';\nimport { registerIntentsStep } from './steps/register-intents.js';\nimport type { Step } from './steps/step.js';\nimport type { UpgradeConfig } from './types.js';\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\n/**\n * Record of a Money Account upgrade sequence that ran to completion.\n */\nexport type MoneyAccountUpgradeStatus = {\n /**\n * Fingerprint of the upgrade config the sequence completed under. The\n * record is only trusted while the active config produces the same\n * fingerprint — if the chain, CHOMP contracts, or Delegation Framework\n * version change, the sequence re-runs.\n */\n configFingerprint: string;\n /** Unix timestamp (in milliseconds) when the sequence completed. */\n completedAt: number;\n};\n\nexport type MoneyAccountUpgradeControllerState = {\n /**\n * Accounts whose upgrade sequence has fully completed, keyed by lowercased\n * account address.\n */\n upgradedAccounts: { [address: Hex]: MoneyAccountUpgradeStatus };\n};\n\nconst moneyAccountUpgradeControllerMetadata = {\n upgradedAccounts: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\n/**\n * Constructs the default {@link MoneyAccountUpgradeController} state. This\n * allows consumers to provide a partial state object when initializing the\n * controller and also helps in constructing complete state objects for this\n * controller in tests.\n *\n * @returns The default {@link MoneyAccountUpgradeController} state.\n */\nexport function getDefaultMoneyAccountUpgradeControllerState(): MoneyAccountUpgradeControllerState {\n return {\n upgradedAccounts: {},\n };\n}\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 | ChompApiServiceGetAssociatedAddressesAction\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 * @param options.state - The initial state, merged with the defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n state?: Partial<MoneyAccountUpgradeControllerState>;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultMoneyAccountUpgradeControllerState(),\n ...state,\n },\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 * A run that completes is recorded in state (keyed by lowercased address,\n * fingerprinted against the active config); subsequent calls for a\n * recorded account return immediately without running any steps. If the\n * active config no longer matches the recorded fingerprint, the sequence\n * re-runs.\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 const config = this.#config;\n\n const accountKey = address.toLowerCase() as Hex;\n const configFingerprint = computeConfigFingerprint(config);\n if (\n this.state.upgradedAccounts[accountKey]?.configFingerprint ===\n configFingerprint\n ) {\n return;\n }\n\n for (const step of this.#steps) {\n try {\n await step.run({\n messenger: this.messenger,\n address,\n ...config,\n });\n } catch (error) {\n throw new MoneyAccountUpgradeStepError(step.name, error);\n }\n }\n\n this.update((state) => {\n state.upgradedAccounts[accountKey] = {\n configFingerprint,\n completedAt: Date.now(),\n };\n });\n }\n}\n\n/**\n * Derives a stable fingerprint of the config fields that define what\n * \"upgraded\" means for an account. A recorded upgrade is only trusted while\n * the active config produces the same fingerprint.\n *\n * @param config - The active upgrade config.\n * @returns A canonical string over the config's identifying fields.\n */\nfunction computeConfigFingerprint(\n config: UpgradeConfig & { chainId: Hex },\n): string {\n return [\n DELEGATION_FRAMEWORK_VERSION,\n config.chainId,\n config.delegateAddress,\n config.musdTokenAddress,\n config.boringVaultAddress,\n config.vedaVaultAdapterAddress,\n config.delegatorImplAddress,\n config.erc20TransferAmountEnforcer,\n config.redeemerEnforcer,\n config.valueLteEnforcer,\n ]\n .map((value) => value.toLowerCase())\n .join('|');\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceListDelegationsAction } from
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangedEvent } from
|
|
3
|
-
import { BaseController } from
|
|
4
|
-
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateIntentsAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetAssociatedAddressesAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceVerifyDelegationAction } from
|
|
5
|
-
import type { DelegationControllerSignDelegationAction } from
|
|
6
|
-
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from
|
|
7
|
-
import type { Messenger } from
|
|
8
|
-
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from
|
|
9
|
-
import type { Hex } from
|
|
10
|
-
import type { MoneyAccountUpgradeControllerMethodActions } from
|
|
1
|
+
import type { AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceListDelegationsAction } from "@metamask/authenticated-user-storage";
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
3
|
+
import { BaseController } from "@metamask/base-controller";
|
|
4
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateIntentsAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetAssociatedAddressesAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceVerifyDelegationAction } from "@metamask/chomp-api-service";
|
|
5
|
+
import type { DelegationControllerSignDelegationAction } from "@metamask/delegation-controller";
|
|
6
|
+
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
7
|
+
import type { Messenger } from "@metamask/messenger";
|
|
8
|
+
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
9
|
+
import type { Hex } from "@metamask/utils";
|
|
10
|
+
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.cjs";
|
|
11
11
|
export declare const controllerName = "MoneyAccountUpgradeController";
|
|
12
12
|
/**
|
|
13
13
|
* Record of a Money Account upgrade sequence that ran to completion.
|
|
@@ -99,4 +99,4 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
|
|
|
99
99
|
upgradeAccount(address: Hex): Promise<void>;
|
|
100
100
|
}
|
|
101
101
|
export {};
|
|
102
|
-
//# sourceMappingURL=MoneyAccountUpgradeController.d.
|
|
102
|
+
//# sourceMappingURL=MoneyAccountUpgradeController.d.cts.map
|
|
@@ -0,0 +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,2CAA2C,EAC3C,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,gEAA+D;AAczH,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;;;OAKG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAC;CACrB,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E,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;;;;;;;;;OAeG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAoClD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceListDelegationsAction } from "@metamask/authenticated-user-storage";
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
3
|
+
import { BaseController } from "@metamask/base-controller";
|
|
4
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateIntentsAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetAssociatedAddressesAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceVerifyDelegationAction } from "@metamask/chomp-api-service";
|
|
5
|
+
import type { DelegationControllerSignDelegationAction } from "@metamask/delegation-controller";
|
|
6
|
+
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
7
|
+
import type { Messenger } from "@metamask/messenger";
|
|
8
|
+
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
9
|
+
import type { Hex } from "@metamask/utils";
|
|
10
|
+
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.mjs";
|
|
11
|
+
export declare const controllerName = "MoneyAccountUpgradeController";
|
|
12
|
+
/**
|
|
13
|
+
* Record of a Money Account upgrade sequence that ran to completion.
|
|
14
|
+
*/
|
|
15
|
+
export type MoneyAccountUpgradeStatus = {
|
|
16
|
+
/**
|
|
17
|
+
* Fingerprint of the upgrade config the sequence completed under. The
|
|
18
|
+
* record is only trusted while the active config produces the same
|
|
19
|
+
* fingerprint — if the chain, CHOMP contracts, or Delegation Framework
|
|
20
|
+
* version change, the sequence re-runs.
|
|
21
|
+
*/
|
|
22
|
+
configFingerprint: string;
|
|
23
|
+
/** Unix timestamp (in milliseconds) when the sequence completed. */
|
|
24
|
+
completedAt: number;
|
|
25
|
+
};
|
|
26
|
+
export type MoneyAccountUpgradeControllerState = {
|
|
27
|
+
/**
|
|
28
|
+
* Accounts whose upgrade sequence has fully completed, keyed by lowercased
|
|
29
|
+
* account address.
|
|
30
|
+
*/
|
|
31
|
+
upgradedAccounts: {
|
|
32
|
+
[address: Hex]: MoneyAccountUpgradeStatus;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Constructs the default {@link MoneyAccountUpgradeController} state. This
|
|
37
|
+
* allows consumers to provide a partial state object when initializing the
|
|
38
|
+
* controller and also helps in constructing complete state objects for this
|
|
39
|
+
* controller in tests.
|
|
40
|
+
*
|
|
41
|
+
* @returns The default {@link MoneyAccountUpgradeController} state.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDefaultMoneyAccountUpgradeControllerState(): MoneyAccountUpgradeControllerState;
|
|
44
|
+
export type MoneyAccountUpgradeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
45
|
+
export type MoneyAccountUpgradeControllerActions = MoneyAccountUpgradeControllerGetStateAction | MoneyAccountUpgradeControllerMethodActions;
|
|
46
|
+
type AllowedActions = AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceListDelegationsAction | ChompApiServiceAssociateAddressAction | ChompApiServiceCreateIntentsAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetAssociatedAddressesAction | ChompApiServiceGetIntentsByAddressAction | ChompApiServiceGetServiceDetailsAction | ChompApiServiceVerifyDelegationAction | DelegationControllerSignDelegationAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
47
|
+
export type MoneyAccountUpgradeControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
48
|
+
export type MoneyAccountUpgradeControllerEvents = MoneyAccountUpgradeControllerStateChangedEvent;
|
|
49
|
+
type AllowedEvents = never;
|
|
50
|
+
export type MoneyAccountUpgradeControllerMessenger = Messenger<typeof controllerName, MoneyAccountUpgradeControllerActions | AllowedActions, MoneyAccountUpgradeControllerEvents | AllowedEvents>;
|
|
51
|
+
/**
|
|
52
|
+
* Controller that orchestrates the Money Account upgrade sequence.
|
|
53
|
+
*/
|
|
54
|
+
export declare class MoneyAccountUpgradeController extends BaseController<typeof controllerName, MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerMessenger> {
|
|
55
|
+
#private;
|
|
56
|
+
/**
|
|
57
|
+
* Constructor for the MoneyAccountUpgradeController.
|
|
58
|
+
*
|
|
59
|
+
* @param options - The options for constructing the controller.
|
|
60
|
+
* @param options.messenger - The messenger to use for inter-controller communication.
|
|
61
|
+
* @param options.state - The initial state, merged with the defaults.
|
|
62
|
+
*/
|
|
63
|
+
constructor({ messenger, state, }: {
|
|
64
|
+
messenger: MoneyAccountUpgradeControllerMessenger;
|
|
65
|
+
state?: Partial<MoneyAccountUpgradeControllerState>;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Fetches service details and validates the controller can operate on the
|
|
69
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
70
|
+
* chain from `@metamask/delegation-deployments`.
|
|
71
|
+
*
|
|
72
|
+
* @param params - The parameters for initialization.
|
|
73
|
+
* @param params.chainId - The chain to initialize for.
|
|
74
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
75
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
76
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
77
|
+
* exposes it.
|
|
78
|
+
*/
|
|
79
|
+
init({ chainId, boringVaultAddress, }: {
|
|
80
|
+
chainId: Hex;
|
|
81
|
+
boringVaultAddress: Hex;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Runs each step in the upgrade sequence in order. A step that reports
|
|
85
|
+
* `'already-done'` is skipped without performing any action; a step that
|
|
86
|
+
* reports `'completed'` has performed its action. An error thrown by any
|
|
87
|
+
* step halts the sequence and is re-thrown wrapped in a
|
|
88
|
+
* {@link MoneyAccountUpgradeStepError} that records which step failed (the
|
|
89
|
+
* original error is preserved as `cause`).
|
|
90
|
+
*
|
|
91
|
+
* A run that completes is recorded in state (keyed by lowercased address,
|
|
92
|
+
* fingerprinted against the active config); subsequent calls for a
|
|
93
|
+
* recorded account return immediately without running any steps. If the
|
|
94
|
+
* active config no longer matches the recorded fingerprint, the sequence
|
|
95
|
+
* re-runs.
|
|
96
|
+
*
|
|
97
|
+
* @param address - The Money Account address to upgrade.
|
|
98
|
+
*/
|
|
99
|
+
upgradeAccount(address: Hex): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=MoneyAccountUpgradeController.d.mts.map
|
|
@@ -0,0 +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,2CAA2C,EAC3C,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,wCAAwC;AAEhG,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAA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Ac,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAUC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;QAClD,KAAK,CAAC,EAAE,OAAO,CAAC,kCAAkC,CAAC,CAAC;KACrD;IAiBD;;;;;;;;;;;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;;;;;;;;;;;;;;;OAeG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAoClD"}
|
|
@@ -10,14 +10,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
13
|
-
import { BaseController } from
|
|
14
|
-
import { DELEGATOR_CONTRACTS } from
|
|
15
|
-
import { hexToNumber } from
|
|
16
|
-
import { MoneyAccountUpgradeStepError } from
|
|
17
|
-
import { associateAddressStep } from
|
|
18
|
-
import { buildDelegationStep } from
|
|
19
|
-
import { eip7702AuthorizationStep } from
|
|
20
|
-
import { registerIntentsStep } from
|
|
13
|
+
import { BaseController } from "@metamask/base-controller";
|
|
14
|
+
import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
|
|
15
|
+
import { hexToNumber } from "@metamask/utils";
|
|
16
|
+
import { MoneyAccountUpgradeStepError } from "./errors.mjs";
|
|
17
|
+
import { associateAddressStep } from "./steps/associate-address.mjs";
|
|
18
|
+
import { buildDelegationStep } from "./steps/build-delegations.mjs";
|
|
19
|
+
import { eip7702AuthorizationStep } from "./steps/eip-7702-authorization.mjs";
|
|
20
|
+
import { registerIntentsStep } from "./steps/register-intents.mjs";
|
|
21
21
|
/**
|
|
22
22
|
* The Delegation Framework deployment version we resolve contract addresses
|
|
23
23
|
* against in `@metamask/delegation-deployments`.
|
|
@@ -189,4 +189,4 @@ function computeConfigFingerprint(config) {
|
|
|
189
189
|
.map((value) => value.toLowerCase())
|
|
190
190
|
.join('|');
|
|
191
191
|
}
|
|
192
|
-
//# sourceMappingURL=MoneyAccountUpgradeController.
|
|
192
|
+
//# sourceMappingURL=MoneyAccountUpgradeController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAW3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAUvE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,4BAA4B,EAAE,qBAAoB;AAE3D,OAAO,EAAE,oBAAoB,EAAE,sCAAqC;AACpE,OAAO,EAAE,mBAAmB,EAAE,sCAAqC;AACnE,OAAO,EAAE,wBAAwB,EAAE,2CAA0C;AAC7E,OAAO,EAAE,mBAAmB,EAAE,qCAAoC;AAIlE;;;GAGG;AACH,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAyB9D,MAAM,qCAAqC,GAAG;IAC5C,gBAAgB,EAAE;QAChB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;KAChB;CAC0D,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,UAAU,4CAA4C;IAC1D,OA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AS,EAAE,IAAI,CAAC,SAAS;oBACzB,OAAO;oBACP,GAAG,MAAM;iBACV,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;QAED,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG;gBACnC,iBAAiB;gBACjB,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;aACxB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;;AAED;;;;;;;GAOG;AACH,SAAS,wBAAwB,CAC/B,MAAwC;IAExC,OAAO;QACL,4BAA4B;QAC5B,MAAM,CAAC,OAAO;QACd,MAAM,CAAC,eAAe;QACtB,MAAM,CAAC,gBAAgB;QACvB,MAAM,CAAC,kBAAkB;QACzB,MAAM,CAAC,uBAAuB;QAC9B,MAAM,CAAC,oBAAoB;QAC3B,MAAM,CAAC,2BAA2B;QAClC,MAAM,CAAC,gBAAgB;QACvB,MAAM,CAAC,gBAAgB;KACxB;SACE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACnC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","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 ChompApiServiceGetAssociatedAddressesAction,\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.js';\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types.js';\nimport { associateAddressStep } from './steps/associate-address.js';\nimport { buildDelegationStep } from './steps/build-delegations.js';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization.js';\nimport { registerIntentsStep } from './steps/register-intents.js';\nimport type { Step } from './steps/step.js';\nimport type { UpgradeConfig } from './types.js';\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\n/**\n * Record of a Money Account upgrade sequence that ran to completion.\n */\nexport type MoneyAccountUpgradeStatus = {\n /**\n * Fingerprint of the upgrade config the sequence completed under. The\n * record is only trusted while the active config produces the same\n * fingerprint — if the chain, CHOMP contracts, or Delegation Framework\n * version change, the sequence re-runs.\n */\n configFingerprint: string;\n /** Unix timestamp (in milliseconds) when the sequence completed. */\n completedAt: number;\n};\n\nexport type MoneyAccountUpgradeControllerState = {\n /**\n * Accounts whose upgrade sequence has fully completed, keyed by lowercased\n * account address.\n */\n upgradedAccounts: { [address: Hex]: MoneyAccountUpgradeStatus };\n};\n\nconst moneyAccountUpgradeControllerMetadata = {\n upgradedAccounts: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\n/**\n * Constructs the default {@link MoneyAccountUpgradeController} state. This\n * allows consumers to provide a partial state object when initializing the\n * controller and also helps in constructing complete state objects for this\n * controller in tests.\n *\n * @returns The default {@link MoneyAccountUpgradeController} state.\n */\nexport function getDefaultMoneyAccountUpgradeControllerState(): MoneyAccountUpgradeControllerState {\n return {\n upgradedAccounts: {},\n };\n}\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 | ChompApiServiceGetAssociatedAddressesAction\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 * @param options.state - The initial state, merged with the defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n state?: Partial<MoneyAccountUpgradeControllerState>;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultMoneyAccountUpgradeControllerState(),\n ...state,\n },\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 * A run that completes is recorded in state (keyed by lowercased address,\n * fingerprinted against the active config); subsequent calls for a\n * recorded account return immediately without running any steps. If the\n * active config no longer matches the recorded fingerprint, the sequence\n * re-runs.\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 const config = this.#config;\n\n const accountKey = address.toLowerCase() as Hex;\n const configFingerprint = computeConfigFingerprint(config);\n if (\n this.state.upgradedAccounts[accountKey]?.configFingerprint ===\n configFingerprint\n ) {\n return;\n }\n\n for (const step of this.#steps) {\n try {\n await step.run({\n messenger: this.messenger,\n address,\n ...config,\n });\n } catch (error) {\n throw new MoneyAccountUpgradeStepError(step.name, error);\n }\n }\n\n this.update((state) => {\n state.upgradedAccounts[accountKey] = {\n configFingerprint,\n completedAt: Date.now(),\n };\n });\n }\n}\n\n/**\n * Derives a stable fingerprint of the config fields that define what\n * \"upgraded\" means for an account. A recorded upgrade is only trusted while\n * the active config produces the same fingerprint.\n *\n * @param config - The active upgrade config.\n * @returns A canonical string over the config's identifying fields.\n */\nfunction computeConfigFingerprint(\n config: UpgradeConfig & { chainId: Hex },\n): string {\n return [\n DELEGATION_FRAMEWORK_VERSION,\n config.chainId,\n config.delegateAddress,\n config.musdTokenAddress,\n config.boringVaultAddress,\n config.vedaVaultAdapterAddress,\n config.delegatorImplAddress,\n config.erc20TransferAmountEnforcer,\n config.redeemerEnforcer,\n config.valueLteEnforcer,\n ]\n .map((value) => value.toLowerCase())\n .join('|');\n}\n"]}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTerminalMoneyAccountUpgradeError = exports.isMoneyAccountUpgradeStepError = exports.TerminalUpgradeError = 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
|
+
this.terminal =
|
|
21
|
+
cause instanceof Error &&
|
|
22
|
+
cause.terminal === true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.MoneyAccountUpgradeStepError = MoneyAccountUpgradeStepError;
|
|
26
|
+
/**
|
|
27
|
+
* Error a step throws to mark a failure as terminal: the condition will not
|
|
28
|
+
* resolve on its own, so retrying the upgrade sequence is pointless — e.g.
|
|
29
|
+
* the account is already delegated to a third-party implementation.
|
|
30
|
+
*
|
|
31
|
+
* Detected structurally via the `terminal` property (rather than
|
|
32
|
+
* `instanceof`) so the marking survives module-realm duplication.
|
|
33
|
+
*/
|
|
34
|
+
class TerminalUpgradeError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message);
|
|
37
|
+
/** Marks the failure as not retryable. */
|
|
38
|
+
this.terminal = true;
|
|
39
|
+
this.name = 'TerminalUpgradeError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TerminalUpgradeError = TerminalUpgradeError;
|
|
43
|
+
/**
|
|
44
|
+
* Type guard for {@link MoneyAccountUpgradeStepError}.
|
|
45
|
+
*
|
|
46
|
+
* Uses a structural check rather than `instanceof` so it holds across module
|
|
47
|
+
* realm boundaries — e.g. when the controller is consumed from a bundled host
|
|
48
|
+
* app where a duplicate copy of this class may exist.
|
|
49
|
+
*
|
|
50
|
+
* @param error - The value to test.
|
|
51
|
+
* @returns Whether `error` is a `MoneyAccountUpgradeStepError`.
|
|
52
|
+
*/
|
|
53
|
+
function isMoneyAccountUpgradeStepError(error) {
|
|
54
|
+
return (error instanceof Error &&
|
|
55
|
+
error.name === 'MoneyAccountUpgradeStepError' &&
|
|
56
|
+
typeof error.step === 'string');
|
|
57
|
+
}
|
|
58
|
+
exports.isMoneyAccountUpgradeStepError = isMoneyAccountUpgradeStepError;
|
|
59
|
+
/**
|
|
60
|
+
* Whether `error` is a {@link MoneyAccountUpgradeStepError} marked as
|
|
61
|
+
* terminal — a failure that will not resolve on its own, so retrying the
|
|
62
|
+
* upgrade sequence cannot succeed.
|
|
63
|
+
*
|
|
64
|
+
* Uses the same structural checks as {@link isMoneyAccountUpgradeStepError}
|
|
65
|
+
* so it holds across module realm boundaries.
|
|
66
|
+
*
|
|
67
|
+
* @param error - The value to test.
|
|
68
|
+
* @returns Whether `error` is a terminal `MoneyAccountUpgradeStepError`.
|
|
69
|
+
*/
|
|
70
|
+
function isTerminalMoneyAccountUpgradeError(error) {
|
|
71
|
+
return (isMoneyAccountUpgradeStepError(error) &&
|
|
72
|
+
error.terminal === true);
|
|
73
|
+
}
|
|
74
|
+
exports.isTerminalMoneyAccountUpgradeError = isTerminalMoneyAccountUpgradeError;
|
|
75
|
+
//# 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;IAcrD,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;QACnB,IAAI,CAAC,QAAQ;YACX,KAAK,YAAY,KAAK;gBACrB,KAAgC,CAAC,QAAQ,KAAK,IAAI,CAAC;IACxD,CAAC;CACF;AAzBD,oEAyBC;AAED;;;;;;;GAOG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAI7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,0CAA0C;QACjC,aAAQ,GAAG,IAAI,CAAC;QAIvB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AARD,oDAQC;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;AAED;;;;;;;;;;GAUG;AACH,SAAgB,kCAAkC,CAChD,KAAc;IAEd,OAAO,CACL,8BAA8B,CAAC,KAAK,CAAC;QACpC,KAAgC,CAAC,QAAQ,KAAK,IAAI,CACpD,CAAC;AACJ,CAAC;AAPD,gFAOC","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 /**\n * Whether the failure is terminal — the condition will not resolve on its\n * own, so retrying the upgrade sequence cannot succeed. Derived from the\n * cause (see {@link TerminalUpgradeError}).\n */\n readonly terminal: boolean;\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 this.terminal =\n cause instanceof Error &&\n (cause as { terminal?: unknown }).terminal === true;\n }\n}\n\n/**\n * Error a step throws to mark a failure as terminal: the condition will not\n * resolve on its own, so retrying the upgrade sequence is pointless — e.g.\n * the account is already delegated to a third-party implementation.\n *\n * Detected structurally via the `terminal` property (rather than\n * `instanceof`) so the marking survives module-realm duplication.\n */\nexport class TerminalUpgradeError extends Error {\n /** Marks the failure as not retryable. */\n readonly terminal = true;\n\n constructor(message: string) {\n super(message);\n this.name = 'TerminalUpgradeError';\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\n/**\n * Whether `error` is a {@link MoneyAccountUpgradeStepError} marked as\n * terminal — a failure that will not resolve on its own, so retrying the\n * upgrade sequence cannot succeed.\n *\n * Uses the same structural checks as {@link isMoneyAccountUpgradeStepError}\n * so it holds across module realm boundaries.\n *\n * @param error - The value to test.\n * @returns Whether `error` is a terminal `MoneyAccountUpgradeStepError`.\n */\nexport function isTerminalMoneyAccountUpgradeError(\n error: unknown,\n): error is MoneyAccountUpgradeStepError {\n return (\n isMoneyAccountUpgradeStepError(error) &&\n (error as { terminal?: unknown }).terminal === true\n );\n}\n"]}
|