contract postICO is Ownable {
    using SafeMath for uint256;

    Token public token;

    address public walletE;
    address public walletB;
    address public walletC;
    address public walletF;
    address public walletG;

    // 05.07.18 @ UTC 23:59
    uint256 public endICODate;

    bool public finished = false;

    uint256 public FTST;

    // Save complete of transfers (due to schedule) to these wallets 
    mapping(uint8 => bool) completedE;
    mapping(uint8 => bool) completedBC;

    uint256 public paymentSizeE;
    uint256 public paymentSizeB;
    uint256 public paymentSizeC;

    /**
     * @dev _endICODate should be 1530835140
     */
    function postICO(
        address _token,
        address _walletE,
        address _walletB,
        address _walletC,
        address _walletF,
        address _walletG,
        uint256 _endICODate
    ) public {
        require(_token != address(0));
        require(_walletE != address(0));
        require(_walletB != address(0));
        require(_walletC != address(0));
        require(_walletF != address(0));
        require(_walletG != address(0));
        require(_endICODate >= now);

        token = Token(_token);
        endICODate = _endICODate;

        walletE = _walletE;
        walletB = _walletB;
        walletC = _walletC;
        walletF = _walletF;
        walletG = _walletG;
    }

    function finish() onlyOwner public {
        require(now > endICODate);
        require(!finished);
        require(token.saleAgent() == address(this));

        FTST = token.totalSupply().mul(100).div(65);

        // post ICO token allocation: 35% of final total supply of tokens (FTST) will be distributed to the wallets E, B, C, F, G due to the schedule described below. Where FTST = the number of tokens sold during crowdsale x 100 / 65.
        // Growth reserve: 21% (4-years lock). Distribute 2.625% of the final total supply of tokens (FTST*2625/100000) 8 (eight) times every half a year during 4 (four) years after the endICODate to the wallet [E].
        // hold this tokens on postICO contract
        paymentSizeE = FTST.mul(2625).div(100000);
        uint256 tokensE = paymentSizeE.mul(8);
        token.mint(this, tokensE);

        // Team: 9.6% (2-years lock).
        // Distribute 0.25% of final total supply of tokens (FTST*25/10000) 4 (four) times every half a year during 2 (two) years after endICODate to the wallet [B].
        // hold this tokens on postICO contract
        paymentSizeB = FTST.mul(25).div(10000);
        uint256 tokensB = paymentSizeB.mul(4);
        token.mint(this, tokensB);

        // Distribute 2.15% of final total supply of tokens (FTST*215/10000) 4 (four) times every half a year during 2 (two) years after endICODate to the wallet [C]. 
        // hold this tokens on postICO contract
        paymentSizeC = FTST.mul(215).div(10000);
        uint256 tokensC = paymentSizeC.mul(4);
        token.mint(this, tokensC);

        // Angel investors: 2%. Distribute 2% of final total supply of tokens (FTST*2/100) after endICODate to the wallet [F].
        uint256 tokensF = FTST.mul(2).div(100);
        token.mint(walletF, tokensF);

        // Referral program 1,3% + Bounty program: 1,1%. Distribute 2,4% of final total supply of tokens (FTST*24/1000) after endICODate to the wallet [G]. 
        uint256 tokensG = FTST.mul(24).div(1000);
        token.mint(walletG, tokensG);

        token.finishMinting();
        finished = true;
    }

    function claimTokensE(uint8 order) onlyOwner public {
        require(finished);
        require(order >= 1 && order <= 8);
        require(!completedE[order]);

        // On January 03, 2019 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 1) {
            // Thursday, 3 January 2019 г., 23:59:00
            require(now >= endICODate + 15724800);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On July 05, 2019 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 2) {
            // Friday, 5 July 2019 г., 23:59:00
            require(now >= endICODate + 31536000);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On January 03, 2020 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 3) {
            // Friday, 3 January 2020 г., 23:59:00
            require(now >= endICODate + 47260800);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On July 04, 2020 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 4) {
            // Saturday, 4 July 2020 г., 23:59:00
            require(now >= endICODate + 63072000);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On January 02, 2021 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 5) {
            // Saturday, 2 January 2021 г., 23:59:00
            require(now >= endICODate + 78796800);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On July 04, 2021 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 6) {
            // Sunday, 4 July 2021 г., 23:59:00
            require(now >= endICODate + 94608000);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On January 02, 2022 @ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 7) {
            // Sunday, 2 January 2022 г., 23:59:00
            require(now >= endICODate + 110332800);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
        // On July 04, 2022@ UTC 23:59 = FTST*2625/100000 (2.625% of final total supply of tokens) to the wallet [E].
        if (order == 8) {
            // Monday, 4 July 2022 г., 23:59:00
            require(now >= endICODate + 126144000);
            token.transfer(walletE, paymentSizeE);
            completedE[order] = true;
        }
    }

    function claimTokensBC(uint8 order) onlyOwner public {
        require(finished);
        require(order >= 1 && order <= 4);
        require(!completedBC[order]);

        // On January 03, 2019 @ UTC 23:59 = FTST*25/10000 (0.25% of final total supply of tokens) to the wallet [B] and FTST*215/10000 (2.15% of final total supply of tokens) to the wallet [C].
        if (order == 1) {
            // Thursday, 3 January 2019 г., 23:59:00
            require(now >= endICODate + 15724800);
            token.transfer(walletB, paymentSizeB);
            token.transfer(walletC, paymentSizeC);
            completedBC[order] = true;
        }
        // On July 05, 2019 @ UTC 23:59 = FTST*25/10000 (0.25% of final total supply of tokens) to the wallet [B] and FTST*215/10000 (2.15% of final total supply of tokens) to the wallet [C].
        if (order == 2) {
            // Friday, 5 July 2019 г., 23:59:00
            require(now >= endICODate + 31536000);
            token.transfer(walletB, paymentSizeB);
            token.transfer(walletC, paymentSizeC);
            completedBC[order] = true;
        }
        // On January 03, 2020 @ UTC 23:59 = FTST*25/10000 (0.25% of final total supply of tokens) to the wallet [B] and FTST*215/10000 (2.15% of final total supply of tokens) to the wallet [C].
        if (order == 3) {
            // Friday, 3 January 2020 г., 23:59:00
            require(now >= endICODate + 47260800);
            token.transfer(walletB, paymentSizeB);
            token.transfer(walletC, paymentSizeC);
            completedBC[order] = true;
        }
        // On July 04, 2020 @ UTC 23:59 = FTST*25/10000 (0.25% of final total supply of tokens) to the wallet [B] and FTST*215/10000 (2.15% of final total supply of tokens) to the wallet [C].
        if (order == 4) {
            // Saturday, 4 July 2020 г., 23:59:00
            require(now >= endICODate + 63072000);
            token.transfer(walletB, paymentSizeB);
            token.transfer(walletC, paymentSizeC);
            completedBC[order] = true;
        }
    }
}
function postICO(
        address _token,
        address _walletE,
        address _walletB,
        address _walletC,
        address _walletF,
        address _walletG,
        uint256 _endICODate
    ) public {
        require(_token != address(0));
        require(_walletE != address(0));
        require(_walletB != address(0));
        require(_walletC != address(0));
        require(_walletF != address(0));
        require(_walletG != address(0));
        require(_endICODate >= now);

        token = Token(_token);
        endICODate = _endICODate;

        walletE = _walletE;
        walletB = _walletB;
        walletC = _walletC;
        walletF = _walletF;
        walletG = _walletG;
    }
/**
 * @dev _endICODate should be 1530835140
 */