Skip to content

Instantly share code, notes, and snippets.

@troggy
Created April 13, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troggy/8287b1c714f951e0da7fd27ebf842e5b to your computer and use it in GitHub Desktop.
Save troggy/8287b1c714f951e0da7fd27ebf842e5b to your computer and use it in GitHub Desktop.
Simple CrowdsaleWithPresale contract
pragma solidity ^0.4.18;
import "zeppelin-solidity/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol";
/**
* @title CrowdsaleWithPresale
* @dev Extension of IncreasingPriceCrowdsale contract that increases the price of tokens
* once the specified period has elapsed (presale time).
*/
contract CrowdsaleWithPresale is IncreasingPriceCrowdsale {
uint256 public presaleClosingTime;
function CrowdsaleWithPresale(uint256 _presaleClosingTime) public {
presaleClosingTime = _presaleClosingTime;
}
/**
* @dev Checks whether the period in which the presale is open has already elapsed.
* @return Whether presale period has elapsed
*/
function presaleClosed() public view returns (bool) {
return now > presaleClosingTime;
}
/**
* @dev Returns the rate of tokens per wei at the present time.
* Note that, as price _increases_ with time, the rate _decreases_.
* @return The number of tokens a buyer gets per wei at a given time
*/
function getCurrentRate() public view returns (uint256) {
return presaleClosed() ? finalRate : initialRate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment