{
    "Function": "_swap",
    "File": "contracts/RubiconRouter.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "SafeMath",
        "RubiconMarket",
        "ERC20",
        "SafeMath",
        "ERC20",
        "SafeMath"
    ],
    "Internal Calls": [
        "abi.encodePacked()",
        "keccak256(bytes)",
        "approveAssetOnMarket",
        "require(bool,string)"
    ],
    "Library Calls": [
        "sub",
        "mul",
        "div"
    ],
    "Low-Level Calls": [],
    "Code": "function _swap(\n        uint256 pay_amt,\n        uint256 buy_amt_min,\n        address[] calldata route, // First address is what is being payed, Last address is what is being bought\n        uint256 expectedMarketFeeBPS,\n        address to // Recipient of swap outputs!\n    ) internal returns (uint256) {\n        address _market = RubiconMarketAddress;\n        uint256 currentAmount = 0;\n        for (uint256 i = 0; i < route.length - 1; i++) {\n            (address input, address output) = (route[i], route[i + 1]);\n            uint256 _pay = i == 0\n                ? pay_amt\n                : (\n                    currentAmount.sub(\n                        currentAmount.mul(expectedMarketFeeBPS).div(10000)\n                    )\n                );\n            if (ERC20(input).allowance(address(this), _market) == 0) {\n                approveAssetOnMarket(input);\n            }\n            uint256 fillAmount = RubiconMarket(_market).sellAllAmount(\n                ERC20(input),\n                _pay,\n                ERC20(output),\n                0 //naively assume no fill_amt here for loop purposes?\n            );\n            currentAmount = fillAmount;\n        }\n        require(currentAmount >= buy_amt_min, \"didnt clear buy_amt_min\");\n\n        // send tokens back to sender if not keeping here\n        if (to != address(this)) {\n            ERC20(route[route.length - 1]).transfer(to, currentAmount);\n        }\n\n        emit LogSwap(\n            pay_amt,\n            route[0],\n            buy_amt_min,\n            route[route.length - 1],\n            keccak256(abi.encodePacked(route[0], route[route.length - 1])),\n            currentAmount,\n            to\n        );\n        return currentAmount;\n    }"
}