{
    "Function": "getBuyAmount",
    "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": [
        "add",
        "add",
        "getBestOffer",
        "sub",
        "require(bool)",
        "rmul",
        "rdiv",
        "getWorseOffer"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function getBuyAmount(\n        ERC20 buy_gem,\n        ERC20 pay_gem,\n        uint256 pay_amt\n    ) external view returns (uint256 fill_amt) {\n        uint256 offerId = getBestOffer(buy_gem, pay_gem); //Get best offer for the token pair\n        while (pay_amt > offers[offerId].buy_amt) {\n            fill_amt = add(fill_amt, offers[offerId].pay_amt); //Add amount to buy accumulator\n            pay_amt = sub(pay_amt, offers[offerId].buy_amt); //Decrease amount to pay\n            if (pay_amt > 0) {\n                //If we still need more offers\n                offerId = getWorseOffer(offerId); //We look for the next best offer\n                require(offerId != 0); //Fails if there are not enough offers to complete\n            }\n        }\n        fill_amt = add(\n            fill_amt,\n            rmul(\n                pay_amt * 10**9,\n                rdiv(offers[offerId].pay_amt, offers[offerId].buy_amt)\n            ) / 10**9\n        ); //Add proportional amount of last offer to buy accumulator\n    }"
}