pragma solidity ^0.4.2;
interface token {
function transfer (address receiver, uint amount) public;
}
contract Crowdsale {
address public beneficiary;
uint public fundingGoal;
uint public amountRaised;
uint public currentBalance;
uint public deadline;
uint public bonusPhaseOneDeadline;
uint public bonusPhaseTwoDeadline;
uint public bonusPhaseThreeDeadline;
uint public price;
uint public phaseOneBonusPercent;
uint public phaseTwoBonusPercent;
uint public phaseThreeBonusPercent;
uint public remainingTokens;
token public tokenReward;
mapping(address => uint256) public balanceOf;
bool public crowdsaleClosed = false;
event GoalReached(address recipient, uint totalAmountRaised);
event FundTransfer(address backer, uint amount, bool isContribution);
function Crowdsale(
address ifSuccessfulSendTo,
uint fundingGoalInEthers,
uint durationInMinutes,
address addressOfTokenUsedAsReward,
uint phaseOneDuration,
uint phaseTwoDuration,
uint phaseThreeDuration,
uint additionalBonusTokens
) public {
beneficiary = ifSuccessfulSendTo;
fundingGoal = fundingGoalInEthers * 1 ether;
deadline = now + durationInMinutes * 1 minutes;
bonusPhaseOneDeadline = now + phaseOneDuration * 1 minutes;
bonusPhaseTwoDeadline = now + phaseTwoDuration * 1 minutes;
bonusPhaseThreeDeadline = now + phaseThreeDuration * 1 minutes;
price = 0.0002 * 1 ether;
tokenReward = token(addressOfTokenUsedAsReward);
currentBalance = 0;
remainingTokens = (5000 * fundingGoalInEthers * 10 ** uint256(8)) + (additionalBonusTokens * 10 ** uint256(8));
phaseOneBonusPercent = 40;
phaseTwoBonusPercent = 35;
phaseThreeBonusPercent = 30;
}
function () public payable {
require(!crowdsaleClosed);
require(now < deadline);
uint amount = msg.value;
if (msg.sender != beneficiary) {
require(msg.value >= 1 ether);
amountRaised += amount;
uint tokens = uint(amount * 10 ** uint256(8) / price);
if (now < bonusPhaseOneDeadline) {
tokens += ((phaseOneBonusPercent * tokens)/100 );
} else if (now < bonusPhaseTwoDeadline) {
tokens += ((phaseTwoBonusPercent * tokens)/100);
} else if (now < bonusPhaseThreeDeadline) {
tokens += ((phaseThreeBonusPercent * tokens)/100);
}
balanceOf[msg.sender] += tokens;
remainingTokens -= tokens;
tokenReward.transfer(msg.sender, tokens);
FundTransfer(msg.sender, amount, true);
}
currentBalance += amount;
}
function checkGoalReached() public {
require(beneficiary == msg.sender);
crowdsaleClosed = true;
}
function safeWithdrawal(uint amountInWei) public {
require(beneficiary == msg.sender);
if (beneficiary.send(amountInWei)) {
FundTransfer(beneficiary, amountInWei, false);
currentBalance -= amountInWei;
}
}
function withdrawUnsold() public {
require(msg.sender == beneficiary);
require(remainingTokens > 0);
tokenReward.transfer(msg.sender, remainingTokens);
}
}
{
"compilationTarget": {
"Crowdsale.sol": "Crowdsale"
},
"evmVersion": "byzantium",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 0
},
"remappings": []
}
[{"constant":false,"inputs":[],"name":"checkGoalReached","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"deadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"beneficiary","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"bonusPhaseOneDeadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"amountInWei","type":"uint256"}],"name":"safeWithdrawal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdrawUnsold","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"tokenReward","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"fundingGoal","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"amountRaised","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"bonusPhaseThreeDeadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"bonusPhaseTwoDeadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"phaseOneBonusPercent","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"phaseTwoBonusPercent","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"price","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"phaseThreeBonusPercent","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"remainingTokens","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"crowdsaleClosed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currentBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"ifSuccessfulSendTo","type":"address"},{"name":"fundingGoalInEthers","type":"uint256"},{"name":"durationInMinutes","type":"uint256"},{"name":"addressOfTokenUsedAsReward","type":"address"},{"name":"phaseOneDuration","type":"uint256"},{"name":"phaseTwoDuration","type":"uint256"},{"name":"phaseThreeDuration","type":"uint256"},{"name":"additionalBonusTokens","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"recipient","type":"address"},{"indexed":false,"name":"totalAmountRaised","type":"uint256"}],"name":"GoalReached","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"backer","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"isContribution","type":"bool"}],"name":"FundTransfer","type":"event"}]