-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPresaleSettings.sol
150 lines (120 loc) · 5.13 KB
/
PresaleSettings.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// SPDX-License-Identifier: UNLICENSED
// @Credits Unicrypt Network 2021
// Settings to initialize presale contracts and edit fees.
pragma solidity 0.6.12;
import "./Ownable.sol";
import "./EnumerableSet.sol";
import "./IERC20.sol";
contract PresaleSettings is Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private EARLY_ACCESS_TOKENS;
mapping(address => uint256) public EARLY_ACCESS_MAP;
EnumerableSet.AddressSet private ALLOWED_REFERRERS;
struct Settings {
uint256 BASE_FEE; // base fee divided by 1000
uint256 TOKEN_FEE; // token fee divided by 1000
uint256 REFERRAL_FEE; // a referrals percentage of the presale profits divided by 1000
address payable ETH_FEE_ADDRESS;
address payable TOKEN_FEE_ADDRESS;
uint256 ETH_CREATION_FEE; // fee to generate a presale contract on the platform
uint256 ROUND1_LENGTH; // length of round 1 in blocks
uint256 MAX_PRESALE_LENGTH; // maximum difference between start and endblock
}
Settings public SETTINGS;
constructor() public {
SETTINGS.BASE_FEE = 18; // 1.8%
SETTINGS.TOKEN_FEE = 18; // 1.8%
SETTINGS.REFERRAL_FEE = 200; // 20%
SETTINGS.ETH_CREATION_FEE = 5e17;
SETTINGS.ETH_FEE_ADDRESS = msg.sender;
SETTINGS.TOKEN_FEE_ADDRESS = msg.sender;
SETTINGS.ROUND1_LENGTH = 10; // 553 blocks = 2 hours
SETTINGS.MAX_PRESALE_LENGTH = 93046; // 2 weeks
}
function getRound1Length () external view returns (uint256) {
return SETTINGS.ROUND1_LENGTH;
}
function getMaxPresaleLength () external view returns (uint256) {
return SETTINGS.MAX_PRESALE_LENGTH;
}
function getBaseFee () external view returns (uint256) {
return SETTINGS.BASE_FEE;
}
function getTokenFee () external view returns (uint256) {
return SETTINGS.TOKEN_FEE;
}
function getReferralFee () external view returns (uint256) {
return SETTINGS.REFERRAL_FEE;
}
function getEthCreationFee () external view returns (uint256) {
return SETTINGS.ETH_CREATION_FEE;
}
function getEthAddress () external view returns (address payable) {
return SETTINGS.ETH_FEE_ADDRESS;
}
function getTokenAddress () external view returns (address payable) {
return SETTINGS.TOKEN_FEE_ADDRESS;
}
function setFeeAddresses(address payable _ethAddress, address payable _tokenFeeAddress) external onlyOwner {
SETTINGS.ETH_FEE_ADDRESS = _ethAddress;
SETTINGS.TOKEN_FEE_ADDRESS = _tokenFeeAddress;
}
function setFees(uint256 _baseFee, uint256 _tokenFee, uint256 _ethCreationFee, uint256 _referralFee) external onlyOwner {
SETTINGS.BASE_FEE = _baseFee;
SETTINGS.TOKEN_FEE = _tokenFee;
SETTINGS.REFERRAL_FEE = _referralFee;
SETTINGS.ETH_CREATION_FEE = _ethCreationFee;
}
function setRound1Length(uint256 _round1Length) external onlyOwner {
SETTINGS.ROUND1_LENGTH = _round1Length;
}
function setMaxPresaleLength(uint256 _maxLength) external onlyOwner {
SETTINGS.MAX_PRESALE_LENGTH = _maxLength;
}
function editAllowedReferrers(address payable _referrer, bool _allow) external onlyOwner {
if (_allow) {
ALLOWED_REFERRERS.add(_referrer);
} else {
ALLOWED_REFERRERS.remove(_referrer);
}
}
function editEarlyAccessTokens(address _token, uint256 _holdAmount, bool _allow) external onlyOwner {
if (_allow) {
EARLY_ACCESS_TOKENS.add(_token);
} else {
EARLY_ACCESS_TOKENS.remove(_token);
}
EARLY_ACCESS_MAP[_token] = _holdAmount;
}
// there will never be more than 10 items in this array. Care for gas limits will be taken.
// We are aware too many tokens in this unbounded array results in out of gas errors.
function userHoldsSufficientRound1Token (address _user) external view returns (bool) {
if (earlyAccessTokensLength() == 0) {
return true;
}
for (uint i = 0; i < earlyAccessTokensLength(); i++) {
(address token, uint256 amountHold) = getEarlyAccessTokenAtIndex(i);
if (IERC20(token).balanceOf(_user) >= amountHold) {
return true;
}
}
return false;
}
function getEarlyAccessTokenAtIndex(uint256 _index) public view returns (address, uint256) {
address tokenAddress = EARLY_ACCESS_TOKENS.at(_index);
return (tokenAddress, EARLY_ACCESS_MAP[tokenAddress]);
}
function earlyAccessTokensLength() public view returns (uint256) {
return EARLY_ACCESS_TOKENS.length();
}
// Referrers
function allowedReferrersLength() external view returns (uint256) {
return ALLOWED_REFERRERS.length();
}
function getReferrerAtIndex(uint256 _index) external view returns (address) {
return ALLOWED_REFERRERS.at(_index);
}
function referrerIsValid(address _referrer) external view returns (bool) {
return ALLOWED_REFERRERS.contains(_referrer);
}
}