-
Notifications
You must be signed in to change notification settings - Fork 5
/
BadgerValidation.sol
57 lines (44 loc) · 1.6 KB
/
BadgerValidation.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
// SPDX-License-Identifier: CC-BY-SA-4.0
// Version of Solidity compiler this program was written for
pragma solidity ^0.8.0;
import "../interfaces/WalletValidator.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenHolderThresholdValidator is WalletValidator
{
IERC20 immutable TOKEN;
uint256 immutable threshold;
Operator immutable operator;
enum Operator
{
None,
GreaterThan,
GreaterEqualThan,
LessThan,
LessEqualThan,
Equal,
MAX_OPERATION
}
constructor(address tokenAddress, uint256 balanceThreshold, Operator operatorIn)
{
require(operatorIn > Operator.None && operatorIn < Operator.MAX_OPERATION);
TOKEN = IERC20(tokenAddress);
threshold = balanceThreshold;
operator = operatorIn;
}
function Validate(address wallet) external view override returns (bool)
{
assert(operator != Operator.None && operator != Operator.MAX_OPERATION);
if(operator == Operator.GreaterEqualThan)
return(TOKEN.balanceOf(wallet) >= threshold);
if(operator == Operator.GreaterThan)
return(TOKEN.balanceOf(wallet) > threshold);
if(operator == Operator.LessEqualThan)
return(TOKEN.balanceOf(wallet) <= threshold);
if(operator == Operator.LessThan)
return(TOKEN.balanceOf(wallet) < threshold);
if(operator == Operator.Equal)
return(TOKEN.balanceOf(wallet) == threshold);
assert(false); // should not reach here.
return false; // satisfy compiler warning
}
}