Crowdsale with different stages automatically change by time

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;
 }
}
1 Like

Hello @startgeek, welcome to the forum! :confetti_ball:

A feature we're working on (and that's scheduled to come out in v2.3, in a couple weeks) are TimeFrames, which I think could be useful for a scenario such as yours. It's still under development, so take a look and see if there are any improvements we could do to it to better cover scenarios such as yours! Your solution seems fine at a glance, but it's always better to rely on tested and tried code for this sort of thing :slight_smile:

1 Like

starting to review timeFrame.sol and it’s related tests

2 Likes

so I tried to download the TimedFrame contract from sonblind fork but I can’t find the contract!

44%20AM

It’s on the add-leasable branch: https://github.com/Sonblind/openzeppelin-solidity/blob/add-leasable/contracts/lifecycle/TimeFrame.sol

dear nventuro greetings
so I forked this repo and fixed problems with test’s that it had . problem’s mostly caused by bigNumber conversion and some problems with solidity helper library so what should I do now ?