This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdmin.sol
executable file
·316 lines (274 loc) · 8.66 KB
/
Admin.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
// import "./interfaces/IAdmin.sol";
import "./interfaces/ITokenSale.sol";
import "./interfaces/IERC20D.sol";
/**
* @title Admin.
* @dev contract creates tokenSales.
*
*/
contract Admin is AccessControl, Initializable {
using SafeERC20 for IERC20D;
bytes32 public constant OPERATOR = keccak256("OPERATOR");
bytes32 public constant STAKING = keccak256("STAKING");
uint256 public constant POINT_BASE = 10000;
uint256 public platformFee;
uint256 public platformTax;
address public factory;
address[] public tokenSales;
address public masterTokenSaleUSDB;
address public masterTokenSaleETH;
address public wallet;
address public USDB;
mapping(address => bool) public tokenSalesM;
mapping(address => bool) public blockClaim;
mapping(address => uint256) public indexOfTokenSales;
mapping(address => ITokenSale.Params) params;
mapping(address => mapping(address => bool)) public blacklist;
mapping(address => bool) public isKYCDone;
mapping(address => bool) public creators;
/**
* @dev Emitted when pool is created.
*/
event CreateTokenSale(address instanceAddress);
/**
* @dev Emitted when airdrop is set.
*/
event SetAirdrop(address airdrop);
/**
** @dev Initialize Function,gives the deployer DEFAULT_ADMIN_ROLE
** @param _owner: Owner address
*/
function initialize(address _owner) public initializer {
_setupRole(DEFAULT_ADMIN_ROLE, _owner);
_setRoleAdmin(OPERATOR, DEFAULT_ADMIN_ROLE);
wallet = _owner;
platformFee = 2 * (10 ** 17);
platformTax = 500;
USDB = 0xA9F81589Cc48Ff000166Bf03B3804A0d8Cec8114;
}
/**
* @dev Modifier that checks address is not ZERO address.
*/
modifier validation(address _address) {
require(_address != address(0), "TokenSale: Zero address");
_;
}
/**
* @dev Only Admin contract can call
*/
modifier onlyAdmin() {
require(
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
"TokenSale: Not admin"
);
_;
}
/**
* @dev Only Staking contract can call
*/
modifier onlyStaking() {
require(hasRole(STAKING, msg.sender), "TokenSale: Only Staking");
_;
}
/**
* @dev Checks IDO existence
*/
modifier onlyExist(address _instance) {
require(tokenSalesM[_instance], "TokenSale: Pool Not Exist");
_;
}
/**
* @dev Checks an Incoming Private pool(IDO)
*/
modifier onlyIncoming(address _instance) {
require(
params[_instance].saleStart > block.timestamp,
"TokenSale: Pool already started"
);
_;
}
/**
* @dev Set Admin Wallet
*/
function setWallet(address _address)
external
validation(_address)
onlyAdmin
{
wallet = _address;
}
/**
* @dev Only Admin can add an Operator
*/
function addOperator(address _address) external virtual onlyAdmin {
grantRole(OPERATOR, _address);
}
/**
* @dev Only Admin can remove an Operator
*/
function removeOperator(address _address) external virtual onlyAdmin {
revokeRole(OPERATOR, _address);
}
/**
** @dev IDO parameters
** @param _instance IDO address
*/
function getParams(address _instance)
external
view
returns (ITokenSale.Params memory)
{
return params[_instance];
}
/**
* @dev add users to blacklist
* @param _blacklist - the list of users to add to the blacklist
*/
function addToBlackList(address _instance, address[] memory _blacklist)
external
onlyIncoming(_instance)
onlyExist(_instance)
onlyRole(OPERATOR)
{
require(_blacklist.length <= 500, "TokenSale: Too large array");
for (uint256 i = 0; i < _blacklist.length; i++) {
blacklist[_instance][_blacklist[i]] = true;
}
}
/**
@dev returns the total no of IDO's created till now
*/
function getTokenSalesCount() external view returns (uint256) {
return tokenSales.length;
}
/**
@dev adds an IDO to an array
@param _addr - address of an Instance
*/
function _addToSales(address _addr) internal {
tokenSalesM[_addr] = true;
indexOfTokenSales[_addr] = tokenSales.length;
tokenSales.push(_addr);
}
/**
@dev removes an IDO to an array
@param _addr - address of an Instance
*/
function _removeFromSales(address _addr) internal {
tokenSalesM[_addr] = false;
tokenSales[indexOfTokenSales[_addr]] = tokenSales[
tokenSales.length - 1
];
indexOfTokenSales[
tokenSales[tokenSales.length - 1]
] = indexOfTokenSales[_addr];
tokenSales.pop();
delete indexOfTokenSales[_addr];
}
/**
@dev Checking parameters of IDO
@param _params - IDO parameters
*/
function _checkingParams(ITokenSale.Params memory _params, ITokenSale.Config memory _config) internal view {
require(_params.totalSupply > 0, "TokenSale: TotalSupply > 0");
require(
_params.saleStart >= block.timestamp,
"TokenSale: Start time > 0"
);
require(
_params.saleEnd > _params.saleStart,
"TokenSale: End time > start time"
);
require(_params.liqudityPercentage > 0 && _params.liqudityPercentage <= POINT_BASE,
"TokenSale: LiqudityPercentage Invalid");
require(_config.NoOfVestingIntervals > 0, "NoOfVestingIntervals can't be Zero");
require(_config.FirstVestPercentage > 0, "FirstVestPercentage can't be Zero");
}
/**
* @dev returns all token sales
*/
function getTokenSales() external view returns (address[] memory) {
return tokenSales;
}
/**
@dev set address for tokensaleUSDB.
@param _address Address of TokenSale contract
*/
function setMasterContractUSDB(address _address)
external
validation(_address)
onlyAdmin
{
masterTokenSaleUSDB = _address;
}
/**
@dev set address for tokensaleETH.
@param _address Address of TokenSale contract
*/
function setMasterContractETH(address _address)
external
validation(_address)
onlyAdmin
{
masterTokenSaleETH = _address;
}
/**
@dev Whitelist users
@param _address Address of User
*/
function setClaimBlock(address _address) external onlyRole(OPERATOR) {
blockClaim[_address] = true;
}
/**
@dev Blacklist users
@param _address Address of User
*/
function removeClaimBlock(address _address) external onlyRole(OPERATOR) {
blockClaim[_address] = false;
}
function setUserKYC(address[] calldata users) public onlyRole(OPERATOR){
for (uint256 i = 0; i < users.length; i++) {
isKYCDone[users[i]] = true;
}
}
function setPlatformFee(uint _fee) public onlyRole(OPERATOR){
platformFee = _fee;
}
function setPlatformTax(uint _tax) public onlyRole(OPERATOR){
platformTax = _tax;
}
function createPoolNew(
ITokenSale.Params memory _params,
ITokenSale.Config memory _config,
uint256 _maxAllocation,
bool _isKYC,
bool isETHBased
) external payable {
require(msg.value == platformFee,"Invalid platform Fee");
_checkingParams(_params, _config);
address instance = isETHBased ? Clones.clone(masterTokenSaleETH) : Clones.clone(masterTokenSaleUSDB);
params[instance] = _params;
ITokenSale(instance).initialize(
_params,
address(this),
msg.sender,
_maxAllocation,
platformTax,
_isKYC
);
ITokenSale(instance).setConfig(_config, msg.sender);
if(!creators[msg.sender]) creators[msg.sender] = true;
IERC20D(_params.tokenAddress).transferFrom(msg.sender, instance, (_params.totalSupply + _params.tokenLiquidity));
(bool suc, ) = payable(wallet).call{value: msg.value}("");
require(suc, "platformFee trn failed");
_addToSales(instance);
emit CreateTokenSale(instance);
}
}