Skip to content

Commit fcf5d23

Browse files
committed
Add detectTransferRestriction for Spender and Tokenid
1 parent 9df0158 commit fcf5d23

6 files changed

Lines changed: 90 additions & 1 deletion

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//SPDX-License-Identifier: MPL-2.0
2+
3+
pragma solidity ^0.8.20;
4+
5+
/* ==== OpenZeppelin === */
6+
import {AccessControl} from "OZ/access/AccessControl.sol";
7+
8+
abstract contract AccessControlModule is AccessControl {
9+
10+
11+
/* ============ Initializer Function ============ */
12+
/**
13+
* @dev
14+
*
15+
* - The grant to the admin role is done by AccessControlDefaultAdminRules
16+
* - The control of the zero address is done by AccessControlDefaultAdminRules
17+
*
18+
*/
19+
function _AccessControlModule_init(address admin)
20+
internal {
21+
if(admin == address(0)){
22+
//revert CMTAT_AccessControlModule_AddressZeroNotAllowed();
23+
}
24+
// we don't check the return value
25+
// _grantRole attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
26+
// return false only if the admin has already the role
27+
_grantRole(DEFAULT_ADMIN_ROLE, admin);
28+
}
29+
30+
31+
/*//////////////////////////////////////////////////////////////
32+
PUBLIC/EXTERNAL FUNCTIONS
33+
//////////////////////////////////////////////////////////////*/
34+
/**
35+
* @dev Returns `true` if `account` has been granted `role`.
36+
*/
37+
function hasRole(
38+
bytes32 role,
39+
address account
40+
) public view virtual override(AccessControl) returns (bool) {
41+
// The Default Admin has all roles
42+
if (AccessControl.hasRole(DEFAULT_ADMIN_ROLE, account)) {
43+
return true;
44+
} else {
45+
return AccessControl.hasRole(role, account);
46+
}
47+
}
48+
}

src/rules/interfaces/IERC7943NonFungibleCompliance.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ interface IERC7943NonFungibleCompliance {
2121
*/
2222
interface IERC7943NonFungibleComplianceExtend is IERC7943NonFungibleCompliance {
2323
function detectTransferRestriction(address from, address to, uint256 tokenId, uint256 amount ) external view returns(uint8 code);
24-
24+
function detectTransferRestrictionFrom(address spender, address from, address to, uint256 tokenId, uint256 value)
25+
external
26+
view
27+
returns (uint8 code);
2528
}
2629

src/rules/validation/RuleBlacklist.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ contract RuleBlacklist is RuleValidateTransfer, RuleAddressSet, RuleBlacklistInv
6262
}
6363
}
6464

65+
function detectTransferRestrictionFrom(address spender, address from, address to, uint256 /* tokenId */, uint256 value )
66+
public
67+
view
68+
override(IERC7943NonFungibleComplianceExtend)
69+
returns (uint8)
70+
{
71+
return detectTransferRestrictionFrom(spender, from, to, value);
72+
}
73+
6574
/**
6675
* @notice To know if the restriction code is valid for this rule or not.
6776
* @param _restrictionCode The target restriction code

src/rules/validation/RuleSanctionsList.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ contract RuleSanctionsList is
9090
return uint8(REJECTED_CODE_BASE.TRANSFER_OK);
9191
}
9292

93+
function detectTransferRestrictionFrom(address spender, address from, address to, uint256 /* tokenId */, uint256 value )
94+
public
95+
view
96+
override(IERC7943NonFungibleComplianceExtend)
97+
returns (uint8)
98+
{
99+
return detectTransferRestrictionFrom(spender, from, to, value);
100+
}
101+
93102
/**
94103
* @notice To know if the restriction code is valid for this rule or not.
95104
* @param _restrictionCode The target restriction code

src/rules/validation/RuleWhitelist.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ contract RuleWhitelist is RuleAddressSet, RuleWhitelistCommon, IIdentityRegistry
105105
return detectTransferRestriction(from, to, value);
106106
}
107107

108+
function detectTransferRestrictionFrom(address spender, address from, address to, uint256 /* tokenId */, uint256 value )
109+
public
110+
view
111+
override(IERC7943NonFungibleComplianceExtend)
112+
returns (uint8)
113+
{
114+
return detectTransferRestrictionFrom(spender, from, to, value);
115+
}
116+
108117
/**
109118
* @notice Checks whether a specific address is currently listed.
110119
* @param targetAddress The address to check.

src/rules/validation/RuleWhitelistWrapper.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {RuleWhitelistCommon} from "./abstract/RuleWhitelistCommon.sol";
99
import {RulesManagementModule} from "RuleEngine/modules/RulesManagementModule.sol";
1010
import {RuleEngineInvariantStorage} from "RuleEngine/modules/library/RuleEngineInvariantStorage.sol";
1111
import {IRule} from "RuleEngine/interfaces/IRule.sol";
12+
import {IERC7943NonFungibleCompliance, IERC7943NonFungibleComplianceExtend} from "../interfaces/IERC7943NonFungibleCompliance.sol";
13+
1214
/**
1315
* @title Wrapper to call several different whitelist rules
1416
*/
@@ -96,6 +98,15 @@ contract RuleWhitelistWrapper is RulesManagementModule, MetaTxModuleStandalone,
9698
}
9799
}
98100

101+
function detectTransferRestrictionFrom(address spender, address from, address to, uint256 /* tokenId */, uint256 value )
102+
public
103+
view
104+
override(IERC7943NonFungibleComplianceExtend)
105+
returns (uint8)
106+
{
107+
return detectTransferRestrictionFrom(spender, from, to, value);
108+
}
109+
99110
/* ============ ACCESS CONTROL ============ */
100111
/**
101112
* @dev Returns `true` if `account` has been granted `role`.

0 commit comments

Comments
 (0)