@chainlink/ace 0.5.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/.foundry-version +1 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/auto-release-version.yml +107 -0
- package/.github/workflows/create-version-pr.yml +95 -0
- package/.github/workflows/forge-docs.yml +90 -0
- package/.github/workflows/forge-test.yml +59 -0
- package/.solhint-test.json +18 -0
- package/.solhint.json +16 -0
- package/.solhintignore +3 -0
- package/.solhintignore-test +2 -0
- package/Glossary.md +141 -0
- package/LICENSE +59 -0
- package/README.md +218 -0
- package/assets/chainlink-logo.svg +21 -0
- package/chainlink-ace-License-grants +2 -0
- package/foundry.toml +33 -0
- package/getting_started/GETTING_STARTED.md +477 -0
- package/getting_started/MyVault.sol +48 -0
- package/getting_started/advanced/.env.example +36 -0
- package/getting_started/advanced/GETTING_STARTED_ADVANCED.md +431 -0
- package/getting_started/advanced/SanctionsList.sol +25 -0
- package/getting_started/advanced/SanctionsPolicy.sol +58 -0
- package/package.json +41 -0
- package/packages/cross-chain-identity/README.md +148 -0
- package/packages/cross-chain-identity/docs/API_GUIDE.md +120 -0
- package/packages/cross-chain-identity/docs/API_REFERENCE.md +271 -0
- package/packages/cross-chain-identity/docs/CONCEPTS.md +253 -0
- package/packages/cross-chain-identity/docs/CREDENTIAL_FLOW.md +195 -0
- package/packages/cross-chain-identity/docs/SECURITY.md +70 -0
- package/packages/cross-chain-identity/src/CredentialRegistry.sol +245 -0
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidator.sol +339 -0
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidatorPolicy.sol +71 -0
- package/packages/cross-chain-identity/src/IdentityRegistry.sol +123 -0
- package/packages/cross-chain-identity/src/TrustedIssuerRegistry.sol +140 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialDataValidator.sol +30 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRegistry.sol +170 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRequirements.sol +192 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialValidator.sol +37 -0
- package/packages/cross-chain-identity/src/interfaces/IIdentityRegistry.sol +85 -0
- package/packages/cross-chain-identity/src/interfaces/IIdentityValidator.sol +18 -0
- package/packages/cross-chain-identity/src/interfaces/ITrustedIssuerRegistry.sol +61 -0
- package/packages/cross-chain-identity/test/CredentialRegistry.t.sol +220 -0
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidator.t.sol +554 -0
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidatorPolicy.t.sol +114 -0
- package/packages/cross-chain-identity/test/IdentityRegistry.t.sol +106 -0
- package/packages/cross-chain-identity/test/IdentityValidator.t.sol +969 -0
- package/packages/cross-chain-identity/test/TrustedIssuerRegistry.t.sol +123 -0
- package/packages/cross-chain-identity/test/helpers/BaseProxyTest.sol +112 -0
- package/packages/cross-chain-identity/test/helpers/MockCredentialDataValidator.sol +26 -0
- package/packages/cross-chain-identity/test/helpers/MockCredentialRegistryReverting.sol +131 -0
- package/packages/policy-management/README.md +197 -0
- package/packages/policy-management/docs/API_GUIDE.md +290 -0
- package/packages/policy-management/docs/API_REFERENCE.md +173 -0
- package/packages/policy-management/docs/CONCEPTS.md +156 -0
- package/packages/policy-management/docs/CUSTOM_POLICIES_TUTORIAL.md +195 -0
- package/packages/policy-management/docs/POLICY_ORDERING_GUIDE.md +91 -0
- package/packages/policy-management/docs/SECURITY.md +57 -0
- package/packages/policy-management/src/core/Policy.sol +124 -0
- package/packages/policy-management/src/core/PolicyEngine.sol +382 -0
- package/packages/policy-management/src/core/PolicyFactory.sol +92 -0
- package/packages/policy-management/src/core/PolicyProtected.sol +126 -0
- package/packages/policy-management/src/extractors/ComplianceTokenForceTransferExtractor.sol +57 -0
- package/packages/policy-management/src/extractors/ComplianceTokenFreezeUnfreezeExtractor.sol +54 -0
- package/packages/policy-management/src/extractors/ComplianceTokenMintBurnExtractor.sol +61 -0
- package/packages/policy-management/src/extractors/ERC20ApproveExtractor.sol +57 -0
- package/packages/policy-management/src/extractors/ERC20TransferExtractor.sol +62 -0
- package/packages/policy-management/src/extractors/ERC3643ForcedTransferExtractor.sol +56 -0
- package/packages/policy-management/src/extractors/ERC3643FreezeUnfreezeExtractor.sol +55 -0
- package/packages/policy-management/src/extractors/ERC3643MintBurnExtractor.sol +51 -0
- package/packages/policy-management/src/extractors/ERC3643SetAddressFrozenExtractor.sol +51 -0
- package/packages/policy-management/src/interfaces/IExtractor.sol +17 -0
- package/packages/policy-management/src/interfaces/IMapper.sol +17 -0
- package/packages/policy-management/src/interfaces/IPolicy.sol +61 -0
- package/packages/policy-management/src/interfaces/IPolicyEngine.sol +264 -0
- package/packages/policy-management/src/interfaces/IPolicyProtected.sol +48 -0
- package/packages/policy-management/src/policies/AllowPolicy.sol +104 -0
- package/packages/policy-management/src/policies/BypassPolicy.sol +90 -0
- package/packages/policy-management/src/policies/IntervalPolicy.sol +223 -0
- package/packages/policy-management/src/policies/MaxPolicy.sol +73 -0
- package/packages/policy-management/src/policies/OnlyAuthorizedSenderPolicy.sol +84 -0
- package/packages/policy-management/src/policies/OnlyOwnerPolicy.sol +35 -0
- package/packages/policy-management/src/policies/PausePolicy.sol +82 -0
- package/packages/policy-management/src/policies/README.md +632 -0
- package/packages/policy-management/src/policies/RejectPolicy.sol +89 -0
- package/packages/policy-management/src/policies/RoleBasedAccessControlPolicy.sol +162 -0
- package/packages/policy-management/src/policies/SecureMintPolicy.sol +271 -0
- package/packages/policy-management/src/policies/VolumePolicy.sol +133 -0
- package/packages/policy-management/src/policies/VolumeRatePolicy.sol +192 -0
- package/packages/policy-management/test/PolicyEngine.t.sol +368 -0
- package/packages/policy-management/test/PolicyFactory.t.sol +114 -0
- package/packages/policy-management/test/PolicyProtectedToken.t.sol +75 -0
- package/packages/policy-management/test/extractors/ComplianceTokenForceTransferExtractor.t.sol +59 -0
- package/packages/policy-management/test/extractors/ComplianceTokenFreezeUnfreezeExtractor.t.sol +74 -0
- package/packages/policy-management/test/extractors/ComplianceTokenMintBurnExtractor.t.sol +92 -0
- package/packages/policy-management/test/extractors/ERC20ApproveExtractor.t.sol +58 -0
- package/packages/policy-management/test/extractors/ERC3643ForcedTransferExtractor.t.sol +59 -0
- package/packages/policy-management/test/extractors/ERC3643FreezeUnfreezeExtractor.t.sol +74 -0
- package/packages/policy-management/test/extractors/ERC3643MintBurnExtractor.t.sol +73 -0
- package/packages/policy-management/test/extractors/ERC3643SetAddressFrozenExtractor.t.sol +56 -0
- package/packages/policy-management/test/helpers/BaseProxyTest.sol +75 -0
- package/packages/policy-management/test/helpers/CustomMapper.sol +26 -0
- package/packages/policy-management/test/helpers/DummyExtractor.sol +11 -0
- package/packages/policy-management/test/helpers/ExpectedParameterPolicy.sol +39 -0
- package/packages/policy-management/test/helpers/MockAggregatorV3.sol +51 -0
- package/packages/policy-management/test/helpers/MockToken.sol +66 -0
- package/packages/policy-management/test/helpers/MockTokenExtractor.sol +34 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysAllowed.sol +45 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysContinue.sol +23 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysRejected.sol +23 -0
- package/packages/policy-management/test/helpers/PolicyFailingRun.sol +22 -0
- package/packages/policy-management/test/policies/AllowPolicy.t.sol +174 -0
- package/packages/policy-management/test/policies/BypassPolicy.t.sol +159 -0
- package/packages/policy-management/test/policies/IntervalPolicy.t.sol +307 -0
- package/packages/policy-management/test/policies/MaxPolicy.t.sol +54 -0
- package/packages/policy-management/test/policies/OnlyAuthorizedSenderPolicy.t.sol +95 -0
- package/packages/policy-management/test/policies/OnlyOwnerPolicy.t.sol +47 -0
- package/packages/policy-management/test/policies/PausePolicy.t.sol +75 -0
- package/packages/policy-management/test/policies/RejectPolicy.t.sol +182 -0
- package/packages/policy-management/test/policies/RoleBasedAccessControlPolicy.t.sol +223 -0
- package/packages/policy-management/test/policies/SecureMintPolicy.t.sol +442 -0
- package/packages/policy-management/test/policies/VolumePolicy.t.sol +158 -0
- package/packages/policy-management/test/policies/VolumeRatePolicy.t.sol +165 -0
- package/packages/tokens/erc-20/src/ComplianceTokenERC20.sol +345 -0
- package/packages/tokens/erc-20/src/ComplianceTokenStoreERC20.sol +29 -0
- package/packages/tokens/erc-20/test/ComplianceTokenERC20.t.sol +556 -0
- package/packages/tokens/erc-20/test/helpers/BaseProxyTest.sol +75 -0
- package/packages/tokens/erc-3643/README.md +24 -0
- package/packages/tokens/erc-3643/src/ComplianceTokenERC3643.sol +564 -0
- package/packages/tokens/erc-3643/src/ComplianceTokenStoreERC3643.sol +30 -0
- package/packages/tokens/erc-3643/test/ComplianceTokenERC3643.t.sol +815 -0
- package/packages/tokens/erc-3643/test/helpers/BaseProxyTest.sol +76 -0
- package/packages/tokens/erc-3643/test/helpers/ExpectedContextPolicy.sol +32 -0
- package/packages/vendor/erc-3643/compliance/modular/IModularCompliance.sol +220 -0
- package/packages/vendor/erc-3643/registry/interface/IClaimTopicsRegistry.sol +101 -0
- package/packages/vendor/erc-3643/registry/interface/IIdentityRegistry.sol +251 -0
- package/packages/vendor/erc-3643/registry/interface/IIdentityRegistryStorage.sol +191 -0
- package/packages/vendor/erc-3643/registry/interface/ITrustedIssuersRegistry.sol +161 -0
- package/packages/vendor/erc-3643/token/IToken.sol +457 -0
- package/packages/vendor/onchain-id/interface/IClaimIssuer.sol +53 -0
- package/packages/vendor/onchain-id/interface/IERC734.sol +110 -0
- package/packages/vendor/onchain-id/interface/IERC735.sol +105 -0
- package/packages/vendor/onchain-id/interface/IIdentity.sol +26 -0
- package/packages/vendor/onchain-id/interface/IImplementationAuthority.sol +21 -0
- package/remappings.txt +6 -0
- package/script/DeployComplianceTokenERC20.s.sol +191 -0
- package/script/DeployComplianceTokenERC3643.s.sol +208 -0
- package/script/DeploySimpleComplianceToken.s.sol +38 -0
- package/script/getting_started/DeployGettingStarted.s.sol +74 -0
- package/script/getting_started/advanced/DeployAdvancedGettingStarted.s.sol +332 -0
- package/script/getting_started/advanced/DeploySanctionsList.s.sol +26 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title IPolicyEngine
|
|
6
|
+
* @dev Interface for the policy engine.
|
|
7
|
+
*/
|
|
8
|
+
interface IPolicyEngine {
|
|
9
|
+
/// @notice Error emitted when the target is not attached to the policy engine.
|
|
10
|
+
error TargetNotAttached(address target);
|
|
11
|
+
/// @notice Error emitted when the target is already attached to the policy engine.
|
|
12
|
+
error TargetAlreadyAttached(address target);
|
|
13
|
+
/// @notice Error emitted when the policy engine is missing or not present.
|
|
14
|
+
error PolicyEngineUndefined();
|
|
15
|
+
/// @notice Error emitted when the PolicyEngine run has been rejected by one of the polices.
|
|
16
|
+
error PolicyRunRejected(bytes4 selector, address policy, string rejectReason);
|
|
17
|
+
/// @notice Error emitted when a policy mapper results in an error.
|
|
18
|
+
error PolicyMapperError(address policy, bytes errorReason);
|
|
19
|
+
/// @notice Error emitted when an individual policy is rejecting a transaction.
|
|
20
|
+
error PolicyRejected(string rejectReason);
|
|
21
|
+
/// @notice Error emitted when the PolicyEngine run encounters an error while executing one of the policies.
|
|
22
|
+
error PolicyRunError(bytes4 selector, address policy, bytes errorReason);
|
|
23
|
+
/// @notice Error emitted when a policy run is unauthorized.
|
|
24
|
+
error PolicyRunUnauthorizedError(address account);
|
|
25
|
+
/// @notice Error emitted when a policy postRun results in an error.
|
|
26
|
+
error PolicyPostRunError(bytes4 selector, address policy, bytes errorReason);
|
|
27
|
+
/// @notice Error emitted when a policy extractor is run with an unsupported selector.
|
|
28
|
+
error UnsupportedSelector(bytes4 selector);
|
|
29
|
+
/// @notice Error emitted when a configuration is invalid.
|
|
30
|
+
error InvalidConfiguration(string errorReason);
|
|
31
|
+
/// @notice Error emitted when an extraction of parameters results in an error.
|
|
32
|
+
error ExtractorError(bytes4 selector, address extractor, bytes errorReason);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @notice Emitted when a target contract has attached to the policy engine.
|
|
36
|
+
* @param target The target contract.
|
|
37
|
+
*/
|
|
38
|
+
event TargetAttached(address indexed target);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @notice Emitted when a target contract has detached from the policy engine.
|
|
42
|
+
* @param target The target contract.
|
|
43
|
+
*/
|
|
44
|
+
event TargetDetached(address indexed target);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @notice Emitted when a policy engine run has completed successfully.
|
|
48
|
+
* @param sender The sender of the transaction.
|
|
49
|
+
* @param target The target contract that invoked the method.
|
|
50
|
+
* @param selector The selector of the method invoked on the target.
|
|
51
|
+
*/
|
|
52
|
+
event PolicyRunComplete(address indexed sender, address indexed target, bytes4 indexed selector);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @notice Emitted when a policy is added to the policy engine.
|
|
56
|
+
* @param target The address of the target contract for which the policy was configured.
|
|
57
|
+
* @param selector The selector of the policy.
|
|
58
|
+
* @param policy The policy address.
|
|
59
|
+
*/
|
|
60
|
+
event PolicyAdded(address indexed target, bytes4 indexed selector, address policy);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @notice Emitted when a policy is removed from the policy engine.
|
|
64
|
+
* param target The address of the target contract for which the policy was configured.
|
|
65
|
+
* @param selector The selector of the policy.
|
|
66
|
+
* @param policy The policy address.
|
|
67
|
+
*/
|
|
68
|
+
event PolicyRemoved(address indexed target, bytes4 indexed selector, address policy);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @notice Emitted when an extractor is set for a selector.
|
|
72
|
+
* @param selector The selector.
|
|
73
|
+
* @param extractor The extractor address.
|
|
74
|
+
*/
|
|
75
|
+
event ExtractorSet(bytes4 indexed selector, address indexed extractor);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @notice Emitted when policy parameters are set for a policy.
|
|
79
|
+
* @param policy The policy address.
|
|
80
|
+
* @param parameters The parameters for the policy.
|
|
81
|
+
*/
|
|
82
|
+
event PolicyParametersSet(address indexed policy, bytes[] parameters);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @notice Emitted when the default policy action rule is set for the policy engine.
|
|
86
|
+
* @param defaultAllow Indicates whether to allow or reject a transaction if no policy explicitly returns an Allow
|
|
87
|
+
* or a Reject. True to allow, false to reject.
|
|
88
|
+
*/
|
|
89
|
+
event DefaultPolicyAllowSet(bool defaultAllow);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @notice Emitted when the default policy allow rule for a target is set.
|
|
93
|
+
* @param target The target contract.
|
|
94
|
+
* @param defaultAllow Indicates whether to allow or reject a transaction if no policy explicitly returns an Allow
|
|
95
|
+
* or a Reject. True to allow, false to reject.
|
|
96
|
+
*/
|
|
97
|
+
event TargetDefaultPolicyAllowSet(address indexed target, bool defaultAllow);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @notice The PolicyResult enum represents the possible types of success results of a policy run. When a policy
|
|
101
|
+
* should reject a transaction, it MUST revert using the `PolicyReject` error with a descriptive reject message.
|
|
102
|
+
* @param None No specific policy result, typically used as a default or uninitialized state.
|
|
103
|
+
* @param Allowed The policy allowed the run.
|
|
104
|
+
* @param Continue The policy did not reject the run and processing should continue to the next policy.
|
|
105
|
+
*/
|
|
106
|
+
enum PolicyResult {
|
|
107
|
+
None,
|
|
108
|
+
Allowed,
|
|
109
|
+
Continue
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @notice The Payload struct combines the components on which policies operate.
|
|
114
|
+
* @param selector The selector of the method being invoked on the target.
|
|
115
|
+
* @param sender The sender of the transaction.
|
|
116
|
+
* @param data The original calldata of the invoked transaction.
|
|
117
|
+
* @param context Additional information or authorization to perform the operation.
|
|
118
|
+
*/
|
|
119
|
+
struct Payload {
|
|
120
|
+
bytes4 selector;
|
|
121
|
+
address sender;
|
|
122
|
+
bytes data;
|
|
123
|
+
bytes context;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @notice The Parameter struct contains the data of the parameters sent to policies.
|
|
128
|
+
* @param name The name of the parameter.
|
|
129
|
+
* @param value The value of the parameter.
|
|
130
|
+
*/
|
|
131
|
+
struct Parameter {
|
|
132
|
+
bytes32 name;
|
|
133
|
+
bytes value;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @notice Attaches the calling contract to the policy engine.
|
|
138
|
+
*/
|
|
139
|
+
function attach() external;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @notice Detaches the calling contract from the policy engine.
|
|
143
|
+
*/
|
|
144
|
+
function detach() external;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @notice Assigns an extractor to the specified selector, enabling policies to utilize it for parameter extraction.
|
|
148
|
+
* @param selector The selector of the policy.
|
|
149
|
+
* @param extractor The extractor address.
|
|
150
|
+
*/
|
|
151
|
+
function setExtractor(bytes4 selector, address extractor) external;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @notice Assigns an extractor to the specified selectors, enabling policies to utilize it for parameter extraction.
|
|
155
|
+
* @param selectors The selectors of the policies.
|
|
156
|
+
* @param extractor The extractor address.
|
|
157
|
+
*/
|
|
158
|
+
function setExtractors(bytes4[] calldata selectors, address extractor) external;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @notice Gets the extractor for a given selector.
|
|
162
|
+
* @param selector The selector.
|
|
163
|
+
* @return The extractor for the selector.
|
|
164
|
+
*/
|
|
165
|
+
function getExtractor(bytes4 selector) external view returns (address);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @notice Sets the custom policy parameter mapper for a policy.
|
|
169
|
+
* @param policy The policy address.
|
|
170
|
+
* @param mapper The mapper address, address(0) to use the default mapper.
|
|
171
|
+
*/
|
|
172
|
+
function setPolicyMapper(address policy, address mapper) external;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @notice Gets the policy parameter mapper for a given policy.
|
|
176
|
+
* @param policy The policy address.
|
|
177
|
+
* @return The custom policy parameter mapper for the policy, address(0) if the policy uses the default mapper.
|
|
178
|
+
*/
|
|
179
|
+
function getPolicyMapper(address policy) external view returns (address);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @notice Adds a policy to the policy engine.
|
|
183
|
+
*
|
|
184
|
+
* - Policy MUST be added to the end of the current policy list.
|
|
185
|
+
*
|
|
186
|
+
* @param target The address of the target contract for which the policy apply.
|
|
187
|
+
* @param selector The selector of the policy.
|
|
188
|
+
* @param policy The policy address.
|
|
189
|
+
* @param policyParameterNames The parameter names for the policy.
|
|
190
|
+
*/
|
|
191
|
+
function addPolicy(address target, bytes4 selector, address policy, bytes32[] calldata policyParameterNames) external;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @notice Adds a policy to the policy engine at a specific position.
|
|
195
|
+
*
|
|
196
|
+
* @param target The address of the target contract for which the policy apply.
|
|
197
|
+
* @param selector The selector of the policy.
|
|
198
|
+
* @param policy The policy address.
|
|
199
|
+
* @param policyParameterNames The parameter names for the policy.
|
|
200
|
+
* @param position The position to add the policy at.
|
|
201
|
+
*/
|
|
202
|
+
function addPolicyAt(
|
|
203
|
+
address target,
|
|
204
|
+
bytes4 selector,
|
|
205
|
+
address policy,
|
|
206
|
+
bytes32[] calldata policyParameterNames,
|
|
207
|
+
uint256 position
|
|
208
|
+
)
|
|
209
|
+
external;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @notice Removes a policy from the policy engine.
|
|
213
|
+
* @param target The address of the target contract for which the policy was configured.
|
|
214
|
+
* @param selector The selector of the policy.
|
|
215
|
+
* @param policy The policy address.
|
|
216
|
+
*/
|
|
217
|
+
function removePolicy(address target, bytes4 selector, address policy) external;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @notice Gets the policies for a given selector and target.
|
|
221
|
+
*
|
|
222
|
+
* - MUST return the policies in the order they will execute.
|
|
223
|
+
* - MUST return an empty array if no policies are found.
|
|
224
|
+
*
|
|
225
|
+
* @param selector The selector of the policy.
|
|
226
|
+
* @param target The address of the target contract for which the policies are configured.
|
|
227
|
+
* @return The policies for the selector and target.
|
|
228
|
+
*/
|
|
229
|
+
function getPolicies(address target, bytes4 selector) external view returns (address[] memory);
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @notice Sets whether to allow or reject the transaction if no policy explicitly returns an Allow or a Reject.
|
|
233
|
+
* @param defaultAllow Indicates whether to allow or reject a transaction if no policy explicitly returns an Allow
|
|
234
|
+
* or a Reject. True to allow, false to reject.
|
|
235
|
+
*/
|
|
236
|
+
function setDefaultPolicyAllow(bool defaultAllow) external;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @notice Sets whether to allow or reject the transaction if no policy explicitly returns an Allow or a Reject
|
|
240
|
+
* for a specific target.
|
|
241
|
+
* @param target The address of the target contract.
|
|
242
|
+
* @param defaultAllow Indicates whether to allow or reject a transaction if no policy explicitly returns an Allow
|
|
243
|
+
* or a Reject. True to allow, false to reject.
|
|
244
|
+
*/
|
|
245
|
+
function setTargetDefaultPolicyAllow(address target, bool defaultAllow) external;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @notice Runs the policies for a given payload for offchain pre-validation. MUST revert on policy rejection/failure.
|
|
249
|
+
* @param payload The payload to run the policies on.
|
|
250
|
+
*/
|
|
251
|
+
function check(Payload calldata payload) external view;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @notice Runs the policies for a given operation payload.
|
|
255
|
+
*
|
|
256
|
+
* - MUST revert on policy rejection/failure.
|
|
257
|
+
* - MUST revert if the target contract that invoked the method is not allowed. Target contract address is
|
|
258
|
+
* obtained from the msg.sender global variable.
|
|
259
|
+
* - MUST execute policies in the order they were added or that were specified using `addPolicyAt`.
|
|
260
|
+
*
|
|
261
|
+
* @param payload The payload to run the policies on.
|
|
262
|
+
*/
|
|
263
|
+
function run(Payload calldata payload) external;
|
|
264
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title IPolicyProtected
|
|
8
|
+
* @dev Interface for attaching a policy engine to a smart contract.
|
|
9
|
+
*/
|
|
10
|
+
interface IPolicyProtected is IERC165 {
|
|
11
|
+
/**
|
|
12
|
+
* @notice Emitted when a policy engine is attached to the contract.
|
|
13
|
+
* @param policyEngine The policy engine attached.
|
|
14
|
+
*/
|
|
15
|
+
event PolicyEngineAttached(address indexed policyEngine);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @notice Attaches a policy engine to the current contract.
|
|
19
|
+
* @param policyEngine The policy engine to attach.
|
|
20
|
+
*/
|
|
21
|
+
function attachPolicyEngine(address policyEngine) external;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @notice Gets the policy engine attached to the current contract.
|
|
25
|
+
* @return The policy engine attached to the contract.
|
|
26
|
+
*/
|
|
27
|
+
function getPolicyEngine() external view returns (address);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @notice Sets the context for the current transaction.
|
|
31
|
+
* @dev WARNING: The context is stored per sender and is not automatically linked to a specific transaction or
|
|
32
|
+
* function call. Ensure that context is set and consumed atomically and that race conditions or reentrancy do not
|
|
33
|
+
* result in stale or mismatched context usage.
|
|
34
|
+
* @param context The context to set.
|
|
35
|
+
*/
|
|
36
|
+
function setContext(bytes calldata context) external;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @notice Gets the context for the current transaction.
|
|
40
|
+
* @return The context for the transaction.
|
|
41
|
+
*/
|
|
42
|
+
function getContext() external view returns (bytes memory);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @notice Clears the context for the current transaction.
|
|
46
|
+
*/
|
|
47
|
+
function clearContext() external;
|
|
48
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
5
|
+
import {Policy} from "@chainlink/policy-management/core/Policy.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title AllowPolicy
|
|
9
|
+
* @notice A policy that permits method calls if all of the addresses are on an allowlist.
|
|
10
|
+
*/
|
|
11
|
+
contract AllowPolicy is Policy {
|
|
12
|
+
/**
|
|
13
|
+
* @notice Emitted when an address is added to the allow list.
|
|
14
|
+
* @param account The address that was added to the allow list.
|
|
15
|
+
*/
|
|
16
|
+
event AddressAllowed(address indexed account);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @notice Emitted when an address is removed from the allow list.
|
|
20
|
+
* @param account The address that was removed from the allow list.
|
|
21
|
+
*/
|
|
22
|
+
event AddressDisallowed(address indexed account);
|
|
23
|
+
|
|
24
|
+
/// @custom:storage-location erc7201:policy-management.AllowPolicy
|
|
25
|
+
struct AllowPolicyStorage {
|
|
26
|
+
/// @notice If the address is not on this list, method calls will always be rejected.
|
|
27
|
+
mapping(address account => bool isAllowed) allowList;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// keccak256(abi.encode(uint256(keccak256("policy-management.AllowPolicy")) - 1)) & ~bytes32(uint256(0xff))
|
|
31
|
+
bytes32 private constant AllowPolicyStorageLocation =
|
|
32
|
+
0x765cab6c47f7237f7aa9342433ee5465ec3e83a263328a78226aaa7d8727a800;
|
|
33
|
+
|
|
34
|
+
function _getAllowPolicyStorage() private pure returns (AllowPolicyStorage storage $) {
|
|
35
|
+
assembly {
|
|
36
|
+
$.slot := AllowPolicyStorageLocation
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @notice Adds the account to the allow list.
|
|
42
|
+
* @dev Throws if the account is already in the allow list.
|
|
43
|
+
* @param account The address to add to the allow list.
|
|
44
|
+
*/
|
|
45
|
+
function allowAddress(address account) public onlyOwner {
|
|
46
|
+
AllowPolicyStorage storage $ = _getAllowPolicyStorage();
|
|
47
|
+
require(!$.allowList[account], "Account already in allow list");
|
|
48
|
+
$.allowList[account] = true;
|
|
49
|
+
emit AddressAllowed(account);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @notice Removes the account from the allow list.
|
|
54
|
+
* @dev Throws if the account is not in the allow list.
|
|
55
|
+
* @param account The address to remove from the allow list.
|
|
56
|
+
*/
|
|
57
|
+
function disallowAddress(address account) public onlyOwner {
|
|
58
|
+
AllowPolicyStorage storage $ = _getAllowPolicyStorage();
|
|
59
|
+
require($.allowList[account], "Account not in allow list");
|
|
60
|
+
$.allowList[account] = false;
|
|
61
|
+
emit AddressDisallowed(account);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @notice Checks if the account is on the allow list.
|
|
66
|
+
* @param account The address to check.
|
|
67
|
+
* @return addressAllowed if the account is on the allow list, false otherwise.
|
|
68
|
+
*/
|
|
69
|
+
function addressAllowed(address account) public view returns (bool) {
|
|
70
|
+
return _getAllowPolicyStorage().allowList[account];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @notice Function to be called by the policy engine to check if execution is allowed.
|
|
75
|
+
* @param parameters encoded policy parameters.
|
|
76
|
+
* [account(address),...] List of addresses to check for present on the allow list.
|
|
77
|
+
* @return result The result of the policy check.
|
|
78
|
+
*/
|
|
79
|
+
function run(
|
|
80
|
+
address, /*caller*/
|
|
81
|
+
address, /*subject*/
|
|
82
|
+
bytes4, /*selector*/
|
|
83
|
+
bytes[] calldata parameters, /*parameters*/
|
|
84
|
+
bytes calldata /*context*/
|
|
85
|
+
)
|
|
86
|
+
public
|
|
87
|
+
view
|
|
88
|
+
override
|
|
89
|
+
returns (IPolicyEngine.PolicyResult)
|
|
90
|
+
{
|
|
91
|
+
require(parameters.length >= 1, "expected at least 1 parameter");
|
|
92
|
+
|
|
93
|
+
// Gas optimization: Load storage reference once instead of calling _getAllowPolicyStorage() in each iteration
|
|
94
|
+
AllowPolicyStorage storage $ = _getAllowPolicyStorage();
|
|
95
|
+
|
|
96
|
+
for (uint256 i = 0; i < parameters.length; i++) {
|
|
97
|
+
address account = abi.decode(parameters[i], (address));
|
|
98
|
+
if (!$.allowList[account]) {
|
|
99
|
+
revert IPolicyEngine.PolicyRejected("address is not on allow list");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return IPolicyEngine.PolicyResult.Continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
5
|
+
import {Policy} from "@chainlink/policy-management/core/Policy.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title BypassPolicy
|
|
9
|
+
* @notice A policy that permits method calls if all of the addresses are on an allowlist, overriding and bypassing any
|
|
10
|
+
* subsequent policies in the chain.
|
|
11
|
+
*/
|
|
12
|
+
contract BypassPolicy is Policy {
|
|
13
|
+
/// @custom:storage-location erc7201:policy-management.BypassPolicy
|
|
14
|
+
struct BypassPolicyStorage {
|
|
15
|
+
/// @notice If the address is on this list, method calls will always be allowed.
|
|
16
|
+
mapping(address account => bool isAllowed) allowList;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// keccak256(abi.encode(uint256(keccak256("policy-management.BypassPolicy")) - 1)) & ~bytes32(uint256(0xff))
|
|
20
|
+
bytes32 private constant BypassPolicyStorageLocation =
|
|
21
|
+
0x58a84146d7d8a792905a46c0c78d69c71c1cf7909b1068f119d17e740a8cb600;
|
|
22
|
+
|
|
23
|
+
function _getBypassPolicyStorage() private pure returns (BypassPolicyStorage storage $) {
|
|
24
|
+
assembly {
|
|
25
|
+
$.slot := BypassPolicyStorageLocation
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @notice Adds the account to the bypass list.
|
|
31
|
+
* @dev Throws if the account is already in the bypass list.
|
|
32
|
+
* @param account The address to add to the bypass list.
|
|
33
|
+
*/
|
|
34
|
+
function allowAddress(address account) public onlyOwner {
|
|
35
|
+
BypassPolicyStorage storage $ = _getBypassPolicyStorage();
|
|
36
|
+
require(!$.allowList[account], "Account already in bypass list");
|
|
37
|
+
$.allowList[account] = true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @notice Removes the account from the bypass list.
|
|
42
|
+
* @dev Throws if the account is not in the bypass list.
|
|
43
|
+
* @param account The address to remove from the bypass list.
|
|
44
|
+
*/
|
|
45
|
+
function disallowAddress(address account) public onlyOwner {
|
|
46
|
+
BypassPolicyStorage storage $ = _getBypassPolicyStorage();
|
|
47
|
+
require($.allowList[account], "Account not in bypass list");
|
|
48
|
+
$.allowList[account] = false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @notice Checks if the account is on the bypass list.
|
|
53
|
+
* @param account The address to check.
|
|
54
|
+
* @return addressAllowed if the account is on the bypass list, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
function addressAllowed(address account) public view returns (bool) {
|
|
57
|
+
BypassPolicyStorage storage $ = _getBypassPolicyStorage();
|
|
58
|
+
return $.allowList[account];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @notice Function to be called by the policy engine to check if execution is allowed.
|
|
63
|
+
* @param parameters encoded policy parameters.
|
|
64
|
+
* [account(address),...] List of addresses to check for present on the bypass list.
|
|
65
|
+
* @return result The result of the policy check.
|
|
66
|
+
*/
|
|
67
|
+
function run(
|
|
68
|
+
address, /*caller*/
|
|
69
|
+
address, /*subject*/
|
|
70
|
+
bytes4, /*selector*/
|
|
71
|
+
bytes[] calldata parameters, /*parameters*/
|
|
72
|
+
bytes calldata /*context*/
|
|
73
|
+
)
|
|
74
|
+
public
|
|
75
|
+
view
|
|
76
|
+
override
|
|
77
|
+
returns (IPolicyEngine.PolicyResult)
|
|
78
|
+
{
|
|
79
|
+
require(parameters.length >= 1, "expected at least 1 parameter");
|
|
80
|
+
// Gas optimization: load storage reference once
|
|
81
|
+
BypassPolicyStorage storage $ = _getBypassPolicyStorage();
|
|
82
|
+
for (uint256 i = 0; i < parameters.length; i++) {
|
|
83
|
+
address account = abi.decode(parameters[i], (address));
|
|
84
|
+
if (!$.allowList[account]) {
|
|
85
|
+
return IPolicyEngine.PolicyResult.Continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return IPolicyEngine.PolicyResult.Allowed;
|
|
89
|
+
}
|
|
90
|
+
}
|