{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/Auction/AuctionParticipant.sol",
    "Parent Contracts": [
        "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": "abstract contract AuctionParticipant is StabilizedPoolUnit, AuctionExtension {\n  using SafeERC20 for ERC20;\n\n  bytes32 public immutable PURCHASE_TRIGGER_ROLE;\n\n  uint256 public replenishingIndex;\n  uint256[] public auctionIds;\n  mapping(uint256 => uint256) public idIndex;\n  uint256 public claimableRewards;\n\n  event SetReplenishingIndex(uint256 index);\n\n  constructor(\n    address timelock,\n    address initialAdmin,\n    address poolFactory,\n    address purchaseExecutor\n  ) StabilizedPoolUnit(timelock, initialAdmin, poolFactory) {\n    PURCHASE_TRIGGER_ROLE = 0xba1d6c105756f1871c32a2336058dfcdec2b9a50c167d72adb7a3048e6502a75;\n    // setup PURCHASE_TRIGGER_ROLE\n    _roleSetup(\n      0xba1d6c105756f1871c32a2336058dfcdec2b9a50c167d72adb7a3048e6502a75,\n      purchaseExecutor\n    );\n  }\n\n  function setupContracts(\n    address _collateralToken,\n    address _auction,\n    address pool\n  ) external onlyRoleMalt(POOL_FACTORY_ROLE, \"Must be pool factory\") {\n    require(!contractActive, \"Participant: Already setup\");\n    require(_collateralToken != address(0), \"Participant: RewardToken addr(0)\");\n    require(_auction != address(0), \"Participant: Auction addr(0)\");\n\n    contractActive = true;\n\n    collateralToken = ERC20(_collateralToken);\n    auction = IAuction(_auction);\n\n    (, address updater, ) = poolFactory.getPool(pool);\n    _setPoolUpdater(updater);\n  }\n\n  function purchaseArbitrageTokens(uint256 maxAmount)\n    external\n    onlyRoleMalt(\n      PURCHASE_TRIGGER_ROLE,\n      \"Must have implied collateral service privs\"\n    )\n    nonReentrant\n    onlyActive\n    returns (uint256 remaining)\n  {\n    // Just to make sure we are starting from 0\n    collateralToken.safeApprove(address(auction), 0);\n\n    uint256 balance = usableBalance();\n\n    if (balance == 0) {\n      return maxAmount;\n    }\n\n    if (maxAmount < balance) {\n      balance = maxAmount;\n    }\n\n    uint256 currentAuction = auction.currentAuctionId();\n\n    if (!auction.auctionActive(currentAuction)) {\n      return maxAmount;\n    }\n\n    // First time participating in this auction\n    if (idIndex[currentAuction] == 0) {\n      auctionIds.push(currentAuction);\n      idIndex[currentAuction] = auctionIds.length;\n    }\n\n    collateralToken.safeApprove(address(auction), balance);\n    auction.purchaseArbitrageTokens(balance, 0); // 0 min due to blocking buys\n\n    // Reset approval\n    collateralToken.safeApprove(address(auction), 0);\n\n    return maxAmount - balance;\n  }\n\n  function claim() external nonReentrant onlyActive {\n    uint256 length = auctionIds.length;\n    if (length == 0 || replenishingIndex >= length) {\n      return;\n    }\n\n    uint256 currentIndex = replenishingIndex;\n    uint256 auctionId = auctionIds[currentIndex];\n    uint256 auctionReplenishing = auction.replenishingAuctionId();\n\n    if (auctionId > auctionReplenishing) {\n      // Not yet replenishing this auction\n      return;\n    }\n\n    uint256 claimableTokens = auction.userClaimableArbTokens(\n      address(this),\n      auctionId\n    );\n\n    if (claimableTokens == 0 && auctionReplenishing > auctionId) {\n      // in this case, we will never receive any more tokens from this auction\n      currentIndex += 1;\n      auctionId = auctionIds[currentIndex];\n      claimableTokens = auction.userClaimableArbTokens(\n        address(this),\n        auctionId\n      );\n    }\n\n    if (claimableTokens == 0) {\n      // Nothing to claim yet\n      replenishingIndex = currentIndex;\n      return;\n    }\n\n    uint256 balance = collateralToken.balanceOf(address(this));\n\n    auction.claimArbitrage(auctionId);\n\n    uint256 finalBalance = collateralToken.balanceOf(address(this));\n    uint256 rewardedAmount = finalBalance - balance;\n\n    claimableRewards = claimableRewards + rewardedAmount;\n\n    if (\n      auction.replenishingAuctionId() > auctionId &&\n      auction.userClaimableArbTokens(address(this), auctionId) == 0\n    ) {\n      // Don't increment replenishingIndex if replenishingAuctionId == auctionId as\n      // claimable could be 0 due to the debt not being 100% replenished.\n      currentIndex += 1;\n    }\n\n    replenishingIndex = currentIndex;\n\n    _handleRewardDistribution(rewardedAmount);\n  }\n\n  function outstandingArbTokens() public view returns (uint256 outstanding) {\n    outstanding = 0;\n\n    uint256 length = auctionIds.length;\n\n    for (uint256 i = replenishingIndex; i < length; i = i + 1) {\n      outstanding =\n        outstanding +\n        auction.balanceOfArbTokens(auctionIds[i], address(this));\n    }\n\n    return outstanding;\n  }\n\n  function getAllAuctionIds() public view returns (uint256[] memory) {\n    return auctionIds;\n  }\n\n  function usableBalance() public view virtual returns (uint256) {\n    return collateralToken.balanceOf(address(this));\n  }\n\n  function _handleRewardDistribution(uint256 rewarded) internal virtual {\n    // Do nothing\n    return;\n  }\n\n  function setReplenishingIndex(uint256 _index)\n    external\n    onlyRoleMalt(ADMIN_ROLE, \"Must have admin privs\")\n  {\n    replenishingIndex = _index;\n    emit SetReplenishingIndex(_index);\n  }\n\n  function _accessControl() internal override(AuctionExtension) {\n    _onlyRoleMalt(POOL_UPDATER_ROLE, \"Must have pool updater role\");\n  }\n}"
}