{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/Witch.sol",
    "Parent Contracts": [
        "contracts/utils/access/AccessControl.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract Witch is AccessControl() {\n    using WMul for uint256;\n    using WDiv for uint256;\n    using WDivUp for uint256;\n    using CastU256U128 for uint256;\n    using CastU256U32 for uint256;\n\n    event IlkSet(bytes6 indexed ilkId, uint32 duration, uint64 initialOffer, uint128 dust);\n    event Bought(bytes12 indexed vaultId, address indexed buyer, uint256 ink, uint256 art);\n    event Auctioned(bytes12 indexed vaultId, uint256 indexed start);\n  \n    struct Auction {\n        address owner;\n        uint32 start;\n    }\n\n    struct Ilk {\n        uint32 duration;      // Time that auctions take to go to minimal price and stay there.\n        uint64 initialOffer;  // Proportion of collateral that is sold at auction start (1e18 = 100%)\n        uint128 dust;         // Minimum collateral that must be left when buying, unless buying all\n    }\n\n    // uint32 public duration = 4 * 60 * 60; // Time that auctions take to go to minimal price and stay there.\n    // uint64 public initialOffer = 5e17;  // Proportion of collateral that is sold at auction start (1e18 = 100%)\n    // uint128 public dust;                     // Minimum collateral that must be left when buying, unless buying all\n\n    ICauldron immutable public cauldron;\n    ILadle immutable public ladle;\n    mapping(bytes12 => Auction) public auctions;\n    mapping(bytes6 => Ilk) public ilks;\n\n    constructor (ICauldron cauldron_, ILadle ladle_) {\n        cauldron = cauldron_;\n        ladle = ladle_;\n    }\n\n    /// @dev Set the auction duration to calculate liquidation prices\n    /* function setDuration(uint32 duration_) external auth {\n        duration = duration_;\n        emit DurationSet(duration_);\n    }\n\n    /// @dev Set the proportion of the collateral that will be sold at auction start\n    function setInitialOffer(uint64 initialOffer_) external auth {\n        require (initialOffer_ <= 1e18, \"Only at or under 100%\");\n        initialOffer = initialOffer_;\n        emit InitialOfferSet(initialOffer_);\n    }\n\n    /// @dev Set the minimum collateral that must be left when buying, unless buying all\n    function setDust(uint128 dust_) external auth {\n        dust = dust_;\n        emit DustSet(dust_);\n    } */\n\n    /// @dev Set:\n    ///  - the auction duration to calculate liquidation prices\n    ///  - the proportion of the collateral that will be sold at auction start\n    ///  - the minimum collateral that must be left when buying, unless buying all\n    function setIlk(bytes6 ilkId, uint32 duration, uint64 initialOffer, uint128 dust) external auth {\n        require (initialOffer <= 1e18, \"Only at or under 100%\");\n        ilks[ilkId] = Ilk({\n            duration: duration,\n            initialOffer: initialOffer,\n            dust: dust\n        });\n        emit IlkSet(ilkId, duration, initialOffer, dust);\n    }\n\n    /// @dev Put an undercollateralized vault up for liquidation.\n    function auction(bytes12 vaultId)\n        external\n    {\n        require (auctions[vaultId].start == 0, \"Vault already under auction\");\n        DataTypes.Vault memory vault = cauldron.vaults(vaultId);\n        auctions[vaultId] = Auction({\n            owner: vault.owner,\n            start: block.timestamp.u32()\n        });\n        cauldron.grab(vaultId, address(this));\n        emit Auctioned(vaultId, block.timestamp.u32());\n    }\n\n    /// @dev Pay `base` of the debt in a vault in liquidation, getting at least `min` collateral.\n    function buy(bytes12 vaultId, uint128 base, uint128 min)\n        external\n        returns (uint256 ink)\n    {\n        DataTypes.Balances memory balances_ = cauldron.balances(vaultId);\n        DataTypes.Vault memory vault_ = cauldron.vaults(vaultId);\n        DataTypes.Series memory series_ = cauldron.series(vault_.seriesId);\n        Auction memory auction_ = auctions[vaultId];\n        Ilk memory ilk_ = ilks[vault_.ilkId];\n\n        require (balances_.art > 0, \"Nothing to buy\");                                      // Cheapest way of failing gracefully if given a non existing vault\n        uint256 art = cauldron.debtFromBase(vault_.seriesId, base);\n        {\n            uint256 elapsed = uint32(block.timestamp) - auction_.start;                      // Auctions will malfunction on the 7th of February 2106, at 06:28:16 GMT, we should replace this contract before then.\n            uint256 price = inkPrice(balances_, ilk_.initialOffer, ilk_.duration, elapsed);\n            ink = uint256(art).wmul(price);                                                    // Calculate collateral to sell. Using divdrup stops rounding from leaving 1 stray wei in vaults.\n            require (ink >= min, \"Not enough bought\");\n            require (ink == balances_.ink || balances_.ink - ink >= ilk_.dust, \"Leaves dust\");\n        }\n\n        cauldron.slurp(vaultId, ink.u128(), art.u128());                                            // Remove debt and collateral from the vault\n        settle(msg.sender, vault_.ilkId, series_.baseId, ink.u128(), base);                   // Move the assets\n        if (balances_.art - art == 0) {                                                             // If there is no debt left, return the vault with the collateral to the owner\n            cauldron.give(vaultId, auction_.owner);\n            delete auctions[vaultId];\n        }\n\n        emit Bought(vaultId, msg.sender, ink, art);\n    }\n\n\n    /// @dev Pay all debt from a vault in liquidation, getting at least `min` collateral.\n    function payAll(bytes12 vaultId, uint128 min)\n        external\n        returns (uint256 ink)\n    {\n        DataTypes.Balances memory balances_ = cauldron.balances(vaultId);\n        DataTypes.Vault memory vault_ = cauldron.vaults(vaultId);\n        DataTypes.Series memory series_ = cauldron.series(vault_.seriesId);\n        Auction memory auction_ = auctions[vaultId];\n        Ilk memory ilk_ = ilks[vault_.ilkId];\n\n        require (balances_.art > 0, \"Nothing to buy\");                                      // Cheapest way of failing gracefully if given a non existing vault\n        {\n            uint256 elapsed = uint32(block.timestamp) - auction_.start;                      // Auctions will malfunction on the 7th of February 2106, at 06:28:16 GMT, we should replace this contract before then.\n            uint256 price = inkPrice(balances_, ilk_.initialOffer, ilk_.duration, elapsed);\n            ink = uint256(balances_.art).wmul(price);                                                    // Calculate collateral to sell. Using divdrup stops rounding from leaving 1 stray wei in vaults.\n            require (ink >= min, \"Not enough bought\");\n            require (ink == balances_.ink || balances_.ink - ink >= ilk_.dust, \"Leaves dust\");\n        }\n\n        cauldron.slurp(vaultId, ink.u128(), balances_.art);                                                     // Remove debt and collateral from the vault\n        settle(msg.sender, vault_.ilkId, series_.baseId, ink.u128(), cauldron.debtToBase(vault_.seriesId, balances_.art));                                        // Move the assets\n        cauldron.give(vaultId, auction_.owner);\n\n        emit Bought(vaultId, msg.sender, ink, balances_.art); // Still the initially read `art` value, not the updated one\n    }\n\n    /// @dev Move base from the buyer to the protocol, and collateral from the protocol to the buyer\n    function settle(address user, bytes6 ilkId, bytes6 baseId, uint128 ink, uint128 art)\n        private\n    {\n        if (ink != 0) {                                                                     // Give collateral to the user\n            IJoin ilkJoin = ladle.joins(ilkId);\n            require (ilkJoin != IJoin(address(0)), \"Join not found\");\n            ilkJoin.exit(user, ink);\n        }\n        if (art != 0) {                                                                     // Take underlying from user\n            IJoin baseJoin = ladle.joins(baseId);\n            require (baseJoin != IJoin(address(0)), \"Join not found\");\n            baseJoin.join(user, art);\n        }    \n    }\n\n    /// @dev Price of a collateral unit, in underlying, at the present moment, for a given vault\n    ///            ink                     min(auction, elapsed)\n    /// price = (------- * (p + (1 - p) * -----------------------))\n    ///            art                          auction\n    function inkPrice(DataTypes.Balances memory balances, uint256 initialOffer_, uint256 duration_, uint256 elapsed)\n        private pure\n        returns (uint256 price)\n    {\n            uint256 term1 = uint256(balances.ink).wdiv(balances.art);\n            uint256 dividend2 = duration_ < elapsed ? duration_ : elapsed;\n            uint256 divisor2 = duration_;\n            uint256 term2 = initialOffer_ + (1e18 - initialOffer_).wmul(dividend2.wdiv(divisor2));\n            price = term1.wmul(term2);\n    }\n}"
}