Skip to content

Commit 2c55b98

Browse files
authored
feat: add token approval revocation functionality (#328)
* feat: implement token approval revocation functionality - Add tests for token approval revocation context, content, and validation. - Create a new TokenApprovalRevocationForm component to handle user input for revocation methods. - Update the RedemptionForm to support various token approval revocation methods. - Refactor existing ERC20TokenRevocationForm references to the new TokenApprovalRevocationForm. - Modify the RPC handler and supported rule types to accommodate the new token approval revocation type. - Remove deprecated ERC20TokenRevocationForm component. * feat: update token approval revocation mechanisms and labels * feat: update approval revocation enforcer address in chain metadata * feat: update dependencies for delegation-core and permission-types * feat: rename permit2ApproveZero to permit2Approve and update related references * feat: update token approval revocation terminology and logic * refactor: remove unnecessary newline in caveats test * feat: update package dependencies and remove deprecated smart-accounts-kit reference * feat: update token approval revocation test to reflect terminology change * feat: refactor token approval revocation types and constants for clarity
1 parent d540f25 commit 2c55b98

39 files changed

Lines changed: 1216 additions & 607 deletions

packages/gator-permissions-snap/locales/en.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
"message": "Unknown chain $1"
213213
},
214214
"permissionRequestSubtitleRevocation": {
215-
"message": "This site wants permissions to revoke your ERC-20 token approvals."
215+
"message": "This site wants permissions to revoke your token approvals."
216216
},
217217
"introAdvancedPermissionsTitle": {
218218
"message": "Advanced permissions keep you in control"
@@ -251,7 +251,7 @@
251251
"message": "Token revocation request"
252252
},
253253
"introManageTokenApprovalsDescription": {
254-
"message": "Token revocation allows sites to revoke token approvals on your behalf."
254+
"message": "Token revocation allows sites to revoke ERC-20, NFT, and Permit2 approvals on your behalf."
255255
},
256256
"introAllowanceTitle": {
257257
"message": "Token allowance request"
@@ -318,6 +318,30 @@
318318
},
319319
"revokeTokenApprovalsLabel": {
320320
"message": "Revoke token approvals"
321+
},
322+
"approvalRevocationPrimitivesLabel": {
323+
"message": "Revocation primitives"
324+
},
325+
"allApprovalRevocationPrimitivesLabel": {
326+
"message": "All primitives"
327+
},
328+
"erc20ApproveRevocationLabel": {
329+
"message": "ERC-20 approve(spender, 0)"
330+
},
331+
"erc721ApproveRevocationLabel": {
332+
"message": "ERC-721 approve(address(0), tokenId)"
333+
},
334+
"erc721SetApprovalForAllRevocationLabel": {
335+
"message": "ERC-721/ERC-1155 setApprovalForAll(false)"
336+
},
337+
"permit2ApproveRevocationLabel": {
338+
"message": "Permit2 approve(token, spender, 0, 0)"
339+
},
340+
"permit2LockdownRevocationLabel": {
341+
"message": "Permit2 lockdown"
342+
},
343+
"permit2InvalidateNoncesRevocationLabel": {
344+
"message": "Permit2 invalidate nonces"
321345
}
322346
}
323347
}

packages/gator-permissions-snap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@metamask/abi-utils": "3.0.0",
51-
"@metamask/delegation-core": "^2.0.0",
51+
"@metamask/delegation-core": "^2.2.1",
5252
"@metamask/profile-sync-controller": "28.1.0",
5353
"@metamask/snaps-sdk": "11.1.0",
5454
"@metamask/utils": "11.11.0",

packages/gator-permissions-snap/snap.manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const manifest: SnapManifest = {
3636
snap_dialog: {},
3737
snap_getPreferences: {},
3838
},
39-
platformVersion: '10.2.0',
39+
platformVersion: '11.1.0',
4040
manifestVersion: '0.1',
4141
};
4242

packages/gator-permissions-snap/src/core/chainMetadata.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type DelegationContracts = {
2020
allowedCalldataEnforcer: Hex;
2121
redeemerEnforcer: Hex;
2222
allowedTargetsEnforcer: Hex;
23+
approvalRevocationEnforcer: Hex;
2324
};
2425

