-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathERC3643ComplianceExtendedModule.sol
More file actions
71 lines (60 loc) · 2.73 KB
/
ERC3643ComplianceExtendedModule.sol
File metadata and controls
71 lines (60 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
/* ==== Interface and other library === */
import {IERC3643ComplianceExtended} from "../interfaces/IERC3643ComplianceExtended.sol";
import {ERC3643ComplianceModule} from "./ERC3643ComplianceModule.sol";
abstract contract ERC3643ComplianceExtendedModule is ERC3643ComplianceModule, IERC3643ComplianceExtended {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(address token => bool approved) private _tokenSelfBindingApproval;
/// @inheritdoc IERC3643ComplianceExtended
function bindTokens(address[] calldata tokens) public virtual override onlyComplianceManager {
for (uint256 i = 0; i < tokens.length; ++i) {
_bindToken(tokens[i]);
}
}
/// @inheritdoc IERC3643ComplianceExtended
function unbindTokens(address[] calldata tokens) public virtual override onlyComplianceManager {
for (uint256 i = 0; i < tokens.length; ++i) {
_unbindToken(tokens[i]);
}
}
/// @inheritdoc IERC3643ComplianceExtended
function setTokenSelfBindingApproval(address token, bool approved) public virtual override onlyComplianceManager {
require(token != address(0), RuleEngine_ERC3643Compliance_InvalidTokenAddress());
_tokenSelfBindingApproval[token] = approved;
emit TokenSelfBindingApprovalSet(token, approved);
}
/// @inheritdoc IERC3643ComplianceExtended
function setTokenSelfBindingApprovalBatch(address[] calldata tokens, bool approved)
public
virtual
override
onlyComplianceManager
{
for (uint256 i = 0; i < tokens.length; ++i) {
address token = tokens[i];
require(token != address(0), RuleEngine_ERC3643Compliance_InvalidTokenAddress());
_tokenSelfBindingApproval[token] = approved;
}
emit TokenSelfBindingApprovalBatchSet(tokens, approved);
}
/// @inheritdoc IERC3643ComplianceExtended
function isTokenSelfBindingApproved(address token) public view virtual override returns (bool) {
return _tokenSelfBindingApproval[token];
}
/// @inheritdoc IERC3643ComplianceExtended
function getTokenBounds() public view virtual override returns (address[] memory) {
return _boundTokens.values();
}
/**
* @dev Authorizes bind/unbind operations.
* Allows compliance manager, or approved token self-calls for T-REX compatibility.
*/
function _authorizeComplianceBindingChange(address token) internal virtual override {
if (_msgSender() == token && _tokenSelfBindingApproval[token]) {
return;
}
_onlyComplianceManager();
}
}