Created
February 28, 2018 14:00
-
-
Save Pavel1991/c409dce0f8198e0a716ea286ec963b14 to your computer and use it in GitHub Desktop.
Pre-Sale SYC Token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.13; | |
interface token { | |
function transfer(address receiver, uint amount) public; | |
} | |
/** | |
* @title Ownable | |
* @dev The Ownable contract has an owner address, and provides basic authorization control | |
* functions, this simplifies the implementation of "user permissions". | |
*/ | |
contract Ownable { | |
address public owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
function Ownable() public { | |
owner = msg.sender; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) onlyOwner public { | |
require(newOwner != address(0)); | |
OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
} | |
} | |
//interface token { | |
// function transfer(address receiver, uint amount); | |
//} | |
contract Crowdsale is Ownable { | |
address public beneficiary; | |
uint public fundingGoal; | |
uint public amountRaised; | |
uint private saleStart; | |
uint private saleEnd; | |
uint public price; | |
token public tokenReward; | |
mapping(address => uint256) public balanceOf; | |
bool fundingGoalReached = false; | |
bool crowdsaleEnded = false; | |
event GoalReached(address recipient, uint totalAmountRaised); | |
event FundTransfer(address backer, uint amount, bool isContribution); | |
function getSaleStart() public view returns (uint256) { | |
return saleStart; | |
} | |
function getSaleEnd() public view returns (uint256) { | |
return saleEnd; | |
} | |
function inSalePeriod() public view returns (bool) { | |
return now > saleStart && now < saleEnd; | |
} | |
/** | |
* Constrctor function | |
* | |
* Setup the owner | |
*/ | |
// Fix for the ERC20 short address attack | |
modifier onlyPayloadSize(uint size) { | |
require(msg.data.length >= size + 4); | |
_; | |
} | |
modifier crowdsaleOpened() { | |
require(!crowdsaleEnded); | |
_; | |
} | |
modifier crowdsaleClosed() { | |
require(crowdsaleEnded); | |
_; | |
} | |
function Crowdsale( | |
address ifSuccessfulSendTo, | |
uint fundingGoalInEthers, | |
uint etherCostOfEachToken, | |
address addressOfTokenUsedAsReward | |
) public { | |
beneficiary = ifSuccessfulSendTo; | |
fundingGoal = fundingGoalInEthers * 1 ether; | |
price = etherCostOfEachToken * 1 wei; | |
tokenReward = token(addressOfTokenUsedAsReward); | |
owner = msg.sender; | |
if (saleStart == 0) { | |
saleStart = 1510904700; //Beginning: 03.17.2018 | |
saleEnd = 1519917315; //End: 04.17.2018 | |
} else { | |
saleStart = saleStart; | |
saleEnd = saleStart + 30 days; | |
} | |
} | |
function () public payable crowdsaleOpened { | |
uint amount = msg.value; | |
balanceOf[msg.sender] += amount; | |
amountRaised += amount; | |
tokenReward.transfer(msg.sender, amount / price); | |
FundTransfer(msg.sender, amount, true); | |
beneficiary.transfer(msg.value); | |
} | |
/** | |
* Check if goal was reached | |
* | |
* Checks if the goal or time limit has been reached and ends the campaign | |
*/ | |
function checkGoalReached() external onlyOwner crowdsaleOpened { | |
if (amountRaised >= fundingGoal){ | |
fundingGoalReached = true; | |
GoalReached(beneficiary, amountRaised); | |
} | |
crowdsaleEnded = true; | |
} | |
/** | |
* | |
* Checks to see if goal or time limit has been reached, and if so, and the funding goal was reached, | |
* the amount they contributed. | |
*/ | |
// function safeWithdrawal() external crowdsaleClosed { | |
// if (!fundingGoalReached) { | |
// uint amount = balanceOf[msg.sender]; | |
// balanceOf[msg.sender] = 0; | |
// if (amount > 0) { | |
// if (msg.sender.send(amount)) { | |
// FundTransfer(msg.sender, amount, false); | |
// } else { | |
// balanceOf[msg.sender] = amount; | |
// } | |
// } | |
// } | |
// if (fundingGoalReached && beneficiary == msg.sender) { | |
// if (beneficiary.send(amountRaised)) { | |
// FundTransfer(beneficiary, amountRaised, false); | |
// } else { | |
// //If we fail to send the funds to beneficiary, unlock funders balance | |
// fundingGoalReached = false; | |
// } | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment