{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/Auction/AuctionEscapeHatch.sol",
    "Parent Contracts": [
        "contracts/StabilizedPoolExtensions/DexHandlerExtension.sol",
        "contracts/StabilizedPoolExtensions/AuctionExtension.sol",
        "contracts/StabilizedPoolExtensions/StabilizedPoolUnit.sol",
        "contracts/Permissions.sol",
        "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol",
        "lib/openzeppelin-contracts/contracts/access/AccessControl.sol",
        "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol",
        "lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol",
        "lib/openzeppelin-contracts/contracts/access/IAccessControl.sol",
        "lib/openzeppelin-contracts/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract AuctionEscapeHatch is\n  StabilizedPoolUnit,\n  AuctionExtension,\n  DexHandlerExtension\n{\n  using SafeERC20 for ERC20;\n\n  uint256 public maxEarlyExitBps = 2000; // 20%\n  uint256 public cooloffPeriod = 60 * 60 * 24; // 24 hours\n\n  mapping(uint256 => AuctionExits) internal auctionEarlyExits;\n\n  event EarlyExit(address account, uint256 amount, uint256 received);\n  event SetEarlyExitBps(uint256 earlyExitBps);\n  event SetCooloffPeriod(uint256 period);\n\n  constructor(\n    address timelock,\n    address repository,\n    address poolFactory\n  ) StabilizedPoolUnit(timelock, repository, poolFactory) {}\n\n  function setupContracts(\n    address _malt,\n    address _collateralToken,\n    address _auction,\n    address _dexHandler,\n    address pool\n  ) external onlyRoleMalt(POOL_FACTORY_ROLE, \"Must be pool factory\") {\n    require(!contractActive, \"EscapeHatch: Already setup\");\n    require(_malt != address(0), \"EscapeHatch: Malt addr(0)\");\n    require(_collateralToken != address(0), \"EscapeHatch: Col addr(0)\");\n    require(_auction != address(0), \"EscapeHatch: Auction addr(0)\");\n    require(_dexHandler != address(0), \"EscapeHatch: DexHandler addr(0)\");\n\n    contractActive = true;\n\n    malt = IBurnMintableERC20(_malt);\n    collateralToken = ERC20(_collateralToken);\n    auction = IAuction(_auction);\n    dexHandler = IDexHandler(_dexHandler);\n\n    (, address updater, ) = poolFactory.getPool(pool);\n    _setPoolUpdater(updater);\n  }\n\n  function exitEarly(\n    uint256 _auctionId,\n    uint256 amount,\n    uint256 minOut\n  ) external nonReentrant onlyActive {\n    AuctionExits storage auctionExits = auctionEarlyExits[_auctionId];\n\n    (, uint256 maltQuantity, uint256 newAmount) = earlyExitReturn(\n      msg.sender,\n      _auctionId,\n      amount\n    );\n\n    require(maltQuantity > 0, \"ExitEarly: Insufficient output\");\n\n    malt.mint(address(dexHandler), maltQuantity);\n    // Early exits happen below peg in recovery mode\n    // So risk of sandwich is very low\n    uint256 amountOut = dexHandler.sellMalt(maltQuantity, 5000);\n\n    require(amountOut >= minOut, \"EarlyExit: Insufficient output\");\n\n    auctionExits.exitedEarly += newAmount;\n    auctionExits.earlyExitReturn += amountOut;\n    auctionExits.maltUsed += maltQuantity;\n    auctionExits.accountExits[msg.sender].exitedEarly += newAmount;\n    auctionExits.accountExits[msg.sender].earlyExitReturn += amountOut;\n    auctionExits.accountExits[msg.sender].maltUsed += maltQuantity;\n\n    auction.accountExit(msg.sender, _auctionId, newAmount);\n\n    collateralToken.safeTransfer(msg.sender, amountOut);\n    emit EarlyExit(msg.sender, newAmount, amountOut);\n  }\n\n  function earlyExitReturn(\n    address account,\n    uint256 _auctionId,\n    uint256 amount\n  )\n    public\n    view\n    returns (\n      uint256 exitAmount,\n      uint256 maltValue,\n      uint256 usedAmount\n    )\n  {\n    // We don't need all the values\n    (\n      ,\n      ,\n      ,\n      ,\n      ,\n      uint256 pegPrice,\n      ,\n      uint256 auctionEndTime,\n      ,\n      bool active\n    ) = auction.getAuctionCore(_auctionId);\n\n    // Cannot exit within 10% of the cooloffPeriod\n    if (\n      active ||\n      block.timestamp < auctionEndTime + (cooloffPeriod * 10000) / 100000\n    ) {\n      return (0, 0, amount);\n    }\n\n    (uint256 maltQuantity, uint256 newAmount) = _getEarlyExitMaltQuantity(\n      account,\n      _auctionId,\n      amount\n    );\n\n    if (maltQuantity == 0) {\n      return (0, 0, newAmount);\n    }\n\n    // Reading direct from pool for this isn't bad as recovery\n    // Mode avoids price being manipulated upwards\n    (uint256 currentPrice, ) = dexHandler.maltMarketPrice();\n    require(currentPrice != 0, \"Price should be more than zero\");\n\n    uint256 fullReturn = (maltQuantity * currentPrice) / pegPrice;\n\n    // setCooloffPeriod guards against cooloffPeriod ever being 0\n    uint256 progressionBps = ((block.timestamp - auctionEndTime) * 10000) /\n      cooloffPeriod;\n    if (progressionBps > 10000) {\n      progressionBps = 10000;\n    }\n\n    if (fullReturn > newAmount) {\n      // Allow a % of profit to be realised\n      // Add additional * 10,000 then / 10,000 to increase precision\n      uint256 maxProfit = ((fullReturn - newAmount) *\n        ((maxEarlyExitBps * 10000 * progressionBps) / 10000)) /\n        10000 /\n        10000;\n      fullReturn = newAmount + maxProfit;\n    }\n\n    return (fullReturn, (fullReturn * pegPrice) / currentPrice, newAmount);\n  }\n\n  function accountEarlyExitReturns(address account)\n    external\n    view\n    returns (uint256[] memory auctions, uint256[] memory earlyExitAmount)\n  {\n    auctions = auction.getAccountCommitmentAuctions(account);\n    uint256 length = auctions.length;\n\n    earlyExitAmount = new uint256[](length);\n\n    for (uint256 i; i < length; ++i) {\n      (uint256 commitment, uint256 redeemed, , uint256 exited) = auction\n        .getAuctionParticipationForAccount(account, auctions[i]);\n      uint256 amount = commitment - redeemed - exited;\n      (uint256 exitAmount, , ) = earlyExitReturn(account, auctions[i], amount);\n      earlyExitAmount[i] = exitAmount;\n    }\n  }\n\n  function accountAuctionExits(address account, uint256 auctionId)\n    external\n    view\n    returns (\n      uint256 exitedEarly,\n      uint256 earlyExitReturn,\n      uint256 maltUsed\n    )\n  {\n    EarlyExitData storage accountExits = auctionEarlyExits[auctionId]\n      .accountExits[account];\n\n    return (\n      accountExits.exitedEarly,\n      accountExits.earlyExitReturn,\n      accountExits.maltUsed\n    );\n  }\n\n  function globalAuctionExits(uint256 auctionId)\n    external\n    view\n    returns (\n      uint256 exitedEarly,\n      uint256 earlyExitReturn,\n      uint256 maltUsed\n    )\n  {\n    AuctionExits storage auctionExits = auctionEarlyExits[auctionId];\n\n    return (\n      auctionExits.exitedEarly,\n      auctionExits.earlyExitReturn,\n      auctionExits.maltUsed\n    );\n  }\n\n  /*\n   * INTERNAL METHODS\n   */\n  function _calculateMaltRequiredForExit(\n    uint256 _auctionId,\n    uint256 amount,\n    uint256 exitedEarly\n  ) internal returns (uint256, uint256) {}\n\n  function _getEarlyExitMaltQuantity(\n    address account,\n    uint256 _auctionId,\n    uint256 amount\n  ) internal view returns (uint256 maltQuantity, uint256 newAmount) {\n    (\n      uint256 userCommitment,\n      uint256 userRedeemed,\n      uint256 userMaltPurchased,\n      uint256 earlyExited\n    ) = auction.getAuctionParticipationForAccount(account, _auctionId);\n\n    uint256 exitedEarly = auctionEarlyExits[_auctionId]\n      .accountExits[account]\n      .exitedEarly;\n\n    // This should never overflow due to guards in redemption code\n    uint256 userOutstanding = userCommitment - userRedeemed - exitedEarly;\n\n    if (amount > userOutstanding) {\n      amount = userOutstanding;\n    }\n\n    if (amount == 0) {\n      return (0, 0);\n    }\n\n    newAmount = amount;\n\n    maltQuantity = (userMaltPurchased * amount) / userCommitment;\n  }\n\n  /*\n   * PRIVILEDGED METHODS\n   */\n  function setEarlyExitBps(uint256 _earlyExitBps)\n    external\n    onlyRoleMalt(ADMIN_ROLE, \"Must have admin privilege\")\n  {\n    require(\n      _earlyExitBps != 0 && _earlyExitBps <= 10000,\n      \"Must be between 0-100%\"\n    );\n    maxEarlyExitBps = _earlyExitBps;\n    emit SetEarlyExitBps(_earlyExitBps);\n  }\n\n  function setCooloffPeriod(uint256 _period)\n    external\n    onlyRoleMalt(ADMIN_ROLE, \"Must have admin privilege\")\n  {\n    require(_period != 0, \"Cannot have 0 cool-off period\");\n    cooloffPeriod = _period;\n    emit SetCooloffPeriod(_period);\n  }\n\n  function _accessControl()\n    internal\n    override(AuctionExtension, DexHandlerExtension)\n  {\n    _onlyRoleMalt(POOL_UPDATER_ROLE, \"Must have pool updater role\");\n  }\n}"
}