{
    "Function": "buyAllAmount",
    "File": "contracts/RubiconMarket.sol",
    "Parent Contracts": [
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol",
        "contracts/RubiconMarket.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "wdiv",
        "sub",
        "rdiv",
        "require(bool)",
        "add",
        "require(bool)",
        "require(bool,string)",
        "add",
        "take",
        "take",
        "rmul",
        "getBestOffer"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function buyAllAmount(\n        ERC20 buy_gem,\n        uint256 buy_amt,\n        ERC20 pay_gem,\n        uint256 max_fill_amount\n    ) external returns (uint256 fill_amt) {\n        require(!locked, \"Reentrancy attempt\");\n        uint256 offerId;\n        while (buy_amt > 0) {\n            //Meanwhile there is amount to buy\n            offerId = getBestOffer(buy_gem, pay_gem); //Get the best offer for the token pair\n            require(offerId != 0);\n\n            // There is a chance that buy_amt is smaller than 1 wei of the other token\n            if (\n                buy_amt * 1 ether <\n                wdiv(offers[offerId].pay_amt, offers[offerId].buy_amt)\n            ) {\n                break; //We consider that all amount is sold\n            }\n            if (buy_amt >= offers[offerId].pay_amt) {\n                //If amount to buy is higher or equal than current offer amount to sell\n                fill_amt = add(fill_amt, offers[offerId].buy_amt); //Add amount sold to acumulator\n                buy_amt = sub(buy_amt, offers[offerId].pay_amt); //Decrease amount to buy\n                take(bytes32(offerId), uint128(offers[offerId].pay_amt)); //We take the whole offer\n            } else {\n                //if lower\n                fill_amt = add(\n                    fill_amt,\n                    rmul(\n                        buy_amt * 10**9,\n                        rdiv(offers[offerId].buy_amt, offers[offerId].pay_amt)\n                    ) / 10**9\n                ); //Add amount sold to acumulator\n                take(bytes32(offerId), uint128(buy_amt)); //We take the portion of the offer that we need\n                buy_amt = 0; //All amount is bought\n            }\n        }\n        require(fill_amt <= max_fill_amount);\n    }"
}