2526
const contracts: DelegationContracts = {
@@ -38,6 +39,7 @@ const contracts: DelegationContracts = {
3839
allowedCalldataEnforcer: '0xc2b0d624c1c4319760C96503BA27C347F3260f55',
3940
redeemerEnforcer: '0xE144b0b2618071B4E56f746313528a669c7E65c5',
4041
allowedTargetsEnforcer: '0x7F20f61b1f09b08D970938F6fa563634d65c4EeB',
42+
approvalRevocationEnforcer: '0xe264F1f09A19505a1ca1a86D5b01E8bFdb64324A',
4143
};
4244

4345
// derived from https://chainid.network/chains.json

packages/gator-permissions-snap/src/core/existingpermissions/permissionFormatter.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { hexToNumber } from '@metamask/utils';
77
import type { Hex } from '@metamask/utils';
88

99
import { DEFAULT_MAX_AMOUNT } from '../../permissions/erc20TokenStream/context';
10+
import { TOKEN_APPROVAL_REVOCATION_PRIMITIVES } from '../../permissions/tokenApprovalRevocation/types';
1011
import type { TokenMetadataService } from '../../services/tokenMetadataService';
1112
import { t } from '../../utils/i18n';
1213
import { getClosestTimePeriod } from '../../utils/time';
@@ -88,13 +89,22 @@ function extractPermissionDetails(
8889
}
8990

9091
// For revocation-type permissions
91-
if (permissionType === 'erc20-token-revocation') {
92+
if (permissionType === 'token-approval-revocation') {
9293
const revokeLabel = t('revokeTokenApprovalsLabel');
93-
const revokeValue = t('allTokens');
94-
details.tokenApprovals = {
95-
label: revokeLabel,
96-
value: revokeValue,
97-
};
94+
const revocationPrimitives = TOKEN_APPROVAL_REVOCATION_PRIMITIVES.filter(
95+
({ key }) => permissionData[key] === true,
96+
).map(({ labelKey }) => t(labelKey));
97+
if (revocationPrimitives.length > 0) {
98+
const revokeValue =
99+
revocationPrimitives.length ===
100+
TOKEN_APPROVAL_REVOCATION_PRIMITIVES.length
101+
? t('allApprovalRevocationPrimitivesLabel')
102+
: revocationPrimitives.join(', ');
103+
details.tokenApprovals = {
104+
label: revokeLabel,
105+
value: revokeValue,
106+
};
107+
}
98108
}
99109
// For periodic-type permissions
100110
else if (

packages/gator-permissions-snap/src/core/permissionHandlerFactory.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import { extractDescriptorName } from '@metamask/7715-permissions-shared/utils';
33
import { InvalidInputError } from '@metamask/snaps-sdk';
44

55
import type { AccountController } from './accountController';
6+
import { PermissionHandler } from './permissionHandler';
7+
import type { PermissionRequestLifecycleOrchestrator } from './permissionRequestLifecycleOrchestrator';
8+
import type {
9+
BaseContext,
10+
DeepRequired,
11+
PermissionDefinition,
12+
PermissionHandlerType,
13+
} from './types';
614
import { erc20TokenAllowancePermissionDefinition } from '../permissions/erc20TokenAllowance';
715
import { erc20TokenPeriodicPermissionDefinition } from '../permissions/erc20TokenPeriodic';
8-
import { erc20TokenRevocationPermissionDefinition } from '../permissions/erc20TokenRevocation';
916
import { erc20TokenStreamPermissionDefinition } from '../permissions/erc20TokenStream';
1017
import { nativeTokenAllowancePermissionDefinition } from '../permissions/nativeTokenAllowance';
1118
import { nativeTokenPeriodicPermissionDefinition } from '../permissions/nativeTokenPeriodic';
1219
import { nativeTokenStreamPermissionDefinition } from '../permissions/nativeTokenStream';
20+
import { tokenApprovalRevocationPermissionDefinition } from '../permissions/tokenApprovalRevocation';
1321
import type { TokenMetadataService } from '../services/tokenMetadataService';
1422
import type { TokenPricesService } from '../services/tokenPricesService';
1523
import type { UserEventDispatcher } from '../userEventDispatcher';
16-
import { PermissionHandler } from './permissionHandler';
17-
import type { PermissionRequestLifecycleOrchestrator } from './permissionRequestLifecycleOrchestrator';
18-
import type {
19-
BaseContext,
20-
DeepRequired,
21-
PermissionDefinition,
22-
PermissionHandlerType,
23-
} from './types';
2424

2525
/**
2626
* Factory for creating permission-specific orchestrators.
@@ -121,9 +121,9 @@ export class PermissionHandlerFactory {
121121
erc20TokenAllowancePermissionDefinition,
122122
);
123123
break;
124-
case 'erc20-token-revocation':
124+
case 'token-approval-revocation':
125125
handler = createPermissionHandler(
126-
erc20TokenRevocationPermissionDefinition,
126+
tokenApprovalRevocationPermissionDefinition,
127127
);
128128
break;
129129
case 'erc20-token-stream':

packages/gator-permissions-snap/src/core/permissionIntroduction/permissionIntroductionContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const permissionIntroductionConfigs: Record<
120120
page1: allowancePage1Content,
121121
page2: fixedPage2Content,
122122
},
123-
'erc20-token-revocation': {
123+
'token-approval-revocation': {
124124
page1: revocationPage1Content,
125125
page2: fixedPage2Content,
126126
},

packages/gator-permissions-snap/src/permissions/erc20TokenRevocation/caveats.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

packages/gator-permissions-snap/src/permissions/erc20TokenRevocation/content.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/gator-permissions-snap/src/permissions/erc20TokenRevocation/types.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)