Created
October 15, 2018 12:42
-
-
Save buddies2705/2e321157c9efc97954ac4605c198c65f to your computer and use it in GitHub Desktop.
Time - sensitive crowdsale
This file contains hidden or 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.24; | |
import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol"; | |
import "openzeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol"; | |
import "openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol"; | |
import "openzeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol"; | |
contract ExampleTokenCrowdsale is MintedCrowdsale, CappedCrowdsale, TimedCrowdsale{ | |
//minimum investor Contribution - 2 ether | |
//minimum investor Contribution - 50 ether | |
uint256 public investorMinCap = 2000000000000000000; | |
uint256 public investorHardCap = 50000000000000000000; | |
mapping(address => uint256) public contributions; | |
constructor(uint256 _rate, | |
address _wallet, | |
ERC20 _token, | |
uint256 _cap, | |
uint256 _openingTime, | |
uint256 _closingTime) | |
Crowdsale(_rate, _wallet, _token) | |
CappedCrowdsale(_cap) | |
TimedCrowdsale(_openingTime, _closingTime) | |
public{ | |
} | |
function _preValidatePurchase( | |
address _beneficiary, | |
uint256 _weiAmount | |
) | |
internal | |
{ | |
super._preValidatePurchase(_beneficiary, _weiAmount); | |
uint256 _existingContribution = contributions[_beneficiary]; | |
uint256 _newContribution = _existingContribution.add(_weiAmount); | |
require(_newContribution >= investorMinCap && _newContribution <= investorHardCap); | |
contributions[_beneficiary] = _newContribution; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment