Skip to content

Commit 08ce082

Browse files
committed
Update CMTAT (v.3.0.0), RuleEngine library, adapt rules to the new RuleEngine, remove operation rule
1 parent 59701eb commit 08ce082

29 files changed

Lines changed: 166 additions & 3181 deletions

lib/CMTAT

Submodule CMTAT updated 51 files

lib/RuleEngine

Submodule RuleEngine updated 403 files
File renamed without changes.

src/rules/operation/abstract/RuleConditionalTransferInvariantStorage.sol renamed to src/rules/operation/abstract/RuleConditionalTransferInvariantStorageOld

File renamed without changes.

src/rules/operation/abstract/RuleConditionalTransferOperator.sol renamed to src/rules/operation/abstract/RuleConditionalTransferOperatorOld

File renamed without changes.

src/rules/validation/RuleBlacklist.sol

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.8.20;
55
import "./abstract/RuleAddressList/invariantStorage/RuleBlacklistInvariantStorage.sol";
66
import "./abstract/RuleAddressList/RuleAddressList.sol";
77
import "./abstract/RuleValidateTransfer.sol";
8-
8+
//import {IERC1404Extend} from "CMTAT/interfaces/tokenization/draft-IERC1404.sol";
99
/**
1010
* @title a blacklist manager
1111
*/
@@ -15,6 +15,7 @@ contract RuleBlacklist is
1515
RuleAddressList,
1616
RuleBlacklistInvariantStorage
1717
{
18+
1819
/**
1920
* @param admin Address of the contract (Access Control)
2021
* @param forwarderIrrevocable Address of the forwarder, required for the gasless support
@@ -40,7 +41,7 @@ contract RuleBlacklist is
4041
} else if (addressIsListed(to)) {
4142
return CODE_ADDRESS_TO_IS_BLACKLISTED;
4243
} else {
43-
return uint8(REJECTED_CODE_BASE.TRANSFER_OK);
44+
return uint8(IERC1404Extend.REJECTED_CODE_BASE.TRANSFER_OK);
4445
}
4546
}
4647

@@ -91,4 +92,25 @@ contract RuleBlacklist is
9192
return TEXT_CODE_NOT_FOUND;
9293
}
9394
}
95+
96+
function transferred(address from, address to, uint256 value) public view {
97+
uint8 code = this.detectTransferRestriction(from, to, value);
98+
require(
99+
code == uint8(REJECTED_CODE_BASE.TRANSFER_OK),
100+
RuleBlacklist_InvalidTransfer(from, to, value, code)
101+
);
102+
}
103+
104+
function transferred(
105+
address spender,
106+
address from,
107+
address to,
108+
uint256 value
109+
) public view {
110+
uint8 code = this.detectTransferRestrictionFrom(spender, from, to, value);
111+
require(
112+
code == uint8(REJECTED_CODE_BASE.TRANSFER_OK),
113+
RuleBlacklist_InvalidTransfer(from, to, value, code)
114+
);
115+
}
94116
}

src/rules/validation/RuleSanctionList.sol

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "../../modules/MetaTxModuleStandalone.sol";
77
import "./abstract/RuleSanctionListInvariantStorage.sol";
88
import "./abstract/RuleValidateTransfer.sol";
99

10+
1011
interface SanctionsList {
1112
function isSanctioned(address addr) external view returns (bool);
1213
}
@@ -17,6 +18,7 @@ contract RuleSanctionList is
1718
RuleValidateTransfer,
1819
RuleSanctionlistInvariantStorage
1920
{
21+
2022
SanctionsList public sanctionsList;
2123

2224
/**
@@ -49,7 +51,7 @@ contract RuleSanctionList is
4951
}
5052

5153
/**
52-
* @notice Check if an addres is in the whitelist or not
54+
* @notice Check if an addres is in the SanctionsList or not
5355
* @param from the origin address
5456
* @param to the destination address
5557
* @return The restricion code or REJECTED_CODE_BASE.TRANSFER_OK
@@ -119,6 +121,27 @@ contract RuleSanctionList is
119121
}
120122
}
121123

124+
function transferred(address from, address to, uint256 value) public view {
125+
uint8 code = this.detectTransferRestriction(from, to, value);
126+
require(
127+
code == uint8(REJECTED_CODE_BASE.TRANSFER_OK),
128+
RuleSanctionsList_InvalidTransfer(from, to, value, code)
129+
);
130+
}
131+
132+
function transferred(
133+
address spender,
134+
address from,
135+
address to,
136+
uint256 value
137+
) public view {
138+
uint8 code = this.detectTransferRestrictionFrom(spender, from, to, value);
139+
require(
140+
code == uint8(REJECTED_CODE_BASE.TRANSFER_OK),
141+
RuleSanctionsList_InvalidTransfer(from, to, value, code)
142+
);
143+
}
144+
122145
/* ============ ACCESS CONTROL ============ */
123146
/**
124147
* @dev Returns `true` if `account` has been granted `role`.
@@ -130,8 +153,10 @@ contract RuleSanctionList is
130153
// The Default Admin has all roles
131154
if (AccessControl.hasRole(DEFAULT_ADMIN_ROLE, account)) {
132155
return true;
156+
} else{
157+
return AccessControl.hasRole(role, account);
133158
}
134-
return AccessControl.hasRole(role, account);
159+
135160
}
136161

137162
/*//////////////////////////////////////////////////////////////

src/rules/validation/RuleWhitelist.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pragma solidity ^0.8.20;
55
import "./abstract/RuleAddressList/RuleAddressList.sol";
66
import "./abstract/RuleWhitelistCommon.sol";
77

8+
import {IERC1404, IERC1404Extend} from "CMTAT/interfaces/tokenization/draft-IERC1404.sol";
9+
810
/**
911
* @title a whitelist manager
1012
*/
@@ -18,6 +20,8 @@ contract RuleWhitelist is RuleAddressList, RuleWhitelistCommon {
1820
address forwarderIrrevocable
1921
) RuleAddressList(admin, forwarderIrrevocable) {}
2022

23+
24+
2125
/**
2226
* @notice Check if an addres is in the whitelist or not
2327
* @param from the origin address
@@ -44,10 +48,12 @@ contract RuleWhitelist is RuleAddressList, RuleWhitelistCommon {
4448
address to,
4549
uint256 value
4650
) public view override returns (uint8) {
47-
if (addressIsListed(spender)) {
51+
if (!addressIsListed(spender)) {
4852
return CODE_ADDRESS_SPENDER_NOT_WHITELISTED;
4953
} else {
50-
return detectTransferRestriction(from,to,value);
54+
return detectTransferRestriction(from, to, value);
5155
}
5256
}
57+
58+
5359
}

src/rules/validation/RuleWhitelistWrapper.sol

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
pragma solidity ^0.8.20;
44

55
import "OZ/access/AccessControl.sol";
6-
import "RuleEngine/modules/RuleEngineValidationCommon.sol";
76
import "../../modules/MetaTxModuleStandalone.sol";
87
import "./abstract/RuleAddressList/RuleAddressList.sol";
98
import "./abstract/RuleWhitelistCommon.sol";
10-
9+
import {RulesManagementModule} from "RuleEngine/modules/RulesManagementModule.sol";
10+
import {RuleEngineInvariantStorage} from "RuleEngine/modules/library/RuleEngineInvariantStorage.sol";
11+
import {IRule} from "RuleEngine/interfaces/IRule.sol";
1112
/**
1213
* @title Wrapper to call several different whitelist rules
1314
*/
1415
contract RuleWhitelistWrapper is
15-
RuleEngineValidationCommon,
16+
RulesManagementModule,
1617
MetaTxModuleStandalone,
1718
RuleWhitelistCommon
1819
{
@@ -25,7 +26,7 @@ contract RuleWhitelistWrapper is
2526
address forwarderIrrevocable
2627
) MetaTxModuleStandalone(forwarderIrrevocable) {
2728
if (admin == address(0)) {
28-
revert RuleEngine_AdminWithAddressZeroNotAllowed();
29+
revert RuleEngineInvariantStorage.RuleEngine_AdminWithAddressZeroNotAllowed();
2930
}
3031
_grantRole(DEFAULT_ADMIN_ROLE, admin);
3132
}
@@ -46,11 +47,11 @@ contract RuleWhitelistWrapper is
4647
bool[] memory result = new bool[](2);
4748
targetAddress[0] = from;
4849
targetAddress[1] = to;
49-
uint256 rulesLength = _rulesValidation.length;
50+
uint256 rulesLength = rulesCount();
5051
// For each whitelist rule, we ask if from or to are in the whitelist
5152
for (uint256 i = 0; i < rulesLength; ++i) {
5253
// External call
53-
isListed = RuleAddressList(_rulesValidation[i])
54+
isListed = RuleAddressList(rule(i))
5455
.addressIsListedBatch(targetAddress);
5556
if (isListed[0] && !result[0]) {
5657
// Update if from is in the list
@@ -85,11 +86,11 @@ contract RuleWhitelistWrapper is
8586
targetAddress[0] = from;
8687
targetAddress[1] = to;
8788
targetAddress[2] = spender;
88-
uint256 rulesLength = _rulesValidation.length;
89+
uint256 rulesLength = rulesCount();
8990
// For each whitelist rule, we ask if from or to are in the whitelist
9091
for (uint256 i = 0; i < rulesLength; ++i) {
9192
// External call
92-
isListed = RuleAddressList(_rulesValidation[i])
93+
isListed = RuleAddressList(rule(i))
9394
.addressIsListedBatch(targetAddress);
9495
if (isListed[0] && !result[0]) {
9596
// Update if from is in the list
@@ -129,8 +130,10 @@ contract RuleWhitelistWrapper is
129130
// The Default Admin has all roles
130131
if (AccessControl.hasRole(DEFAULT_ADMIN_ROLE, account)) {
131132
return true;
133+
} else {
134+
return AccessControl.hasRole(role, account);
132135
}
133-
return AccessControl.hasRole(role, account);
136+
134137
}
135138

136139
/*//////////////////////////////////////////////////////////////

src/rules/validation/abstract/RuleAddressList/invariantStorage/RuleBlacklistInvariantStorage.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ pragma solidity ^0.8.20;
55
import "../../RuleCommonInvariantStorage.sol";
66

77
abstract contract RuleBlacklistInvariantStorage is RuleCommonInvariantStorage {
8+
error RuleBlacklist_InvalidTransfer(
9+
address from,
10+
address to,
11+
uint256 value,
12+
uint8 code
13+
);
814
/* ============ String message ============ */
915
string constant TEXT_ADDRESS_FROM_IS_BLACKLISTED =
1016
"The sender is blacklisted";

0 commit comments

Comments
 (0)