Skip to content

Commit b38a5e8

Browse files
author
Dennis D
committed
Fix comment from auditing report and internal business testing
1 parent cb66e71 commit b38a5e8

File tree

1 file changed

+86
-61
lines changed

1 file changed

+86
-61
lines changed

GreenX-Test.sol

+86-61
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ contract Owner {
1414
}
1515

1616
function changeOwner(address _newOwnerAddr) public onlyOwner {
17+
require(_newOwnerAddr != address(0));
1718
owner = _newOwnerAddr;
1819
}
1920
}
@@ -71,59 +72,56 @@ contract GreenX is Owner {
7172
string public constant name = "GREENX";
7273
string public constant symbol = "GEX";
7374
uint public constant decimals = 18;
74-
uint256 constant public totalSupply = 375000000 * 10 ** 18; // 375 mil tokens will be created
75+
uint256 constant public totalSupply = 375000000 * 10 ** 18; // 375 mil tokens will be supplied
7576

76-
mapping(address => uint256) balances;
77+
mapping(address => uint256) internal balances;
7778
mapping(address => mapping (address => uint256)) internal allowed;
7879

7980
address public portalAddress;
8081
address public adminAddress;
81-
address public wallet;
82+
address public walletAddress;
8283
address public founderAddress;
8384
address public teamAddress;
8485

8586
mapping(address => bool) public privateList;
8687
mapping(address => bool) public whiteList;
8788
mapping(address => uint256) public totalInvestedAmountOf;
8889

89-
uint saleState;
90-
uint public icoStartTime;
91-
uint public icoEndTime;
92-
bool public inActive;
93-
bool public isSelling;
94-
bool public isTransferable;
95-
96-
uint constant NOT_SALE = 0; // not in sales
97-
uint constant IN_PRIVATE_SALE = 1; // in private sales
98-
uint constant IN_PRESALE = 2; // in presales
99-
uint constant END_PRESALE = 3; // end presales
100-
uint constant IN_1ST_ICO = 4; // in ICO 1st round
101-
uint constant IN_2ND_ICO = 5; // in ICO 2nd round
102-
uint constant IN_3RD_ICO = 6; // in ICO 3rd round
103-
uint constant END_SALE = 7; // end sales
104-
105-
uint founderAllocatedTime = 1;
106-
uint teamAllocatedTime = 1;
10790
uint constant lockPeriod1 = 180 days; // 1st locked period for tokens allocation of founder and team
10891
uint constant lockPeriod2 = 1 years; // 2nd locked period for tokens allocation of founder and team
10992
uint constant lockPeriod3 = 2 years; // locked period for remaining sale tokens after ending ICO
93+
uint constant NOT_SALE = 0; // Not in sales
94+
uint constant IN_PRIVATE_SALE = 1; // In private sales
95+
uint constant IN_PRESALE = 2; // In presales
96+
uint constant END_PRESALE = 3; // End presales
97+
uint constant IN_1ST_ICO = 4; // In ICO 1st round
98+
uint constant IN_2ND_ICO = 5; // In ICO 2nd round
99+
uint constant IN_3RD_ICO = 6; // In ICO 3rd round
100+
uint constant END_SALE = 7; // End sales
110101

111102
uint256 public constant salesAllocation = 187500000 * 10 ** 18; // 187.5 mil tokens allocated for sales
112103
uint256 public constant bonusAllocation = 37500000 * 10 ** 18; // 37.5 mil tokens allocated for token sale bonuses
113104
uint256 public constant reservedAllocation = 90000000 * 10 ** 18; // 90 mil tokens allocated for reserved, bounty campaigns, ICO partners, and bonus fund
114105
uint256 public constant founderAllocation = 37500000 * 10 ** 18; // 37.5 mil tokens allocated for founders
115106
uint256 public constant teamAllocation = 22500000 * 10 ** 18; // 22.5 mil tokens allocated for team
116-
uint256 public constant minInvestedCap = 2500 * 10 ** 18; // If this softcap will not be reached till end time, investors can refund ether
117-
uint256 public constant minInvestedAmount = 0.1 * 10 ** 18; // Mininum ether contribution per transaction
118-
107+
uint256 public constant minInvestedCap = 2500 * 10 ** 18; // 2500 ether for softcap
108+
uint256 public constant minInvestedAmount = 0.1 * 10 ** 18; // 0.1 ether for mininum ether contribution per transaction
109+
110+
uint saleState;
111+
uint256 totalInvestedAmount;
112+
uint public icoStartTime;
113+
uint public icoEndTime;
114+
bool public inActive;
115+
bool public isSelling;
116+
bool public isTransferable;
117+
uint public founderAllocatedTime = 1;
118+
uint public teamAllocatedTime = 1;
119119
uint256 public privateSalePrice;
120120
uint256 public preSalePrice;
121121
uint256 public icoStandardPrice;
122122
uint256 public ico1stPrice;
123123
uint256 public ico2ndPrice;
124-
125-
uint256 totalInvestedAmount;
126-
uint256 public totalRemainingTokensForSales; // Total tokens remain for sales
124+
uint256 public totalRemainingTokensForSales; // Total tokens remaining for sales
127125
uint256 public totalReservedAndBonusTokenAllocation; // Total tokens allocated for reserved and bonuses
128126
uint256 public totalLoadedRefund; // Total ether will be loaded to contract for refund
129127
uint256 public totalRefundedAmount; // Total ether refunded to investors
@@ -141,10 +139,10 @@ contract GreenX is Owner {
141139

142140
event SetPrivateSalePrice(uint256 price); // Set private sale price
143141
event SetPreSalePrice(uint256 price); // Set presale price
144-
event SetICOPrice(uint256 price); // Set ICO sale prices
142+
event SetICOPrice(uint256 price); // Set ICO standard price
145143

146144
event IssueTokens(address investorAddress, uint256 amount, uint256 tokenAmount, uint state); // Issue tokens to investor
147-
event RevokeTokens(address investorAddress, uint256 amount, uint256 tokenAmount, uint256 txFee); // Revoke tokens after ending ICO for uncompleted KYC investors
145+
event RevokeTokens(address investorAddress, uint256 amount, uint256 tokenAmount, uint256 txFee); // Revoke tokens after ending ICO for incompleted KYC investors
148146
event AllocateTokensForFounder(address founderAddress, uint256 founderAllocatedTime, uint256 tokenAmount); // Allocate tokens to founders' address
149147
event AllocateTokensForTeam(address teamAddress, uint256 teamAllocatedTime, uint256 tokenAmount); // Allocate tokens to team's address
150148
event AllocateReservedTokens(address reservedAddress, uint256 tokenAmount); // Allocate reserved tokens
@@ -175,8 +173,11 @@ contract GreenX is Owner {
175173
_;
176174
}
177175

178-
function GreenX(address _fundAddr, address _adminAddr, address _portalAddr) public Owner(msg.sender) {
179-
wallet = _fundAddr;
176+
function GreenX(address _walletAddr, address _adminAddr, address _portalAddr) public Owner(msg.sender) {
177+
require(_walletAddr != address(0));
178+
require(_adminAddr != address(0));
179+
require(_portalAddr != address(0));
180+
walletAddress = _walletAddr;
180181
adminAddress = _adminAddr;
181182
portalAddress = _portalAddr;
182183
inActive = true;
@@ -204,27 +205,30 @@ contract GreenX is Owner {
204205
revert();
205206
}
206207

207-
// Load ether amount to contract for refuding or revoking
208-
function loadFund() external payable isActive {
208+
// Load ether amount to contract for refunding or revoking
209+
function loadFund() external payable {
209210
require(msg.value > 0);
210211
totalLoadedRefund = totalLoadedRefund.add(msg.value);
211212
}
212213

213214
// ERC20 standard function
214-
function transfer(address _to, uint256 _value) external transferable isActive returns (bool) {
215+
function transfer(address _to, uint256 _value) external transferable returns (bool) {
215216
require(_to != address(0));
216-
require(_value <= balances[msg.sender]);
217+
require(_value > 0);
218+
// require(_value <= balances[msg.sender]);
217219
balances[msg.sender] = balances[msg.sender].sub(_value);
218220
balances[_to] = balances[_to].add(_value);
219221
emit Transfer(msg.sender, _to, _value);
220222
return true;
221223
}
222224

223225
// ERC20 standard function
224-
function transferFrom(address _from, address _to, uint256 _value) external transferable isActive returns (bool) {
226+
function transferFrom(address _from, address _to, uint256 _value) external transferable returns (bool) {
225227
require(_to != address(0));
226-
require(_value <= balances[_from]);
227-
require(_value <= allowed[_from][msg.sender]);
228+
require(_from != address(0));
229+
require(_value > 0);
230+
// require(_value <= balances[_from]);
231+
// require(_value <= allowed[_from][msg.sender]);
228232
balances[_from] = balances[_from].sub(_value);
229233
balances[_to] = balances[_to].add(_value);
230234
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
@@ -233,7 +237,9 @@ contract GreenX is Owner {
233237
}
234238

235239
// ERC20 standard function
236-
function approve(address _spender, uint256 _value) external transferable isActive returns (bool) {
240+
function approve(address _spender, uint256 _value) external transferable returns (bool) {
241+
require(_spender != address(0));
242+
require(_value > 0);
237243
allowed[msg.sender][_spender] = _value;
238244
emit Approval(msg.sender, _spender, _value);
239245
return true;
@@ -251,7 +257,7 @@ contract GreenX is Owner {
251257
// Modify private list
252258
function modifyPrivateList(address[] _investorAddrs, bool _isPrivateListed) external isActive onlyOwnerOrAdminOrPortal returns(bool) {
253259
for (uint256 i = 0; i < _investorAddrs.length; i++) {
254-
whiteList[_investorAddrs[i]] = _isPrivateListed;
260+
privateList[_investorAddrs[i]] = _isPrivateListed;
255261
emit ModifyPrivateList(_investorAddrs[i], _isPrivateListed);
256262
}
257263
return true;
@@ -270,7 +276,7 @@ contract GreenX is Owner {
270276
// Start presales
271277
function startPreSales() external isActive onlyOwnerOrAdmin returns (bool) {
272278
require(saleState < IN_PRESALE);
273-
require(preSalePrice != 0);
279+
require(preSalePrice > 0);
274280
saleState = IN_PRESALE;
275281
isSelling = true;
276282
emit StartPresales(saleState);
@@ -289,6 +295,7 @@ contract GreenX is Owner {
289295
// Start ICO
290296
function startICO() external isActive onlyOwnerOrAdmin returns (bool) {
291297
require(saleState == END_PRESALE);
298+
require(icoStandardPrice > 0);
292299
saleState = IN_1ST_ICO;
293300
icoStartTime = now;
294301
isSelling = true;
@@ -309,20 +316,23 @@ contract GreenX is Owner {
309316

310317
// Set private sales price
311318
function setPrivateSalePrice(uint256 _tokenPerEther) external onlyOwnerOrAdmin returns(bool) {
319+
require(_tokenPerEther > 0);
312320
privateSalePrice = _tokenPerEther;
313321
emit SetPrivateSalePrice(privateSalePrice);
314322
return true;
315323
}
316324

317325
// Set presales price
318326
function setPreSalePrice(uint256 _tokenPerEther) external onlyOwnerOrAdmin returns(bool) {
327+
require(_tokenPerEther > 0);
319328
preSalePrice = _tokenPerEther;
320329
emit SetPreSalePrice(preSalePrice);
321330
return true;
322331
}
323332

324333
// Set ICO price including ICO standard price, ICO 1st round price, ICO 2nd round price
325334
function setICOPrice(uint256 _tokenPerEther) external onlyOwnerOrAdmin returns(bool) {
335+
require(_tokenPerEther > 0);
326336
icoStandardPrice = _tokenPerEther;
327337
ico1stPrice = _tokenPerEther + _tokenPerEther * 20 / 100;
328338
ico2ndPrice = _tokenPerEther + _tokenPerEther * 10 / 100;
@@ -331,11 +341,13 @@ contract GreenX is Owner {
331341
}
332342

333343
// Revoke tokens from incompleted KYC investors' addresses
334-
function revokeTokens(address _noneKycAddr, uint256 _transactionFee) external isActive onlyOwnerOrAdmin {
344+
function revokeTokens(address _noneKycAddr, uint256 _transactionFee) external onlyOwnerOrAdmin {
345+
require(_noneKycAddr != address(0));
335346
uint256 investedAmount = totalInvestedAmountOf[_noneKycAddr];
336347
uint256 totalRemainingRefund = totalLoadedRefund.sub(totalRefundedAmount);
337348
require(whiteList[_noneKycAddr] == false && privateList[_noneKycAddr] == false);
338-
require(investedAmount > 0 && investedAmount >= _transactionFee);
349+
// require(investedAmount > 0 && investedAmount >= _transactionFee);
350+
require(investedAmount > 0);
339351
require(totalRemainingRefund >= investedAmount);
340352
require(saleState == END_SALE);
341353
uint256 refundAmount = investedAmount.sub(_transactionFee);
@@ -349,7 +361,7 @@ contract GreenX is Owner {
349361
}
350362

351363
// Investors can claim ether refund if total raised fund doesn't reach our softcap
352-
function refund() external isActive {
364+
function refund() external {
353365
uint256 refundedAmount = totalInvestedAmountOf[msg.sender];
354366
uint256 totalRemainingRefund = totalLoadedRefund.sub(totalRefundedAmount);
355367
uint256 tokenRevoked = balances[msg.sender];
@@ -364,42 +376,52 @@ contract GreenX is Owner {
364376
emit Refund(msg.sender, refundedAmount, tokenRevoked);
365377
}
366378

367-
// Activate contract after deploying successfully
379+
// Activate token sale function
368380
function activate() external onlyOwner {
369381
inActive = false;
370382
}
371383

384+
// Deacivate token sale function
385+
function deActivate() external onlyOwner {
386+
inActive = true;
387+
}
388+
372389
// Enable transfer feature of tokens
373-
function enableTokenTransfer() external onlyOwner {
390+
function enableTokenTransfer() external isActive onlyOwner {
374391
isTransferable = true;
375392
}
376393

377394
// Modify wallet
378395
function changeWallet(address _newAddress) external onlyOwner {
379-
require(wallet != _newAddress);
380-
wallet = _newAddress;
396+
require(_newAddress != address(0));
397+
require(walletAddress != _newAddress);
398+
walletAddress = _newAddress;
381399
}
382400

383401
// Modify admin
384402
function changeAdminAddress(address _newAddress) external onlyOwner {
403+
require(_newAddress != address(0));
385404
require(adminAddress != _newAddress);
386405
adminAddress = _newAddress;
387406
}
388407

389408
// Modify portal
390409
function changePortalAddress(address _newAddress) external onlyOwner {
410+
require(_newAddress != address(0));
391411
require(portalAddress != _newAddress);
392412
portalAddress = _newAddress;
393413
}
394414

395415
// Modify founder address to receive founder tokens allocation
396416
function changeFounderAddress(address _newAddress) external onlyOwnerOrAdmin {
417+
require(_newAddress != address(0));
397418
require(founderAddress != _newAddress);
398419
founderAddress = _newAddress;
399420
}
400421

401422
// Modify team address to receive team tokens allocation
402423
function changeTeamAddress(address _newAddress) external onlyOwnerOrAdmin {
424+
require(_newAddress != address(0));
403425
require(teamAddress != _newAddress);
404426
teamAddress = _newAddress;
405427
}
@@ -429,6 +451,7 @@ contract GreenX is Owner {
429451
amount = founderAllocation * 50/100;
430452
balances[founderAddress] = balances[founderAddress].add(amount);
431453
emit AllocateTokensForFounder(founderAddress, founderAllocatedTime, amount);
454+
founderAllocatedTime = 4;
432455
return;
433456
}
434457
revert();
@@ -459,30 +482,32 @@ contract GreenX is Owner {
459482
amount = teamAllocation * 50/100;
460483
balances[teamAddress] = balances[teamAddress].add(amount);
461484
emit AllocateTokensForTeam(teamAddress, teamAllocatedTime, amount);
485+
teamAllocatedTime = 4;
462486
return;
463487
}
464488
revert();
465489
}
466490

467491
// Remaining tokens for sales will be locked by contract in 2 years
468492
function allocateRemainingTokens(address _addr) external isActive onlyOwnerOrAdmin {
493+
require(_addr != address(0));
469494
require(saleState == END_SALE);
470495
require(totalRemainingTokensForSales > 0);
471496
require(now >= icoEndTime + lockPeriod3);
472-
require(_addr != address(0));
473497
balances[_addr] = balances[_addr].add(totalRemainingTokensForSales);
474498
totalRemainingTokensForSales = 0;
475499
}
476500

477501
// Allocate reserved tokens
478-
function allocateReservedTokens(address _addr, uint amount) external isActive onlyOwnerOrAdmin {
502+
function allocateReservedTokens(address _addr, uint _amount) external isActive onlyOwnerOrAdmin {
479503
require(saleState == END_SALE);
480-
require(totalReservedAndBonusTokenAllocation > 0);
481-
require(totalReservedAndBonusTokenAllocation >= amount);
504+
// require(totalReservedAndBonusTokenAllocation > 0);
505+
// require(totalReservedAndBonusTokenAllocation >= amount);
506+
require(_amount > 0);
482507
require(_addr != address(0));
483-
balances[_addr] = balances[_addr].add(amount);
484-
totalReservedAndBonusTokenAllocation = totalReservedAndBonusTokenAllocation.sub(amount);
485-
emit AllocateReservedTokens(_addr, amount);
508+
balances[_addr] = balances[_addr].add(_amount);
509+
totalReservedAndBonusTokenAllocation = totalReservedAndBonusTokenAllocation.sub(_amount);
510+
emit AllocateReservedTokens(_addr, _amount);
486511
}
487512

488513
// ERC20 standard function
@@ -539,17 +564,17 @@ contract GreenX is Owner {
539564

540565
// Issue tokens to investors and transfer ether to wallet
541566
function issueTokens(uint256 _price, uint _state) private {
542-
require(wallet != address(0));
567+
require(walletAddress != address(0));
543568
uint tokenAmount = msg.value.mul(_price).mul(10**18).div(1 ether);
544-
require(totalRemainingTokensForSales >= tokenAmount);
569+
// require(totalRemainingTokensForSales >= tokenAmount);
545570
balances[msg.sender] = balances[msg.sender].add(tokenAmount);
546571
totalInvestedAmountOf[msg.sender] = totalInvestedAmountOf[msg.sender].add(msg.value);
547572
totalRemainingTokensForSales = totalRemainingTokensForSales.sub(tokenAmount);
548573
totalInvestedAmount = totalInvestedAmount.add(msg.value);
549-
wallet.transfer(msg.value);
574+
walletAddress.transfer(msg.value);
550575
emit IssueTokens(msg.sender, msg.value, tokenAmount, _state);
551576
}
552-
577+
553578
// ForTestOnly
554579
function checkTokenAllocation() public view returns(bool) {
555580
uint256 totalTokenAllocation = salesAllocation + bonusAllocation + reservedAllocation + founderAllocation + teamAllocation;
@@ -565,7 +590,7 @@ contract GreenX is Owner {
565590
}
566591

567592
// ForTestOnly
568-
function decreaseICOEndTimeForTestOnly(uint256 day) public {
593+
function decreaseICOEndTime(uint256 day) public {
569594
icoEndTime = icoEndTime - day * 1 days;
570595
}
571-
}
596+
}

0 commit comments

Comments
 (0)