@ensuro/access-managed-proxy 0.1.0

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.
Files changed (55) hide show
  1. package/README.md +15 -0
  2. package/build/build-info.json +1 -0
  3. package/build/contracts/AccessManagedProxy.sol/AccessManagedProxy.json +105 -0
  4. package/build/contracts/amps/AccessManagedProxyS1.sol/AccessManagedProxyS1.json +123 -0
  5. package/build/contracts/amps/AccessManagedProxyS10.sol/AccessManagedProxyS10.json +123 -0
  6. package/build/contracts/amps/AccessManagedProxyS11.sol/AccessManagedProxyS11.json +123 -0
  7. package/build/contracts/amps/AccessManagedProxyS12.sol/AccessManagedProxyS12.json +123 -0
  8. package/build/contracts/amps/AccessManagedProxyS13.sol/AccessManagedProxyS13.json +123 -0
  9. package/build/contracts/amps/AccessManagedProxyS14.sol/AccessManagedProxyS14.json +123 -0
  10. package/build/contracts/amps/AccessManagedProxyS15.sol/AccessManagedProxyS15.json +123 -0
  11. package/build/contracts/amps/AccessManagedProxyS16.sol/AccessManagedProxyS16.json +123 -0
  12. package/build/contracts/amps/AccessManagedProxyS17.sol/AccessManagedProxyS17.json +123 -0
  13. package/build/contracts/amps/AccessManagedProxyS18.sol/AccessManagedProxyS18.json +123 -0
  14. package/build/contracts/amps/AccessManagedProxyS19.sol/AccessManagedProxyS19.json +123 -0
  15. package/build/contracts/amps/AccessManagedProxyS2.sol/AccessManagedProxyS2.json +123 -0
  16. package/build/contracts/amps/AccessManagedProxyS20.sol/AccessManagedProxyS20.json +123 -0
  17. package/build/contracts/amps/AccessManagedProxyS21.sol/AccessManagedProxyS21.json +123 -0
  18. package/build/contracts/amps/AccessManagedProxyS22.sol/AccessManagedProxyS22.json +123 -0
  19. package/build/contracts/amps/AccessManagedProxyS23.sol/AccessManagedProxyS23.json +123 -0
  20. package/build/contracts/amps/AccessManagedProxyS24.sol/AccessManagedProxyS24.json +123 -0
  21. package/build/contracts/amps/AccessManagedProxyS3.sol/AccessManagedProxyS3.json +123 -0
  22. package/build/contracts/amps/AccessManagedProxyS4.sol/AccessManagedProxyS4.json +123 -0
  23. package/build/contracts/amps/AccessManagedProxyS5.sol/AccessManagedProxyS5.json +123 -0
  24. package/build/contracts/amps/AccessManagedProxyS6.sol/AccessManagedProxyS6.json +123 -0
  25. package/build/contracts/amps/AccessManagedProxyS7.sol/AccessManagedProxyS7.json +123 -0
  26. package/build/contracts/amps/AccessManagedProxyS8.sol/AccessManagedProxyS8.json +123 -0
  27. package/build/contracts/amps/AccessManagedProxyS9.sol/AccessManagedProxyS9.json +123 -0
  28. package/build/contracts/mock/DummyImplementation.sol/DummyImplementation.json +225 -0
  29. package/contracts/AccessManagedProxy.sol +85 -0
  30. package/contracts/amps/AccessManagedProxyS1.sol +63 -0
  31. package/contracts/amps/AccessManagedProxyS10.sol +99 -0
  32. package/contracts/amps/AccessManagedProxyS11.sol +103 -0
  33. package/contracts/amps/AccessManagedProxyS12.sol +107 -0
  34. package/contracts/amps/AccessManagedProxyS13.sol +111 -0
  35. package/contracts/amps/AccessManagedProxyS14.sol +115 -0
  36. package/contracts/amps/AccessManagedProxyS15.sol +119 -0
  37. package/contracts/amps/AccessManagedProxyS16.sol +123 -0
  38. package/contracts/amps/AccessManagedProxyS17.sol +127 -0
  39. package/contracts/amps/AccessManagedProxyS18.sol +131 -0
  40. package/contracts/amps/AccessManagedProxyS19.sol +135 -0
  41. package/contracts/amps/AccessManagedProxyS2.sol +67 -0
  42. package/contracts/amps/AccessManagedProxyS20.sol +139 -0
  43. package/contracts/amps/AccessManagedProxyS21.sol +143 -0
  44. package/contracts/amps/AccessManagedProxyS22.sol +147 -0
  45. package/contracts/amps/AccessManagedProxyS23.sol +151 -0
  46. package/contracts/amps/AccessManagedProxyS24.sol +155 -0
  47. package/contracts/amps/AccessManagedProxyS3.sol +71 -0
  48. package/contracts/amps/AccessManagedProxyS4.sol +75 -0
  49. package/contracts/amps/AccessManagedProxyS5.sol +79 -0
  50. package/contracts/amps/AccessManagedProxyS6.sol +83 -0
  51. package/contracts/amps/AccessManagedProxyS7.sol +87 -0
  52. package/contracts/amps/AccessManagedProxyS8.sol +91 -0
  53. package/contracts/amps/AccessManagedProxyS9.sol +95 -0
  54. package/contracts/mock/DummyImplementation.sol +53 -0
  55. package/package.json +28 -0
