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