Skip to content

Commit

Permalink
formatting, comment formatting, comment typos
Browse files Browse the repository at this point in the history
  • Loading branch information
JaheMerah authored and agnesenvaite committed Oct 31, 2017
1 parent acfe02a commit 8e8bb1f
Showing 1 changed file with 100 additions and 95 deletions.
195 changes: 100 additions & 95 deletions Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -110,61 +100,62 @@ 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;
}
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;
Expand All @@ -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);
Expand All @@ -191,7 +191,12 @@ contract Crowdsale is Ownable {
Refund(msg.sender, refund);
}

function drainEther() external onlyOwner {

function drainEther()
external
onlyOwner
{
fund.transfer(this.balance);
}

}

0 comments on commit 8e8bb1f

Please sign in to comment.