@@ -0,0 +1,75 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS4
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS4 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+
20
+ /**
21
+ * @notice Constructor of the proxy, defining the implementation and the access manager
22
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
23
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
24
+ *
25
+ * @param implementation The initial implementation contract.
26
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
27
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
28
+ * @param manager The access manager that will handle access control
29
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
30
+ * views and other methods for gas optimization.
31
+ *
32
+ * Requirements:
33
+ *
34
+ * - If `data` is empty, `msg.value` must be zero.
35
+ */
36
+ constructor(
37
+ address implementation,
38
+ bytes memory _data,
39
+ IAccessManager manager,
40
+ bytes4[4] memory passThruMethods
41
+ ) payable AccessManagedProxy(implementation, _data, manager) {
42
+ PASS_THRU_METHODS_0 = passThruMethods[0];
43
+ PASS_THRU_METHODS_1 = passThruMethods[1];
44
+ PASS_THRU_METHODS_2 = passThruMethods[2];
45
+ PASS_THRU_METHODS_3 = passThruMethods[3];
46
+ }
47
+
48
+ /*
49
+ * @notice Skips the access control if the method called is one of the passThruMethods
50
+ * @dev See {PASS_THRU_METHODS()}
51
+ * @param selector The selector of the method called
52
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
53
+ */
54
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
55
+ return
56
+ selector == PASS_THRU_METHODS_0 ||
57
+ selector == PASS_THRU_METHODS_1 ||
58
+ selector == PASS_THRU_METHODS_2 ||
59
+ selector == PASS_THRU_METHODS_3;
60
+ }
61
+
62
+ /**
63
+ * @notice Gives observability to the methods that are skipped from access control
64
+ * @dev This list is fixed and defined on contract construction
65
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
66
+ */
67
+ // solhint-disable-next-line func-name-mixedcase
68
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
69
+ methods = new bytes4[](4);
70
+ methods[0] = PASS_THRU_METHODS_0;
71
+ methods[1] = PASS_THRU_METHODS_1;
72
+ methods[2] = PASS_THRU_METHODS_2;
73
+ methods[3] = PASS_THRU_METHODS_3;
74
+ }
75
+ }
@@ -0,0 +1,79 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS5
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS5 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+ bytes4 internal immutable PASS_THRU_METHODS_4;
20
+
21
+ /**
22
+ * @notice Constructor of the proxy, defining the implementation and the access manager
23
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
24
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
25
+ *
26
+ * @param implementation The initial implementation contract.
27
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
28
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
29
+ * @param manager The access manager that will handle access control
30
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
31
+ * views and other methods for gas optimization.
32
+ *
33
+ * Requirements:
34
+ *
35
+ * - If `data` is empty, `msg.value` must be zero.
36
+ */
37
+ constructor(
38
+ address implementation,
39
+ bytes memory _data,
40
+ IAccessManager manager,
41
+ bytes4[5] memory passThruMethods
42
+ ) payable AccessManagedProxy(implementation, _data, manager) {
43
+ PASS_THRU_METHODS_0 = passThruMethods[0];
44
+ PASS_THRU_METHODS_1 = passThruMethods[1];
45
+ PASS_THRU_METHODS_2 = passThruMethods[2];
46
+ PASS_THRU_METHODS_3 = passThruMethods[3];
47
+ PASS_THRU_METHODS_4 = passThruMethods[4];
48
+ }
49
+
50
+ /*
51
+ * @notice Skips the access control if the method called is one of the passThruMethods
52
+ * @dev See {PASS_THRU_METHODS()}
53
+ * @param selector The selector of the method called
54
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
55
+ */
56
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
57
+ return
58
+ selector == PASS_THRU_METHODS_0 ||
59
+ selector == PASS_THRU_METHODS_1 ||
60
+ selector == PASS_THRU_METHODS_2 ||
61
+ selector == PASS_THRU_METHODS_3 ||
62
+ selector == PASS_THRU_METHODS_4;
63
+ }
64
+
65
+ /**
66
+ * @notice Gives observability to the methods that are skipped from access control
67
+ * @dev This list is fixed and defined on contract construction
68
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
69
+ */
70
+ // solhint-disable-next-line func-name-mixedcase
71
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
72
+ methods = new bytes4[](5);
73
+ methods[0] = PASS_THRU_METHODS_0;
74
+ methods[1] = PASS_THRU_METHODS_1;
75
+ methods[2] = PASS_THRU_METHODS_2;
76
+ methods[3] = PASS_THRU_METHODS_3;
77
+ methods[4] = PASS_THRU_METHODS_4;
78
+ }
79
+ }
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS6
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS6 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+ bytes4 internal immutable PASS_THRU_METHODS_4;
20
+ bytes4 internal immutable PASS_THRU_METHODS_5;
21
+
22
+ /**
23
+ * @notice Constructor of the proxy, defining the implementation and the access manager
24
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
25
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
26
+ *
27
+ * @param implementation The initial implementation contract.
28
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
29
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
30
+ * @param manager The access manager that will handle access control
31
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
32
+ * views and other methods for gas optimization.
33
+ *
34
+ * Requirements:
35
+ *
36
+ * - If `data` is empty, `msg.value` must be zero.
37
+ */
38
+ constructor(
39
+ address implementation,
40
+ bytes memory _data,
41
+ IAccessManager manager,
42
+ bytes4[6] memory passThruMethods
43
+ ) payable AccessManagedProxy(implementation, _data, manager) {
44
+ PASS_THRU_METHODS_0 = passThruMethods[0];
45
+ PASS_THRU_METHODS_1 = passThruMethods[1];
46
+ PASS_THRU_METHODS_2 = passThruMethods[2];
47
+ PASS_THRU_METHODS_3 = passThruMethods[3];
48
+ PASS_THRU_METHODS_4 = passThruMethods[4];
49
+ PASS_THRU_METHODS_5 = passThruMethods[5];
50
+ }
51
+
52
+ /*
53
+ * @notice Skips the access control if the method called is one of the passThruMethods
54
+ * @dev See {PASS_THRU_METHODS()}
55
+ * @param selector The selector of the method called
56
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
57
+ */
58
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
59
+ return
60
+ selector == PASS_THRU_METHODS_0 ||
61
+ selector == PASS_THRU_METHODS_1 ||
62
+ selector == PASS_THRU_METHODS_2 ||
63
+ selector == PASS_THRU_METHODS_3 ||
64
+ selector == PASS_THRU_METHODS_4 ||
65
+ selector == PASS_THRU_METHODS_5;
66
+ }
67
+
68
+ /**
69
+ * @notice Gives observability to the methods that are skipped from access control
70
+ * @dev This list is fixed and defined on contract construction
71
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
72
+ */
73
+ // solhint-disable-next-line func-name-mixedcase
74
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
75
+ methods = new bytes4[](6);
76
+ methods[0] = PASS_THRU_METHODS_0;
77
+ methods[1] = PASS_THRU_METHODS_1;
78
+ methods[2] = PASS_THRU_METHODS_2;
79
+ methods[3] = PASS_THRU_METHODS_3;
80
+ methods[4] = PASS_THRU_METHODS_4;
81
+ methods[5] = PASS_THRU_METHODS_5;
82
+ }
83
+ }
@@ -0,0 +1,87 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS7
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS7 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+ bytes4 internal immutable PASS_THRU_METHODS_4;
20
+ bytes4 internal immutable PASS_THRU_METHODS_5;
21
+ bytes4 internal immutable PASS_THRU_METHODS_6;
22
+
23
+ /**
24
+ * @notice Constructor of the proxy, defining the implementation and the access manager
25
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
26
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
27
+ *
28
+ * @param implementation The initial implementation contract.
29
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
30
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
31
+ * @param manager The access manager that will handle access control
32
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
33
+ * views and other methods for gas optimization.
34
+ *
35
+ * Requirements:
36
+ *
37
+ * - If `data` is empty, `msg.value` must be zero.
38
+ */
39
+ constructor(
40
+ address implementation,
41
+ bytes memory _data,
42
+ IAccessManager manager,
43
+ bytes4[7] memory passThruMethods
44
+ ) payable AccessManagedProxy(implementation, _data, manager) {
45
+ PASS_THRU_METHODS_0 = passThruMethods[0];
46
+ PASS_THRU_METHODS_1 = passThruMethods[1];
47
+ PASS_THRU_METHODS_2 = passThruMethods[2];
48
+ PASS_THRU_METHODS_3 = passThruMethods[3];
49
+ PASS_THRU_METHODS_4 = passThruMethods[4];
50
+ PASS_THRU_METHODS_5 = passThruMethods[5];
51
+ PASS_THRU_METHODS_6 = passThruMethods[6];
52
+ }
53
+
54
+ /*
55
+ * @notice Skips the access control if the method called is one of the passThruMethods
56
+ * @dev See {PASS_THRU_METHODS()}
57
+ * @param selector The selector of the method called
58
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
59
+ */
60
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
61
+ return
62
+ selector == PASS_THRU_METHODS_0 ||
63
+ selector == PASS_THRU_METHODS_1 ||
64
+ selector == PASS_THRU_METHODS_2 ||
65
+ selector == PASS_THRU_METHODS_3 ||
66
+ selector == PASS_THRU_METHODS_4 ||
67
+ selector == PASS_THRU_METHODS_5 ||
68
+ selector == PASS_THRU_METHODS_6;
69
+ }
70
+
71
+ /**
72
+ * @notice Gives observability to the methods that are skipped from access control
73
+ * @dev This list is fixed and defined on contract construction
74
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
75
+ */
76
+ // solhint-disable-next-line func-name-mixedcase
77
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
78
+ methods = new bytes4[](7);
79
+ methods[0] = PASS_THRU_METHODS_0;
80
+ methods[1] = PASS_THRU_METHODS_1;
81
+ methods[2] = PASS_THRU_METHODS_2;
82
+ methods[3] = PASS_THRU_METHODS_3;
83
+ methods[4] = PASS_THRU_METHODS_4;
84
+ methods[5] = PASS_THRU_METHODS_5;
85
+ methods[6] = PASS_THRU_METHODS_6;
86
+ }
87
+ }
@@ -0,0 +1,91 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS8
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS8 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+ bytes4 internal immutable PASS_THRU_METHODS_4;
20
+ bytes4 internal immutable PASS_THRU_METHODS_5;
21
+ bytes4 internal immutable PASS_THRU_METHODS_6;
22
+ bytes4 internal immutable PASS_THRU_METHODS_7;
23
+
24
+ /**
25
+ * @notice Constructor of the proxy, defining the implementation and the access manager
26
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
27
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
28
+ *
29
+ * @param implementation The initial implementation contract.
30
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
31
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
32
+ * @param manager The access manager that will handle access control
33
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
34
+ * views and other methods for gas optimization.
35
+ *
36
+ * Requirements:
37
+ *
38
+ * - If `data` is empty, `msg.value` must be zero.
39
+ */
40
+ constructor(
41
+ address implementation,
42
+ bytes memory _data,
43
+ IAccessManager manager,
44
+ bytes4[8] memory passThruMethods
45
+ ) payable AccessManagedProxy(implementation, _data, manager) {
46
+ PASS_THRU_METHODS_0 = passThruMethods[0];
47
+ PASS_THRU_METHODS_1 = passThruMethods[1];
48
+ PASS_THRU_METHODS_2 = passThruMethods[2];
49
+ PASS_THRU_METHODS_3 = passThruMethods[3];
50
+ PASS_THRU_METHODS_4 = passThruMethods[4];
51
+ PASS_THRU_METHODS_5 = passThruMethods[5];
52
+ PASS_THRU_METHODS_6 = passThruMethods[6];
53
+ PASS_THRU_METHODS_7 = passThruMethods[7];
54
+ }
55
+
56
+ /*
57
+ * @notice Skips the access control if the method called is one of the passThruMethods
58
+ * @dev See {PASS_THRU_METHODS()}
59
+ * @param selector The selector of the method called
60
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
61
+ */
62
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
63
+ return
64
+ selector == PASS_THRU_METHODS_0 ||
65
+ selector == PASS_THRU_METHODS_1 ||
66
+ selector == PASS_THRU_METHODS_2 ||
67
+ selector == PASS_THRU_METHODS_3 ||
68
+ selector == PASS_THRU_METHODS_4 ||
69
+ selector == PASS_THRU_METHODS_5 ||
70
+ selector == PASS_THRU_METHODS_6 ||
71
+ selector == PASS_THRU_METHODS_7;
72
+ }
73
+
74
+ /**
75
+ * @notice Gives observability to the methods that are skipped from access control
76
+ * @dev This list is fixed and defined on contract construction
77
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
78
+ */
79
+ // solhint-disable-next-line func-name-mixedcase
80
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
81
+ methods = new bytes4[](8);
82
+ methods[0] = PASS_THRU_METHODS_0;
83
+ methods[1] = PASS_THRU_METHODS_1;
84
+ methods[2] = PASS_THRU_METHODS_2;
85
+ methods[3] = PASS_THRU_METHODS_3;
86
+ methods[4] = PASS_THRU_METHODS_4;
87
+ methods[5] = PASS_THRU_METHODS_5;
88
+ methods[6] = PASS_THRU_METHODS_6;
89
+ methods[7] = PASS_THRU_METHODS_7;
90
+ }
91
+ }
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {AccessManagedProxy} from "../AccessManagedProxy.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
6
+
7
+ /**
8
+ * @title AccessManagedProxyS9
9
+ * @notice Specialization of AccessManagedProxy with pass thru (skips AM) for some messages for gas optimization
10
+ *
11
+ * @custom:security-contact security@ensuro.co
12
+ * @author Ensuro
13
+ */
14
+ contract AccessManagedProxyS9 is AccessManagedProxy {
15
+ bytes4 internal immutable PASS_THRU_METHODS_0;
16
+ bytes4 internal immutable PASS_THRU_METHODS_1;
17
+ bytes4 internal immutable PASS_THRU_METHODS_2;
18
+ bytes4 internal immutable PASS_THRU_METHODS_3;
19
+ bytes4 internal immutable PASS_THRU_METHODS_4;
20
+ bytes4 internal immutable PASS_THRU_METHODS_5;
21
+ bytes4 internal immutable PASS_THRU_METHODS_6;
22
+ bytes4 internal immutable PASS_THRU_METHODS_7;
23
+ bytes4 internal immutable PASS_THRU_METHODS_8;
24
+
25
+ /**
26
+ * @notice Constructor of the proxy, defining the implementation and the access manager
27
+ * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation` and
28
+ * with `manager` as the ACCESS_MANAGER that will handle access control.
29
+ *
30
+ * @param implementation The initial implementation contract.
31
+ * @param _data If nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
32
+ * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
33
+ * @param manager The access manager that will handle access control
34
+ * @param passThruMethods The selector of methods that will skip the access control validation, typically used for
35
+ * views and other methods for gas optimization.
36
+ *
37
+ * Requirements:
38
+ *
39
+ * - If `data` is empty, `msg.value` must be zero.
40
+ */
41
+ constructor(
42
+ address implementation,
43
+ bytes memory _data,
44
+ IAccessManager manager,
45
+ bytes4[9] memory passThruMethods
46
+ ) payable AccessManagedProxy(implementation, _data, manager) {
47
+ PASS_THRU_METHODS_0 = passThruMethods[0];
48
+ PASS_THRU_METHODS_1 = passThruMethods[1];
49
+ PASS_THRU_METHODS_2 = passThruMethods[2];
50
+ PASS_THRU_METHODS_3 = passThruMethods[3];
51
+ PASS_THRU_METHODS_4 = passThruMethods[4];
52
+ PASS_THRU_METHODS_5 = passThruMethods[5];
53
+ PASS_THRU_METHODS_6 = passThruMethods[6];
54
+ PASS_THRU_METHODS_7 = passThruMethods[7];
55
+ PASS_THRU_METHODS_8 = passThruMethods[8];
56
+ }
57
+
58
+ /*
59
+ * @notice Skips the access control if the method called is one of the passThruMethods
60
+ * @dev See {PASS_THRU_METHODS()}
61
+ * @param selector The selector of the method called
62
+ * @return Whether the access control using ACCESS_MANAGER should be skipped or not
63
+ */
64
+ function _skipAC(bytes4 selector) internal view override returns (bool) {
65
+ return
66
+ selector == PASS_THRU_METHODS_0 ||
67
+ selector == PASS_THRU_METHODS_1 ||
68
+ selector == PASS_THRU_METHODS_2 ||
69
+ selector == PASS_THRU_METHODS_3 ||
70
+ selector == PASS_THRU_METHODS_4 ||
71
+ selector == PASS_THRU_METHODS_5 ||
72
+ selector == PASS_THRU_METHODS_6 ||
73
+ selector == PASS_THRU_METHODS_7 ||
74
+ selector == PASS_THRU_METHODS_8;
75
+ }
76
+
77
+ /**
78
+ * @notice Gives observability to the methods that are skipped from access control
79
+ * @dev This list is fixed and defined on contract construction
80
+ * @return methods The list of method selectors that skip ACCESS_MANAGER access control
81
+ */
82
+ // solhint-disable-next-line func-name-mixedcase
83
+ function PASS_THRU_METHODS() external view returns (bytes4[] memory methods) {
84
+ methods = new bytes4[](9);
85
+ methods[0] = PASS_THRU_METHODS_0;
86
+ methods[1] = PASS_THRU_METHODS_1;
87
+ methods[2] = PASS_THRU_METHODS_2;
88
+ methods[3] = PASS_THRU_METHODS_3;
89
+ methods[4] = PASS_THRU_METHODS_4;
90
+ methods[5] = PASS_THRU_METHODS_5;
91
+ methods[6] = PASS_THRU_METHODS_6;
92
+ methods[7] = PASS_THRU_METHODS_7;
93
+ methods[8] = PASS_THRU_METHODS_8;
94
+ }
95
+ }
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.16;
3
+
4
+ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
5
+
6
+ /**
7
+ * @title Dummy implementation contract that supports upgrade and logs methods called
8
+ *
9
+ * @custom:security-contact security@ensuro.co
10
+ * @author Ensuro
11
+ */
12
+ contract DummyImplementation is UUPSUpgradeable {
13
+ event MethodCalled(bytes4 selector);
14
+
15
+ /// @custom:oz-upgrades-unsafe-allow constructor
16
+ constructor() {
17
+ _disableInitializers();
18
+ }
19
+
20
+ function initialize() public virtual initializer {}
21
+
22
+ /// @inheritdoc UUPSUpgradeable
23
+ function _authorizeUpgrade(address newImplementation) internal override {}
24
+
25
+ // For making gas usage comparisons easier, I'm going to use different methods for each variant
26
+ function callThruAMP() external {
27
+ emit MethodCalled(this.callThruAMP.selector);
28
+ }
29
+
30
+ function callThru1967() external {
31
+ emit MethodCalled(this.callThru1967.selector);
32
+ }
33
+
34
+ function callDirect() external {
35
+ emit MethodCalled(this.callDirect.selector);
36
+ }
37
+
38
+ function callThruAMPSkippedMethod() external {
39
+ emit MethodCalled(this.callThruAMPSkippedMethod.selector);
40
+ }
41
+
42
+ function callThruAMPNonSkippedMethod() external {
43
+ emit MethodCalled(this.callThruAMPNonSkippedMethod.selector);
44
+ }
45
+
46
+ function viewMethod() external view returns (address) {
47
+ return msg.sender;
48
+ }
49
+
50
+ function pureMethod() external pure returns (uint256) {
51
+ return 123456;
52
+ }
53
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@ensuro/access-managed-proxy",
3
+ "description": "Variant of ERC-1967 proxy with built-in access control using OZ 5.x AccessManager",
4
+ "version": "0.1.0",
5
+ "files": [
6
+ "**/*.sol",
7
+ "/build",
8
+ "/js/*.js"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:ensuro/access-managed-proxy.git"
13
+ },
14
+ "keywords": [
15
+ "solidity",
16
+ "ethereum",
17
+ "smart",
18
+ "contracts",
19
+ "decentralized",
20
+ "erc1967"
21
+ ],
22
+ "author": "Ensuro <guillermo@ensuro.co>",
23
+ "license": "Apache-2.0",
24
+ "bugs": {
25
+ "url": "https://github.com/ensuro/access-managed-proxy/issues"
26
+ },
27
+ "homepage": "https://github.com/ensuro/access-managed-proxy#readme"
28
+ }