@chainlink/ace 0.5.0 → 1.0.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.
- package/.github/workflows/npm-publish.yml +28 -0
- package/README.md +9 -1
- package/UPGRADE_GUIDE.md +754 -0
- package/getting_started/GETTING_STARTED.md +6 -0
- package/getting_started/MyVault.sol +2 -2
- package/getting_started/advanced/SanctionsPolicy.sol +6 -2
- package/package.json +3 -3
- package/packages/cross-chain-identity/docs/API_REFERENCE.md +2 -0
- package/packages/cross-chain-identity/src/CredentialRegistry.sol +9 -7
- package/packages/cross-chain-identity/src/CredentialRegistryFactory.sol +96 -0
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidator.sol +15 -4
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidatorPolicy.sol +10 -7
- package/packages/cross-chain-identity/src/IdentityRegistry.sol +33 -17
- package/packages/cross-chain-identity/src/IdentityRegistryFactory.sol +96 -0
- package/packages/cross-chain-identity/src/TrustedIssuerRegistry.sol +8 -6
- package/packages/cross-chain-identity/src/TrustedIssuerRegistryFactory.sol +96 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRegistry.sol +6 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRequirements.sol +2 -1
- package/packages/cross-chain-identity/src/interfaces/IIdentityRegistry.sol +7 -1
- package/packages/cross-chain-identity/src/interfaces/ITrustedIssuerRegistry.sol +6 -0
- package/packages/cross-chain-identity/test/CredentialRegistry.t.sol +1 -1
- package/packages/cross-chain-identity/test/CredentialRegistryFactory.t.sol +105 -0
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidator.t.sol +16 -1
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidatorPolicy.t.sol +58 -1
- package/packages/cross-chain-identity/test/IdentityRegistry.t.sol +140 -1
- package/packages/cross-chain-identity/test/IdentityRegistryFactory.t.sol +103 -0
- package/packages/cross-chain-identity/test/IdentityValidator.t.sol +1 -1
- package/packages/cross-chain-identity/test/TrustedIssuerRegistry.t.sol +1 -1
- package/packages/cross-chain-identity/test/TrustedIssuerRegistryFactory.t.sol +107 -0
- package/packages/cross-chain-identity/test/helpers/BaseProxyTest.sol +1 -1
- package/packages/cross-chain-identity/test/helpers/MockCredentialDataValidator.sol +1 -1
- package/packages/cross-chain-identity/test/helpers/MockCredentialRegistryReverting.sol +3 -1
- package/packages/policy-management/README.md +1 -0
- package/packages/policy-management/docs/API_GUIDE.md +2 -0
- package/packages/policy-management/docs/API_REFERENCE.md +3 -1
- package/packages/policy-management/docs/CUSTOM_POLICIES_TUTORIAL.md +10 -4
- package/packages/policy-management/src/core/Policy.sol +5 -4
- package/packages/policy-management/src/core/PolicyEngine.sol +113 -57
- package/packages/policy-management/src/core/PolicyEngineFactory.sol +102 -0
- package/packages/policy-management/src/core/PolicyFactory.sol +1 -1
- package/packages/policy-management/src/core/PolicyProtected.sol +28 -55
- package/packages/policy-management/src/core/PolicyProtectedUpgradeable.sol +134 -0
- package/packages/policy-management/src/extractors/ComplianceTokenForceTransferExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ComplianceTokenFreezeUnfreezeExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ComplianceTokenMintBurnExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC20ApproveExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC20TransferExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC3643ForcedTransferExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC3643FreezeUnfreezeExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC3643MintBurnExtractor.sol +4 -1
- package/packages/policy-management/src/extractors/ERC3643SetAddressFrozenExtractor.sol +4 -1
- package/packages/policy-management/src/interfaces/ICertifiedActionValidator.sol +110 -0
- package/packages/policy-management/src/interfaces/IExtractor.sol +6 -0
- package/packages/policy-management/src/interfaces/IMapper.sol +6 -0
- package/packages/policy-management/src/interfaces/IPolicy.sol +6 -0
- package/packages/policy-management/src/interfaces/IPolicyEngine.sol +90 -10
- package/packages/policy-management/src/interfaces/IPolicyProtected.sol +6 -0
- package/packages/policy-management/src/libraries/CertifiedActionLib.sol +47 -0
- package/packages/policy-management/src/policies/AllowPolicy.sol +12 -7
- package/packages/policy-management/src/policies/BypassPolicy.sol +23 -5
- package/packages/policy-management/src/policies/CertifiedActionDONValidatorPolicy.sol +156 -0
- package/packages/policy-management/src/policies/CertifiedActionERC20TransferValidatorPolicy.sol +202 -0
- package/packages/policy-management/src/policies/CertifiedActionValidatorPolicy.sol +365 -0
- package/packages/policy-management/src/policies/IntervalPolicy.sol +64 -48
- package/packages/policy-management/src/policies/MaxPolicy.sol +7 -5
- package/packages/policy-management/src/policies/OnlyAuthorizedSenderPolicy.sol +20 -4
- package/packages/policy-management/src/policies/OnlyOwnerPolicy.sol +4 -2
- package/packages/policy-management/src/policies/PausePolicy.sol +16 -15
- package/packages/policy-management/src/policies/RejectPolicy.sol +23 -5
- package/packages/policy-management/src/policies/RoleBasedAccessControlPolicy.sol +7 -5
- package/packages/policy-management/src/policies/SecureMintPolicy.sol +136 -48
- package/packages/policy-management/src/policies/VolumePolicy.sol +9 -5
- package/packages/policy-management/src/policies/VolumeRatePolicy.sol +11 -7
- package/packages/policy-management/test/PolicyEngine.t.sol +131 -23
- package/packages/policy-management/test/PolicyEngineFactory.t.sol +95 -0
- package/packages/policy-management/test/PolicyFactory.t.sol +1 -1
- package/packages/policy-management/test/{PolicyProtectedToken.t.sol → PolicyProtected.t.sol} +54 -8
- package/packages/policy-management/test/PolicyProtectedUpgradeable.t.sol +126 -0
- package/packages/policy-management/test/extractors/ComplianceTokenForceTransferExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ComplianceTokenFreezeUnfreezeExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ComplianceTokenMintBurnExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ERC20ApproveExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ERC3643ForcedTransferExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ERC3643FreezeUnfreezeExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ERC3643MintBurnExtractor.t.sol +1 -1
- package/packages/policy-management/test/extractors/ERC3643SetAddressFrozenExtractor.t.sol +1 -1
- package/packages/policy-management/test/helpers/BaseCertifiedActionTest.sol +44 -0
- package/packages/policy-management/test/helpers/BaseProxyTest.sol +88 -7
- package/packages/policy-management/test/helpers/CustomMapper.sol +3 -1
- package/packages/policy-management/test/helpers/DummyExtractor.sol +3 -1
- package/packages/policy-management/test/helpers/ExpectedParameterPolicy.sol +3 -1
- package/packages/policy-management/test/helpers/FaultyPolicyEngine.sol +54 -0
- package/packages/policy-management/test/helpers/MockCertifiedActionValidatorPolicyExtension.sol +46 -0
- package/packages/policy-management/test/helpers/MockToken.sol +2 -5
- package/packages/policy-management/test/helpers/MockTokenExtractor.sol +9 -4
- package/packages/policy-management/test/helpers/MockTokenUpgradeable.sol +66 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysAllowed.sol +3 -1
- package/packages/policy-management/test/helpers/PolicyAlwaysContinue.sol +3 -1
- package/packages/policy-management/test/helpers/PolicyAlwaysRejected.sol +10 -1
- package/packages/policy-management/test/helpers/PolicyFailingRun.sol +3 -1
- package/packages/policy-management/test/policies/AllowPolicy.t.sol +39 -23
- package/packages/policy-management/test/policies/BypassPolicy.t.sol +48 -20
- package/packages/policy-management/test/policies/CertifiedActionDONValidatorPolicy.t.sol +172 -0
- package/packages/policy-management/test/policies/CertifiedActionERC20TransferValidatorPolicy.t.sol +217 -0
- package/packages/policy-management/test/policies/CertifiedActionValidatorPolicy.t.sol +1083 -0
- package/packages/policy-management/test/policies/IntervalPolicy.t.sol +105 -55
- package/packages/policy-management/test/policies/MaxPolicy.t.sol +15 -7
- package/packages/policy-management/test/policies/OnlyAuthorizedSenderPolicy.t.sol +91 -16
- package/packages/policy-management/test/policies/OnlyOwnerPolicy.t.sol +11 -7
- package/packages/policy-management/test/policies/PausePolicy.t.sol +46 -16
- package/packages/policy-management/test/policies/RejectPolicy.t.sol +52 -24
- package/packages/policy-management/test/policies/RoleBasedAccessControlPolicy.t.sol +50 -30
- package/packages/policy-management/test/policies/SecureMintPolicy.t.sol +211 -32
- package/packages/policy-management/test/policies/VolumePolicy.t.sol +20 -10
- package/packages/policy-management/test/policies/VolumeRatePolicy.t.sol +24 -18
- package/packages/tokens/erc-20/src/ComplianceTokenERC20.sol +4 -7
- package/packages/tokens/erc-20/src/ComplianceTokenStoreERC20.sol +4 -4
- package/packages/tokens/erc-20/test/ComplianceTokenERC20.t.sol +92 -82
- package/packages/tokens/erc-20/test/helpers/BaseProxyTest.sol +74 -1
- package/packages/tokens/erc-3643/src/ComplianceTokenERC3643.sol +12 -7
- package/packages/tokens/erc-3643/src/ComplianceTokenStoreERC3643.sol +4 -4
- package/packages/tokens/erc-3643/test/ComplianceTokenERC3643.t.sol +108 -119
- package/packages/tokens/erc-3643/test/helpers/BaseProxyTest.sol +74 -1
- package/packages/tokens/erc-3643/test/helpers/ExpectedContextPolicy.sol +3 -1
- package/remappings.txt +1 -0
- package/script/DeployCertifiedActionsComplianceTokenERC3643.s.sol +125 -0
|
@@ -3,61 +3,32 @@ pragma solidity ^0.8.20;
|
|
|
3
3
|
|
|
4
4
|
import {IPolicyEngine} from "../interfaces/IPolicyEngine.sol";
|
|
5
5
|
import {IPolicyProtected} from "../interfaces/IPolicyProtected.sol";
|
|
6
|
-
import {IERC165} from "@openzeppelin/contracts/utils/introspection/
|
|
7
|
-
import {
|
|
8
|
-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
9
|
-
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
6
|
+
import {IERC165, ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
7
|
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* @title PolicyProtected.sol
|
|
13
|
-
* @dev Base implementation for attaching a policy engine to a smart contract.
|
|
14
|
-
* to
|
|
15
|
-
* of the extending contract to run the policy engine before executing the method.
|
|
11
|
+
* @dev Base implementation for attaching a policy engine to a smart contract. Provides modifiers to be attached
|
|
12
|
+
* to methods of the extending contract to run the policy engine before executing the method.
|
|
16
13
|
*/
|
|
17
|
-
abstract contract PolicyProtected is
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
IPolicyEngine policyEngine;
|
|
21
|
-
mapping(address sender => bytes context) senderContext; // use transient storage eventually
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// keccak256(abi.encode(uint256(keccak256("policy-management.PolicyProtected")) - 1)) &
|
|
25
|
-
// ~bytes32(uint256(0xff))
|
|
26
|
-
// solhint-disable-next-line const-name-snakecase
|
|
27
|
-
bytes32 private constant policyProtectedStorageLocation =
|
|
28
|
-
0x381e6510830aa5d1f847c166134370760011d6c9becccc73371e64e18c3c4f00;
|
|
29
|
-
|
|
30
|
-
function _policyProtectedStorage() private pure returns (PolicyProtectedStorage storage $) {
|
|
31
|
-
// solhint-disable-next-line no-inline-assembly
|
|
32
|
-
assembly {
|
|
33
|
-
$.slot := policyProtectedStorageLocation
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
constructor() {
|
|
38
|
-
_disableInitializers();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function __PolicyProtected_init(address initialOwner, address policyEngine) internal onlyInitializing {
|
|
42
|
-
__Ownable_init(initialOwner);
|
|
43
|
-
__ERC165_init();
|
|
44
|
-
__PolicyProtected_init_unchained(policyEngine);
|
|
45
|
-
}
|
|
14
|
+
abstract contract PolicyProtected is Ownable, ERC165, IPolicyProtected {
|
|
15
|
+
IPolicyEngine internal s_policyEngine;
|
|
16
|
+
mapping(address sender => bytes context) internal s_senderContext; // use transient storage eventually
|
|
46
17
|
|
|
47
|
-
|
|
18
|
+
constructor(address initialOwner, address policyEngine) Ownable(initialOwner) {
|
|
48
19
|
_attachPolicyEngine(policyEngine);
|
|
49
20
|
}
|
|
21
|
+
|
|
50
22
|
/**
|
|
51
23
|
* @dev Modifier to run the policy engine on the current method.
|
|
52
24
|
* @notice After the function execution completes, any context that was set will be automatically cleared.
|
|
53
25
|
*/
|
|
54
|
-
|
|
55
26
|
modifier runPolicy() {
|
|
56
|
-
if (address(
|
|
27
|
+
if (address(s_policyEngine) == address(0)) {
|
|
57
28
|
revert IPolicyEngine.PolicyEngineUndefined();
|
|
58
29
|
}
|
|
59
30
|
bytes memory context = getContext();
|
|
60
|
-
|
|
31
|
+
s_policyEngine.run(
|
|
61
32
|
IPolicyEngine.Payload({selector: msg.sig, sender: msg.sender, data: msg.data[4:], context: context})
|
|
62
33
|
);
|
|
63
34
|
_;
|
|
@@ -71,10 +42,10 @@ abstract contract PolicyProtected is Initializable, OwnableUpgradeable, ERC165Up
|
|
|
71
42
|
* @param context Additional information or authorization to perform the operation.
|
|
72
43
|
*/
|
|
73
44
|
modifier runPolicyWithContext(bytes calldata context) {
|
|
74
|
-
if (address(
|
|
45
|
+
if (address(s_policyEngine) == address(0)) {
|
|
75
46
|
revert IPolicyEngine.PolicyEngineUndefined();
|
|
76
47
|
}
|
|
77
|
-
|
|
48
|
+
s_policyEngine.run(
|
|
78
49
|
IPolicyEngine.Payload({selector: msg.sig, sender: msg.sender, data: msg.data[4:], context: context})
|
|
79
50
|
);
|
|
80
51
|
_;
|
|
@@ -86,41 +57,43 @@ abstract contract PolicyProtected is Initializable, OwnableUpgradeable, ERC165Up
|
|
|
86
57
|
}
|
|
87
58
|
|
|
88
59
|
function _attachPolicyEngine(address policyEngine) internal {
|
|
89
|
-
|
|
90
|
-
|
|
60
|
+
require(policyEngine != address(0), "Policy engine is zero address");
|
|
61
|
+
if (address(s_policyEngine) != address(0)) {
|
|
62
|
+
try s_policyEngine.detach() {
|
|
63
|
+
// Detachment succeeded
|
|
64
|
+
} catch (bytes memory reason) {
|
|
65
|
+
emit PolicyEngineDetachFailed(address(s_policyEngine), reason);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
s_policyEngine = IPolicyEngine(policyEngine);
|
|
69
|
+
s_policyEngine.attach();
|
|
91
70
|
emit PolicyEngineAttached(policyEngine);
|
|
92
71
|
}
|
|
93
72
|
|
|
94
73
|
/// @inheritdoc IPolicyProtected
|
|
95
74
|
function getPolicyEngine() public view virtual override returns (address) {
|
|
96
|
-
return address(
|
|
75
|
+
return address(s_policyEngine);
|
|
97
76
|
}
|
|
98
77
|
|
|
99
78
|
/// @inheritdoc IPolicyProtected
|
|
100
79
|
function setContext(bytes calldata context) public override {
|
|
101
|
-
|
|
80
|
+
s_senderContext[msg.sender] = context;
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
/// @inheritdoc IPolicyProtected
|
|
105
84
|
function getContext() public view override returns (bytes memory) {
|
|
106
|
-
return
|
|
85
|
+
return s_senderContext[msg.sender];
|
|
107
86
|
}
|
|
108
87
|
|
|
109
88
|
/// @inheritdoc IPolicyProtected
|
|
110
89
|
function clearContext() public override {
|
|
111
|
-
delete
|
|
90
|
+
delete s_senderContext[msg.sender];
|
|
112
91
|
}
|
|
113
92
|
|
|
114
93
|
/**
|
|
115
94
|
* @dev See {IERC165-supportsInterface}.
|
|
116
95
|
*/
|
|
117
|
-
function supportsInterface(bytes4 interfaceId)
|
|
118
|
-
public
|
|
119
|
-
view
|
|
120
|
-
virtual
|
|
121
|
-
override(ERC165Upgradeable, IERC165)
|
|
122
|
-
returns (bool)
|
|
123
|
-
{
|
|
96
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
|
124
97
|
return interfaceId == type(IPolicyProtected).interfaceId || super.supportsInterface(interfaceId);
|
|
125
98
|
}
|
|
126
99
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
import {IPolicyEngine} from "../interfaces/IPolicyEngine.sol";
|
|
5
|
+
import {IPolicyProtected} from "../interfaces/IPolicyProtected.sol";
|
|
6
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
7
|
+
import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
|
|
8
|
+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
9
|
+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @title PolicyProtectedUpgradeable.sol
|
|
13
|
+
* @dev Base implementation for attaching a policy engine to an upgradeable smart contract. Uses ERC-7201 storage
|
|
14
|
+
* to not conflict with other storage slots of extending contracts. Provides modifiers to be attached to methods
|
|
15
|
+
* of the extending contract to run the policy engine before executing the method.
|
|
16
|
+
*/
|
|
17
|
+
abstract contract PolicyProtectedUpgradeable is Initializable, OwnableUpgradeable, ERC165Upgradeable, IPolicyProtected {
|
|
18
|
+
/// @custom:storage-location erc7201:chainlink.ace.PolicyProtected
|
|
19
|
+
struct PolicyProtectedStorage {
|
|
20
|
+
IPolicyEngine policyEngine;
|
|
21
|
+
mapping(address sender => bytes context) senderContext; // use transient storage eventually
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// keccak256(abi.encode(uint256(keccak256("chainlink.ace.PolicyProtected")) - 1)) &
|
|
25
|
+
// ~bytes32(uint256(0xff))
|
|
26
|
+
// solhint-disable-next-line const-name-snakecase
|
|
27
|
+
bytes32 private constant policyProtectedStorageLocation =
|
|
28
|
+
0x5970a53874f73819f13c80052b0c1b19d6ce68b29b2ad28a7413019c8a409000;
|
|
29
|
+
|
|
30
|
+
function _policyProtectedStorage() private pure returns (PolicyProtectedStorage storage $) {
|
|
31
|
+
// solhint-disable-next-line no-inline-assembly
|
|
32
|
+
assembly {
|
|
33
|
+
$.slot := policyProtectedStorageLocation
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
_disableInitializers();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __PolicyProtected_init(address initialOwner, address policyEngine) internal onlyInitializing {
|
|
42
|
+
__Ownable_init(initialOwner);
|
|
43
|
+
__ERC165_init();
|
|
44
|
+
__PolicyProtected_init_unchained(policyEngine);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function __PolicyProtected_init_unchained(address policyEngine) internal onlyInitializing {
|
|
48
|
+
_attachPolicyEngine(policyEngine);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @dev Modifier to run the policy engine on the current method.
|
|
52
|
+
* @notice After the function execution completes, any context that was set will be automatically cleared.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
modifier runPolicy() {
|
|
56
|
+
if (address(_policyProtectedStorage().policyEngine) == address(0)) {
|
|
57
|
+
revert IPolicyEngine.PolicyEngineUndefined();
|
|
58
|
+
}
|
|
59
|
+
bytes memory context = getContext();
|
|
60
|
+
_policyProtectedStorage().policyEngine.run(
|
|
61
|
+
IPolicyEngine.Payload({selector: msg.sig, sender: msg.sender, data: msg.data[4:], context: context})
|
|
62
|
+
);
|
|
63
|
+
_;
|
|
64
|
+
if (context.length > 0) {
|
|
65
|
+
clearContext();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @dev Modifier to run the policy engine on the current method with the provided context.
|
|
71
|
+
* @param context Additional information or authorization to perform the operation.
|
|
72
|
+
*/
|
|
73
|
+
modifier runPolicyWithContext(bytes calldata context) {
|
|
74
|
+
if (address(_policyProtectedStorage().policyEngine) == address(0)) {
|
|
75
|
+
revert IPolicyEngine.PolicyEngineUndefined();
|
|
76
|
+
}
|
|
77
|
+
_policyProtectedStorage().policyEngine.run(
|
|
78
|
+
IPolicyEngine.Payload({selector: msg.sig, sender: msg.sender, data: msg.data[4:], context: context})
|
|
79
|
+
);
|
|
80
|
+
_;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// @inheritdoc IPolicyProtected
|
|
84
|
+
function attachPolicyEngine(address policyEngine) external virtual override onlyOwner {
|
|
85
|
+
_attachPolicyEngine(policyEngine);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function _attachPolicyEngine(address policyEngine) internal {
|
|
89
|
+
require(policyEngine != address(0), "Policy engine is zero address");
|
|
90
|
+
if (address(_policyProtectedStorage().policyEngine) != address(0)) {
|
|
91
|
+
try _policyProtectedStorage().policyEngine.detach() {
|
|
92
|
+
// Detachment succeeded
|
|
93
|
+
} catch (bytes memory reason) {
|
|
94
|
+
emit PolicyEngineDetachFailed(address(_policyProtectedStorage().policyEngine), reason);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
_policyProtectedStorage().policyEngine = IPolicyEngine(policyEngine);
|
|
98
|
+
IPolicyEngine(policyEngine).attach();
|
|
99
|
+
emit PolicyEngineAttached(policyEngine);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// @inheritdoc IPolicyProtected
|
|
103
|
+
function getPolicyEngine() public view virtual override returns (address) {
|
|
104
|
+
return address(_policyProtectedStorage().policyEngine);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// @inheritdoc IPolicyProtected
|
|
108
|
+
function setContext(bytes calldata context) public override {
|
|
109
|
+
_policyProtectedStorage().senderContext[msg.sender] = context;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// @inheritdoc IPolicyProtected
|
|
113
|
+
function getContext() public view override returns (bytes memory) {
|
|
114
|
+
return _policyProtectedStorage().senderContext[msg.sender];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// @inheritdoc IPolicyProtected
|
|
118
|
+
function clearContext() public override {
|
|
119
|
+
delete _policyProtectedStorage().senderContext[msg.sender];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @dev See {IERC165-supportsInterface}.
|
|
124
|
+
*/
|
|
125
|
+
function supportsInterface(bytes4 interfaceId)
|
|
126
|
+
public
|
|
127
|
+
view
|
|
128
|
+
virtual
|
|
129
|
+
override(ERC165Upgradeable, IERC165)
|
|
130
|
+
returns (bool)
|
|
131
|
+
{
|
|
132
|
+
return interfaceId == type(IPolicyProtected).interfaceId || super.supportsInterface(interfaceId);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -13,6 +13,9 @@ import {ComplianceTokenERC20} from "../../../tokens/erc-20/src/ComplianceTokenER
|
|
|
13
13
|
* authorized agents to move tokens between addresses without approval for compliance purposes.
|
|
14
14
|
*/
|
|
15
15
|
contract ComplianceTokenForceTransferExtractor is IExtractor {
|
|
16
|
+
/// @notice Type and version of the extractor
|
|
17
|
+
string public constant override typeAndVersion = "ComplianceTokenForceTransferExtractor 1.0.0";
|
|
18
|
+
|
|
16
19
|
/// @notice Parameter key for the sender/from address in forced transfer operations
|
|
17
20
|
bytes32 public constant PARAM_FROM = keccak256("from");
|
|
18
21
|
|
package/packages/policy-management/src/extractors/ComplianceTokenFreezeUnfreezeExtractor.sol
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -12,6 +12,9 @@ import {ComplianceTokenERC20} from "../../../tokens/erc-20/src/ComplianceTokenER
|
|
|
12
12
|
* and extracts the target account address and amount parameters for compliance-related freezing operations.
|
|
13
13
|
*/
|
|
14
14
|
contract ComplianceTokenFreezeUnfreezeExtractor is IExtractor {
|
|
15
|
+
/// @notice Type and version of the extractor
|
|
16
|
+
string public constant override typeAndVersion = "ComplianceTokenFreezeUnfreezeExtractor 1.0.0";
|
|
17
|
+
|
|
15
18
|
/// @notice Parameter key for the target account address in freeze/unfreeze operations
|
|
16
19
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
17
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -13,6 +13,9 @@ import {ComplianceTokenERC20} from "../../../tokens/erc-20/src/ComplianceTokenER
|
|
|
13
13
|
* For burn(), the account is set to msg.sender since it burns from the caller's balance.
|
|
14
14
|
*/
|
|
15
15
|
contract ComplianceTokenMintBurnExtractor is IExtractor {
|
|
16
|
+
/// @notice Type and version of the extractor
|
|
17
|
+
string public constant override typeAndVersion = "ComplianceTokenMintBurnExtractor 1.0.0";
|
|
18
|
+
|
|
16
19
|
/// @notice Parameter key for the target account address in mint/burn operations
|
|
17
20
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
18
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -12,6 +12,9 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
12
12
|
* spender address, and amount parameters from the function calldata.
|
|
13
13
|
*/
|
|
14
14
|
contract ERC20ApproveExtractor is IExtractor {
|
|
15
|
+
/// @notice Type and version of the extractor
|
|
16
|
+
string public constant override typeAndVersion = "ERC20ApproveExtractor 1.0.0";
|
|
17
|
+
|
|
15
18
|
/// @notice Parameter key for the account granting the approval (msg.sender)
|
|
16
19
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
17
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -13,6 +13,9 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
13
13
|
* is set to the transaction sender (msg.sender).
|
|
14
14
|
*/
|
|
15
15
|
contract ERC20TransferExtractor is IExtractor {
|
|
16
|
+
/// @notice Type and version of the extractor
|
|
17
|
+
string public constant override typeAndVersion = "ERC20TransferExtractor 1.0.0";
|
|
18
|
+
|
|
16
19
|
/// @notice Parameter key for the sender/from address in transfer operations
|
|
17
20
|
bytes32 public constant PARAM_FROM = keccak256("from");
|
|
18
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -13,6 +13,9 @@ import {IToken} from "../../../vendor/erc-3643/token/IToken.sol";
|
|
|
13
13
|
* Forced transfers allow authorized agents to move tokens between addresses without approval.
|
|
14
14
|
*/
|
|
15
15
|
contract ERC3643ForcedTransferExtractor is IExtractor {
|
|
16
|
+
/// @notice Type and version of the extractor
|
|
17
|
+
string public constant override typeAndVersion = "ERC3643ForcedTransferExtractor 1.0.0";
|
|
18
|
+
|
|
16
19
|
/// @notice Parameter key for the sender/from address in forced transfer operations
|
|
17
20
|
bytes32 public constant PARAM_FROM = keccak256("from");
|
|
18
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -12,6 +12,9 @@ import {IToken} from "../../../vendor/erc-3643/token/IToken.sol";
|
|
|
12
12
|
* from the ERC3643 token standard and extracts the target account address and amount parameters.
|
|
13
13
|
*/
|
|
14
14
|
contract ERC3643FreezeUnfreezeExtractor is IExtractor {
|
|
15
|
+
/// @notice Type and version of the extractor
|
|
16
|
+
string public constant override typeAndVersion = "ERC3643FreezeUnfreezeExtractor 1.0.0";
|
|
17
|
+
|
|
15
18
|
/// @notice Parameter key for the target account address in freeze/unfreeze operations
|
|
16
19
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
17
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -12,6 +12,9 @@ import {IToken} from "../../../vendor/erc-3643/token/IToken.sol";
|
|
|
12
12
|
* and extracts the target account address and amount parameters from the function calldata.
|
|
13
13
|
*/
|
|
14
14
|
contract ERC3643MintBurnExtractor is IExtractor {
|
|
15
|
+
/// @notice Type and version of the extractor
|
|
16
|
+
string public constant override typeAndVersion = "ERC3643MintBurnExtractor 1.0.0";
|
|
17
|
+
|
|
15
18
|
/// @notice Parameter key for the target account address in mint/burn operations
|
|
16
19
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
17
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
3
|
|
|
4
4
|
import {IExtractor} from "@chainlink/policy-management/interfaces/IExtractor.sol";
|
|
5
5
|
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
@@ -12,6 +12,9 @@ import {IToken} from "../../../vendor/erc-3643/token/IToken.sol";
|
|
|
12
12
|
* and extracts the target account address and freeze status (boolean value) parameters.
|
|
13
13
|
*/
|
|
14
14
|
contract ERC3643SetAddressFrozenExtractor is IExtractor {
|
|
15
|
+
/// @notice Type and version of the extractor
|
|
16
|
+
string public constant override typeAndVersion = "ERC3643SetAddressFrozenExtractor 1.0.0";
|
|
17
|
+
|
|
15
18
|
/// @notice Parameter key for the target account address in freeze/unfreeze operations
|
|
16
19
|
bytes32 public constant PARAM_ACCOUNT = keccak256("account");
|
|
17
20
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
interface ICertifiedActionValidator {
|
|
5
|
+
struct Permit {
|
|
6
|
+
bytes32 permitId;
|
|
7
|
+
address caller;
|
|
8
|
+
address subject;
|
|
9
|
+
bytes4 selector;
|
|
10
|
+
bytes[] parameters;
|
|
11
|
+
bytes metadata;
|
|
12
|
+
uint64 maxUses;
|
|
13
|
+
uint48 expiry;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
struct SignedPermit {
|
|
17
|
+
Permit permit;
|
|
18
|
+
bytes signature;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @notice Emitted when an issuer is allowed to sign permits.
|
|
23
|
+
* @param issuerKey The key of the issuer.
|
|
24
|
+
*/
|
|
25
|
+
event IssuerAllowed(bytes issuerKey);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @notice Emitted when an issuer is disallowed from signing permits.
|
|
29
|
+
* @param issuerKey The key of the issuer.
|
|
30
|
+
*/
|
|
31
|
+
event IssuerDisAllowed(bytes issuerKey);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @notice Emitted when a permit is stored.
|
|
35
|
+
* @param permitId The ID of the permit.
|
|
36
|
+
*/
|
|
37
|
+
event PermitStored(bytes32 indexed permitId);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @notice Emitted when a permit is used.
|
|
41
|
+
* @param permitId The ID of the permit.
|
|
42
|
+
*/
|
|
43
|
+
event PermitUsed(bytes32 indexed permitId);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @notice Emitted when a permit is revoked.
|
|
47
|
+
* @param permitId The ID of the permit.
|
|
48
|
+
*/
|
|
49
|
+
event PermitRevoked(bytes32 indexed permitId);
|
|
50
|
+
|
|
51
|
+
/// @notice Error emitted when a permit signature is invalid.
|
|
52
|
+
error InvalidSignature(bytes32 permitId);
|
|
53
|
+
/// @notice Error emitted when a permit has expired.
|
|
54
|
+
error PermitExpired(bytes32 permitId, uint48 expiration);
|
|
55
|
+
/// @notice Error emitted when an issuer is already allowed or disallowed.
|
|
56
|
+
error IssuerAllowedAlreadySet(bytes issuerKey, bool allowed);
|
|
57
|
+
/// @notice Error emitted when a permit has already been presented.
|
|
58
|
+
error PermitAlreadyPresented(bytes32 permitId);
|
|
59
|
+
/// @notice Error emitted when a permit has been revoked.
|
|
60
|
+
error PermitAlreadyRevoked(bytes32 permitId);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @notice Presents and stores a permit in the validator. Since only 1 valid permit for the same intent is allowed,
|
|
64
|
+
* presenting a new permit will override any previous permit for the same intent. Note that the act of presenting a
|
|
65
|
+
* permit override any ability for a context permit for the same intent.
|
|
66
|
+
* @param permit The permit to present.
|
|
67
|
+
* @param signature The signature of the permit.
|
|
68
|
+
*/
|
|
69
|
+
function present(Permit calldata permit, bytes calldata signature) external;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @notice Checks if a permit is valid.
|
|
73
|
+
* @param permit The permit to check.
|
|
74
|
+
* @param signature The signature of the permit.
|
|
75
|
+
* @return True if the permit is valid, false otherwise.
|
|
76
|
+
*/
|
|
77
|
+
function check(Permit calldata permit, bytes calldata signature) external view returns (bool);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @notice Revokes a permit.
|
|
81
|
+
* @param permitId The ID of the permit to revoke.
|
|
82
|
+
*/
|
|
83
|
+
function revoke(bytes32 permitId) external;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @notice Gets the usage count of a permit.
|
|
87
|
+
* @param permitId The ID of the permit.
|
|
88
|
+
* @return The usage count of the permit.
|
|
89
|
+
*/
|
|
90
|
+
function getUsage(bytes32 permitId) external view returns (uint256);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @notice Allows an issuer to sign permits.
|
|
94
|
+
* @param issuerKey The key of the issuer.
|
|
95
|
+
*/
|
|
96
|
+
function allowIssuer(bytes calldata issuerKey) external;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @notice Disallows an issuer from signing permits.
|
|
100
|
+
* @param issuerKey The key of the issuer.
|
|
101
|
+
*/
|
|
102
|
+
function disAllowIssuer(bytes calldata issuerKey) external;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @notice Gets if an issuer is allowed to sign permits.
|
|
106
|
+
* @param issuerKey The key of the issuer.
|
|
107
|
+
* @return True if the issuer is allowed, false otherwise.
|
|
108
|
+
*/
|
|
109
|
+
function getIssuerAllowed(bytes calldata issuerKey) external view returns (bool);
|
|
110
|
+
}
|
|
@@ -8,6 +8,12 @@ import {IPolicyEngine} from "./IPolicyEngine.sol";
|
|
|
8
8
|
* @dev Interface for extracting parameters from a payload.
|
|
9
9
|
*/
|
|
10
10
|
interface IExtractor {
|
|
11
|
+
/**
|
|
12
|
+
* @notice Returns the type and version of the extractor.
|
|
13
|
+
* @return A string representing the type and version of the extractor.
|
|
14
|
+
*/
|
|
15
|
+
function typeAndVersion() external pure returns (string memory);
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* @notice Extracts parameters from a payload.
|
|
13
19
|
* @param payload The payload to extract parameters from.
|
|
@@ -8,6 +8,12 @@ import {IPolicyEngine} from "./IPolicyEngine.sol";
|
|
|
8
8
|
* @dev Interface for mapping extracted parameters to a list of policy parameters.
|
|
9
9
|
*/
|
|
10
10
|
interface IMapper {
|
|
11
|
+
/**
|
|
12
|
+
* @notice Returns the type and version of the mapper.
|
|
13
|
+
* @return A string representing the type and version of the mapper.
|
|
14
|
+
*/
|
|
15
|
+
function typeAndVersion() external pure returns (string memory);
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* @notice Maps extracted parameters to a list of policy parameters.
|
|
13
19
|
* @param extractedParameters The extracted parameters.
|
|
@@ -9,6 +9,12 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
|
9
9
|
* @dev Interface for running a policy.
|
|
10
10
|
*/
|
|
11
11
|
interface IPolicy is IERC165 {
|
|
12
|
+
/**
|
|
13
|
+
* @notice Returns the type and version of the policy.
|
|
14
|
+
* @return A string representing the type and version of the policy.
|
|
15
|
+
*/
|
|
16
|
+
function typeAndVersion() external pure returns (string memory);
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* @notice Hook called upon installation of the policy.
|
|
14
20
|
* @param selector The selector of the policy.
|