{
    "Function": "withdraw",
    "File": "contracts/GeVault.sol",
    "Parent Contracts": [
        "contracts/openzeppelin-solidity/contracts/security/ReentrancyGuard.sol",
        "contracts/openzeppelin-solidity/contracts/access/Ownable.sol",
        "contracts/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol",
        "contracts/openzeppelin-solidity/contracts/token/ERC20/extensions/IERC20Metadata.sol",
        "contracts/openzeppelin-solidity/contracts/token/ERC20/IERC20.sol",
        "contracts/openzeppelin-solidity/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [
        "SafeERC20",
        "SafeERC20",
        "IPriceOracle",
        "IWETH",
        "ERC20"
    ],
    "Internal Calls": [
        "balanceOf",
        "getTVL",
        "nonReentrant",
        "poolMatchesOracle",
        "require(bool,string)",
        "getAdjustedBaseFee",
        "removeFromAllTicks",
        "require(bool,string)",
        "deployAssets",
        "totalSupply",
        "balanceOf",
        "_burn",
        "require(bool,string)"
    ],
    "Library Calls": [
        "safeTransfer",
        "safeTransfer"
    ],
    "Low-Level Calls": [],
    "Code": "function withdraw(uint liquidity, address token) public nonReentrant returns (uint amount) {\n    require(poolMatchesOracle(), \"GEV: Oracle Error\");\n    if (liquidity == 0) liquidity = balanceOf(msg.sender);\n    require(liquidity <= balanceOf(msg.sender), \"GEV: Insufficient Balance\");\n    require(liquidity > 0, \"GEV: Withdraw Zero\");\n    \n    uint vaultValueX8 = getTVL();\n    uint valueX8 = vaultValueX8 * liquidity / totalSupply();\n    amount = valueX8 * 10**ERC20(token).decimals() / oracle.getAssetPrice(token);\n    uint fee = amount * getAdjustedBaseFee(token == address(token1)) / 1e4;\n    \n    _burn(msg.sender, liquidity);\n    removeFromAllTicks();\n    ERC20(token).safeTransfer(treasury, fee);\n    uint bal = amount - fee;\n\n    if (token == address(WETH)){\n      WETH.withdraw(bal);\n      payable(msg.sender).transfer(bal);\n    }\n    else {\n      ERC20(token).safeTransfer(msg.sender, bal);\n    }\n    \n    // if pool enabled, deploy assets in ticks, otherwise just let assets sit here until totally withdrawn\n    if (isEnabled) deployAssets();\n    emit Withdraw(msg.sender, token, amount, liquidity);\n  }"
}