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