Skip to content

Commit 3ee884d

Browse files
authored
feat: add approvalRevocationEnforcer and update delegation-deployments dependency (#335)
1 parent b30063b commit 3ee884d

3 files changed

Lines changed: 119 additions & 18 deletions

File tree

packages/gator-permissions-snap/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"dependencies": {
5050
"@metamask/abi-utils": "3.0.0",
5151
"@metamask/delegation-core": "^2.2.1",
52+
"@metamask/delegation-deployments": "^1.4.0",
5253
"@metamask/profile-sync-controller": "28.1.0",
5354
"@metamask/snaps-sdk": "11.1.0",
5455
"@metamask/utils": "11.11.0",

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

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import type { Hex } from '@metamask/delegation-core';
2+
import {
3+
CHAIN_ID,
4+
DELEGATOR_CONTRACTS,
5+
} from '@metamask/delegation-deployments';
26
import { numberToHex } from '@metamask/utils';
37

48
import { t } from '../utils/i18n';
@@ -23,23 +27,111 @@ export type DelegationContracts = {
2327
approvalRevocationEnforcer: Hex;
2428
};
2529

26-
const contracts: DelegationContracts = {
27-
delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3',
28-
eip7702StatelessDeleGatorImpl: '0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B',
29-
limitedCallsEnforcer: '0x04658B29F6b82ed55274221a06Fc97D318E25416',
30-
erc20StreamingEnforcer: '0x56c97aE02f233B29fa03502Ecc0457266d9be00e',
31-
erc20PeriodTransferEnforcer: '0x474e3Ae7E169e940607cC624Da8A15Eb120139aB',
32-
nativeTokenStreamingEnforcer: '0xD10b97905a320b13a0608f7E9cC506b56747df19',
33-
nativeTokenPeriodTransferEnforcer:
34-
'0x9BC0FAf4Aca5AE429F4c06aEEaC517520CB16BD9',
35-
valueLteEnforcer: '0x92Bf12322527cAA612fd31a0e810472BBB106A8F',
36-
timestampEnforcer: '0x1046bb45C8d673d4ea75321280DB34899413c069',
37-
exactCalldataEnforcer: '0x99F2e9bF15ce5eC84685604836F71aB835DBBdED',
38-
nonceEnforcer: '0xDE4f2FAC4B3D87A1d9953Ca5FC09FCa7F366254f',
39-
allowedCalldataEnforcer: '0xc2b0d624c1c4319760C96503BA27C347F3260f55',
40-
redeemerEnforcer: '0xE144b0b2618071B4E56f746313528a669c7E65c5',
41-
allowedTargetsEnforcer: '0x7F20f61b1f09b08D970938F6fa563634d65c4EeB',
42-
approvalRevocationEnforcer: '0xe264F1f09A19505a1ca1a86D5b01E8bFdb64324A',
30+
const DELEGATOR_CONTRACT_VERSION = '1.3.0';
31+
32+
type DeployedContracts = (typeof DELEGATOR_CONTRACTS)[string][number];
33+
34+
const getDeployedContracts = (chainId: number): DeployedContracts => {
35+
const deployedContractsByChainId =
36+
DELEGATOR_CONTRACTS[DELEGATOR_CONTRACT_VERSION];
37+
38+
if (!deployedContractsByChainId) {
39+
throw new Error(
40+
`Delegator contract deployments are missing for version ${DELEGATOR_CONTRACT_VERSION}`,
41+
);
42+
}
43+
44+
const deployedContracts =
45+
deployedContractsByChainId[chainId] ??
46+
deployedContractsByChainId[CHAIN_ID.mainnet];
47+
48+
if (!deployedContracts) {
49+
throw new Error(
50+
`Delegator contract deployments are missing for chain ${chainId}`,
51+
);
52+
}
53+
54+
return deployedContracts;
55+
};
56+
57+
const getDeployedContractAddress = (
58+
deployedContracts: DeployedContracts,
59+
contractName: string,
60+
): Hex => {
61+
const address = deployedContracts[contractName];
62+
63+
if (!address) {
64+
throw new Error(`Delegator contract deployment is missing ${contractName}`);
65+
}
66+
67+
return address;
68+
};
69+
70+
const getContracts = (chainId: number): DelegationContracts => {
71+
const deployedContracts = getDeployedContracts(chainId);
72+
73+
return {
74+
delegationManager: getDeployedContractAddress(
75+
deployedContracts,
76+
'DelegationManager',
77+
),
78+
eip7702StatelessDeleGatorImpl: getDeployedContractAddress(
79+
deployedContracts,
80+
'EIP7702StatelessDeleGatorImpl',
81+
),
82+
limitedCallsEnforcer: getDeployedContractAddress(
83+
deployedContracts,
84+
'LimitedCallsEnforcer',
85+
),
86+
erc20StreamingEnforcer: getDeployedContractAddress(
87+
deployedContracts,
88+
'ERC20StreamingEnforcer',
89+
),
90+
erc20PeriodTransferEnforcer: getDeployedContractAddress(
91+
deployedContracts,
92+
'ERC20PeriodTransferEnforcer',
93+
),
94+
nativeTokenStreamingEnforcer: getDeployedContractAddress(
95+
deployedContracts,
96+
'NativeTokenStreamingEnforcer',
97+
),
98+
nativeTokenPeriodTransferEnforcer: getDeployedContractAddress(
99+
deployedContracts,
100+
'NativeTokenPeriodTransferEnforcer',
101+
),
102+
valueLteEnforcer: getDeployedContractAddress(
103+
deployedContracts,
104+
'ValueLteEnforcer',
105+
),
106+
timestampEnforcer: getDeployedContractAddress(
107+
deployedContracts,
108+
'TimestampEnforcer',
109+
),
110+
exactCalldataEnforcer: getDeployedContractAddress(
111+
deployedContracts,
112+
'ExactCalldataEnforcer',
113+
),
114+
nonceEnforcer: getDeployedContractAddress(
115+
deployedContracts,
116+
'NonceEnforcer',
117+
),
118+
allowedCalldataEnforcer: getDeployedContractAddress(
119+
deployedContracts,
120+
'AllowedCalldataEnforcer',
121+
),
122+
redeemerEnforcer: getDeployedContractAddress(
123+
deployedContracts,
124+
'RedeemerEnforcer',
125+
),
126+
allowedTargetsEnforcer: getDeployedContractAddress(
127+
deployedContracts,
128+
'AllowedTargetsEnforcer',
129+
),
130+
approvalRevocationEnforcer: getDeployedContractAddress(
131+
deployedContracts,
132+
'ApprovalRevocationEnforcer',
133+
),
134+
};
43135
};
44136

45137
// derived from https://chainid.network/chains.json
@@ -121,7 +213,7 @@ export const getChainMetadata = ({
121213
const { explorerUrl, name } = nameAndExplorerUrlByChainId[chainId] ?? {};
122214

123215
const metadata = {
124-
contracts,
216+
contracts: getContracts(chainId),
125217
name: name ?? t('unknownChain', [numberToHex(chainId)]),
126218
explorerUrl,
127219
};

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,13 @@ __metadata:
30933093
languageName: node
30943094
linkType: hard
30953095

3096+
"@metamask/delegation-deployments@npm:^1.4.0":
3097+
version: 1.4.0
3098+
resolution: "@metamask/delegation-deployments@npm:1.4.0"
3099+
checksum: 10/e5e7b83e27daec5b1b61482647d43d4b685954818ff02687e2dbe8169a4dfe199cc8d2ed444242b60425ac2e7d2cf2a5ca29f3e69936abe6a8391f578ec693bb
3100+
languageName: node
3101+
linkType: hard
3102+
30963103
"@metamask/eslint-config-jest@npm:15.0.0":
30973104
version: 15.0.0
30983105
resolution: "@metamask/eslint-config-jest@npm:15.0.0"
@@ -3236,6 +3243,7 @@ __metadata:
32363243
"@metamask/abi-utils": "npm:3.0.0"
32373244
"@metamask/auto-changelog": "npm:6.1.0"
32383245
"@metamask/delegation-core": "npm:^2.2.1"
3246+
"@metamask/delegation-deployments": "npm:^1.4.0"
32393247
"@metamask/eslint-config": "npm:15.0.0"
32403248
"@metamask/eslint-config-jest": "npm:15.0.0"
32413249
"@metamask/eslint-config-nodejs": "npm:15.0.0"

0 commit comments

Comments
 (0)