hey guys greetings and congrats on new forum:star_struck:
so I want to have a crowdsale with 5 different stages each with its own rate but I dont want an admin to update stage I want it to be time based and automatic. I dont think openzeppelin provide such a thing or at least I couldnt find any solution to this but I tried to implement it like this:
pragma solidity >=0.4.21 <0.6.0;
import "./BoltToken.sol";
import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import "openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "openzeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol";
// import "openzeppelin-solidity/contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol";
// import "openzeppelin-solidity/contracts/crowdsale/distribution/FinalizableCrowdsale.sol";
contract BoltTokenCrowdsale is Crowdsale
, CappedCrowdsale
, TimedCrowdsale
// , IndividuallyCappedCrowdsale
// , FinalizableCrowdsale
{
// Track investor contributions
uint256 public investorMinCap = 2000000000000000; // 0.002 ether
uint256 public investorHardCap = 50000000000000000000; // 50 ether
mapping(address => uint256) public contributions;
// // Crowdsale Stages
enum CrowdsaleStage { one, two, three, four, five }
// // Default to presale stage
CrowdsaleStage public stage = CrowdsaleStage.one;
// // Token Distribution
uint256 public tokenSalePercentage = 70;
uint256 public founderPercentage = 15;
uint256 public founderSpendPercentage = 15;
// Token reserve funds
address public _foundersFund;
address public _founderSpendFund;
address public _crowdsaleFund;
constructor (
address payable _wallet,
ERC20 _token,
uint256 _cap,
uint256 _openingTime,
uint256 _closingTime
)
Crowdsale(_rateStageOne, _wallet, _token)
CappedCrowdsale(_cap)
TimedCrowdsale(_openingTime, _closingTime)
// IndividuallyCappedCrowdsale()
// FinalizableCrowdsale()
public
{
_foundersFund = foundersFund;
_founderSpendFund = founderSpendFund;
_crowdsaleFund = crowdsaleFund;
if (now >= start + 60 weeks) {
_finalization()
}
if (now >= start + 40 weeks) {
_rate = 3000
}
if (condition) {
}
if (condition) {
}
if (condition) {
} else {
}
}
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;
}
}