Feat: subscription delegation - #10130
Conversation
…ial period handling
…etadata into SubscriptionDelegationService
|
|
||
| ### Changed | ||
|
|
||
| - Accept `'subscription-payment'` as a CHOMP intent / delegation metadata type alongside `'cash-deposit'` and `'cash-withdrawal'`. ([#10130](https://github.com/MetaMask/core/pull/10130)) |
There was a problem hiding this comment.
we should rename the intent and delegation type according to https://consensyssoftware.atlassian.net/jira/software/c/projects/CHOMP/boards/6409/backlog?issueParent=389761&selectedIssue=CHOMP-37
| const ChompIntentTypeStruct = enums([ | ||
| 'cash-deposit', | ||
| 'cash-withdrawal', | ||
| 'subscription-payment', |
| export type ChompIntentType = | ||
| | 'cash-deposit' | ||
| | 'cash-withdrawal' | ||
| | 'subscription-payment'; |
There was a problem hiding this comment.
same as above.
Note that when we support premium vault, we may need add more intent and delegations: cash-deposit-premium, cash-withdrawal-premium
| InvalidDecimals = 'Subscription delegation decimals must be a non-negative integer', | ||
| LossyAmountScale = 'Subscription delegation amount cannot be scaled to token decimals without remainder', | ||
| UnsupportedRecurringInterval = 'Unsupported subscription recurring interval', | ||
| UnsupportedProduct = 'Subscription delegation is only supported for Money Account Plus', |
There was a problem hiding this comment.
will we show this error message to end users? We may use MM Orange? Is it possible to have translations instead?
| /** | ||
| * Storage / CHOMP metadata type for subscription-payment delegations. | ||
| */ | ||
| export const SUBSCRIPTION_PAYMENT_DELEGATION_TYPE = 'subscription-payment'; |
There was a problem hiding this comment.
may need to rename to cash-subscription
| periodDuration, | ||
| startDate, | ||
| }), | ||
| args: '0x', |
There was a problem hiding this comment.
do we need redeemerCaveat just like the other delegations "cash-deposit", "cash-withdrawal"?
| tokenAddress: request.tokenAddress, | ||
| periodAmount, | ||
| periodDuration, | ||
| startDate, |
There was a problem hiding this comment.
we'll need to add the recipient address which is subscription payment address?
Explanation
Money Account Plus crypto subscribe needs a subscription-payment delegation (periodic ERC-20 transfer caveats + CHOMP intent), not the Shield-style ERC-20 approval path. That workflow was split across clients and backend services with no single Core orchestrator.
This PR adds a stateless
SubscriptionDelegationServicethat owns setup end-to-end and returns a verifieddelegationHashforSubscriptionController.startSubscriptionWithCrypto. The controller does not depend on this service; clients callSubscriptionDelegationService:prepareDelegationfirst, then start the subscription with the hash.prepareDelegationflowmoneyAccountVaultConfig(remote feature flags), the temporary delegate from CHOMPautoDepositDelegate, and Delegation Framework v1.3.0 enforcers from@metamask/delegation-deployments.unitAmount/unitDecimals/ token decimals.{ delegationHash, disposition: 'created' | 'reused' }.Only
MONEY_ACCOUNT_PLUSis supported; Shield continues to use ERC-20 approval.Package split
@metamask/subscription-controllerSubscriptionDelegationService, helpers (amount,caveats,fingerprint), messenger actionSubscriptionDelegationService:prepareDelegation.@metamask/chomp-api-service'subscription-payment'as an intent / metadata type (with exportedChompIntentType).@metamask/walletDelegationController:signDelegation, andRemoteFeatureFlagController:getState.Hosts must register
AuthenticatedUserStorageService,ChompApiService, andDelegationControlleron the root messenger before callingprepareDelegation.RemoteFeatureFlagControlleris already initialized by the default wallet factory.References
Checklist