{
    "Function": "swap",
    "File": "contracts/external/UniswapV2Pair.sol",
    "Parent Contracts": [
        "contracts/external/UniswapV2ERC20.sol",
        "contracts/interfaces/external/uniswap/IUniswapV2Pair.sol",
        "contracts/interfaces/external/uniswap/IUniswapV2ERC20.sol"
    ],
    "High-Level Calls": [
        "IUniswapV2Callee",
        "IERC20",
        "IERC20"
    ],
    "Internal Calls": [
        "_safeTransfer",
        "_safeTransfer",
        "require(bool,string)",
        "_update",
        "require(bool,string)",
        "lock",
        "require(bool,string)",
        "require(bool,string)",
        "getReserves",
        "require(bool,string)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function swap(\n        uint256 amount0Out,\n        uint256 amount1Out,\n        address to,\n        bytes calldata data\n    ) external lock {\n        require(\n            amount0Out > 0 || amount1Out > 0,\n            \"UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT\"\n        );\n        (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n        require(\n            amount0Out < _reserve0 && amount1Out < _reserve1,\n            \"UniswapV2: INSUFFICIENT_LIQUIDITY\"\n        );\n\n        uint256 balance0;\n        uint256 balance1;\n        {\n            // scope for _token{0,1}, avoids stack too deep errors\n            address _token0 = token0;\n            address _token1 = token1;\n            require(to != _token0 && to != _token1, \"UniswapV2: INVALID_TO\");\n            if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens\n            if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens\n            if (data.length > 0)\n                IUniswapV2Callee(to).uniswapV2Call(\n                    msg.sender,\n                    amount0Out,\n                    amount1Out,\n                    data\n                );\n            balance0 = IERC20(_token0).balanceOf(address(this));\n            balance1 = IERC20(_token1).balanceOf(address(this));\n        }\n        uint256 amount0In = balance0 > _reserve0 - amount0Out\n            ? balance0 - (_reserve0 - amount0Out)\n            : 0;\n        uint256 amount1In = balance1 > _reserve1 - amount1Out\n            ? balance1 - (_reserve1 - amount1Out)\n            : 0;\n        require(\n            amount0In > 0 || amount1In > 0,\n            \"UniswapV2: INSUFFICIENT_INPUT_AMOUNT\"\n        );\n        {\n            // scope for reserve{0,1}Adjusted, avoids stack too deep errors\n            uint256 balance0Adjusted = (balance0 * 1000) - (amount0In * 3);\n            uint256 balance1Adjusted = (balance1 * 1000) - (amount1In * 3);\n            require(\n                balance0Adjusted * balance1Adjusted >=\n                    uint256(_reserve0) * _reserve1 * 1000**2,\n                \"UniswapV2: K\"\n            );\n        }\n\n        _update(balance0, balance1, _reserve0, _reserve1);\n        emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);\n    }"
}