@metamask/money-account-upgrade-controller 1.3.2 → 2.0.1
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 +28 -1
- package/dist/MoneyAccountUpgradeController.cjs +36 -6
- package/dist/MoneyAccountUpgradeController.cjs.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.cts +16 -7
- package/dist/MoneyAccountUpgradeController.d.cts.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.mts +16 -7
- package/dist/MoneyAccountUpgradeController.d.mts.map +1 -1
- package/dist/MoneyAccountUpgradeController.mjs +36 -6
- package/dist/MoneyAccountUpgradeController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- 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.mjs +127 -0
- 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.cts +16 -0
- 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.mjs +21 -0
- package/dist/steps/delegation-matchers.mjs.map +1 -0
- package/dist/steps/eip-7702-authorization.cjs +29 -9
- package/dist/steps/eip-7702-authorization.cjs.map +1 -1
- package/dist/steps/eip-7702-authorization.d.cts.map +1 -1
- package/dist/steps/eip-7702-authorization.d.mts.map +1 -1
- package/dist/steps/eip-7702-authorization.mjs +29 -9
- package/dist/steps/eip-7702-authorization.mjs.map +1 -1
- package/dist/steps/register-intents.cjs +69 -0
- package/dist/steps/register-intents.cjs.map +1 -0
- package/dist/steps/register-intents.d.cts +18 -0
- 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.mjs +66 -0
- package/dist/steps/register-intents.mjs.map +1 -0
- package/dist/steps/step.cjs.map +1 -1
- package/dist/steps/step.d.cts +7 -0
- package/dist/steps/step.d.cts.map +1 -1
- package/dist/steps/step.d.mts +7 -0
- package/dist/steps/step.d.mts.map +1 -1
- package/dist/steps/step.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +12 -10
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +12 -10
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.0.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/network-controller` from `^31.1.0` to `^32.0.0` ([#8774](https://github.com/MetaMask/core/pull/8774))
|
|
15
|
+
|
|
16
|
+
## [2.0.0]
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Add remaining steps in money account upgrade process ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **BREAKING:** The controller messenger now requires access to six additional allowed actions: `AuthenticatedUserStorageService:listDelegations`, `AuthenticatedUserStorageService:createDelegation`, `ChompApiService:verifyDelegation`, `ChompApiService:getIntentsByAddress`, `ChompApiService:createIntents`, and `DelegationController:signDelegation`. Delegation signing is now delegated to `@metamask/delegation-controller` rather than calling `KeyringController:signTypedMessage` directly; consumers must instantiate `DelegationController` and update their messenger configuration accordingly. ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
25
|
+
- **BREAKING:** `init()` now takes a `{ chainId, boringVaultAddress }` object instead of an `InitConfig`. The EIP-7702 delegator implementation and caveat enforcer addresses are resolved from `@metamask/delegation-deployments` for the target chain; `init()` throws if the chain is not supported by Delegation Framework 1.3.0. The `InitConfig` type is no longer exported. ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
26
|
+
- Add `@metamask/authenticated-user-storage`, `@metamask/delegation-controller`, `@metamask/delegation-core`, and `@metamask/delegation-deployments` as dependencies. ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
27
|
+
- Bump `@metamask/network-controller` from `^31.0.0` to `^31.1.0` ([#8765](https://github.com/MetaMask/core/pull/8765))
|
|
28
|
+
- Bump `@metamask/chomp-api-service` from `^3.0.1` to `^3.1.0` ([#8769](https://github.com/MetaMask/core/pull/8769))
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Build-delegation step no longer emits a redundant duplicate `ValueLteEnforcer` caveat; the Delegation Framework treats both as equivalent, but the duplicate was inadvertently inherited from `@metamask/smart-accounts-kit`'s `erc20TransferAmount` scope helper. ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
33
|
+
- EIP-7702 authorization step now treats a 409 response from `POST /v1/account-upgrade` as `already-done` instead of a fatal error, making the step retry-safe when a prior submission was accepted by CHOMP but has not yet been observed on-chain. ([#8621](https://github.com/MetaMask/core/pull/8621))
|
|
34
|
+
|
|
10
35
|
## [1.3.2]
|
|
11
36
|
|
|
12
37
|
### Changed
|
|
@@ -60,7 +85,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
60
85
|
|
|
61
86
|
- Add `MoneyAccountUpgradeController` with `upgradeAccount` method ([#8426](https://github.com/MetaMask/core/pull/8426))
|
|
62
87
|
|
|
63
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@
|
|
88
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.1...HEAD
|
|
89
|
+
[2.0.1]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@2.0.0...@metamask/money-account-upgrade-controller@2.0.1
|
|
90
|
+
[2.0.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.3.2...@metamask/money-account-upgrade-controller@2.0.0
|
|
64
91
|
[1.3.2]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.3.1...@metamask/money-account-upgrade-controller@1.3.2
|
|
65
92
|
[1.3.1]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.3.0...@metamask/money-account-upgrade-controller@1.3.1
|
|
66
93
|
[1.3.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.2.0...@metamask/money-account-upgrade-controller@1.3.0
|
|
@@ -14,8 +14,17 @@ var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MoneyAccountUpgradeController = exports.controllerName = void 0;
|
|
16
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");
|
|
17
19
|
const associate_address_1 = require("./steps/associate-address.cjs");
|
|
20
|
+
const build_delegations_1 = require("./steps/build-delegations.cjs");
|
|
18
21
|
const eip_7702_authorization_1 = require("./steps/eip-7702-authorization.cjs");
|
|
22
|
+
const register_intents_1 = require("./steps/register-intents.cjs");
|
|
23
|
+
/**
|
|
24
|
+
* The Delegation Framework deployment version we resolve contract addresses
|
|
25
|
+
* against in `@metamask/delegation-deployments`.
|
|
26
|
+
*/
|
|
27
|
+
const DELEGATION_FRAMEWORK_VERSION = '1.3.0';
|
|
19
28
|
exports.controllerName = 'MoneyAccountUpgradeController';
|
|
20
29
|
const moneyAccountUpgradeControllerMetadata = {};
|
|
21
30
|
const MESSENGER_EXPOSED_METHODS = ['upgradeAccount'];
|
|
@@ -37,17 +46,31 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
37
46
|
state: {},
|
|
38
47
|
});
|
|
39
48
|
_MoneyAccountUpgradeController_config.set(this, void 0);
|
|
40
|
-
_MoneyAccountUpgradeController_steps.set(this, [
|
|
49
|
+
_MoneyAccountUpgradeController_steps.set(this, [
|
|
50
|
+
associate_address_1.associateAddressStep,
|
|
51
|
+
eip_7702_authorization_1.eip7702AuthorizationStep,
|
|
52
|
+
build_delegations_1.buildDelegationStep,
|
|
53
|
+
register_intents_1.registerIntentsStep,
|
|
54
|
+
]);
|
|
41
55
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
42
56
|
}
|
|
43
57
|
/**
|
|
44
58
|
* Fetches service details and validates the controller can operate on the
|
|
45
|
-
* given chain.
|
|
59
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
60
|
+
* chain from `@metamask/delegation-deployments`.
|
|
46
61
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
62
|
+
* @param params - The parameters for initialization.
|
|
63
|
+
* @param params.chainId - The chain to initialize for.
|
|
64
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
65
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
66
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
67
|
+
* exposes it.
|
|
49
68
|
*/
|
|
50
|
-
async init(chainId,
|
|
69
|
+
async init({ chainId, boringVaultAddress, }) {
|
|
70
|
+
const contracts = delegation_deployments_1.DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][(0, utils_1.hexToNumber)(chainId)];
|
|
71
|
+
if (!contracts) {
|
|
72
|
+
throw new Error(`Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`);
|
|
73
|
+
}
|
|
51
74
|
const response = await this.messenger.call('ChompApiService:getServiceDetails', [chainId]);
|
|
52
75
|
const chain = response.chains[chainId];
|
|
53
76
|
if (!chain) {
|
|
@@ -62,7 +85,14 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
62
85
|
}
|
|
63
86
|
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_config, {
|
|
64
87
|
chainId,
|
|
65
|
-
|
|
88
|
+
delegateAddress: chain.autoDepositDelegate,
|
|
89
|
+
musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,
|
|
90
|
+
boringVaultAddress,
|
|
91
|
+
vedaVaultAdapterAddress: vedaProtocol.adapterAddress,
|
|
92
|
+
delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,
|
|
93
|
+
erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,
|
|
94
|
+
redeemerEnforcer: contracts.RedeemerEnforcer,
|
|
95
|
+
valueLteEnforcer: contracts.ValueLteEnforcer,
|
|
66
96
|
}, "f");
|
|
67
97
|
}
|
|
68
98
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
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,G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,CAAC;QACJ,CAAC;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,17 +1,18 @@
|
|
|
1
|
+
import type { AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceListDelegationsAction } from "@metamask/authenticated-user-storage";
|
|
1
2
|
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
2
3
|
import { BaseController } from "@metamask/base-controller";
|
|
3
|
-
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateIntentsAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceVerifyDelegationAction } from "@metamask/chomp-api-service";
|
|
5
|
+
import type { DelegationControllerSignDelegationAction } from "@metamask/delegation-controller";
|
|
4
6
|
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
5
7
|
import type { Messenger } from "@metamask/messenger";
|
|
6
8
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
7
9
|
import type { Hex } from "@metamask/utils";
|
|
8
10
|
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.cjs";
|
|
9
|
-
import type { InitConfig } from "./types.cjs";
|
|
10
11
|
export declare const controllerName = "MoneyAccountUpgradeController";
|
|
11
12
|
export type MoneyAccountUpgradeControllerState = Record<string, never>;
|
|
12
13
|
export type MoneyAccountUpgradeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
13
14
|
export type MoneyAccountUpgradeControllerActions = MoneyAccountUpgradeControllerGetStateAction | MoneyAccountUpgradeControllerMethodActions;
|
|
14
|
-
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
15
|
+
type AllowedActions = AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceListDelegationsAction | ChompApiServiceAssociateAddressAction | ChompApiServiceCreateIntentsAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetIntentsByAddressAction | ChompApiServiceGetServiceDetailsAction | ChompApiServiceVerifyDelegationAction | DelegationControllerSignDelegationAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
15
16
|
export type MoneyAccountUpgradeControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
16
17
|
export type MoneyAccountUpgradeControllerEvents = MoneyAccountUpgradeControllerStateChangedEvent;
|
|
17
18
|
type AllowedEvents = never;
|
|
@@ -32,12 +33,20 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
|
|
|
32
33
|
});
|
|
33
34
|
/**
|
|
34
35
|
* Fetches service details and validates the controller can operate on the
|
|
35
|
-
* given chain.
|
|
36
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
37
|
+
* chain from `@metamask/delegation-deployments`.
|
|
36
38
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
+
* @param params - The parameters for initialization.
|
|
40
|
+
* @param params.chainId - The chain to initialize for.
|
|
41
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
42
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
43
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
44
|
+
* exposes it.
|
|
39
45
|
*/
|
|
40
|
-
init(chainId
|
|
46
|
+
init({ chainId, boringVaultAddress, }: {
|
|
47
|
+
chainId: Hex;
|
|
48
|
+
boringVaultAddress: Hex;
|
|
49
|
+
}): Promise<void>;
|
|
41
50
|
/**
|
|
42
51
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
43
52
|
* `'already-done'` is skipped without performing any action; a step that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,sCAAsC,
|
|
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;AAE3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AActH,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,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thenticatedUserStorageServiceListDelegationsAction } from "@metamask/authenticated-user-storage";
|
|
1
2
|
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
2
3
|
import { BaseController } from "@metamask/base-controller";
|
|
3
|
-
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateIntentsAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetIntentsByAddressAction, ChompApiServiceGetServiceDetailsAction, ChompApiServiceVerifyDelegationAction } from "@metamask/chomp-api-service";
|
|
5
|
+
import type { DelegationControllerSignDelegationAction } from "@metamask/delegation-controller";
|
|
4
6
|
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
5
7
|
import type { Messenger } from "@metamask/messenger";
|
|
6
8
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
7
9
|
import type { Hex } from "@metamask/utils";
|
|
8
10
|
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.mjs";
|
|
9
|
-
import type { InitConfig } from "./types.mjs";
|
|
10
11
|
export declare const controllerName = "MoneyAccountUpgradeController";
|
|
11
12
|
export type MoneyAccountUpgradeControllerState = Record<string, never>;
|
|
12
13
|
export type MoneyAccountUpgradeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
13
14
|
export type MoneyAccountUpgradeControllerActions = MoneyAccountUpgradeControllerGetStateAction | MoneyAccountUpgradeControllerMethodActions;
|
|
14
|
-
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
15
|
+
type AllowedActions = AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceListDelegationsAction | ChompApiServiceAssociateAddressAction | ChompApiServiceCreateIntentsAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetIntentsByAddressAction | ChompApiServiceGetServiceDetailsAction | ChompApiServiceVerifyDelegationAction | DelegationControllerSignDelegationAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
15
16
|
export type MoneyAccountUpgradeControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
16
17
|
export type MoneyAccountUpgradeControllerEvents = MoneyAccountUpgradeControllerStateChangedEvent;
|
|
17
18
|
type AllowedEvents = never;
|
|
@@ -32,12 +33,20 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
|
|
|
32
33
|
});
|
|
33
34
|
/**
|
|
34
35
|
* Fetches service details and validates the controller can operate on the
|
|
35
|
-
* given chain.
|
|
36
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
37
|
+
* chain from `@metamask/delegation-deployments`.
|
|
36
38
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
+
* @param params - The parameters for initialization.
|
|
40
|
+
* @param params.chainId - The chain to initialize for.
|
|
41
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
42
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
43
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
44
|
+
* exposes it.
|
|
39
45
|
*/
|
|
40
|
-
init(chainId
|
|
46
|
+
init({ chainId, boringVaultAddress, }: {
|
|
47
|
+
chainId: Hex;
|
|
48
|
+
boringVaultAddress: Hex;
|
|
49
|
+
}): Promise<void>;
|
|
41
50
|
/**
|
|
42
51
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
43
52
|
* `'already-done'` is skipped without performing any action; a step that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,sCAAsC,
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qDAAqD,EACrD,oDAAoD,EACrD,6CAA6C;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,kCAAkC,EAClC,wCAAwC,EACxC,sCAAsC,EACtC,qCAAqC,EACtC,oCAAoC;AACrC,OAAO,KAAK,EAAE,wCAAwC,EAAE,wCAAwC;AAEhG,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC5C,qCAAqC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AActH,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAOvE,MAAM,MAAM,2CAA2C,GACrD,wBAAwB,CACtB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,oCAAoC,GAC5C,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C,KAAK,cAAc,GACf,qDAAqD,GACrD,oDAAoD,GACpD,qCAAqC,GACrC,kCAAkC,GAClC,kCAAkC,GAClC,wCAAwC,GACxC,sCAAsC,GACtC,qCAAqC,GACrC,wCAAwC,GACxC,+CAA+C,GAC/C,0CAA0C,GAC1C,mDAAmD,GACnD,2CAA2C,CAAC;AAEhD,MAAM,MAAM,8CAA8C,GACxD,2BAA2B,CACzB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,mCAAmC,GAC7C,8CAA8C,CAAC;AAEjD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,cAAc,EACrB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAUC;;;;;OAKG;gBACS,EACV,SAAS,GACV,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,EACT,OAAO,EACP,kBAAkB,GACnB,EAAE;QACD,OAAO,EAAE,GAAG,CAAC;QACb,kBAAkB,EAAE,GAAG,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CjB;;;;;;;OAOG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAelD"}
|
|
@@ -11,8 +11,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
|
+
import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
|
|
15
|
+
import { hexToNumber } from "@metamask/utils";
|
|
14
16
|
import { associateAddressStep } from "./steps/associate-address.mjs";
|
|
17
|
+
import { buildDelegationStep } from "./steps/build-delegations.mjs";
|
|
15
18
|
import { eip7702AuthorizationStep } from "./steps/eip-7702-authorization.mjs";
|
|
19
|
+
import { registerIntentsStep } from "./steps/register-intents.mjs";
|
|
20
|
+
/**
|
|
21
|
+
* The Delegation Framework deployment version we resolve contract addresses
|
|
22
|
+
* against in `@metamask/delegation-deployments`.
|
|
23
|
+
*/
|
|
24
|
+
const DELEGATION_FRAMEWORK_VERSION = '1.3.0';
|
|
16
25
|
export const controllerName = 'MoneyAccountUpgradeController';
|
|
17
26
|
const moneyAccountUpgradeControllerMetadata = {};
|
|
18
27
|
const MESSENGER_EXPOSED_METHODS = ['upgradeAccount'];
|
|
@@ -34,17 +43,31 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
34
43
|
state: {},
|
|
35
44
|
});
|
|
36
45
|
_MoneyAccountUpgradeController_config.set(this, void 0);
|
|
37
|
-
_MoneyAccountUpgradeController_steps.set(this, [
|
|
46
|
+
_MoneyAccountUpgradeController_steps.set(this, [
|
|
47
|
+
associateAddressStep,
|
|
48
|
+
eip7702AuthorizationStep,
|
|
49
|
+
buildDelegationStep,
|
|
50
|
+
registerIntentsStep,
|
|
51
|
+
]);
|
|
38
52
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
39
53
|
}
|
|
40
54
|
/**
|
|
41
55
|
* Fetches service details and validates the controller can operate on the
|
|
42
|
-
* given chain.
|
|
56
|
+
* given chain. Resolves the Delegation Framework contract addresses for the
|
|
57
|
+
* chain from `@metamask/delegation-deployments`.
|
|
43
58
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
59
|
+
* @param params - The parameters for initialization.
|
|
60
|
+
* @param params.chainId - The chain to initialize for.
|
|
61
|
+
* @param params.boringVaultAddress - The Veda boring vault contract
|
|
62
|
+
* (vmUSD) for the given chain. Used as the withdrawal-side delegation
|
|
63
|
+
* token. Supplied by the consumer until the CHOMP service-details API
|
|
64
|
+
* exposes it.
|
|
46
65
|
*/
|
|
47
|
-
async init(chainId,
|
|
66
|
+
async init({ chainId, boringVaultAddress, }) {
|
|
67
|
+
const contracts = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION][hexToNumber(chainId)];
|
|
68
|
+
if (!contracts) {
|
|
69
|
+
throw new Error(`Delegation Framework ${DELEGATION_FRAMEWORK_VERSION} is not deployed on chain ${chainId}`);
|
|
70
|
+
}
|
|
48
71
|
const response = await this.messenger.call('ChompApiService:getServiceDetails', [chainId]);
|
|
49
72
|
const chain = response.chains[chainId];
|
|
50
73
|
if (!chain) {
|
|
@@ -59,7 +82,14 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
59
82
|
}
|
|
60
83
|
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_config, {
|
|
61
84
|
chainId,
|
|
62
|
-
|
|
85
|
+
delegateAddress: chain.autoDepositDelegate,
|
|
86
|
+
musdTokenAddress: vedaProtocol.supportedTokens[0].tokenAddress,
|
|
87
|
+
boringVaultAddress,
|
|
88
|
+
vedaVaultAdapterAddress: vedaProtocol.adapterAddress,
|
|
89
|
+
delegatorImplAddress: contracts.EIP7702StatelessDeleGatorImpl,
|
|
90
|
+
erc20TransferAmountEnforcer: contracts.ERC20TransferAmountEnforcer,
|
|
91
|
+
redeemerEnforcer: contracts.RedeemerEnforcer,
|
|
92
|
+
valueLteEnforcer: contracts.ValueLteEnforcer,
|
|
63
93
|
}, "f");
|
|
64
94
|
}
|
|
65
95
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCA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,KAAK,CACb,uDAAuD,OAAO,EAAE,CACjE,CAAC;QACJ,CAAC;QAED,uBAAA,IAAI,yCAAW;YACb,OAAO;YACP,oBAAoB,EAAE,UAAU,CAAC,oBAAoB;SACtD,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 ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetServiceDetailsAction,\n} from '@metamask/chomp-api-service';\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 type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport type { Step } from './steps/step';\nimport type { InitConfig } from './types';\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 | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetServiceDetailsAction\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?: { chainId: Hex; delegatorImplAddress: Hex };\n\n readonly #steps: Step[] = [associateAddressStep, eip7702AuthorizationStep];\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.\n *\n * @param chainId - The chain to initialize for.\n * @param initConfig - Contract addresses not available from the service details API.\n */\n async init(chainId: Hex, initConfig: InitConfig): Promise<void> {\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 delegatorImplAddress: initConfig.delegatorImplAddress,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAUvE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAI9C,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,mBAAmB,EAAE,sCAAkC;AAChE,OAAO,EAAE,wBAAwB,EAAE,2CAAuC;AAC1E,OAAO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QAED,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;QACxC,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,oCAAoC,OAAO,8BAA8B,CAC1E,CAAC;QACJ,CAAC;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","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"]}
|
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 {
|
|
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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { UpgradeConfig } from "./types.cjs";
|
|
2
2
|
export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.cjs";
|
|
3
3
|
export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.cjs";
|
|
4
4
|
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,
|
|
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"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { UpgradeConfig } from "./types.mjs";
|
|
2
2
|
export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.mjs";
|
|
3
3
|
export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.mjs";
|
|
4
4
|
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,
|
|
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"}
|
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 {
|
|
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"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildDelegationStep = void 0;
|
|
4
|
+
const delegation_core_1 = require("@metamask/delegation-core");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
const delegation_matchers_1 = require("./delegation-matchers.cjs");
|
|
7
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
8
|
+
const MAX_UINT256_HEX = (0, utils_1.add0x)(MAX_UINT256.toString(16));
|
|
9
|
+
/**
|
|
10
|
+
* Builds, signs, verifies (with CHOMP), and persists a single auto-deposit
|
|
11
|
+
* delegation for the given token. Both the deposit (mUSD) and withdrawal
|
|
12
|
+
* (vmUSD / boring vault) delegations share this shape; only the token
|
|
13
|
+
* address, symbol, and metadata `type` differ.
|
|
14
|
+
*
|
|
15
|
+
* @param params - The parameters for building the delegation.
|
|
16
|
+
* @param params.messenger - The messenger to call signing/verifying actions on.
|
|
17
|
+
* @param params.address - The delegator (the Money Account being upgraded).
|
|
18
|
+
* @param params.chainId - The chain to scope the delegation to.
|
|
19
|
+
* @param params.delegateAddress - CHOMP's delegate.
|
|
20
|
+
* @param params.tokenAddress - The token the delegation authorises transfers of.
|
|
21
|
+
* @param params.tokenSymbol - Symbol stored in the delegation metadata (e.g. "mUSD").
|
|
22
|
+
* @param params.delegationType - Storage metadata `type` field; matches CHOMP's intent type.
|
|
23
|
+
* @param params.vedaVaultAdapterAddress - The redeemer (Veda vault adapter).
|
|
24
|
+
* @param params.erc20TransferAmountEnforcer - The ERC20TransferAmountEnforcer contract.
|
|
25
|
+
* @param params.redeemerEnforcer - The RedeemerEnforcer contract.
|
|
26
|
+
* @param params.valueLteEnforcer - The ValueLteEnforcer contract.
|
|
27
|
+
*/
|
|
28
|
+
async function signAndStoreDelegation(params) {
|
|
29
|
+
const { messenger, address, chainId, delegateAddress, tokenAddress, tokenSymbol, delegationType, vedaVaultAdapterAddress, erc20TransferAmountEnforcer, redeemerEnforcer, valueLteEnforcer, } = params;
|
|
30
|
+
const saltBytes = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
31
|
+
const salt = (0, utils_1.bytesToHex)(saltBytes);
|
|
32
|
+
const delegation = {
|
|
33
|
+
delegate: delegateAddress,
|
|
34
|
+
delegator: address,
|
|
35
|
+
authority: delegation_core_1.ROOT_AUTHORITY,
|
|
36
|
+
caveats: [
|
|
37
|
+
{
|
|
38
|
+
enforcer: valueLteEnforcer,
|
|
39
|
+
terms: (0, delegation_core_1.createValueLteTerms)({ maxValue: 0n }),
|
|
40
|
+
args: '0x',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
enforcer: erc20TransferAmountEnforcer,
|
|
44
|
+
terms: (0, delegation_core_1.createERC20TransferAmountTerms)({
|
|
45
|
+
tokenAddress,
|
|
46
|
+
maxAmount: MAX_UINT256,
|
|
47
|
+
}),
|
|
48
|
+
args: '0x',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
enforcer: redeemerEnforcer,
|
|
52
|
+
terms: (0, delegation_core_1.createRedeemerTerms)({ redeemers: [vedaVaultAdapterAddress] }),
|
|
53
|
+
args: '0x',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
salt,
|
|
57
|
+
};
|
|
58
|
+
const signature = (await messenger.call('DelegationController:signDelegation', { delegation, chainId }));
|
|
59
|
+
const signedDelegation = { ...delegation, signature };
|
|
60
|
+
const result = await messenger.call('ChompApiService:verifyDelegation', {
|
|
61
|
+
signedDelegation,
|
|
62
|
+
chainId,
|
|
63
|
+
});
|
|
64
|
+
if (!result.valid) {
|
|
65
|
+
throw new Error(`CHOMP rejected delegation: ${result.errors?.join(', ') ?? 'unknown error'}`);
|
|
66
|
+
}
|
|
67
|
+
const delegationHash = (0, delegation_core_1.hashDelegation)({
|
|
68
|
+
...delegation,
|
|
69
|
+
salt: BigInt(salt),
|
|
70
|
+
signature,
|
|
71
|
+
});
|
|
72
|
+
await messenger.call('AuthenticatedUserStorageService:createDelegation', {
|
|
73
|
+
signedDelegation,
|
|
74
|
+
metadata: {
|
|
75
|
+
delegationHash,
|
|
76
|
+
chainIdHex: chainId,
|
|
77
|
+
allowance: MAX_UINT256_HEX,
|
|
78
|
+
tokenSymbol,
|
|
79
|
+
tokenAddress,
|
|
80
|
+
type: delegationType,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.buildDelegationStep = {
|
|
85
|
+
name: 'build-delegation',
|
|
86
|
+
async run({ messenger, address, chainId, boringVaultAddress, delegateAddress, erc20TransferAmountEnforcer, musdTokenAddress, redeemerEnforcer, valueLteEnforcer, vedaVaultAdapterAddress, }) {
|
|
87
|
+
const existingDelegations = await messenger.call('AuthenticatedUserStorageService:listDelegations');
|
|
88
|
+
const hasVedaRedeemerCaveat = (0, delegation_matchers_1.makeHasVedaRedeemerCaveat)(redeemerEnforcer, vedaVaultAdapterAddress);
|
|
89
|
+
const matches = (tokenAddress) => (entry) => (0, delegation_matchers_1.equalsIgnoreCase)(entry.signedDelegation.delegator, address) &&
|
|
90
|
+
(0, delegation_matchers_1.equalsIgnoreCase)(entry.signedDelegation.delegate, delegateAddress) &&
|
|
91
|
+
(0, delegation_matchers_1.equalsIgnoreCase)(entry.metadata.chainIdHex, chainId) &&
|
|
92
|
+
(0, delegation_matchers_1.equalsIgnoreCase)(entry.metadata.tokenAddress, tokenAddress) &&
|
|
93
|
+
hasVedaRedeemerCaveat(entry);
|
|
94
|
+
// The deposit delegation authorises transfers of mUSD (delegator → vault);
|
|
95
|
+
// the withdrawal delegation authorises transfers of vmUSD (vault share
|
|
96
|
+
// token → adapter, which redeems back to mUSD).
|
|
97
|
+
const delegations = [
|
|
98
|
+
{
|
|
99
|
+
tokenAddress: musdTokenAddress,
|
|
100
|
+
tokenSymbol: 'mUSD',
|
|
101
|
+
delegationType: 'cash-deposit',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
tokenAddress: boringVaultAddress,
|
|
105
|
+
tokenSymbol: 'vmUSD',
|
|
106
|
+
delegationType: 'cash-withdrawal',
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
let didWork = false;
|
|
110
|
+
for (const config of delegations) {
|
|
111
|
+
if (existingDelegations.some(matches(config.tokenAddress))) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
await signAndStoreDelegation({
|
|
115
|
+
messenger,
|
|
116
|
+
address,
|
|
117
|
+
chainId,
|
|
118
|
+
delegateAddress,
|
|
119
|
+
...config,
|
|
120
|
+
vedaVaultAdapterAddress,
|
|
121
|
+
erc20TransferAmountEnforcer,
|
|
122
|
+
redeemerEnforcer,
|
|
123
|
+
valueLteEnforcer,
|
|
124
|
+
});
|
|
125
|
+
didWork = true;
|
|
126
|
+
}
|
|
127
|
+
return didWork ? 'completed' : 'already-done';
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=build-delegations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-delegations.cjs","sourceRoot":"","sources":["../../src/steps/build-delegations.ts"],"names":[],"mappings":";;;AACA,+DAMmC;AACnC,2CAAoD;AAIpD,mEAG+B;AAG/B,MAAM,WAAW,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;AACpC,MAAM,eAAe,GAAQ,IAAA,aAAK,EAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,sBAAsB,CAAC,MAYrC;IACC,MAAM,EACJ,SAAS,EACT,OAAO,EACP,OAAO,EACP,eAAe,EACf,YAAY,EACZ,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,2BAA2B,EAC3B,gBAAgB,EAChB,gBAAgB,GACjB,GAAG,MAAM,CAAC;IAEX,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,IAAA,kBAAU,EAAC,SAAS,CAAC,CAAC;IAEnC,MAAM,UAAU,GAAG;QACjB,QAAQ,EAAE,eAAe;QACzB,SAAS,EAAE,OAAO;QAClB,SAAS,EAAE,gCAAc;QACzB,OAAO,EAAE;YACP;gBACE,QAAQ,EAAE,gBAAgB;gBAC1B,KAAK,EAAE,IAAA,qCAAmB,EAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;gBAC5C,IAAI,EAAE,IAAW;aAClB;YACD;gBACE,QAAQ,EAAE,2BAA2B;gBACrC,KAAK,EAAE,IAAA,gDAA8B,EAAC;oBACpC,YAAY;oBACZ,SAAS,EAAE,WAAW;iBACvB,CAAC;gBACF,IAAI,EAAE,IAAW;aAClB;YACD;gBACE,QAAQ,EAA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CAAC;QACjB,CAAC;QAED,OAAO,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC;IAChD,CAAC;CACF,CAAC","sourcesContent":["import type { DelegationResponse } from '@metamask/authenticated-user-storage';\nimport {\n ROOT_AUTHORITY,\n createERC20TransferAmountTerms,\n createRedeemerTerms,\n createValueLteTerms,\n hashDelegation,\n} from '@metamask/delegation-core';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMessenger } from '../MoneyAccountUpgradeController';\nimport {\n equalsIgnoreCase,\n makeHasVedaRedeemerCaveat,\n} from './delegation-matchers';\nimport type { Step } from './step';\n\nconst MAX_UINT256 = 2n ** 256n - 1n;\nconst MAX_UINT256_HEX: Hex = add0x(MAX_UINT256.toString(16));\n\n/**\n * Builds, signs, verifies (with CHOMP), and persists a single auto-deposit\n * delegation for the given token. Both the deposit (mUSD) and withdrawal\n * (vmUSD / boring vault) delegations share this shape; only the token\n * address, symbol, and metadata `type` differ.\n *\n * @param params - The parameters for building the delegation.\n * @param params.messenger - The messenger to call signing/verifying actions on.\n * @param params.address - The delegator (the Money Account being upgraded).\n * @param params.chainId - The chain to scope the delegation to.\n * @param params.delegateAddress - CHOMP's delegate.\n * @param params.tokenAddress - The token the delegation authorises transfers of.\n * @param params.tokenSymbol - Symbol stored in the delegation metadata (e.g. \"mUSD\").\n * @param params.delegationType - Storage metadata `type` field; matches CHOMP's intent type.\n * @param params.vedaVaultAdapterAddress - The redeemer (Veda vault adapter).\n * @param params.erc20TransferAmountEnforcer - The ERC20TransferAmountEnforcer contract.\n * @param params.redeemerEnforcer - The RedeemerEnforcer contract.\n * @param params.valueLteEnforcer - The ValueLteEnforcer contract.\n */\nasync function signAndStoreDelegation(params: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n address: Hex;\n chainId: Hex;\n delegateAddress: Hex;\n tokenAddress: Hex;\n tokenSymbol: string;\n delegationType: 'cash-deposit' | 'cash-withdrawal';\n vedaVaultAdapterAddress: Hex;\n erc20TransferAmountEnforcer: Hex;\n redeemerEnforcer: Hex;\n valueLteEnforcer: Hex;\n}): Promise<void> {\n const {\n messenger,\n address,\n chainId,\n delegateAddress,\n tokenAddress,\n tokenSymbol,\n delegationType,\n vedaVaultAdapterAddress,\n erc20TransferAmountEnforcer,\n redeemerEnforcer,\n valueLteEnforcer,\n } = params;\n\n const saltBytes = globalThis.crypto.getRandomValues(new Uint8Array(32));\n const salt = bytesToHex(saltBytes);\n\n const delegation = {\n delegate: delegateAddress,\n delegator: address,\n authority: ROOT_AUTHORITY,\n caveats: [\n {\n enforcer: valueLteEnforcer,\n terms: createValueLteTerms({ maxValue: 0n }),\n args: '0x' as Hex,\n },\n {\n enforcer: erc20TransferAmountEnforcer,\n terms: createERC20TransferAmountTerms({\n tokenAddress,\n maxAmount: MAX_UINT256,\n }),\n args: '0x' as Hex,\n },\n {\n enforcer: redeemerEnforcer,\n terms: createRedeemerTerms({ redeemers: [vedaVaultAdapterAddress] }),\n args: '0x' as Hex,\n },\n ],\n salt,\n };\n\n const signature = (await messenger.call(\n 'DelegationController:signDelegation',\n { delegation, chainId },\n )) as Hex;\n\n const signedDelegation = { ...delegation, signature };\n\n const result = await messenger.call('ChompApiService:verifyDelegation', {\n signedDelegation,\n chainId,\n });\n\n if (!result.valid) {\n throw new Error(\n `CHOMP rejected delegation: ${result.errors?.join(', ') ?? 'unknown error'}`,\n );\n }\n\n const delegationHash = hashDelegation({\n ...delegation,\n salt: BigInt(salt),\n signature,\n });\n\n await messenger.call('AuthenticatedUserStorageService:createDelegation', {\n signedDelegation,\n metadata: {\n delegationHash,\n chainIdHex: chainId,\n allowance: MAX_UINT256_HEX,\n tokenSymbol,\n tokenAddress,\n type: delegationType,\n },\n });\n}\n\nexport const buildDelegationStep: Step = {\n name: 'build-delegation',\n async run({\n messenger,\n address,\n chainId,\n boringVaultAddress,\n delegateAddress,\n erc20TransferAmountEnforcer,\n musdTokenAddress,\n redeemerEnforcer,\n valueLteEnforcer,\n vedaVaultAdapterAddress,\n }) {\n const existingDelegations = await messenger.call(\n 'AuthenticatedUserStorageService:listDelegations',\n );\n\n const hasVedaRedeemerCaveat = makeHasVedaRedeemerCaveat(\n redeemerEnforcer,\n vedaVaultAdapterAddress,\n );\n\n const matches =\n (tokenAddress: Hex) =>\n (entry: DelegationResponse): boolean =>\n equalsIgnoreCase(entry.signedDelegation.delegator, address) &&\n equalsIgnoreCase(entry.signedDelegation.delegate, delegateAddress) &&\n equalsIgnoreCase(entry.metadata.chainIdHex, chainId) &&\n equalsIgnoreCase(entry.metadata.tokenAddress, tokenAddress) &&\n hasVedaRedeemerCaveat(entry);\n\n // The deposit delegation authorises transfers of mUSD (delegator → vault);\n // the withdrawal delegation authorises transfers of vmUSD (vault share\n // token → adapter, which redeems back to mUSD).\n const delegations = [\n {\n tokenAddress: musdTokenAddress,\n tokenSymbol: 'mUSD',\n delegationType: 'cash-deposit' as const,\n },\n {\n tokenAddress: boringVaultAddress,\n tokenSymbol: 'vmUSD',\n delegationType: 'cash-withdrawal' as const,\n },\n ];\n\n let didWork = false;\n for (const config of delegations) {\n if (existingDelegations.some(matches(config.tokenAddress))) {\n continue;\n }\n await signAndStoreDelegation({\n messenger,\n address,\n chainId,\n delegateAddress,\n ...config,\n vedaVaultAdapterAddress,\n erc20TransferAmountEnforcer,\n redeemerEnforcer,\n valueLteEnforcer,\n });\n didWork = true;\n }\n\n return didWork ? 'completed' : 'already-done';\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-delegations.d.cts","sourceRoot":"","sources":["../../src/steps/build-delegations.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAsHnC,eAAO,MAAM,mBAAmB,EAAE,IAqEjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-delegations.d.mts","sourceRoot":"","sources":["../../src/steps/build-delegations.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAsHnC,eAAO,MAAM,mBAAmB,EAAE,IAqEjC,CAAC"}
|