{
    "Function": "getPayAmount",
    "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": [
        "getWorseOffer",
        "add",
        "add",
        "require(bool)",
        "sub",
        "getBestOffer",
        "rmul",
        "rdiv"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function getPayAmount(\n        ERC20 pay_gem,\n        ERC20 buy_gem,\n        uint256 buy_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 (buy_amt > offers[offerId].pay_amt) {\n            fill_amt = add(fill_amt, offers[offerId].buy_amt); //Add amount to pay accumulator\n            buy_amt = sub(buy_amt, offers[offerId].pay_amt); //Decrease amount to buy\n            if (buy_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                buy_amt * 10**9,\n                rdiv(offers[offerId].buy_amt, offers[offerId].pay_amt)\n            ) / 10**9\n        ); //Add proportional amount of last offer to pay accumulator\n    }"
}