Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule engine architecture #250

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/CMTAT_STANDALONE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract CMTAT_STANDALONE is CMTAT_BASE {
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IERC1404Wrapper ruleEngine_,
IRuleEngineCMTAT ruleEngine_,
string memory information_,
uint256 flag_
) MetaTxModule(forwarderIrrevocable) {
Expand Down
17 changes: 17 additions & 0 deletions contracts/interfaces/draft-IERC1404/IRuleEngineCMTAT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;

import "./draft-IERC1404Wrapper.sol";

interface IRuleEngineCMTAT is IERC1404Wrapper {
/**
* @dev Returns true if the operation is a success, and false otherwise.
*/
function operateOnTransfer(
address _from,
address _to,
uint256 _amount
) external returns (bool isValid);

}
10 changes: 10 additions & 0 deletions contracts/mocks/RuleEngine/RuleEngineMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ contract RuleEngineMock is IRuleEngine {
return detectTransferRestriction(_from, _to, _amount) == 0;
}

/*
@dev
Warning: if you want to use this mock, you have to restrict the access to this function through an an access control
*/
function operateOnTransfer( address _from,
address _to,
uint256 _amount) public override returns (bool){
return validateTransfer(_from, _to, _amount);
}

/**
@dev
For all the rules, each restriction code has to be unique.
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/RuleEngine/interfaces/IRuleEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
pragma solidity ^0.8.0;

import "./IRule.sol";
import "../../../interfaces/draft-IERC1404/draft-IERC1404Wrapper.sol";
import "../../../interfaces/draft-IERC1404/IRuleEngineCMTAT.sol";

interface IRuleEngine is IERC1404Wrapper {
interface IRuleEngine is IRuleEngineCMTAT {
/**
* @dev define the rules, the precedent rules will be overwritten
*/
Expand Down
27 changes: 13 additions & 14 deletions contracts/modules/CMTAT_BASE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ abstract contract CMTAT_BASE is
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IERC1404Wrapper ruleEngine_,
string memory information_,
IRuleEngineCMTAT ruleEngine_,
string memory information_,
uint256 flag_
) public initializer {
__CMTAT_init(
Expand Down Expand Up @@ -91,7 +91,7 @@ abstract contract CMTAT_BASE is
uint8 decimalsIrrevocable,
string memory tokenId_,
string memory terms_,
IERC1404Wrapper ruleEngine_,
IRuleEngineCMTAT ruleEngine_,
string memory information_,
uint256 flag_
) internal onlyInitializing {
Expand All @@ -110,9 +110,11 @@ abstract contract CMTAT_BASE is
__Enforcement_init_unchained();
/*
SnapshotModule:
Add this call in case you add the SnapshotModule
Add these two calls in case you add the SnapshotModule

__SnapshotModuleBase_init_unchained();
__ERC20Snapshot_init_unchained();
*/
*/
__Validation_init_unchained(ruleEngine_);

/* Wrapper */
Expand Down Expand Up @@ -174,26 +176,23 @@ abstract contract CMTAT_BASE is

/**
* @dev
* SnapshotModule:
* - override SnapshotModuleInternal if you add the SnapshotModule
* e.g. override(ERC20SnapshotModuleInternal, ERC20Upgradeable)
* - remove the keyword view
*
*/
function _update(
address from,
address to,
uint256 amount
) internal override(ERC20Upgradeable) {
if (!ValidationModule.validateTransfer(from, to, amount)) {
if (!ValidationModule._operateOnTransfer(from, to, amount)) {
revert Errors.CMTAT_InvalidTransfer(from, to, amount);
}
ERC20Upgradeable._update(from, to, amount);
// We call the SnapshotModule only if the transfer is valid
/*
SnapshotModule:
Add this call in case you add the SnapshotModule
ERC20SnapshotModuleInternal._update(from, to, amount);
Add this in case you add the SnapshotModule
We call the SnapshotModule only if the transfer is valid
*/
// ERC20SnapshotModuleInternal._snapshotUpdate(from, to);
ERC20Upgradeable._update(from, to, amount);
}

/**
Expand Down
Loading