contract FeeApprover is OwnableUpgradeSafe {
    using SafeMath for uint256;

    function initialize(
        address _HDCOREAddress,
        address _WETHAddress,
        address _hdcoreVaultAddress
    ) public initializer {
        OwnableUpgradeSafe.__Ownable_init();
        hdcoreTokenAddress = _HDCOREAddress;
        WETHAddress = _WETHAddress;
        tokenUniswapPair = IUniswapV2Factory(address(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f)).getPair(WETHAddress,hdcoreTokenAddress);
        hdcoreVaultAddress = _hdcoreVaultAddress;
        feePercentX100 = 15;
        paused = false; // We start paused until sync post LGE happens.
    }

    address tokenUniswapPair;
    IUniswapV2Factory public uniswapFactory;
    address internal WETHAddress;
    address hdcoreTokenAddress;
    address hdcoreVaultAddress;
    uint8 public feePercentX100;
    uint256 public lastTotalSupplyOfLPTokens;
    bool paused;

    // Pausing transfers of the token
    function setPaused(bool _pause) public onlyOwner {
        paused = _pause;
    }

    function setFeeMultiplier(uint8 _feeMultiplier) public onlyOwner {
        feePercentX100 = _feeMultiplier;
    }

    function setHdcoreVaultAddress(address _hdcoreVaultAddress) public onlyOwner {
        hdcoreVaultAddress = _hdcoreVaultAddress;
    }

    function sync() public {
        uint256 _LPSupplyOfPairTotal = IERC20(tokenUniswapPair).totalSupply();
        lastTotalSupplyOfLPTokens = _LPSupplyOfPairTotal;
    }

    function calculateAmountsAfterFee(
        address sender,
        address recipient, // unusued maybe use din future
        uint256 amount
    )
        public
        returns (
          uint256 transferToAmount,
          uint256 transferToFeeDistributorAmount
        )
    {
        require(paused == false, "FEE APPROVER: Transfers Paused");
        uint256 _LPSupplyOfPairTotal = IERC20(tokenUniswapPair).totalSupply();

        if(sender == tokenUniswapPair) {
            require(lastTotalSupplyOfLPTokens <= _LPSupplyOfPairTotal, "Liquidity withdrawals forbidden");
        }

        // Dont have a fee when hdcoreVault is sending, or infinite loop
        // And when pair is sending ( buys are happening, do not tax on it)
        if(sender == hdcoreVaultAddress || sender == tokenUniswapPair ) {
            console.log("Sending without fee");
            transferToFeeDistributorAmount = 0;
            transferToAmount = amount;
        } else {
            console.log("Normal fee transfer");
            transferToFeeDistributorAmount = amount.mul(feePercentX100).div(1000);
            transferToAmount = amount.sub(transferToFeeDistributorAmount);
        }

        lastTotalSupplyOfLPTokens = _LPSupplyOfPairTotal;
    }
}
function setPaused(bool _pause) public onlyOwner {
    paused = _pause;
}

// Pausing transfers of the token