contract Redeem is Deposit {

    event eAllowedMTU(address LeavingAway, uint NoOfTokens);
    event eRedeem(address Investor, uint NoOfTokens, uint withdrawVal);

    // wei per MTU // rate will be 0 to stop redeeming
    uint256 public redeemRate;
    uint256 public ethRedeemed;
    uint256 public unRedeemedMTU;
    uint256 public RedeemingTimeLimit;

    mapping(address => uint256) public Redeemer;    
    
    function SetRedeemRate(uint256 weiAmt) onlyAdmin public {
        redeemRate = weiAmt;
        // 7 days into seconds to currenct time in unix epoch seconds
        RedeemingTimeLimit = block.timestamp + 7 * 24 * 60 * 60;
    }

    // allow MTU transfer
    function DepositMTU(uint256 NoOfTokens) paused public {
        require(block.timestamp > RedeemingTimeLimit);
        address tokenAddress = getAddress("unit");
        token tokenFunction = token(tokenAddress);
        tokenFunction.transferFrom(msg.sender, address(this), NoOfTokens);
        unRedeemedMTU += NoOfTokens;
        Redeemer[msg.sender] += NoOfTokens;
        emit eAllowedMTU(msg.sender, NoOfTokens);
    }

    // redeem MTU
    function RedeemMTU(bool redeem) paused public {
        uint256 AppliedUnits = Redeemer[msg.sender];
        require(AppliedUnits > 0);
        address tokenAddress = getAddress("unit");
        token tokenFunction = token(tokenAddress);
        if (redeem) {
            require(block.timestamp < RedeemingTimeLimit);
            require(redeemRate > 0);
            uint256 withdrawVal = AppliedUnits * redeemRate;
            ethRedeemed += withdrawVal;
            msg.sender.transfer(withdrawVal);
            emit eRedeem(msg.sender, AppliedUnits, withdrawVal);
        } else {
            tokenFunction.transfer(msg.sender, AppliedUnits);
        }
        Redeemer[msg.sender] = 0;
        unRedeemedMTU -= AppliedUnits;
    }

    function getRedeemEst(address Claimer, uint256 NoOfTokens) public view returns(uint256 RedeemEstimate) {
        uint WithdrawEther = redeemRate * NoOfTokens;
        return WithdrawEther;
    }

}
function RedeemMTU(bool redeem) paused public {
    uint256 AppliedUnits = Redeemer[msg.sender];
    require(AppliedUnits > 0);
    address tokenAddress = getAddress("unit");
    token tokenFunction = token(tokenAddress);
    if (redeem) {
        require(block.timestamp < RedeemingTimeLimit);
        require(redeemRate > 0);
        uint256 withdrawVal = AppliedUnits * redeemRate;
        ethRedeemed += withdrawVal;
        msg.sender.transfer(withdrawVal);
        emit eRedeem(msg.sender, AppliedUnits, withdrawVal);
    } else {
        tokenFunction.transfer(msg.sender, AppliedUnits);
    }
    Redeemer[msg.sender] = 0;
    unRedeemedMTU -= AppliedUnits;
}

// redeem MTU