-
Notifications
You must be signed in to change notification settings - Fork 4
/
MaxAmountValidator.sol
103 lines (90 loc) · 2.58 KB
/
MaxAmountValidator.sol
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
pragma solidity 0.4.24;
import "openzeppelin-solidity/contracts/lifecycle/Pausable.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "../interfaces/IModuleContract.sol";
import "../inheritables/TransferValidator.sol";
import "../interfaces/IERC20.sol";
/**
* @title Transfer Validator that checks if the trade will increase the to address above a max number of tokens
*/
contract MaxAmountValidator is TransferValidator, IModuleContract, Pausable {
using SafeMath for uint256;
/*----------- Constants -----------*/
bytes32 public constant moduleName = "MaxAmountValidator";
/*----------- Globals -----------*/
uint internal maxAmount_;
/*----------- Events -----------*/
event LogChangeMaxAmount(address sender, uint maxAmount);
/**
* @dev Constructor for contract
* @param _maxAmount maximum number of tokens an address can own
*/
constructor(
uint _maxAmount
) public {
maxAmount_ = _maxAmount;
}
/*----------- Validator Methods -----------*/
/**
* @dev Validate whether an address is not on the blacklist
* @param _token address Unused for this validation
* @param _to address The address which you want to transfer to
* @param _from address unused for this validation
* @param _amount uint256 unused for this validation
* @return bool
*/
function canSend(address _token, address _from, address _to, uint256 _amount)
external
returns(bool)
{
IERC20 token = IERC20(_token);
uint toBalance = token.balanceOf(_to);
uint newTotal = toBalance.add(_amount);
return (maxAmount_ >= newTotal);
}
/*----------- Setter Methods -----------*/
function setMaxAmount(uint _maxAmount)
external
onlyOwner
whenNotPaused
returns (bool success)
{
maxAmount_ = _maxAmount;
emit LogChangeMaxAmount(msg.sender, maxAmount_);
return true;
}
/*----------- Getter Methods -----------*/
/**
* @dev Returns the name of the validator
* @return bytes32
*/
function getName()
external
view
returns(bytes32)
{
return moduleName;
}
/**
* @dev Returns the type of the validator
* @return uint8
*/
function getType()
external
view
returns(uint8)
{
return moduleType;
}
/**
* @dev Returns the maxAmount of the validator
* @return uint
*/
function maxAmount()
external
view
returns(uint)
{
return maxAmount_;
}
}