contract HydroTokenSwap is Ownable {
    using SafeMath for uint256;
    uint256 public totalAmountSwapped;

    address constant Hydro_ADDRESS= 0x946112efaB61C3636CBD52DE2E1392D7A75A6f01;
    address Main_ADDRESS= 0x4aE8bfB81205837DE1437De26D02E5ca87694714;
    bool public isActive;
    
    struct User {
      address userAdd;
      uint256 totalAmountSwapped;
    }
    
    //a mapping to keep the details of users
    mapping(address => User) public userDetails;

    //main event that is emitted after a successful deposit
    event SwapDeposit(address indexed depositor, uint256 outputAmount);
    
    //make sure contract is open to swaps
    modifier notActive {
        require(isActive!=true, "Swapping is currently paused");
        _;
    }



    /**
     * @dev Allows the user to deposit some amount of Hydro tokens. Records user/swap data and emits a SwapDeposit event.
     * @param amount Amount of input tokens to be swapped.
     */
    function swap( uint256 amount) external  {
        require (isActive==true);
        require(amount > 0, "Input amount must be positive.");
        uint256 outputAmount = amount;
        require(outputAmount > 0, "Amount too small.");
        require(IERC20(Hydro_ADDRESS).transferFrom(msg.sender, Main_ADDRESS, amount), "Transferring Hydro tokens from user failed");
        userDetails[msg.sender].totalAmountSwapped+=amount;
        totalAmountSwapped+=amount;
        emit SwapDeposit(msg.sender,amount);
        
    }
    
    function totalAmountSwappedInContract() public view returns(uint256){
        return totalAmountSwapped;
    }
    
  //allow the owner to activate the escrow contract
    function openEscrow() public onlyOwner notActive returns(bool){
        isActive=true;
    }
    
     //allow the owner to deactivate the escrow contract
    function closeEscrow() public onlyOwner returns(bool){
        isActive=false;
    }
    
    //allow owner to rescue any tokens sent to the contract
    function transferOut(address _token) public onlyOwner returns(bool){
        IERC20 token= IERC20(_token); 
        uint256 balance= token.balanceOf(address(this));
        require(token.transfer(msg.sender,balance),"HydroSwap: Token Transfer error");
return true;
    }
    /**
    
    !!!!!!!!!!!!!!!!!!
    !!!!!CAUTION!!!!!!
    !!!!!!!!!!!!!!!!!!
    
    **/
     //allow owner to change central wallet
    
    function changeCentralWallet(address _newWallet) public onlyOwner returns(bool){
        require(_newWallet!=address(0),"Error: Burn address not supported");
        Main_ADDRESS=_newWallet;
        return true;
    }

  
}
/**
 * @title Hydro ERC20-BEP20 Swap Contract
 */
function openEscrow() public onlyOwner notActive returns(bool){
    isActive=true;
}

//allow the owner to activate the escrow contract