-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathValidationModuleAllowlist.sol
More file actions
113 lines (105 loc) · 3.67 KB
/
ValidationModuleAllowlist.sol
File metadata and controls
113 lines (105 loc) · 3.67 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
/* ==== Module === */
import {ValidationModule} from "./ValidationModule.sol";
import {AllowlistModule} from "../options/AllowlistModule.sol";
/**
* @title ValidationModule - Allowlist
* @dev Validation module with allowlist.
*
* Useful for to restrict and validate transfers
*/
abstract contract ValidationModuleAllowlist is
AllowlistModule, ValidationModule
{
/*//////////////////////////////////////////////////////////////
INTERNAL/PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/* ============ View functions ============ */
/**
* @dev Use forcedTransfer (or forcedBurn) to burn tokens from an non-allowlist address
*/
function _canMintBurnByModule(
address account
) internal view virtual override(ValidationModule) returns (bool) {
if(_isAllowlistEnabled() && !isAllowlisted(account)){
return false;
} else {
return ValidationModule._canMintBurnByModule(account);
}
}
/**
* @dev Add allowlist check for standard transfer
*/
function _canTransferStandardByModuleAllowlist(
address spender,
address from,
address to
) internal view virtual returns (bool) {
if(_isAllowlistEnabled()){
bool spenderCheck = spender != address(0) && !isAllowlisted(spender);
if (spenderCheck || !isAllowlisted(from) || !isAllowlisted(to)){
return true;
}
}
return false;
}
/**
* @dev Add allowlist check for standard transfer
*/
function _canTransferStandardByModule(
address spender,
address from,
address to
) internal view virtual override(ValidationModule) returns (bool) {
if(_canTransferStandardByModuleAllowlist(spender, from, to)){
return false;
}
return ValidationModule._canTransferStandardByModule(spender, from, to);
}
function _canTransact(address account) internal view virtual override(ValidationModule) returns (bool allowed) {
if(_isAllowlistEnabled() && !isAllowlisted(account)){
return false;
} else {
return ValidationModule._canTransact(account);
}
}
/* ============ View functions which revert ============ */
function _canMintBurnByModuleAndRevert(
address account
) internal view virtual override(ValidationModule) {
if(_isAllowlistEnabled() && !isAllowlisted(account)){
revert ERC7943CannotTransact(account);
} else {
ValidationModule._canMintBurnByModuleAndRevert(account);
}
}
function _canTransferStandardByModuleAndRevert(
address spender,
address from,
address to
) internal view virtual override(ValidationModule) {
_canTransferStandardByModuleAllowlistAndRevert(spender, from, to);
ValidationModule._canTransferStandardByModuleAndRevert(spender, from, to);
}
function _canTransferStandardByModuleAllowlistAndRevert(
address spender,
address from,
address to
) internal view virtual {
address account;
if(_isAllowlistEnabled()){
if (spender != address(0) && !isAllowlisted(spender)){
account = spender;
} else if (!isAllowlisted(from)) {
account = from;
} else if(!isAllowlisted(to) ){
account = to;
} else {
return;
}
// Will revert if the last else branch has not be taken
revert ERC7943CannotTransact(account);
}
}
}