diff --git a/Crowdsale.sol b/Crowdsale.sol index 676a89b..49749ed 100644 --- a/Crowdsale.sol +++ b/Crowdsale.sol @@ -4,9 +4,7 @@ import "./Ownable.sol"; import "./SafeMath.sol"; -/* - Interface of GeeToken contract -*/ +/* Interface of GeeToken contract */ contract Token { function transfer(address _to, uint256 _value) external; @@ -20,64 +18,54 @@ contract Crowdsale is Ownable { using SafeMath for uint256; - //Counts how many Gee coins are soldTokens - uint256 public soldTokens; - //Hard cap in Gee coins (with 8 decimals) - uint256 public hardCapInTokens = 67 * (10**6) * (10**8); - //Min amount of Ether - uint256 public constant MIN_ETHER = 0.03 ether; - //Max amount of Ether - uint256 public constant MAX_ETHER = 1000 ether; - - //Address where funds are forwarded during the ICO - address fund = 0x77E32B38a4AfdAb4dA3863a1de198809170644Df; - - //Mined blocks per DAY - uint256 public constant DAY = 5082; - - //Start block - uint256 public constant START_BLOCK_NUMBER = 4506960; - //Start + 3 days - uint256 public TIER2 = START_BLOCK_NUMBER.ADD(DAY.MUL(3)); - //Start + 10 days ( 3 days + 7 days) - uint256 public TIER3 = START_BLOCK_NUMBER.ADD(DAY.MUL(10)); - //Start + 20 days ( 3 days + 7 days + 10 days) - uint256 public TIER4 = START_BLOCK_NUMBER.ADD(DAY.MUL(20)); - //Start + 30 days - uint256 public endBlockNumber = START_BLOCK_NUMBER.ADD(DAY.MUL(30)); - - //GEE price - uint256 public price; - //Price in 1st tier - uint256 public constant TIER1_PRICE = 6000000; - //Price in 2nd tier - uint256 public constant TIER2_PRICE = 6700000; - //Price in 3rd tier - uint256 public constant TIER3_PRICE = 7400000; - //Price in 4th tier - uint256 public constant TIER4_PRICE = 8200000; - - //GeeToken contract - Token public gee; - - //softcap in ETH - uint256 public constant SOFT_CAP_IN_ETHER = 13500 ether; - //saves how mush ETH user spent on GEE - mapping (address => uint256) public bought; - //saves how mush ETH was collected - uint256 public collected; - - //to check if ICO is stopped - bool public stopped; - + //VARIABLE + uint256 public soldTokens; //Counts how many Gee coins are soldTokens + + uint256 public hardCapInTokens = 67 * (10**6) * (10**8); //Hard cap in Gee coins (with 8 decimals) + + uint256 public constant MIN_ETHER = 0.03 ether; //Min amount of Ether + uint256 public constant MAX_ETHER = 1000 ether; //Max amount of Ether + + + address fund = 0x77E32B38a4AfdAb4dA3863a1de198809170644Df; //Address where funds are forwarded during the ICO + + + uint256 public constant DAY = 5082; //Mined blocks per DAY + uint256 public constant START_BLOCK_NUMBER = 4506960; //Start block + + uint256 public TIER2 = START_BLOCK_NUMBER.ADD(DAY.MUL(3)); //Start + 3 days + uint256 public TIER3 = START_BLOCK_NUMBER.ADD(DAY.MUL(10)); //Start + 10 days ( 3 days + 7 days) + uint256 public TIER4 = START_BLOCK_NUMBER.ADD(DAY.MUL(20)); //Start + 20 days ( 3 days + 7 days + 10 days) + uint256 public endBlockNumber = START_BLOCK_NUMBER.ADD(DAY.MUL(30)); //Start + 30 days + + + uint256 public price; //GEE price + + uint256 public constant TIER1_PRICE = 6000000; //Price in 1st tier + uint256 public constant TIER2_PRICE = 6700000; //Price in 2nd tier + uint256 public constant TIER3_PRICE = 7400000; //Price in 3rd tier + uint256 public constant TIER4_PRICE = 8200000; //Price in 4th tier + + Token public gee; //GeeToken contract + + uint256 public constant SOFT_CAP_IN_ETHER = 13500 ether; //softcap in ETH + + uint256 public collected; //saves how much ETH was collected + bool public stopped; //to check if ICO is stopped uint256 public constant GEE100 = 100 * (10**8); - //Keep track of buyings - event Buy (address indexed _who, uint256 _amount, uint256 indexed _price); - //Keep track of refunding - event Refund (address indexed _who, uint256 _amount); + //MAP + mapping (address => uint256) public bought; //saves how much ETH user spent on GEE + + + //EVENT + event Buy (address indexed _who, uint256 _amount, uint256 indexed _price); //Keep track of buyings + event Refund (address indexed _who, uint256 _amount); //Keep track of refunding + + + //FUNCTION //Payable - can store ETH function Crowdsale(Token _geeToken) notZeroAddress(_geeToken) @@ -86,22 +74,24 @@ contract Crowdsale is Ownable { gee = _geeToken; } - /* - Fallback function is called when Ether is sent to the contract - */ - function() external payable { + + /* Fallback function is called when Ether is sent to the contract */ + function() + external + payable + { if (isCrowdsaleActive()) { buy(); - } else { //after crowdsale owner can send back eth for refund - require (msg.sender == fund || msg.sender == owner); + } else { + require (msg.sender == fund || msg.sender == owner); //after crowdsale owner can send back eth for refund } } - /* - Burn unsold GEE after crowdsale - */ - function finalize() external { + /* Burn unsold GEE after crowdsale */ + function finalize() + external + { require(soldTokens != hardCapInTokens); if (soldTokens < (hardCapInTokens - GEE100)) { require(block.number > endBlockNumber); @@ -110,47 +100,49 @@ contract Crowdsale is Ownable { hardCapInTokens = soldTokens; } + + /* Buy tokens */ function buy() - public - payable + public + payable { uint256 amountWei = msg.value; uint256 blocks = block.number; - //Ether limitation - require(amountWei >= MIN_ETHER); + + require(amountWei >= MIN_ETHER); //Ether limitation require(amountWei <= MAX_ETHER); price = getPrice(); - //Count how many GEE sender can buy - uint256 amount = amountWei / price; - //Add amount to soldTokens - soldTokens = soldTokens.ADD(amount); + + uint256 amount = amountWei / price; //Count how many GEE sender can buy + + soldTokens = soldTokens.ADD(amount); //Add amount to soldTokens require(soldTokens <= hardCapInTokens); if (soldTokens == hardCapInTokens) { endBlockNumber = blocks; } - - //counts ETH - collected = collected.ADD(amountWei); + + collected = collected.ADD(amountWei); //counts ETH bought[msg.sender] = bought[msg.sender].ADD(amountWei); - //Transfer amount of Gee coins to msg.sender - gee.transfer(msg.sender, amount); + + gee.transfer(msg.sender, amount); //Transfer amount of Gee coins to msg.sender - //Transfer contract Ether to fund - fund.transfer(this.balance); + fund.transfer(this.balance); //Transfer contract Ether to fund Buy(msg.sender, amount, price); } - /* - Function returns if Crowdsale is ongoing - */ - function isCrowdsaleActive() public constant returns (bool) { + /* Return Crowdsale status, depending on block numbers and stopInEmergency() state */ + function isCrowdsaleActive() + public + constant + returns (bool) + { if (endBlockNumber < block.number || stopped || START_BLOCK_NUMBER > block.number) { return false; @@ -158,13 +150,12 @@ contract Crowdsale is Ownable { return true; } - /* - Function which automatically changes tiers - */ + + /* Change tier taking block numbers as time */ function getPrice() - internal - constant - returns (uint256) + internal + constant + returns (uint256) { if (block.number < TIER2) { return TIER1_PRICE; @@ -177,12 +168,21 @@ contract Crowdsale is Ownable { return TIER4_PRICE; } - function stopInEmergency() external onlyOwner { + + /* Stop CROWDSALE in emergency */ + function stopInEmergency() + external + onlyOwner + { require (!stopped); stopped = true; } - function refund() external { + + /* Refund, if the soft cap is not reached */ + function refund() + external + { uint256 refund = bought[msg.sender]; require (!isCrowdsaleActive()); require (collected < SOFT_CAP_IN_ETHER); @@ -191,7 +191,12 @@ contract Crowdsale is Ownable { Refund(msg.sender, refund); } - function drainEther() external onlyOwner { + + function drainEther() + external + onlyOwner + { fund.transfer(this.balance); } + } \ No newline at end of file