Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Comptroller
- Optimization enabled
- true
- Compiler version
- v0.5.17+commit.d19bba13
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-07-26T18:20:56.589850Z
contracts/Comptroller.sol
pragma solidity 0.5.17; import "./CToken.sol"; import "./ErrorReporter.sol"; import "./PriceOracle.sol"; import "./ComptrollerInterface.sol"; import "./ComptrollerStorage.sol"; import "./Unitroller.sol"; import "./EIP20Interface.sol"; import "./Tokenomics/IAllowlist.sol"; import "./OpenZeppelin/SafeERC20.sol"; /** * @title Protocol's Comptroller Contract * @author RBL */ contract Comptroller is ComptrollerVXStorage, ComptrollerInterface, ComptrollerErrorReporter, ExponentialNoError { using SafeERC20 for EIP20Interface; /// @notice Emitted when an admin supports a market event MarketListed(CToken cToken); /// @notice Emitted when an account enters a market event MarketEntered(CToken cToken, address account); /// @notice Emitted when an account exits a market event MarketExited(CToken cToken, address account); /// @notice Emitted when close factor is changed by admin event NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa); /// @notice Emitted when a collateral factor is changed by admin event NewCollateralFactor(CToken cToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa); /// @notice Emitted when liquidation incentive is changed by admin event NewLiquidationIncentive(uint oldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa); /// @notice Emitted when price oracle is changed event NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle); /// @notice Emitted when pause guardian is changed event NewPauseGuardian(address oldPauseGuardian, address newPauseGuardian); /// @notice Emitted when an action is paused globally event ActionPaused(string action, bool pauseState); /// @notice Emitted when an action is paused on a market event ActionPaused(CToken cToken, string action, bool pauseState); /// @notice Emitted when supplier reward speed is updated event SupplyRewardSpeedUpdated(uint8 rewardToken, CToken indexed cToken, uint newSupplyRewardSpeed); /// @notice Emitted when borrower reward speed is updated event BorrowRewardSpeedUpdated(uint8 rewardToken, CToken indexed cToken, uint newBorrowRewardSpeed); /// @notice Emitted when rewards are distributed to a borrower event DistributedBorrowerReward(uint8 indexed tokenType, CToken indexed cToken, address indexed borrower, uint amountDelta, uint borrowIndex); /// @notice Emitted when rewards are distributed to a supplier event DistributedSupplierReward(uint8 indexed tokenType, CToken indexed cToken, address indexed supplier, uint amountDelta, uint supplyIndex); /// @notice Emitted when borrow cap for a cToken is changed event NewBorrowCap(CToken indexed cToken, uint newBorrowCap); /// @notice Emitted when borrow cap guardian is changed event NewBorrowCapGuardian(address oldBorrowCapGuardian, address newBorrowCapGuardian); /// @notice Emitted when reward token is granted by admin event RewardTokenGranted(address recipient, uint8 rewardType, uint amount); /// @notice Emitted when whitelisted liquidators verifier is changed event NewLiquidatorsWhitelistVerifier(address oldLiquidatorsWhitelistVerifier, address newLiquidatorsWhitelistVerifier); /// @notice Emitted when a new reward is configured event NewRewardType(address indexed rewardAddress, uint8 indexed rewardIndex); /// @notice The initial rewards index for a market uint224 public constant initialIndexConstant = 1e36; // closeFactorMantissa must be strictly greater than this value uint internal constant closeFactorMinMantissa = 0.05e18; // 0.05 // closeFactorMantissa must not exceed this value uint internal constant closeFactorMaxMantissa = 0.9e18; // 0.9 // No collateralFactorMantissa may exceed this value uint internal constant collateralFactorMaxMantissa = 0.9e18; // 0.9 // reward token type native (ether) uint8 public constant rewardNativeToken = 1; constructor() public { admin = msg.sender; } /*** Assets You Are In ***/ /** * @notice Returns the assets an account has entered * @param account The address of the account to pull assets for * @return A dynamic list with the assets the account has entered */ function getAssetsIn(address account) external view returns (CToken[] memory) { CToken[] memory assetsIn = accountAssets[account]; return assetsIn; } /** * @notice Returns whether the given account is entered in the given asset * @param account The address of the account to check * @param cToken The cToken to check * @return True if the account is in the asset, otherwise false. */ function checkMembership(address account, CToken cToken) external view returns (bool) { return markets[address(cToken)].accountMembership[account]; } /** * @notice Add assets to be included in account liquidity calculation * @param cTokens The list of addresses of the cToken markets to be enabled * @return Success indicator for whether each corresponding market was entered */ function enterMarkets(address[] memory cTokens) public returns (uint[] memory) { uint len = cTokens.length; uint[] memory results = new uint[](len); for (uint i = 0; i < len; i++) { CToken cToken = CToken(cTokens[i]); results[i] = uint(addToMarketInternal(cToken, msg.sender)); } return results; } /** * @notice Add the market to the borrower's "assets in" for liquidity calculations * @param cToken The market to enter * @param borrower The address of the account to modify * @return Success indicator for whether the market was entered */ function addToMarketInternal(CToken cToken, address borrower) internal returns (Error) { Market storage marketToJoin = markets[address(cToken)]; if (!marketToJoin.isListed) { // market is not listed, cannot join return Error.MARKET_NOT_LISTED; } if (marketToJoin.accountMembership[borrower] == true) { // already joined return Error.NO_ERROR; } // survived the gauntlet, add to list // NOTE: we store these somewhat redundantly as a significant optimization // this avoids having to iterate through the list for the most common use cases // that is, only when we need to perform liquidity checks // and not whenever we want to check if an account is in a particular market marketToJoin.accountMembership[borrower] = true; accountAssets[borrower].push(cToken); emit MarketEntered(cToken, borrower); return Error.NO_ERROR; } /** * @notice Removes asset from sender's account liquidity calculation * @dev Sender must not have an outstanding borrow balance in the asset, * or be providing necessary collateral for an outstanding borrow. * @param cTokenAddress The address of the asset to be removed * @return Whether or not the account successfully exited the market */ function exitMarket(address cTokenAddress) external returns (uint) { CToken cToken = CToken(cTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the cToken */ (uint oErr, uint tokensHeld, uint amountOwed, ) = cToken.getAccountSnapshot(msg.sender); require(oErr == 0, "CF"); // semi-opaque error code /* Fail if the sender has a borrow balance */ if (amountOwed != 0) { return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED); } /* Fail if the sender is not permitted to redeem all of their tokens */ uint allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[address(cToken)]; /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint(Error.NO_ERROR); } /* Set cToken account membership to false */ delete marketToExit.accountMembership[msg.sender]; /* Delete cToken from the account’s list of assets */ // load into memory for faster iteration CToken[] memory userAssetList = accountAssets[msg.sender]; uint len = userAssetList.length; uint assetIndex = len; for (uint i = 0; i < len; i++) { if (userAssetList[i] == cToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 CToken[] storage storedList = accountAssets[msg.sender]; storedList[assetIndex] = storedList[storedList.length - 1]; storedList.length--; emit MarketExited(cToken, msg.sender); return uint(Error.NO_ERROR); } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param cToken The market to verify the mint against * @param minter The account which would get the minted tokens * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!mintGuardianPaused[cToken], "MP"); // Shh - currently unused mintAmount; if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Keep the flywheel moving updateAndDistributeSupplierRewardsForToken(cToken, minter); return uint(Error.NO_ERROR); } /** * @notice Checks if the account should be allowed to redeem tokens in the given market * @param cToken The market to verify the redeem against * @param redeemer The account which would redeem the tokens * @param redeemTokens The number of cTokens to exchange for the underlying asset in the market * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint) { uint allowed = redeemAllowedInternal(cToken, redeemer, redeemTokens); if (allowed != uint(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving updateAndDistributeSupplierRewardsForToken(cToken, redeemer); return uint(Error.NO_ERROR); } function redeemAllowedInternal(address cToken, address redeemer, uint redeemTokens) internal view returns (uint) { if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */ if (!markets[cToken].accountMembership[redeemer]) { return uint(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(redeemer, CToken(cToken), redeemTokens, 0); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates redeem and reverts on rejection. May emit logs. * @param cToken Asset being redeemed * @param redeemer The address redeeming the tokens * @param redeemAmount The amount of the underlying asset being redeemed * @param redeemTokens The number of tokens being redeemed */ function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external { // Shh - currently unused cToken; redeemer; // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("RV"); } } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param cToken The market to verify the borrow against * @param borrower The account which would borrow the asset * @param borrowAmount The amount of underlying the account would borrow * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!borrowGuardianPaused[cToken], "BP"); if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (!markets[cToken].accountMembership[borrower]) { // only cTokens may call borrowAllowed if borrower not in market require(msg.sender == cToken, "CT"); // attempt to add borrower to the market Error err = addToMarketInternal(CToken(msg.sender), borrower); if (err != Error.NO_ERROR) { return uint(err); } // it should be impossible to break the important invariant assert(markets[cToken].accountMembership[borrower]); } if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { return uint(Error.PRICE_ERROR); } uint borrowCap = borrowCaps[cToken]; // Borrow cap of 0 corresponds to unlimited borrowing if (borrowCap != 0) { uint totalBorrows = CToken(cToken).totalBorrows(); uint nextTotalBorrows = add_(totalBorrows, borrowAmount); require(nextTotalBorrows < borrowCap, "BC"); } (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(borrower, CToken(cToken), 0, borrowAmount); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } // Keep the flywheel moving Exp memory borrowIndex = Exp({mantissa: CToken(cToken).borrowIndex()}); updateAndDistributeBorrowerRewardsForToken(cToken, borrower, borrowIndex); return uint(Error.NO_ERROR); } /** * @notice Checks if the account should be allowed to repay a borrow in the given market * @param cToken The market to verify the repay against * @param payer The account which would repay the asset * @param borrower The account which would borrowed the asset * @param repayAmount The amount of the underlying asset the account would repay * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint) { // Shh - currently unused payer; borrower; repayAmount; if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Keep the flywheel moving Exp memory borrowIndex = Exp({mantissa: CToken(cToken).borrowIndex()}); updateAndDistributeBorrowerRewardsForToken(cToken, borrower, borrowIndex); return uint(Error.NO_ERROR); } /** * @notice Checks if the liquidation should be allowed to occur * @param cTokenBorrowed Asset which was borrowed by the borrower * @param cTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint) { if(!IAllowList(liquidatorsWhitelistVerifier).allowed(liquidator)){ return uint(Error.UNAUTHORIZED); } if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) { return uint(Error.MARKET_NOT_LISTED); } if(!markets[cTokenCollateral].accountMembership[borrower]){ return uint(Error.MARKET_NOT_ENTERED); } /* The borrower must have shortfall in order to be liquidatable */ (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall == 0) { return uint(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint borrowBalance = CToken(cTokenBorrowed).borrowBalanceStored(borrower); uint maxClose = mul_ScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance); if (repayAmount > maxClose) { return uint(Error.TOO_MUCH_REPAY); } return uint(Error.NO_ERROR); } /** * @notice Checks if the seizing of assets should be allowed to occur * @param cTokenCollateral Asset which was used as collateral and will be seized * @param cTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!seizeGuardianPaused, "SP"); // Shh - currently unused seizeTokens; if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (CToken(cTokenCollateral).comptroller() != CToken(cTokenBorrowed).comptroller()) { return uint(Error.COMPTROLLER_MISMATCH); } if(!markets[cTokenCollateral].accountMembership[borrower]){ return uint(Error.MARKET_NOT_ENTERED); } // Keep the flywheel moving updateAndDistributeSupplierRewardsForToken(cTokenCollateral, borrower); updateAndDistributeSupplierRewardsForToken(cTokenCollateral, liquidator); return uint(Error.NO_ERROR); } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param cToken The market to verify the transfer against * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!transferGuardianPaused, "TP"); // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens uint allowed = redeemAllowedInternal(cToken, src, transferTokens); if (allowed != uint(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving updateAndDistributeSupplierRewardsForToken(cToken, src); updateAndDistributeSupplierRewardsForToken(cToken, dst); return uint(Error.NO_ERROR); } /*** Liquidity/Liquidation Calculations ***/ /** * @dev Local vars for avoiding stack-depth limits in calculating account liquidity. * Note that `cTokenBalance` is the number of cTokens the account owns in the market, * whereas `borrowBalance` is the amount of underlying that the account has borrowed. */ struct AccountLiquidityLocalVars { uint sumCollateral; uint sumBorrowPlusEffects; uint cTokenBalance; uint borrowBalance; uint exchangeRateMantissa; uint oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToDenom; } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code (semi-opaque), account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidity(address account) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); return (uint(err), liquidity, shortfall); } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code, account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) { return getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @return (possible error code (semi-opaque), hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidity( address account, address cTokenModify, uint redeemTokens, uint borrowAmount) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(cTokenModify), redeemTokens, borrowAmount); return (uint(err), liquidity, shortfall); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @dev Note that we calculate the exchangeRateStored for each collateral cToken using stored data, * without calculating accumulated interest. * @return (possible error code, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, CToken cTokenModify, uint redeemTokens, uint borrowAmount) internal view returns (Error, uint, uint) { AccountLiquidityLocalVars memory vars; // Holds all our calculation results uint oErr; // For each asset the account is in CToken[] memory assets = accountAssets[account]; for (uint i = 0; i < assets.length; i++) { CToken asset = assets[i]; // Read the balances and exchange rate from the cToken (oErr, vars.cTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot(account); if (oErr != 0) { // semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades return (Error.SNAPSHOT_ERROR, 0, 0); } vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa}); vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa}); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0); } vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa}); // Pre-compute a conversion factor from tokens -> dollar (normalized price value) vars.tokensToDenom = mul_(mul_(vars.collateralFactor, vars.exchangeRate), vars.oraclePrice); // sumCollateral += tokensToDenom * cTokenBalance vars.sumCollateral = mul_ScalarTruncateAddUInt(vars.tokensToDenom, vars.cTokenBalance, vars.sumCollateral); // sumBorrowPlusEffects += oraclePrice * borrowBalance vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects); // Calculate effects of interacting with cTokenModify if (asset == cTokenModify) { // redeem effect // sumBorrowPlusEffects += tokensToDenom * redeemTokens vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.tokensToDenom, redeemTokens, vars.sumBorrowPlusEffects); // borrow effect // sumBorrowPlusEffects += oraclePrice * borrowAmount vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects); } } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral); } } /** * @notice Calculate number of tokens of collateral asset to seize given an underlying amount * @dev Used in liquidation (called in cToken.liquidateBorrowFresh) * @param cTokenBorrowed The address of the borrowed cToken * @param cTokenCollateral The address of the collateral cToken * @param actualRepayAmount The amount of cTokenBorrowed underlying to convert into cTokenCollateral tokens * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation) */ function liquidateCalculateSeizeTokens(address cTokenBorrowed, address cTokenCollateral, uint actualRepayAmount) external view returns (uint, uint) { /* Read oracle prices for borrowed and collateral markets */ uint priceBorrowedMantissa = oracle.getUnderlyingPrice(CToken(cTokenBorrowed)); uint priceCollateralMantissa = oracle.getUnderlyingPrice(CToken(cTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint(Error.PRICE_ERROR), 0); } /* * Get the exchange rate and calculate the number of collateral tokens to seize: * seizeAmount = actualRepayAmount * liquidationIncentive * priceBorrowed / priceCollateral * seizeTokens = seizeAmount / exchangeRate * = actualRepayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate) */ uint exchangeRateMantissa = CToken(cTokenCollateral).exchangeRateStored(); // Note: reverts on error uint seizeTokens; Exp memory numerator; Exp memory denominator; Exp memory ratio; numerator = mul_(mul_(Exp({mantissa: liquidationIncentiveMantissa}), Exp({mantissa: priceBorrowedMantissa})), actualRepayAmount); denominator = mul_(Exp({mantissa: priceCollateralMantissa}), Exp({mantissa: exchangeRateMantissa})); ratio = div_(numerator, denominator); seizeTokens = truncate(ratio); return (uint(Error.NO_ERROR), seizeTokens); } /*** Admin Functions ***/ /** * @notice Sets a new price oracle for the comptroller * @dev Admin function to set a new price oracle * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPriceOracle(PriceOracle newOracle) public returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the comptroller PriceOracle oldOracle = oracle; // Set comptroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint(Error.NO_ERROR); } /** * @notice Sets the closeFactor used when liquidating borrows * @dev Admin function to set closeFactor * @param newCloseFactorMantissa New close factor, scaled by 1e18 * @return uint 0=success, otherwise a failure */ function _setCloseFactor(uint newCloseFactorMantissa) external returns (uint) { // Check caller is admin require(msg.sender == admin, "AO"); uint oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets the collateralFactor for a market * @dev Admin function to set per-market collateralFactor * @param cToken The market to set the factor on * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCollateralFactor(CToken cToken, uint newCollateralFactorMantissa) external returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COLLATERAL_FACTOR_OWNER_CHECK); } // Verify market is listed Market storage market = markets[address(cToken)]; if (!market.isListed) { return fail(Error.MARKET_NOT_LISTED, FailureInfo.SET_COLLATERAL_FACTOR_NO_EXISTS); } Exp memory newCollateralFactorExp = Exp({mantissa: newCollateralFactorMantissa}); // Check collateral factor <= 0.9 Exp memory highLimit = Exp({mantissa: collateralFactorMaxMantissa}); if (lessThanExp(highLimit, newCollateralFactorExp)) { return fail(Error.INVALID_COLLATERAL_FACTOR, FailureInfo.SET_COLLATERAL_FACTOR_VALIDATION); } // If collateral factor != 0, fail if price == 0 if (newCollateralFactorMantissa != 0 && oracle.getUnderlyingPrice(cToken) == 0) { return fail(Error.PRICE_ERROR, FailureInfo.SET_COLLATERAL_FACTOR_WITHOUT_PRICE); } // Set market's collateral factor to new collateral factor, remember old value uint oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(cToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets liquidationIncentive * @dev Admin function to set liquidationIncentive * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK); } // Save current value for use in log uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint(Error.NO_ERROR); } /** * @notice Add the market to the markets mapping and set it as listed * @dev Admin function to set isListed and add support for the market * @param cToken The address of the market (token) to list * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _supportMarket(CToken cToken) external returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK); } if (markets[address(cToken)].isListed) { return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS); } cToken.isCToken(); // Sanity check to make sure its really a CToken markets[address(cToken)] = Market({isListed: true, collateralFactorMantissa: 0}); _addMarketInternal(address(cToken)); for(uint8 i = 0; i < rewardTokens.length; i++) { _initializeMarket(i ,address(cToken)); } emit MarketListed(cToken); return uint(Error.NO_ERROR); } function _addMarketInternal(address cToken) internal { for (uint i = 0; i < allMarkets.length; i ++) { require(allMarkets[i] != CToken(cToken), "MAA"); } allMarkets.push(CToken(cToken)); } function _initializeMarket(uint8 rewardType, address qiToken) internal { uint32 blockTimestamp = safe32(getBlockTimestamp(), "32"); RewardMarketState storage supplyState = rewardSupplyState[rewardType][qiToken]; RewardMarketState storage borrowState = rewardBorrowState[rewardType][qiToken]; if (supplyState.index == 0) { supplyState.index = initialIndexConstant; } if (borrowState.index == 0) { borrowState.index = initialIndexConstant; } supplyState.timestamp = borrowState.timestamp = blockTimestamp; } /** * @notice Set the given borrow caps for the given cToken markets. Borrowing that brings total borrows to or above borrow cap will revert. * @dev Admin or borrowCapGuardian function to set the borrow caps. A borrow cap of 0 corresponds to unlimited borrowing. * @param cTokens The addresses of the markets (tokens) to change the borrow caps for * @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing. */ function _setMarketBorrowCaps(CToken[] calldata cTokens, uint[] calldata newBorrowCaps) external { require(msg.sender == admin || msg.sender == borrowCapGuardian, "PG"); uint numMarkets = cTokens.length; uint numBorrowCaps = newBorrowCaps.length; require(numMarkets != 0 && numMarkets == numBorrowCaps, "II"); for(uint i = 0; i < numMarkets; i++) { borrowCaps[address(cTokens[i])] = newBorrowCaps[i]; emit NewBorrowCap(cTokens[i], newBorrowCaps[i]); } } /** * @notice Admin function to change the Borrow Cap Guardian * @param newBorrowCapGuardian The address of the new Borrow Cap Guardian */ function _setBorrowCapGuardian(address newBorrowCapGuardian) external { require(msg.sender == admin, "AO"); // Save current value for inclusion in log address oldBorrowCapGuardian = borrowCapGuardian; // Store borrowCapGuardian with value newBorrowCapGuardian borrowCapGuardian = newBorrowCapGuardian; // Emit NewBorrowCapGuardian(OldBorrowCapGuardian, NewBorrowCapGuardian) emit NewBorrowCapGuardian(oldBorrowCapGuardian, newBorrowCapGuardian); } /** * @notice Admin function to change the Pause Guardian * @param newPauseGuardian The address of the new Pause Guardian * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _setPauseGuardian(address newPauseGuardian) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PAUSE_GUARDIAN_OWNER_CHECK); } // Save current value for inclusion in log address oldPauseGuardian = pauseGuardian; // Store pauseGuardian with value newPauseGuardian pauseGuardian = newPauseGuardian; // Emit NewPauseGuardian(OldPauseGuardian, NewPauseGuardian) emit NewPauseGuardian(oldPauseGuardian, pauseGuardian); return uint(Error.NO_ERROR); } function _setMintPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "ML"); require(msg.sender == pauseGuardian || msg.sender == admin, "PG"); require(msg.sender == admin || state == true, "AO"); mintGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Mint", state); return state; } function _setBorrowPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "ML"); require(msg.sender == pauseGuardian || msg.sender == admin, "PG"); require(msg.sender == admin || state == true, "AO"); borrowGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Borrow", state); return state; } function _setTransferPaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "PG"); require(msg.sender == admin || state == true, "AO"); transferGuardianPaused = state; emit ActionPaused("Transfer", state); return state; } function _setSeizePaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "PG"); require(msg.sender == admin || state == true, "AO"); seizeGuardianPaused = state; emit ActionPaused("Seize", state); return state; } function _become(Unitroller unitroller) public { require(msg.sender == unitroller.admin(), "AO"); require(unitroller._acceptImplementation() == 0, "AF"); } /** * @notice Checks caller is admin, or this contract is becoming the new implementation */ function adminOrInitializing() internal view returns (bool) { return msg.sender == admin || msg.sender == comptrollerImplementation; } /*** Rewards Distribution ***/ /** * @notice Set reward speed for a single market * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken Market whose speed to update * @param newSupplyRewardSpeed New supply speed * @param newBorrowRewardSpeed New borrow speed */ function setRewardSpeedInternal(uint8 rewardType, CToken cToken, uint newSupplyRewardSpeed, uint newBorrowRewardSpeed) internal { require(markets[address(cToken)].isListed, "ML"); uint currentSupplyRewardSpeed = supplyRewardSpeeds[rewardType][address(cToken)]; uint currentBorrowRewardSpeed = borrowRewardSpeeds[rewardType][address(cToken)]; if (currentSupplyRewardSpeed != newSupplyRewardSpeed) { updateRewardSupplyIndex(rewardType, address(cToken)); supplyRewardSpeeds[rewardType][address(cToken)] = newSupplyRewardSpeed; emit SupplyRewardSpeedUpdated(rewardType, cToken, newSupplyRewardSpeed); } if (currentBorrowRewardSpeed != newBorrowRewardSpeed) { Exp memory borrowIndex = Exp({ mantissa: cToken.borrowIndex() }); updateRewardBorrowIndex(rewardType, address(cToken), borrowIndex); borrowRewardSpeeds[rewardType][address(cToken)] = newBorrowRewardSpeed; emit BorrowRewardSpeedUpdated(rewardType, cToken, newBorrowRewardSpeed); } } /** * @notice Accrue rewards to the market by updating the supply index * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken The market whose supply index to update */ function updateRewardSupplyIndex(uint8 rewardType, address cToken) internal { require(rewardType < rewardTokens.length, "IR"); RewardMarketState storage supplyState = rewardSupplyState[rewardType][cToken]; uint supplySpeed = supplyRewardSpeeds[rewardType][cToken]; uint blockTimestamp = getBlockTimestamp(); uint deltaTimestamps = sub_(blockTimestamp, uint(supplyState.timestamp)); if (deltaTimestamps > 0 && supplySpeed > 0) { uint supplyTokens = CToken(cToken).totalSupply(); uint rewardsAccrued = mul_(deltaTimestamps, supplySpeed); Double memory ratio = supplyTokens > 0 ? fraction(rewardsAccrued, supplyTokens) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: supplyState.index}), ratio); rewardSupplyState[rewardType][cToken] = RewardMarketState({ index: safe224(index.mantissa, "224"), timestamp: safe32(blockTimestamp, "32") }); } else if (deltaTimestamps > 0) { supplyState.timestamp = safe32(blockTimestamp, "32"); } } /** * @notice Accrue rewards to the market by updating the borrow index * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken The market whose borrow index to update */ function updateRewardBorrowIndex(uint8 rewardType, address cToken, Exp memory marketBorrowIndex) internal { require(rewardType < rewardTokens.length, "IR"); RewardMarketState storage borrowState = rewardBorrowState[rewardType][cToken]; uint borrowSpeed = borrowRewardSpeeds[rewardType][cToken]; uint blockTimestamp = getBlockTimestamp(); uint deltaTimestamps = sub_(blockTimestamp, uint(borrowState.timestamp)); if (deltaTimestamps > 0 && borrowSpeed > 0) { uint borrowAmount = div_(CToken(cToken).totalBorrows(), marketBorrowIndex); uint rewardsAccrued = mul_(deltaTimestamps, borrowSpeed); Double memory ratio = borrowAmount > 0 ? fraction(rewardsAccrued, borrowAmount) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: borrowState.index}), ratio); rewardBorrowState[rewardType][cToken] = RewardMarketState({ index: safe224(index.mantissa, "224"), timestamp: safe32(blockTimestamp, "32") }); } else if (deltaTimestamps > 0) { borrowState.timestamp = safe32(blockTimestamp, "32"); } } /** * @notice Refactored function to calc and rewards accounts supplier rewards * @param cToken The market to verify the mint against * @param account The acount to whom rewards are distributed */ function updateAndDistributeSupplierRewardsForToken(address cToken, address account) internal { for (uint8 rewardType = 0; rewardType < rewardTokens.length; rewardType++) { updateRewardSupplyIndex(rewardType, cToken); distributeSupplierReward(rewardType, cToken, account); } } /** * @notice Calculate rewards accrued by a supplier and possibly transfer it to them * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken The market in which the supplier is interacting * @param supplier The address of the supplier to distribute rewards to */ function distributeSupplierReward(uint8 rewardType, address cToken, address supplier) internal { require(rewardType < rewardTokens.length, "IR"); RewardMarketState storage supplyState = rewardSupplyState[rewardType][cToken]; Double memory supplyIndex = Double({mantissa: supplyState.index}); Double memory supplierIndex = Double({mantissa: rewardSupplierIndex[rewardType][cToken][supplier]}); rewardSupplierIndex[rewardType][cToken][supplier] = supplyIndex.mantissa; if (supplierIndex.mantissa == 0 && supplyIndex.mantissa >= initialIndexConstant) { supplierIndex.mantissa = initialIndexConstant; } Double memory deltaIndex = sub_(supplyIndex, supplierIndex); uint supplierTokens = CToken(cToken).balanceOf(supplier); uint supplierDelta = mul_(supplierTokens, deltaIndex); uint supplierAccrued = add_(rewardAccrued[rewardType][supplier], supplierDelta); rewardAccrued[rewardType][supplier] = supplierAccrued; emit DistributedSupplierReward(rewardType, CToken(cToken), supplier, supplierDelta, supplyIndex.mantissa); } /** * @notice Refactored function to calc and rewards accounts supplier rewards * @param cToken The market to verify the mint against * @param borrower Borrower to be rewarded */ function updateAndDistributeBorrowerRewardsForToken(address cToken, address borrower, Exp memory marketBorrowIndex) internal { for (uint8 rewardType = 0; rewardType < rewardTokens.length; rewardType++) { updateRewardBorrowIndex(rewardType, cToken, marketBorrowIndex); distributeBorrowerReward(rewardType, cToken, borrower, marketBorrowIndex); } } /** * @notice Calculate rewards accrued by a borrower and possibly transfer it to them * @dev Borrowers will not begin to accrue until after the first interaction with the protocol. * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken The market in which the borrower is interacting * @param borrower The address of the borrower to distribute rewards to */ function distributeBorrowerReward(uint8 rewardType, address cToken, address borrower, Exp memory marketBorrowIndex) internal { require(rewardType < rewardTokens.length, "IR"); RewardMarketState storage borrowState = rewardBorrowState [rewardType][cToken]; Double memory borrowIndex = Double({mantissa: borrowState.index}); Double memory borrowerIndex = Double({mantissa: rewardBorrowerIndex[rewardType][cToken][borrower]}); rewardBorrowerIndex[rewardType][cToken][borrower] = borrowIndex.mantissa; if (borrowerIndex.mantissa == 0 && borrowIndex.mantissa >= initialIndexConstant) { borrowerIndex.mantissa = initialIndexConstant; } Double memory deltaIndex = sub_(borrowIndex, borrowerIndex); uint borrowerAmount = div_(CToken(cToken).borrowBalanceStored(borrower), marketBorrowIndex); uint borrowerDelta = mul_(borrowerAmount, deltaIndex); uint borrowerAccrued = add_(rewardAccrued[rewardType][borrower], borrowerDelta); rewardAccrued[rewardType][borrower] = borrowerAccrued; emit DistributedBorrowerReward(rewardType, CToken(cToken), borrower, borrowerDelta, borrowIndex.mantissa); } /** * @notice Claim all the rewards accrued by holder in all markets * @param holder The address to claim rewards for */ function claimReward(uint8 rewardType, address payable holder) public { return claimReward(rewardType,holder, allMarkets); } /** * @notice Claim all the rewards accrued by holder in the specified markets * @param holder The address to claim rewards for * @param cTokens The list of markets to claim rewards in */ function claimReward(uint8 rewardType, address payable holder, CToken[] memory cTokens) public { address payable [] memory holders = new address payable[](1); holders[0] = holder; claimReward(rewardType, holders, cTokens, true, true); } /** * @notice Claim all rewards accrued by the holders * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param holders The addresses to claim rewards for * @param cTokens The list of markets to claim rewards in * @param borrowers Whether or not to claim rewards earned by borrowing * @param suppliers Whether or not to claim rewards earned by supplying */ function claimReward(uint8 rewardType, address payable[] memory holders, CToken[] memory cTokens, bool borrowers, bool suppliers) public payable { require(rewardType < rewardTokens.length, "IR"); for (uint i = 0; i < cTokens.length; i++) { CToken cToken = cTokens[i]; require(markets[address(cToken)].isListed, "ML"); if (borrowers == true) { Exp memory borrowIndex = Exp({mantissa: cToken.borrowIndex()}); updateRewardBorrowIndex(rewardType,address(cToken), borrowIndex); for (uint j = 0; j < holders.length; j++) { distributeBorrowerReward(rewardType,address(cToken), holders[j], borrowIndex); grantRewardInternal(rewardType, holders[j], rewardAccrued[rewardType][holders[j]]); } } if (suppliers == true) { updateRewardSupplyIndex(rewardType,address(cToken)); for (uint j = 0; j < holders.length; j++) { distributeSupplierReward(rewardType,address(cToken), holders[j]); grantRewardInternal(rewardType, holders[j], rewardAccrued[rewardType][holders[j]]); } } } } /** * @notice Transfer rewards to the user * @dev Note: If there is not enough rewards, we do not perform the transfer all. * @param user The address of the user to transfer rewards to * @param amount The amount of rewards to (possibly) transfer * @return The amount of rewards which was NOT transferred to the user */ function grantRewardInternal(uint8 rewardType, address payable user, uint amount) internal { if (rewardType == rewardNativeToken) { uint nativeTokenRemaining = address(this).balance; if (amount > 0 && amount <= nativeTokenRemaining) { rewardAccrued[rewardType][user] = 0; (bool success, ) = user.call.value(amount).gas(4029)(""); require(success, "TF"); emit RewardTokenGranted(user, rewardType, amount); return; } }else{ EIP20Interface rewardToken = EIP20Interface(rewardTokens[rewardType]); uint balanceRemaining = rewardToken.balanceOf(address(this)); if (amount > 0 && amount <= balanceRemaining) { rewardAccrued[rewardType][user] = 0; rewardToken.safeTransfer(user, amount); emit RewardTokenGranted(user, rewardType, amount); return; } } rewardAccrued[rewardType][user] = amount; } /*** Token Distribution Admin ***/ /** * @notice Transfer reward tokens to the recipient * @dev Note: If there is not enough reward tokens, we do not perform the transfer all. * @param recipient The address of the recipient to transfer reward tokens to * @param amount The amount of reward tokens to (possibly) transfer */ function _grantRewardTokens(address payable recipient, uint8 rewardType, uint amount) public { require(adminOrInitializing(), "AO"); require(rewardType < rewardTokens.length, "IR"); require(amount > 0, "IA"); if(rewardType == rewardNativeToken) { require(amount <= address(this).balance, 'IF'); (bool success, ) = recipient.call.value(amount).gas(4029)(""); require(success, "TF"); }else { require(amount <= EIP20Interface(rewardTokens[rewardType]).balanceOf(address(this)), "IF"); EIP20Interface(rewardTokens[rewardType]).safeTransfer(recipient, amount); } emit RewardTokenGranted(recipient, rewardType, amount); } /** * @notice Set reward speed for a single market * @param rewardType 1 = Native token, != 1 ERC20 Tokens * @param cToken The market whose reward speed to update * @param supplyRewardSpeed New supply reward speed for the market * @param borrowRewardSpeed New borrow reward speed for the market */ function _setRewardSpeed(uint8 rewardType, CToken cToken, uint supplyRewardSpeed, uint borrowRewardSpeed) public { require(rewardType < rewardTokens.length, "IR"); require(adminOrInitializing(), "AO"); setRewardSpeedInternal(rewardType, cToken, supplyRewardSpeed, borrowRewardSpeed); } /** * @notice Set the protocol token address */ function setProtocolTokenAddress(address newProtocolTokenAddress) public { require(msg.sender == admin); protocolTokenAddress = newProtocolTokenAddress; } /** * @notice Return all of the markets * @dev The automatic getter may be used to access an individual market. * @return The list of market addresses */ function getAllMarkets() public view returns (CToken[] memory) { return allMarkets; } function getBlockTimestamp() public view returns (uint) { return block.timestamp; } /** * @notice payable function needed to receive native tokens */ function () payable external { } /** * @notice Set the liquidators whitelist verifier address */ function setliquidatorsWhitelistAddress(address newLiquidatorsWhitelistVerifier) public { require(msg.sender == admin, "AO"); emit NewLiquidatorsWhitelistVerifier(liquidatorsWhitelistVerifier, newLiquidatorsWhitelistVerifier); liquidatorsWhitelistVerifier = newLiquidatorsWhitelistVerifier; } /** * @notice Configure new reward type to the protocol */ function setRewardType(address rewardAddress) public { require(msg.sender == admin, "AO"); if(rewardTokens.length == 0){ require(protocolTokenAddress != address(0) && rewardAddress == protocolTokenAddress, "PT"); }else if(rewardTokens.length == 1){ require(rewardAddress == address(0), "NO"); } bool alreadySet = false; for(uint i = 0; i < rewardTokens.length; i++){ if(rewardTokens[i] == rewardAddress) { alreadySet = true; break; } } require(!alreadySet, "AS"); uint8 rewardIndex = uint8(rewardTokens.length); emit NewRewardType(rewardAddress, rewardIndex); rewardTokens.push(rewardAddress); CToken[] memory markets = getAllMarkets(); uint marketsLength = markets.length; for(uint i = 0; i < marketsLength; i++) { _initializeMarket(rewardIndex, address(markets[i])); } } /** * @notice Return all reward tokens configured */ function getAllRewardTokens() public view returns (address[] memory) { return rewardTokens; } }
contracts/CarefulMath.sol
pragma solidity 0.5.17; /** * @title Careful Math * @author RBL * @notice Derived from OpenZeppelin's SafeMath library * https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol */ contract CarefulMath { /** * @dev Possible error codes that we can return */ enum MathError { NO_ERROR, DIVISION_BY_ZERO, INTEGER_OVERFLOW, INTEGER_UNDERFLOW } /** * @dev Multiplies two numbers, returns an error on overflow. */ function mulUInt(uint a, uint b) internal pure returns (MathError, uint) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint c = a * b; if (c / a != b) { return (MathError.INTEGER_OVERFLOW, 0); } else { return (MathError.NO_ERROR, c); } } /** * @dev Integer division of two numbers, truncating the quotient. */ function divUInt(uint a, uint b) internal pure returns (MathError, uint) { if (b == 0) { return (MathError.DIVISION_BY_ZERO, 0); } return (MathError.NO_ERROR, a / b); } /** * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend). */ function subUInt(uint a, uint b) internal pure returns (MathError, uint) { if (b <= a) { return (MathError.NO_ERROR, a - b); } else { return (MathError.INTEGER_UNDERFLOW, 0); } } /** * @dev Adds two numbers, returns an error on overflow. */ function addUInt(uint a, uint b) internal pure returns (MathError, uint) { uint c = a + b; if (c >= a) { return (MathError.NO_ERROR, c); } else { return (MathError.INTEGER_OVERFLOW, 0); } } /** * @dev add a and b and then subtract c */ function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) { (MathError err0, uint sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } }
contracts/CToken.sol
pragma solidity 0.5.17; import "./ComptrollerInterface.sol"; import "./CTokenInterfaces.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./EIP20Interface.sol"; import "./InterestRateModel.sol"; /** * @title Protocol's CToken Contract * @notice Abstract base for CTokens * @author RBL */ contract CToken is CTokenInterface, Exponential, TokenErrorReporter { /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_) public { require(msg.sender == admin, "only admin may initialize the market"); require(accrualBlockTimestamp == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the comptroller uint err = _setComptroller(comptroller_); require(err == uint(Error.NO_ERROR), "setting comptroller failed"); // Initialize block timestamp and borrow index (block timestamp mocks depend on comptroller being set) accrualBlockTimestamp = getBlockTimestamp(); borrowIndex = mantissaOne; // Set the interest rate model (depends on block timestamp / borrow index) err = _setInterestRateModelFresh(interestRateModel_); require(err == uint(Error.NO_ERROR), "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally * @param spender The address of the account performing the transfer * @param src The address of the source account * @param dst The address of the destination account * @param tokens The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) { /* Fail if transfer not allowed */ uint allowed = comptroller.transferAllowed(address(this), src, dst, tokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed); } /* Do not allow self-transfers */ if (src == dst) { return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED); } /* Get the allowance, infinite for the account owner */ uint startingAllowance = 0; if (spender == src) { startingAllowance = uint(-1); } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ MathError mathErr; uint allowanceNew; uint srcTokensNew; uint dstTokensNew; (mathErr, allowanceNew) = subUInt(startingAllowance, tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED); } (mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH); } (mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) accountTokens[src] = srcTokensNew; accountTokens[dst] = dstTokensNew; /* Eat some of the allowance (if necessary) */ if (startingAllowance != uint(-1)) { transferAllowances[src][spender] = allowanceNew; } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); return uint(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool) { address src = msg.sender; transferAllowances[src][spender] = amount; emit Approval(src, spender, amount); return true; } /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256) { return transferAllowances[owner][spender]; } /** * @notice Get the token balance of the `owner` * @param owner The address of the account to query * @return The number of tokens owned by `owner` */ function balanceOf(address owner) external view returns (uint256) { return accountTokens[owner]; } /** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */ function balanceOfUnderlying(address owner) external returns (uint) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); (MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]); require(mErr == MathError.NO_ERROR, "balance could not be calculated"); return balance; } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by comptroller to more efficiently perform liquidity checks. * @param account Address of the account to snapshot * @return (possible error, token balance, borrow balance, exchange rate mantissa) */ function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint) { uint cTokenBalance = accountTokens[account]; uint borrowBalance; uint exchangeRateMantissa; MathError mErr; (mErr, borrowBalance) = borrowBalanceStoredInternal(account); if (mErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0, 0, 0); } (mErr, exchangeRateMantissa) = exchangeRateStoredInternal(); if (mErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0, 0, 0); } return (uint(Error.NO_ERROR), cTokenBalance, borrowBalance, exchangeRateMantissa); } /** * @dev Function to simply retrieve block timestamp * This exists mainly for inheriting test contracts to stub this result. */ function getBlockTimestamp() internal view returns (uint) { return block.timestamp; } /** * @notice Returns the current per-timestamp borrow interest rate for this cToken * @return The borrow interest rate per timestmp, scaled by 1e18 */ function borrowRatePerTimestamp() external view returns (uint) { return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves); } /** * @notice Returns the current per-timestamp supply interest rate for this cToken * @return The supply interest rate per timestmp, scaled by 1e18 */ function supplyRatePerTimestamp() external view returns (uint) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return totalBorrows; } /** * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex * @param account The address whose balance should be calculated after updating borrowIndex * @return The calculated balance */ function borrowBalanceCurrent(address account) external nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return borrowBalanceStored(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return The calculated balance */ function borrowBalanceStored(address account) public view returns (uint) { (MathError err, uint result) = borrowBalanceStoredInternal(account); require(err == MathError.NO_ERROR, "borrowBalanceStored: borrowBalanceStoredInternal failed"); return result; } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return (error code, the calculated balance or 0 if error code is non-zero) */ function borrowBalanceStoredInternal(address account) internal view returns (MathError, uint) { /* Note: we do not assert that the market is up to date */ MathError mathErr; uint principalTimesIndex; uint result; /* Get borrowBalance and borrowIndex */ BorrowSnapshot storage borrowSnapshot = accountBorrows[account]; /* If borrowBalance = 0 then borrowIndex is likely also 0. * Rather than failing the calculation with a division by 0, we immediately return 0 in this case. */ if (borrowSnapshot.principal == 0) { return (MathError.NO_ERROR, 0); } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ (mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal, borrowIndex); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, result); } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public nonReentrant returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view returns (uint) { (MathError err, uint result) = exchangeRateStoredInternal(); require(err == MathError.NO_ERROR, "exchangeRateStored: exchangeRateStoredInternal failed"); return result; } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return (error code, calculated exchange rate scaled by 1e18) */ function exchangeRateStoredInternal() internal view returns (MathError, uint) { uint _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return (MathError.NO_ERROR, initialExchangeRateMantissa); } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint totalCash = getCashPrior(); uint cashPlusBorrowsMinusReserves; Exp memory exchangeRate; MathError mathErr; (mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, totalReserves); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, _totalSupply); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, exchangeRate.mantissa); } } /** * @notice Get cash balance of this cToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view returns (uint) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public returns (uint) { /* Remember the initial block timestamp */ uint currentBlockTimestamp = getBlockTimestamp(); uint accrualBlockTimestampPrior = accrualBlockTimestamp; /* Short-circuit accumulating 0 interest */ if (accrualBlockTimestampPrior == currentBlockTimestamp) { return uint(Error.NO_ERROR); } /* Read the previous values out of storage */ uint cashPrior = getCashPrior(); uint borrowsPrior = totalBorrows; uint reservesPrior = totalReserves; uint borrowIndexPrior = borrowIndex; /* Calculate the current borrow interest rate */ uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of blocks elapsed since the last accrual */ (MathError mathErr, uint blockDelta) = subUInt(currentBlockTimestamp, accrualBlockTimestampPrior); require(mathErr == MathError.NO_ERROR, "could not calculate block delta"); /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * blockDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor; uint interestAccumulated; uint totalBorrowsNew; uint totalReservesNew; uint borrowIndexNew; (mathErr, simpleInterestFactor) = mulScalar(Exp({mantissa: borrowRateMantissa}), blockDelta); if (mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, uint(mathErr)); } (mathErr, interestAccumulated) = mulScalarTruncate(simpleInterestFactor, borrowsPrior); if (mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, uint(mathErr)); } (mathErr, totalBorrowsNew) = addUInt(interestAccumulated, borrowsPrior); if (mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, uint(mathErr)); } (mathErr, totalReservesNew) = mulScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior); if (mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, uint(mathErr)); } (mathErr, borrowIndexNew) = mulScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior); if (mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, uint(mathErr)); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accrualBlockTimestamp = currentBlockTimestamp; borrowIndex = borrowIndexNew; totalBorrows = totalBorrowsNew; totalReserves = totalReservesNew; /* We emit an AccrueInterest event */ emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew); return uint(Error.NO_ERROR); } /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint mintAmount) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0); } // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to return mintFresh(msg.sender, mintAmount); } struct MintLocalVars { Error err; MathError mathErr; uint exchangeRateMantissa; uint mintTokens; uint totalSupplyNew; uint accountTokensNew; uint actualMintAmount; } /** * @notice User supplies assets into the market and receives cTokens in exchange * @dev Assumes interest has already been accrued up to the current block * @param minter The address of the account which is supplying the assets * @param mintAmount The amount of the underlying asset to supply * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintFresh(address minter, uint mintAmount) internal returns (uint, uint) { /* Fail if mint not allowed */ uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK), 0); } MintLocalVars memory vars; (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return (failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call `doTransferIn` for the minter and the mintAmount. * Note: The cToken must handle variations between ERC-20 and native token underlying. * `doTransferIn` reverts if anything goes wrong, since we can't be sure if * side-effects occurred. The function returns the amount actually transferred, * in case of a fee. On success, the cToken holds an additional `actualMintAmount` * of cash. */ vars.actualMintAmount = doTransferIn(minter, mintAmount); /* * We get the current exchange rate and calculate the number of cTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ (vars.mathErr, vars.mintTokens) = divScalarByExpTruncate(vars.actualMintAmount, Exp({mantissa: vars.exchangeRateMantissa})); require(vars.mathErr == MathError.NO_ERROR, "MINT_EXCHANGE_CALCULATION_FAILED"); /* * We calculate the new total supply of cTokens and minter token balance, checking for overflow: * totalSupplyNew = totalSupply + mintTokens * accountTokensNew = accountTokens[minter] + mintTokens */ (vars.mathErr, vars.totalSupplyNew) = addUInt(totalSupply, vars.mintTokens); require(vars.mathErr == MathError.NO_ERROR, "MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED"); (vars.mathErr, vars.accountTokensNew) = addUInt(accountTokens[minter], vars.mintTokens); require(vars.mathErr == MathError.NO_ERROR, "MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED"); /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[minter] = vars.accountTokensNew; /* We emit a Mint event, and a Transfer event */ emit Mint(minter, vars.actualMintAmount, vars.mintTokens); emit Transfer(address(this), minter, vars.mintTokens); return (uint(Error.NO_ERROR), vars.actualMintAmount); } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint redeemTokens) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, redeemTokens, 0); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming cTokens * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, 0, redeemAmount); } struct RedeemLocalVars { Error err; MathError mathErr; uint exchangeRateMantissa; uint redeemTokens; uint redeemAmount; uint totalSupplyNew; uint accountTokensNew; } /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of cTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @param redeemAmountIn The number of underlying tokens to receive from redeeming cTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal returns (uint) { require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero"); RedeemLocalVars memory vars; /* exchangeRate = invoke Exchange Rate Stored() */ (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)); } /* If redeemTokensIn > 0: */ if (redeemTokensIn > 0) { /* * We calculate the exchange rate and the amount of underlying to be redeemed: * redeemTokens = redeemTokensIn * redeemAmount = redeemTokensIn x exchangeRateCurrent */ if (redeemTokensIn == uint(-1)) { vars.redeemTokens = accountTokens[redeemer]; } else { vars.redeemTokens = redeemTokensIn; } (vars.mathErr, vars.redeemAmount) = mulScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint(vars.mathErr)); } } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ if (redeemAmountIn == uint(-1)) { vars.redeemTokens = accountTokens[redeemer]; (vars.mathErr, vars.redeemAmount) = mulScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint(vars.mathErr)); } } else { vars.redeemAmount = redeemAmountIn; (vars.mathErr, vars.redeemTokens) = divScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa})); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, uint(vars.mathErr)); } } } /* Fail if redeem not allowed */ uint allowed = comptroller.redeemAllowed(address(this), redeemer, vars.redeemTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REDEEM_COMPTROLLER_REJECTION, allowed); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK); } /* * We calculate the new total supply and redeemer balance, checking for underflow: * totalSupplyNew = totalSupply - redeemTokens * accountTokensNew = accountTokens[redeemer] - redeemTokens */ (vars.mathErr, vars.totalSupplyNew) = subUInt(totalSupply, vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr)); } (vars.mathErr, vars.accountTokensNew) = subUInt(accountTokens[redeemer], vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } /* Fail gracefully if protocol has insufficient cash */ if (getCashPrior() < vars.redeemAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[redeemer] = vars.accountTokensNew; /* * We invoke doTransferOut for the redeemer and the redeemAmount. * Note: The cToken must handle variations between ERC-20 and native token underlying. * On success, the cToken has redeemAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(redeemer, vars.redeemAmount); /* We emit a Transfer event, and a Redeem event */ emit Transfer(redeemer, address(this), vars.redeemTokens); emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens); /* We call the defense hook */ comptroller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens); return uint(Error.NO_ERROR); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowInternal(uint borrowAmount) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED); } // borrowFresh emits borrow-specific logs on errors, so we don't need to return borrowFresh(msg.sender, borrowAmount); } struct BorrowLocalVars { MathError mathErr; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowFresh(address payable borrower, uint borrowAmount) internal returns (uint) { /* Fail if borrow not allowed */ uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK); } /* Fail gracefully if protocol has insufficient underlying cash */ if (getCashPrior() < borrowAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE); } BorrowLocalVars memory vars; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } (vars.mathErr, vars.accountBorrowsNew) = addUInt(vars.accountBorrows, borrowAmount); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } (vars.mathErr, vars.totalBorrowsNew) = addUInt(totalBorrows, borrowAmount); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The cToken must handle variations between ERC-20 and native token underlying. * On success, the cToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount); /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); return uint(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint repayAmount) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, msg.sender, repayAmount); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal(address borrower, uint repayAmount) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, borrower, repayAmount); } struct RepayBorrowLocalVars { Error err; MathError mathErr; uint repayAmount; uint borrowerIndex; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; uint actualRepayAmount; } /** * @notice Borrows are repaid by another user (possibly the borrower). * @param payer the account paying off the borrow * @param borrower the account with the debt being payed off * @param repayAmount the amount of undelrying tokens being returned * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowFresh(address payer, address borrower, uint repayAmount) internal returns (uint, uint) { /* Fail if repayBorrow not allowed */ uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0); } RepayBorrowLocalVars memory vars; /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower); if (vars.mathErr != MathError.NO_ERROR) { return (failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)), 0); } /* If repayAmount == -1, repayAmount = accountBorrows */ if (repayAmount == uint(-1)) { vars.repayAmount = vars.accountBorrows; } else { vars.repayAmount = repayAmount; } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the payer and the repayAmount * Note: The cToken must handle variations between ERC-20 and native token underlying. * On success, the cToken holds an additional repayAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ (vars.mathErr, vars.accountBorrowsNew) = subUInt(vars.accountBorrows, vars.actualRepayAmount); require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED"); (vars.mathErr, vars.totalBorrowsNew) = subUInt(totalBorrows, vars.actualRepayAmount); require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED"); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); return (uint(Error.NO_ERROR), vars.actualRepayAmount); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowInternal(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal nonReentrant returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0); } error = cTokenCollateral.accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal returns (uint, uint) { /* Fail if liquidate not allowed */ uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0); } /* Verify cTokenCollateral market's block timestamp equals current block timestamp */ if (cTokenCollateral.accrualBlockTimestamp() != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0); } /* Fail if repayAmount = -1 */ if (repayAmount == uint(-1)) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0); } /* Fail if repayBorrow fails */ (uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount); if (repayBorrowError != uint(Error.NO_ERROR)) { return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), actualRepayAmount); require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED"); /* Revert if borrower collateral token balance < seizeTokens */ require(cTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH"); // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call uint seizeError; if (address(cTokenCollateral) == address(this)) { seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { seizeError = cTokenCollateral.seize(liquidator, borrower, seizeTokens); } /* Revert if seize tokens fails (since we cannot be sure of side effects) */ require(seizeError == uint(Error.NO_ERROR), "token seizure failed"); /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens); return (uint(Error.NO_ERROR), actualRepayAmount); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another cToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize(address liquidator, address borrower, uint seizeTokens) external nonReentrant returns (uint) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } struct SeizeInternalLocalVars { MathError mathErr; uint borrowerTokensNew; uint liquidatorTokensNew; uint liquidatorSeizeTokens; uint protocolSeizeTokens; uint protocolSeizeAmount; uint exchangeRateMantissa; uint totalReservesNew; uint totalSupplyNew; } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken. * Its absolutely critical to use msg.sender as the seizer cToken and not a parameter. * @param seizerToken The contract seizing the collateral (i.e. borrowed cToken) * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal returns (uint) { /* Fail if seize not allowed */ uint allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER); } SeizeInternalLocalVars memory vars; /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ (vars.mathErr, vars.borrowerTokensNew) = subUInt(accountTokens[borrower], seizeTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, uint(vars.mathErr)); } vars.protocolSeizeTokens = mul_(seizeTokens, Exp({mantissa: protocolSeizeShareMantissa})); vars.liquidatorSeizeTokens = sub_(seizeTokens, vars.protocolSeizeTokens); (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); require(vars.mathErr == MathError.NO_ERROR, "exchange rate math error"); vars.protocolSeizeAmount = mul_ScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), vars.protocolSeizeTokens); vars.totalReservesNew = add_(totalReserves, vars.protocolSeizeAmount); vars.totalSupplyNew = sub_(totalSupply, vars.protocolSeizeTokens); (vars.mathErr, vars.liquidatorTokensNew) = addUInt(accountTokens[liquidator], vars.liquidatorSeizeTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, uint(vars.mathErr)); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ totalReserves = vars.totalReservesNew; totalSupply = vars.totalSupplyNew; accountTokens[borrower] = vars.borrowerTokensNew; accountTokens[liquidator] = vars.liquidatorTokensNew; /* Emit a Transfer event */ emit Transfer(borrower, liquidator, vars.liquidatorSeizeTokens); emit Transfer(borrower, address(this), vars.protocolSeizeTokens); emit ReservesAdded(address(this), vars.protocolSeizeAmount, vars.totalReservesNew); return uint(Error.NO_ERROR); } /*** Admin Functions ***/ /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() external returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Sets a new comptroller for the market * @dev Admin function to set a new comptroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setComptroller(ComptrollerInterface newComptroller) public returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COMPTROLLER_OWNER_CHECK); } ComptrollerInterface oldComptroller = comptroller; // Ensure invoke comptroller.isComptroller() returns true require(newComptroller.isComptroller(), "marker method returned false"); // Set market's comptroller to newComptroller comptroller = newComptroller; // Emit NewComptroller(oldComptroller, newComptroller) emit NewComptroller(oldComptroller, newComptroller); return uint(Error.NO_ERROR); } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint newReserveFactorMantissa) external nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed. return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED); } // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK); } // Verify market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK); } // Check newReserveFactor ≤ maxReserveFactor if (newReserveFactorMantissa > reserveFactorMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK); } uint oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Accrues interest and reduces reserves by transferring from msg.sender * @param addAmount Amount of addition to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReservesInternal(uint addAmount) internal nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED); } // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to. (error, ) = _addReservesFresh(addAmount); return error; } /** * @notice Add reserves by transferring from caller * @dev Requires fresh interest accrual * @param addAmount Amount of addition to reserves * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees */ function _addReservesFresh(uint addAmount) internal returns (uint, uint) { // totalReserves + actualAddAmount uint totalReservesNew; uint actualAddAmount; // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.ADD_RESERVES_FRESH_CHECK), actualAddAmount); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the caller and the addAmount * Note: The cToken must handle variations between ERC-20 and native token underlying. * On success, the cToken holds an additional addAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ actualAddAmount = doTransferIn(msg.sender, addAmount); totalReservesNew = totalReserves + actualAddAmount; /* Revert on overflow */ require(totalReservesNew >= totalReserves, "add reserves unexpected overflow"); // Store reserves[n+1] = reserves[n] + actualAddAmount totalReserves = totalReservesNew; /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */ emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew); /* Return (NO_ERROR, actualAddAmount) */ return (uint(Error.NO_ERROR), actualAddAmount); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint reduceAmount) external nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED); } // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint reduceAmount) internal returns (uint) { // totalReserves - reduceAmount uint totalReservesNew; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK); } // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) totalReservesNew = totalReserves - reduceAmount; // We checked reduceAmount <= totalReserves above, so this should never revert. require(totalReservesNew <= totalReserves, "reduce reserves unexpected underflow"); // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. doTransferOut(admin, reduceAmount); emit ReservesReduced(admin, reduceAmount, totalReservesNew); return uint(Error.NO_ERROR); } /** * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh * @dev Admin function to accrue interest and update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED); } // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK); } // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK); } // Track the market's current interest rate model oldInterestRateModel = interestRateModel; // Ensure invoke newInterestRateModel.isInterestRateModel() returns true require(newInterestRateModel.isInterestRateModel(), "marker method returned false"); // Set the interest rate model to newInterestRateModel interestRateModel = newInterestRateModel; // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel) emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel); return uint(Error.NO_ERROR); } /** * @notice accrues interest and updates the protocol seize share using _setProtocolSeizeShareFresh * @dev Admin function to accrue interest and update the protocol seize share * @param newProtocolSeizeShareMantissa the new protocol seize share to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setProtocolSeizeShare(uint newProtocolSeizeShareMantissa) external nonReentrant returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of protocol seize share failed return fail(Error(error), FailureInfo.SET_PROTOCOL_SEIZE_SHARE_ACCRUE_INTEREST_FAILED); } // _setProtocolSeizeShareFresh emits protocol-seize-share-update-specific logs on errors, so we don't need to. return _setProtocolSeizeShareFresh(newProtocolSeizeShareMantissa); } /** * @notice updates the protocol seize share (*requires fresh interest accrual) * @dev Admin function to update the protocol seize share * @param newProtocolSeizeShareMantissa the new protocol seize share to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setProtocolSeizeShareFresh(uint newProtocolSeizeShareMantissa) internal returns (uint) { // Used to store old share for use in the event that is emitted on success uint oldProtocolSeizeShareMantissa; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PROTOCOL_SEIZE_SHARE_OWNER_CHECK); } // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_PROTOCOL_SEIZE_SHARE_FRESH_CHECK); } // Track the market's current protocol seize share oldProtocolSeizeShareMantissa = protocolSeizeShareMantissa; // Set the protocol seize share to newProtocolSeizeShareMantissa protocolSeizeShareMantissa = newProtocolSeizeShareMantissa; // Emit NewProtocolSeizeShareMantissa(oldProtocolSeizeShareMantissa, newProtocolSeizeShareMantissa) emit NewProtocolSeizeShare(oldProtocolSeizeShareMantissa, newProtocolSeizeShareMantissa); return uint(Error.NO_ERROR); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying owned by this contract */ function getCashPrior() internal view returns (uint); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn(address from, uint amount) internal returns (uint); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut(address payable to, uint amount) internal; /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() { require(_notEntered, "re-entered"); _notEntered = false; _; _notEntered = true; // get a gas-refund post-Istanbul } }
contracts/CTokenInterfaces.sol
pragma solidity 0.5.17; import "./ComptrollerInterface.sol"; import "./InterestRateModel.sol"; import "./EIP20NonStandardInterface.sol"; contract CTokenStorage { /** * @dev Guard variable for re-entrancy checks */ bool internal _notEntered; /** * @notice EIP-20 token name for this token */ string public name; /** * @notice EIP-20 token symbol for this token */ string public symbol; /** * @notice EIP-20 token decimals for this token */ uint8 public decimals; /** * @notice Maximum borrow rate that can ever be applied (.0005% / block) */ uint internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves */ uint internal constant reserveFactorMaxMantissa = 1e18; /** * @notice Administrator for this contract */ address payable public admin; /** * @notice Pending administrator for this contract */ address payable public pendingAdmin; /** * @notice Contract which oversees inter-cToken operations */ ComptrollerInterface public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) */ uint internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint public accrualBlockTimestamp; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint public totalReserves; /** * @notice Total number of tokens in circulation */ uint public totalSupply; /** * @notice Official record of token balances for each account */ mapping (address => uint) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping (address => mapping (address => uint)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint principal; uint interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; /** * @notice Share of seized collateral that is added to reserves */ uint public protocolSeizeShareMantissa; } contract CTokenInterface is CTokenStorage { /** * @notice Indicator that this is a CToken contract (for inspection) */ bool public constant isCToken = true; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint mintAmount, uint mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint redeemAmount, uint redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens); /*** Admin Events ***/ /** * @notice Event emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Event emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /** * @notice Event emitted when comptroller is changed */ event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa); /** * @notice Event emitted when the protocol seize share is changed */ event NewProtocolSeizeShare(uint oldProtocolSeizeShareMantissa, uint newProtocolSeizeShareMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint amount); /** * @notice Failure event */ event Failure(uint error, uint info, uint detail); /*** User Interface ***/ function transfer(address dst, uint amount) external returns (bool); function transferFrom(address src, address dst, uint amount) external returns (bool); function approve(address spender, uint amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint); function balanceOf(address owner) external view returns (uint); function balanceOfUnderlying(address owner) external returns (uint); function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint); function borrowRatePerTimestamp() external view returns (uint); function supplyRatePerTimestamp() external view returns (uint); function totalBorrowsCurrent() external returns (uint); function borrowBalanceCurrent(address account) external returns (uint); function borrowBalanceStored(address account) public view returns (uint); function exchangeRateCurrent() public returns (uint); function exchangeRateStored() public view returns (uint); function getCash() external view returns (uint); function accrueInterest() public returns (uint); function seize(address liquidator, address borrower, uint seizeTokens) external returns (uint); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint); function _acceptAdmin() external returns (uint); function _setComptroller(ComptrollerInterface newComptroller) public returns (uint); function _setReserveFactor(uint newReserveFactorMantissa) external returns (uint); function _reduceReserves(uint reduceAmount) external returns (uint); function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint); function _setProtocolSeizeShare(uint newProtocolSeizeShareMantissa) external returns (uint); } contract CErc20Storage { /** * @notice Underlying asset for this CToken */ address public underlying; } contract CWNatStorage { address public genesisPool; } contract CErc20Interface is CErc20Storage { /*** User Interface ***/ function mint(uint mintAmount) external returns (uint); function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow(uint repayAmount) external returns (uint); function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint); function sweepToken(EIP20NonStandardInterface token) external; /*** Admin Functions ***/ function _addReserves(uint addAmount) external returns (uint); } contract CNativeInterface { /*** User Interface ***/ function mint() external payable; function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow() external payable; function repayBorrowBehalf(address borrower) external payable; function liquidateBorrow(address borrower, CTokenInterface cTokenCollateral) external payable; function () external payable; /*** Admin Functions ***/ function _addReserves() external payable returns (uint); } contract ProtocolTokenDelegationStorage { /** * @notice Implementation address for this contract */ address public implementation; } contract ProtocolTokenDelegatorInterface is ProtocolTokenDelegationStorage { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public; } contract ProtocolTokenDelegateInterface is ProtocolTokenDelegationStorage { /** * @notice Called by the delegator on a delegate to initialize it for duty * @dev Should revert if any issues arise which make it unfit for delegation * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes memory data) public; /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() public; }
contracts/ComptrollerInterface.sol
pragma solidity 0.5.17; contract ComptrollerInterface { /// @notice Indicator that this is a Comptroller contract (for inspection) bool public constant isComptroller = true; /*** Assets You Are In ***/ function enterMarkets(address[] calldata cTokens) external returns (uint[] memory); function exitMarket(address cToken) external returns (uint); /*** Policy Hooks ***/ function mintAllowed(address qiToken, address minter, uint mintAmount) external returns (uint); function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint); function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external; function borrowAllowed(address qiToken, address borrower, uint borrowAmount) external returns (uint); function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint); function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint); function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint); function transferAllowed(address qiToken, address src, address dst, uint transferTokens) external returns (uint); /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint repayAmount) external view returns (uint, uint); }
contracts/ComptrollerStorage.sol
pragma solidity 0.5.17; import "./CToken.sol"; import "./PriceOracle.sol"; contract UnitrollerAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Active brains of Unitroller */ address public comptrollerImplementation; /** * @notice Pending brains of Unitroller */ address public pendingComptrollerImplementation; } contract ComptrollerVXStorage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ PriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint public liquidationIncentiveMantissa; /** * @notice Max number of assets a single account can participate in (borrow or use as collateral) */ uint public maxAssets; /** * @notice Per-account mapping of "assets you are in", capped by maxAssets */ mapping(address => CToken[]) public accountAssets; struct Market { /// @notice Whether or not this market is listed bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint collateralFactorMantissa; /// @notice Per-market mapping of "accounts in this asset" mapping(address => bool) accountMembership; } /** * @notice Official mapping of cTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /** * @notice The Pause Guardian can pause certain actions as a safety mechanism. * Actions which allow users to remove their own assets cannot be paused. * Liquidation / seizing / transfer can only be paused globally, not by market. */ address public pauseGuardian; bool public _mintGuardianPaused; bool public _borrowGuardianPaused; bool public transferGuardianPaused; bool public seizeGuardianPaused; mapping(address => bool) public mintGuardianPaused; mapping(address => bool) public borrowGuardianPaused; /// @notice A list of all markets CToken[] public allMarkets; // @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market. address public borrowCapGuardian; // @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing. mapping(address => uint) public borrowCaps; struct RewardMarketState { /// @notice The market's last updated rewardBorrowIndex or rewardSupplyIndex uint224 index; /// @notice The block timestamp the index was last updated at uint32 timestamp; } /// @notice The rate at which the flywheel distributes reward, per timestamp mapping(uint8 => uint) rewardRate; /// @notice The portion of reward rate that each market currently receives for supplying mapping(uint8 => mapping(address => uint)) public supplyRewardSpeeds; /// @notice The rewards market supply state for each market mapping(uint8 => mapping(address => RewardMarketState)) public rewardSupplyState; /// @notice The rewards market borrow state for each market mapping(uint8 =>mapping(address => RewardMarketState)) public rewardBorrowState; /// @notice The rewards borrow index for each market for each supplier as of the last time they accrued reward mapping(uint8 => mapping(address => mapping(address => uint))) public rewardSupplierIndex; /// @notice The rewards borrow index for each market for each borrower as of the last time they accrued reward mapping(uint8 => mapping(address => mapping(address => uint))) public rewardBorrowerIndex; /// @notice The rewards accrued but not yet transferred to each user mapping(uint8 => mapping(address => uint)) public rewardAccrued; /// @notice Protocol token contract address address public protocolTokenAddress; /// @notice The portion of reward rate that each market currently receives for borrowing mapping(uint8 => mapping(address => uint)) public borrowRewardSpeeds; /// @notice Whitelisted Liquidators verifier contract address address public liquidatorsWhitelistVerifier; /// @notice The reward tokens configured address[] internal rewardTokens; }
contracts/EIP20Interface.sol
pragma solidity 0.5.17; /** * @title ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface EIP20Interface { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external returns (bool success); /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external returns (bool success); /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
contracts/EIP20NonStandardInterface.sol
pragma solidity 0.5.17; /** * @title EIP20NonStandardInterface * @dev Version of ERC20 with no return values for `transfer` and `transferFrom` * See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ interface EIP20NonStandardInterface { /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transfer(address dst, uint256 amount) external; /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transferFrom(address src, address dst, uint256 amount) external; /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
contracts/ErrorReporter.sol
pragma solidity 0.5.17; contract ComptrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, COMPTROLLER_MISMATCH, INSUFFICIENT_SHORTFALL, INSUFFICIENT_LIQUIDITY, INVALID_CLOSE_FACTOR, INVALID_COLLATERAL_FACTOR, INVALID_LIQUIDATION_INCENTIVE, MARKET_NOT_ENTERED, MARKET_NOT_LISTED, MARKET_ALREADY_LISTED, MATH_ERROR, NONZERO_BORROW_BALANCE, PRICE_ERROR, REJECTION, SNAPSHOT_ERROR, TOO_MANY_ASSETS, TOO_MUCH_REPAY } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, EXIT_MARKET_BALANCE_OWED, EXIT_MARKET_REJECTION, SET_CLOSE_FACTOR_OWNER_CHECK, SET_CLOSE_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_NO_EXISTS, SET_COLLATERAL_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_WITHOUT_PRICE, SET_IMPLEMENTATION_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_VALIDATION, SET_MAX_ASSETS_OWNER_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK, SET_PRICE_ORACLE_OWNER_CHECK, SUPPORT_MARKET_EXISTS, SUPPORT_MARKET_OWNER_CHECK, SET_PAUSE_GUARDIAN_OWNER_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } } contract TokenErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, BAD_INPUT, COMPTROLLER_REJECTION, COMPTROLLER_CALCULATION_ERROR, INTEREST_RATE_MODEL_ERROR, INVALID_ACCOUNT_PAIR, INVALID_CLOSE_AMOUNT_REQUESTED, INVALID_COLLATERAL_FACTOR, MATH_ERROR, MARKET_NOT_FRESH, MARKET_NOT_LISTED, TOKEN_INSUFFICIENT_ALLOWANCE, TOKEN_INSUFFICIENT_BALANCE, TOKEN_INSUFFICIENT_CASH, TOKEN_TRANSFER_IN_FAILED, TOKEN_TRANSFER_OUT_FAILED } /* * Note: FailureInfo (but not Error) is kept in alphabetical order * This is because FailureInfo grows significantly faster, and * the order of Error has some meaning, while the order of FailureInfo * is entirely arbitrary. */ enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, BORROW_ACCRUE_INTEREST_FAILED, BORROW_CASH_NOT_AVAILABLE, BORROW_FRESHNESS_CHECK, BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, BORROW_MARKET_NOT_LISTED, BORROW_COMPTROLLER_REJECTION, LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED, LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED, LIQUIDATE_COLLATERAL_FRESHNESS_CHECK, LIQUIDATE_COMPTROLLER_REJECTION, LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED, LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX, LIQUIDATE_CLOSE_AMOUNT_IS_ZERO, LIQUIDATE_FRESHNESS_CHECK, LIQUIDATE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_REPAY_BORROW_FRESH_FAILED, LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_SEIZE_TOO_MUCH, MINT_ACCRUE_INTEREST_FAILED, MINT_COMPTROLLER_REJECTION, MINT_EXCHANGE_CALCULATION_FAILED, MINT_EXCHANGE_RATE_READ_FAILED, MINT_FRESHNESS_CHECK, MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, MINT_TRANSFER_IN_FAILED, MINT_TRANSFER_IN_NOT_POSSIBLE, REDEEM_ACCRUE_INTEREST_FAILED, REDEEM_COMPTROLLER_REJECTION, REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, REDEEM_EXCHANGE_RATE_READ_FAILED, REDEEM_FRESHNESS_CHECK, REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, REDEEM_TRANSFER_OUT_NOT_POSSIBLE, REDUCE_RESERVES_ACCRUE_INTEREST_FAILED, REDUCE_RESERVES_ADMIN_CHECK, REDUCE_RESERVES_CASH_NOT_AVAILABLE, REDUCE_RESERVES_FRESH_CHECK, REDUCE_RESERVES_VALIDATION, REPAY_BEHALF_ACCRUE_INTEREST_FAILED, REPAY_BORROW_ACCRUE_INTEREST_FAILED, REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, REPAY_BORROW_COMPTROLLER_REJECTION, REPAY_BORROW_FRESHNESS_CHECK, REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_VALIDATION, SET_COMPTROLLER_OWNER_CHECK, SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED, SET_INTEREST_RATE_MODEL_FRESH_CHECK, SET_INTEREST_RATE_MODEL_OWNER_CHECK, SET_MAX_ASSETS_OWNER_CHECK, SET_ORACLE_MARKET_NOT_LISTED, SET_PENDING_ADMIN_OWNER_CHECK, SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED, SET_RESERVE_FACTOR_ADMIN_CHECK, SET_RESERVE_FACTOR_FRESH_CHECK, SET_RESERVE_FACTOR_BOUNDS_CHECK, TRANSFER_COMPTROLLER_REJECTION, TRANSFER_NOT_ALLOWED, TRANSFER_NOT_ENOUGH, TRANSFER_TOO_MUCH, ADD_RESERVES_ACCRUE_INTEREST_FAILED, ADD_RESERVES_FRESH_CHECK, ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE, SET_PROTOCOL_SEIZE_SHARE_ACCRUE_INTEREST_FAILED, SET_PROTOCOL_SEIZE_SHARE_OWNER_CHECK, SET_PROTOCOL_SEIZE_SHARE_FRESH_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } }
contracts/Exponential.sol
pragma solidity 0.5.17; import "./CarefulMath.sol"; import "./ExponentialNoError.sol"; /** * @title Exponential module for storing fixed-precision decimals * @author RBL * @dev Legacy contract for compatibility reasons with existing contracts that still use MathError * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places. * Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is: * `Exp({mantissa: 5100000000000000000})`. */ contract Exponential is CarefulMath, ExponentialNoError { /** * @dev Creates an exponential from numerator and denominator values. * Note: Returns an error if (`num` * 10e18) > MAX_INT, * or if `denom` is zero. */ function getExp(uint num, uint denom) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint rational) = divUInt(scaledNumerator, denom); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: rational})); } /** * @dev Adds two exponentials, returning a new exponential. */ function addExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError error, uint result) = addUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Subtracts two exponentials, returning a new exponential. */ function subExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError error, uint result) = subUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Multiply an Exp by a scalar, returning a new Exp. */ function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa})); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa})); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ (MathError err0, uint numerator) = mulUInt(expScale, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return getExp(numerator, divisor.mantissa); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } // We add half the scale before dividing so that we get rounding instead of truncation. // See "Listing 6" and text above it at https://accu.org/index.php/journals/1717 // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18. (MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale); // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero. assert(err2 == MathError.NO_ERROR); return (MathError.NO_ERROR, Exp({mantissa: product})); } /** * @dev Multiplies two exponentials given their mantissas, returning a new exponential. */ function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) { return mulExp(Exp({mantissa: a}), Exp({mantissa: b})); } /** * @dev Multiplies three exponentials, returning a new exponential. */ function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) { (MathError err, Exp memory ab) = mulExp(a, b); if (err != MathError.NO_ERROR) { return (err, ab); } return mulExp(ab, c); } /** * @dev Divides two exponentials, returning a new exponential. * (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, * which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa) */ function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } }
contracts/ExponentialNoError.sol
pragma solidity 0.5.17; /** * @title Exponential module for storing fixed-precision decimals * @author RBL * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places. * Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is: * `Exp({mantissa: 5100000000000000000})`. */ contract ExponentialNoError { uint constant expScale = 1e18; uint constant doubleScale = 1e36; uint constant halfExpScale = expScale/2; uint constant mantissaOne = expScale; struct Exp { uint mantissa; } struct Double { uint mantissa; } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) pure internal returns (uint) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint scalar) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev Checks if left Exp > right Exp. */ function greaterThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa > right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) pure internal returns (bool) { return value.mantissa == 0; } function safe224(uint n, string memory errorMessage) pure internal returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint n, string memory errorMessage) pure internal returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint a, uint b) pure internal returns (uint) { return add_(a, b, "addition overflow"); } function add_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { uint c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint a, uint b) pure internal returns (uint) { return sub_(a, b, "subtraction underflow"); } function sub_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Exp memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Double memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint a, uint b) pure internal returns (uint) { return mul_(a, b, "multiplication overflow"); } function mul_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { if (a == 0 || b == 0) { return 0; } uint c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Exp memory b) pure internal returns (uint) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Double memory b) pure internal returns (uint) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint a, uint b) pure internal returns (uint) { return div_(a, b, "divide by zero"); } function div_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b > 0, errorMessage); return a / b; } function fraction(uint a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } }
contracts/InterestRateModel.sol
pragma solidity 0.5.17; /** * @title Protocol's InterestRateModel Interface * @author RBL */ contract InterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) bool public constant isInterestRateModel = true; /** * @notice Calculates the current borrow interest rate per timestmp * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @return The borrow rate per timestmp (as a percentage, and scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint); /** * @notice Calculates the current supply interest rate per timestmp * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per timestmp (as a percentage, and scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view returns (uint); }
contracts/OpenZeppelin/Address.sol
pragma solidity 0.5.17; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } }
contracts/OpenZeppelin/SafeERC20.sol
pragma solidity 0.5.17; import "../EIP20Interface.sol"; import "../SafeMath.sol"; import "./Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(EIP20Interface token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(EIP20Interface token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(EIP20Interface token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "NZA" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(EIP20Interface token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(EIP20Interface token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(EIP20Interface token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "CNC"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "LLCF"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "EODNS"); } } }
contracts/PriceOracle.sol
pragma solidity 0.5.17; import "./CToken.sol"; contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /** * @notice Get the underlying price of a cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(CToken cToken) external view returns (uint); }
contracts/SafeMath.sol
pragma solidity 0.5.17; // From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/Math.sol // Subject to the MIT license. /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the addition of two unsigned integers, reverting with custom message on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction underflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } /** * @dev Returns the integer division of two unsigned integers. * Reverts on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. * Reverts with custom message on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
contracts/Tokenomics/IAllowlist.sol
interface IAllowList{ function allowed(address address_) external returns (bool); }
contracts/Unitroller.sol
pragma solidity 0.5.17; import "./ErrorReporter.sol"; import "./ComptrollerStorage.sol"; /** * @title ComptrollerCore * @dev Storage for the comptroller is at this address, while execution is delegated to the `comptrollerImplementation`. * CTokens should reference this contract as their comptroller. */ contract Unitroller is UnitrollerAdminStorage, ComptrollerErrorReporter { /** * @notice Emitted when pendingComptrollerImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingComptrollerImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingComptrollerImplementation || pendingComptrollerImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = comptrollerImplementation; address oldPendingImplementation = pendingComptrollerImplementation; comptrollerImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = address(0); emit NewImplementation(oldImplementation, comptrollerImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // delegate all other functions to current implementation (bool success, ) = comptrollerImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[]},{"type":"event","name":"ActionPaused","inputs":[{"type":"string","name":"action","internalType":"string","indexed":false},{"type":"bool","name":"pauseState","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"ActionPaused","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":false},{"type":"string","name":"action","internalType":"string","indexed":false},{"type":"bool","name":"pauseState","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"BorrowRewardSpeedUpdated","inputs":[{"type":"uint8","name":"rewardToken","internalType":"uint8","indexed":false},{"type":"address","name":"cToken","internalType":"contract CToken","indexed":true},{"type":"uint256","name":"newBorrowRewardSpeed","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"DistributedBorrowerReward","inputs":[{"type":"uint8","name":"tokenType","internalType":"uint8","indexed":true},{"type":"address","name":"cToken","internalType":"contract CToken","indexed":true},{"type":"address","name":"borrower","internalType":"address","indexed":true},{"type":"uint256","name":"amountDelta","internalType":"uint256","indexed":false},{"type":"uint256","name":"borrowIndex","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"DistributedSupplierReward","inputs":[{"type":"uint8","name":"tokenType","internalType":"uint8","indexed":true},{"type":"address","name":"cToken","internalType":"contract CToken","indexed":true},{"type":"address","name":"supplier","internalType":"address","indexed":true},{"type":"uint256","name":"amountDelta","internalType":"uint256","indexed":false},{"type":"uint256","name":"supplyIndex","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Failure","inputs":[{"type":"uint256","name":"error","internalType":"uint256","indexed":false},{"type":"uint256","name":"info","internalType":"uint256","indexed":false},{"type":"uint256","name":"detail","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"MarketEntered","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":false},{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"MarketExited","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":false},{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"MarketListed","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":false}],"anonymous":false},{"type":"event","name":"NewBorrowCap","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":true},{"type":"uint256","name":"newBorrowCap","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NewBorrowCapGuardian","inputs":[{"type":"address","name":"oldBorrowCapGuardian","internalType":"address","indexed":false},{"type":"address","name":"newBorrowCapGuardian","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewCloseFactor","inputs":[{"type":"uint256","name":"oldCloseFactorMantissa","internalType":"uint256","indexed":false},{"type":"uint256","name":"newCloseFactorMantissa","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NewCollateralFactor","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken","indexed":false},{"type":"uint256","name":"oldCollateralFactorMantissa","internalType":"uint256","indexed":false},{"type":"uint256","name":"newCollateralFactorMantissa","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NewLiquidationIncentive","inputs":[{"type":"uint256","name":"oldLiquidationIncentiveMantissa","internalType":"uint256","indexed":false},{"type":"uint256","name":"newLiquidationIncentiveMantissa","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NewLiquidatorsWhitelistVerifier","inputs":[{"type":"address","name":"oldLiquidatorsWhitelistVerifier","internalType":"address","indexed":false},{"type":"address","name":"newLiquidatorsWhitelistVerifier","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewPauseGuardian","inputs":[{"type":"address","name":"oldPauseGuardian","internalType":"address","indexed":false},{"type":"address","name":"newPauseGuardian","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewPriceOracle","inputs":[{"type":"address","name":"oldPriceOracle","internalType":"contract PriceOracle","indexed":false},{"type":"address","name":"newPriceOracle","internalType":"contract PriceOracle","indexed":false}],"anonymous":false},{"type":"event","name":"NewRewardType","inputs":[{"type":"address","name":"rewardAddress","internalType":"address","indexed":true},{"type":"uint8","name":"rewardIndex","internalType":"uint8","indexed":true}],"anonymous":false},{"type":"event","name":"RewardTokenGranted","inputs":[{"type":"address","name":"recipient","internalType":"address","indexed":false},{"type":"uint8","name":"rewardType","internalType":"uint8","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"SupplyRewardSpeedUpdated","inputs":[{"type":"uint8","name":"rewardToken","internalType":"uint8","indexed":false},{"type":"address","name":"cToken","internalType":"contract CToken","indexed":true},{"type":"uint256","name":"newSupplyRewardSpeed","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"fallback","stateMutability":"payable","payable":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"_become","inputs":[{"type":"address","name":"unitroller","internalType":"contract Unitroller"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_borrowGuardianPaused","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"_grantRewardTokens","inputs":[{"type":"address","name":"recipient","internalType":"address payable"},{"type":"uint8","name":"rewardType","internalType":"uint8"},{"type":"uint256","name":"amount","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_mintGuardianPaused","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"_setBorrowCapGuardian","inputs":[{"type":"address","name":"newBorrowCapGuardian","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_setBorrowPaused","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken"},{"type":"bool","name":"state","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_setCloseFactor","inputs":[{"type":"uint256","name":"newCloseFactorMantissa","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_setCollateralFactor","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken"},{"type":"uint256","name":"newCollateralFactorMantissa","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_setLiquidationIncentive","inputs":[{"type":"uint256","name":"newLiquidationIncentiveMantissa","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"_setMarketBorrowCaps","inputs":[{"type":"address[]","name":"cTokens","internalType":"contract CToken[]"},{"type":"uint256[]","name":"newBorrowCaps","internalType":"uint256[]"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_setMintPaused","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken"},{"type":"bool","name":"state","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_setPauseGuardian","inputs":[{"type":"address","name":"newPauseGuardian","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_setPriceOracle","inputs":[{"type":"address","name":"newOracle","internalType":"contract PriceOracle"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"_setRewardSpeed","inputs":[{"type":"uint8","name":"rewardType","internalType":"uint8"},{"type":"address","name":"cToken","internalType":"contract CToken"},{"type":"uint256","name":"supplyRewardSpeed","internalType":"uint256"},{"type":"uint256","name":"borrowRewardSpeed","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_setSeizePaused","inputs":[{"type":"bool","name":"state","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"_setTransferPaused","inputs":[{"type":"bool","name":"state","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"_supportMarket","inputs":[{"type":"address","name":"cToken","internalType":"contract CToken"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract CToken"}],"name":"accountAssets","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"admin","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract CToken"}],"name":"allMarkets","inputs":[{"type":"uint256","name":"","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"borrowAllowed","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"borrower","internalType":"address"},{"type":"uint256","name":"borrowAmount","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"borrowCapGuardian","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"borrowCaps","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"borrowGuardianPaused","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"borrowRewardSpeeds","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"checkMembership","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"address","name":"cToken","internalType":"contract CToken"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"claimReward","inputs":[{"type":"uint8","name":"rewardType","internalType":"uint8"},{"type":"address","name":"holder","internalType":"address payable"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"claimReward","inputs":[{"type":"uint8","name":"rewardType","internalType":"uint8"},{"type":"address","name":"holder","internalType":"address payable"},{"type":"address[]","name":"cTokens","internalType":"contract CToken[]"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"claimReward","inputs":[{"type":"uint8","name":"rewardType","internalType":"uint8"},{"type":"address[]","name":"holders","internalType":"address payable[]"},{"type":"address[]","name":"cTokens","internalType":"contract CToken[]"},{"type":"bool","name":"borrowers","internalType":"bool"},{"type":"bool","name":"suppliers","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"closeFactorMantissa","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"comptrollerImplementation","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"enterMarkets","inputs":[{"type":"address[]","name":"cTokens","internalType":"address[]"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"exitMarket","inputs":[{"type":"address","name":"cTokenAddress","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getAccountLiquidity","inputs":[{"type":"address","name":"account","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"contract CToken[]"}],"name":"getAllMarkets","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getAllRewardTokens","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address[]","name":"","internalType":"contract CToken[]"}],"name":"getAssetsIn","inputs":[{"type":"address","name":"account","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBlockTimestamp","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getHypotheticalAccountLiquidity","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"address","name":"cTokenModify","internalType":"address"},{"type":"uint256","name":"redeemTokens","internalType":"uint256"},{"type":"uint256","name":"borrowAmount","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint224","name":"","internalType":"uint224"}],"name":"initialIndexConstant","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isComptroller","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"liquidateBorrowAllowed","inputs":[{"type":"address","name":"cTokenBorrowed","internalType":"address"},{"type":"address","name":"cTokenCollateral","internalType":"address"},{"type":"address","name":"liquidator","internalType":"address"},{"type":"address","name":"borrower","internalType":"address"},{"type":"uint256","name":"repayAmount","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"liquidateCalculateSeizeTokens","inputs":[{"type":"address","name":"cTokenBorrowed","internalType":"address"},{"type":"address","name":"cTokenCollateral","internalType":"address"},{"type":"uint256","name":"actualRepayAmount","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"liquidationIncentiveMantissa","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"liquidatorsWhitelistVerifier","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"isListed","internalType":"bool"},{"type":"uint256","name":"collateralFactorMantissa","internalType":"uint256"}],"name":"markets","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxAssets","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintAllowed","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"minter","internalType":"address"},{"type":"uint256","name":"mintAmount","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"mintGuardianPaused","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract PriceOracle"}],"name":"oracle","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pauseGuardian","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pendingAdmin","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pendingComptrollerImplementation","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"protocolTokenAddress","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"redeemAllowed","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"redeemer","internalType":"address"},{"type":"uint256","name":"redeemTokens","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"redeemVerify","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"redeemer","internalType":"address"},{"type":"uint256","name":"redeemAmount","internalType":"uint256"},{"type":"uint256","name":"redeemTokens","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"repayBorrowAllowed","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"payer","internalType":"address"},{"type":"address","name":"borrower","internalType":"address"},{"type":"uint256","name":"repayAmount","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardAccrued","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint224","name":"index","internalType":"uint224"},{"type":"uint32","name":"timestamp","internalType":"uint32"}],"name":"rewardBorrowState","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardBorrowerIndex","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"rewardNativeToken","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardSupplierIndex","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint224","name":"index","internalType":"uint224"},{"type":"uint32","name":"timestamp","internalType":"uint32"}],"name":"rewardSupplyState","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"seizeAllowed","inputs":[{"type":"address","name":"cTokenCollateral","internalType":"address"},{"type":"address","name":"cTokenBorrowed","internalType":"address"},{"type":"address","name":"liquidator","internalType":"address"},{"type":"address","name":"borrower","internalType":"address"},{"type":"uint256","name":"seizeTokens","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"seizeGuardianPaused","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setProtocolTokenAddress","inputs":[{"type":"address","name":"newProtocolTokenAddress","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setRewardType","inputs":[{"type":"address","name":"rewardAddress","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setliquidatorsWhitelistAddress","inputs":[{"type":"address","name":"newLiquidatorsWhitelistVerifier","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"supplyRewardSpeeds","inputs":[{"type":"uint8","name":"","internalType":"uint8"},{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"transferAllowed","inputs":[{"type":"address","name":"cToken","internalType":"address"},{"type":"address","name":"src","internalType":"address"},{"type":"address","name":"dst","internalType":"address"},{"type":"uint256","name":"transferTokens","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transferGuardianPaused","inputs":[],"constant":true}]
Contract Creation Code
0x608060405234801561001057600080fd5b50600080546001600160a01b03191633179055615fb680620000336000396000f3fe60806040526004361061040f5760003560e01c8063796b89b91161021e578063c299823811610123578063e3ff9370116100ab578063eabe7d911161007a578063eabe7d9114611407578063ed302dfd1461144a578063ede4edd01461147b578063f706b1f2146114ae578063f851a440146114c35761040f565b8063e3ff937014611371578063e4028eee146113a4578063e6653f3d146113dd578063e8755446146113f25761040f565b8063d02f7351116100f2578063d02f735114611251578063d81c5e45146112a4578063da3d454c146112e0578063dce1544914611323578063dcfbc0c71461135c5761040f565b8063c2998238146110cf578063c376fada1461117d578063c488847b146111b9578063cf9cfb61146112155761040f565b806394b2294b116101a6578063ac0b0bb711610175578063ac0b0bb714611032578063b0772d0b14611047578063bb82aa5e1461105c578063bdcdc25814611071578063bf0fd615146110ba5761040f565b806394b2294b14610f8c578063a76b3fda14610fa1578063a957455614610fd4578063abfceffc14610fff5761040f565b806388e972b8116101ed57806388e972b814610e605780638c5fb24e14610ea45780638e8f294b14610ed75780638ebf636414610f25578063929fe9a114610f515761040f565b8063796b89b914610ceb5780637dc0d1d014610d0057806387f7630314610d155780638805714b14610d2a5761040f565b80633f6fa1781161032457806355ee1fe1116102ac578063607ef6c11161027b578063607ef6c114610ab05780636d154ea514610b7b578063731f0c2b14610bae578063744532ae14610be15780637937969d14610ca75761040f565b806355ee1fe1146109c45780635ec88c79146109f75780635f5af1aa14610a2a5780635fc7e71e14610a5d5761040f565b80634e79238f116102f35780634e79238f1461087d5780634ef4c3e1146108e45780634fd42e171461092757806351dff9891461095157806352d84d1e1461099a5761040f565b80633f6fa1781461078f5780634a584432146107d15780634ada90af146108045780634b3a0a74146108195761040f565b806324008a62116103a7578063317b0b7711610376578063317b0b77146106af578063391957d7146106d95780633bcf7ec11461070c5780633c94786f146107475780633f0769211461075c5761040f565b806324008a621461061057806324a3d62214610659578063267822471461066e5780632d70db78146106835761040f565b806318c882a5116103e357806318c882a5146105295780631d504dc6146105645780631d94cb941461059757806321af4569146105df5761040f565b80627e3dd21461041157806305b9783d1461043a5780630952c5631461048857806312edb24c146104c4575b005b34801561041d57600080fd5b506104266114d8565b604080519115158252519081900360200190f35b34801561044657600080fd5b506104766004803603604081101561045d57600080fd5b50803560ff1690602001356001600160a01b03166114dd565b60408051918252519081900360200190f35b34801561049457600080fd5b5061040f600480360360408110156104ab57600080fd5b50803560ff1690602001356001600160a01b03166114fa565b3480156104d057600080fd5b506104d9611563565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156105155781810151838201526020016104fd565b505050509050019250505060405180910390f35b34801561053557600080fd5b506104266004803603604081101561054c57600080fd5b506001600160a01b03813516906020013515156115c6565b34801561057057600080fd5b5061040f6004803603602081101561058757600080fd5b50356001600160a01b0316611748565b3480156105a357600080fd5b5061040f600480360360808110156105ba57600080fd5b5060ff813516906001600160a01b03602082013516906040810135906060013561188f565b3480156105eb57600080fd5b506105f461191d565b604080516001600160a01b039092168252519081900360200190f35b34801561061c57600080fd5b506104766004803603608081101561063357600080fd5b506001600160a01b0381358116916020810135821691604082013516906060013561192c565b34801561066557600080fd5b506105f46119e9565b34801561067a57600080fd5b506105f46119f8565b34801561068f57600080fd5b50610426600480360360208110156106a657600080fd5b50351515611a07565b3480156106bb57600080fd5b50610476600480360360208110156106d257600080fd5b5035611b28565b3480156106e557600080fd5b5061040f600480360360208110156106fc57600080fd5b50356001600160a01b0316611bba565b34801561071857600080fd5b506104266004803603604081101561072f57600080fd5b506001600160a01b0381351690602001351515611c61565b34801561075357600080fd5b50610426611dde565b34801561076857600080fd5b5061040f6004803603602081101561077f57600080fd5b50356001600160a01b0316611dee565b34801561079b57600080fd5b5061040f600480360360608110156107b257600080fd5b506001600160a01b038135169060ff6020820135169060400135611e9c565b3480156107dd57600080fd5b50610476600480360360208110156107f457600080fd5b50356001600160a01b0316612179565b34801561081057600080fd5b5061047661218b565b34801561082557600080fd5b506108556004803603604081101561083c57600080fd5b50803560ff1690602001356001600160a01b0316612191565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b34801561088957600080fd5b506108c6600480360360808110156108a057600080fd5b506001600160a01b038135811691602081013590911690604081013590606001356121c6565b60408051938452602084019290925282820152519081900360600190f35b3480156108f057600080fd5b506104766004803603606081101561090757600080fd5b506001600160a01b03813581169160208101359091169060400135612200565b34801561093357600080fd5b506104766004803603602081101561094a57600080fd5b5035612291565b34801561095d57600080fd5b5061040f6004803603608081101561097457600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135612301565b3480156109a657600080fd5b506105f4600480360360208110156109bd57600080fd5b5035612346565b3480156109d057600080fd5b50610476600480360360208110156109e757600080fd5b50356001600160a01b031661236d565b348015610a0357600080fd5b506108c660048036036020811015610a1a57600080fd5b50356001600160a01b03166123f2565b348015610a3657600080fd5b5061047660048036036020811015610a4d57600080fd5b50356001600160a01b0316612427565b348015610a6957600080fd5b50610476600480360360a0811015610a8057600080fd5b506001600160a01b03813581169160208101358216916040820135811691606081013590911690608001356124ab565b348015610abc57600080fd5b5061040f60048036036040811015610ad357600080fd5b810190602081018135600160201b811115610aed57600080fd5b820183602082011115610aff57600080fd5b803590602001918460208302840111600160201b83111715610b2057600080fd5b919390929091602081019035600160201b811115610b3d57600080fd5b820183602082011115610b4f57600080fd5b803590602001918460208302840111600160201b83111715610b7057600080fd5b5090925090506126d1565b348015610b8757600080fd5b5061042660048036036020811015610b9e57600080fd5b50356001600160a01b0316612851565b348015610bba57600080fd5b5061042660048036036020811015610bd157600080fd5b50356001600160a01b0316612866565b348015610bed57600080fd5b5061040f60048036036060811015610c0457600080fd5b60ff823516916001600160a01b0360208201351691810190606081016040820135600160201b811115610c3657600080fd5b820183602082011115610c4857600080fd5b803590602001918460208302840111600160201b83111715610c6957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061287b945050505050565b348015610cb357600080fd5b5061047660048036036060811015610cca57600080fd5b5060ff813516906001600160a01b03602082013581169160400135166128d9565b348015610cf757600080fd5b506104766128fc565b348015610d0c57600080fd5b506105f4612900565b348015610d2157600080fd5b5061042661290f565b61040f600480360360a0811015610d4057600080fd5b60ff8235169190810190604081016020820135600160201b811115610d6457600080fd5b820183602082011115610d7657600080fd5b803590602001918460208302840111600160201b83111715610d9757600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b811115610de657600080fd5b820183602082011115610df857600080fd5b803590602001918460208302840111600160201b83111715610e1957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955050505080351515915060200135151561291f565b348015610e6c57600080fd5b5061047660048036036060811015610e8357600080fd5b5060ff813516906001600160a01b0360208201358116916040013516612ba7565b348015610eb057600080fd5b5061040f60048036036020811015610ec757600080fd5b50356001600160a01b0316612bca565b348015610ee357600080fd5b50610f0a60048036036020811015610efa57600080fd5b50356001600160a01b0316612e13565b60408051921515835260208301919091528051918290030190f35b348015610f3157600080fd5b5061042660048036036020811015610f4857600080fd5b50351515612e32565b348015610f5d57600080fd5b5061042660048036036040811015610f7457600080fd5b506001600160a01b0381358116916020013516612f52565b348015610f9857600080fd5b50610476612f85565b348015610fad57600080fd5b5061047660048036036020811015610fc457600080fd5b50356001600160a01b0316612f8b565b348015610fe057600080fd5b50610fe96114d8565b6040805160ff9092168252519081900360200190f35b34801561100b57600080fd5b506104d96004803603602081101561102257600080fd5b50356001600160a01b03166130eb565b34801561103e57600080fd5b50610426613174565b34801561105357600080fd5b506104d9613184565b34801561106857600080fd5b506105f46131e4565b34801561107d57600080fd5b506104766004803603608081101561109457600080fd5b506001600160a01b038135811691602081013582169160408201351690606001356131f3565b3480156110c657600080fd5b506105f461326a565b3480156110db57600080fd5b506104d9600480360360208110156110f257600080fd5b810190602081018135600160201b81111561110c57600080fd5b82018360208201111561111e57600080fd5b803590602001918460208302840111600160201b8311171561113f57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550613279945050505050565b34801561118957600080fd5b50610476600480360360408110156111a057600080fd5b50803560ff1690602001356001600160a01b0316613310565b3480156111c557600080fd5b506111fc600480360360608110156111dc57600080fd5b506001600160a01b0381358116916020810135909116906040013561332d565b6040805192835260208301919091528051918290030190f35b34801561122157600080fd5b506104766004803603604081101561123857600080fd5b50803560ff1690602001356001600160a01b031661355d565b34801561125d57600080fd5b50610476600480360360a081101561127457600080fd5b506001600160a01b038135811691602081013582169160408201358116916060810135909116906080013561357a565b3480156112b057600080fd5b50610855600480360360408110156112c757600080fd5b50803560ff1690602001356001600160a01b0316613750565b3480156112ec57600080fd5b506104766004803603606081101561130357600080fd5b506001600160a01b03813581169160208101359091169060400135613785565b34801561132f57600080fd5b506105f46004803603604081101561134657600080fd5b506001600160a01b038135169060200135613b19565b34801561136857600080fd5b506105f4613b4e565b34801561137d57600080fd5b5061040f6004803603602081101561139457600080fd5b50356001600160a01b0316613b5d565b3480156113b057600080fd5b50610476600480360360408110156113c757600080fd5b506001600160a01b038135169060200135613b96565b3480156113e957600080fd5b50610426613d46565b3480156113fe57600080fd5b50610476613d56565b34801561141357600080fd5b506104766004803603606081101561142a57600080fd5b506001600160a01b03813581169160208101359091169060400135613d5c565b34801561145657600080fd5b5061145f613d8e565b604080516001600160e01b039092168252519081900360200190f35b34801561148757600080fd5b506104766004803603602081101561149e57600080fd5b50356001600160a01b0316613da0565b3480156114ba57600080fd5b506105f46140ae565b3480156114cf57600080fd5b506105f46140bd565b600181565b601660209081526000928352604080842090915290825290205481565b61155f8282600d80548060200260200160405190810160405280929190818152602001828054801561155557602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611537575b505050505061287b565b5050565b6060601a8054806020026020016040519081016040528092919081815260200182805480156115bb57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161159d575b505050505090505b90565b6001600160a01b03821660009081526009602052604081205460ff16611618576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b600a546001600160a01b031633148061163b57506000546001600160a01b031633145b611671576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b031633148061168c57506001821515145b6116c2576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6001600160a01b0383166000818152600c6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260069083015265426f72726f7760d01b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150805b92915050565b806001600160a01b031663f851a4406040518163ffffffff1660e01b815260040160206040518083038186803b15801561178157600080fd5b505afa158015611795573d6000803e3d6000fd5b505050506040513d60208110156117ab57600080fd5b50516001600160a01b031633146117ee576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b806001600160a01b031663c1e803346040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561182957600080fd5b505af115801561183d573d6000803e3d6000fd5b505050506040513d602081101561185357600080fd5b50511561188c576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b50565b601a5460ff8516106118cd576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b6118d56140cc565b61190b576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b611917848484846140f5565b50505050565b600e546001600160a01b031681565b6001600160a01b03841660009081526009602052604081205460ff16611954575060096119e1565b61195c615ec2565b6040518060200160405280876001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119a057600080fd5b505afa1580156119b4573d6000803e3d6000fd5b505050506040513d60208110156119ca57600080fd5b5051905290506119db8685836142f8565b60009150505b949350505050565b600a546001600160a01b031681565b6001546001600160a01b031681565b600a546000906001600160a01b0316331480611a2d57506000546001600160a01b031633145b611a63576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480611a7e57506001821515145b611ab4576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600a8054831515600160b81b810260ff60b81b1990921691909117909155604080516020810192909252808252600582820152645365697a6560d81b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a150805b919050565b600080546001600160a01b03163314611b6d576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6005805490839055604080518281526020810185905281517f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd9929181900390910190a160005b9392505050565b6000546001600160a01b03163314611bfe576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600e80546001600160a01b038381166001600160a01b0319831681179093556040805191909216808252602082019390935281517feda98690e518e9a05f8ec6837663e188211b2da8f4906648b323f2c1d4434e29929181900390910190a15050565b6001600160a01b03821660009081526009602052604081205460ff16611cb3576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b600a546001600160a01b0316331480611cd657506000546001600160a01b031633145b611d0c576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480611d2757506001821515145b611d5d576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6001600160a01b0383166000818152600b6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260049083015263135a5b9d60e21b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150919050565b600a54600160a01b900460ff1681565b6000546001600160a01b03163314611e32576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601954604080516001600160a01b039283168152918316602083015280517fc2689fb64a73fb7e8c5d93c42a54cf839d2c0b41f51bd192f2a4e16dbb29b63c9281900390910190a1601980546001600160a01b0319166001600160a01b0392909216919091179055565b611ea46140cc565b611eda576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601a5460ff831610611f18576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60008111611f52576040805162461bcd60e51b8152602060048201526002602482015261494160f01b604482015290519081900360640190fd5b60ff82166001141561202e5747811115611f98576040805162461bcd60e51b815260206004820152600260248201526124a360f11b604482015290519081900360640190fd5b6040516000906001600160a01b03851690610fbd90849084818181858888f193505050503d8060008114611fe8576040519150601f19603f3d011682016040523d82523d6000602084013e611fed565b606091505b5050905080612028576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b50612129565b601a8260ff168154811061203e57fe5b60009182526020918290200154604080516370a0823160e01b815230600482015290516001600160a01b03909216926370a0823192602480840193829003018186803b15801561208d57600080fd5b505afa1580156120a1573d6000803e3d6000fd5b505050506040513d60208110156120b757600080fd5b50518111156120f2576040805162461bcd60e51b815260206004820152600260248201526124a360f11b604482015290519081900360640190fd5b6121298382601a8560ff168154811061210757fe5b6000918252602090912001546001600160a01b0316919063ffffffff61432716565b604080516001600160a01b038516815260ff8416602082015280820183905290517fce7d734fdce67e276e886b8335e89f7c635c6680207366139dd02a51c96b08489181900360600190a1505050565b600f6020526000908152604090205481565b60065481565b60136020908152600092835260408084209091529082529020546001600160e01b03811690600160e01b900463ffffffff1682565b6000806000806000806121db8a8a8a8a61437e565b9250925092508260118111156121ed57fe5b95509093509150505b9450945094915050565b6001600160a01b0383166000908152600b602052604081205460ff1615612253576040805162461bcd60e51b815260206004820152600260248201526104d560f41b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff1661227d5760095b9050611bb3565b61228784846146b6565b6000949350505050565b600080546001600160a01b031633146122b7576122b06001600b6146e3565b9050611b23565b6006805490839055604080518281526020810185905281517faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec1316929181900390910190a16000611bb3565b8015801561230f5750600082115b15611917576040805162461bcd60e51b8152602060048201526002602482015261292b60f11b604482015290519081900360640190fd5b600d818154811061235357fe5b6000918252602090912001546001600160a01b0316905081565b600080546001600160a01b0316331461238c576122b0600160106146e3565b600480546001600160a01b038481166001600160a01b0319831681179093556040805191909216808252602082019390935281517fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22929181900390910190a16000611bb3565b60008060008060008061240987600080600061437e565b92509250925082601181111561241b57fe5b97919650945092505050565b600080546001600160a01b03163314612446576122b0600160136146e3565b600a80546001600160a01b038481166001600160a01b0319831617928390556040805192821680845293909116602083015280517f0613b6ee6a04f0d09f390e4d9318894b9f6ac7fd83897cd8d18896ba579c401e9281900390910190a16000611bb3565b6019546040805163d63a8e1160e01b81526001600160a01b0386811660048301529151600093929092169163d63a8e119160248082019260209290919082900301818787803b1580156124fd57600080fd5b505af1158015612511573d6000803e3d6000fd5b505050506040513d602081101561252757600080fd5b50516125375760015b90506126c8565b6001600160a01b03861660009081526009602052604090205460ff16158061257857506001600160a01b03851660009081526009602052604090205460ff16155b15612584576009612530565b6001600160a01b038086166000908152600960209081526040808320938716835260029093019052205460ff166125bc576008612530565b6000806125c885614749565b919350909150600090508260118111156125de57fe5b146125f8578160118111156125ef57fe5b925050506126c8565b806126045760036125ef565b6000886001600160a01b03166395dd9193876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561265c57600080fd5b505afa158015612670573d6000803e3d6000fd5b505050506040513d602081101561268657600080fd5b5051604080516020810190915260055481529091506000906126a89083614769565b9050808611156126bf5760119450505050506126c8565b60009450505050505b95945050505050565b6000546001600160a01b03163314806126f45750600e546001600160a01b031633145b61272a576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b8281811580159061273a57508082145b612770576040805162461bcd60e51b8152602060048201526002602482015261494960f01b604482015290519081900360640190fd5b60005b828110156128485784848281811061278757fe5b90506020020135600f600089898581811061279e57fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b03168152602001908152602001600020819055508686828181106127de57fe5b905060200201356001600160a01b03166001600160a01b03167f6f1951b2aad10f3fc81b86d91105b413a5b3f847a34bbc5ce1904201b14438f686868481811061282457fe5b905060200201356040518082815260200191505060405180910390a2600101612773565b50505050505050565b600c6020526000908152604090205460ff1681565b600b6020526000908152604090205460ff1681565b6040805160018082528183019092526060916020808301908038833901905050905082816000815181106128ab57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505061191784828460018061291f565b601560209081526000938452604080852082529284528284209052825290205481565b4290565b6004546001600160a01b031681565b600a54600160b01b900460ff1681565b601a5460ff86161061295d576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60005b8351811015612b9f57600084828151811061297757fe5b6020908102919091018101516001600160a01b0381166000908152600990925260409091205490915060ff166129d9576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b60018415151415612b0e576129ec615ec2565b6040518060200160405280836001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612a3057600080fd5b505afa158015612a44573d6000803e3d6000fd5b505050506040513d6020811015612a5a57600080fd5b505190529050612a6b888383614788565b60005b8751811015612b0b57612a9689848a8481518110612a8857fe5b602002602001015185614a7b565b612b0389898381518110612aa657fe5b6020026020010151601660008d60ff1660ff16815260200190815260200160002060008c8681518110612ad557fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054614ce6565b600101612a6e565b50505b60018315151415612b9657612b238782614f1c565b60005b8651811015612b9457612b4d8883898481518110612b4057fe5b60200260200101516151cf565b612b8c88888381518110612b5d57fe5b6020026020010151601660008c60ff1660ff16815260200190815260200160002060008b8681518110612ad557fe5b600101612b26565b505b50600101612960565b505050505050565b601460209081526000938452604080852082529284528284209052825290205481565b6000546001600160a01b03163314612c0e576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601a54612c77576017546001600160a01b031615801590612c3c57506017546001600160a01b038281169116145b612c72576040805162461bcd60e51b8152602060048201526002602482015261141560f21b604482015290519081900360640190fd5b612cc3565b601a5460011415612cc3576001600160a01b03811615612cc3576040805162461bcd60e51b81526020600482015260026024820152614e4f60f01b604482015290519081900360640190fd5b6000805b601a54811015612d1457826001600160a01b0316601a8281548110612ce857fe5b6000918252602090912001546001600160a01b03161415612d0c5760019150612d14565b600101612cc7565b508015612d4d576040805162461bcd60e51b8152602060048201526002602482015261415360f01b604482015290519081900360640190fd5b601a5460405160ff8216906001600160a01b038516907f44ce9959cf08b43b70e35e8f294c500e0ee993d805c21cef930f5c5c5967e9db90600090a3601a80546001810182556000919091527f057c384a7d1c54f3a1b2e5e67b2617b8224fdfd1ea7234eea573a6ff665ff63e0180546001600160a01b0319166001600160a01b0385161790556060612dde613184565b805190915060005b81811015612b9f57612e0b84848381518110612dfe57fe5b6020026020010151615431565b600101612de6565b6009602052600090815260409020805460019091015460ff9091169082565b600a546000906001600160a01b0316331480612e5857506000546001600160a01b031633145b612e8e576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480612ea957506001821515145b612edf576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600a8054831515600160b01b810260ff60b01b1990921691909117909155604080516020810192909252808252600882820152672a3930b739b332b960c11b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a15090565b6001600160a01b038082166000908152600960209081526040808320938616835260029093019052205460ff1692915050565b60075481565b600080546001600160a01b03163314612faa576122b0600160126146e3565b6001600160a01b03821660009081526009602052604090205460ff1615612fd7576122b0600a60116146e3565b816001600160a01b031663fe9c44ae6040518163ffffffff1660e01b815260040160206040518083038186803b15801561301057600080fd5b505afa158015613024573d6000803e3d6000fd5b505050506040513d602081101561303a57600080fd5b50506040805180820182526001808252600060208084018281526001600160a01b038816835260099091529390209151825460ff1916901515178255915191015561308482615527565b60005b601a5460ff821610156130a65761309e8184615431565b600101613087565b50604080516001600160a01b038416815290517fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f9181900360200190a1600092915050565b60608060086000846001600160a01b03166001600160a01b0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561316757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613149575b5093979650505050505050565b600a54600160b81b900460ff1681565b6060600d8054806020026020016040519081016040528092919081815260200182805480156115bb576020028201919060005260206000209081546001600160a01b0316815260019091019060200180831161159d575050505050905090565b6002546001600160a01b031681565b600a54600090600160b01b900460ff161561323a576040805162461bcd60e51b8152602060048201526002602482015261054560f41b604482015290519081900360640190fd5b60006132478686856155f4565b905080156132565790506119e1565b61326086866146b6565b6119db86856146b6565b6019546001600160a01b031681565b60606000825190506060816040519080825280602002602001820160405280156132ad578160200160208202803883390190505b50905060005b828110156133085760008582815181106132c957fe5b602002602001015190506132dd81336156a0565b60118111156132e857fe5b8383815181106132f457fe5b6020908102919091010152506001016132b3565b509392505050565b601860209081526000928352604080842090915290825290205481565b600480546040805163fc57d4df60e01b81526001600160a01b038781169482019490945290516000938493849391169163fc57d4df91602480820192602092909190829003018186803b15801561338357600080fd5b505afa158015613397573d6000803e3d6000fd5b505050506040513d60208110156133ad57600080fd5b5051600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051939450600093929091169163fc57d4df91602480820192602092909190829003018186803b15801561340657600080fd5b505afa15801561341a573d6000803e3d6000fd5b505050506040513d602081101561343057600080fd5b5051905081158061343f575080155b1561345457600d935060009250613555915050565b6000866001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b15801561348f57600080fd5b505afa1580156134a3573d6000803e3d6000fd5b505050506040513d60208110156134b957600080fd5b5051905060006134c7615ec2565b6134cf615ec2565b6134d7615ec2565b613508613502604051806020016040528060065481525060405180602001604052808b815250615796565b8b6157d5565b9250613530604051806020016040528088815250604051806020016040528088815250615796565b915061353c83836157ff565b905061354781615832565b600099509750505050505050505b935093915050565b601160209081526000928352604080842090915290825290205481565b600a54600090600160b81b900460ff16156135c1576040805162461bcd60e51b8152602060048201526002602482015261053560f41b604482015290519081900360640190fd5b6001600160a01b03861660009081526009602052604090205460ff16158061360257506001600160a01b03851660009081526009602052604090205460ff16155b1561360e576009612530565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561364757600080fd5b505afa15801561365b573d6000803e3d6000fd5b505050506040513d602081101561367157600080fd5b505160408051635fe3b56760e01b815290516001600160a01b0392831692891691635fe3b567916004808301926020929190829003018186803b1580156136b757600080fd5b505afa1580156136cb573d6000803e3d6000fd5b505050506040513d60208110156136e157600080fd5b50516001600160a01b0316146136f8576002612530565b6001600160a01b038087166000908152600960209081526040808320938716835260029093019052205460ff16613730576008612530565b61373a86846146b6565b61374486856146b6565b60009695505050505050565b60126020908152600092835260408084209091529082529020546001600160e01b03811690600160e01b900463ffffffff1682565b6001600160a01b0383166000908152600c602052604081205460ff16156137d8576040805162461bcd60e51b8152602060048201526002602482015261042560f41b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff166137ff576009612276565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff166138dc57336001600160a01b03851614613872576040805162461bcd60e51b815260206004820152600260248201526110d560f21b604482015290519081900360640190fd5b600061387e33856156a0565b9050600081601181111561388e57fe5b146138a75780601181111561389f57fe5b915050611bb3565b6001600160a01b038086166000908152600960209081526040808320938816835260029093019052205460ff166138da57fe5b505b600480546040805163fc57d4df60e01b81526001600160a01b03888116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b15801561392d57600080fd5b505afa158015613941573d6000803e3d6000fd5b505050506040513d602081101561395757600080fd5b505161396457600d612276565b6001600160a01b0384166000908152600f60205260409020548015613a36576000856001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b1580156139be57600080fd5b505afa1580156139d2573d6000803e3d6000fd5b505050506040513d60208110156139e857600080fd5b5051905060006139f88286615841565b9050828110613a33576040805162461bcd60e51b8152602060048201526002602482015261424360f01b604482015290519081900360640190fd5b50505b600080613a46868860008861437e565b91935090915060009050826011811115613a5c57fe5b14613a7757816011811115613a6d57fe5b9350505050611bb3565b8015613a84576004613a6d565b613a8c615ec2565b6040518060200160405280896001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b158015613ad057600080fd5b505afa158015613ae4573d6000803e3d6000fd5b505050506040513d6020811015613afa57600080fd5b505190529050613b0b8888836142f8565b600098975050505050505050565b60086020528160005260406000208181548110613b3257fe5b6000918252602090912001546001600160a01b03169150829050565b6003546001600160a01b031681565b6000546001600160a01b03163314613b7457600080fd5b601780546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160a01b03163314613bbc57613bb5600160066146e3565b9050611742565b6001600160a01b0383166000908152600960205260409020805460ff16613bf157613be9600960076146e3565b915050611742565b613bf9615ec2565b506040805160208101909152838152613c10615ec2565b506040805160208101909152670c7d713b49da00008152613c318183615877565b15613c4c57613c42600660086146e3565b9350505050611742565b8415801590613cd55750600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b158015613ca757600080fd5b505afa158015613cbb573d6000803e3d6000fd5b505050506040513d6020811015613cd157600080fd5b5051155b15613ce657613c42600d60096146e3565b60018301805490869055604080516001600160a01b03891681526020810183905280820188905290517f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59181900360600190a16000979650505050505050565b600a54600160a81b900460ff1681565b60055481565b600080613d6a8585856155f4565b90508015613d79579050611bb3565b613d8385856146b6565b600095945050505050565b6a0c097ce7bc90715b34b9f160241b81565b6000808290506000806000836001600160a01b031663c37f68e2336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b158015613e0157600080fd5b505afa158015613e15573d6000803e3d6000fd5b505050506040513d6080811015613e2b57600080fd5b508051602082015160409092015190945090925090508215613e79576040805162461bcd60e51b815260206004820152600260248201526121a360f11b604482015290519081900360640190fd5b8015613e9657613e8b600c60026146e3565b945050505050611b23565b6000613ea38733856155f4565b90508015613ec457613eb8600e60038361587e565b95505050505050611b23565b6001600160a01b0385166000908152600960209081526040808320338452600281019092529091205460ff16613f035760009650505050505050611b23565b3360009081526002820160209081526040808320805460ff191690556008825291829020805483518184028101840190945280845260609392830182828015613f7557602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613f57575b5050835193945083925060009150505b82811015613fca57896001600160a01b0316848281518110613fa357fe5b60200260200101516001600160a01b03161415613fc257809150613fca565b600101613f85565b50818110613fd457fe5b336000908152600860205260409020805481906000198101908110613ff557fe5b9060005260206000200160009054906101000a90046001600160a01b031681838154811061401f57fe5b600091825260209091200180546001600160a01b0319166001600160a01b03929092169190911790558054614058826000198301615ed5565b50604080516001600160a01b038c16815233602082015281517fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d929181900390910190a160009c9b505050505050505050505050565b6017546001600160a01b031681565b6000546001600160a01b031681565b600080546001600160a01b03163314806140f057506002546001600160a01b031633145b905090565b6001600160a01b03831660009081526009602052604090205460ff16614147576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b60ff841660008181526011602090815260408083206001600160a01b03881680855290835281842054948452601883528184209084529091529020548382146141fb576141948686614f1c565b60ff861660008181526011602090815260408083206001600160a01b038a16808552908352928190208890558051938452908301879052805191927f2577edc53863f2e6d759b5da2c36549292f23909793d20feb1886bc21b17782f929081900390910190a25b828114612b9f5761420a615ec2565b6040518060200160405280876001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561424e57600080fd5b505afa158015614262573d6000803e3d6000fd5b505050506040513d602081101561427857600080fd5b505190529050614289878783614788565b60ff871660008181526018602090815260408083206001600160a01b038b16808552908352928190208890558051938452908301879052805191927fee48fe28e41d25c72d48e0c4580dbeac6fb4ef83cd3401ced307912114e2e5eb929081900390910190a250505050505050565b60005b601a5460ff8216101561191757614313818584614788565b61431f81858585614a7b565b6001016142fb565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526143799084906158e4565b505050565b600080600061438b615ef9565b6001600160a01b038816600090815260086020908152604080832080548251818502810185019093528083526060938301828280156143f357602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116143d5575b50939450600093505050505b815181101561467757600082828151811061441657fe5b60200260200101519050806001600160a01b031663c37f68e28d6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b15801561447657600080fd5b505afa15801561448a573d6000803e3d6000fd5b505050506040513d60808110156144a057600080fd5b508051602082015160408084015160609485015160808b01529389019390935291870191909152935083156144e55750600f9650600095508594506121f69350505050565b60408051602080820183526001600160a01b0380851660008181526009845285902060010154845260c08a01939093528351808301855260808a0151815260e08a015260048054855163fc57d4df60e01b815291820194909452935192169263fc57d4df9260248083019392829003018186803b15801561456557600080fd5b505afa158015614579573d6000803e3d6000fd5b505050506040513d602081101561458f57600080fd5b505160a086018190526145b25750600d9650600095508594506121f69350505050565b604080516020810190915260a0860151815261010086015260c085015160e08601516145ec916145e191615796565b866101000151615796565b610120860181905260408601518651614606929190615a69565b855261010085015160608601516020870151614623929190615a69565b60208601526001600160a01b03818116908c16141561466e576146508561012001518b8760200151615a69565b60208601819052610100860151614668918b90615a69565b60208601525b506001016143ff565b5060208301518351111561469d57505060208101519051600094500391508290506121f6565b50508051602090910151600094508493500390506121f6565b60005b601a5460ff82161015614379576146d08184614f1c565b6146db8184846151cf565b6001016146b9565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa083601181111561471257fe5b83601381111561471e57fe5b604080519283526020830191909152600082820152519081900360600190a1826011811115611bb357fe5b600080600061475c84600080600061437e565b9250925092509193909250565b6000614773615ec2565b61477d84846157d5565b90506119e181615832565b601a5460ff8416106147c6576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff831660008181526013602090815260408083206001600160a01b038716808552908352818420948452601883528184209084529091528120549061480a6128fc565b835490915060009061482a908390600160e01b900463ffffffff16615a91565b905060008111801561483c5750600083115b15614a295760006148b1876001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561487f57600080fd5b505afa158015614893573d6000803e3d6000fd5b505050506040513d60208110156148a957600080fd5b505187615acb565b905060006148bf8386615ae9565b90506148c9615ec2565b600083116148e657604051806020016040528060008152506148f0565b6148f08284615b2b565b90506148fa615ec2565b604080516020810190915288546001600160e01b0316815261491c9083615b5f565b905060405180604001604052806149528360000151604051806040016040528060038152602001620c8c8d60ea1b815250615b84565b6001600160e01b031681526020016149848860405180604001604052806002815260200161199960f11b815250615c1e565b63ffffffff16815250601360008d60ff1660ff16815260200190815260200160002060008c6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a8154816001600160e01b0302191690836001600160e01b03160217905550602082015181600001601c6101000a81548163ffffffff021916908363ffffffff16021790555090505050505050612848565b801561284857614a538260405180604001604052806002815260200161199960f11b815250615c1e565b845463ffffffff91909116600160e01b026001600160e01b0390911617845550505050505050565b601a5460ff851610614ab9576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff841660009081526013602090815260408083206001600160a01b03871684529091529020614ae7615ec2565b50604080516020810190915281546001600160e01b03168152614b08615ec2565b50604080516020808201835260ff89166000908152601582528381206001600160a01b03808b16835290835284822090891680835281845294822080548552865195909252909152919091558051158015614b72575081516a0c097ce7bc90715b34b9f160241b11155b15614b89576a0c097ce7bc90715b34b9f160241b81525b614b91615ec2565b614b9b8383615c73565b90506000614bf8886001600160a01b03166395dd9193896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561487f57600080fd5b90506000614c068284615c98565b60ff8b1660009081526016602090815260408083206001600160a01b038d16845290915281205491925090614c3b9083615841565b905080601660008d60ff1660ff16815260200190815260200160002060008b6001600160a01b03166001600160a01b0316815260200190815260200160002081905550886001600160a01b03168a6001600160a01b03168c60ff167fa1b6a046664a0ecf068059f26de56878f8d0e799907ca2e42d9148ccbdc717a7858a60000151604051808381526020018281526020019250505060405180910390a45050505050505050505050565b60ff831660011415614e0957478115801590614d025750808211155b15614e035760ff841660009081526016602090815260408083206001600160a01b038716808552925280832083905551610fbd90859084818181858888f193505050503d8060008114614d71576040519150601f19603f3d011682016040523d82523d6000602084013e614d76565b606091505b5050905080614db1576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b604080516001600160a01b038616815260ff8716602082015280820185905290517fce7d734fdce67e276e886b8335e89f7c635c6680207366139dd02a51c96b08489181900360600190a15050614379565b50614ef0565b6000601a8460ff1681548110614e1b57fe5b6000918252602080832090910154604080516370a0823160e01b815230600482015290516001600160a01b03909216945084926370a0823192602480840193829003018186803b158015614e6e57600080fd5b505afa158015614e82573d6000803e3d6000fd5b505050506040513d6020811015614e9857600080fd5b505190508215801590614eab5750808311155b15614eed5760ff851660009081526016602090815260408083206001600160a01b0380891685529252822091909155614db1908316858563ffffffff61432716565b50505b60ff9290921660009081526016602090815260408083206001600160a01b039490941683529290522055565b601a5460ff831610614f5a576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff821660008181526012602090815260408083206001600160a01b0386168085529083528184209484526011835281842090845290915281205490614f9e6128fc565b8354909150600090614fbe908390600160e01b900463ffffffff16615a91565b9050600081118015614fd05750600083115b1561517e576000856001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561501057600080fd5b505afa158015615024573d6000803e3d6000fd5b505050506040513d602081101561503a57600080fd5b50519050600061504a8386615ae9565b9050615054615ec2565b60008311615071576040518060200160405280600081525061507b565b61507b8284615b2b565b9050615085615ec2565b604080516020810190915288546001600160e01b031681526150a79083615b5f565b905060405180604001604052806150dd8360000151604051806040016040528060038152602001620c8c8d60ea1b815250615b84565b6001600160e01b0316815260200161510f8860405180604001604052806002815260200161199960f11b815250615c1e565b63ffffffff90811690915260ff8c1660009081526012602090815260408083206001600160a01b038f1684528252909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b0319909416939093171691909117905550612b9f92505050565b8015612b9f576151a88260405180604001604052806002815260200161199960f11b815250615c1e565b845463ffffffff91909116600160e01b026001600160e01b03909116178455505050505050565b601a5460ff84161061520d576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff831660009081526012602090815260408083206001600160a01b0386168452909152902061523b615ec2565b50604080516020810190915281546001600160e01b0316815261525c615ec2565b50604080516020808201835260ff88166000908152601482528381206001600160a01b03808a168352908352848220908816808352818452948220805485528651959092529091529190915580511580156152c6575081516a0c097ce7bc90715b34b9f160241b11155b156152dd576a0c097ce7bc90715b34b9f160241b81525b6152e5615ec2565b6152ef8383615c73565b90506000866001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561534957600080fd5b505afa15801561535d573d6000803e3d6000fd5b505050506040513d602081101561537357600080fd5b5051905060006153838284615c98565b60ff8a1660009081526016602090815260408083206001600160a01b038c168452909152812054919250906153b89083615841565b60ff8b1660008181526016602090815260408083206001600160a01b03808f16808652918452938290208690558b51825189815293840152815195965094928e1693927faccd035d02c456be35306aecd5a5fe62320713dde09ccd68b0a5e8ed930399999281900390910190a450505050505050505050565b600061545e61543e6128fc565b60405180604001604052806002815260200161199960f11b815250615c1e565b60ff841660008181526012602090815260408083206001600160a01b038816808552908352818420948452601383528184209084529091529020815492935090916001600160e01b03166154cb5781546001600160e01b0319166a0c097ce7bc90715b34b9f160241b1782555b80546001600160e01b03166154f95780546001600160e01b0319166a0c097ce7bc90715b34b9f160241b1781555b805463ffffffff909316600160e01b026001600160e01b039384168117909155815490921690911790555050565b60005b600d548110156155a157816001600160a01b0316600d828154811061554b57fe5b6000918252602090912001546001600160a01b03161415615599576040805162461bcd60e51b81526020600482015260036024820152624d414160e81b604482015290519081900360640190fd5b60010161552a565b50600d80546001810182556000919091527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb50180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03831660009081526009602052604081205460ff1661561b576009612276565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff16615653576000612276565b600080615663858786600061437e565b9193509091506000905082601181111561567957fe5b146156935781601181111561568a57fe5b92505050611bb3565b801561374457600461568a565b6001600160a01b0382166000908152600960205260408120805460ff166156cb576009915050611742565b6001600160a01b038316600090815260028201602052604090205460ff161515600114156156fd576000915050611742565b6001600160a01b0380841660008181526002840160209081526040808320805460ff19166001908117909155600883528184208054918201815584529282902090920180549489166001600160a01b031990951685179055815193845283019190915280517f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a59281900390910190a15060009392505050565b61579e615ec2565b6040518060200160405280670de0b6b3a76400006157c486600001518660000151615ae9565b816157cb57fe5b0490529392505050565b6157dd615ec2565b60405180602001604052806157f6856000015185615ae9565b90529392505050565b615807615ec2565b60405180602001604052806157f661582b8660000151670de0b6b3a7640000615ae9565b8551615cc6565b51670de0b6b3a7640000900490565b6000611bb38383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250615cf9565b5190511090565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08460118111156158ad57fe5b8460138111156158b957fe5b604080519283526020830191909152818101859052519081900360600190a18360118111156119e157fe5b6158f6826001600160a01b0316615d57565b61592d576040805162461bcd60e51b8152602060048201526003602482015262434e4360e81b604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b6020831061596b5780518252601f19909201916020918201910161594c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146159cd576040519150601f19603f3d011682016040523d82523d6000602084013e6159d2565b606091505b509150915081615a12576040805162461bcd60e51b81526020600480830191909152602482015263262621a360e11b604482015290519081900360640190fd5b80511561191757808060200190516020811015615a2e57600080fd5b5051611917576040805162461bcd60e51b8152602060048201526005602482015264454f444e5360d81b604482015290519081900360640190fd5b6000615a73615ec2565b615a7d85856157d5565b90506126c8615a8b82615832565b84615841565b6000611bb38383604051806040016040528060158152602001747375627472616374696f6e20756e646572666c6f7760581b815250615d90565b6000611bb3615ae284670de0b6b3a7640000615ae9565b8351615cc6565b6000611bb383836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250615dea565b615b33615ec2565b60405180602001604052806157f6615b59866a0c097ce7bc90715b34b9f160241b615ae9565b85615cc6565b615b67615ec2565b60405180602001604052806157f685600001518560000151615841565b600081600160e01b8410615c165760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015615bdb578181015183820152602001615bc3565b50505050905090810190601f168015615c085780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b509192915050565b600081600160201b8410615c165760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b615c7b615ec2565b60405180602001604052806157f685600001518560000151615a91565b60006a0c097ce7bc90715b34b9f160241b615cb7848460000151615ae9565b81615cbe57fe5b049392505050565b6000611bb383836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250615e60565b60008383018285821015615d4e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b50949350505050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4708181148015906119e1575050151592915050565b60008184841115615de25760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b505050900390565b6000831580615df7575082155b15615e0457506000611bb3565b83830283858281615e1157fe5b04148390615d4e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b60008183615eaf5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b50828481615eb957fe5b04949350505050565b6040518060200160405280600081525090565b81548183558181111561437957600083815260209020614379918101908301615f63565b604051806101400160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001615f37615ec2565b8152602001615f44615ec2565b8152602001615f51615ec2565b8152602001615f5e615ec2565b905290565b6115c391905b80821115615f7d5760008155600101615f69565b509056fea265627a7a723158206795c7e0baf5327fc2f79712b6c89044d8b9b01060540156919d2b5b07b70c6b64736f6c63430005110032
Deployed ByteCode
0x60806040526004361061040f5760003560e01c8063796b89b91161021e578063c299823811610123578063e3ff9370116100ab578063eabe7d911161007a578063eabe7d9114611407578063ed302dfd1461144a578063ede4edd01461147b578063f706b1f2146114ae578063f851a440146114c35761040f565b8063e3ff937014611371578063e4028eee146113a4578063e6653f3d146113dd578063e8755446146113f25761040f565b8063d02f7351116100f2578063d02f735114611251578063d81c5e45146112a4578063da3d454c146112e0578063dce1544914611323578063dcfbc0c71461135c5761040f565b8063c2998238146110cf578063c376fada1461117d578063c488847b146111b9578063cf9cfb61146112155761040f565b806394b2294b116101a6578063ac0b0bb711610175578063ac0b0bb714611032578063b0772d0b14611047578063bb82aa5e1461105c578063bdcdc25814611071578063bf0fd615146110ba5761040f565b806394b2294b14610f8c578063a76b3fda14610fa1578063a957455614610fd4578063abfceffc14610fff5761040f565b806388e972b8116101ed57806388e972b814610e605780638c5fb24e14610ea45780638e8f294b14610ed75780638ebf636414610f25578063929fe9a114610f515761040f565b8063796b89b914610ceb5780637dc0d1d014610d0057806387f7630314610d155780638805714b14610d2a5761040f565b80633f6fa1781161032457806355ee1fe1116102ac578063607ef6c11161027b578063607ef6c114610ab05780636d154ea514610b7b578063731f0c2b14610bae578063744532ae14610be15780637937969d14610ca75761040f565b806355ee1fe1146109c45780635ec88c79146109f75780635f5af1aa14610a2a5780635fc7e71e14610a5d5761040f565b80634e79238f116102f35780634e79238f1461087d5780634ef4c3e1146108e45780634fd42e171461092757806351dff9891461095157806352d84d1e1461099a5761040f565b80633f6fa1781461078f5780634a584432146107d15780634ada90af146108045780634b3a0a74146108195761040f565b806324008a62116103a7578063317b0b7711610376578063317b0b77146106af578063391957d7146106d95780633bcf7ec11461070c5780633c94786f146107475780633f0769211461075c5761040f565b806324008a621461061057806324a3d62214610659578063267822471461066e5780632d70db78146106835761040f565b806318c882a5116103e357806318c882a5146105295780631d504dc6146105645780631d94cb941461059757806321af4569146105df5761040f565b80627e3dd21461041157806305b9783d1461043a5780630952c5631461048857806312edb24c146104c4575b005b34801561041d57600080fd5b506104266114d8565b604080519115158252519081900360200190f35b34801561044657600080fd5b506104766004803603604081101561045d57600080fd5b50803560ff1690602001356001600160a01b03166114dd565b60408051918252519081900360200190f35b34801561049457600080fd5b5061040f600480360360408110156104ab57600080fd5b50803560ff1690602001356001600160a01b03166114fa565b3480156104d057600080fd5b506104d9611563565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156105155781810151838201526020016104fd565b505050509050019250505060405180910390f35b34801561053557600080fd5b506104266004803603604081101561054c57600080fd5b506001600160a01b03813516906020013515156115c6565b34801561057057600080fd5b5061040f6004803603602081101561058757600080fd5b50356001600160a01b0316611748565b3480156105a357600080fd5b5061040f600480360360808110156105ba57600080fd5b5060ff813516906001600160a01b03602082013516906040810135906060013561188f565b3480156105eb57600080fd5b506105f461191d565b604080516001600160a01b039092168252519081900360200190f35b34801561061c57600080fd5b506104766004803603608081101561063357600080fd5b506001600160a01b0381358116916020810135821691604082013516906060013561192c565b34801561066557600080fd5b506105f46119e9565b34801561067a57600080fd5b506105f46119f8565b34801561068f57600080fd5b50610426600480360360208110156106a657600080fd5b50351515611a07565b3480156106bb57600080fd5b50610476600480360360208110156106d257600080fd5b5035611b28565b3480156106e557600080fd5b5061040f600480360360208110156106fc57600080fd5b50356001600160a01b0316611bba565b34801561071857600080fd5b506104266004803603604081101561072f57600080fd5b506001600160a01b0381351690602001351515611c61565b34801561075357600080fd5b50610426611dde565b34801561076857600080fd5b5061040f6004803603602081101561077f57600080fd5b50356001600160a01b0316611dee565b34801561079b57600080fd5b5061040f600480360360608110156107b257600080fd5b506001600160a01b038135169060ff6020820135169060400135611e9c565b3480156107dd57600080fd5b50610476600480360360208110156107f457600080fd5b50356001600160a01b0316612179565b34801561081057600080fd5b5061047661218b565b34801561082557600080fd5b506108556004803603604081101561083c57600080fd5b50803560ff1690602001356001600160a01b0316612191565b604080516001600160e01b03909316835263ffffffff90911660208301528051918290030190f35b34801561088957600080fd5b506108c6600480360360808110156108a057600080fd5b506001600160a01b038135811691602081013590911690604081013590606001356121c6565b60408051938452602084019290925282820152519081900360600190f35b3480156108f057600080fd5b506104766004803603606081101561090757600080fd5b506001600160a01b03813581169160208101359091169060400135612200565b34801561093357600080fd5b506104766004803603602081101561094a57600080fd5b5035612291565b34801561095d57600080fd5b5061040f6004803603608081101561097457600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135612301565b3480156109a657600080fd5b506105f4600480360360208110156109bd57600080fd5b5035612346565b3480156109d057600080fd5b50610476600480360360208110156109e757600080fd5b50356001600160a01b031661236d565b348015610a0357600080fd5b506108c660048036036020811015610a1a57600080fd5b50356001600160a01b03166123f2565b348015610a3657600080fd5b5061047660048036036020811015610a4d57600080fd5b50356001600160a01b0316612427565b348015610a6957600080fd5b50610476600480360360a0811015610a8057600080fd5b506001600160a01b03813581169160208101358216916040820135811691606081013590911690608001356124ab565b348015610abc57600080fd5b5061040f60048036036040811015610ad357600080fd5b810190602081018135600160201b811115610aed57600080fd5b820183602082011115610aff57600080fd5b803590602001918460208302840111600160201b83111715610b2057600080fd5b919390929091602081019035600160201b811115610b3d57600080fd5b820183602082011115610b4f57600080fd5b803590602001918460208302840111600160201b83111715610b7057600080fd5b5090925090506126d1565b348015610b8757600080fd5b5061042660048036036020811015610b9e57600080fd5b50356001600160a01b0316612851565b348015610bba57600080fd5b5061042660048036036020811015610bd157600080fd5b50356001600160a01b0316612866565b348015610bed57600080fd5b5061040f60048036036060811015610c0457600080fd5b60ff823516916001600160a01b0360208201351691810190606081016040820135600160201b811115610c3657600080fd5b820183602082011115610c4857600080fd5b803590602001918460208302840111600160201b83111715610c6957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061287b945050505050565b348015610cb357600080fd5b5061047660048036036060811015610cca57600080fd5b5060ff813516906001600160a01b03602082013581169160400135166128d9565b348015610cf757600080fd5b506104766128fc565b348015610d0c57600080fd5b506105f4612900565b348015610d2157600080fd5b5061042661290f565b61040f600480360360a0811015610d4057600080fd5b60ff8235169190810190604081016020820135600160201b811115610d6457600080fd5b820183602082011115610d7657600080fd5b803590602001918460208302840111600160201b83111715610d9757600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b811115610de657600080fd5b820183602082011115610df857600080fd5b803590602001918460208302840111600160201b83111715610e1957600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955050505080351515915060200135151561291f565b348015610e6c57600080fd5b5061047660048036036060811015610e8357600080fd5b5060ff813516906001600160a01b0360208201358116916040013516612ba7565b348015610eb057600080fd5b5061040f60048036036020811015610ec757600080fd5b50356001600160a01b0316612bca565b348015610ee357600080fd5b50610f0a60048036036020811015610efa57600080fd5b50356001600160a01b0316612e13565b60408051921515835260208301919091528051918290030190f35b348015610f3157600080fd5b5061042660048036036020811015610f4857600080fd5b50351515612e32565b348015610f5d57600080fd5b5061042660048036036040811015610f7457600080fd5b506001600160a01b0381358116916020013516612f52565b348015610f9857600080fd5b50610476612f85565b348015610fad57600080fd5b5061047660048036036020811015610fc457600080fd5b50356001600160a01b0316612f8b565b348015610fe057600080fd5b50610fe96114d8565b6040805160ff9092168252519081900360200190f35b34801561100b57600080fd5b506104d96004803603602081101561102257600080fd5b50356001600160a01b03166130eb565b34801561103e57600080fd5b50610426613174565b34801561105357600080fd5b506104d9613184565b34801561106857600080fd5b506105f46131e4565b34801561107d57600080fd5b506104766004803603608081101561109457600080fd5b506001600160a01b038135811691602081013582169160408201351690606001356131f3565b3480156110c657600080fd5b506105f461326a565b3480156110db57600080fd5b506104d9600480360360208110156110f257600080fd5b810190602081018135600160201b81111561110c57600080fd5b82018360208201111561111e57600080fd5b803590602001918460208302840111600160201b8311171561113f57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550613279945050505050565b34801561118957600080fd5b50610476600480360360408110156111a057600080fd5b50803560ff1690602001356001600160a01b0316613310565b3480156111c557600080fd5b506111fc600480360360608110156111dc57600080fd5b506001600160a01b0381358116916020810135909116906040013561332d565b6040805192835260208301919091528051918290030190f35b34801561122157600080fd5b506104766004803603604081101561123857600080fd5b50803560ff1690602001356001600160a01b031661355d565b34801561125d57600080fd5b50610476600480360360a081101561127457600080fd5b506001600160a01b038135811691602081013582169160408201358116916060810135909116906080013561357a565b3480156112b057600080fd5b50610855600480360360408110156112c757600080fd5b50803560ff1690602001356001600160a01b0316613750565b3480156112ec57600080fd5b506104766004803603606081101561130357600080fd5b506001600160a01b03813581169160208101359091169060400135613785565b34801561132f57600080fd5b506105f46004803603604081101561134657600080fd5b506001600160a01b038135169060200135613b19565b34801561136857600080fd5b506105f4613b4e565b34801561137d57600080fd5b5061040f6004803603602081101561139457600080fd5b50356001600160a01b0316613b5d565b3480156113b057600080fd5b50610476600480360360408110156113c757600080fd5b506001600160a01b038135169060200135613b96565b3480156113e957600080fd5b50610426613d46565b3480156113fe57600080fd5b50610476613d56565b34801561141357600080fd5b506104766004803603606081101561142a57600080fd5b506001600160a01b03813581169160208101359091169060400135613d5c565b34801561145657600080fd5b5061145f613d8e565b604080516001600160e01b039092168252519081900360200190f35b34801561148757600080fd5b506104766004803603602081101561149e57600080fd5b50356001600160a01b0316613da0565b3480156114ba57600080fd5b506105f46140ae565b3480156114cf57600080fd5b506105f46140bd565b600181565b601660209081526000928352604080842090915290825290205481565b61155f8282600d80548060200260200160405190810160405280929190818152602001828054801561155557602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611537575b505050505061287b565b5050565b6060601a8054806020026020016040519081016040528092919081815260200182805480156115bb57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161159d575b505050505090505b90565b6001600160a01b03821660009081526009602052604081205460ff16611618576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b600a546001600160a01b031633148061163b57506000546001600160a01b031633145b611671576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b031633148061168c57506001821515145b6116c2576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6001600160a01b0383166000818152600c6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260069083015265426f72726f7760d01b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150805b92915050565b806001600160a01b031663f851a4406040518163ffffffff1660e01b815260040160206040518083038186803b15801561178157600080fd5b505afa158015611795573d6000803e3d6000fd5b505050506040513d60208110156117ab57600080fd5b50516001600160a01b031633146117ee576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b806001600160a01b031663c1e803346040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561182957600080fd5b505af115801561183d573d6000803e3d6000fd5b505050506040513d602081101561185357600080fd5b50511561188c576040805162461bcd60e51b815260206004820152600260248201526120a360f11b604482015290519081900360640190fd5b50565b601a5460ff8516106118cd576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b6118d56140cc565b61190b576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b611917848484846140f5565b50505050565b600e546001600160a01b031681565b6001600160a01b03841660009081526009602052604081205460ff16611954575060096119e1565b61195c615ec2565b6040518060200160405280876001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156119a057600080fd5b505afa1580156119b4573d6000803e3d6000fd5b505050506040513d60208110156119ca57600080fd5b5051905290506119db8685836142f8565b60009150505b949350505050565b600a546001600160a01b031681565b6001546001600160a01b031681565b600a546000906001600160a01b0316331480611a2d57506000546001600160a01b031633145b611a63576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480611a7e57506001821515145b611ab4576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600a8054831515600160b81b810260ff60b81b1990921691909117909155604080516020810192909252808252600582820152645365697a6560d81b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a150805b919050565b600080546001600160a01b03163314611b6d576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6005805490839055604080518281526020810185905281517f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd9929181900390910190a160005b9392505050565b6000546001600160a01b03163314611bfe576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600e80546001600160a01b038381166001600160a01b0319831681179093556040805191909216808252602082019390935281517feda98690e518e9a05f8ec6837663e188211b2da8f4906648b323f2c1d4434e29929181900390910190a15050565b6001600160a01b03821660009081526009602052604081205460ff16611cb3576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b600a546001600160a01b0316331480611cd657506000546001600160a01b031633145b611d0c576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480611d2757506001821515145b611d5d576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b6001600160a01b0383166000818152600b6020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260049083015263135a5b9d60e21b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150919050565b600a54600160a01b900460ff1681565b6000546001600160a01b03163314611e32576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601954604080516001600160a01b039283168152918316602083015280517fc2689fb64a73fb7e8c5d93c42a54cf839d2c0b41f51bd192f2a4e16dbb29b63c9281900390910190a1601980546001600160a01b0319166001600160a01b0392909216919091179055565b611ea46140cc565b611eda576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601a5460ff831610611f18576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60008111611f52576040805162461bcd60e51b8152602060048201526002602482015261494160f01b604482015290519081900360640190fd5b60ff82166001141561202e5747811115611f98576040805162461bcd60e51b815260206004820152600260248201526124a360f11b604482015290519081900360640190fd5b6040516000906001600160a01b03851690610fbd90849084818181858888f193505050503d8060008114611fe8576040519150601f19603f3d011682016040523d82523d6000602084013e611fed565b606091505b5050905080612028576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b50612129565b601a8260ff168154811061203e57fe5b60009182526020918290200154604080516370a0823160e01b815230600482015290516001600160a01b03909216926370a0823192602480840193829003018186803b15801561208d57600080fd5b505afa1580156120a1573d6000803e3d6000fd5b505050506040513d60208110156120b757600080fd5b50518111156120f2576040805162461bcd60e51b815260206004820152600260248201526124a360f11b604482015290519081900360640190fd5b6121298382601a8560ff168154811061210757fe5b6000918252602090912001546001600160a01b0316919063ffffffff61432716565b604080516001600160a01b038516815260ff8416602082015280820183905290517fce7d734fdce67e276e886b8335e89f7c635c6680207366139dd02a51c96b08489181900360600190a1505050565b600f6020526000908152604090205481565b60065481565b60136020908152600092835260408084209091529082529020546001600160e01b03811690600160e01b900463ffffffff1682565b6000806000806000806121db8a8a8a8a61437e565b9250925092508260118111156121ed57fe5b95509093509150505b9450945094915050565b6001600160a01b0383166000908152600b602052604081205460ff1615612253576040805162461bcd60e51b815260206004820152600260248201526104d560f41b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff1661227d5760095b9050611bb3565b61228784846146b6565b6000949350505050565b600080546001600160a01b031633146122b7576122b06001600b6146e3565b9050611b23565b6006805490839055604080518281526020810185905281517faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec1316929181900390910190a16000611bb3565b8015801561230f5750600082115b15611917576040805162461bcd60e51b8152602060048201526002602482015261292b60f11b604482015290519081900360640190fd5b600d818154811061235357fe5b6000918252602090912001546001600160a01b0316905081565b600080546001600160a01b0316331461238c576122b0600160106146e3565b600480546001600160a01b038481166001600160a01b0319831681179093556040805191909216808252602082019390935281517fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22929181900390910190a16000611bb3565b60008060008060008061240987600080600061437e565b92509250925082601181111561241b57fe5b97919650945092505050565b600080546001600160a01b03163314612446576122b0600160136146e3565b600a80546001600160a01b038481166001600160a01b0319831617928390556040805192821680845293909116602083015280517f0613b6ee6a04f0d09f390e4d9318894b9f6ac7fd83897cd8d18896ba579c401e9281900390910190a16000611bb3565b6019546040805163d63a8e1160e01b81526001600160a01b0386811660048301529151600093929092169163d63a8e119160248082019260209290919082900301818787803b1580156124fd57600080fd5b505af1158015612511573d6000803e3d6000fd5b505050506040513d602081101561252757600080fd5b50516125375760015b90506126c8565b6001600160a01b03861660009081526009602052604090205460ff16158061257857506001600160a01b03851660009081526009602052604090205460ff16155b15612584576009612530565b6001600160a01b038086166000908152600960209081526040808320938716835260029093019052205460ff166125bc576008612530565b6000806125c885614749565b919350909150600090508260118111156125de57fe5b146125f8578160118111156125ef57fe5b925050506126c8565b806126045760036125ef565b6000886001600160a01b03166395dd9193876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561265c57600080fd5b505afa158015612670573d6000803e3d6000fd5b505050506040513d602081101561268657600080fd5b5051604080516020810190915260055481529091506000906126a89083614769565b9050808611156126bf5760119450505050506126c8565b60009450505050505b95945050505050565b6000546001600160a01b03163314806126f45750600e546001600160a01b031633145b61272a576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b8281811580159061273a57508082145b612770576040805162461bcd60e51b8152602060048201526002602482015261494960f01b604482015290519081900360640190fd5b60005b828110156128485784848281811061278757fe5b90506020020135600f600089898581811061279e57fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b03168152602001908152602001600020819055508686828181106127de57fe5b905060200201356001600160a01b03166001600160a01b03167f6f1951b2aad10f3fc81b86d91105b413a5b3f847a34bbc5ce1904201b14438f686868481811061282457fe5b905060200201356040518082815260200191505060405180910390a2600101612773565b50505050505050565b600c6020526000908152604090205460ff1681565b600b6020526000908152604090205460ff1681565b6040805160018082528183019092526060916020808301908038833901905050905082816000815181106128ab57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505061191784828460018061291f565b601560209081526000938452604080852082529284528284209052825290205481565b4290565b6004546001600160a01b031681565b600a54600160b01b900460ff1681565b601a5460ff86161061295d576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60005b8351811015612b9f57600084828151811061297757fe5b6020908102919091018101516001600160a01b0381166000908152600990925260409091205490915060ff166129d9576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b60018415151415612b0e576129ec615ec2565b6040518060200160405280836001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612a3057600080fd5b505afa158015612a44573d6000803e3d6000fd5b505050506040513d6020811015612a5a57600080fd5b505190529050612a6b888383614788565b60005b8751811015612b0b57612a9689848a8481518110612a8857fe5b602002602001015185614a7b565b612b0389898381518110612aa657fe5b6020026020010151601660008d60ff1660ff16815260200190815260200160002060008c8681518110612ad557fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054614ce6565b600101612a6e565b50505b60018315151415612b9657612b238782614f1c565b60005b8651811015612b9457612b4d8883898481518110612b4057fe5b60200260200101516151cf565b612b8c88888381518110612b5d57fe5b6020026020010151601660008c60ff1660ff16815260200190815260200160002060008b8681518110612ad557fe5b600101612b26565b505b50600101612960565b505050505050565b601460209081526000938452604080852082529284528284209052825290205481565b6000546001600160a01b03163314612c0e576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b601a54612c77576017546001600160a01b031615801590612c3c57506017546001600160a01b038281169116145b612c72576040805162461bcd60e51b8152602060048201526002602482015261141560f21b604482015290519081900360640190fd5b612cc3565b601a5460011415612cc3576001600160a01b03811615612cc3576040805162461bcd60e51b81526020600482015260026024820152614e4f60f01b604482015290519081900360640190fd5b6000805b601a54811015612d1457826001600160a01b0316601a8281548110612ce857fe5b6000918252602090912001546001600160a01b03161415612d0c5760019150612d14565b600101612cc7565b508015612d4d576040805162461bcd60e51b8152602060048201526002602482015261415360f01b604482015290519081900360640190fd5b601a5460405160ff8216906001600160a01b038516907f44ce9959cf08b43b70e35e8f294c500e0ee993d805c21cef930f5c5c5967e9db90600090a3601a80546001810182556000919091527f057c384a7d1c54f3a1b2e5e67b2617b8224fdfd1ea7234eea573a6ff665ff63e0180546001600160a01b0319166001600160a01b0385161790556060612dde613184565b805190915060005b81811015612b9f57612e0b84848381518110612dfe57fe5b6020026020010151615431565b600101612de6565b6009602052600090815260409020805460019091015460ff9091169082565b600a546000906001600160a01b0316331480612e5857506000546001600160a01b031633145b612e8e576040805162461bcd60e51b8152602060048201526002602482015261504760f01b604482015290519081900360640190fd5b6000546001600160a01b0316331480612ea957506001821515145b612edf576040805162461bcd60e51b8152602060048201526002602482015261414f60f01b604482015290519081900360640190fd5b600a8054831515600160b01b810260ff60b01b1990921691909117909155604080516020810192909252808252600882820152672a3930b739b332b960c11b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a15090565b6001600160a01b038082166000908152600960209081526040808320938616835260029093019052205460ff1692915050565b60075481565b600080546001600160a01b03163314612faa576122b0600160126146e3565b6001600160a01b03821660009081526009602052604090205460ff1615612fd7576122b0600a60116146e3565b816001600160a01b031663fe9c44ae6040518163ffffffff1660e01b815260040160206040518083038186803b15801561301057600080fd5b505afa158015613024573d6000803e3d6000fd5b505050506040513d602081101561303a57600080fd5b50506040805180820182526001808252600060208084018281526001600160a01b038816835260099091529390209151825460ff1916901515178255915191015561308482615527565b60005b601a5460ff821610156130a65761309e8184615431565b600101613087565b50604080516001600160a01b038416815290517fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f9181900360200190a1600092915050565b60608060086000846001600160a01b03166001600160a01b0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561316757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613149575b5093979650505050505050565b600a54600160b81b900460ff1681565b6060600d8054806020026020016040519081016040528092919081815260200182805480156115bb576020028201919060005260206000209081546001600160a01b0316815260019091019060200180831161159d575050505050905090565b6002546001600160a01b031681565b600a54600090600160b01b900460ff161561323a576040805162461bcd60e51b8152602060048201526002602482015261054560f41b604482015290519081900360640190fd5b60006132478686856155f4565b905080156132565790506119e1565b61326086866146b6565b6119db86856146b6565b6019546001600160a01b031681565b60606000825190506060816040519080825280602002602001820160405280156132ad578160200160208202803883390190505b50905060005b828110156133085760008582815181106132c957fe5b602002602001015190506132dd81336156a0565b60118111156132e857fe5b8383815181106132f457fe5b6020908102919091010152506001016132b3565b509392505050565b601860209081526000928352604080842090915290825290205481565b600480546040805163fc57d4df60e01b81526001600160a01b038781169482019490945290516000938493849391169163fc57d4df91602480820192602092909190829003018186803b15801561338357600080fd5b505afa158015613397573d6000803e3d6000fd5b505050506040513d60208110156133ad57600080fd5b5051600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051939450600093929091169163fc57d4df91602480820192602092909190829003018186803b15801561340657600080fd5b505afa15801561341a573d6000803e3d6000fd5b505050506040513d602081101561343057600080fd5b5051905081158061343f575080155b1561345457600d935060009250613555915050565b6000866001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b15801561348f57600080fd5b505afa1580156134a3573d6000803e3d6000fd5b505050506040513d60208110156134b957600080fd5b5051905060006134c7615ec2565b6134cf615ec2565b6134d7615ec2565b613508613502604051806020016040528060065481525060405180602001604052808b815250615796565b8b6157d5565b9250613530604051806020016040528088815250604051806020016040528088815250615796565b915061353c83836157ff565b905061354781615832565b600099509750505050505050505b935093915050565b601160209081526000928352604080842090915290825290205481565b600a54600090600160b81b900460ff16156135c1576040805162461bcd60e51b8152602060048201526002602482015261053560f41b604482015290519081900360640190fd5b6001600160a01b03861660009081526009602052604090205460ff16158061360257506001600160a01b03851660009081526009602052604090205460ff16155b1561360e576009612530565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561364757600080fd5b505afa15801561365b573d6000803e3d6000fd5b505050506040513d602081101561367157600080fd5b505160408051635fe3b56760e01b815290516001600160a01b0392831692891691635fe3b567916004808301926020929190829003018186803b1580156136b757600080fd5b505afa1580156136cb573d6000803e3d6000fd5b505050506040513d60208110156136e157600080fd5b50516001600160a01b0316146136f8576002612530565b6001600160a01b038087166000908152600960209081526040808320938716835260029093019052205460ff16613730576008612530565b61373a86846146b6565b61374486856146b6565b60009695505050505050565b60126020908152600092835260408084209091529082529020546001600160e01b03811690600160e01b900463ffffffff1682565b6001600160a01b0383166000908152600c602052604081205460ff16156137d8576040805162461bcd60e51b8152602060048201526002602482015261042560f41b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff166137ff576009612276565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff166138dc57336001600160a01b03851614613872576040805162461bcd60e51b815260206004820152600260248201526110d560f21b604482015290519081900360640190fd5b600061387e33856156a0565b9050600081601181111561388e57fe5b146138a75780601181111561389f57fe5b915050611bb3565b6001600160a01b038086166000908152600960209081526040808320938816835260029093019052205460ff166138da57fe5b505b600480546040805163fc57d4df60e01b81526001600160a01b03888116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b15801561392d57600080fd5b505afa158015613941573d6000803e3d6000fd5b505050506040513d602081101561395757600080fd5b505161396457600d612276565b6001600160a01b0384166000908152600f60205260409020548015613a36576000856001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b1580156139be57600080fd5b505afa1580156139d2573d6000803e3d6000fd5b505050506040513d60208110156139e857600080fd5b5051905060006139f88286615841565b9050828110613a33576040805162461bcd60e51b8152602060048201526002602482015261424360f01b604482015290519081900360640190fd5b50505b600080613a46868860008861437e565b91935090915060009050826011811115613a5c57fe5b14613a7757816011811115613a6d57fe5b9350505050611bb3565b8015613a84576004613a6d565b613a8c615ec2565b6040518060200160405280896001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b158015613ad057600080fd5b505afa158015613ae4573d6000803e3d6000fd5b505050506040513d6020811015613afa57600080fd5b505190529050613b0b8888836142f8565b600098975050505050505050565b60086020528160005260406000208181548110613b3257fe5b6000918252602090912001546001600160a01b03169150829050565b6003546001600160a01b031681565b6000546001600160a01b03163314613b7457600080fd5b601780546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160a01b03163314613bbc57613bb5600160066146e3565b9050611742565b6001600160a01b0383166000908152600960205260409020805460ff16613bf157613be9600960076146e3565b915050611742565b613bf9615ec2565b506040805160208101909152838152613c10615ec2565b506040805160208101909152670c7d713b49da00008152613c318183615877565b15613c4c57613c42600660086146e3565b9350505050611742565b8415801590613cd55750600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b158015613ca757600080fd5b505afa158015613cbb573d6000803e3d6000fd5b505050506040513d6020811015613cd157600080fd5b5051155b15613ce657613c42600d60096146e3565b60018301805490869055604080516001600160a01b03891681526020810183905280820188905290517f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59181900360600190a16000979650505050505050565b600a54600160a81b900460ff1681565b60055481565b600080613d6a8585856155f4565b90508015613d79579050611bb3565b613d8385856146b6565b600095945050505050565b6a0c097ce7bc90715b34b9f160241b81565b6000808290506000806000836001600160a01b031663c37f68e2336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b158015613e0157600080fd5b505afa158015613e15573d6000803e3d6000fd5b505050506040513d6080811015613e2b57600080fd5b508051602082015160409092015190945090925090508215613e79576040805162461bcd60e51b815260206004820152600260248201526121a360f11b604482015290519081900360640190fd5b8015613e9657613e8b600c60026146e3565b945050505050611b23565b6000613ea38733856155f4565b90508015613ec457613eb8600e60038361587e565b95505050505050611b23565b6001600160a01b0385166000908152600960209081526040808320338452600281019092529091205460ff16613f035760009650505050505050611b23565b3360009081526002820160209081526040808320805460ff191690556008825291829020805483518184028101840190945280845260609392830182828015613f7557602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613f57575b5050835193945083925060009150505b82811015613fca57896001600160a01b0316848281518110613fa357fe5b60200260200101516001600160a01b03161415613fc257809150613fca565b600101613f85565b50818110613fd457fe5b336000908152600860205260409020805481906000198101908110613ff557fe5b9060005260206000200160009054906101000a90046001600160a01b031681838154811061401f57fe5b600091825260209091200180546001600160a01b0319166001600160a01b03929092169190911790558054614058826000198301615ed5565b50604080516001600160a01b038c16815233602082015281517fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d929181900390910190a160009c9b505050505050505050505050565b6017546001600160a01b031681565b6000546001600160a01b031681565b600080546001600160a01b03163314806140f057506002546001600160a01b031633145b905090565b6001600160a01b03831660009081526009602052604090205460ff16614147576040805162461bcd60e51b8152602060048201526002602482015261135360f21b604482015290519081900360640190fd5b60ff841660008181526011602090815260408083206001600160a01b03881680855290835281842054948452601883528184209084529091529020548382146141fb576141948686614f1c565b60ff861660008181526011602090815260408083206001600160a01b038a16808552908352928190208890558051938452908301879052805191927f2577edc53863f2e6d759b5da2c36549292f23909793d20feb1886bc21b17782f929081900390910190a25b828114612b9f5761420a615ec2565b6040518060200160405280876001600160a01b031663aa5af0fd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561424e57600080fd5b505afa158015614262573d6000803e3d6000fd5b505050506040513d602081101561427857600080fd5b505190529050614289878783614788565b60ff871660008181526018602090815260408083206001600160a01b038b16808552908352928190208890558051938452908301879052805191927fee48fe28e41d25c72d48e0c4580dbeac6fb4ef83cd3401ced307912114e2e5eb929081900390910190a250505050505050565b60005b601a5460ff8216101561191757614313818584614788565b61431f81858585614a7b565b6001016142fb565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526143799084906158e4565b505050565b600080600061438b615ef9565b6001600160a01b038816600090815260086020908152604080832080548251818502810185019093528083526060938301828280156143f357602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116143d5575b50939450600093505050505b815181101561467757600082828151811061441657fe5b60200260200101519050806001600160a01b031663c37f68e28d6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b15801561447657600080fd5b505afa15801561448a573d6000803e3d6000fd5b505050506040513d60808110156144a057600080fd5b508051602082015160408084015160609485015160808b01529389019390935291870191909152935083156144e55750600f9650600095508594506121f69350505050565b60408051602080820183526001600160a01b0380851660008181526009845285902060010154845260c08a01939093528351808301855260808a0151815260e08a015260048054855163fc57d4df60e01b815291820194909452935192169263fc57d4df9260248083019392829003018186803b15801561456557600080fd5b505afa158015614579573d6000803e3d6000fd5b505050506040513d602081101561458f57600080fd5b505160a086018190526145b25750600d9650600095508594506121f69350505050565b604080516020810190915260a0860151815261010086015260c085015160e08601516145ec916145e191615796565b866101000151615796565b610120860181905260408601518651614606929190615a69565b855261010085015160608601516020870151614623929190615a69565b60208601526001600160a01b03818116908c16141561466e576146508561012001518b8760200151615a69565b60208601819052610100860151614668918b90615a69565b60208601525b506001016143ff565b5060208301518351111561469d57505060208101519051600094500391508290506121f6565b50508051602090910151600094508493500390506121f6565b60005b601a5460ff82161015614379576146d08184614f1c565b6146db8184846151cf565b6001016146b9565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa083601181111561471257fe5b83601381111561471e57fe5b604080519283526020830191909152600082820152519081900360600190a1826011811115611bb357fe5b600080600061475c84600080600061437e565b9250925092509193909250565b6000614773615ec2565b61477d84846157d5565b90506119e181615832565b601a5460ff8416106147c6576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff831660008181526013602090815260408083206001600160a01b038716808552908352818420948452601883528184209084529091528120549061480a6128fc565b835490915060009061482a908390600160e01b900463ffffffff16615a91565b905060008111801561483c5750600083115b15614a295760006148b1876001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561487f57600080fd5b505afa158015614893573d6000803e3d6000fd5b505050506040513d60208110156148a957600080fd5b505187615acb565b905060006148bf8386615ae9565b90506148c9615ec2565b600083116148e657604051806020016040528060008152506148f0565b6148f08284615b2b565b90506148fa615ec2565b604080516020810190915288546001600160e01b0316815261491c9083615b5f565b905060405180604001604052806149528360000151604051806040016040528060038152602001620c8c8d60ea1b815250615b84565b6001600160e01b031681526020016149848860405180604001604052806002815260200161199960f11b815250615c1e565b63ffffffff16815250601360008d60ff1660ff16815260200190815260200160002060008c6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a8154816001600160e01b0302191690836001600160e01b03160217905550602082015181600001601c6101000a81548163ffffffff021916908363ffffffff16021790555090505050505050612848565b801561284857614a538260405180604001604052806002815260200161199960f11b815250615c1e565b845463ffffffff91909116600160e01b026001600160e01b0390911617845550505050505050565b601a5460ff851610614ab9576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff841660009081526013602090815260408083206001600160a01b03871684529091529020614ae7615ec2565b50604080516020810190915281546001600160e01b03168152614b08615ec2565b50604080516020808201835260ff89166000908152601582528381206001600160a01b03808b16835290835284822090891680835281845294822080548552865195909252909152919091558051158015614b72575081516a0c097ce7bc90715b34b9f160241b11155b15614b89576a0c097ce7bc90715b34b9f160241b81525b614b91615ec2565b614b9b8383615c73565b90506000614bf8886001600160a01b03166395dd9193896040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561487f57600080fd5b90506000614c068284615c98565b60ff8b1660009081526016602090815260408083206001600160a01b038d16845290915281205491925090614c3b9083615841565b905080601660008d60ff1660ff16815260200190815260200160002060008b6001600160a01b03166001600160a01b0316815260200190815260200160002081905550886001600160a01b03168a6001600160a01b03168c60ff167fa1b6a046664a0ecf068059f26de56878f8d0e799907ca2e42d9148ccbdc717a7858a60000151604051808381526020018281526020019250505060405180910390a45050505050505050505050565b60ff831660011415614e0957478115801590614d025750808211155b15614e035760ff841660009081526016602090815260408083206001600160a01b038716808552925280832083905551610fbd90859084818181858888f193505050503d8060008114614d71576040519150601f19603f3d011682016040523d82523d6000602084013e614d76565b606091505b5050905080614db1576040805162461bcd60e51b81526020600482015260026024820152612a2360f11b604482015290519081900360640190fd5b604080516001600160a01b038616815260ff8716602082015280820185905290517fce7d734fdce67e276e886b8335e89f7c635c6680207366139dd02a51c96b08489181900360600190a15050614379565b50614ef0565b6000601a8460ff1681548110614e1b57fe5b6000918252602080832090910154604080516370a0823160e01b815230600482015290516001600160a01b03909216945084926370a0823192602480840193829003018186803b158015614e6e57600080fd5b505afa158015614e82573d6000803e3d6000fd5b505050506040513d6020811015614e9857600080fd5b505190508215801590614eab5750808311155b15614eed5760ff851660009081526016602090815260408083206001600160a01b0380891685529252822091909155614db1908316858563ffffffff61432716565b50505b60ff9290921660009081526016602090815260408083206001600160a01b039490941683529290522055565b601a5460ff831610614f5a576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff821660008181526012602090815260408083206001600160a01b0386168085529083528184209484526011835281842090845290915281205490614f9e6128fc565b8354909150600090614fbe908390600160e01b900463ffffffff16615a91565b9050600081118015614fd05750600083115b1561517e576000856001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561501057600080fd5b505afa158015615024573d6000803e3d6000fd5b505050506040513d602081101561503a57600080fd5b50519050600061504a8386615ae9565b9050615054615ec2565b60008311615071576040518060200160405280600081525061507b565b61507b8284615b2b565b9050615085615ec2565b604080516020810190915288546001600160e01b031681526150a79083615b5f565b905060405180604001604052806150dd8360000151604051806040016040528060038152602001620c8c8d60ea1b815250615b84565b6001600160e01b0316815260200161510f8860405180604001604052806002815260200161199960f11b815250615c1e565b63ffffffff90811690915260ff8c1660009081526012602090815260408083206001600160a01b038f1684528252909120835181549490920151909216600160e01b026001600160e01b039182166001600160e01b0319909416939093171691909117905550612b9f92505050565b8015612b9f576151a88260405180604001604052806002815260200161199960f11b815250615c1e565b845463ffffffff91909116600160e01b026001600160e01b03909116178455505050505050565b601a5460ff84161061520d576040805162461bcd60e51b815260206004820152600260248201526124a960f11b604482015290519081900360640190fd5b60ff831660009081526012602090815260408083206001600160a01b0386168452909152902061523b615ec2565b50604080516020810190915281546001600160e01b0316815261525c615ec2565b50604080516020808201835260ff88166000908152601482528381206001600160a01b03808a168352908352848220908816808352818452948220805485528651959092529091529190915580511580156152c6575081516a0c097ce7bc90715b34b9f160241b11155b156152dd576a0c097ce7bc90715b34b9f160241b81525b6152e5615ec2565b6152ef8383615c73565b90506000866001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561534957600080fd5b505afa15801561535d573d6000803e3d6000fd5b505050506040513d602081101561537357600080fd5b5051905060006153838284615c98565b60ff8a1660009081526016602090815260408083206001600160a01b038c168452909152812054919250906153b89083615841565b60ff8b1660008181526016602090815260408083206001600160a01b03808f16808652918452938290208690558b51825189815293840152815195965094928e1693927faccd035d02c456be35306aecd5a5fe62320713dde09ccd68b0a5e8ed930399999281900390910190a450505050505050505050565b600061545e61543e6128fc565b60405180604001604052806002815260200161199960f11b815250615c1e565b60ff841660008181526012602090815260408083206001600160a01b038816808552908352818420948452601383528184209084529091529020815492935090916001600160e01b03166154cb5781546001600160e01b0319166a0c097ce7bc90715b34b9f160241b1782555b80546001600160e01b03166154f95780546001600160e01b0319166a0c097ce7bc90715b34b9f160241b1781555b805463ffffffff909316600160e01b026001600160e01b039384168117909155815490921690911790555050565b60005b600d548110156155a157816001600160a01b0316600d828154811061554b57fe5b6000918252602090912001546001600160a01b03161415615599576040805162461bcd60e51b81526020600482015260036024820152624d414160e81b604482015290519081900360640190fd5b60010161552a565b50600d80546001810182556000919091527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb50180546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03831660009081526009602052604081205460ff1661561b576009612276565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff16615653576000612276565b600080615663858786600061437e565b9193509091506000905082601181111561567957fe5b146156935781601181111561568a57fe5b92505050611bb3565b801561374457600461568a565b6001600160a01b0382166000908152600960205260408120805460ff166156cb576009915050611742565b6001600160a01b038316600090815260028201602052604090205460ff161515600114156156fd576000915050611742565b6001600160a01b0380841660008181526002840160209081526040808320805460ff19166001908117909155600883528184208054918201815584529282902090920180549489166001600160a01b031990951685179055815193845283019190915280517f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a59281900390910190a15060009392505050565b61579e615ec2565b6040518060200160405280670de0b6b3a76400006157c486600001518660000151615ae9565b816157cb57fe5b0490529392505050565b6157dd615ec2565b60405180602001604052806157f6856000015185615ae9565b90529392505050565b615807615ec2565b60405180602001604052806157f661582b8660000151670de0b6b3a7640000615ae9565b8551615cc6565b51670de0b6b3a7640000900490565b6000611bb38383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250615cf9565b5190511090565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08460118111156158ad57fe5b8460138111156158b957fe5b604080519283526020830191909152818101859052519081900360600190a18360118111156119e157fe5b6158f6826001600160a01b0316615d57565b61592d576040805162461bcd60e51b8152602060048201526003602482015262434e4360e81b604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b6020831061596b5780518252601f19909201916020918201910161594c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146159cd576040519150601f19603f3d011682016040523d82523d6000602084013e6159d2565b606091505b509150915081615a12576040805162461bcd60e51b81526020600480830191909152602482015263262621a360e11b604482015290519081900360640190fd5b80511561191757808060200190516020811015615a2e57600080fd5b5051611917576040805162461bcd60e51b8152602060048201526005602482015264454f444e5360d81b604482015290519081900360640190fd5b6000615a73615ec2565b615a7d85856157d5565b90506126c8615a8b82615832565b84615841565b6000611bb38383604051806040016040528060158152602001747375627472616374696f6e20756e646572666c6f7760581b815250615d90565b6000611bb3615ae284670de0b6b3a7640000615ae9565b8351615cc6565b6000611bb383836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250615dea565b615b33615ec2565b60405180602001604052806157f6615b59866a0c097ce7bc90715b34b9f160241b615ae9565b85615cc6565b615b67615ec2565b60405180602001604052806157f685600001518560000151615841565b600081600160e01b8410615c165760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015615bdb578181015183820152602001615bc3565b50505050905090810190601f168015615c085780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b509192915050565b600081600160201b8410615c165760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b615c7b615ec2565b60405180602001604052806157f685600001518560000151615a91565b60006a0c097ce7bc90715b34b9f160241b615cb7848460000151615ae9565b81615cbe57fe5b049392505050565b6000611bb383836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250615e60565b60008383018285821015615d4e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b50949350505050565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4708181148015906119e1575050151592915050565b60008184841115615de25760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b505050900390565b6000831580615df7575082155b15615e0457506000611bb3565b83830283858281615e1157fe5b04148390615d4e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b60008183615eaf5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315615bdb578181015183820152602001615bc3565b50828481615eb957fe5b04949350505050565b6040518060200160405280600081525090565b81548183558181111561437957600083815260209020614379918101908301615f63565b604051806101400160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001615f37615ec2565b8152602001615f44615ec2565b8152602001615f51615ec2565b8152602001615f5e615ec2565b905290565b6115c391905b80821115615f7d5760008155600101615f69565b509056fea265627a7a723158206795c7e0baf5327fc2f79712b6c89044d8b9b01060540156919d2b5b07b70c6b64736f6c63430005110032