contract ReserveFund is SafeMath{//Reserve fund
    address payable public owner;   
    address payable public manager; 
    address public  issueContract;
    address public  reciveTokenTo;
    /* Initializes contract*/
    constructor () public {  
        owner = msg.sender;
    }  

    // this function called every time anyone sends a transaction to this contract
    function () external payable 
    {        
    }    
    
    function changeOwner(address payable _add)public returns (bool success) {
        require (msg.sender == owner) ;
        require (_add != address(0x0)) ;
        owner = _add ;
        return true;
    }

    function changeManager(address payable _add)public returns (bool success) {
        require (msg.sender == owner) ;
        require (_add != address(0x0)) ;
        manager = _add ;
        return true;
    }

    function changeIssueContract(address payable _add)public returns (bool success) {
        require (msg.sender == owner) ;
        require (_add != address(0x0)) ;
        issueContract = _add ;
        return true;
    }

    function changeReciveTokenTo(address payable _add)public returns (bool success) {
        require (msg.sender == owner) ;
        require (_add != address(0x0)) ;
        reciveTokenTo = _add ;
        return true;
    }

    function doRedeemNPA(uint256 _amount,address _token,bool _isReceiveToken)public returns (bool success) {		
        require (msg.sender == manager) ;
        require (reciveTokenTo != address(0x0)) ;
        TokenIssue(issueContract).redeemNPA(_amount,_token,_isReceiveToken);
        if(_isReceiveToken == true){
            bool isTransferFrom = TokenIssue(issueContract).isTransferFrom(_token);
            uint _value = safeDiv(safeMul(_amount , safePower(10,TokenIssue(issueContract).tokenDecimals(_token))) , safePower(10,TokenIssue(issueContract).decimals())) ;
              if(isTransferFrom == true){
                   Token(_token).transfer(reciveTokenTo,_value); 
              }else{
                   TokenUSDT(_token).transfer(reciveTokenTo,_value); 
              }             
        }
        return true;
    }

    function doIssue(address _token, uint256 _amount)public returns (bool success) {
        require (msg.sender == manager) ;
        TokenIssue(issueContract).issue(_token,_amount);
        return true;
    }

    function approveToken(address _token, uint256 _amount)public returns (bool success) {
        require (msg.sender == manager) ;
        bool isTransferFrom = TokenIssue(issueContract).isTransferFrom(_token);
        if(isTransferFrom == true){
              Token(_token).approve(issueContract,_amount);
        }else{
            TokenUSDT(_token).approve(issueContract,_amount);
        }      
        return true;
    }
    
    function doRedeem(uint256 _amount)public returns (bool success) {
        require (msg.sender == manager) ;
        TokenIssue(issueContract).redeem(_amount);
        return true;
    }
}
function () external payable 
{        
}    

// this function called every time anyone sends a transaction to this contract