-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add token approval revocation functionality #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b12594e
b060ca3
b7b8c62
0b8a4e6
fdb4c5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not for this PR, but we should probably just import @metamask/delegation-deployments instead of copying the contract addresses 🤔 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { hexToNumber } from '@metamask/utils'; | |
| import type { Hex } from '@metamask/utils'; | ||
|
|
||
| import { DEFAULT_MAX_AMOUNT } from '../../permissions/erc20TokenStream/context'; | ||
| import { TOKEN_APPROVAL_REVOCATION_PRIMITIVES } from '../../permissions/tokenApprovalRevocation/types'; | ||
| import type { TokenMetadataService } from '../../services/tokenMetadataService'; | ||
| import { t } from '../../utils/i18n'; | ||
| import { getClosestTimePeriod } from '../../utils/time'; | ||
|
|
@@ -88,9 +89,15 @@ function extractPermissionDetails( | |
| } | ||
|
|
||
| // For revocation-type permissions | ||
| if (permissionType === 'erc20-token-revocation') { | ||
| if (permissionType === 'token-approval-revocation') { | ||
| const revokeLabel = t('revokeTokenApprovalsLabel'); | ||
| const revokeValue = t('allTokens'); | ||
| const revocationMechanisms = TOKEN_APPROVAL_REVOCATION_PRIMITIVES.filter( | ||
| ({ key }) => permissionData[key] === true, | ||
| ).map(({ labelKey }) => t(labelKey)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does |
||
| const revokeValue = | ||
| revocationMechanisms.length > 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we saying that if none of the booleans values in the I had considered this an invalid request. But maybe it would be a good idea, if all of the revocation primitives are true that we should say "All revocation primitives" or something instead of listing them all out. I suspect that would be the more common experience. |
||
| ? revocationMechanisms.join(', ') | ||
| : t('allTokens'); | ||
| details.tokenApprovals = { | ||
| label: revokeLabel, | ||
| value: revokeValue, | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { ZERO_ADDRESS } from '@metamask/7715-permissions-shared/types'; | ||
| import type { Caveat } from '@metamask/delegation-core'; | ||
| import { createApprovalRevocationTerms } from '@metamask/delegation-core'; | ||
| import { InvalidInputError } from '@metamask/snaps-sdk'; | ||
|
|
||
| import type { PopulatedTokenApprovalRevocationPermission } from './types'; | ||
| import type { DelegationContracts } from '../../core/chainMetadata'; | ||
|
|
||
| /** | ||
| * Appends permission-specific caveats for token approval revocation. | ||
| * @param args - The options object containing the permission and caveat builder. | ||
| * @param args.permission - The complete token approval revocation permission. | ||
| * @param args.contracts - The contracts to use for the caveats. | ||
| * @returns The permission caveats. | ||
| */ | ||
| export async function createPermissionCaveats({ | ||
| permission, | ||
| contracts, | ||
| }: { | ||
| permission: PopulatedTokenApprovalRevocationPermission; | ||
| contracts: DelegationContracts; | ||
| }): Promise<Caveat[]> { | ||
| if (contracts.approvalRevocationEnforcer === ZERO_ADDRESS) { | ||
| throw new InvalidInputError( | ||
| 'ApprovalRevocationEnforcer address is not configured.', | ||
| ); | ||
| } | ||
|
Comment on lines
+23
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a temporary check until we add the revocation enforcer? I don't think we have this check on the other enforcers. |
||
|
|
||
| const approvalRevocationCaveat: Caveat = { | ||
| enforcer: contracts.approvalRevocationEnforcer, | ||
| terms: createApprovalRevocationTerms(permission.data), | ||
| args: '0x', | ||
| }; | ||
|
|
||
| return [approvalRevocationCaveat]; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; we've used the term
Primitiveto refer to the different ways that a permit can be revoked - at least in code I think it's a good idea to standardise that.