-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplianceModule.sol
More file actions
99 lines (72 loc) · 3.51 KB
/
complianceModule.sol
File metadata and controls
99 lines (72 loc) · 3.51 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
// @title complianceModule.sol
interface IComplianceRegistry{
function isApproved (address user) external view returns (bool);
function isBlackListed (address user) external view returns (bool);
function getInvestorClass(address user) external view returns ( bytes32);
}
contract ComplianceModule is Initializable, AccessControlUpgradeable {
//===============Roles============================
bytes32 public constant RULES_ADMIN_ROLE = keccak256 ("RULES_ADMIN_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256 ("PAUSER_ROLE");
//======================sTATE Variables==================
IComplianceRegistry public complianceRegistry;
bool internal transferPaused;
//investorClass => max shares per transfer (simplified)
mapping (bytes32 => uint256 ) internal holdingLimit;
//wallet => lockup expiry
mapping ( address => uint64) internal lockUpExpiry;
uint256 [46] private __gap;
//@custom: oz-upgrades-unsafe-allow constructor
constructor () {
_disableInitializers();
}
//=================init======================
function initialize (address admin, address _registry) external initializer{
__AccessControl_init ();
complianceRegistry= IComplianceRegistry(_registry) ;
_grantRole (RULES_ADMIN_ROLE, admin);
_grantRole (PAUSER_ROLE, admin);
_grantRole (DEFAULT_ADMIN_ROLE, admin);
}
//====================Core Compliance============================
function canTransfer ( address from, address to, uint256 amount) external view returns (bool) {
// sanity check
if (from == address (0) && to == address (0)) return false;
if (amount == 0) return false;
if(transferPaused) return false;
// check blacklist
if ( complianceRegistry.isBlackListed (from) || complianceRegistry.isBlackListed(to)) return false;
// check for approval
if (!complianceRegistry.isApproved(to)) return false;
// lock up period
if (block.timestamp < lockUpExpiry[from] ) return false;
// holding limit
bytes32 classTo = complianceRegistry. getInvestorClass(to);
uint256 limit = holdingLimit[classTo];
//@ notice limit > 0 ( means a limit is configured)
// limit == 0 , means no limit has been configured
// 0 is used as a sentinel value
if (limit > 0 && amount > limit) return false; // if a limit exists and amount exceeds it, reject!
return true;
}
// ==============================Admin ===================================
function pauseTransfers () external onlyRole (PAUSER_ROLE){
transferPaused = true;
}
function unpauseTransfers() external onlyRole (PAUSER_ROLE){
transferPaused = false;
}
function setHoldingLimit(bytes32 investorClass, uint256 limit) external onlyRole (RULES_ADMIN_ROLE){
holdingLimit [investorClass] = limit;
}
function setLockUp(address investor, uint64 expiry)external onlyRole (RULES_ADMIN_ROLE){
lockUpExpiry[investor] = expiry;
}
function getHoldingLimit(bytes32 investorClass) external view returns (uint256){
return holdingLimit[investorClass];
}
}