@@ -5,8 +5,8 @@ pragma solidity ^0.8.20;
55import "CMTAT/interfaces/engine/IRuleEngine.sol " ;
66import "./modules/MetaTxModuleStandalone.sol " ;
77import "./modules/RuleEngineOperation.sol " ;
8- import "./modules/RuleEngineValidation.sol " ;
9-
8+ import {RuleEngineValidation} from "./modules/RuleEngineValidation.sol " ;
9+ import {IRuleValidation} from " ./interfaces/IRuleValidation.sol " ;
1010/**
1111 * @title Implementation of a ruleEngine as defined by the CMTAT
1212 */
@@ -16,6 +16,7 @@ contract RuleEngine is
1616 RuleEngineValidation ,
1717 MetaTxModuleStandalone
1818{
19+
1920 /**
2021 * @notice
2122 * Get the current version of the smart contract
@@ -42,21 +43,21 @@ contract RuleEngine is
4243
4344 /**
4445 * @notice Go through all the rule to know if a restriction exists on the transfer
45- * @param _from the origin address
46- * @param _to the destination address
47- * @param _amount to transfer
46+ * @param from the origin address
47+ * @param to the destination address
48+ * @param value to transfer
4849 * @return The restricion code or REJECTED_CODE_BASE.TRANSFER_OK
4950 **/
5051 function detectTransferRestriction (
51- address _from ,
52- address _to ,
53- uint256 _amount
52+ address from ,
53+ address to ,
54+ uint256 value
5455 ) public view override returns (uint8 ) {
5556 // Validation
5657 uint8 code = RuleEngineValidation.detectTransferRestrictionValidation (
57- _from ,
58- _to ,
59- _amount
58+ from ,
59+ to ,
60+ value
6061 );
6162 if (code != uint8 (REJECTED_CODE_BASE.TRANSFER_OK)) {
6263 return code;
@@ -66,7 +67,36 @@ contract RuleEngine is
6667 uint256 rulesLength = _rulesOperation.length ;
6768 for (uint256 i = 0 ; i < rulesLength; ++ i) {
6869 uint8 restriction = IRuleValidation (_rulesOperation[i])
69- .detectTransferRestriction (_from, _to, _amount);
70+ .detectTransferRestriction (from, to, value);
71+ if (restriction > 0 ) {
72+ return restriction;
73+ }
74+ }
75+
76+ return uint8 (REJECTED_CODE_BASE.TRANSFER_OK);
77+ }
78+
79+ function detectTransferRestrictionFrom (
80+ address spender ,
81+ address from ,
82+ address to ,
83+ uint256 value
84+ ) public view override returns (uint8 ) {
85+ // Validation
86+ uint8 code = RuleEngineValidation.detectTransferRestrictionValidationFrom (spender,
87+ from,
88+ to,
89+ value
90+ );
91+ if (code != uint8 (REJECTED_CODE_BASE.TRANSFER_OK)) {
92+ return code;
93+ }
94+
95+ // Operation
96+ uint256 rulesLength = _rulesOperation.length ;
97+ for (uint256 i = 0 ; i < rulesLength; ++ i) {
98+ uint8 restriction = IRuleValidation (_rulesOperation[i])
99+ .detectTransferRestrictionFrom (spender,from, to, value);
70100 if (restriction > 0 ) {
71101 return restriction;
72102 }
@@ -77,18 +107,36 @@ contract RuleEngine is
77107
78108 /**
79109 * @notice Validate a transfer
80- * @param _from the origin address
81- * @param _to the destination address
82- * @param _amount to transfer
110+ * @param from the origin address
111+ * @param to the destination address
112+ * @param value to transfer
83113 * @return True if the transfer is valid, false otherwise
84114 **/
85- function validateTransfer (
86- address _from ,
87- address _to ,
88- uint256 _amount
115+ function canTransfer (
116+ address from ,
117+ address to ,
118+ uint256 value
89119 ) public view override returns (bool ) {
90120 return
91- detectTransferRestriction (_from, _to, _amount) ==
121+ detectTransferRestriction (from, to, value) ==
122+ uint8 (REJECTED_CODE_BASE.TRANSFER_OK);
123+ }
124+
125+ /**
126+ * @notice Validate a transfer
127+ * @param from the origin address
128+ * @param to the destination address
129+ * @param value to transfer
130+ * @return True if the transfer is valid, false otherwise
131+ **/
132+ function canTransferFrom (
133+ address /*spender*/ ,
134+ address from ,
135+ address to ,
136+ uint256 value
137+ ) public view override returns (bool ) {
138+ return
139+ detectTransferRestriction (from, to, value) ==
92140 uint8 (REJECTED_CODE_BASE.TRANSFER_OK);
93141 }
94142
@@ -130,19 +178,29 @@ contract RuleEngine is
130178 /*
131179 * @notice function protected by access control
132180 */
133- function operateOnTransfer (
181+ function transferred (
182+ address spender ,
134183 address from ,
135184 address to ,
136185 uint256 amount
137- ) external override onlyRole (TOKEN_CONTRACT_ROLE) returns (bool isValid ) {
138- // Validate the transfer
139- if (
140- ! RuleEngineValidation.validateTransferValidation (from, to, amount)
141- ) {
142- return false ;
143- }
186+ ) external override onlyRole (TOKEN_CONTRACT_ROLE) {
187+ // Validate transfer
188+ require (RuleEngineValidation.canTransferValidation (from, to, amount),RuleEngine_InvalidTransfer (from, to, amount));
189+
190+ // Apply operation on RuleEngine
191+ require (RuleEngineOperation._operateOnTransfer (from, to, amount),RuleEngine_InvalidTransfer (from, to, amount));
192+ }
193+
194+ function transferred (
195+ address from ,
196+ address to ,
197+ uint256 amount
198+ ) external override onlyRole (TOKEN_CONTRACT_ROLE) {
199+ // Validate transfer
200+ require (RuleEngineValidation.canTransferValidation (from, to, amount),RuleEngine_InvalidTransfer (from, to, amount));
201+
144202 // Apply operation on RuleEngine
145- return RuleEngineOperation._operateOnTransfer (from, to, amount);
203+ require ( RuleEngineOperation._operateOnTransfer (from, to, amount), RuleEngine_InvalidTransfer (from, to, amount) );
146204 }
147205
148206 /* ============ ACCESS CONTROL ============ */
0 commit comments