Skip to content

Commit f9a2a22

Browse files
committed
Clean up
1 parent 762d8e2 commit f9a2a22

28 files changed

Lines changed: 252 additions & 263 deletions

src/RuleEngine.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {ERC3643Compliance, IERC3643Compliance} from "./modules/ERC3643Compliance
1313
import {RuleEngineOperation} from "./modules/RuleEngineOperation.sol";
1414
import {RuleEngineValidationRead, RuleEngineValidation} from "./modules/RuleEngineValidationRead.sol";
1515
import {IRuleValidation} from "./interfaces/IRuleValidation.sol";
16+
import {RuleEngineInvariantStorage} from "./modules/library/RuleEngineInvariantStorage.sol";
1617
/**
1718
* @title Implementation of a ruleEngine as defined by the CMTAT
1819
*/
@@ -21,7 +22,8 @@ contract RuleEngine is
2122
RuleEngineOperation,
2223
RuleEngineValidationRead,
2324
MetaTxModuleStandalone,
24-
ERC3643Compliance
25+
ERC3643Compliance,
26+
RuleEngineInvariantStorage
2527
{
2628

2729
/**
Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,68 @@
11
//SPDX-License-Identifier: MPL-2.0
22

33
pragma solidity ^0.8.20;
4-
4+
import {IRuleOperation} from "./IRuleOperation.sol";
55
interface IRuleEngineOperation {
66
/**
7-
* @dev define the rules, the precedent rules will be overwritten
7+
* @notice Defines the operation rules for the rule engine.
8+
* @dev Sets the list of rule contract addresses for operations.
9+
* Any previously set rules will be completely overwritten by the new list.
10+
* Rules should be deployed contracts that implement the expected interface.
11+
* @param rules_ The array of addresses representing the new rules to be set.
12+
* @dev Revert if one rule is a zero address or if the rule is already present
813
*/
9-
function setRulesOperation(address[] calldata rules_) external;
14+
function setRulesOperation(IRuleOperation[] calldata rules_) external;
1015

1116
/**
12-
* @dev return the number of rules
17+
* @notice Returns the number of rules currently set for operations.
18+
* @dev The count corresponds to the total number of elements in the rules array.
19+
* @return The number of operation rules.
1320
*/
1421
function rulesCountOperation() external view returns (uint256);
1522

1623
/**
17-
* @dev return the rule at the index specified by ruleId
24+
* @notice Retrieves the rule address at a specific index.
25+
* @dev The index corresponds to the position in the rules array.
26+
* Reverts if `ruleId` is out of bounds.
27+
* @param ruleId The index of the rule to retrieve.
28+
* @return The address of the rule contract.
1829
*/
1930
function ruleOperation(uint256 ruleId) external view returns (address);
2031

2132
/**
22-
* @dev return all the rules
33+
* @notice Returns the full list of operation rules.
34+
* @dev This is a view-only function that returns all the currently stored rule addresses.
35+
* @return An array containing all the rule contract addresses.
2336
*/
2437
function rulesOperation() external view returns (address[] memory);
38+
39+
40+
/**
41+
* @notice Clear all the rules of the array of rules
42+
*
43+
*/
44+
function clearRulesOperation() external;
45+
46+
/**
47+
* @notice Add a rule to the array of rules
48+
* Revert if one rule is a zero address or if the rule is already present
49+
*
50+
*/
51+
function addRuleOperation(
52+
IRuleOperation rule_
53+
) external;
54+
55+
56+
/**
57+
* @notice Remove a rule from the array of rules
58+
* Revert if the rule found at the specified index does not match the rule in argument
59+
* @param rule_ address of the target rule
60+
* @dev To reduce the array size, the last rule is moved to the location occupied
61+
* by the rule to remove
62+
*
63+
*
64+
*/
65+
function removeRuleOperation(
66+
IRuleOperation rule_
67+
) external;
2568
}

src/interfaces/IRuleEngineValidation.sol

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pragma solidity ^0.8.20;
44

5+
import {IRuleValidation} from "./IRuleValidation.sol";
56
interface IRuleEngineValidationRead {
67
/**
78
* @dev See ERC-1404
@@ -35,20 +36,57 @@ interface IRuleEngineValidation {
3536
/**
3637
* @dev define the rules, the precedent rules will be overwritten
3738
*/
38-
function setRulesValidation(address[] calldata rules_) external;
39+
function setRulesValidation(IRuleValidation[] calldata rules_) external;
3940

40-
/**
41-
* @dev return the number of rules
41+
/**
42+
* @return The number of rules inside the array
4243
*/
4344
function rulesCountValidation() external view returns (uint256);
4445

45-
/**
46-
* @dev return the rule at the index specified by ruleId
46+
/**
47+
* @notice Get the rule at the position specified by ruleId
48+
* @param ruleId index of the rule
49+
* @return a rule address
4750
*/
4851
function ruleValidation(uint256 ruleId) external view returns (address);
4952

5053
/**
51-
* @dev return all the rules
54+
* @notice Get all the rules
55+
* @return An array of rules
5256
*/
5357
function rulesValidation() external view returns (address[] memory);
58+
59+
/**
60+
* @notice Remove a rule from the array of rules
61+
* Revert if the rule found at the specified index does not match the rule in argument
62+
* @param rule_ address of the target rule
63+
* @dev To reduce the array size, the last rule is moved to the location occupied
64+
* by the rule to remove
65+
*
66+
*
67+
*/
68+
function removeRuleValidation(
69+
IRuleValidation rule_
70+
) external;
71+
72+
/**
73+
* @notice Clear all the rules of the array of rules
74+
*
75+
*/
76+
function clearRulesValidation() external;
77+
78+
/**
79+
* @notice Add a rule to the array of rules
80+
* @dev Revert if one rule is a zero address or if the rule is already present
81+
*
82+
*/
83+
function addRuleValidation(
84+
IRuleValidation rule_
85+
) external;
86+
87+
/**
88+
* @notice Check if a rule is present
89+
*
90+
*/
91+
function rulesValidationIsPresent(IRuleValidation rule_) external returns (bool);
5492
}

