More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Loading...
Loading
Contract Name:
Comptroller
Compiler Version
v0.8.10+commit.fc410830
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import { ICErc20 } from "./CTokenInterfaces.sol"; import { ComptrollerErrorReporter } from "./ErrorReporter.sol"; import { Exponential } from "./Exponential.sol"; import { BasePriceOracle } from "../oracles/BasePriceOracle.sol"; import { Unitroller } from "./Unitroller.sol"; import { IFeeDistributor } from "./IFeeDistributor.sol"; import { IIonicFlywheel } from "../ionic/strategies/flywheel/IIonicFlywheel.sol"; import { DiamondExtension, DiamondBase, LibDiamond } from "../ionic/DiamondExtension.sol"; import { ComptrollerExtensionInterface, ComptrollerBase, ComptrollerInterface } from "./ComptrollerInterface.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; /** * @title Compound's Comptroller Contract * @author Compound * @dev This contract should not to be deployed alone; instead, deploy `Unitroller` (proxy contract) on top of this `Comptroller` (logic/implementation contract). */ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorReporter, Exponential, DiamondExtension { using EnumerableSet for EnumerableSet.AddressSet; /// @notice Emitted when an admin supports a market event MarketListed(ICErc20 cToken); /// @notice Emitted when an account enters a market event MarketEntered(ICErc20 cToken, address account); /// @notice Emitted when an account exits a market event MarketExited(ICErc20 cToken, address account); /// @notice Emitted when close factor is changed by admin event NewCloseFactor(uint256 oldCloseFactorMantissa, uint256 newCloseFactorMantissa); /// @notice Emitted when a collateral factor is changed by admin event NewCollateralFactor(ICErc20 cToken, uint256 oldCollateralFactorMantissa, uint256 newCollateralFactorMantissa); /// @notice Emitted when liquidation incentive is changed by admin event NewLiquidationIncentive(uint256 oldLiquidationIncentiveMantissa, uint256 newLiquidationIncentiveMantissa); /// @notice Emitted when price oracle is changed event NewPriceOracle(BasePriceOracle oldPriceOracle, BasePriceOracle newPriceOracle); /// @notice Emitted when the whitelist enforcement is changed event WhitelistEnforcementChanged(bool enforce); /// @notice Emitted when a new RewardsDistributor contract is added to hooks event AddedRewardsDistributor(address rewardsDistributor); // closeFactorMantissa must be strictly greater than this value uint256 internal constant closeFactorMinMantissa = 0.05e18; // 0.05 // closeFactorMantissa must not exceed this value uint256 internal constant closeFactorMaxMantissa = 0.9e18; // 0.9 // No collateralFactorMantissa may exceed this value uint256 internal constant collateralFactorMaxMantissa = 0.9e18; // 0.9 // liquidationIncentiveMantissa must be no less than this value uint256 internal constant liquidationIncentiveMinMantissa = 1.0e18; // 1.0 // liquidationIncentiveMantissa must be no greater than this value uint256 internal constant liquidationIncentiveMaxMantissa = 1.5e18; // 1.5 modifier isAuthorized() { require(IFeeDistributor(ionicAdmin).canCall(address(this), msg.sender, address(this), msg.sig), "not authorized"); _; } /*** 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 (ICErc20[] memory) { ICErc20[] 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, ICErc20 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 override isAuthorized returns (uint256[] memory) { uint256 len = cTokens.length; uint256[] memory results = new uint256[](len); for (uint256 i = 0; i < len; i++) { ICErc20 cToken = ICErc20(cTokens[i]); results[i] = uint256(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(ICErc20 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); // Add to allBorrowers if (!borrowers[borrower]) { allBorrowers.push(borrower); borrowers[borrower] = true; borrowerIndexes[borrower] = allBorrowers.length - 1; } 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 override isAuthorized returns (uint256) { // TODO require(markets[cTokenAddress].isListed, "!Comptroller:exitMarket"); ICErc20 cToken = ICErc20(cTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the cToken */ (uint256 oErr, uint256 tokensHeld, uint256 amountOwed, ) = cToken.getAccountSnapshot(msg.sender); require(oErr == 0, "!exitMarket"); // 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 */ uint256 allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[cTokenAddress]; /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint256(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 ICErc20[] memory userAssetList = accountAssets[msg.sender]; uint256 len = userAssetList.length; uint256 assetIndex = len; for (uint256 i = 0; i < len; i++) { if (userAssetList[i] == ICErc20(cTokenAddress)) { 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 ICErc20[] storage storedList = accountAssets[msg.sender]; storedList[assetIndex] = storedList[storedList.length - 1]; storedList.pop(); // If the user has exited all markets, remove them from the `allBorrowers` array if (storedList.length == 0) { allBorrowers[borrowerIndexes[msg.sender]] = allBorrowers[allBorrowers.length - 1]; // Copy last item in list to location of item to be removed allBorrowers.pop(); // Reduce length by 1 borrowerIndexes[allBorrowers[borrowerIndexes[msg.sender]]] = borrowerIndexes[msg.sender]; // Set borrower index of moved item to correct index borrowerIndexes[msg.sender] = 0; // Reset sender borrower index to 0 for a gas refund borrowers[msg.sender] = false; // Tell the contract that the sender is no longer a borrower (so it knows to add the borrower back if they enter a market in the future) } emit MarketExited(ICErc20(cTokenAddress), msg.sender); return uint256(Error.NO_ERROR); } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param cTokenAddress 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 cTokenAddress, address minter, uint256 mintAmount ) external override returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!mintGuardianPaused[cTokenAddress], "!mint:paused"); // Make sure market is listed if (!markets[cTokenAddress].isListed) { return uint256(Error.MARKET_NOT_LISTED); } // Make sure minter is whitelisted if (enforceWhitelist && !whitelist[minter]) { return uint256(Error.SUPPLIER_NOT_WHITELISTED); } // Check supply cap uint256 supplyCap = supplyCaps[cTokenAddress]; // Supply cap of 0 corresponds to unlimited supplying if (supplyCap != 0 && !supplyCapWhitelist[cTokenAddress].contains(minter)) { uint256 totalUnderlyingSupply = ICErc20(cTokenAddress).getTotalUnderlyingSupplied(); uint256 whitelistedSuppliersSupply = asComptrollerExtension().getWhitelistedSuppliersSupply(cTokenAddress); uint256 nonWhitelistedTotalSupply; if (whitelistedSuppliersSupply >= totalUnderlyingSupply) nonWhitelistedTotalSupply = 0; else nonWhitelistedTotalSupply = totalUnderlyingSupply - whitelistedSuppliersSupply; require(nonWhitelistedTotalSupply + mintAmount < supplyCap, "!supply cap"); } // Keep the flywheel moving flywheelPreSupplierAction(cTokenAddress, minter); return uint256(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, uint256 redeemTokens ) external override returns (uint256) { uint256 allowed = redeemAllowedInternal(cToken, redeemer, redeemTokens); if (allowed != uint256(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving flywheelPreSupplierAction(cToken, redeemer); return uint256(Error.NO_ERROR); } function redeemAllowedInternal( address cToken, address redeemer, uint256 redeemTokens ) internal view returns (uint256) { if (!markets[cToken].isListed) { return uint256(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 uint256(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , , uint256 shortfall) = getHypotheticalAccountLiquidityInternal( redeemer, ICErc20(cToken), redeemTokens, 0, 0 ); if (err != Error.NO_ERROR) { return uint256(err); } if (shortfall > 0) { return uint256(Error.INSUFFICIENT_LIQUIDITY); } return uint256(Error.NO_ERROR); } /** * @notice Validates mint and reverts on rejection. May emit logs. * @param cToken Asset being minted * @param minter The address minting the tokens * @param actualMintAmount The amount of the underlying asset being minted * @param mintTokens The number of tokens being minted */ function mintVerify( address cToken, address minter, uint256 actualMintAmount, uint256 mintTokens ) external { // Add minter to suppliers mapping suppliers[minter] = true; } /** * @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, uint256 redeemAmount, uint256 redeemTokens ) external override { require(markets[msg.sender].isListed, "!market"); // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("!zero"); } } function getMaxRedeemOrBorrow( address account, ICErc20 cTokenModify, bool isBorrow ) external view override returns (uint256) { address cToken = address(cTokenModify); // Accrue interest uint256 balanceOfUnderlying = cTokenModify.balanceOfUnderlying(account); // Get account liquidity (Error err, , uint256 liquidity, uint256 shortfall) = getHypotheticalAccountLiquidityInternal( account, isBorrow ? cTokenModify : ICErc20(address(0)), 0, 0, 0 ); require(err == Error.NO_ERROR, "!liquidity"); if (shortfall > 0) return 0; // Shortfall, so no more borrow/redeem // Get max borrow/redeem uint256 maxBorrowOrRedeemAmount; if (!isBorrow && !markets[cToken].accountMembership[account]) { // Max redeem = balance of underlying if not used as collateral maxBorrowOrRedeemAmount = balanceOfUnderlying; } else { // Avoid "stack too deep" error by separating this logic maxBorrowOrRedeemAmount = _getMaxRedeemOrBorrow(liquidity, cTokenModify, isBorrow); // Redeem only: max out at underlying balance if (!isBorrow && balanceOfUnderlying < maxBorrowOrRedeemAmount) maxBorrowOrRedeemAmount = balanceOfUnderlying; } // Get max borrow or redeem considering cToken liquidity uint256 cTokenLiquidity = cTokenModify.getCash(); // Return the minimum of the two maximums return maxBorrowOrRedeemAmount <= cTokenLiquidity ? maxBorrowOrRedeemAmount : cTokenLiquidity; } /** * @dev Portion of the logic in `getMaxRedeemOrBorrow` above separated to avoid "stack too deep" errors. */ function _getMaxRedeemOrBorrow( uint256 liquidity, ICErc20 cTokenModify, bool isBorrow ) internal view returns (uint256) { if (liquidity == 0) return 0; // No available account liquidity, so no more borrow/redeem // Get the normalized price of the asset uint256 conversionFactor = oracle.getUnderlyingPrice(cTokenModify); require(conversionFactor > 0, "!oracle"); // Pre-compute a conversion factor from tokens -> ether (normalized price value) if (!isBorrow) { uint256 collateralFactorMantissa = markets[address(cTokenModify)].collateralFactorMantissa; conversionFactor = (collateralFactorMantissa * conversionFactor) / 1e18; } // Get max borrow or redeem considering excess account liquidity return (liquidity * 1e18) / conversionFactor; } /** * @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, uint256 borrowAmount ) external override returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!borrowGuardianPaused[cToken], "!borrow:paused"); // Make sure market is listed if (!markets[cToken].isListed) { return uint256(Error.MARKET_NOT_LISTED); } if (!markets[cToken].accountMembership[borrower]) { // only cTokens may call borrowAllowed if borrower not in market require(msg.sender == cToken, "!ctoken"); // attempt to add borrower to the market Error err = addToMarketInternal(ICErc20(msg.sender), borrower); if (err != Error.NO_ERROR) { return uint256(err); } // it should be impossible to break the important invariant assert(markets[cToken].accountMembership[borrower]); } // Make sure oracle price is available if (oracle.getUnderlyingPrice(ICErc20(cToken)) == 0) { return uint256(Error.PRICE_ERROR); } // Make sure borrower is whitelisted if (enforceWhitelist && !whitelist[borrower]) { return uint256(Error.SUPPLIER_NOT_WHITELISTED); } // Check borrow cap uint256 borrowCap = borrowCaps[cToken]; // Borrow cap of 0 corresponds to unlimited borrowing if (borrowCap != 0 && !borrowCapWhitelist[cToken].contains(borrower)) { uint256 totalBorrows = ICErc20(cToken).totalBorrowsCurrent(); uint256 whitelistedBorrowersBorrows = asComptrollerExtension().getWhitelistedBorrowersBorrows(cToken); uint256 nonWhitelistedTotalBorrows; if (whitelistedBorrowersBorrows >= totalBorrows) nonWhitelistedTotalBorrows = 0; else nonWhitelistedTotalBorrows = totalBorrows - whitelistedBorrowersBorrows; require(nonWhitelistedTotalBorrows + borrowAmount < borrowCap, "!borrow:cap"); } // Keep the flywheel moving flywheelPreBorrowerAction(cToken, borrower); // Perform a hypothetical liquidity check to guard against shortfall (uint256 err, , , uint256 shortfall) = this.getHypotheticalAccountLiquidity(borrower, cToken, 0, borrowAmount, 0); if (err != uint256(Error.NO_ERROR)) { return err; } if (shortfall > 0) { return uint256(Error.INSUFFICIENT_LIQUIDITY); } return uint256(Error.NO_ERROR); } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param cToken Asset whose underlying is being borrowed * @param accountBorrowsNew The user's new borrow balance of the underlying asset */ function borrowWithinLimits(address cToken, uint256 accountBorrowsNew) external view override returns (uint256) { // Check if min borrow exists uint256 minBorrowEth = IFeeDistributor(ionicAdmin).minBorrowEth(); if (minBorrowEth > 0) { // Get new underlying borrow balance of account for this cToken uint256 oraclePriceMantissa = oracle.getUnderlyingPrice(ICErc20(cToken)); if (oraclePriceMantissa == 0) return uint256(Error.PRICE_ERROR); (MathError mathErr, uint256 borrowBalanceEth) = mulScalarTruncate( Exp({ mantissa: oraclePriceMantissa }), accountBorrowsNew ); if (mathErr != MathError.NO_ERROR) return uint256(Error.MATH_ERROR); // Check against min borrow if (borrowBalanceEth < minBorrowEth) return uint256(Error.BORROW_BELOW_MIN); } // Return no error return uint256(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, uint256 repayAmount ) external override returns (uint256) { // Make sure market is listed if (!markets[cToken].isListed) { return uint256(Error.MARKET_NOT_LISTED); } // Keep the flywheel moving flywheelPreBorrowerAction(cToken, borrower); return uint256(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, uint256 repayAmount ) external override returns (uint256) { // Make sure markets are listed if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) { return uint256(Error.MARKET_NOT_LISTED); } // Get borrowers' underlying borrow balance uint256 borrowBalance = ICErc20(cTokenBorrowed).borrowBalanceCurrent(borrower); /* allow accounts to be liquidated if the market is deprecated */ if (isDeprecated(ICErc20(cTokenBorrowed))) { require(borrowBalance >= repayAmount, "!borrow>repay"); } else { /* The borrower must have shortfall in order to be liquidateable */ (Error err, , , uint256 shortfall) = getHypotheticalAccountLiquidityInternal( borrower, ICErc20(address(0)), 0, 0, 0 ); if (err != Error.NO_ERROR) { return uint256(err); } if (shortfall == 0) { return uint256(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint256 maxClose = mul_ScalarTruncate(Exp({ mantissa: closeFactorMantissa }), borrowBalance); if (repayAmount > maxClose) { return uint256(Error.TOO_MUCH_REPAY); } } return uint256(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, uint256 seizeTokens ) external override returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!seizeGuardianPaused, "!seize:paused"); // Make sure markets are listed if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) { return uint256(Error.MARKET_NOT_LISTED); } // Make sure cToken Comptrollers are identical if (ICErc20(cTokenCollateral).comptroller() != ICErc20(cTokenBorrowed).comptroller()) { return uint256(Error.COMPTROLLER_MISMATCH); } // Keep the flywheel moving flywheelPreTransferAction(cTokenCollateral, borrower, liquidator); return uint256(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, uint256 transferTokens ) external override returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!transferGuardianPaused, "!transfer:paused"); // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens uint256 allowed = redeemAllowedInternal(cToken, src, transferTokens); if (allowed != uint256(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving flywheelPreTransferAction(cToken, src, dst); return uint256(Error.NO_ERROR); } /*** Flywheel Hooks ***/ /** * @notice Keeps the flywheel moving pre-mint and pre-redeem * @param cToken The relevant market * @param supplier The minter/redeemer */ function flywheelPreSupplierAction(address cToken, address supplier) internal { for (uint256 i = 0; i < rewardsDistributors.length; i++) IIonicFlywheel(rewardsDistributors[i]).flywheelPreSupplierAction(cToken, supplier); } /** * @notice Keeps the flywheel moving pre-borrow and pre-repay * @param cToken The relevant market * @param borrower The borrower */ function flywheelPreBorrowerAction(address cToken, address borrower) internal { for (uint256 i = 0; i < rewardsDistributors.length; i++) IIonicFlywheel(rewardsDistributors[i]).flywheelPreBorrowerAction(cToken, borrower); } /** * @notice Keeps the flywheel moving pre-transfer and pre-seize * @param cToken The relevant market * @param src The account which sources the tokens * @param dst The account which receives the tokens */ function flywheelPreTransferAction( address cToken, address src, address dst ) internal { for (uint256 i = 0; i < rewardsDistributors.length; i++) IIonicFlywheel(rewardsDistributors[i]).flywheelPreTransferAction(cToken, src, dst); } /*** 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 { ICErc20 asset; uint256 sumCollateral; uint256 sumBorrowPlusEffects; uint256 cTokenBalance; uint256 borrowBalance; uint256 exchangeRateMantissa; uint256 oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToDenom; uint256 borrowCapForCollateral; uint256 borrowedAssetPrice; uint256 assetAsCollateralValueCap; } function getAccountLiquidity(address account) public view override returns ( uint256, uint256, uint256, uint256 ) { ( Error err, uint256 collateralValue, uint256 liquidity, uint256 shortfall ) = getHypotheticalAccountLiquidityInternal(account, ICErc20(address(0)), 0, 0, 0); return (uint256(err), collateralValue, 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 * @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, uint256 redeemTokens, uint256 borrowAmount, uint256 repayAmount ) public view returns ( uint256, uint256, uint256, uint256 ) { ( Error err, uint256 collateralValue, uint256 liquidity, uint256 shortfall ) = getHypotheticalAccountLiquidityInternal( account, ICErc20(cTokenModify), redeemTokens, borrowAmount, repayAmount ); return (uint256(err), collateralValue, 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 * @return (possible error code, hypothetical account collateral value, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, ICErc20 cTokenModify, uint256 redeemTokens, uint256 borrowAmount, uint256 repayAmount ) internal view returns ( Error, uint256, uint256, uint256 ) { AccountLiquidityLocalVars memory vars; // Holds all our calculation results if (address(cTokenModify) != address(0)) { vars.borrowedAssetPrice = oracle.getUnderlyingPrice(cTokenModify); } // For each asset the account is in for (uint256 i = 0; i < accountAssets[account].length; i++) { vars.asset = accountAssets[account][i]; { // Read the balances and exchange rate from the cToken uint256 oErr; (oErr, vars.cTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = vars.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, 0); } } { vars.collateralFactor = Exp({ mantissa: markets[address(vars.asset)].collateralFactorMantissa }); vars.exchangeRate = Exp({ mantissa: vars.exchangeRateMantissa }); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(vars.asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0, 0); } vars.oraclePrice = Exp({ mantissa: vars.oraclePriceMantissa }); // Pre-compute a conversion factor from tokens -> ether (normalized price value) vars.tokensToDenom = mul_(mul_(vars.collateralFactor, vars.exchangeRate), vars.oraclePrice); } { // Exclude the asset-to-be-borrowed from the liquidity, except for when redeeming vars.assetAsCollateralValueCap = asComptrollerExtension().getAssetAsCollateralValueCap( vars.asset, cTokenModify, redeemTokens > 0, account ); // accumulate the collateral value to sumCollateral uint256 assetCollateralValue = mul_ScalarTruncate(vars.tokensToDenom, vars.cTokenBalance); if (assetCollateralValue > vars.assetAsCollateralValueCap) assetCollateralValue = vars.assetAsCollateralValueCap; vars.sumCollateral += assetCollateralValue; } // sumBorrowPlusEffects += oraclePrice * borrowBalance vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt( vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects ); // Calculate effects of interacting with cTokenModify if (vars.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 ); uint256 repayEffect = mul_ScalarTruncate(vars.oraclePrice, repayAmount); if (repayEffect >= vars.sumBorrowPlusEffects) { vars.sumBorrowPlusEffects = 0; } else { vars.sumBorrowPlusEffects -= repayEffect; } } } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, vars.sumCollateral, 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, uint256 actualRepayAmount ) external view override returns (uint256, uint256) { /* Read oracle prices for borrowed and collateral markets */ uint256 priceBorrowedMantissa = oracle.getUnderlyingPrice(ICErc20(cTokenBorrowed)); uint256 priceCollateralMantissa = oracle.getUnderlyingPrice(ICErc20(cTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint256(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) */ ICErc20 collateralCToken = ICErc20(cTokenCollateral); uint256 exchangeRateMantissa = collateralCToken.exchangeRateCurrent(); uint256 seizeTokens; Exp memory numerator; Exp memory denominator; Exp memory ratio; uint256 protocolSeizeShareMantissa = collateralCToken.protocolSeizeShareMantissa(); uint256 feeSeizeShareMantissa = collateralCToken.feeSeizeShareMantissa(); /* * The liquidation penalty includes * - the liquidator incentive * - the protocol fees (Ionic admin fees) * - the market fee */ Exp memory totalPenaltyMantissa = add_( add_(Exp({ mantissa: liquidationIncentiveMantissa }), Exp({ mantissa: protocolSeizeShareMantissa })), Exp({ mantissa: feeSeizeShareMantissa }) ); numerator = mul_(totalPenaltyMantissa, Exp({ mantissa: priceBorrowedMantissa })); denominator = mul_(Exp({ mantissa: priceCollateralMantissa }), Exp({ mantissa: exchangeRateMantissa })); ratio = div_(numerator, denominator); seizeTokens = mul_ScalarTruncate(ratio, actualRepayAmount); return (uint256(Error.NO_ERROR), seizeTokens); } /*** Admin Functions ***/ /** * @notice Add a RewardsDistributor contracts. * @dev Admin function to add a RewardsDistributor contract * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addRewardsDistributor(address distributor) external returns (uint256) { require(hasAdminRights(), "!admin"); // Check marker method require(IIonicFlywheel(distributor).isRewardsDistributor(), "!isRewardsDistributor"); // Check for existing RewardsDistributor for (uint256 i = 0; i < rewardsDistributors.length; i++) require(distributor != rewardsDistributors[i], "!added"); // Add RewardsDistributor to array rewardsDistributors.push(distributor); emit AddedRewardsDistributor(distributor); return uint256(Error.NO_ERROR); } /** * @notice Sets the whitelist enforcement for the comptroller * @dev Admin function to set a new whitelist enforcement boolean * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setWhitelistEnforcement(bool enforce) external returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_WHITELIST_ENFORCEMENT_OWNER_CHECK); } // Check if `enforceWhitelist` already equals `enforce` if (enforceWhitelist == enforce) { return uint256(Error.NO_ERROR); } // Set comptroller's `enforceWhitelist` to `enforce` enforceWhitelist = enforce; // Emit WhitelistEnforcementChanged(bool enforce); emit WhitelistEnforcementChanged(enforce); return uint256(Error.NO_ERROR); } /** * @notice Sets the whitelist `statuses` for `suppliers` * @dev Admin function to set the whitelist `statuses` for `suppliers` * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setWhitelistStatuses(address[] calldata suppliers, bool[] calldata statuses) external returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_WHITELIST_STATUS_OWNER_CHECK); } // Set whitelist statuses for suppliers for (uint256 i = 0; i < suppliers.length; i++) { address supplier = suppliers[i]; if (statuses[i]) { // If not already whitelisted, add to whitelist if (!whitelist[supplier]) { whitelist[supplier] = true; whitelistArray.push(supplier); whitelistIndexes[supplier] = whitelistArray.length - 1; } } else { // If whitelisted, remove from whitelist if (whitelist[supplier]) { whitelistArray[whitelistIndexes[supplier]] = whitelistArray[whitelistArray.length - 1]; // Copy last item in list to location of item to be removed whitelistArray.pop(); // Reduce length by 1 whitelistIndexes[whitelistArray[whitelistIndexes[supplier]]] = whitelistIndexes[supplier]; // Set whitelist index of moved item to correct index whitelistIndexes[supplier] = 0; // Reset supplier whitelist index to 0 for a gas refund whitelist[supplier] = false; // Tell the contract that the supplier is no longer whitelisted } } } return uint256(Error.NO_ERROR); } /** * @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(BasePriceOracle newOracle) public returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the comptroller BasePriceOracle oldOracle = oracle; // Set comptroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint256(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. (See ErrorReporter for details) */ function _setCloseFactor(uint256 newCloseFactorMantissa) external returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_CLOSE_FACTOR_OWNER_CHECK); } // Check limits Exp memory newCloseFactorExp = Exp({ mantissa: newCloseFactorMantissa }); Exp memory lowLimit = Exp({ mantissa: closeFactorMinMantissa }); if (lessThanOrEqualExp(newCloseFactorExp, lowLimit)) { return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION); } Exp memory highLimit = Exp({ mantissa: closeFactorMaxMantissa }); if (lessThanExp(highLimit, newCloseFactorExp)) { return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION); } // Set pool close factor to new close factor, remember old value uint256 oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; // Emit event emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint256(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(ICErc20 cToken, uint256 newCollateralFactorMantissa) public returns (uint256) { // Check caller is admin if (!hasAdminRights()) { 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 uint256 oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(cToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint256(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(uint256 newLiquidationIncentiveMantissa) external returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK); } // Check de-scaled min <= newLiquidationIncentive <= max Exp memory newLiquidationIncentive = Exp({ mantissa: newLiquidationIncentiveMantissa }); Exp memory minLiquidationIncentive = Exp({ mantissa: liquidationIncentiveMinMantissa }); if (lessThanExp(newLiquidationIncentive, minLiquidationIncentive)) { return fail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION); } Exp memory maxLiquidationIncentive = Exp({ mantissa: liquidationIncentiveMaxMantissa }); if (lessThanExp(maxLiquidationIncentive, newLiquidationIncentive)) { return fail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION); } // Save current value for use in log uint256 oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint256(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(ICErc20 cToken) internal returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK); } // Is market already listed? if (markets[address(cToken)].isListed) { return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS); } // Check cToken.comptroller == this require(address(cToken.comptroller()) == address(this), "!comptroller"); // Make sure market is not already listed address underlying = ICErc20(address(cToken)).underlying(); if (address(cTokensByUnderlying[underlying]) != address(0)) { return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS); } // List market and emit event Market storage market = markets[address(cToken)]; market.isListed = true; market.collateralFactorMantissa = 0; allMarkets.push(cToken); cTokensByUnderlying[underlying] = cToken; emit MarketListed(cToken); return uint256(Error.NO_ERROR); } /** * @notice Deploy cToken, add the market to the markets mapping, and set it as listed and set the collateral factor * @dev Admin function to deploy cToken, set isListed, and add support for the market and set the collateral factor * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _deployMarket( uint8 delegateType, bytes calldata constructorData, bytes calldata becomeImplData, uint256 collateralFactorMantissa ) external returns (uint256) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK); } // Temporarily enable Ionic admin rights for asset deployment (storing the original value) bool oldIonicAdminHasRights = ionicAdminHasRights; ionicAdminHasRights = true; // Deploy via Ionic admin ICErc20 cToken = ICErc20(IFeeDistributor(ionicAdmin).deployCErc20(delegateType, constructorData, becomeImplData)); // Reset Ionic admin rights to the original value ionicAdminHasRights = oldIonicAdminHasRights; // Support market here in the Comptroller uint256 err = _supportMarket(cToken); IFeeDistributor(ionicAdmin).authoritiesRegistry().reconfigureAuthority(address(this)); // Set collateral factor return err == uint256(Error.NO_ERROR) ? _setCollateralFactor(cToken, collateralFactorMantissa) : err; } function _becomeImplementation() external { require(msg.sender == address(this), "!self call"); if (!_notEnteredInitialized) { _notEntered = true; _notEnteredInitialized = true; } } /*** Helper Functions ***/ /** * @notice Returns true if the given cToken market has been deprecated * @dev All borrows in a deprecated cToken market can be immediately liquidated * @param cToken The market to check if deprecated */ function isDeprecated(ICErc20 cToken) public view returns (bool) { return markets[address(cToken)].collateralFactorMantissa == 0 && borrowGuardianPaused[address(cToken)] == true && add_(add_(cToken.reserveFactorMantissa(), cToken.adminFeeMantissa()), cToken.ionicFeeMantissa()) == 1e18; } function asComptrollerExtension() internal view returns (ComptrollerExtensionInterface) { return ComptrollerExtensionInterface(address(this)); } function _getExtensionFunctions() external pure virtual override returns (bytes4[] memory functionSelectors) { uint8 fnsCount = 30; functionSelectors = new bytes4[](fnsCount); functionSelectors[--fnsCount] = this.isDeprecated.selector; functionSelectors[--fnsCount] = this._deployMarket.selector; functionSelectors[--fnsCount] = this.getAssetsIn.selector; functionSelectors[--fnsCount] = this.checkMembership.selector; functionSelectors[--fnsCount] = this._setPriceOracle.selector; functionSelectors[--fnsCount] = this._setCloseFactor.selector; functionSelectors[--fnsCount] = this._setCollateralFactor.selector; functionSelectors[--fnsCount] = this._setLiquidationIncentive.selector; functionSelectors[--fnsCount] = this._setWhitelistEnforcement.selector; functionSelectors[--fnsCount] = this._setWhitelistStatuses.selector; functionSelectors[--fnsCount] = this._addRewardsDistributor.selector; functionSelectors[--fnsCount] = this.getHypotheticalAccountLiquidity.selector; functionSelectors[--fnsCount] = this.getMaxRedeemOrBorrow.selector; functionSelectors[--fnsCount] = this.enterMarkets.selector; functionSelectors[--fnsCount] = this.exitMarket.selector; functionSelectors[--fnsCount] = this.mintAllowed.selector; functionSelectors[--fnsCount] = this.redeemAllowed.selector; functionSelectors[--fnsCount] = this.redeemVerify.selector; functionSelectors[--fnsCount] = this.borrowAllowed.selector; functionSelectors[--fnsCount] = this.borrowWithinLimits.selector; functionSelectors[--fnsCount] = this.repayBorrowAllowed.selector; functionSelectors[--fnsCount] = this.liquidateBorrowAllowed.selector; functionSelectors[--fnsCount] = this.seizeAllowed.selector; functionSelectors[--fnsCount] = this.transferAllowed.selector; functionSelectors[--fnsCount] = this.mintVerify.selector; functionSelectors[--fnsCount] = this.getAccountLiquidity.selector; functionSelectors[--fnsCount] = this.liquidateCalculateSeizeTokens.selector; functionSelectors[--fnsCount] = this._beforeNonReentrant.selector; functionSelectors[--fnsCount] = this._afterNonReentrant.selector; functionSelectors[--fnsCount] = this._becomeImplementation.selector; require(fnsCount == 0, "use the correct array length"); } /*** Pool-Wide/Cross-Asset Reentrancy Prevention ***/ /** * @dev Called by cTokens before a non-reentrant function for pool-wide reentrancy prevention. * Prevents pool-wide/cross-asset reentrancy exploits like AMP on Cream. */ function _beforeNonReentrant() external override { require(markets[msg.sender].isListed, "!Comptroller:_beforeNonReentrant"); require(_notEntered, "!reentered"); _notEntered = false; } /** * @dev Called by cTokens after a non-reentrant function for pool-wide reentrancy prevention. * Prevents pool-wide/cross-asset reentrancy exploits like AMP on Cream. */ function _afterNonReentrant() external override { require(markets[msg.sender].isListed, "!Comptroller:_afterNonReentrant"); _notEntered = true; // get a gas-refund post-Istanbul } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/ERC1967/ERC1967Proxy.sol) pragma solidity ^0.8.0; import "../Proxy.sol"; import "./ERC1967Upgrade.sol"; /** * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an * implementation address that can be changed. This address is stored in storage in the location specified by * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the * implementation behind the proxy. */ contract ERC1967Proxy is Proxy, ERC1967Upgrade { /** * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`. * * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded * function call, and allows initializing the storage of the proxy like a Solidity constructor. */ constructor(address _logic, bytes memory _data) payable { _upgradeToAndCall(_logic, _data, false); } /** * @dev Returns the current implementation address. */ function _implementation() internal view virtual override returns (address impl) { return ERC1967Upgrade._getImplementation(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeacon.sol"; import "../../interfaces/draft-IERC1822.sol"; import "../../utils/Address.sol"; import "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967Upgrade { // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS( address newImplementation, bytes memory data, bool forceCall ) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overridden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overridden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/transparent/TransparentUpgradeableProxy.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967Proxy.sol"; /** * @dev This contract implements a proxy that is upgradeable by an admin. * * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector * clashing], which can potentially be used in an attack, this contract uses the * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two * things that go hand in hand: * * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if * that call matches one of the admin functions exposed by the proxy itself. * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the * implementation. If the admin tries to call a function on the implementation it will fail with an error that says * "admin cannot fallback to proxy target". * * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due * to sudden errors when trying to call a function from the proxy implementation. * * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy. */ contract TransparentUpgradeableProxy is ERC1967Proxy { /** * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. */ constructor( address _logic, address admin_, bytes memory _data ) payable ERC1967Proxy(_logic, _data) { _changeAdmin(admin_); } /** * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin. */ modifier ifAdmin() { if (msg.sender == _getAdmin()) { _; } else { _fallback(); } } /** * @dev Returns the current admin. * * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` */ function admin() external ifAdmin returns (address admin_) { admin_ = _getAdmin(); } /** * @dev Returns the current implementation. * * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` */ function implementation() external ifAdmin returns (address implementation_) { implementation_ = _implementation(); } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. * * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. */ function changeAdmin(address newAdmin) external virtual ifAdmin { _changeAdmin(newAdmin); } /** * @dev Upgrade the implementation of the proxy. * * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeToAndCall(newImplementation, bytes(""), false); } /** * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the * proxied contract. * * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. */ function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeToAndCall(newImplementation, data, true); } /** * @dev Returns the current admin. */ function _admin() internal view virtual returns (address) { return _getAdmin(); } /** * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. */ function _beforeFallback() internal virtual override { require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); super._beforeFallback(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @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 * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://consensys.net/diligence/blog/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]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import { IonicComptroller } from "./ComptrollerInterface.sol"; import { InterestRateModel } from "./InterestRateModel.sol"; import { ComptrollerV3Storage } from "./ComptrollerStorage.sol"; import { AddressesProvider } from "../ionic/AddressesProvider.sol"; abstract contract CTokenAdminStorage { /* * Administrator for Ionic */ address payable public ionicAdmin; } abstract contract CErc20Storage is CTokenAdminStorage { /** * @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; /* * Maximum borrow rate that can ever be applied (.0005% / block) */ uint256 internal constant borrowRateMaxMantissa = 0.0005e16; /* * Maximum fraction of interest that can be set aside for reserves + fees */ uint256 internal constant reserveFactorPlusFeesMaxMantissa = 1e18; /** * @notice Contract which oversees inter-cToken operations */ IonicComptroller public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /* * Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) */ uint256 internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for admin fees */ uint256 public adminFeeMantissa; /** * @notice Fraction of interest currently set aside for Ionic fees */ uint256 public ionicFeeMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint256 public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint256 public accrualBlockNumber; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint256 public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint256 public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint256 public totalReserves; /** * @notice Total amount of admin fees of the underlying held in this market */ uint256 public totalAdminFees; /** * @notice Total amount of Ionic fees of the underlying held in this market */ uint256 public totalIonicFees; /** * @notice Total number of tokens in circulation */ uint256 public totalSupply; /* * Official record of token balances for each account */ mapping(address => uint256) internal accountTokens; /* * Approved token transfer amounts on behalf of others */ mapping(address => mapping(address => uint256)) 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 { uint256 principal; uint256 interestIndex; } /* * Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; /* * Share of seized collateral that is added to reserves */ uint256 public constant protocolSeizeShareMantissa = 2.8e16; //2.8% /* * Share of seized collateral taken as fees */ uint256 public constant feeSeizeShareMantissa = 1e17; //10% /** * @notice Underlying asset for this CToken */ address public underlying; /** * @notice Addresses Provider */ AddressesProvider public ap; } abstract contract CTokenBaseEvents { /* ERC20 */ /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint256 amount); /*** Admin Events ***/ /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint256 oldReserveFactorMantissa, uint256 newReserveFactorMantissa); /** * @notice Event emitted when the admin fee is changed */ event NewAdminFee(uint256 oldAdminFeeMantissa, uint256 newAdminFeeMantissa); /** * @notice Event emitted when the Ionic fee is changed */ event NewIonicFee(uint256 oldIonicFeeMantissa, uint256 newIonicFeeMantissa); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint256 amount); /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint256 cashPrior, uint256 interestAccumulated, uint256 borrowIndex, uint256 totalBorrows); } abstract contract CTokenFirstExtensionEvents is CTokenBaseEvents { event Flash(address receiver, uint256 amount); } abstract contract CTokenSecondExtensionEvents is CTokenBaseEvents { /*** Market Events ***/ /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint256 mintAmount, uint256 mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint256 borrowAmount, uint256 accountBorrows, uint256 totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint256 repayAmount, uint256 accountBorrows, uint256 totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow( address liquidator, address borrower, uint256 repayAmount, address cTokenCollateral, uint256 seizeTokens ); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint256 addAmount, uint256 newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint256 reduceAmount, uint256 newTotalReserves); } interface CTokenFirstExtensionInterface { /*** User Interface ***/ function transfer(address dst, uint256 amount) external returns (bool); function transferFrom( address src, address dst, uint256 amount ) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function balanceOf(address owner) external view returns (uint256); /*** Admin Functions ***/ function _setReserveFactor(uint256 newReserveFactorMantissa) external returns (uint256); function _setAdminFee(uint256 newAdminFeeMantissa) external returns (uint256); function _setInterestRateModel(InterestRateModel newInterestRateModel) external returns (uint256); function getAccountSnapshot(address account) external view returns ( uint256, uint256, uint256, uint256 ); function borrowRatePerBlock() external view returns (uint256); function supplyRatePerBlock() external view returns (uint256); function exchangeRateCurrent() external view returns (uint256); function accrueInterest() external returns (uint256); function totalBorrowsCurrent() external view returns (uint256); function borrowBalanceCurrent(address account) external view returns (uint256); function getTotalUnderlyingSupplied() external view returns (uint256); function balanceOfUnderlying(address owner) external view returns (uint256); function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); function flash(uint256 amount, bytes calldata data) external; function supplyRatePerBlockAfterDeposit(uint256 mintAmount) external view returns (uint256); function supplyRatePerBlockAfterWithdraw(uint256 withdrawAmount) external view returns (uint256); function borrowRatePerBlockAfterBorrow(uint256 borrowAmount) external view returns (uint256); function registerInSFS() external returns (uint256); } interface CTokenSecondExtensionInterface { function mint(uint256 mintAmount) external returns (uint256); function redeem(uint256 redeemTokens) external returns (uint256); function redeemUnderlying(uint256 redeemAmount) external returns (uint256); function borrow(uint256 borrowAmount) external returns (uint256); function repayBorrow(uint256 repayAmount) external returns (uint256); function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256); function liquidateBorrow( address borrower, uint256 repayAmount, address cTokenCollateral ) external returns (uint256); function getCash() external view returns (uint256); function seize( address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); /*** Admin Functions ***/ function _withdrawAdminFees(uint256 withdrawAmount) external returns (uint256); function _withdrawIonicFees(uint256 withdrawAmount) external returns (uint256); function selfTransferOut(address to, uint256 amount) external; function selfTransferIn(address from, uint256 amount) external returns (uint256); } interface CDelegatorInterface { function implementation() external view returns (address); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationSafe(address implementation_, bytes calldata becomeImplementationData) external; /** * @dev upgrades the implementation if necessary */ function _upgrade() external; } interface CDelegateInterface { /** * @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 calldata data) external; function delegateType() external pure returns (uint8); function contractType() external pure returns (string memory); } abstract contract CErc20AdminBase is CErc20Storage { /** * @notice Returns a boolean indicating if the sender has admin rights */ function hasAdminRights() internal view returns (bool) { ComptrollerV3Storage comptrollerStorage = ComptrollerV3Storage(address(comptroller)); return (msg.sender == comptrollerStorage.admin() && comptrollerStorage.adminHasRights()) || (msg.sender == address(ionicAdmin) && comptrollerStorage.ionicAdminHasRights()); } } abstract contract CErc20FirstExtensionBase is CErc20AdminBase, CTokenFirstExtensionEvents, CTokenFirstExtensionInterface {} abstract contract CTokenSecondExtensionBase is CErc20AdminBase, CTokenSecondExtensionEvents, CTokenSecondExtensionInterface, CDelegateInterface {} abstract contract CErc20DelegatorBase is CErc20AdminBase, CTokenSecondExtensionEvents, CDelegatorInterface {} interface CErc20StorageInterface { function admin() external view returns (address); function adminHasRights() external view returns (bool); function ionicAdmin() external view returns (address); function ionicAdminHasRights() external view returns (bool); function comptroller() external view returns (IonicComptroller); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint256); function adminFeeMantissa() external view returns (uint256); function ionicFeeMantissa() external view returns (uint256); function reserveFactorMantissa() external view returns (uint256); function protocolSeizeShareMantissa() external view returns (uint256); function feeSeizeShareMantissa() external view returns (uint256); function totalReserves() external view returns (uint256); function totalAdminFees() external view returns (uint256); function totalIonicFees() external view returns (uint256); function totalBorrows() external view returns (uint256); function accrualBlockNumber() external view returns (uint256); function underlying() external view returns (address); function borrowIndex() external view returns (uint256); function interestRateModel() external view returns (address); } interface CErc20PluginStorageInterface is CErc20StorageInterface { function plugin() external view returns (address); } interface CErc20PluginRewardsInterface is CErc20PluginStorageInterface { function approve(address, address) external; } interface ICErc20 is CErc20StorageInterface, CTokenSecondExtensionInterface, CTokenFirstExtensionInterface, CDelegatorInterface, CDelegateInterface {} interface ICErc20Plugin is CErc20PluginStorageInterface, ICErc20 { function _updatePlugin(address _plugin) external; } interface ICErc20PluginRewards is CErc20PluginRewardsInterface, ICErc20 {}
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; /** * @title Careful Math * @author Compound * @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(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint256 c; unchecked { 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(uint256 a, uint256 b) internal pure returns (MathError, uint256) { 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(uint256 a, uint256 b) internal pure returns (MathError, uint256) { 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(uint256 a, uint256 b) internal pure returns (MathError, uint256) { uint256 c; unchecked { 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( uint256 a, uint256 b, uint256 c ) internal pure returns (MathError, uint256) { (MathError err0, uint256 sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import { BasePriceOracle } from "../oracles/BasePriceOracle.sol"; import { ICErc20 } from "./CTokenInterfaces.sol"; import { ComptrollerV3Storage } from "../compound/ComptrollerStorage.sol"; interface ComptrollerInterface { function isDeprecated(ICErc20 cToken) external view returns (bool); function _becomeImplementation() external; function _deployMarket( uint8 delegateType, bytes memory constructorData, bytes calldata becomeImplData, uint256 collateralFactorMantissa ) external returns (uint256); function getAssetsIn(address account) external view returns (ICErc20[] memory); function checkMembership(address account, ICErc20 cToken) external view returns (bool); function _setPriceOracle(BasePriceOracle newOracle) external returns (uint256); function _setCloseFactor(uint256 newCloseFactorMantissa) external returns (uint256); function _setCollateralFactor(ICErc20 market, uint256 newCollateralFactorMantissa) external returns (uint256); function _setLiquidationIncentive(uint256 newLiquidationIncentiveMantissa) external returns (uint256); function _setWhitelistEnforcement(bool enforce) external returns (uint256); function _setWhitelistStatuses(address[] calldata _suppliers, bool[] calldata statuses) external returns (uint256); function _addRewardsDistributor(address distributor) external returns (uint256); function getHypotheticalAccountLiquidity( address account, address cTokenModify, uint256 redeemTokens, uint256 borrowAmount, uint256 repayAmount ) external view returns ( uint256, uint256, uint256, uint256 ); function getMaxRedeemOrBorrow( address account, ICErc20 cToken, bool isBorrow ) external view returns (uint256); /*** Assets You Are In ***/ function enterMarkets(address[] calldata cTokens) external returns (uint256[] memory); function exitMarket(address cToken) external returns (uint256); /*** Policy Hooks ***/ function mintAllowed( address cToken, address minter, uint256 mintAmount ) external returns (uint256); function redeemAllowed( address cToken, address redeemer, uint256 redeemTokens ) external returns (uint256); function redeemVerify( address cToken, address redeemer, uint256 redeemAmount, uint256 redeemTokens ) external; function borrowAllowed( address cToken, address borrower, uint256 borrowAmount ) external returns (uint256); function borrowWithinLimits(address cToken, uint256 accountBorrowsNew) external view returns (uint256); function repayBorrowAllowed( address cToken, address payer, address borrower, uint256 repayAmount ) external returns (uint256); function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint256 repayAmount ) external returns (uint256); function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); function transferAllowed( address cToken, address src, address dst, uint256 transferTokens ) external returns (uint256); function mintVerify( address cToken, address minter, uint256 actualMintAmount, uint256 mintTokens ) external; /*** Liquidity/Liquidation Calculations ***/ function getAccountLiquidity(address account) external view returns ( uint256 error, uint256 collateralValue, uint256 liquidity, uint256 shortfall ); function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint256 repayAmount ) external view returns (uint256, uint256); /*** Pool-Wide/Cross-Asset Reentrancy Prevention ***/ function _beforeNonReentrant() external; function _afterNonReentrant() external; } interface ComptrollerStorageInterface { function admin() external view returns (address); function adminHasRights() external view returns (bool); function ionicAdmin() external view returns (address); function ionicAdminHasRights() external view returns (bool); function pendingAdmin() external view returns (address); function oracle() external view returns (BasePriceOracle); function pauseGuardian() external view returns (address); function closeFactorMantissa() external view returns (uint256); function liquidationIncentiveMantissa() external view returns (uint256); function isUserOfPool(address user) external view returns (bool); function whitelist(address account) external view returns (bool); function enforceWhitelist() external view returns (bool); function borrowCapForCollateral(address borrowed, address collateral) external view returns (uint256); function borrowingAgainstCollateralBlacklist(address borrowed, address collateral) external view returns (bool); function suppliers(address account) external view returns (bool); function cTokensByUnderlying(address) external view returns (address); function supplyCaps(address cToken) external view returns (uint256); function borrowCaps(address cToken) external view returns (uint256); function markets(address cToken) external view returns (bool, uint256); function accountAssets(address, uint256) external view returns (address); function borrowGuardianPaused(address cToken) external view returns (bool); function mintGuardianPaused(address cToken) external view returns (bool); function rewardsDistributors(uint256) external view returns (address); } interface SFSRegister { function register(address _recipient) external returns (uint256 tokenId); } interface ComptrollerExtensionInterface { function getWhitelistedSuppliersSupply(address cToken) external view returns (uint256 supplied); function getWhitelistedBorrowersBorrows(address cToken) external view returns (uint256 borrowed); function getAllMarkets() external view returns (ICErc20[] memory); function getAllBorrowers() external view returns (address[] memory); function getAllBorrowersCount() external view returns (uint256); function getPaginatedBorrowers(uint256 page, uint256 pageSize) external view returns (uint256 _totalPages, address[] memory _pageOfBorrowers); function getRewardsDistributors() external view returns (address[] memory); function getAccruingFlywheels() external view returns (address[] memory); function _supplyCapWhitelist( address cToken, address account, bool whitelisted ) external; function _setBorrowCapForCollateral( address cTokenBorrow, address cTokenCollateral, uint256 borrowCap ) external; function _setBorrowCapForCollateralWhitelist( address cTokenBorrow, address cTokenCollateral, address account, bool whitelisted ) external; function isBorrowCapForCollateralWhitelisted( address cTokenBorrow, address cTokenCollateral, address account ) external view returns (bool); function _blacklistBorrowingAgainstCollateral( address cTokenBorrow, address cTokenCollateral, bool blacklisted ) external; function _blacklistBorrowingAgainstCollateralWhitelist( address cTokenBorrow, address cTokenCollateral, address account, bool whitelisted ) external; function isBlacklistBorrowingAgainstCollateralWhitelisted( address cTokenBorrow, address cTokenCollateral, address account ) external view returns (bool); function isSupplyCapWhitelisted(address cToken, address account) external view returns (bool); function _borrowCapWhitelist( address cToken, address account, bool whitelisted ) external; function isBorrowCapWhitelisted(address cToken, address account) external view returns (bool); function _removeFlywheel(address flywheelAddress) external returns (bool); function getWhitelist() external view returns (address[] memory); function addNonAccruingFlywheel(address flywheelAddress) external returns (bool); function _setMarketSupplyCaps(ICErc20[] calldata cTokens, uint256[] calldata newSupplyCaps) external; function _setMarketBorrowCaps(ICErc20[] calldata cTokens, uint256[] calldata newBorrowCaps) external; function _setBorrowCapGuardian(address newBorrowCapGuardian) external; function _setPauseGuardian(address newPauseGuardian) external returns (uint256); function _setMintPaused(ICErc20 cToken, bool state) external returns (bool); function _setBorrowPaused(ICErc20 cToken, bool state) external returns (bool); function _setTransferPaused(bool state) external returns (bool); function _setSeizePaused(bool state) external returns (bool); function _unsupportMarket(ICErc20 cToken) external returns (uint256); function getAssetAsCollateralValueCap( ICErc20 collateral, ICErc20 cTokenModify, bool redeeming, address account ) external view returns (uint256); function registerInSFS() external returns (uint256); } interface UnitrollerInterface { function comptrollerImplementation() external view returns (address); function _upgrade() external; function _acceptAdmin() external returns (uint256); function _setPendingAdmin(address newPendingAdmin) external returns (uint256); function _toggleAdminRights(bool hasRights) external returns (uint256); } interface IComptrollerExtension is ComptrollerExtensionInterface, ComptrollerStorageInterface {} //interface IComptrollerBase is ComptrollerInterface, ComptrollerStorageInterface {} interface IonicComptroller is ComptrollerInterface, ComptrollerExtensionInterface, UnitrollerInterface, ComptrollerStorageInterface { } abstract contract ComptrollerBase is ComptrollerV3Storage { /// @notice Indicator that this is a Comptroller contract (for inspection) bool public constant isComptroller = true; }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "./IFeeDistributor.sol"; import "../oracles/BasePriceOracle.sol"; import { ICErc20 } from "./CTokenInterfaces.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; contract UnitrollerAdminStorage { /* * Administrator for Ionic */ address payable public ionicAdmin; /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Whether or not the Ionic admin has admin rights */ bool public ionicAdminHasRights = true; /** * @notice Whether or not the admin has admin rights */ bool public adminHasRights = true; /** * @notice Returns a boolean indicating if the sender has admin rights */ function hasAdminRights() internal view returns (bool) { return (msg.sender == admin && adminHasRights) || (msg.sender == address(ionicAdmin) && ionicAdminHasRights); } } contract ComptrollerV1Storage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ BasePriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint256 public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint256 public liquidationIncentiveMantissa; /* * UNUSED AFTER UPGRADE: Max number of assets a single account can participate in (borrow or use as collateral) */ uint256 internal maxAssets; /** * @notice Per-account mapping of "assets you are in", capped by maxAssets */ mapping(address => ICErc20[]) public accountAssets; } contract ComptrollerV2Storage is ComptrollerV1Storage { struct Market { // Whether or not this market is listed bool isListed; // 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. uint256 collateralFactorMantissa; // 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 A list of all markets ICErc20[] public allMarkets; /** * @dev Maps borrowers to booleans indicating if they have entered any markets */ mapping(address => bool) internal borrowers; /// @notice A list of all borrowers who have entered markets address[] public allBorrowers; // Indexes of borrower account addresses in the `allBorrowers` array mapping(address => uint256) internal borrowerIndexes; /** * @dev Maps suppliers to booleans indicating if they have ever supplied to any markets */ mapping(address => bool) public suppliers; /// @notice All cTokens addresses mapped by their underlying token addresses mapping(address => ICErc20) public cTokensByUnderlying; /// @notice Whether or not the supplier whitelist is enforced bool public enforceWhitelist; /// @notice Maps addresses to booleans indicating if they are allowed to supply assets (i.e., mint cTokens) mapping(address => bool) public whitelist; /// @notice An array of all whitelisted accounts address[] public whitelistArray; // Indexes of account addresses in the `whitelistArray` array mapping(address => uint256) internal whitelistIndexes; /** * @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; } contract ComptrollerV3Storage is ComptrollerV2Storage { /// @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 => uint256) public borrowCaps; /// @notice Supply caps enforced by mintAllowed for each cToken address. Defaults to zero which corresponds to unlimited supplying. mapping(address => uint256) public supplyCaps; /// @notice RewardsDistributor contracts to notify of flywheel changes. address[] public rewardsDistributors; /// @dev Guard variable for pool-wide/cross-asset re-entrancy checks bool internal _notEntered; /// @dev Whether or not _notEntered has been initialized bool internal _notEnteredInitialized; /// @notice RewardsDistributor to list for claiming, but not to notify of flywheel changes. address[] public nonAccruingRewardsDistributors; /// @dev cap for each user's borrows against specific assets - denominated in the borrowed asset mapping(address => mapping(address => uint256)) public borrowCapForCollateral; /// @dev blacklist to disallow the borrowing of an asset against specific collateral mapping(address => mapping(address => bool)) public borrowingAgainstCollateralBlacklist; /// @dev set of whitelisted accounts that are allowed to bypass the borrowing against specific collateral cap mapping(address => mapping(address => EnumerableSet.AddressSet)) internal borrowCapForCollateralWhitelist; /// @dev set of whitelisted accounts that are allowed to bypass the borrow cap mapping(address => mapping(address => EnumerableSet.AddressSet)) internal borrowingAgainstCollateralBlacklistWhitelist; /// @dev set of whitelisted accounts that are allowed to bypass the supply cap mapping(address => EnumerableSet.AddressSet) internal supplyCapWhitelist; /// @dev set of whitelisted accounts that are allowed to bypass the borrow cap mapping(address => EnumerableSet.AddressSet) internal borrowCapWhitelist; }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; contract ComptrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, COMPTROLLER_MISMATCH, INSUFFICIENT_SHORTFALL, INSUFFICIENT_LIQUIDITY, INVALID_CLOSE_FACTOR, INVALID_COLLATERAL_FACTOR, INVALID_LIQUIDATION_INCENTIVE, MARKET_NOT_LISTED, MARKET_ALREADY_LISTED, MATH_ERROR, NONZERO_BORROW_BALANCE, PRICE_ERROR, REJECTION, SNAPSHOT_ERROR, TOO_MANY_ASSETS, TOO_MUCH_REPAY, SUPPLIER_NOT_WHITELISTED, BORROW_BELOW_MIN, SUPPLY_ABOVE_MAX, NONZERO_TOTAL_SUPPLY } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, ADD_REWARDS_DISTRIBUTOR_OWNER_CHECK, EXIT_MARKET_BALANCE_OWED, EXIT_MARKET_REJECTION, TOGGLE_ADMIN_RIGHTS_OWNER_CHECK, TOGGLE_AUTO_IMPLEMENTATIONS_ENABLED_OWNER_CHECK, 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_LIQUIDATION_INCENTIVE_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_VALIDATION, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_CONTRACT_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK, SET_PRICE_ORACLE_OWNER_CHECK, SET_WHITELIST_ENFORCEMENT_OWNER_CHECK, SET_WHITELIST_STATUS_OWNER_CHECK, SUPPORT_MARKET_EXISTS, SUPPORT_MARKET_OWNER_CHECK, SET_PAUSE_GUARDIAN_OWNER_CHECK, UNSUPPORT_MARKET_OWNER_CHECK, UNSUPPORT_MARKET_DOES_NOT_EXIST, UNSUPPORT_MARKET_IN_USE } /** * @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(uint256 error, uint256 info, uint256 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 (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return uint256(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, UTILIZATION_ABOVE_MAX } /* * 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_NEW_TOTAL_IONIC_FEES_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_TOTAL_ADMIN_FEES_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, NEW_UTILIZATION_RATE_ABOVE_MAX, 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, WITHDRAW_IONIC_FEES_ACCRUE_INTEREST_FAILED, WITHDRAW_IONIC_FEES_CASH_NOT_AVAILABLE, WITHDRAW_IONIC_FEES_FRESH_CHECK, WITHDRAW_IONIC_FEES_VALIDATION, WITHDRAW_ADMIN_FEES_ACCRUE_INTEREST_FAILED, WITHDRAW_ADMIN_FEES_CASH_NOT_AVAILABLE, WITHDRAW_ADMIN_FEES_FRESH_CHECK, WITHDRAW_ADMIN_FEES_VALIDATION, 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, TOGGLE_ADMIN_RIGHTS_OWNER_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_ADMIN_FEE_ACCRUE_INTEREST_FAILED, SET_ADMIN_FEE_ADMIN_CHECK, SET_ADMIN_FEE_FRESH_CHECK, SET_ADMIN_FEE_BOUNDS_CHECK, SET_IONIC_FEE_ACCRUE_INTEREST_FAILED, SET_IONIC_FEE_FRESH_CHECK, SET_IONIC_FEE_BOUNDS_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 } /** * @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(uint256 error, uint256 info, uint256 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 (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return err == Error.COMPTROLLER_REJECTION ? 1000 + opaqueError : uint256(err); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "./CarefulMath.sol"; import "./ExponentialNoError.sol"; /** * @title Exponential module for storing fixed-precision decimals * @author Compound * @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(uint256 num, uint256 denom) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({ mantissa: 0 })); } (MathError err1, uint256 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) internal pure returns (MathError, Exp memory) { (MathError error, uint256 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) internal pure returns (MathError, Exp memory) { (MathError error, uint256 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, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 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, uint256 scalar) internal pure returns (MathError, uint256) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 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(uint256 scalar, Exp memory divisor) internal pure 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, uint256 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(uint256 scalar, Exp memory divisor) internal pure returns (MathError, uint256) { (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) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 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, uint256 doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({ mantissa: 0 })); } (MathError err2, uint256 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(uint256 a, uint256 b) internal pure 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 ) internal pure 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) internal pure returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; /** * @title Exponential module for storing fixed-precision decimals * @author Compound * @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 { uint256 constant expScale = 1e18; uint256 constant doubleScale = 1e36; uint256 constant halfExpScale = expScale / 2; uint256 constant mantissaOne = expScale; struct Exp { uint256 mantissa; } struct Double { uint256 mantissa; } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) internal pure returns (uint256) { // 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, uint256 scalar) internal pure returns (uint256) { 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, uint256 scalar, uint256 addend ) internal pure returns (uint256) { 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) internal pure returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev Checks if left Exp > right Exp. */ function greaterThanExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa > right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) internal pure returns (bool) { return value.mantissa == 0; } function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({ mantissa: add_(a.mantissa, b.mantissa) }); } function add_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({ mantissa: add_(a.mantissa, b.mantissa) }); } function add_(uint256 a, uint256 b) internal pure returns (uint256) { return add_(a, b, "addition overflow"); } function add_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({ mantissa: sub_(a.mantissa, b.mantissa) }); } function sub_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({ mantissa: sub_(a.mantissa, b.mantissa) }); } function sub_(uint256 a, uint256 b) internal pure returns (uint256) { return sub_(a, b, "subtraction underflow"); } function sub_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({ mantissa: mul_(a.mantissa, b.mantissa) / expScale }); } function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({ mantissa: mul_(a.mantissa, b) }); } function mul_(uint256 a, Exp memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({ mantissa: mul_(a.mantissa, b.mantissa) / doubleScale }); } function mul_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({ mantissa: mul_(a.mantissa, b) }); } function mul_(uint256 a, Double memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint256 a, uint256 b) internal pure returns (uint256) { return mul_(a, b, "multiplication overflow"); } function mul_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({ mantissa: div_(mul_(a.mantissa, expScale), b.mantissa) }); } function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({ mantissa: div_(a.mantissa, b) }); } function div_(uint256 a, Exp memory b) internal pure returns (uint256) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({ mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa) }); } function div_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({ mantissa: div_(a.mantissa, b) }); } function div_(uint256 a, Double memory b) internal pure returns (uint256) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint256 a, uint256 b) internal pure returns (uint256) { return div_(a, b, "divide by zero"); } function div_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } function fraction(uint256 a, uint256 b) internal pure returns (Double memory) { return Double({ mantissa: div_(mul_(a, doubleScale), b) }); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "../ionic/AuthoritiesRegistry.sol"; interface IFeeDistributor { function minBorrowEth() external view returns (uint256); function maxUtilizationRate() external view returns (uint256); function interestFeeRate() external view returns (uint256); function latestComptrollerImplementation(address oldImplementation) external view returns (address); function latestCErc20Delegate(uint8 delegateType) external view returns (address cErc20Delegate, bytes memory becomeImplementationData); function latestPluginImplementation(address oldImplementation) external view returns (address); function getComptrollerExtensions(address comptroller) external view returns (address[] memory); function getCErc20DelegateExtensions(address cErc20Delegate) external view returns (address[] memory); function deployCErc20( uint8 delegateType, bytes calldata constructorData, bytes calldata becomeImplData ) external returns (address); function canCall( address pool, address user, address target, bytes4 functionSig ) external view returns (bool); function authoritiesRegistry() external view returns (AuthoritiesRegistry); fallback() external payable; receive() external payable; }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; /** * @title Compound's InterestRateModel Interface * @author Compound */ abstract 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 block * @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 block (as a percentage, and scaled by 1e18) */ function getBorrowRate( uint256 cash, uint256 borrows, uint256 reserves ) public view virtual returns (uint256); /** * @notice Calculates the current supply interest rate per block * @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 block (as a percentage, and scaled by 1e18) */ function getSupplyRate( uint256 cash, uint256 borrows, uint256 reserves, uint256 reserveFactorMantissa ) public view virtual returns (uint256); }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "./ErrorReporter.sol"; import "./ComptrollerStorage.sol"; import "./Comptroller.sol"; import { DiamondExtension, DiamondBase, LibDiamond } from "../ionic/DiamondExtension.sol"; /** * @title Unitroller * @dev Storage for the comptroller is at this address, while execution is delegated via the Diamond Extensions * CTokens should reference this contract as their comptroller. */ contract Unitroller is ComptrollerV3Storage, ComptrollerErrorReporter, DiamondBase { /** * @notice Event emitted when the admin rights are changed */ event AdminRightsToggled(bool hasRights); /** * @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(address payable _ionicAdmin) { admin = msg.sender; ionicAdmin = _ionicAdmin; } /*** Admin Functions ***/ /** * @notice Toggles admin rights. * @param hasRights Boolean indicating if the admin is to have rights. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _toggleAdminRights(bool hasRights) external returns (uint256) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.TOGGLE_ADMIN_RIGHTS_OWNER_CHECK); } // Check that rights have not already been set to the desired value if (adminHasRights == hasRights) return uint256(Error.NO_ERROR); adminHasRights = hasRights; emit AdminRightsToggled(hasRights); return uint256(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 (uint256) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } address oldPendingAdmin = pendingAdmin; pendingAdmin = newPendingAdmin; emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint256(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 (uint256) { // 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; admin = pendingAdmin; pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint256(Error.NO_ERROR); } function comptrollerImplementation() public view returns (address) { return LibDiamond.getExtensionForFunction(bytes4(keccak256(bytes("_deployMarket(uint8,bytes,bytes,uint256)")))); } /** * @dev upgrades the implementation if necessary */ function _upgrade() external { require(msg.sender == address(this) || hasAdminRights(), "!self || !admin"); address currentImplementation = comptrollerImplementation(); address latestComptrollerImplementation = IFeeDistributor(ionicAdmin).latestComptrollerImplementation( currentImplementation ); _updateExtensions(latestComptrollerImplementation); if (currentImplementation != latestComptrollerImplementation) { // reinitialize _functionCall(address(this), abi.encodeWithSignature("_becomeImplementation()"), "!become impl"); } } function _functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.call(data); if (!success) { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } return returndata; } function _updateExtensions(address currentComptroller) internal { address[] memory latestExtensions = IFeeDistributor(ionicAdmin).getComptrollerExtensions(currentComptroller); address[] memory currentExtensions = LibDiamond.listExtensions(); // removed the current (old) extensions for (uint256 i = 0; i < currentExtensions.length; i++) { LibDiamond.removeExtension(DiamondExtension(currentExtensions[i])); } // add the new extensions for (uint256 i = 0; i < latestExtensions.length; i++) { LibDiamond.addExtension(DiamondExtension(latestExtensions[i])); } } /** * @dev register a logic extension * @param extensionToAdd the extension whose functions are to be added * @param extensionToReplace the extension whose functions are to be removed/replaced */ function _registerExtension(DiamondExtension extensionToAdd, DiamondExtension extensionToReplace) external override { require(hasAdminRights(), "!unauthorized"); LibDiamond.registerExtension(extensionToAdd, extensionToReplace); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import { SafeOwnableUpgradeable } from "../ionic/SafeOwnableUpgradeable.sol"; /** * @title AddressesProvider * @notice The Addresses Provider serves as a central storage of system internal and external * contract addresses that change between deploys and across chains * @author Veliko Minkov <[email protected]> */ contract AddressesProvider is SafeOwnableUpgradeable { mapping(string => address) private _addresses; mapping(address => Contract) public plugins; mapping(address => Contract) public flywheelRewards; mapping(address => RedemptionStrategy) public redemptionStrategiesConfig; mapping(address => FundingStrategy) public fundingStrategiesConfig; JarvisPool[] public jarvisPoolsConfig; CurveSwapPool[] public curveSwapPoolsConfig; mapping(address => mapping(address => address)) public balancerPoolForTokens; /// @dev Initializer to set the admin that can set and change contracts addresses function initialize(address owner) public initializer { __SafeOwnable_init(owner); } /** * @dev The contract address and a string that uniquely identifies the contract's interface */ struct Contract { address addr; string contractInterface; } struct RedemptionStrategy { address addr; string contractInterface; address outputToken; } struct FundingStrategy { address addr; string contractInterface; address inputToken; } struct JarvisPool { address syntheticToken; address collateralToken; address liquidityPool; uint256 expirationTime; } struct CurveSwapPool { address poolAddress; address[] coins; } /** * @dev sets the address and contract interface ID of the flywheel for the reward token * @param rewardToken the reward token address * @param flywheelRewardsModule the flywheel rewards module address * @param contractInterface a string that uniquely identifies the contract's interface */ function setFlywheelRewards( address rewardToken, address flywheelRewardsModule, string calldata contractInterface ) public onlyOwner { flywheelRewards[rewardToken] = Contract(flywheelRewardsModule, contractInterface); } /** * @dev sets the address and contract interface ID of the ERC4626 plugin for the asset * @param asset the asset address * @param plugin the ERC4626 plugin address * @param contractInterface a string that uniquely identifies the contract's interface */ function setPlugin( address asset, address plugin, string calldata contractInterface ) public onlyOwner { plugins[asset] = Contract(plugin, contractInterface); } /** * @dev sets the address and contract interface ID of the redemption strategy for the asset * @param asset the asset address * @param strategy redemption strategy address * @param contractInterface a string that uniquely identifies the contract's interface */ function setRedemptionStrategy( address asset, address strategy, string calldata contractInterface, address outputToken ) public onlyOwner { redemptionStrategiesConfig[asset] = RedemptionStrategy(strategy, contractInterface, outputToken); } function getRedemptionStrategy(address asset) public view returns (RedemptionStrategy memory) { return redemptionStrategiesConfig[asset]; } /** * @dev sets the address and contract interface ID of the funding strategy for the asset * @param asset the asset address * @param strategy funding strategy address * @param contractInterface a string that uniquely identifies the contract's interface */ function setFundingStrategy( address asset, address strategy, string calldata contractInterface, address inputToken ) public onlyOwner { fundingStrategiesConfig[asset] = FundingStrategy(strategy, contractInterface, inputToken); } function getFundingStrategy(address asset) public view returns (FundingStrategy memory) { return fundingStrategiesConfig[asset]; } /** * @dev configures the Jarvis pool of a Jarvis synthetic token * @param syntheticToken the synthetic token address * @param collateralToken the collateral token address * @param liquidityPool the liquidity pool address * @param expirationTime the operation expiration time */ function setJarvisPool( address syntheticToken, address collateralToken, address liquidityPool, uint256 expirationTime ) public onlyOwner { jarvisPoolsConfig.push(JarvisPool(syntheticToken, collateralToken, liquidityPool, expirationTime)); } function setCurveSwapPool(address poolAddress, address[] calldata coins) public onlyOwner { curveSwapPoolsConfig.push(CurveSwapPool(poolAddress, coins)); } /** * @dev Sets an address for an id replacing the address saved in the addresses map * @param id The id * @param newAddress The address to set */ function setAddress(string calldata id, address newAddress) external onlyOwner { _addresses[id] = newAddress; } /** * @dev Returns an address by id * @return The address */ function getAddress(string calldata id) public view returns (address) { return _addresses[id]; } function getCurveSwapPools() public view returns (CurveSwapPool[] memory) { return curveSwapPoolsConfig; } function getJarvisPools() public view returns (JarvisPool[] memory) { return jarvisPoolsConfig; } function setBalancerPoolForTokens( address inputToken, address outputToken, address pool ) external onlyOwner { balancerPoolForTokens[inputToken][outputToken] = pool; } function getBalancerPoolForTokens(address inputToken, address outputToken) external view returns (address) { return balancerPoolForTokens[inputToken][outputToken]; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import { PoolRolesAuthority } from "../ionic/PoolRolesAuthority.sol"; import { SafeOwnableUpgradeable } from "../ionic/SafeOwnableUpgradeable.sol"; import { IonicComptroller } from "../compound/ComptrollerInterface.sol"; import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; contract AuthoritiesRegistry is SafeOwnableUpgradeable { mapping(address => PoolRolesAuthority) public poolsAuthorities; PoolRolesAuthority public poolAuthLogic; address public leveredPositionsFactory; bool public noAuthRequired; function initialize(address _leveredPositionsFactory) public initializer { __SafeOwnable_init(msg.sender); leveredPositionsFactory = _leveredPositionsFactory; poolAuthLogic = new PoolRolesAuthority(); } function reinitialize(address _leveredPositionsFactory) public onlyOwnerOrAdmin { leveredPositionsFactory = _leveredPositionsFactory; poolAuthLogic = new PoolRolesAuthority(); // for Neon the auth is not required noAuthRequired = block.chainid == 245022934; } function createPoolAuthority(address pool) public onlyOwner returns (PoolRolesAuthority auth) { require(address(poolsAuthorities[pool]) == address(0), "already created"); TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(poolAuthLogic), _getProxyAdmin(), ""); auth = PoolRolesAuthority(address(proxy)); auth.initialize(address(this)); poolsAuthorities[pool] = auth; auth.openPoolSupplierCapabilities(IonicComptroller(pool)); auth.setUserRole(address(this), auth.REGISTRY_ROLE(), true); // sets the registry owner as the auth owner reconfigureAuthority(pool); } function reconfigureAuthority(address poolAddress) public { IonicComptroller pool = IonicComptroller(poolAddress); PoolRolesAuthority auth = poolsAuthorities[address(pool)]; if (msg.sender != poolAddress || address(auth) != address(0)) { require(address(auth) != address(0), "no such authority"); require(msg.sender == owner() || msg.sender == poolAddress, "not owner or pool"); auth.configureRegistryCapabilities(); auth.configurePoolSupplierCapabilities(pool); auth.configurePoolBorrowerCapabilities(pool); // everyone can be a liquidator auth.configureOpenPoolLiquidatorCapabilities(pool); auth.configureLeveredPositionCapabilities(pool); if (auth.owner() != owner()) { auth.setOwner(owner()); } } } function canCall( address pool, address user, address target, bytes4 functionSig ) external view returns (bool) { PoolRolesAuthority authorityForPool = poolsAuthorities[pool]; if (address(authorityForPool) == address(0)) { return noAuthRequired; } else { // allow only if an auth exists and it allows the action return authorityForPool.canCall(user, target, functionSig); } } function setUserRole( address pool, address user, uint8 role, bool enabled ) external { PoolRolesAuthority poolAuth = poolsAuthorities[pool]; require(address(poolAuth) != address(0), "auth does not exist"); require(msg.sender == owner() || msg.sender == leveredPositionsFactory, "not owner or factory"); require(msg.sender != leveredPositionsFactory || role == poolAuth.LEVERED_POSITION_ROLE(), "only lev pos role"); poolAuth.setUserRole(user, role, enabled); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; /** * @notice a base contract for logic extensions that use the diamond pattern storage * to map the functions when looking up the extension contract to delegate to. */ abstract contract DiamondExtension { /** * @return a list of all the function selectors that this logic extension exposes */ function _getExtensionFunctions() external pure virtual returns (bytes4[] memory); } // When no function exists for function called error FunctionNotFound(bytes4 _functionSelector); // When no extension exists for function called error ExtensionNotFound(bytes4 _functionSelector); // When the function is already added error FunctionAlreadyAdded(bytes4 _functionSelector, address _currentImpl); abstract contract DiamondBase { /** * @dev register a logic extension * @param extensionToAdd the extension whose functions are to be added * @param extensionToReplace the extension whose functions are to be removed/replaced */ function _registerExtension(DiamondExtension extensionToAdd, DiamondExtension extensionToReplace) external virtual; function _listExtensions() public view returns (address[] memory) { return LibDiamond.listExtensions(); } fallback() external { address extension = LibDiamond.getExtensionForFunction(msg.sig); if (extension == address(0)) revert FunctionNotFound(msg.sig); // Execute external function from extension using delegatecall and return any value. assembly { // copy function selector and any arguments calldatacopy(0, 0, calldatasize()) // execute function call using the extension let result := delegatecall(gas(), extension, 0, calldatasize(), 0, 0) // get any return value returndatacopy(0, 0, returndatasize()) // return any return value or error back to the caller switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } } /** * @notice a library to use in a contract, whose logic is extended with diamond extension */ library LibDiamond { bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.extensions.diamond.storage"); struct Function { address extension; bytes4 selector; } struct LogicStorage { Function[] functions; address[] extensions; } function getExtensionForFunction(bytes4 msgSig) internal view returns (address) { return getExtensionForSelector(msgSig, diamondStorage()); } function diamondStorage() internal pure returns (LogicStorage storage ds) { bytes32 position = DIAMOND_STORAGE_POSITION; assembly { ds.slot := position } } function listExtensions() internal view returns (address[] memory) { return diamondStorage().extensions; } function registerExtension(DiamondExtension extensionToAdd, DiamondExtension extensionToReplace) internal { if (address(extensionToReplace) != address(0)) { removeExtension(extensionToReplace); } addExtension(extensionToAdd); } function removeExtension(DiamondExtension extension) internal { LogicStorage storage ds = diamondStorage(); // remove all functions of the extension to replace removeExtensionFunctions(extension); for (uint8 i = 0; i < ds.extensions.length; i++) { if (ds.extensions[i] == address(extension)) { ds.extensions[i] = ds.extensions[ds.extensions.length - 1]; ds.extensions.pop(); } } } function addExtension(DiamondExtension extension) internal { LogicStorage storage ds = diamondStorage(); for (uint8 i = 0; i < ds.extensions.length; i++) { require(ds.extensions[i] != address(extension), "extension already added"); } addExtensionFunctions(extension); ds.extensions.push(address(extension)); } function removeExtensionFunctions(DiamondExtension extension) internal { bytes4[] memory fnsToRemove = extension._getExtensionFunctions(); LogicStorage storage ds = diamondStorage(); for (uint16 i = 0; i < fnsToRemove.length; i++) { bytes4 selectorToRemove = fnsToRemove[i]; // must never fail assert(address(extension) == getExtensionForSelector(selectorToRemove, ds)); // swap with the last element in the selectorAtIndex array and remove the last element uint16 indexToKeep = getIndexForSelector(selectorToRemove, ds); ds.functions[indexToKeep] = ds.functions[ds.functions.length - 1]; ds.functions.pop(); } } function addExtensionFunctions(DiamondExtension extension) internal { bytes4[] memory fnsToAdd = extension._getExtensionFunctions(); LogicStorage storage ds = diamondStorage(); uint16 functionsCount = uint16(ds.functions.length); for (uint256 functionsIndex = 0; functionsIndex < fnsToAdd.length; functionsIndex++) { bytes4 selector = fnsToAdd[functionsIndex]; address oldImplementation = getExtensionForSelector(selector, ds); if (oldImplementation != address(0)) revert FunctionAlreadyAdded(selector, oldImplementation); ds.functions.push(Function(address(extension), selector)); functionsCount++; } } function getExtensionForSelector(bytes4 selector, LogicStorage storage ds) internal view returns (address) { uint256 fnsLen = ds.functions.length; for (uint256 i = 0; i < fnsLen; i++) { if (ds.functions[i].selector == selector) return ds.functions[i].extension; } return address(0); } function getIndexForSelector(bytes4 selector, LogicStorage storage ds) internal view returns (uint16) { uint16 fnsLen = uint16(ds.functions.length); for (uint16 i = 0; i < fnsLen; i++) { if (ds.functions[i].selector == selector) return i; } return type(uint16).max; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import { IonicComptroller, ComptrollerInterface } from "../compound/ComptrollerInterface.sol"; import { ICErc20, CTokenSecondExtensionInterface, CTokenFirstExtensionInterface } from "../compound/CTokenInterfaces.sol"; import { RolesAuthority, Authority } from "solmate/auth/authorities/RolesAuthority.sol"; import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; contract PoolRolesAuthority is RolesAuthority, Initializable { constructor() RolesAuthority(address(0), Authority(address(0))) { _disableInitializers(); } function initialize(address _owner) public initializer { owner = _owner; authority = this; } // up to 256 roles uint8 public constant REGISTRY_ROLE = 0; uint8 public constant SUPPLIER_ROLE = 1; uint8 public constant BORROWER_ROLE = 2; uint8 public constant LIQUIDATOR_ROLE = 3; uint8 public constant LEVERED_POSITION_ROLE = 4; function configureRegistryCapabilities() external requiresAuth { setRoleCapability(REGISTRY_ROLE, address(this), PoolRolesAuthority.configureRegistryCapabilities.selector, true); setRoleCapability( REGISTRY_ROLE, address(this), PoolRolesAuthority.configurePoolSupplierCapabilities.selector, true ); setRoleCapability( REGISTRY_ROLE, address(this), PoolRolesAuthority.configurePoolBorrowerCapabilities.selector, true ); setRoleCapability( REGISTRY_ROLE, address(this), PoolRolesAuthority.configureClosedPoolLiquidatorCapabilities.selector, true ); setRoleCapability( REGISTRY_ROLE, address(this), PoolRolesAuthority.configureOpenPoolLiquidatorCapabilities.selector, true ); setRoleCapability( REGISTRY_ROLE, address(this), PoolRolesAuthority.configureLeveredPositionCapabilities.selector, true ); setRoleCapability(REGISTRY_ROLE, address(this), RolesAuthority.setUserRole.selector, true); } function openPoolSupplierCapabilities(IonicComptroller pool) external requiresAuth { _setPublicPoolSupplierCapabilities(pool, true); } function closePoolSupplierCapabilities(IonicComptroller pool) external requiresAuth { _setPublicPoolSupplierCapabilities(pool, false); } function _setPublicPoolSupplierCapabilities(IonicComptroller pool, bool setPublic) internal { setPublicCapability(address(pool), pool.enterMarkets.selector, setPublic); setPublicCapability(address(pool), pool.exitMarket.selector, setPublic); ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { bytes4[] memory selectors = getSupplierMarketSelectors(); for (uint256 j = 0; j < selectors.length; j++) { setPublicCapability(address(allMarkets[i]), selectors[j], setPublic); } } } function configurePoolSupplierCapabilities(IonicComptroller pool) external requiresAuth { _configurePoolSupplierCapabilities(pool, SUPPLIER_ROLE); } function getSupplierMarketSelectors() internal pure returns (bytes4[] memory selectors) { uint8 fnsCount = 6; selectors = new bytes4[](fnsCount); selectors[--fnsCount] = CTokenSecondExtensionInterface.mint.selector; selectors[--fnsCount] = CTokenSecondExtensionInterface.redeem.selector; selectors[--fnsCount] = CTokenSecondExtensionInterface.redeemUnderlying.selector; selectors[--fnsCount] = CTokenFirstExtensionInterface.transfer.selector; selectors[--fnsCount] = CTokenFirstExtensionInterface.transferFrom.selector; selectors[--fnsCount] = CTokenFirstExtensionInterface.approve.selector; require(fnsCount == 0, "use the correct array length"); return selectors; } function _configurePoolSupplierCapabilities(IonicComptroller pool, uint8 role) internal { setRoleCapability(role, address(pool), pool.enterMarkets.selector, true); setRoleCapability(role, address(pool), pool.exitMarket.selector, true); ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { bytes4[] memory selectors = getSupplierMarketSelectors(); for (uint256 j = 0; j < selectors.length; j++) { setRoleCapability(role, address(allMarkets[i]), selectors[j], true); } } } function openPoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth { _setPublicPoolBorrowerCapabilities(pool, true); } function closePoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth { _setPublicPoolBorrowerCapabilities(pool, false); } function _setPublicPoolBorrowerCapabilities(IonicComptroller pool, bool setPublic) internal { ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { setPublicCapability(address(allMarkets[i]), allMarkets[i].borrow.selector, setPublic); setPublicCapability(address(allMarkets[i]), allMarkets[i].repayBorrow.selector, setPublic); setPublicCapability(address(allMarkets[i]), allMarkets[i].repayBorrowBehalf.selector, setPublic); setPublicCapability(address(allMarkets[i]), allMarkets[i].flash.selector, setPublic); } } function configurePoolBorrowerCapabilities(IonicComptroller pool) external requiresAuth { // borrowers have the SUPPLIER_ROLE capabilities by default _configurePoolSupplierCapabilities(pool, BORROWER_ROLE); ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].borrow.selector, true); setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrow.selector, true); setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrowBehalf.selector, true); setRoleCapability(BORROWER_ROLE, address(allMarkets[i]), allMarkets[i].flash.selector, true); } } function configureClosedPoolLiquidatorCapabilities(IonicComptroller pool) external requiresAuth { ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { setPublicCapability(address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, false); setRoleCapability(LIQUIDATOR_ROLE, address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, true); setRoleCapability(LIQUIDATOR_ROLE, address(allMarkets[i]), allMarkets[i].redeem.selector, true); } } function configureOpenPoolLiquidatorCapabilities(IonicComptroller pool) external requiresAuth { ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { setPublicCapability(address(allMarkets[i]), allMarkets[i].liquidateBorrow.selector, true); // TODO this leaves redeeming open for everyone setPublicCapability(address(allMarkets[i]), allMarkets[i].redeem.selector, true); } } function configureLeveredPositionCapabilities(IonicComptroller pool) external requiresAuth { setRoleCapability(LEVERED_POSITION_ROLE, address(pool), pool.enterMarkets.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(pool), pool.exitMarket.selector, true); ICErc20[] memory allMarkets = pool.getAllMarkets(); for (uint256 i = 0; i < allMarkets.length; i++) { setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].mint.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].redeem.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].redeemUnderlying.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].borrow.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].repayBorrow.selector, true); setRoleCapability(LEVERED_POSITION_ROLE, address(allMarkets[i]), allMarkets[i].flash.selector, true); } } }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol"; /** * @dev Ownable extension that requires a two-step process of setting the pending owner and the owner accepting it. * @notice Existing OwnableUpgradeable contracts cannot be upgraded due to the extra storage variable * that will shift the other. */ abstract contract SafeOwnableUpgradeable is OwnableUpgradeable { /** * @notice Pending owner of this contract */ address public pendingOwner; function __SafeOwnable_init(address owner_) internal onlyInitializing { __Ownable_init(); _transferOwnership(owner_); } struct AddressSlot { address value; } modifier onlyOwnerOrAdmin() { bool isOwner = owner() == _msgSender(); if (!isOwner) { address admin = _getProxyAdmin(); bool isAdmin = admin == _msgSender(); require(isAdmin, "Ownable: caller is neither the owner nor the admin"); } _; } /** * @notice Emitted when pendingOwner is changed */ event NewPendingOwner(address oldPendingOwner, address newPendingOwner); /** * @notice Emitted when pendingOwner is accepted, which means owner is updated */ event NewOwner(address oldOwner, address newOwner); /** * @notice Begins transfer of owner rights. The newPendingOwner must call `_acceptOwner` to finalize the transfer. * @dev Owner function to begin change of owner. The newPendingOwner must call `_acceptOwner` to finalize the transfer. * @param newPendingOwner New pending owner. */ function _setPendingOwner(address newPendingOwner) public onlyOwner { // Save current value, if any, for inclusion in log address oldPendingOwner = pendingOwner; // Store pendingOwner with value newPendingOwner pendingOwner = newPendingOwner; // Emit NewPendingOwner(oldPendingOwner, newPendingOwner) emit NewPendingOwner(oldPendingOwner, newPendingOwner); } /** * @notice Accepts transfer of owner rights. msg.sender must be pendingOwner * @dev Owner function for pending owner to accept role and update owner */ function _acceptOwner() public { // Check caller is pendingOwner and pendingOwner ≠ address(0) require(msg.sender == pendingOwner, "not the pending owner"); // Save current values for inclusion in log address oldOwner = owner(); address oldPendingOwner = pendingOwner; // Store owner with value pendingOwner _transferOwnership(pendingOwner); // Clear the pending value pendingOwner = address(0); emit NewOwner(oldOwner, pendingOwner); emit NewPendingOwner(oldPendingOwner, pendingOwner); } function renounceOwnership() public override onlyOwner { // do not remove this overriding fn revert("not used anymore"); } function transferOwnership(address newOwner) public override onlyOwner { emit NewPendingOwner(pendingOwner, newOwner); pendingOwner = newOwner; } function _getProxyAdmin() internal view returns (address admin) { bytes32 _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; AddressSlot storage adminSlot; assembly { adminSlot.slot := _ADMIN_SLOT } admin = adminSlot.value; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.10; import { ERC20 } from "solmate/tokens/ERC20.sol"; interface IIonicFlywheel { function isRewardsDistributor() external returns (bool); function isFlywheel() external returns (bool); function flywheelPreSupplierAction(address market, address supplier) external; function flywheelPreBorrowerAction(address market, address borrower) external; function flywheelPreTransferAction(address market, address src, address dst) external; function compAccrued(address user) external view returns (uint256); function addMarketForRewards(ERC20 strategy) external; function marketState(ERC20 strategy) external view returns (uint224 index, uint32 lastUpdatedTimestamp); }
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0; import "../compound/CTokenInterfaces.sol"; /** * @title BasePriceOracle * @notice Returns prices of underlying tokens directly without the caller having to specify a cToken address. * @dev Implements the `PriceOracle` interface. * @author David Lucid <[email protected]> (https://github.com/davidlucid) */ interface BasePriceOracle { /** * @notice Get the price of an underlying asset. * @param underlying The underlying asset to get the price of. * @return The underlying asset price in ETH as a mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function price(address underlying) external view returns (uint256); /** * @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(ICErc20 cToken) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Internal function that returns the initialized version. Returns `_initialized` */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Internal function that returns the initialized version. Returns `_initializing` */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://consensys.net/diligence/blog/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]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol) /// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol) abstract contract Auth { event OwnerUpdated(address indexed user, address indexed newOwner); event AuthorityUpdated(address indexed user, Authority indexed newAuthority); address public owner; Authority public authority; constructor(address _owner, Authority _authority) { owner = _owner; authority = _authority; emit OwnerUpdated(msg.sender, _owner); emit AuthorityUpdated(msg.sender, _authority); } modifier requiresAuth() virtual { require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED"); _; } function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) { Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas. // Checking if the caller is the owner only after calling the authority saves gas in most cases, but be // aware that this makes protected functions uncallable even to the owner if the authority is out of order. return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner; } function setAuthority(Authority newAuthority) public virtual { // We check if the caller is the owner first because we want to ensure they can // always swap out the authority even if it's reverting or using up a lot of gas. require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig)); authority = newAuthority; emit AuthorityUpdated(msg.sender, newAuthority); } function setOwner(address newOwner) public virtual requiresAuth { owner = newOwner; emit OwnerUpdated(msg.sender, newOwner); } } /// @notice A generic interface for a contract which provides authorization data to an Auth instance. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol) /// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol) interface Authority { function canCall( address user, address target, bytes4 functionSig ) external view returns (bool); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import {Auth, Authority} from "../Auth.sol"; /// @notice Role based Authority that supports up to 256 roles. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/authorities/RolesAuthority.sol) /// @author Modified from Dappsys (https://github.com/dapphub/ds-roles/blob/master/src/roles.sol) contract RolesAuthority is Auth, Authority { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event UserRoleUpdated(address indexed user, uint8 indexed role, bool enabled); event PublicCapabilityUpdated(address indexed target, bytes4 indexed functionSig, bool enabled); event RoleCapabilityUpdated(uint8 indexed role, address indexed target, bytes4 indexed functionSig, bool enabled); /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor(address _owner, Authority _authority) Auth(_owner, _authority) {} /*////////////////////////////////////////////////////////////// ROLE/USER STORAGE //////////////////////////////////////////////////////////////*/ mapping(address => bytes32) public getUserRoles; mapping(address => mapping(bytes4 => bool)) public isCapabilityPublic; mapping(address => mapping(bytes4 => bytes32)) public getRolesWithCapability; function doesUserHaveRole(address user, uint8 role) public view virtual returns (bool) { return (uint256(getUserRoles[user]) >> role) & 1 != 0; } function doesRoleHaveCapability( uint8 role, address target, bytes4 functionSig ) public view virtual returns (bool) { return (uint256(getRolesWithCapability[target][functionSig]) >> role) & 1 != 0; } /*////////////////////////////////////////////////////////////// AUTHORIZATION LOGIC //////////////////////////////////////////////////////////////*/ function canCall( address user, address target, bytes4 functionSig ) public view virtual override returns (bool) { return isCapabilityPublic[target][functionSig] || bytes32(0) != getUserRoles[user] & getRolesWithCapability[target][functionSig]; } /*////////////////////////////////////////////////////////////// ROLE CAPABILITY CONFIGURATION LOGIC //////////////////////////////////////////////////////////////*/ function setPublicCapability( address target, bytes4 functionSig, bool enabled ) public virtual requiresAuth { isCapabilityPublic[target][functionSig] = enabled; emit PublicCapabilityUpdated(target, functionSig, enabled); } function setRoleCapability( uint8 role, address target, bytes4 functionSig, bool enabled ) public virtual requiresAuth { if (enabled) { getRolesWithCapability[target][functionSig] |= bytes32(1 << role); } else { getRolesWithCapability[target][functionSig] &= ~bytes32(1 << role); } emit RoleCapabilityUpdated(role, target, functionSig, enabled); } /*////////////////////////////////////////////////////////////// USER ROLE ASSIGNMENT LOGIC //////////////////////////////////////////////////////////////*/ function setUserRole( address user, uint8 role, bool enabled ) public virtual requiresAuth { if (enabled) { getUserRoles[user] |= bytes32(1 << role); } else { getUserRoles[user] &= ~bytes32(1 << role); } emit UserRoleUpdated(user, role, enabled); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Modern and gas efficient ERC20 + EIP-2612 implementation. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol) /// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it. abstract contract ERC20 { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); /*////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ string public name; string public symbol; uint8 public immutable decimals; /*////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; /*////////////////////////////////////////////////////////////// EIP-2612 STORAGE //////////////////////////////////////////////////////////////*/ uint256 internal immutable INITIAL_CHAIN_ID; bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR; mapping(address => uint256) public nonces; /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor( string memory _name, string memory _symbol, uint8 _decimals ) { name = _name; symbol = _symbol; decimals = _decimals; INITIAL_CHAIN_ID = block.chainid; INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); } /*////////////////////////////////////////////////////////////// ERC20 LOGIC //////////////////////////////////////////////////////////////*/ function approve(address spender, uint256 amount) public virtual returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transfer(address to, uint256 amount) public virtual returns (bool) { balanceOf[msg.sender] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(msg.sender, to, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual returns (bool) { uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount; balanceOf[from] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(from, to, amount); return true; } /*////////////////////////////////////////////////////////////// EIP-2612 LOGIC //////////////////////////////////////////////////////////////*/ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED"); // Unchecked because the only math done is incrementing // the owner's nonce which cannot realistically overflow. unchecked { address recoveredAddress = ecrecover( keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR(), keccak256( abi.encode( keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ), owner, spender, value, nonces[owner]++, deadline ) ) ) ), v, r, s ); require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER"); allowance[recoveredAddress][spender] = value; } emit Approval(owner, spender, value); } function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); } function computeDomainSeparator() internal view virtual returns (bytes32) { return keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name)), keccak256("1"), block.chainid, address(this) ) ); } /*////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint(address to, uint256 amount) internal virtual { totalSupply += amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(address(0), to, amount); } function _burn(address from, uint256 amount) internal virtual { balanceOf[from] -= amount; // Cannot underflow because a user's balance // will never be larger than the total supply. unchecked { totalSupply -= amount; } emit Transfer(from, address(0), amount); } }
{ "evmVersion": "london", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"rewardsDistributor","type":"address"}],"name":"AddedRewardsDistributor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"error","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"info","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"detail","type":"uint256"}],"name":"Failure","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ICErc20","name":"cToken","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"MarketEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ICErc20","name":"cToken","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"MarketExited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ICErc20","name":"cToken","type":"address"}],"name":"MarketListed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldCloseFactorMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCloseFactorMantissa","type":"uint256"}],"name":"NewCloseFactor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract ICErc20","name":"cToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldCollateralFactorMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCollateralFactorMantissa","type":"uint256"}],"name":"NewCollateralFactor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLiquidationIncentiveMantissa","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLiquidationIncentiveMantissa","type":"uint256"}],"name":"NewLiquidationIncentive","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract BasePriceOracle","name":"oldPriceOracle","type":"address"},{"indexed":false,"internalType":"contract BasePriceOracle","name":"newPriceOracle","type":"address"}],"name":"NewPriceOracle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enforce","type":"bool"}],"name":"WhitelistEnforcementChanged","type":"event"},{"inputs":[{"internalType":"address","name":"distributor","type":"address"}],"name":"_addRewardsDistributor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_afterNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_becomeImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_beforeNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_borrowGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"delegateType","type":"uint8"},{"internalType":"bytes","name":"constructorData","type":"bytes"},{"internalType":"bytes","name":"becomeImplData","type":"bytes"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"}],"name":"_deployMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_getExtensionFunctions","outputs":[{"internalType":"bytes4[]","name":"functionSelectors","type":"bytes4[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"_mintGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newCloseFactorMantissa","type":"uint256"}],"name":"_setCloseFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ICErc20","name":"cToken","type":"address"},{"internalType":"uint256","name":"newCollateralFactorMantissa","type":"uint256"}],"name":"_setCollateralFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLiquidationIncentiveMantissa","type":"uint256"}],"name":"_setLiquidationIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BasePriceOracle","name":"newOracle","type":"address"}],"name":"_setPriceOracle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enforce","type":"bool"}],"name":"_setWhitelistEnforcement","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"suppliers","type":"address[]"},{"internalType":"bool[]","name":"statuses","type":"bool[]"}],"name":"_setWhitelistStatuses","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"accountAssets","outputs":[{"internalType":"contract ICErc20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adminHasRights","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allBorrowers","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allMarkets","outputs":[{"internalType":"contract ICErc20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"name":"borrowAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"borrowCapForCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowCapGuardian","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"borrowCaps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"borrowGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"uint256","name":"accountBorrowsNew","type":"uint256"}],"name":"borrowWithinLimits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"borrowingAgainstCollateralBlacklist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"cTokensByUnderlying","outputs":[{"internalType":"contract ICErc20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract ICErc20","name":"cToken","type":"address"}],"name":"checkMembership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeFactorMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enforceWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"cTokens","type":"address[]"}],"name":"enterMarkets","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"cTokenAddress","type":"address"}],"name":"exitMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAccountLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAssetsIn","outputs":[{"internalType":"contract ICErc20[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"cTokenModify","type":"address"},{"internalType":"uint256","name":"redeemTokens","type":"uint256"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"getHypotheticalAccountLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract ICErc20","name":"cTokenModify","type":"address"},{"internalType":"bool","name":"isBorrow","type":"bool"}],"name":"getMaxRedeemOrBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ionicAdmin","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ionicAdminHasRights","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isComptroller","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ICErc20","name":"cToken","type":"address"}],"name":"isDeprecated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cTokenBorrowed","type":"address"},{"internalType":"address","name":"cTokenCollateral","type":"address"},{"internalType":"address","name":"liquidator","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"liquidateBorrowAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"cTokenBorrowed","type":"address"},{"internalType":"address","name":"cTokenCollateral","type":"address"},{"internalType":"uint256","name":"actualRepayAmount","type":"uint256"}],"name":"liquidateCalculateSeizeTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidationIncentiveMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"markets","outputs":[{"internalType":"bool","name":"isListed","type":"bool"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cTokenAddress","type":"address"},{"internalType":"address","name":"minter","type":"address"},{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"mintAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"minter","type":"address"},{"internalType":"uint256","name":"actualMintAmount","type":"uint256"},{"internalType":"uint256","name":"mintTokens","type":"uint256"}],"name":"mintVerify","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nonAccruingRewardsDistributors","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract BasePriceOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pauseGuardian","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"redeemer","type":"address"},{"internalType":"uint256","name":"redeemTokens","type":"uint256"}],"name":"redeemAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"redeemer","type":"address"},{"internalType":"uint256","name":"redeemAmount","type":"uint256"},{"internalType":"uint256","name":"redeemTokens","type":"uint256"}],"name":"redeemVerify","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"repayBorrowAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardsDistributors","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cTokenCollateral","type":"address"},{"internalType":"address","name":"cTokenBorrowed","type":"address"},{"internalType":"address","name":"liquidator","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"seizeTokens","type":"uint256"}],"name":"seizeAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"seizeGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"suppliers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"supplyCaps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"src","type":"address"},{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"transferTokens","type":"uint256"}],"name":"transferAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"whitelistArray","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040526002805461ffff60a01b191661010160a01b17905534801561002557600080fd5b506154dc806100356000396000f3fe608060405234801561001057600080fd5b50600436106103c45760003560e01c80637e361b11116101ff578063c488847b1161011a578063da3d454c116100ad578063e87554461161007c578063e8755446146109a6578063eabe7d91146109af578063ede4edd0146109c2578063f851a440146109d557600080fd5b8063da3d454c14610959578063dce154491461096c578063e4028eee1461097f578063e6653f3d1461099257600080fd5b8063c91a424f116100e9578063c91a424f1461090c578063cf6bfd2d1461091f578063d02f735114610933578063d251fefc1461094657600080fd5b8063c488847b146108b6578063c6c5b0dd146108de578063c8c9c975146108f1578063c90c20b11461090457600080fd5b80639b19251a11610192578063b452ef6211610161578063b452ef621461085d578063b9b5b15314610870578063bdcdc25814610883578063c29982381461089657600080fd5b80639b19251a146107f9578063abfceffc1461081c578063ac0b0bb71461083c578063b09572101461085057600080fd5b8063929fe9a1116101ce578063929fe9a114610767578063940cd6f1146107a857806394543c15146107d3578063952adf5a146107e657600080fd5b80637e361b11146106e757806387f76303146106fa57806389f8132e1461070e5780638e8f294b1461072357600080fd5b80634ada90af116102ef5780635fc7e71e11610282578063731f0c2b11610251578063731f0c2b1461068b5780637515bafa146106ae578063779b2294146106c15780637dc0d1d0146106d457600080fd5b80635fc7e71e1461063a578063632e51421461064d5780636bd02b8a146106555780636d154ea51461066857600080fd5b806352d84d1e116102be57806352d84d1e146105d957806355ee1fe1146105ec5780635d72de62146105ff5780635ec88c791461060757600080fd5b80634ada90af146105975780634ef4c3e1146105a05780634fd42e17146105b357806351dff989146105c657600080fd5b806324008a621161036757806331ff47fa1161033657806331ff47fa146105035780633c94786f1461052c57806341c728b9146105405780634a5844321461057757600080fd5b806324008a62146104b757806324a3d622146104ca57806326782247146104dd578063317b0b77146104f057600080fd5b806316dc15fe116103a357806316dc15fe146104285780631976828e1461044b5780631c819e431461045e57806321af45691461048c57600080fd5b80627e3dd2146103c957806302c3bcbb146103e65780630a755ec214610414575b600080fd5b6103d1600181565b60405190151581526020015b60405180910390f35b6104066103f4366004614c62565b60186020526000908152604090205481565b6040519081526020016103dd565b6002546103d190600160a81b900460ff1681565b6103d1610436366004614c62565b600d6020526000908152604090205460ff1681565b610406610459366004614c8d565b6109e8565b6103d161046c366004614cd8565b601d60209081526000928352604080842090915290825290205460ff1681565b60165461049f906001600160a01b031681565b6040516001600160a01b0390911681526020016103dd565b6104066104c5366004614d11565b610bdd565b60135461049f906001600160a01b031681565b60025461049f906001600160a01b031681565b6104066104fe366004614d62565b610c1f565b61049f610511366004614c62565b600e602052600090815260409020546001600160a01b031681565b6013546103d190600160a01b900460ff1681565b61057561054e366004614d7b565b50506001600160a01b03166000908152600d60205260409020805460ff1916600117905550565b005b610406610585366004614c62565b60176020526000908152604090205481565b61040660055481565b6104066105ae366004614dc1565b610cf9565b6104066105c1366004614d62565b610f51565b6105756105d4366004614d7b565b61100d565b61049f6105e7366004614d62565b61109f565b6104066105fa366004614c62565b6110c9565b610575611149565b61061a610615366004614c62565b6111a6565b6040805194855260208501939093529183015260608201526080016103dd565b610406610648366004614e02565b6111ea565b6105756113ab565b61049f610663366004614d62565b611419565b6103d1610676366004614c62565b60156020526000908152604090205460ff1681565b6103d1610699366004614c62565b60146020526000908152604090205460ff1681565b61049f6106bc366004614d62565b611429565b6104066106cf366004614e66565b611439565b60035461049f906001600160a01b031681565b61061a6106f5366004614e92565b611594565b6013546103d190600160b01b900460ff1681565b6107166115de565b6040516103dd9190614ee3565b610750610731366004614c62565b6008602052600090815260409020805460019091015460ff9091169082565b6040805192151583526020830191909152016103dd565b6103d1610775366004614cd8565b6001600160a01b038082166000908152600860209081526040808320938616835260029093019052205460ff1692915050565b6104066107b6366004614cd8565b601c60209081526000928352604080842090915290825290205481565b6103d16107e1366004614c62565b611df8565b6104066107f4366004614f31565b611f62565b6103d1610807366004614c62565b60106020526000908152604090205460ff1681565b61082f61082a366004614c62565b611fe0565b6040516103dd9190614f4e565b6013546103d190600160b81b900460ff1681565b600f546103d19060ff1681565b61040661086b366004614fd1565b612056565b61040661087e366004614c62565b612234565b610406610891366004614d11565b61241c565b6108a96108a4366004615078565b61249f565b6040516103dd919061513d565b6108c96108c4366004614dc1565b612629565b604080519283526020830191909152016103dd565b61049f6108ec366004614d62565b612955565b6104066108ff3660046151ba565b612965565b610575612c0c565b60005461049f906001600160a01b031681565b6002546103d190600160a01b900460ff1681565b610406610941366004614e02565b612cb6565b61049f610954366004614d62565b612e3d565b610406610967366004614dc1565b612e4d565b61049f61097a366004614e66565b6132d4565b61040661098d366004614e66565b61330c565b6013546103d190600160a81b900460ff1681565b61040660045481565b6104066109bd366004614dc1565b613496565b6104066109d0366004614c62565b6134b3565b60015461049f906001600160a01b031681565b604051633af9e66960e01b81526001600160a01b0384811660048301526000918491839190831690633af9e66990602401602060405180830381865afa158015610a36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5a9190615226565b90506000806000610a7d8988610a71576000610a73565b895b6000806000613a3c565b929550935090915060009050836014811115610a9b57610a9b61523f565b14610ada5760405162461bcd60e51b815260206004820152600a602482015269216c697175696469747960b01b60448201526064015b60405180910390fd5b8015610aee57600095505050505050610bd6565b600087158015610b2857506001600160a01b038087166000908152600860209081526040808320938e16835260029093019052205460ff16155b15610b34575083610b56565b610b3f838a8a613ebf565b905087158015610b4e57508085105b15610b565750835b6000896001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bba9190615226565b905080821115610bca5780610bcc565b815b9750505050505050505b9392505050565b6001600160a01b03841660009081526008602052604081205460ff16610c075760085b9050610c17565b610c118584613fd8565b60005b90505b949350505050565b6000610c29614080565b610c3f57610c39600160076140d4565b92915050565b6040805160208082018352848252825190810190925266b1a2bc2ec50000808352815191929111610c7657610c17600560086140d4565b6040805160208101909152670c7d713b49da000080825283511115610caa57610ca1600560086140d4565b95945050505050565b600480549086905560408051828152602081018890527f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd991015b60405180910390a160005b9695505050505050565b6001600160a01b03831660009081526014602052604081205460ff1615610d515760405162461bcd60e51b815260206004820152600c60248201526b085b5a5b9d0e9c185d5cd95960a21b6044820152606401610ad1565b6001600160a01b03841660009081526008602052604090205460ff16610d7b5760085b9050610bd6565b600f5460ff168015610da657506001600160a01b03831660009081526010602052604090205460ff16155b15610db2576011610d74565b6001600160a01b0384166000908152601860205260409020548015801590610df857506001600160a01b03851660009081526020805260409020610df6908561414d565b155b15610f3c576000856001600160a01b0316634aeb3d9a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e619190615226565b9050600030604051637db121fd60e11b81526001600160a01b038981166004830152919091169063fb6243fa90602401602060405180830381865afa158015610eae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed29190615226565b90506000828210610ee557506000610ef2565b610eef828461526b565b90505b83610efd8783615282565b10610f385760405162461bcd60e51b815260206004820152600b60248201526a021737570706c79206361760ac1b6044820152606401610ad1565b5050505b610f46858561416f565b600095945050505050565b6000610f5b614080565b610f6b57610c396001600d6140d4565b60408051602080820183528482528251908101909252670de0b6b3a764000080835281519192911015610fa457610c176007600e6140d4565b60408051602081019091526714d1120d7b16000080825283511115610fcf57610ca16007600e6140d4565b600580549086905560408051828152602081018890527faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec13169101610ce4565b3360009081526008602052604090205460ff166110565760405162461bcd60e51b8152602060048201526007602482015266085b585c9ad95d60ca1b6044820152606401610ad1565b801580156110645750600082115b156110995760405162461bcd60e51b8152602060048201526005602482015264217a65726f60d81b6044820152606401610ad1565b50505050565b600981815481106110af57600080fd5b6000918252602090912001546001600160a01b0316905081565b60006110d3614080565b6110e357610c39600160126140d4565b600380546001600160a01b038481166001600160a01b031983168117909355604080519190921680825260208201939093527fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22910160405180910390a160009392505050565b3330146111855760405162461bcd60e51b815260206004820152600a602482015269085cd95b198818d85b1b60b21b6044820152606401610ad1565b601a54610100900460ff166111a457601a805461ffff19166101011790555b565b6000806000806000806000806111c189600080600080613a3c565b93509350935093508360148111156111db576111db61523f565b99929850909650945092505050565b6001600160a01b03851660009081526008602052604081205460ff16158061122b57506001600160a01b03851660009081526008602052604090205460ff16155b1561123a5760085b9050610ca1565b6040516305eff7ef60e21b81526001600160a01b038481166004830152600091908816906317bfdfbc90602401602060405180830381865afa158015611284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a89190615226565b90506112b387611df8565b156112fd57828110156112f85760405162461bcd60e51b815260206004820152600d60248201526c21626f72726f773e726570617960981b6044820152606401610ad1565b61139e565b60008061130f86600080600080613a3c565b935050509150600060148111156113285761132861523f565b82601481111561133a5761133a61523f565b1461135b578160148111156113515761135161523f565b9350505050610ca1565b80611367576003611351565b6000611383604051806020016040528060045481525085614211565b90508086111561139a576010945050505050610ca1565b5050505b5060009695505050505050565b3360009081526008602052604090205460ff1661140a5760405162461bcd60e51b815260206004820152601f60248201527f21436f6d7074726f6c6c65723a5f61667465724e6f6e5265656e7472616e74006044820152606401610ad1565b601a805460ff19166001179055565b601b81815481106110af57600080fd5b600b81815481106110af57600080fd5b600080546040805163fdb25fb160e01b8152905183926001600160a01b03169163fdb25fb19160048083019260209291908290030181865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190615226565b9050801561158a5760035460405163fc57d4df60e01b81526001600160a01b038681166004830152600092169063fc57d4df90602401602060405180830381865afa1580156114fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061151e9190615226565b90508061153057600c92505050610c39565b60008061154b60405180602001604052808581525087614229565b909250905060008260038111156115645761156461523f565b1461157757600a5b945050505050610c39565b8381101561158657601261156c565b5050505b6000949350505050565b6000806000806000806000806115ad8d8d8d8d8d613a3c565b93509350935093508360148111156115c7576115c761523f565b975091955093509150505b95509550955095915050565b60408051601e8082526103e082019092526060919081602082016103c0803683370190505091506394543c1560e01b826116178361529a565b92508260ff168151811061162d5761162d6152b7565b6001600160e01b031990921660209283029190910190910152635a2977b160e11b826116588361529a565b92508260ff168151811061166e5761166e6152b7565b6001600160e01b031990921660209283029190910190910152632aff3bff60e21b826116998361529a565b92508260ff16815181106116af576116af6152b7565b6001600160e01b03199092166020928302919091019091015263929fe9a160e01b826116da8361529a565b92508260ff16815181106116f0576116f06152b7565b6001600160e01b0319909216602092830291909101909101526355ee1fe160e01b8261171b8361529a565b92508260ff1681518110611731576117316152b7565b6001600160e01b03199092166020928302919091019091015263317b0b7760e01b8261175c8361529a565b92508260ff1681518110611772576117726152b7565b6001600160e01b031990921660209283029190910190910152637201477760e11b8261179d8361529a565b92508260ff16815181106117b3576117b36152b7565b6001600160e01b031990921660209283029190910190910152634fd42e1760e01b826117de8361529a565b92508260ff16815181106117f4576117f46152b7565b6001600160e01b031990921660209283029190910190910152634a956fad60e11b8261181f8361529a565b92508260ff1681518110611835576118356152b7565b6001600160e01b03199092166020928302919091019091015263c8c9c97560e01b826118608361529a565b92508260ff1681518110611876576118766152b7565b6001600160e01b03199092166020928302919091019091015263b9b5b15360e01b826118a18361529a565b92508260ff16815181106118b7576118b76152b7565b6001600160e01b031990921660209283029190910190910152637e361b1160e01b826118e28361529a565b92508260ff16815181106118f8576118f86152b7565b6001600160e01b031990921660209283029190910190910152630cbb414760e11b826119238361529a565b92508260ff1681518110611939576119396152b7565b6001600160e01b031990921660209283029190910190910152631853304760e31b826119648361529a565b92508260ff168151811061197a5761197a6152b7565b6001600160e01b031990921660209283029190910190910152630ede4edd60e41b826119a58361529a565b92508260ff16815181106119bb576119bb6152b7565b6001600160e01b031990921660209283029190910190910152634ef4c3e160e01b826119e68361529a565b92508260ff16815181106119fc576119fc6152b7565b6001600160e01b03199092166020928302919091019091015263eabe7d9160e01b82611a278361529a565b92508260ff1681518110611a3d57611a3d6152b7565b6001600160e01b0319909216602092830291909101909101526351dff98960e01b82611a688361529a565b92508260ff1681518110611a7e57611a7e6152b7565b6001600160e01b03199092166020928302919091019091015263368f515360e21b82611aa98361529a565b92508260ff1681518110611abf57611abf6152b7565b6001600160e01b031990921660209283029190910190910152631de6c8a560e21b82611aea8361529a565b92508260ff1681518110611b0057611b006152b7565b6001600160e01b031990921660209283029190910190910152631200453160e11b82611b2b8361529a565b92508260ff1681518110611b4157611b416152b7565b6001600160e01b031990921660209283029190910190910152632fe3f38f60e11b82611b6c8361529a565b92508260ff1681518110611b8257611b826152b7565b6001600160e01b03199092166020928302919091019091015263d02f735160e01b82611bad8361529a565b92508260ff1681518110611bc357611bc36152b7565b6001600160e01b0319909216602092830291909101909101526317b9b84b60e31b82611bee8361529a565b92508260ff1681518110611c0457611c046152b7565b6001600160e01b0319909216602092830291909101909101526341c728b960e01b82611c2f8361529a565b92508260ff1681518110611c4557611c456152b7565b6001600160e01b031990921660209283029190910190910152635ec88c7960e01b82611c708361529a565b92508260ff1681518110611c8657611c866152b7565b6001600160e01b03199092166020928302919091019091015263c488847b60e01b82611cb18361529a565b92508260ff1681518110611cc757611cc76152b7565b6001600160e01b03199092166020928302919091019091015263c90c20b160e01b82611cf28361529a565b92508260ff1681518110611d0857611d086152b7565b6001600160e01b03199092166020928302919091019091015263319728a160e11b82611d338361529a565b92508260ff1681518110611d4957611d496152b7565b6001600160e01b031990921660209283029190910190910152632eb96f3160e11b82611d748361529a565b92508260ff1681518110611d8a57611d8a6152b7565b6001600160e01b03199092166020928302919091019091015260ff811615611df45760405162461bcd60e51b815260206004820152601c60248201527f7573652074686520636f7272656374206172726179206c656e677468000000006044820152606401610ad1565b5090565b6001600160a01b038116600090815260086020526040812060010154158015611e3e57506001600160a01b03821660009081526015602052604090205460ff1615156001145b8015610c395750611f52611f14836001600160a01b031663173b99046040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ead9190615226565b846001600160a01b0316638d02d9a16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0f9190615226565b61427c565b836001600160a01b031663c3bf11cd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eeb573d6000803e3d6000fd5b670de0b6b3a76400001492915050565b6000611f6c614080565b611f7c57610c39600160136140d4565b600f5460ff1615158215151415611f94576000610c39565b600f805460ff19168315159081179091556040519081527f84c7d948374a180eddab35d27d2f7a94167a1ff4e79467f1e89c061984190a1e906020015b60405180910390a16000610c39565b6001600160a01b038116600090815260076020908152604080832080548251818502810185019093528083526060949383018282801561204957602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161202b575b5093979650505050505050565b6000612060614080565b61207757612070600160166140d4565b9050610cef565b60028054600160a01b60ff60a01b1982168117909255600080546040516328f816b560e11b81529390920460ff169290916001600160a01b0316906351f02d6a906120ce908c908c908c908c908c906004016152f6565b6020604051808303816000875af11580156120ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121119190615326565b6002805460ff60a01b1916600160a01b8515150217905590506000612135826142b2565b905060008054906101000a90046001600160a01b03166001600160a01b0316638aac2f0c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612188573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ac9190615326565b604051635a89ef5160e01b81523060048201526001600160a01b039190911690635a89ef5190602401600060405180830381600087803b1580156121ef57600080fd5b505af1158015612203573d6000803e3d6000fd5b5060009250612210915050565b811461221c5780612226565b612226828661330c565b9a9950505050505050505050565b600061223e614080565b6122735760405162461bcd60e51b815260206004820152600660248201526510b0b236b4b760d11b6044820152606401610ad1565b816001600160a01b031663abc6d72d6040518163ffffffff1660e01b81526004016020604051808303816000875af11580156122b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d79190615343565b61231b5760405162461bcd60e51b815260206004820152601560248201527410b4b9a932bbb0b93239a234b9ba3934b13aba37b960591b6044820152606401610ad1565b60005b60195481101561239d576019818154811061233b5761233b6152b7565b6000918252602090912001546001600160a01b038481169116141561238b5760405162461bcd60e51b815260206004820152600660248201526508585919195960d21b6044820152606401610ad1565b8061239581615360565b91505061231e565b50601980546001810182556000919091527f944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c96950180546001600160a01b0319166001600160a01b0384169081179091556040519081527f98ef1187fb6fd2bc85f8996489877eb2b5428f9e9bdfc068c9ad6c2ea82eacc790602001611fd1565b601354600090600160b01b900460ff161561246c5760405162461bcd60e51b815260206004820152601060248201526f085d1c985b9cd9995c8e9c185d5cd95960821b6044820152606401610ad1565b60006124798686856144f9565b90508015612488579050610c17565b6124938686866145c1565b60009695505050505050565b60008054604051631beb2b9760e31b81526060926001600160a01b039092169163df595cb8916124e49130913391839190356001600160e01b0319169060040161537b565b602060405180830381865afa158015612501573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125259190615343565b6125625760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606401610ad1565b815160008167ffffffffffffffff81111561257f5761257f615062565b6040519080825280602002602001820160405280156125a8578160200160208202803683370190505b50905060005b8281101561261f5760008582815181106125ca576125ca6152b7565b602002602001015190506125de813361466c565b60148111156125ef576125ef61523f565b838381518110612601576126016152b7565b6020908102919091010152508061261781615360565b9150506125ae565b509150505b919050565b60035460405163fc57d4df60e01b81526001600160a01b038581166004830152600092839283929091169063fc57d4df90602401602060405180830381865afa15801561267a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061269e9190615226565b60035460405163fc57d4df60e01b81526001600160a01b0388811660048301529293506000929091169063fc57d4df90602401602060405180830381865afa1580156126ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127129190615226565b905081158061271f575080155b1561273357600c600093509350505061294d565b60008690506000816001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612778573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061279c9190615226565b905060006127b66040518060200160405280600081525090565b6040805160208101909152600081526040805160208101909152600081526000866001600160a01b0316636752e7026040518163ffffffff1660e01b8152600401602060405180830381865afa158015612814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128389190615226565b90506000876001600160a01b031663be99f1196040518163ffffffff1660e01b8152600401602060405180830381865afa15801561287a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061289e9190615226565b905060006128e16128cd6040518060200160405280600554815250604051806020016040528087815250614807565b604051806020016040528085815250614807565b90506128fb8160405180602001604052808e81525061483c565b955061292360405180602001604052808c81525060405180602001604052808b81525061483c565b945061292f868661487b565b935061293b848f614211565b60009d509b5050505050505050505050505b935093915050565b601981815481106110af57600080fd5b600061296f614080565b61297f57610c00600160146140d4565b60005b84811015612c0457600086868381811061299e5761299e6152b7565b90506020020160208101906129b39190614c62565b90508484838181106129c7576129c76152b7565b90506020020160208101906129dc9190614f31565b15612a94576001600160a01b03811660009081526010602052604090205460ff16612a8f576001600160a01b0381166000818152601060205260408120805460ff19166001908117909155601180548083018255928190527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6890920180546001600160a01b03191690931790925554612a75919061526b565b6001600160a01b0382166000908152601260205260409020555b612bf1565b6001600160a01b03811660009081526010602052604090205460ff1615612bf15760118054612ac59060019061526b565b81548110612ad557612ad56152b7565b60009182526020808320909101546001600160a01b0384811684526012909252604090922054601180549290931692918110612b1357612b136152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506011805480612b5257612b526153ae565b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b038316825260129081905260408220546011805491939184908110612ba657612ba66152b7565b60009182526020808320909101546001600160a01b039081168452838201949094526040928301822094909455918416825260128352808220829055601090925220805460ff191690555b5080612bfc81615360565b915050612982565b506000610c14565b3360009081526008602052604090205460ff16612c6b5760405162461bcd60e51b815260206004820181905260248201527f21436f6d7074726f6c6c65723a5f6265666f72654e6f6e5265656e7472616e746044820152606401610ad1565b601a5460ff16612caa5760405162461bcd60e51b815260206004820152600a602482015269085c99595b9d195c995960b21b6044820152606401610ad1565b601a805460ff19169055565b601354600090600160b81b900460ff1615612d035760405162461bcd60e51b815260206004820152600d60248201526c085cd95a5e994e9c185d5cd959609a1b6044820152606401610ad1565b6001600160a01b03861660009081526008602052604090205460ff161580612d4457506001600160a01b03851660009081526008602052604090205460ff16155b15612d50576008611233565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612db29190615326565b6001600160a01b0316866001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612df9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e1d9190615326565b6001600160a01b031614612e32576002611233565b6124938684866145c1565b601181815481106110af57600080fd5b6001600160a01b03831660009081526015602052604081205460ff1615612ea75760405162461bcd60e51b815260206004820152600e60248201526d08589bdc9c9bddce9c185d5cd95960921b6044820152606401610ad1565b6001600160a01b03841660009081526008602052604090205460ff16612ece576008610d74565b6001600160a01b038085166000908152600860209081526040808320938716835260029093019052205460ff16612fbd57336001600160a01b03851614612f415760405162461bcd60e51b815260206004820152600760248201526610b1ba37b5b2b760c91b6044820152606401610ad1565b6000612f4d338561466c565b90506000816014811115612f6357612f6361523f565b14612f8257806014811115612f7a57612f7a61523f565b915050610bd6565b6001600160a01b038086166000908152600860209081526040808320938816835260029093019052205460ff16612fbb57612fbb6153c4565b505b60035460405163fc57d4df60e01b81526001600160a01b0386811660048301529091169063fc57d4df90602401602060405180830381865afa158015613007573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061302b9190615226565b61303657600c610d74565b600f5460ff16801561306157506001600160a01b03831660009081526010602052604090205460ff16155b1561306d576011610d74565b6001600160a01b03841660009081526017602052604090205480158015906130b457506001600160a01b03851660009081526021602052604090206130b2908561414d565b155b156131f8576000856001600160a01b03166373acee986040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061311d9190615226565b9050600030604051631d3965af60e11b81526001600160a01b0389811660048301529190911690633a72cb5e90602401602060405180830381865afa15801561316a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318e9190615226565b905060008282106131a1575060006131ae565b6131ab828461526b565b90505b836131b98783615282565b106131f45760405162461bcd60e51b815260206004820152600b60248201526a021626f72726f773a6361760ac1b6044820152606401610ad1565b5050505b6132028585613fd8565b604051637e361b1160e01b81526001600160a01b0380861660048301528616602482015260006044820181905260648201859052608482018190529081903090637e361b119060a401608060405180830381865afa158015613268573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061328c91906153da565b935050509150600060148111156132a5576132a561523f565b82146132b557509150610bd69050565b80156132c75760049350505050610bd6565b6000979650505050505050565b600760205281600052604060002081815481106132f057600080fd5b6000918252602090912001546001600160a01b03169150829050565b6000613316614080565b61332d57613326600160096140d4565b9050610c39565b6001600160a01b0383166000908152600860205260409020805460ff166133625761335a6008600a6140d4565b915050610c39565b60408051602080820183528582528251908101909252670c7d713b49da000082529061339081835190511090565b156133ab576133a16006600b6140d4565b9350505050610c39565b8415801590613425575060035460405163fc57d4df60e01b81526001600160a01b0388811660048301529091169063fc57d4df90602401602060405180830381865afa1580156133ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134239190615226565b155b15613435576133a1600c806140d4565b60018301805490869055604080516001600160a01b0389168152602081018390529081018790527f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59060600160405180910390a16000979650505050505050565b6000806134a48585856144f9565b90508015610f3c579050610bd6565b60008054604051631beb2b9760e31b81526001600160a01b039091169063df595cb8906134f5903090339082906001600160e01b03198835169060040161537b565b602060405180830381865afa158015613512573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135369190615343565b6135735760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606401610ad1565b6001600160a01b03821660009081526008602052604090205460ff166135db5760405162461bcd60e51b815260206004820152601760248201527f21436f6d7074726f6c6c65723a657869744d61726b65740000000000000000006044820152606401610ad1565b6040516361bfb47160e11b81523360048201528290600090819081906001600160a01b0385169063c37f68e290602401608060405180830381865afa158015613628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061364c91906153da565b50925092509250826000146136915760405162461bcd60e51b815260206004820152600b60248201526a08595e1a5d13585c9ad95d60aa1b6044820152606401610ad1565b80156136a357610cef600b60036140d4565b60006136b08733856144f9565b905080156136d0576136c5600d6004836148b5565b979650505050505050565b6001600160a01b0387166000908152600860209081526040808320338452600281019092529091205460ff1661370e57600098975050505050505050565b3360009081526002820160209081526040808320805460ff19169055600782528083208054825181850281018501909352808352919290919083018282801561378057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613762575b5050835193945083925060009150505b828110156137e5578b6001600160a01b03168482815181106137b4576137b46152b7565b60200260200101516001600160a01b031614156137d3578091506137e5565b806137dd81615360565b915050613790565b508181106137f5576137f56153c4565b336000908152600760205260409020805481906138149060019061526b565b81548110613824576138246152b7565b9060005260206000200160009054906101000a90046001600160a01b0316818381548110613854576138546152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555080805480613892576138926153ae565b600082815260209020810160001990810180546001600160a01b031916905501905580546139e957600b80546138ca9060019061526b565b815481106138da576138da6152b7565b6000918252602080832090910154338352600c909152604090912054600b80546001600160a01b03909316929091908110613917576139176152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550600b805480613956576139566153ae565b60008281526020808220830160001990810180546001600160a01b0319169055909201909255338252600c908190526040822054600b8054919391849081106139a1576139a16152b7565b60009182526020808320909101546001600160a01b03168352828101939093526040918201812093909355338352600c8252808320839055600a9091529020805460ff191690555b604080516001600160a01b038e1681523360208201527fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d910160405180910390a160009c9b505050505050505050505050565b600080600080613a4a614b77565b6001600160a01b03891615613ace5760035460405163fc57d4df60e01b81526001600160a01b038b811660048301529091169063fc57d4df90602401602060405180830381865afa158015613aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ac79190615226565b6101808201525b60005b6001600160a01b038b16600090815260076020526040902054811015613e5b576001600160a01b038b166000908152600760205260409020805482908110613b1b57613b1b6152b7565b60009182526020822001546001600160a01b039081168085526040516361bfb47160e11b8152918e1660048301529063c37f68e290602401608060405180830381865afa158015613b70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b9491906153da565b60a08701526080860152606085015290508015613bc257600e600080600096509650965096505050506115d2565b50604080516020808201835284516001600160a01b0390811660009081526008835284902060010154835260e08601929092528251908101835260a085015181526101008501526003548451925163fc57d4df60e01b81529282166004840152169063fc57d4df90602401602060405180830381865afa158015613c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c6e9190615226565b60c08301819052613c8f57600c6000806000955095509550955050506115d2565b604080516020810190915260c0830151815261012083015260e0820151610100830151613cca91613cbf9161483c565b83610120015161483c565b610140830152308251604051633c1f884b60e11b81526001600160a01b0391821660048201528c821660248201528b151560448201528d8216606482015291169063783f109690608401602060405180830381865afa158015613d31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d559190615226565b6101a08301526101408201516060830151600091613d7291614211565b9050826101a00151811115613d8957506101a08201515b8083602001818151613d9b9190615282565b9052505061012082015160808301516040840151613dba92919061492d565b604083015281516001600160a01b038b811691161415613e4957613de88261014001518a846040015161492d565b60408301819052610120830151613e00918a9061492d565b6040830152610120820151600090613e189089614211565b905082604001518110613e315760006040840152613e47565b8083604001818151613e43919061526b565b9052505b505b80613e5381615360565b915050613ad1565b50806040015181602001511115613e94576020810151604082015160009190613e84908261526b565b60009450945094509450506115d2565b60008160200151600083602001518460400151613eb1919061526b565b9450945094509450506115d2565b600083613ece57506000610bd6565b60035460405163fc57d4df60e01b81526001600160a01b038581166004830152600092169063fc57d4df90602401602060405180830381865afa158015613f19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f3d9190615226565b905060008111613f795760405162461bcd60e51b8152602060048201526007602482015266216f7261636c6560c81b6044820152606401610ad1565b82613fbb576001600160a01b038416600090815260086020526040902060010154670de0b6b3a7640000613fad8383615410565b613fb7919061542f565b9150505b80613fce86670de0b6b3a7640000615410565b610ca1919061542f565b60005b60195481101561407b5760198181548110613ff857613ff86152b7565b600091825260209091200154604051631cdc2c5d60e31b81526001600160a01b03858116600483015284811660248301529091169063e6e162e890604401600060405180830381600087803b15801561405057600080fd5b505af1158015614064573d6000803e3d6000fd5b50505050808061407390615360565b915050613fdb565b505050565b6001546000906001600160a01b0316331480156140a65750600254600160a81b900460ff165b806140cf57506000546001600160a01b0316331480156140cf5750600254600160a01b900460ff165b905090565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08360148111156141095761410961523f565b83601a81111561411b5761411b61523f565b60408051928352602083019190915260009082015260600160405180910390a1826014811115610bd657610bd661523f565b6001600160a01b03811660009081526001830160205260408120541515610bd6565b60005b60195481101561407b576019818154811061418f5761418f6152b7565b60009182526020909120015460405162e48b0f60e51b81526001600160a01b038581166004830152848116602483015290911690631c9161e090604401600060405180830381600087803b1580156141e657600080fd5b505af11580156141fa573d6000803e3d6000fd5b50505050808061420990615360565b915050614172565b60008061421e848461494e565b9050610c1781614976565b600080600080614239868661498e565b909250905060008260038111156142525761425261523f565b146142635750915060009050614275565b600061426e82614976565b9350935050505b9250929050565b6000610bd68383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250614a0a565b60006142bc614080565b6142cc57610c39600160166140d4565b6001600160a01b03821660009081526008602052604090205460ff16156142f957610c39600960156140d4565b306001600160a01b0316826001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143659190615326565b6001600160a01b0316146143aa5760405162461bcd60e51b815260206004820152600c60248201526b10b1b7b6b83a3937b63632b960a11b6044820152606401610ad1565b6000826001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156143ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061440e9190615326565b6001600160a01b038082166000908152600e6020526040902054919250161561443d57610bd6600960156140d4565b6001600160a01b038381166000818152600860209081526040808320805460ff1916600190811782558082018590556009805491820190557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b031990811687179091559587168452600e835292819020805490951684179094559251918252917fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f910160405180910390a16000610c17565b6001600160a01b03831660009081526008602052604081205460ff16614520576008610d74565b6001600160a01b038085166000908152600860209081526040808320938716835260029093019052205460ff16614558576000610d74565b600080614569858786600080613a3c565b935050509150600060148111156145825761458261523f565b8260148111156145945761459461523f565b146145b4578160148111156145ab576145ab61523f565b92505050610bd6565b80156124935760046145ab565b60005b60195481101561109957601981815481106145e1576145e16152b7565b600091825260209091200154604051634e081c9560e01b81526001600160a01b0386811660048301528581166024830152848116604483015290911690634e081c9590606401600060405180830381600087803b15801561464157600080fd5b505af1158015614655573d6000803e3d6000fd5b50505050808061466490615360565b9150506145c4565b6001600160a01b0382166000908152600860205260408120805460ff16614697576008915050610c39565b6001600160a01b038316600090815260028201602052604090205460ff161515600114156146c9576000915050610c39565b6001600160a01b03838116600081815260028401602090815260408083208054600160ff199091168117909155600783528184208054918201815584528284200180546001600160a01b031916958a1695909517909455918152600a909152205460ff166147ba57600b8054600180820183557f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990910180546001600160a01b0319166001600160a01b0387169081179091556000908152600a60205260409020805460ff19168217905590546147a0919061526b565b6001600160a01b0384166000908152600c60205260409020555b604080516001600160a01b038087168252851660208201527f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a5910160405180910390a15060009392505050565b60408051602081019091526000815260405180602001604052806148338560000151856000015161427c565b90529392505050565b6040805160208101909152600081526040518060200160405280670de0b6b3a764000061487186600001518660000151614a44565b614833919061542f565b60408051602081019091526000815260405180602001604052806148336148ae8660000151670de0b6b3a7640000614a44565b8551614a86565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08460148111156148ea576148ea61523f565b84601a8111156148fc576148fc61523f565b604080519283526020830191909152810184905260600160405180910390a1836014811115610c1757610c1761523f565b60008061493a858561494e565b9050610ca161494882614976565b8461427c565b6040805160208101909152600081526040518060200160405280614833856000015185614a44565b8051600090610c3990670de0b6b3a76400009061542f565b60006149a66040518060200160405280600081525090565b6000806149b7866000015186614ab9565b909250905060008260038111156149d0576149d061523f565b146149ef57506040805160208101909152600081529092509050614275565b60408051602081019091529081526000969095509350505050565b600080614a178486615282565b90508285821015614a3b5760405162461bcd60e51b8152600401610ad19190615451565b50949350505050565b6000610bd683836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250614af8565b6000610bd683836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250614b4b565b60008083614acc57506000905080614275565b83830283614ada868361542f565b14614aed57600260009250925050614275565b600092509050614275565b6000831580614b05575082155b15614b1257506000610bd6565b6000614b1e8486615410565b905083614b2b868361542f565b148390614a3b5760405162461bcd60e51b8152600401610ad19190615451565b60008183614b6c5760405162461bcd60e51b8152600401610ad19190615451565b50610c17838561542f565b604051806101c0016040528060006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001614bd36040518060200160405280600081525090565b8152602001614bee6040518060200160405280600081525090565b8152602001614c096040518060200160405280600081525090565b8152602001614c246040518060200160405280600081525090565b81526020016000815260200160008152602001600081525090565b6001600160a01b0381168114614c5457600080fd5b50565b803561262481614c3f565b600060208284031215614c7457600080fd5b8135610bd681614c3f565b8015158114614c5457600080fd5b600080600060608486031215614ca257600080fd5b8335614cad81614c3f565b92506020840135614cbd81614c3f565b91506040840135614ccd81614c7f565b809150509250925092565b60008060408385031215614ceb57600080fd5b8235614cf681614c3f565b91506020830135614d0681614c3f565b809150509250929050565b60008060008060808587031215614d2757600080fd5b8435614d3281614c3f565b93506020850135614d4281614c3f565b92506040850135614d5281614c3f565b9396929550929360600135925050565b600060208284031215614d7457600080fd5b5035919050565b60008060008060808587031215614d9157600080fd5b8435614d9c81614c3f565b93506020850135614dac81614c3f565b93969395505050506040820135916060013590565b600080600060608486031215614dd657600080fd5b8335614de181614c3f565b92506020840135614df181614c3f565b929592945050506040919091013590565b600080600080600060a08688031215614e1a57600080fd5b8535614e2581614c3f565b94506020860135614e3581614c3f565b93506040860135614e4581614c3f565b92506060860135614e5581614c3f565b949793965091946080013592915050565b60008060408385031215614e7957600080fd5b8235614e8481614c3f565b946020939093013593505050565b600080600080600060a08688031215614eaa57600080fd5b8535614eb581614c3f565b94506020860135614ec581614c3f565b94979496505050506040830135926060810135926080909101359150565b6020808252825182820181905260009190848201906040850190845b81811015614f255783516001600160e01b03191683529284019291840191600101614eff565b50909695505050505050565b600060208284031215614f4357600080fd5b8135610bd681614c7f565b6020808252825182820181905260009190848201906040850190845b81811015614f255783516001600160a01b031683529284019291840191600101614f6a565b60008083601f840112614fa157600080fd5b50813567ffffffffffffffff811115614fb957600080fd5b60208301915083602082850101111561427557600080fd5b60008060008060008060808789031215614fea57600080fd5b863560ff81168114614ffb57600080fd5b9550602087013567ffffffffffffffff8082111561501857600080fd5b6150248a838b01614f8f565b9097509550604089013591508082111561503d57600080fd5b5061504a89828a01614f8f565b979a9699509497949695606090950135949350505050565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121561508b57600080fd5b823567ffffffffffffffff808211156150a357600080fd5b818501915085601f8301126150b757600080fd5b8135818111156150c9576150c9615062565b8060051b604051601f19603f830116810181811085821117156150ee576150ee615062565b60405291825284820192508381018501918883111561510c57600080fd5b938501935b828510156151315761512285614c57565b84529385019392850192615111565b98975050505050505050565b6020808252825182820181905260009190848201906040850190845b81811015614f2557835183529284019291840191600101615159565b60008083601f84011261518757600080fd5b50813567ffffffffffffffff81111561519f57600080fd5b6020830191508360208260051b850101111561427557600080fd5b600080600080604085870312156151d057600080fd5b843567ffffffffffffffff808211156151e857600080fd5b6151f488838901615175565b9096509450602087013591508082111561520d57600080fd5b5061521a87828801615175565b95989497509550505050565b60006020828403121561523857600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008282101561527d5761527d615255565b500390565b6000821982111561529557615295615255565b500190565b600060ff8216806152ad576152ad615255565b6000190192915050565b634e487b7160e01b600052603260045260246000fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60ff861681526060602082015260006153136060830186886152cd565b82810360408401526151318185876152cd565b60006020828403121561533857600080fd5b8151610bd681614c3f565b60006020828403121561535557600080fd5b8151610bd681614c7f565b600060001982141561537457615374615255565b5060010190565b6001600160a01b0394851681529284166020840152921660408201526001600160e01b0319909116606082015260800190565b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052600160045260246000fd5b600080600080608085870312156153f057600080fd5b505082516020840151604085015160609095015191969095509092509050565b600081600019048311821515161561542a5761542a615255565b500290565b60008261544c57634e487b7160e01b600052601260045260246000fd5b500490565b600060208083528351808285015260005b8181101561547e57858101830151858201604001528201615462565b81811115615490576000604083870101525b50601f01601f191692909201604001939250505056fea2646970667358221220767c1ff16851be58a8c5ad1f66422f8cb25f1dfeb02c516a0459e7bedf9c56b864736f6c634300080a0033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103c45760003560e01c80637e361b11116101ff578063c488847b1161011a578063da3d454c116100ad578063e87554461161007c578063e8755446146109a6578063eabe7d91146109af578063ede4edd0146109c2578063f851a440146109d557600080fd5b8063da3d454c14610959578063dce154491461096c578063e4028eee1461097f578063e6653f3d1461099257600080fd5b8063c91a424f116100e9578063c91a424f1461090c578063cf6bfd2d1461091f578063d02f735114610933578063d251fefc1461094657600080fd5b8063c488847b146108b6578063c6c5b0dd146108de578063c8c9c975146108f1578063c90c20b11461090457600080fd5b80639b19251a11610192578063b452ef6211610161578063b452ef621461085d578063b9b5b15314610870578063bdcdc25814610883578063c29982381461089657600080fd5b80639b19251a146107f9578063abfceffc1461081c578063ac0b0bb71461083c578063b09572101461085057600080fd5b8063929fe9a1116101ce578063929fe9a114610767578063940cd6f1146107a857806394543c15146107d3578063952adf5a146107e657600080fd5b80637e361b11146106e757806387f76303146106fa57806389f8132e1461070e5780638e8f294b1461072357600080fd5b80634ada90af116102ef5780635fc7e71e11610282578063731f0c2b11610251578063731f0c2b1461068b5780637515bafa146106ae578063779b2294146106c15780637dc0d1d0146106d457600080fd5b80635fc7e71e1461063a578063632e51421461064d5780636bd02b8a146106555780636d154ea51461066857600080fd5b806352d84d1e116102be57806352d84d1e146105d957806355ee1fe1146105ec5780635d72de62146105ff5780635ec88c791461060757600080fd5b80634ada90af146105975780634ef4c3e1146105a05780634fd42e17146105b357806351dff989146105c657600080fd5b806324008a621161036757806331ff47fa1161033657806331ff47fa146105035780633c94786f1461052c57806341c728b9146105405780634a5844321461057757600080fd5b806324008a62146104b757806324a3d622146104ca57806326782247146104dd578063317b0b77146104f057600080fd5b806316dc15fe116103a357806316dc15fe146104285780631976828e1461044b5780631c819e431461045e57806321af45691461048c57600080fd5b80627e3dd2146103c957806302c3bcbb146103e65780630a755ec214610414575b600080fd5b6103d1600181565b60405190151581526020015b60405180910390f35b6104066103f4366004614c62565b60186020526000908152604090205481565b6040519081526020016103dd565b6002546103d190600160a81b900460ff1681565b6103d1610436366004614c62565b600d6020526000908152604090205460ff1681565b610406610459366004614c8d565b6109e8565b6103d161046c366004614cd8565b601d60209081526000928352604080842090915290825290205460ff1681565b60165461049f906001600160a01b031681565b6040516001600160a01b0390911681526020016103dd565b6104066104c5366004614d11565b610bdd565b60135461049f906001600160a01b031681565b60025461049f906001600160a01b031681565b6104066104fe366004614d62565b610c1f565b61049f610511366004614c62565b600e602052600090815260409020546001600160a01b031681565b6013546103d190600160a01b900460ff1681565b61057561054e366004614d7b565b50506001600160a01b03166000908152600d60205260409020805460ff1916600117905550565b005b610406610585366004614c62565b60176020526000908152604090205481565b61040660055481565b6104066105ae366004614dc1565b610cf9565b6104066105c1366004614d62565b610f51565b6105756105d4366004614d7b565b61100d565b61049f6105e7366004614d62565b61109f565b6104066105fa366004614c62565b6110c9565b610575611149565b61061a610615366004614c62565b6111a6565b6040805194855260208501939093529183015260608201526080016103dd565b610406610648366004614e02565b6111ea565b6105756113ab565b61049f610663366004614d62565b611419565b6103d1610676366004614c62565b60156020526000908152604090205460ff1681565b6103d1610699366004614c62565b60146020526000908152604090205460ff1681565b61049f6106bc366004614d62565b611429565b6104066106cf366004614e66565b611439565b60035461049f906001600160a01b031681565b61061a6106f5366004614e92565b611594565b6013546103d190600160b01b900460ff1681565b6107166115de565b6040516103dd9190614ee3565b610750610731366004614c62565b6008602052600090815260409020805460019091015460ff9091169082565b6040805192151583526020830191909152016103dd565b6103d1610775366004614cd8565b6001600160a01b038082166000908152600860209081526040808320938616835260029093019052205460ff1692915050565b6104066107b6366004614cd8565b601c60209081526000928352604080842090915290825290205481565b6103d16107e1366004614c62565b611df8565b6104066107f4366004614f31565b611f62565b6103d1610807366004614c62565b60106020526000908152604090205460ff1681565b61082f61082a366004614c62565b611fe0565b6040516103dd9190614f4e565b6013546103d190600160b81b900460ff1681565b600f546103d19060ff1681565b61040661086b366004614fd1565b612056565b61040661087e366004614c62565b612234565b610406610891366004614d11565b61241c565b6108a96108a4366004615078565b61249f565b6040516103dd919061513d565b6108c96108c4366004614dc1565b612629565b604080519283526020830191909152016103dd565b61049f6108ec366004614d62565b612955565b6104066108ff3660046151ba565b612965565b610575612c0c565b60005461049f906001600160a01b031681565b6002546103d190600160a01b900460ff1681565b610406610941366004614e02565b612cb6565b61049f610954366004614d62565b612e3d565b610406610967366004614dc1565b612e4d565b61049f61097a366004614e66565b6132d4565b61040661098d366004614e66565b61330c565b6013546103d190600160a81b900460ff1681565b61040660045481565b6104066109bd366004614dc1565b613496565b6104066109d0366004614c62565b6134b3565b60015461049f906001600160a01b031681565b604051633af9e66960e01b81526001600160a01b0384811660048301526000918491839190831690633af9e66990602401602060405180830381865afa158015610a36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a5a9190615226565b90506000806000610a7d8988610a71576000610a73565b895b6000806000613a3c565b929550935090915060009050836014811115610a9b57610a9b61523f565b14610ada5760405162461bcd60e51b815260206004820152600a602482015269216c697175696469747960b01b60448201526064015b60405180910390fd5b8015610aee57600095505050505050610bd6565b600087158015610b2857506001600160a01b038087166000908152600860209081526040808320938e16835260029093019052205460ff16155b15610b34575083610b56565b610b3f838a8a613ebf565b905087158015610b4e57508085105b15610b565750835b6000896001600160a01b0316633b1d21a26040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bba9190615226565b905080821115610bca5780610bcc565b815b9750505050505050505b9392505050565b6001600160a01b03841660009081526008602052604081205460ff16610c075760085b9050610c17565b610c118584613fd8565b60005b90505b949350505050565b6000610c29614080565b610c3f57610c39600160076140d4565b92915050565b6040805160208082018352848252825190810190925266b1a2bc2ec50000808352815191929111610c7657610c17600560086140d4565b6040805160208101909152670c7d713b49da000080825283511115610caa57610ca1600560086140d4565b95945050505050565b600480549086905560408051828152602081018890527f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd991015b60405180910390a160005b9695505050505050565b6001600160a01b03831660009081526014602052604081205460ff1615610d515760405162461bcd60e51b815260206004820152600c60248201526b085b5a5b9d0e9c185d5cd95960a21b6044820152606401610ad1565b6001600160a01b03841660009081526008602052604090205460ff16610d7b5760085b9050610bd6565b600f5460ff168015610da657506001600160a01b03831660009081526010602052604090205460ff16155b15610db2576011610d74565b6001600160a01b0384166000908152601860205260409020548015801590610df857506001600160a01b03851660009081526020805260409020610df6908561414d565b155b15610f3c576000856001600160a01b0316634aeb3d9a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e619190615226565b9050600030604051637db121fd60e11b81526001600160a01b038981166004830152919091169063fb6243fa90602401602060405180830381865afa158015610eae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed29190615226565b90506000828210610ee557506000610ef2565b610eef828461526b565b90505b83610efd8783615282565b10610f385760405162461bcd60e51b815260206004820152600b60248201526a021737570706c79206361760ac1b6044820152606401610ad1565b5050505b610f46858561416f565b600095945050505050565b6000610f5b614080565b610f6b57610c396001600d6140d4565b60408051602080820183528482528251908101909252670de0b6b3a764000080835281519192911015610fa457610c176007600e6140d4565b60408051602081019091526714d1120d7b16000080825283511115610fcf57610ca16007600e6140d4565b600580549086905560408051828152602081018890527faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec13169101610ce4565b3360009081526008602052604090205460ff166110565760405162461bcd60e51b8152602060048201526007602482015266085b585c9ad95d60ca1b6044820152606401610ad1565b801580156110645750600082115b156110995760405162461bcd60e51b8152602060048201526005602482015264217a65726f60d81b6044820152606401610ad1565b50505050565b600981815481106110af57600080fd5b6000918252602090912001546001600160a01b0316905081565b60006110d3614080565b6110e357610c39600160126140d4565b600380546001600160a01b038481166001600160a01b031983168117909355604080519190921680825260208201939093527fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22910160405180910390a160009392505050565b3330146111855760405162461bcd60e51b815260206004820152600a602482015269085cd95b198818d85b1b60b21b6044820152606401610ad1565b601a54610100900460ff166111a457601a805461ffff19166101011790555b565b6000806000806000806000806111c189600080600080613a3c565b93509350935093508360148111156111db576111db61523f565b99929850909650945092505050565b6001600160a01b03851660009081526008602052604081205460ff16158061122b57506001600160a01b03851660009081526008602052604090205460ff16155b1561123a5760085b9050610ca1565b6040516305eff7ef60e21b81526001600160a01b038481166004830152600091908816906317bfdfbc90602401602060405180830381865afa158015611284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a89190615226565b90506112b387611df8565b156112fd57828110156112f85760405162461bcd60e51b815260206004820152600d60248201526c21626f72726f773e726570617960981b6044820152606401610ad1565b61139e565b60008061130f86600080600080613a3c565b935050509150600060148111156113285761132861523f565b82601481111561133a5761133a61523f565b1461135b578160148111156113515761135161523f565b9350505050610ca1565b80611367576003611351565b6000611383604051806020016040528060045481525085614211565b90508086111561139a576010945050505050610ca1565b5050505b5060009695505050505050565b3360009081526008602052604090205460ff1661140a5760405162461bcd60e51b815260206004820152601f60248201527f21436f6d7074726f6c6c65723a5f61667465724e6f6e5265656e7472616e74006044820152606401610ad1565b601a805460ff19166001179055565b601b81815481106110af57600080fd5b600b81815481106110af57600080fd5b600080546040805163fdb25fb160e01b8152905183926001600160a01b03169163fdb25fb19160048083019260209291908290030181865afa158015611483573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a79190615226565b9050801561158a5760035460405163fc57d4df60e01b81526001600160a01b038681166004830152600092169063fc57d4df90602401602060405180830381865afa1580156114fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061151e9190615226565b90508061153057600c92505050610c39565b60008061154b60405180602001604052808581525087614229565b909250905060008260038111156115645761156461523f565b1461157757600a5b945050505050610c39565b8381101561158657601261156c565b5050505b6000949350505050565b6000806000806000806000806115ad8d8d8d8d8d613a3c565b93509350935093508360148111156115c7576115c761523f565b975091955093509150505b95509550955095915050565b60408051601e8082526103e082019092526060919081602082016103c0803683370190505091506394543c1560e01b826116178361529a565b92508260ff168151811061162d5761162d6152b7565b6001600160e01b031990921660209283029190910190910152635a2977b160e11b826116588361529a565b92508260ff168151811061166e5761166e6152b7565b6001600160e01b031990921660209283029190910190910152632aff3bff60e21b826116998361529a565b92508260ff16815181106116af576116af6152b7565b6001600160e01b03199092166020928302919091019091015263929fe9a160e01b826116da8361529a565b92508260ff16815181106116f0576116f06152b7565b6001600160e01b0319909216602092830291909101909101526355ee1fe160e01b8261171b8361529a565b92508260ff1681518110611731576117316152b7565b6001600160e01b03199092166020928302919091019091015263317b0b7760e01b8261175c8361529a565b92508260ff1681518110611772576117726152b7565b6001600160e01b031990921660209283029190910190910152637201477760e11b8261179d8361529a565b92508260ff16815181106117b3576117b36152b7565b6001600160e01b031990921660209283029190910190910152634fd42e1760e01b826117de8361529a565b92508260ff16815181106117f4576117f46152b7565b6001600160e01b031990921660209283029190910190910152634a956fad60e11b8261181f8361529a565b92508260ff1681518110611835576118356152b7565b6001600160e01b03199092166020928302919091019091015263c8c9c97560e01b826118608361529a565b92508260ff1681518110611876576118766152b7565b6001600160e01b03199092166020928302919091019091015263b9b5b15360e01b826118a18361529a565b92508260ff16815181106118b7576118b76152b7565b6001600160e01b031990921660209283029190910190910152637e361b1160e01b826118e28361529a565b92508260ff16815181106118f8576118f86152b7565b6001600160e01b031990921660209283029190910190910152630cbb414760e11b826119238361529a565b92508260ff1681518110611939576119396152b7565b6001600160e01b031990921660209283029190910190910152631853304760e31b826119648361529a565b92508260ff168151811061197a5761197a6152b7565b6001600160e01b031990921660209283029190910190910152630ede4edd60e41b826119a58361529a565b92508260ff16815181106119bb576119bb6152b7565b6001600160e01b031990921660209283029190910190910152634ef4c3e160e01b826119e68361529a565b92508260ff16815181106119fc576119fc6152b7565b6001600160e01b03199092166020928302919091019091015263eabe7d9160e01b82611a278361529a565b92508260ff1681518110611a3d57611a3d6152b7565b6001600160e01b0319909216602092830291909101909101526351dff98960e01b82611a688361529a565b92508260ff1681518110611a7e57611a7e6152b7565b6001600160e01b03199092166020928302919091019091015263368f515360e21b82611aa98361529a565b92508260ff1681518110611abf57611abf6152b7565b6001600160e01b031990921660209283029190910190910152631de6c8a560e21b82611aea8361529a565b92508260ff1681518110611b0057611b006152b7565b6001600160e01b031990921660209283029190910190910152631200453160e11b82611b2b8361529a565b92508260ff1681518110611b4157611b416152b7565b6001600160e01b031990921660209283029190910190910152632fe3f38f60e11b82611b6c8361529a565b92508260ff1681518110611b8257611b826152b7565b6001600160e01b03199092166020928302919091019091015263d02f735160e01b82611bad8361529a565b92508260ff1681518110611bc357611bc36152b7565b6001600160e01b0319909216602092830291909101909101526317b9b84b60e31b82611bee8361529a565b92508260ff1681518110611c0457611c046152b7565b6001600160e01b0319909216602092830291909101909101526341c728b960e01b82611c2f8361529a565b92508260ff1681518110611c4557611c456152b7565b6001600160e01b031990921660209283029190910190910152635ec88c7960e01b82611c708361529a565b92508260ff1681518110611c8657611c866152b7565b6001600160e01b03199092166020928302919091019091015263c488847b60e01b82611cb18361529a565b92508260ff1681518110611cc757611cc76152b7565b6001600160e01b03199092166020928302919091019091015263c90c20b160e01b82611cf28361529a565b92508260ff1681518110611d0857611d086152b7565b6001600160e01b03199092166020928302919091019091015263319728a160e11b82611d338361529a565b92508260ff1681518110611d4957611d496152b7565b6001600160e01b031990921660209283029190910190910152632eb96f3160e11b82611d748361529a565b92508260ff1681518110611d8a57611d8a6152b7565b6001600160e01b03199092166020928302919091019091015260ff811615611df45760405162461bcd60e51b815260206004820152601c60248201527f7573652074686520636f7272656374206172726179206c656e677468000000006044820152606401610ad1565b5090565b6001600160a01b038116600090815260086020526040812060010154158015611e3e57506001600160a01b03821660009081526015602052604090205460ff1615156001145b8015610c395750611f52611f14836001600160a01b031663173b99046040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ead9190615226565b846001600160a01b0316638d02d9a16040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0f9190615226565b61427c565b836001600160a01b031663c3bf11cd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eeb573d6000803e3d6000fd5b670de0b6b3a76400001492915050565b6000611f6c614080565b611f7c57610c39600160136140d4565b600f5460ff1615158215151415611f94576000610c39565b600f805460ff19168315159081179091556040519081527f84c7d948374a180eddab35d27d2f7a94167a1ff4e79467f1e89c061984190a1e906020015b60405180910390a16000610c39565b6001600160a01b038116600090815260076020908152604080832080548251818502810185019093528083526060949383018282801561204957602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161202b575b5093979650505050505050565b6000612060614080565b61207757612070600160166140d4565b9050610cef565b60028054600160a01b60ff60a01b1982168117909255600080546040516328f816b560e11b81529390920460ff169290916001600160a01b0316906351f02d6a906120ce908c908c908c908c908c906004016152f6565b6020604051808303816000875af11580156120ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121119190615326565b6002805460ff60a01b1916600160a01b8515150217905590506000612135826142b2565b905060008054906101000a90046001600160a01b03166001600160a01b0316638aac2f0c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612188573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ac9190615326565b604051635a89ef5160e01b81523060048201526001600160a01b039190911690635a89ef5190602401600060405180830381600087803b1580156121ef57600080fd5b505af1158015612203573d6000803e3d6000fd5b5060009250612210915050565b811461221c5780612226565b612226828661330c565b9a9950505050505050505050565b600061223e614080565b6122735760405162461bcd60e51b815260206004820152600660248201526510b0b236b4b760d11b6044820152606401610ad1565b816001600160a01b031663abc6d72d6040518163ffffffff1660e01b81526004016020604051808303816000875af11580156122b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d79190615343565b61231b5760405162461bcd60e51b815260206004820152601560248201527410b4b9a932bbb0b93239a234b9ba3934b13aba37b960591b6044820152606401610ad1565b60005b60195481101561239d576019818154811061233b5761233b6152b7565b6000918252602090912001546001600160a01b038481169116141561238b5760405162461bcd60e51b815260206004820152600660248201526508585919195960d21b6044820152606401610ad1565b8061239581615360565b91505061231e565b50601980546001810182556000919091527f944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c96950180546001600160a01b0319166001600160a01b0384169081179091556040519081527f98ef1187fb6fd2bc85f8996489877eb2b5428f9e9bdfc068c9ad6c2ea82eacc790602001611fd1565b601354600090600160b01b900460ff161561246c5760405162461bcd60e51b815260206004820152601060248201526f085d1c985b9cd9995c8e9c185d5cd95960821b6044820152606401610ad1565b60006124798686856144f9565b90508015612488579050610c17565b6124938686866145c1565b60009695505050505050565b60008054604051631beb2b9760e31b81526060926001600160a01b039092169163df595cb8916124e49130913391839190356001600160e01b0319169060040161537b565b602060405180830381865afa158015612501573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125259190615343565b6125625760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606401610ad1565b815160008167ffffffffffffffff81111561257f5761257f615062565b6040519080825280602002602001820160405280156125a8578160200160208202803683370190505b50905060005b8281101561261f5760008582815181106125ca576125ca6152b7565b602002602001015190506125de813361466c565b60148111156125ef576125ef61523f565b838381518110612601576126016152b7565b6020908102919091010152508061261781615360565b9150506125ae565b509150505b919050565b60035460405163fc57d4df60e01b81526001600160a01b038581166004830152600092839283929091169063fc57d4df90602401602060405180830381865afa15801561267a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061269e9190615226565b60035460405163fc57d4df60e01b81526001600160a01b0388811660048301529293506000929091169063fc57d4df90602401602060405180830381865afa1580156126ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127129190615226565b905081158061271f575080155b1561273357600c600093509350505061294d565b60008690506000816001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612778573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061279c9190615226565b905060006127b66040518060200160405280600081525090565b6040805160208101909152600081526040805160208101909152600081526000866001600160a01b0316636752e7026040518163ffffffff1660e01b8152600401602060405180830381865afa158015612814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128389190615226565b90506000876001600160a01b031663be99f1196040518163ffffffff1660e01b8152600401602060405180830381865afa15801561287a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061289e9190615226565b905060006128e16128cd6040518060200160405280600554815250604051806020016040528087815250614807565b604051806020016040528085815250614807565b90506128fb8160405180602001604052808e81525061483c565b955061292360405180602001604052808c81525060405180602001604052808b81525061483c565b945061292f868661487b565b935061293b848f614211565b60009d509b5050505050505050505050505b935093915050565b601981815481106110af57600080fd5b600061296f614080565b61297f57610c00600160146140d4565b60005b84811015612c0457600086868381811061299e5761299e6152b7565b90506020020160208101906129b39190614c62565b90508484838181106129c7576129c76152b7565b90506020020160208101906129dc9190614f31565b15612a94576001600160a01b03811660009081526010602052604090205460ff16612a8f576001600160a01b0381166000818152601060205260408120805460ff19166001908117909155601180548083018255928190527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c6890920180546001600160a01b03191690931790925554612a75919061526b565b6001600160a01b0382166000908152601260205260409020555b612bf1565b6001600160a01b03811660009081526010602052604090205460ff1615612bf15760118054612ac59060019061526b565b81548110612ad557612ad56152b7565b60009182526020808320909101546001600160a01b0384811684526012909252604090922054601180549290931692918110612b1357612b136152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506011805480612b5257612b526153ae565b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b038316825260129081905260408220546011805491939184908110612ba657612ba66152b7565b60009182526020808320909101546001600160a01b039081168452838201949094526040928301822094909455918416825260128352808220829055601090925220805460ff191690555b5080612bfc81615360565b915050612982565b506000610c14565b3360009081526008602052604090205460ff16612c6b5760405162461bcd60e51b815260206004820181905260248201527f21436f6d7074726f6c6c65723a5f6265666f72654e6f6e5265656e7472616e746044820152606401610ad1565b601a5460ff16612caa5760405162461bcd60e51b815260206004820152600a602482015269085c99595b9d195c995960b21b6044820152606401610ad1565b601a805460ff19169055565b601354600090600160b81b900460ff1615612d035760405162461bcd60e51b815260206004820152600d60248201526c085cd95a5e994e9c185d5cd959609a1b6044820152606401610ad1565b6001600160a01b03861660009081526008602052604090205460ff161580612d4457506001600160a01b03851660009081526008602052604090205460ff16155b15612d50576008611233565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612db29190615326565b6001600160a01b0316866001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612df9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e1d9190615326565b6001600160a01b031614612e32576002611233565b6124938684866145c1565b601181815481106110af57600080fd5b6001600160a01b03831660009081526015602052604081205460ff1615612ea75760405162461bcd60e51b815260206004820152600e60248201526d08589bdc9c9bddce9c185d5cd95960921b6044820152606401610ad1565b6001600160a01b03841660009081526008602052604090205460ff16612ece576008610d74565b6001600160a01b038085166000908152600860209081526040808320938716835260029093019052205460ff16612fbd57336001600160a01b03851614612f415760405162461bcd60e51b815260206004820152600760248201526610b1ba37b5b2b760c91b6044820152606401610ad1565b6000612f4d338561466c565b90506000816014811115612f6357612f6361523f565b14612f8257806014811115612f7a57612f7a61523f565b915050610bd6565b6001600160a01b038086166000908152600860209081526040808320938816835260029093019052205460ff16612fbb57612fbb6153c4565b505b60035460405163fc57d4df60e01b81526001600160a01b0386811660048301529091169063fc57d4df90602401602060405180830381865afa158015613007573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061302b9190615226565b61303657600c610d74565b600f5460ff16801561306157506001600160a01b03831660009081526010602052604090205460ff16155b1561306d576011610d74565b6001600160a01b03841660009081526017602052604090205480158015906130b457506001600160a01b03851660009081526021602052604090206130b2908561414d565b155b156131f8576000856001600160a01b03166373acee986040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061311d9190615226565b9050600030604051631d3965af60e11b81526001600160a01b0389811660048301529190911690633a72cb5e90602401602060405180830381865afa15801561316a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318e9190615226565b905060008282106131a1575060006131ae565b6131ab828461526b565b90505b836131b98783615282565b106131f45760405162461bcd60e51b815260206004820152600b60248201526a021626f72726f773a6361760ac1b6044820152606401610ad1565b5050505b6132028585613fd8565b604051637e361b1160e01b81526001600160a01b0380861660048301528616602482015260006044820181905260648201859052608482018190529081903090637e361b119060a401608060405180830381865afa158015613268573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061328c91906153da565b935050509150600060148111156132a5576132a561523f565b82146132b557509150610bd69050565b80156132c75760049350505050610bd6565b6000979650505050505050565b600760205281600052604060002081815481106132f057600080fd5b6000918252602090912001546001600160a01b03169150829050565b6000613316614080565b61332d57613326600160096140d4565b9050610c39565b6001600160a01b0383166000908152600860205260409020805460ff166133625761335a6008600a6140d4565b915050610c39565b60408051602080820183528582528251908101909252670c7d713b49da000082529061339081835190511090565b156133ab576133a16006600b6140d4565b9350505050610c39565b8415801590613425575060035460405163fc57d4df60e01b81526001600160a01b0388811660048301529091169063fc57d4df90602401602060405180830381865afa1580156133ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134239190615226565b155b15613435576133a1600c806140d4565b60018301805490869055604080516001600160a01b0389168152602081018390529081018790527f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59060600160405180910390a16000979650505050505050565b6000806134a48585856144f9565b90508015610f3c579050610bd6565b60008054604051631beb2b9760e31b81526001600160a01b039091169063df595cb8906134f5903090339082906001600160e01b03198835169060040161537b565b602060405180830381865afa158015613512573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135369190615343565b6135735760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606401610ad1565b6001600160a01b03821660009081526008602052604090205460ff166135db5760405162461bcd60e51b815260206004820152601760248201527f21436f6d7074726f6c6c65723a657869744d61726b65740000000000000000006044820152606401610ad1565b6040516361bfb47160e11b81523360048201528290600090819081906001600160a01b0385169063c37f68e290602401608060405180830381865afa158015613628573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061364c91906153da565b50925092509250826000146136915760405162461bcd60e51b815260206004820152600b60248201526a08595e1a5d13585c9ad95d60aa1b6044820152606401610ad1565b80156136a357610cef600b60036140d4565b60006136b08733856144f9565b905080156136d0576136c5600d6004836148b5565b979650505050505050565b6001600160a01b0387166000908152600860209081526040808320338452600281019092529091205460ff1661370e57600098975050505050505050565b3360009081526002820160209081526040808320805460ff19169055600782528083208054825181850281018501909352808352919290919083018282801561378057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311613762575b5050835193945083925060009150505b828110156137e5578b6001600160a01b03168482815181106137b4576137b46152b7565b60200260200101516001600160a01b031614156137d3578091506137e5565b806137dd81615360565b915050613790565b508181106137f5576137f56153c4565b336000908152600760205260409020805481906138149060019061526b565b81548110613824576138246152b7565b9060005260206000200160009054906101000a90046001600160a01b0316818381548110613854576138546152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555080805480613892576138926153ae565b600082815260209020810160001990810180546001600160a01b031916905501905580546139e957600b80546138ca9060019061526b565b815481106138da576138da6152b7565b6000918252602080832090910154338352600c909152604090912054600b80546001600160a01b03909316929091908110613917576139176152b7565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550600b805480613956576139566153ae565b60008281526020808220830160001990810180546001600160a01b0319169055909201909255338252600c908190526040822054600b8054919391849081106139a1576139a16152b7565b60009182526020808320909101546001600160a01b03168352828101939093526040918201812093909355338352600c8252808320839055600a9091529020805460ff191690555b604080516001600160a01b038e1681523360208201527fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d910160405180910390a160009c9b505050505050505050505050565b600080600080613a4a614b77565b6001600160a01b03891615613ace5760035460405163fc57d4df60e01b81526001600160a01b038b811660048301529091169063fc57d4df90602401602060405180830381865afa158015613aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ac79190615226565b6101808201525b60005b6001600160a01b038b16600090815260076020526040902054811015613e5b576001600160a01b038b166000908152600760205260409020805482908110613b1b57613b1b6152b7565b60009182526020822001546001600160a01b039081168085526040516361bfb47160e11b8152918e1660048301529063c37f68e290602401608060405180830381865afa158015613b70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b9491906153da565b60a08701526080860152606085015290508015613bc257600e600080600096509650965096505050506115d2565b50604080516020808201835284516001600160a01b0390811660009081526008835284902060010154835260e08601929092528251908101835260a085015181526101008501526003548451925163fc57d4df60e01b81529282166004840152169063fc57d4df90602401602060405180830381865afa158015613c4a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c6e9190615226565b60c08301819052613c8f57600c6000806000955095509550955050506115d2565b604080516020810190915260c0830151815261012083015260e0820151610100830151613cca91613cbf9161483c565b83610120015161483c565b610140830152308251604051633c1f884b60e11b81526001600160a01b0391821660048201528c821660248201528b151560448201528d8216606482015291169063783f109690608401602060405180830381865afa158015613d31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d559190615226565b6101a08301526101408201516060830151600091613d7291614211565b9050826101a00151811115613d8957506101a08201515b8083602001818151613d9b9190615282565b9052505061012082015160808301516040840151613dba92919061492d565b604083015281516001600160a01b038b811691161415613e4957613de88261014001518a846040015161492d565b60408301819052610120830151613e00918a9061492d565b6040830152610120820151600090613e189089614211565b905082604001518110613e315760006040840152613e47565b8083604001818151613e43919061526b565b9052505b505b80613e5381615360565b915050613ad1565b50806040015181602001511115613e94576020810151604082015160009190613e84908261526b565b60009450945094509450506115d2565b60008160200151600083602001518460400151613eb1919061526b565b9450945094509450506115d2565b600083613ece57506000610bd6565b60035460405163fc57d4df60e01b81526001600160a01b038581166004830152600092169063fc57d4df90602401602060405180830381865afa158015613f19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f3d9190615226565b905060008111613f795760405162461bcd60e51b8152602060048201526007602482015266216f7261636c6560c81b6044820152606401610ad1565b82613fbb576001600160a01b038416600090815260086020526040902060010154670de0b6b3a7640000613fad8383615410565b613fb7919061542f565b9150505b80613fce86670de0b6b3a7640000615410565b610ca1919061542f565b60005b60195481101561407b5760198181548110613ff857613ff86152b7565b600091825260209091200154604051631cdc2c5d60e31b81526001600160a01b03858116600483015284811660248301529091169063e6e162e890604401600060405180830381600087803b15801561405057600080fd5b505af1158015614064573d6000803e3d6000fd5b50505050808061407390615360565b915050613fdb565b505050565b6001546000906001600160a01b0316331480156140a65750600254600160a81b900460ff165b806140cf57506000546001600160a01b0316331480156140cf5750600254600160a01b900460ff165b905090565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08360148111156141095761410961523f565b83601a81111561411b5761411b61523f565b60408051928352602083019190915260009082015260600160405180910390a1826014811115610bd657610bd661523f565b6001600160a01b03811660009081526001830160205260408120541515610bd6565b60005b60195481101561407b576019818154811061418f5761418f6152b7565b60009182526020909120015460405162e48b0f60e51b81526001600160a01b038581166004830152848116602483015290911690631c9161e090604401600060405180830381600087803b1580156141e657600080fd5b505af11580156141fa573d6000803e3d6000fd5b50505050808061420990615360565b915050614172565b60008061421e848461494e565b9050610c1781614976565b600080600080614239868661498e565b909250905060008260038111156142525761425261523f565b146142635750915060009050614275565b600061426e82614976565b9350935050505b9250929050565b6000610bd68383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250614a0a565b60006142bc614080565b6142cc57610c39600160166140d4565b6001600160a01b03821660009081526008602052604090205460ff16156142f957610c39600960156140d4565b306001600160a01b0316826001600160a01b0316635fe3b5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143659190615326565b6001600160a01b0316146143aa5760405162461bcd60e51b815260206004820152600c60248201526b10b1b7b6b83a3937b63632b960a11b6044820152606401610ad1565b6000826001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156143ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061440e9190615326565b6001600160a01b038082166000908152600e6020526040902054919250161561443d57610bd6600960156140d4565b6001600160a01b038381166000818152600860209081526040808320805460ff1916600190811782558082018590556009805491820190557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b031990811687179091559587168452600e835292819020805490951684179094559251918252917fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f910160405180910390a16000610c17565b6001600160a01b03831660009081526008602052604081205460ff16614520576008610d74565b6001600160a01b038085166000908152600860209081526040808320938716835260029093019052205460ff16614558576000610d74565b600080614569858786600080613a3c565b935050509150600060148111156145825761458261523f565b8260148111156145945761459461523f565b146145b4578160148111156145ab576145ab61523f565b92505050610bd6565b80156124935760046145ab565b60005b60195481101561109957601981815481106145e1576145e16152b7565b600091825260209091200154604051634e081c9560e01b81526001600160a01b0386811660048301528581166024830152848116604483015290911690634e081c9590606401600060405180830381600087803b15801561464157600080fd5b505af1158015614655573d6000803e3d6000fd5b50505050808061466490615360565b9150506145c4565b6001600160a01b0382166000908152600860205260408120805460ff16614697576008915050610c39565b6001600160a01b038316600090815260028201602052604090205460ff161515600114156146c9576000915050610c39565b6001600160a01b03838116600081815260028401602090815260408083208054600160ff199091168117909155600783528184208054918201815584528284200180546001600160a01b031916958a1695909517909455918152600a909152205460ff166147ba57600b8054600180820183557f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990910180546001600160a01b0319166001600160a01b0387169081179091556000908152600a60205260409020805460ff19168217905590546147a0919061526b565b6001600160a01b0384166000908152600c60205260409020555b604080516001600160a01b038087168252851660208201527f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a5910160405180910390a15060009392505050565b60408051602081019091526000815260405180602001604052806148338560000151856000015161427c565b90529392505050565b6040805160208101909152600081526040518060200160405280670de0b6b3a764000061487186600001518660000151614a44565b614833919061542f565b60408051602081019091526000815260405180602001604052806148336148ae8660000151670de0b6b3a7640000614a44565b8551614a86565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa08460148111156148ea576148ea61523f565b84601a8111156148fc576148fc61523f565b604080519283526020830191909152810184905260600160405180910390a1836014811115610c1757610c1761523f565b60008061493a858561494e565b9050610ca161494882614976565b8461427c565b6040805160208101909152600081526040518060200160405280614833856000015185614a44565b8051600090610c3990670de0b6b3a76400009061542f565b60006149a66040518060200160405280600081525090565b6000806149b7866000015186614ab9565b909250905060008260038111156149d0576149d061523f565b146149ef57506040805160208101909152600081529092509050614275565b60408051602081019091529081526000969095509350505050565b600080614a178486615282565b90508285821015614a3b5760405162461bcd60e51b8152600401610ad19190615451565b50949350505050565b6000610bd683836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250614af8565b6000610bd683836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250614b4b565b60008083614acc57506000905080614275565b83830283614ada868361542f565b14614aed57600260009250925050614275565b600092509050614275565b6000831580614b05575082155b15614b1257506000610bd6565b6000614b1e8486615410565b905083614b2b868361542f565b148390614a3b5760405162461bcd60e51b8152600401610ad19190615451565b60008183614b6c5760405162461bcd60e51b8152600401610ad19190615451565b50610c17838561542f565b604051806101c0016040528060006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001614bd36040518060200160405280600081525090565b8152602001614bee6040518060200160405280600081525090565b8152602001614c096040518060200160405280600081525090565b8152602001614c246040518060200160405280600081525090565b81526020016000815260200160008152602001600081525090565b6001600160a01b0381168114614c5457600080fd5b50565b803561262481614c3f565b600060208284031215614c7457600080fd5b8135610bd681614c3f565b8015158114614c5457600080fd5b600080600060608486031215614ca257600080fd5b8335614cad81614c3f565b92506020840135614cbd81614c3f565b91506040840135614ccd81614c7f565b809150509250925092565b60008060408385031215614ceb57600080fd5b8235614cf681614c3f565b91506020830135614d0681614c3f565b809150509250929050565b60008060008060808587031215614d2757600080fd5b8435614d3281614c3f565b93506020850135614d4281614c3f565b92506040850135614d5281614c3f565b9396929550929360600135925050565b600060208284031215614d7457600080fd5b5035919050565b60008060008060808587031215614d9157600080fd5b8435614d9c81614c3f565b93506020850135614dac81614c3f565b93969395505050506040820135916060013590565b600080600060608486031215614dd657600080fd5b8335614de181614c3f565b92506020840135614df181614c3f565b929592945050506040919091013590565b600080600080600060a08688031215614e1a57600080fd5b8535614e2581614c3f565b94506020860135614e3581614c3f565b93506040860135614e4581614c3f565b92506060860135614e5581614c3f565b949793965091946080013592915050565b60008060408385031215614e7957600080fd5b8235614e8481614c3f565b946020939093013593505050565b600080600080600060a08688031215614eaa57600080fd5b8535614eb581614c3f565b94506020860135614ec581614c3f565b94979496505050506040830135926060810135926080909101359150565b6020808252825182820181905260009190848201906040850190845b81811015614f255783516001600160e01b03191683529284019291840191600101614eff565b50909695505050505050565b600060208284031215614f4357600080fd5b8135610bd681614c7f565b6020808252825182820181905260009190848201906040850190845b81811015614f255783516001600160a01b031683529284019291840191600101614f6a565b60008083601f840112614fa157600080fd5b50813567ffffffffffffffff811115614fb957600080fd5b60208301915083602082850101111561427557600080fd5b60008060008060008060808789031215614fea57600080fd5b863560ff81168114614ffb57600080fd5b9550602087013567ffffffffffffffff8082111561501857600080fd5b6150248a838b01614f8f565b9097509550604089013591508082111561503d57600080fd5b5061504a89828a01614f8f565b979a9699509497949695606090950135949350505050565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121561508b57600080fd5b823567ffffffffffffffff808211156150a357600080fd5b818501915085601f8301126150b757600080fd5b8135818111156150c9576150c9615062565b8060051b604051601f19603f830116810181811085821117156150ee576150ee615062565b60405291825284820192508381018501918883111561510c57600080fd5b938501935b828510156151315761512285614c57565b84529385019392850192615111565b98975050505050505050565b6020808252825182820181905260009190848201906040850190845b81811015614f2557835183529284019291840191600101615159565b60008083601f84011261518757600080fd5b50813567ffffffffffffffff81111561519f57600080fd5b6020830191508360208260051b850101111561427557600080fd5b600080600080604085870312156151d057600080fd5b843567ffffffffffffffff808211156151e857600080fd5b6151f488838901615175565b9096509450602087013591508082111561520d57600080fd5b5061521a87828801615175565b95989497509550505050565b60006020828403121561523857600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008282101561527d5761527d615255565b500390565b6000821982111561529557615295615255565b500190565b600060ff8216806152ad576152ad615255565b6000190192915050565b634e487b7160e01b600052603260045260246000fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60ff861681526060602082015260006153136060830186886152cd565b82810360408401526151318185876152cd565b60006020828403121561533857600080fd5b8151610bd681614c3f565b60006020828403121561535557600080fd5b8151610bd681614c7f565b600060001982141561537457615374615255565b5060010190565b6001600160a01b0394851681529284166020840152921660408201526001600160e01b0319909116606082015260800190565b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052600160045260246000fd5b600080600080608085870312156153f057600080fd5b505082516020840151604085015160609095015191969095509092509050565b600081600019048311821515161561542a5761542a615255565b500290565b60008261544c57634e487b7160e01b600052601260045260246000fd5b500490565b600060208083528351808285015260005b8181101561547e57858101830151858201604001528201615462565b81811115615490576000604083870101525b50601f01601f191692909201604001939250505056fea2646970667358221220767c1ff16851be58a8c5ad1f66422f8cb25f1dfeb02c516a0459e7bedf9c56b864736f6c634300080a0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.