src/interfaces/IRuleOperation.sol

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
pragma solidity ^0.8.20;
44

5-
interface IRuleOperation {
6-
/**
7-
* @dev Returns true if the transfer is valid, and false otherwise.
8-
*/
9-
function transferred(
10-
address from,
11-
address to,
12-
uint256 value
13-
) external;
5+
import {IERC3643IComplianceContract} from "CMTAT/interfaces/tokenization/IERC3643Partial.sol";
6+
7+
interface IRuleOperation is IERC3643IComplianceContract {
148
}

src/modules/RuleEngineInvariantStorage.sol

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

src/modules/RuleEngineOperation.sol

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@ import {AccessControl} from "OZ/access/AccessControl.sol";
88
// Other
99
import {IRuleEngineOperation} from "../interfaces/IRuleEngineOperation.sol";
1010
import {IRuleOperation} from "../interfaces/IRuleOperation.sol";
11-
import {RuleEngineInvariantStorage} from "./RuleEngineInvariantStorage.sol";
11+
import {RuleEngineInvariantStorageCommon} from "./library/RuleEngineInvariantStorageCommon.sol";
1212
/**
1313
* @title RuleEngine - Operation part
1414
*/
1515
abstract contract RuleEngineOperation is
1616
AccessControl,
17-
RuleEngineInvariantStorage,
17+
RuleEngineInvariantStorageCommon,
1818
IRuleEngineOperation
1919
{
20-
21-
/// @dev Array of rules
22-
//address[] internal _rulesOperation;
2320
// Add the library methods
2421
using EnumerableSet for EnumerableSet.AddressSet;
2522

23+
/// @notice Generate when a rule is added
24+
event AddRuleOperation(IRuleOperation indexed rule);
25+
/// @notice Generate when a rule is removed
26+
event RemoveRuleOperation(IRuleOperation indexed rule);
27+
/// @notice Generate when all the rules are cleared
28+
event ClearRulesOperation();
29+
30+
2631
// Declare a set state variable
32+
/// @dev Array of rules
2733
EnumerableSet.AddressSet internal _rulesOperation;
2834

2935
/*//////////////////////////////////////////////////////////////
@@ -37,7 +43,7 @@ abstract contract RuleEngineOperation is
3743
*
3844
*/
3945
function setRulesOperation(
40-
address[] calldata rules_
46+
IRuleOperation[] calldata rules_
4147
) public virtual onlyRole(RULE_ENGINE_OPERATOR_ROLE) {
4248
if (rules_.length == 0) {
4349
revert RuleEngine_ArrayIsEmpty();
@@ -48,7 +54,7 @@ abstract contract RuleEngineOperation is
4854
for(uint256 i = 0; i < rules_.length; ++i){
4955
_checkRule(address(rules_[i]));
5056
_rulesOperation.add(address(rules_[i]));
51-
emit AddRule(rules_[i]);
57+
emit AddRuleOperation(rules_[i]);
5258
}
5359

5460
}
@@ -72,7 +78,7 @@ abstract contract RuleEngineOperation is
7278
) public virtual onlyRole(RULE_ENGINE_OPERATOR_ROLE) {
7379
_checkRule(address(rule_));
7480
_rulesOperation.add(address(rule_));
75-
emit AddRule(address(rule_));
81+
emit AddRuleOperation(rule_);
7682
}
7783

7884
/**
@@ -88,7 +94,7 @@ abstract contract RuleEngineOperation is
8894
IRuleOperation rule_
8995
) public virtual onlyRole(RULE_ENGINE_OPERATOR_ROLE) {
9096
require(rulesOperationIsPresent(rule_), RuleEngine_RuleDoNotMatch());
91-
_removeRuleOperation(address(rule_));
97+
_removeRuleOperation(rule_);
9298
}
9399

94100
/* ============ View functions ============ */
@@ -139,7 +145,7 @@ abstract contract RuleEngineOperation is
139145
function _clearRulesOperation() internal virtual {
140146
// we remove the last element first since it is more optimized.
141147

142-
emit ClearRules();
148+
emit ClearRulesOperation();
143149
_rulesOperation.clear();
144150
}
145151

@@ -174,9 +180,9 @@ abstract contract RuleEngineOperation is
174180
*
175181
*
176182
*/
177-
function _removeRuleOperation(address rule_) internal virtual {
178-
_rulesOperation.remove(rule_);
179-
emit RemoveRule(address(rule_));
183+
function _removeRuleOperation(IRuleOperation rule_) internal virtual {
184+
_rulesOperation.remove(address(rule_));
185+
emit RemoveRuleOperation(rule_);
180186
}
181187

182188
function _checkRule(address rule_) internal{

0 commit comments

Comments
 (0)