Contract
0x53cc546053a09431c9d1a2b288471680d15000a4
1
Contract Overview
Balance:
0 ETH
ETH Value:
$0.00
My Name Tag:
Not Available
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0xe3f638a60acc5e970f6c4a9b98ab55cc59f5f6a2100d3a1e4c37adb344d9a70a | 0x60806040 | 4706132 | 123 days 8 hrs ago | 0xb8f02248d53f7edfa38e79263e743e9390f81942 | IN | Create: Comptroller | 0 ETH | 0.158122057254 ETH |
[ Download CSV Export ]
Latest 25 internal transaction
[ Download CSV Export ]
Contract Name:
Comptroller
Compiler Version
v0.5.17+commit.d19bba13
Contract Source Code (Solidity Multiple files format)
pragma solidity ^0.5.16; import "./CToken.sol"; import "./CErc20.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./PriceOracle.sol"; import "./ComptrollerInterface.sol"; import "./ComptrollerStorage.sol"; import "./Unitroller.sol"; import "./RewardsDistributorDelegate.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 ComptrollerV3Storage, ComptrollerInterface, ComptrollerErrorReporter, Exponential { /// @notice Emitted when an admin supports a market event MarketListed(CToken cToken); /// @notice Emitted when an admin unsupports a market event MarketUnlisted(CToken cToken); /// @notice Emitted when an account enters a market event MarketEntered(CToken cToken, address account); /// @notice Emitted when an account exits a market event MarketExited(CToken cToken, address account); /// @notice Emitted when close factor is changed by admin event NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa); /// @notice Emitted when a collateral factor is changed by admin event NewCollateralFactor(CToken cToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa); /// @notice Emitted when liquidation incentive is changed by admin event NewLiquidationIncentive(uint oldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa); /// @notice Emitted when price oracle is changed event NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle); /// @notice Emitted when pause guardian is changed event NewPauseGuardian(address oldPauseGuardian, address newPauseGuardian); /// @notice Emitted when an action is paused globally event ActionPaused(string action, bool pauseState); /// @notice Emitted when an action is paused on a market event ActionPaused(CToken cToken, string action, bool pauseState); /// @notice Emitted when the whitelist enforcement is changed event WhitelistEnforcementChanged(bool enforce); /// @notice Emitted when auto implementations are toggled event AutoImplementationsToggled(bool enabled); /// @notice Emitted when supply cap for a cToken is changed event NewSupplyCap(CToken indexed cToken, uint newSupplyCap); /// @notice Emitted when borrow cap for a cToken is changed event NewBorrowCap(CToken indexed cToken, uint newBorrowCap); /// @notice Emitted when borrow cap guardian is changed event NewBorrowCapGuardian(address oldBorrowCapGuardian, address newBorrowCapGuardian); /// @notice Emitted when a new RewardsDistributor contract is added to hooks event AddedRewardsDistributor(address rewardsDistributor); // closeFactorMantissa must be strictly greater than this value uint internal constant closeFactorMinMantissa = 0.05e18; // 0.05 // closeFactorMantissa must not exceed this value uint internal constant closeFactorMaxMantissa = 0.9e18; // 0.9 // No collateralFactorMantissa may exceed this value uint internal constant collateralFactorMaxMantissa = 0.9e18; // 0.9 // liquidationIncentiveMantissa must be no less than this value uint internal constant liquidationIncentiveMinMantissa = 1.0e18; // 1.0 // liquidationIncentiveMantissa must be no greater than this value uint internal constant liquidationIncentiveMaxMantissa = 1.5e18; // 1.5 /*** Assets You Are In ***/ /** * @notice Returns the assets an account has entered * @param account The address of the account to pull assets for * @return A dynamic list with the assets the account has entered */ function getAssetsIn(address account) external view returns (CToken[] memory) { CToken[] memory assetsIn = accountAssets[account]; return assetsIn; } /** * @notice Returns whether the given account is entered in the given asset * @param account The address of the account to check * @param cToken The cToken to check * @return True if the account is in the asset, otherwise false. */ function checkMembership(address account, CToken cToken) external view returns (bool) { return markets[address(cToken)].accountMembership[account]; } /** * @notice Add assets to be included in account liquidity calculation * @param cTokens The list of addresses of the cToken markets to be enabled * @return Success indicator for whether each corresponding market was entered */ function enterMarkets(address[] memory cTokens) public returns (uint[] memory) { uint len = cTokens.length; uint[] memory results = new uint[](len); for (uint i = 0; i < len; i++) { CToken cToken = CToken(cTokens[i]); results[i] = uint(addToMarketInternal(cToken, msg.sender)); } return results; } /** * @notice Add the market to the borrower's "assets in" for liquidity calculations * @param cToken The market to enter * @param borrower The address of the account to modify * @return Success indicator for whether the market was entered */ function addToMarketInternal(CToken cToken, address borrower) internal returns (Error) { Market storage marketToJoin = markets[address(cToken)]; if (!marketToJoin.isListed) { // market is not listed, cannot join return Error.MARKET_NOT_LISTED; } if (marketToJoin.accountMembership[borrower] == true) { // already joined return Error.NO_ERROR; } // survived the gauntlet, add to list // NOTE: we store these somewhat redundantly as a significant optimization // this avoids having to iterate through the list for the most common use cases // that is, only when we need to perform liquidity checks // and not whenever we want to check if an account is in a particular market marketToJoin.accountMembership[borrower] = true; accountAssets[borrower].push(cToken); // 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 neccessary collateral for an outstanding borrow. * @param cTokenAddress The address of the asset to be removed * @return Whether or not the account successfully exited the market */ function exitMarket(address cTokenAddress) external returns (uint) { CToken cToken = CToken(cTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the cToken */ (uint oErr, uint tokensHeld, uint amountOwed, ) = cToken.getAccountSnapshot(msg.sender); require(oErr == 0, "exitMarket: getAccountSnapshot failed"); // semi-opaque error code /* Fail if the sender has a borrow balance */ if (amountOwed != 0) { return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED); } /* Fail if the sender is not permitted to redeem all of their tokens */ uint allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[address(cToken)]; /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint(Error.NO_ERROR); } /* Set cToken account membership to false */ delete marketToExit.accountMembership[msg.sender]; /* Delete cToken from the account’s list of assets */ // load into memory for faster iteration CToken[] memory userAssetList = accountAssets[msg.sender]; uint len = userAssetList.length; uint assetIndex = len; for (uint i = 0; i < len; i++) { if (userAssetList[i] == cToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 CToken[] storage storedList = accountAssets[msg.sender]; storedList[assetIndex] = storedList[storedList.length - 1]; storedList.length--; // If the user has exited all markets, remove them from the `allBorrowers` array if (storedList.length == 0) { uint256 borrowerIndex = borrowerIndexes[msg.sender]; // If borrower not at the end of the borrower array, replace it with the item at the end of the borrower array if (borrowerIndex < allBorrowers.length - 1) { address lastElement = allBorrowers[allBorrowers.length - 1]; allBorrowers[borrowerIndex] = lastElement; // Copy last item in list to location of item to be removed borrowerIndexes[lastElement] = borrowerIndex; // Set borrower index of moved item to correct index } // Remove the last element of the borrower array allBorrowers.length--; // Reduce length by 1 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(cToken, msg.sender); return uint(Error.NO_ERROR); } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param cToken The market to verify the mint against * @param minter The account which would get the minted tokens * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!mintGuardianPaused[cToken], "mint is paused"); // Shh - currently unused minter; mintAmount; // Make sure market is listed if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Make sure minter is whitelisted if (enforceWhitelist && !whitelist[minter]) { return uint(Error.SUPPLIER_NOT_WHITELISTED); } // Check supply cap uint supplyCap = supplyCaps[cToken]; // Supply cap of 0 corresponds to unlimited supplying if (supplyCap != 0) { uint totalCash = CToken(cToken).getCash(); uint totalBorrows = CToken(cToken).totalBorrows(); uint totalReserves = CToken(cToken).totalReserves(); uint totalFuseFees = CToken(cToken).totalFuseFees(); uint totalAdminFees = CToken(cToken).totalAdminFees(); // totalUnderlyingSupply = totalCash + totalBorrows - (totalReserves + totalFuseFees + totalAdminFees) (MathError mathErr, uint totalUnderlyingSupply) = addThenSubUInt(totalCash, totalBorrows, add_(add_(totalReserves, totalFuseFees), totalAdminFees)); if (mathErr != MathError.NO_ERROR) return uint(Error.MATH_ERROR); uint nextTotalUnderlyingSupply; (mathErr, nextTotalUnderlyingSupply) = addUInt(totalUnderlyingSupply, mintAmount); if (mathErr != MathError.NO_ERROR) return uint(Error.MATH_ERROR); require(nextTotalUnderlyingSupply < supplyCap, "market supply cap reached"); } // Keep the flywheel moving flywheelPreSupplierAction(cToken, minter); return uint(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, uint actualMintAmount, uint mintTokens) external { // Shh - currently unused cToken; minter; actualMintAmount; mintTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } // Add minter to suppliers mapping suppliers[minter] = true; } /** * @notice Checks if the account should be allowed to redeem tokens in the given market * @param cToken The market to verify the redeem against * @param redeemer The account which would redeem the tokens * @param redeemTokens The number of cTokens to exchange for the underlying asset in the market * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint) { uint allowed = redeemAllowedInternal(cToken, redeemer, redeemTokens); if (allowed != uint(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving flywheelPreSupplierAction(cToken, redeemer); return uint(Error.NO_ERROR); } function redeemAllowedInternal(address cToken, address redeemer, uint redeemTokens) internal view returns (uint) { if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */ if (!markets[cToken].accountMembership[redeemer]) { return uint(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(redeemer, CToken(cToken), redeemTokens, 0); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates redeem and reverts on rejection. May emit logs. * @param cToken Asset being redeemed * @param redeemer The address redeeming the tokens * @param redeemAmount The amount of the underlying asset being redeemed * @param redeemTokens The number of tokens being redeemed */ function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external { // Shh - currently unused cToken; redeemer; // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("redeemTokens zero"); } } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param cToken The market to verify the borrow against * @param borrower The account which would borrow the asset * @param borrowAmount The amount of underlying the account would borrow * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!borrowGuardianPaused[cToken], "borrow is paused"); // Make sure market is listed if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (!markets[cToken].accountMembership[borrower]) { // only cTokens may call borrowAllowed if borrower not in market require(msg.sender == cToken, "sender must be cToken"); // attempt to add borrower to the market Error err = addToMarketInternal(CToken(msg.sender), borrower); if (err != Error.NO_ERROR) { return uint(err); } // it should be impossible to break the important invariant assert(markets[cToken].accountMembership[borrower]); } // Make sure oracle price is available if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { return uint(Error.PRICE_ERROR); } // Make sure borrower is whitelisted if (enforceWhitelist && !whitelist[borrower]) { return uint(Error.SUPPLIER_NOT_WHITELISTED); } // Check borrow cap uint borrowCap = borrowCaps[cToken]; // Borrow cap of 0 corresponds to unlimited borrowing if (borrowCap != 0) { uint totalBorrows = CToken(cToken).totalBorrows(); (MathError mathErr, uint nextTotalBorrows) = addUInt(totalBorrows, borrowAmount); if (mathErr != MathError.NO_ERROR) return uint(Error.MATH_ERROR); require(nextTotalBorrows < borrowCap, "market borrow cap reached"); } // Keep the flywheel moving flywheelPreBorrowerAction(cToken, borrower); // Perform a hypothetical liquidity check to guard against shortfall (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(borrower, CToken(cToken), 0, borrowAmount); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(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, uint accountBorrowsNew) external returns (uint) { // Check if min borrow exists uint minBorrowEth = fuseAdmin.minBorrowEth(); if (minBorrowEth > 0) { // Get new underlying borrow balance of account for this cToken uint oraclePriceMantissa = oracle.getUnderlyingPrice(CToken(cToken)); if (oraclePriceMantissa == 0) return uint(Error.PRICE_ERROR); (MathError mathErr, uint borrowBalanceEth) = mulScalarTruncate(Exp({mantissa: oraclePriceMantissa}), accountBorrowsNew); if (mathErr != MathError.NO_ERROR) return uint(Error.MATH_ERROR); // Check against min borrow if (borrowBalanceEth < minBorrowEth) return uint(Error.BORROW_BELOW_MIN); } // Return no error return uint(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 exchangeRateMantissa Underlying/cToken exchange rate * @param accountTokens Initial account cToken balance * @param accountTokens Underlying amount to mint */ function mintWithinLimits(address cToken, uint exchangeRateMantissa, uint accountTokens, uint mintAmount) external returns (uint) { // Return no error return uint(Error.NO_ERROR); } /** * @notice Validates borrow and reverts on rejection. May emit logs. * @param cToken Asset whose underlying is being borrowed * @param borrower The address borrowing the underlying * @param borrowAmount The amount of the underlying asset requested to borrow */ function borrowVerify(address cToken, address borrower, uint borrowAmount) external { // Shh - currently unused cToken; borrower; borrowAmount; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to repay a borrow in the given market * @param cToken The market to verify the repay against * @param payer The account which would repay the asset * @param borrower The account which would borrowed the asset * @param repayAmount The amount of the underlying asset the account would repay * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint) { // Shh - currently unused payer; borrower; repayAmount; // Make sure market is listed if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Keep the flywheel moving flywheelPreBorrowerAction(cToken, borrower); return uint(Error.NO_ERROR); } /** * @notice Validates repayBorrow and reverts on rejection. May emit logs. * @param cToken Asset being repaid * @param payer The address repaying the borrow * @param borrower The address of the borrower * @param actualRepayAmount The amount of underlying being repaid */ function repayBorrowVerify( address cToken, address payer, address borrower, uint actualRepayAmount, uint borrowerIndex) external { // Shh - currently unused cToken; payer; borrower; actualRepayAmount; borrowerIndex; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the liquidation should be allowed to occur * @param cTokenBorrowed Asset which was borrowed by the borrower * @param cTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint) { // Shh - currently unused liquidator; // Make sure markets are listed if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Get borrowers's underlying borrow balance uint borrowBalance = CToken(cTokenBorrowed).borrowBalanceStored(borrower); /* allow accounts to be liquidated if the market is deprecated */ if (isDeprecated(CToken(cTokenBorrowed))) { require(borrowBalance >= repayAmount, "Can not repay more than the total borrow"); } else { /* The borrower must have shortfall in order to be liquidatable */ (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall == 0) { return uint(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint maxClose = mul_ScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance); if (repayAmount > maxClose) { return uint(Error.TOO_MUCH_REPAY); } } return uint(Error.NO_ERROR); } /** * @notice Validates liquidateBorrow and reverts on rejection. May emit logs. * @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 actualRepayAmount The amount of underlying being repaid */ function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint actualRepayAmount, uint seizeTokens) external { // Shh - currently unused cTokenBorrowed; cTokenCollateral; liquidator; borrower; actualRepayAmount; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the seizing of assets should be allowed to occur * @param cTokenCollateral Asset which was used as collateral and will be seized * @param cTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!seizeGuardianPaused, "seize is paused"); // Shh - currently unused liquidator; borrower; seizeTokens; // Make sure markets are listed if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) { return uint(Error.MARKET_NOT_LISTED); } // Make sure cToken Comptrollers are identical if (CToken(cTokenCollateral).comptroller() != CToken(cTokenBorrowed).comptroller()) { return uint(Error.COMPTROLLER_MISMATCH); } // Keep the flywheel moving flywheelPreTransferAction(cTokenCollateral, borrower, liquidator); return uint(Error.NO_ERROR); } /** * @notice Validates seize and reverts on rejection. May emit logs. * @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 seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external { // Shh - currently unused cTokenCollateral; cTokenBorrowed; liquidator; borrower; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param cToken The market to verify the transfer against * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint) { // Pausing is a very serious situation - we revert to sound the alarms require(!transferGuardianPaused, "transfer is paused"); // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens uint allowed = redeemAllowedInternal(cToken, src, transferTokens); if (allowed != uint(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving flywheelPreTransferAction(cToken, src, dst); return uint(Error.NO_ERROR); } /** * @notice Validates transfer and reverts on rejection. May emit logs. * @param cToken Asset being transferred * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer */ function transferVerify(address cToken, address src, address dst, uint transferTokens) external { // Shh - currently unused cToken; src; dst; transferTokens; // Shh - we don't ever want this hook to be marked pure if (false) { maxAssets = maxAssets; } } /*** 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++) RewardsDistributorDelegate(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++) RewardsDistributorDelegate(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++) RewardsDistributorDelegate(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 { uint sumCollateral; uint sumBorrowPlusEffects; uint cTokenBalance; uint borrowBalance; uint exchangeRateMantissa; uint oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToDenom; } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code (semi-opaque), account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidity(address account) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); return (uint(err), liquidity, shortfall); } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code, account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) { return getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @return (possible error code (semi-opaque), hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidity( address account, address cTokenModify, uint redeemTokens, uint borrowAmount) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(cTokenModify), redeemTokens, borrowAmount); return (uint(err), liquidity, shortfall); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @dev Note that we calculate the exchangeRateStored for each collateral cToken using stored data, * without calculating accumulated interest. * @return (possible error code, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, CToken cTokenModify, uint redeemTokens, uint borrowAmount) internal view returns (Error, uint, uint) { AccountLiquidityLocalVars memory vars; // Holds all our calculation results uint oErr; // For each asset the account is in CToken[] memory assets = accountAssets[account]; for (uint i = 0; i < assets.length; i++) { CToken asset = assets[i]; // Read the balances and exchange rate from the cToken (oErr, vars.cTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot(account); if (oErr != 0) { // semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades return (Error.SNAPSHOT_ERROR, 0, 0); } vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa}); vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa}); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0); } vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa}); // Pre-compute a conversion factor from tokens -> ether (normalized price value) vars.tokensToDenom = mul_(mul_(vars.collateralFactor, vars.exchangeRate), vars.oraclePrice); // sumCollateral += tokensToDenom * cTokenBalance vars.sumCollateral = mul_ScalarTruncateAddUInt(vars.tokensToDenom, vars.cTokenBalance, vars.sumCollateral); // sumBorrowPlusEffects += oraclePrice * borrowBalance vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects); // Calculate effects of interacting with cTokenModify if (asset == cTokenModify) { // redeem effect // sumBorrowPlusEffects += tokensToDenom * redeemTokens vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.tokensToDenom, redeemTokens, vars.sumBorrowPlusEffects); // borrow effect // sumBorrowPlusEffects += oraclePrice * borrowAmount vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects); } } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral); } } /** * @notice Calculate number of tokens of collateral asset to seize given an underlying amount * @dev Used in liquidation (called in cToken.liquidateBorrowFresh) * @param cTokenBorrowed The address of the borrowed cToken * @param cTokenCollateral The address of the collateral cToken * @param actualRepayAmount The amount of cTokenBorrowed underlying to convert into cTokenCollateral tokens * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation) */ function liquidateCalculateSeizeTokens(address cTokenBorrowed, address cTokenCollateral, uint actualRepayAmount) external view returns (uint, uint) { /* Read oracle prices for borrowed and collateral markets */ uint priceBorrowedMantissa = oracle.getUnderlyingPrice(CToken(cTokenBorrowed)); uint priceCollateralMantissa = oracle.getUnderlyingPrice(CToken(cTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint(Error.PRICE_ERROR), 0); } /* * Get the exchange rate and calculate the number of collateral tokens to seize: * seizeAmount = actualRepayAmount * liquidationIncentive * priceBorrowed / priceCollateral * seizeTokens = seizeAmount / exchangeRate * = actualRepayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate) */ uint exchangeRateMantissa = CToken(cTokenCollateral).exchangeRateStored(); // Note: reverts on error uint seizeTokens; Exp memory numerator; Exp memory denominator; Exp memory ratio; numerator = mul_(Exp({mantissa: liquidationIncentiveMantissa}), Exp({mantissa: priceBorrowedMantissa})); denominator = mul_(Exp({mantissa: priceCollateralMantissa}), Exp({mantissa: exchangeRateMantissa})); ratio = div_(numerator, denominator); seizeTokens = mul_ScalarTruncate(ratio, actualRepayAmount); return (uint(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 (uint) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.ADD_REWARDS_DISTRIBUTOR_OWNER_CHECK); } // Check marker method require(RewardsDistributorDelegate(distributor).isRewardsDistributor(), "marker method returned false"); // Check for existing RewardsDistributor for (uint i = 0; i < rewardsDistributors.length; i++) require(distributor != rewardsDistributors[i], "RewardsDistributor contract already added"); // Add RewardsDistributor to array rewardsDistributors.push(distributor); emit AddedRewardsDistributor(distributor); return uint(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 (uint) { // 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 uint(Error.NO_ERROR); } // Set comptroller's `enforceWhitelist` to `enforce` enforceWhitelist = enforce; // Emit WhitelistEnforcementChanged(bool enforce); emit WhitelistEnforcementChanged(enforce); return uint(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 (uint) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_WHITELIST_STATUS_OWNER_CHECK); } // Set whitelist statuses for suppliers for (uint 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]) { uint256 supplierIndex = whitelistIndexes[supplier]; // If supplier not at the end of the whitelist array, replace it with the item at the end of the whitelist array if (supplierIndex < whitelistArray.length - 1) { address lastElement = whitelistArray[whitelistArray.length - 1]; whitelistArray[supplierIndex] = lastElement; // Copy last item in list to location of item to be removed whitelistIndexes[lastElement] = supplierIndex; // Set whitelist index of moved item to correct index } // Remove the last element of the whitelist array whitelistArray.length--; // Reduce length by 1 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 uint(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(PriceOracle newOracle) public returns (uint) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the comptroller PriceOracle oldOracle = oracle; // Set comptroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint(Error.NO_ERROR); } /** * @notice Sets the closeFactor used when liquidating borrows * @dev Admin function to set closeFactor * @param newCloseFactorMantissa New close factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCloseFactor(uint 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 uint oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; // Emit event emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets the collateralFactor for a market * @dev Admin function to set per-market collateralFactor * @param cToken The market to set the factor on * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCollateralFactor(CToken cToken, uint newCollateralFactorMantissa) 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 uint oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(cToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets liquidationIncentive * @dev Admin function to set liquidationIncentive * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external returns (uint) { // Check caller is admin if (!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 uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint(Error.NO_ERROR); } /** * @notice Add the market to the markets mapping and set it as listed * @dev Admin function to set isListed and add support for the market * @param cToken The address of the market (token) to list * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _supportMarket(CToken cToken) internal returns (uint) { // 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); } // Sanity check to make sure its really a CToken require(cToken.isCToken(), "marker method returned false"); // Check cToken.comptroller == this require(address(cToken.comptroller()) == address(this), "Cannot support a market with a different Comptroller."); // Make sure market is not already listed address underlying = cToken.isCEther() ? address(0) : CErc20(address(cToken)).underlying(); if (address(cTokensByUnderlying[underlying]) != address(0)) { return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS); } // List market and emit event markets[address(cToken)] = Market({isListed: true, collateralFactorMantissa: 0}); allMarkets.push(cToken); cTokensByUnderlying[underlying] = cToken; emit MarketListed(cToken); return uint(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( bool isCEther, bytes calldata constructorData, uint collateralFactorMantissa ) external returns (uint) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK); } // Temporarily enable Fuse admin rights for asset deployment (storing the original value) bool oldFuseAdminHasRights = fuseAdminHasRights; fuseAdminHasRights = true; // Deploy via Fuse admin CToken cToken = CToken(isCEther ? fuseAdmin.deployCEther(constructorData) : fuseAdmin.deployCErc20(constructorData)); // Reset Fuse admin rights to the original value fuseAdminHasRights = oldFuseAdminHasRights; // Support market here in the Comptroller uint256 err = _supportMarket(cToken); // Set collateral factor return err == uint(Error.NO_ERROR) ? _setCollateralFactor(cToken, collateralFactorMantissa) : err; } /** * @notice Removed a market from the markets mapping and sets it as unlisted * @dev Admin function unset isListed and collateralFactorMantissa and unadd support for the market * @param cToken The address of the market (token) to unlist * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _unsupportMarket(CToken cToken) external returns (uint) { // Check admin rights if (!hasAdminRights()) return fail(Error.UNAUTHORIZED, FailureInfo.UNSUPPORT_MARKET_OWNER_CHECK); // Check if market is already unlisted if (!markets[address(cToken)].isListed) return fail(Error.MARKET_NOT_LISTED, FailureInfo.UNSUPPORT_MARKET_DOES_NOT_EXIST); // Check if market is in use if (cToken.totalSupply() > 0) return fail(Error.NONZERO_TOTAL_SUPPLY, FailureInfo.UNSUPPORT_MARKET_IN_USE); // Unlist market delete markets[address(cToken)]; /* Delete cToken from allMarkets */ // load into memory for faster iteration CToken[] memory _allMarkets = allMarkets; uint len = _allMarkets.length; uint assetIndex = len; for (uint i = 0; i < len; i++) { if (_allMarkets[i] == cToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 allMarkets[assetIndex] = allMarkets[allMarkets.length - 1]; allMarkets.length--; cTokensByUnderlying[cToken.isCEther() ? address(0) : CErc20(address(cToken)).underlying()] = CToken(address(0)); emit MarketUnlisted(cToken); return uint(Error.NO_ERROR); } /** * @notice Toggles the auto-implementation feature * @param enabled If the feature is to be enabled * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _toggleAutoImplementations(bool enabled) public returns (uint) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.TOGGLE_AUTO_IMPLEMENTATIONS_ENABLED_OWNER_CHECK); } // Return no error if already set to the desired value if (autoImplementation == enabled) return uint(Error.NO_ERROR); // Store autoImplementation with value enabled autoImplementation = enabled; // Emit AutoImplementationsToggled(enabled) emit AutoImplementationsToggled(enabled); return uint(Error.NO_ERROR); } /** * @notice Set the given supply caps for the given cToken markets. Supplying that brings total underlying supply to or above supply cap will revert. * @dev Admin or borrowCapGuardian function to set the supply caps. A supply cap of 0 corresponds to unlimited supplying. * @param cTokens The addresses of the markets (tokens) to change the supply caps for * @param newSupplyCaps The new supply cap values in underlying to be set. A value of 0 corresponds to unlimited supplying. */ function _setMarketSupplyCaps(CToken[] calldata cTokens, uint[] calldata newSupplyCaps) external { require(hasAdminRights() || msg.sender == borrowCapGuardian, "only admin or borrow cap guardian can set supply caps"); uint numMarkets = cTokens.length; uint numSupplyCaps = newSupplyCaps.length; require(numMarkets != 0 && numMarkets == numSupplyCaps, "invalid input"); for(uint i = 0; i < numMarkets; i++) { supplyCaps[address(cTokens[i])] = newSupplyCaps[i]; emit NewSupplyCap(cTokens[i], newSupplyCaps[i]); } } /** * @notice Set the given borrow caps for the given cToken markets. Borrowing that brings total borrows to or above borrow cap will revert. * @dev Admin or borrowCapGuardian function to set the borrow caps. A borrow cap of 0 corresponds to unlimited borrowing. * @param cTokens The addresses of the markets (tokens) to change the borrow caps for * @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing. */ function _setMarketBorrowCaps(CToken[] calldata cTokens, uint[] calldata newBorrowCaps) external { require(hasAdminRights() || msg.sender == borrowCapGuardian, "only admin or borrow cap guardian can set borrow caps"); uint numMarkets = cTokens.length; uint numBorrowCaps = newBorrowCaps.length; require(numMarkets != 0 && numMarkets == numBorrowCaps, "invalid input"); for(uint i = 0; i < numMarkets; i++) { borrowCaps[address(cTokens[i])] = newBorrowCaps[i]; emit NewBorrowCap(cTokens[i], newBorrowCaps[i]); } } /** * @notice Admin function to change the Borrow Cap Guardian * @param newBorrowCapGuardian The address of the new Borrow Cap Guardian */ function _setBorrowCapGuardian(address newBorrowCapGuardian) external { require(hasAdminRights(), "only admin can set borrow cap guardian"); // Save current value for inclusion in log address oldBorrowCapGuardian = borrowCapGuardian; // Store borrowCapGuardian with value newBorrowCapGuardian borrowCapGuardian = newBorrowCapGuardian; // Emit NewBorrowCapGuardian(OldBorrowCapGuardian, NewBorrowCapGuardian) emit NewBorrowCapGuardian(oldBorrowCapGuardian, newBorrowCapGuardian); } /** * @notice Admin function to change the Pause Guardian * @param newPauseGuardian The address of the new Pause Guardian * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _setPauseGuardian(address newPauseGuardian) public returns (uint) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PAUSE_GUARDIAN_OWNER_CHECK); } // Save current value for inclusion in log address oldPauseGuardian = pauseGuardian; // Store pauseGuardian with value newPauseGuardian pauseGuardian = newPauseGuardian; // Emit NewPauseGuardian(OldPauseGuardian, NewPauseGuardian) emit NewPauseGuardian(oldPauseGuardian, pauseGuardian); return uint(Error.NO_ERROR); } function _setMintPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || hasAdminRights(), "only pause guardian and admin can pause"); require(hasAdminRights() || state == true, "only admin can unpause"); mintGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Mint", state); return state; } function _setBorrowPaused(CToken cToken, bool state) public returns (bool) { require(markets[address(cToken)].isListed, "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || hasAdminRights(), "only pause guardian and admin can pause"); require(hasAdminRights() || state == true, "only admin can unpause"); borrowGuardianPaused[address(cToken)] = state; emit ActionPaused(cToken, "Borrow", state); return state; } function _setTransferPaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || hasAdminRights(), "only pause guardian and admin can pause"); require(hasAdminRights() || state == true, "only admin can unpause"); transferGuardianPaused = state; emit ActionPaused("Transfer", state); return state; } function _setSeizePaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || hasAdminRights(), "only pause guardian and admin can pause"); require(hasAdminRights() || state == true, "only admin can unpause"); seizeGuardianPaused = state; emit ActionPaused("Seize", state); return state; } function _become(Unitroller unitroller) public { require((msg.sender == address(fuseAdmin) && unitroller.fuseAdminHasRights()) || (msg.sender == unitroller.admin() && unitroller.adminHasRights()), "only unitroller admin can change brains"); uint changeStatus = unitroller._acceptImplementation(); require(changeStatus == 0, "change not authorized"); Comptroller(address(unitroller))._becomeImplementation(); } function _becomeImplementation() external { require(msg.sender == comptrollerImplementation, "only implementation may call _becomeImplementation"); if (!_notEnteredInitialized) { _notEntered = true; _notEnteredInitialized = true; } } /*** Helper Functions ***/ /** * @notice Return all of the markets * @dev The automatic getter may be used to access an individual market. * @return The list of market addresses */ function getAllMarkets() public view returns (CToken[] memory) { return allMarkets; } /** * @notice Return all of the borrowers * @dev The automatic getter may be used to access an individual borrower. * @return The list of borrower account addresses */ function getAllBorrowers() public view returns (address[] memory) { return allBorrowers; } /** * @notice Return all of the whitelist * @dev The automatic getter may be used to access an individual whitelist status. * @return The list of borrower account addresses */ function getWhitelist() external view returns (address[] memory) { return whitelistArray; } /** * @notice Returns an array of all RewardsDistributors */ function getRewardsDistributors() external view returns (address[] memory) { return rewardsDistributors; } /** * @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(CToken cToken) public view returns (bool) { return markets[address(cToken)].collateralFactorMantissa == 0 && borrowGuardianPaused[address(cToken)] == true && add_(add_(cToken.reserveFactorMantissa(), cToken.adminFeeMantissa()), cToken.fuseFeeMantissa()) == 1e18 ; } /*** 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 { require(markets[msg.sender].isListed, "Comptroller:_beforeNonReentrant: caller not listed as market"); require(_notEntered, "re-entered across assets"); _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 { require(markets[msg.sender].isListed, "Comptroller:_afterNonReentrant: caller not listed as market"); _notEntered = true; // get a gas-refund post-Istanbul } }
pragma solidity ^0.5.16; /** * @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(uint a, uint b) internal pure returns (MathError, uint) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint c = a * b; if (c / a != b) { return (MathError.INTEGER_OVERFLOW, 0); } else { return (MathError.NO_ERROR, c); } } /** * @dev Integer division of two numbers, truncating the quotient. */ function divUInt(uint a, uint b) internal pure returns (MathError, uint) { if (b == 0) { return (MathError.DIVISION_BY_ZERO, 0); } return (MathError.NO_ERROR, a / b); } /** * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend). */ function subUInt(uint a, uint b) internal pure returns (MathError, uint) { if (b <= a) { return (MathError.NO_ERROR, a - b); } else { return (MathError.INTEGER_UNDERFLOW, 0); } } /** * @dev Adds two numbers, returns an error on overflow. */ function addUInt(uint a, uint b) internal pure returns (MathError, uint) { uint c = a + b; if (c >= a) { return (MathError.NO_ERROR, c); } else { return (MathError.INTEGER_OVERFLOW, 0); } } /** * @dev add a and b and then subtract c */ function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) { (MathError err0, uint sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } }
pragma solidity ^0.5.16; import "./CErc20Delegate.sol"; /** * @title Compound's CDai Contract * @notice CToken which wraps Multi-Collateral DAI * @author Compound */ contract CDaiDelegate is CErc20Delegate { /** * @notice DAI adapter address */ address public daiJoinAddress; /** * @notice DAI Savings Rate (DSR) pot address */ address public potAddress; /** * @notice DAI vat address */ address public vatAddress; /** * @notice Delegate interface to become the implementation * @param data The encoded arguments for becoming */ function _becomeImplementation(bytes calldata data) external { require(msg.sender == address(this) || hasAdminRights(), "only self or admin may call _becomeImplementation"); // Decode data (address daiJoinAddress_, address potAddress_) = abi.decode(data, (address, address)); return _becomeImplementation(daiJoinAddress_, potAddress_); } /** * @notice Explicit interface to become the implementation * @param daiJoinAddress_ DAI adapter address * @param potAddress_ DAI Savings Rate (DSR) pot address */ function _becomeImplementation(address daiJoinAddress_, address potAddress_) internal { // Get dai and vat and sanity check the underlying DaiJoinLike daiJoin = DaiJoinLike(daiJoinAddress_); PotLike pot = PotLike(potAddress_); GemLike dai = daiJoin.dai(); VatLike vat = daiJoin.vat(); require(address(dai) == underlying, "DAI must be the same as underlying"); // Remember the relevant addresses daiJoinAddress = daiJoinAddress_; potAddress = potAddress_; vatAddress = address(vat); // Approve moving our DAI into the vat through daiJoin dai.approve(daiJoinAddress, uint(-1)); // Approve the pot to transfer our funds within the vat vat.hope(potAddress); vat.hope(daiJoinAddress); // Accumulate DSR interest -- must do this in order to doTransferIn pot.drip(); // Transfer all cash in (doTransferIn does this regardless of amount) doTransferIn(address(this), 0); } /** * @notice Delegate interface to resign the implementation */ function _resignImplementation() internal { // Transfer all cash out of the DSR - note that this relies on self-transfer DaiJoinLike daiJoin = DaiJoinLike(daiJoinAddress); PotLike pot = PotLike(potAddress); VatLike vat = VatLike(vatAddress); // Accumulate interest pot.drip(); // Calculate the total amount in the pot, and move it out uint pie = pot.pie(address(this)); pot.exit(pie); // Checks the actual balance of DAI in the vat after the pot exit uint bal = vat.dai(address(this)); // Remove our whole balance daiJoin.exit(address(this), bal / RAY); } /*** CToken Overrides ***/ /** * @notice Accrues DSR then applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public returns (uint) { // Accumulate DSR interest PotLike(potAddress).drip(); // Accumulate CToken interest return super.accrueInterest(); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying tokens owned by this contract */ function getCashPrior() internal view returns (uint) { PotLike pot = PotLike(potAddress); uint pie = pot.pie(address(this)); return mul(pot.chi(), pie) / RAY; } /** * @notice Transfer the underlying to this contract and sweep into DSR pot * @param from Address to transfer funds from * @param amount Amount of underlying to transfer * @return The actual amount that is transferred */ function doTransferIn(address from, uint amount) internal returns (uint) { // Perform the EIP-20 transfer in EIP20Interface token = EIP20Interface(underlying); require(token.transferFrom(from, address(this), amount), "unexpected EIP-20 transfer in return"); DaiJoinLike daiJoin = DaiJoinLike(daiJoinAddress); GemLike dai = GemLike(underlying); PotLike pot = PotLike(potAddress); VatLike vat = VatLike(vatAddress); // Convert all our DAI to internal DAI in the vat daiJoin.join(address(this), dai.balanceOf(address(this))); // Checks the actual balance of DAI in the vat after the join uint bal = vat.dai(address(this)); // Calculate the percentage increase to th pot for the entire vat, and move it in // Note: We may leave a tiny bit of DAI in the vat...but we do the whole thing every time uint pie = bal / pot.chi(); pot.join(pie); return amount; } /** * @notice Transfer the underlying from this contract, after sweeping out of DSR pot * @param to Address to transfer funds to * @param amount Amount of underlying to transfer */ function doTransferOut(address payable to, uint amount) internal { DaiJoinLike daiJoin = DaiJoinLike(daiJoinAddress); PotLike pot = PotLike(potAddress); // Calculate the percentage decrease from the pot, and move that much out // Note: Use a slightly larger pie size to ensure that we get at least amount in the vat uint pie = add(mul(amount, RAY) / pot.chi(), 1); pot.exit(pie); daiJoin.exit(to, amount); } /*** Maker Internals ***/ uint256 constant RAY = 10 ** 27; function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, "add-overflow"); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, "mul-overflow"); } } /*** Maker Interfaces ***/ interface PotLike { function chi() external view returns (uint); function pie(address) external view returns (uint); function drip() external returns (uint); function join(uint) external; function exit(uint) external; } interface GemLike { function approve(address, uint) external; function balanceOf(address) external view returns (uint); function transferFrom(address, address, uint) external returns (bool); } interface VatLike { function dai(address) external view returns (uint); function hope(address) external; } interface DaiJoinLike { function vat() external returns (VatLike); function dai() external returns (GemLike); function join(address, uint) external payable; function exit(address, uint) external; }
pragma solidity ^0.5.16; import "./CToken.sol"; interface CompLike { function delegate(address delegatee) external; } /** * @title Compound's CErc20 Contract * @notice CTokens which wrap an EIP-20 underlying * @dev This contract should not to be deployed on its own; instead, deploy `CErc20Delegator` (proxy contract) and `CErc20Delegate` (logic/implementation contract). * @author Compound */ contract CErc20 is CToken, CErc20Interface { /** * @notice Initialize the new money market * @param underlying_ The address of the underlying asset * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token */ function initialize(address underlying_, ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, string memory name_, string memory symbol_, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) public { // CToken initialize does the bulk of the work uint256 initialExchangeRateMantissa_ = 0.2e18; uint8 decimals_ = EIP20Interface(underlying_).decimals(); super.initialize(comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_, reserveFactorMantissa_, adminFeeMantissa_); // Set underlying and sanity check it underlying = underlying_; EIP20Interface(underlying).totalSupply(); } /*** User Interface ***/ /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function mint(uint mintAmount) external returns (uint) { (uint err,) = mintInternal(mintAmount); return err; } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeem(uint redeemTokens) external returns (uint) { return redeemInternal(redeemTokens); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to redeem * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlying(uint redeemAmount) external returns (uint) { return redeemUnderlyingInternal(redeemAmount); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrow(uint borrowAmount) external returns (uint) { return borrowInternal(borrowAmount); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrow(uint repayAmount) external returns (uint) { (uint err,) = repayBorrowInternal(repayAmount); return err; } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint) { (uint err,) = repayBorrowBehalfInternal(borrower, repayAmount); return err; } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param cTokenCollateral The market in which to seize collateral from the borrower * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint) { (uint err,) = liquidateBorrowInternal(borrower, repayAmount, cTokenCollateral); return err; } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying tokens owned by this contract */ function getCashPrior() internal view returns (uint) { EIP20Interface token = EIP20Interface(underlying); return token.balanceOf(address(this)); } /** * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case. * This will revert due to insufficient balance or insufficient allowance. * This function returns the actual amount received, * which may be less than `amount` if there is a fee attached to the transfer. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferIn(address from, uint amount) internal returns (uint) { uint balanceBefore = EIP20Interface(underlying).balanceOf(address(this)); _callOptionalReturn(abi.encodeWithSelector(EIP20NonStandardInterface(underlying).transferFrom.selector, from, address(this), amount), "TOKEN_TRANSFER_IN_FAILED"); // Calculate the amount that was *actually* transferred uint balanceAfter = EIP20Interface(underlying).balanceOf(address(this)); require(balanceAfter >= balanceBefore, "TOKEN_TRANSFER_IN_OVERFLOW"); return balanceAfter - balanceBefore; // underflow already checked above, just subtract } /** * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory * error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to * insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified * it is >= amount, this should not revert in normal conditions. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferOut(address payable to, uint amount) internal { _callOptionalReturn(abi.encodeWithSelector(EIP20NonStandardInterface(underlying).transfer.selector, to, amount), "TOKEN_TRANSFER_OUT_FAILED"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param data The call data (encoded using abi.encode or one of its variants). * @param errorMessage The revert string to return on failure. */ function _callOptionalReturn(bytes memory data, string memory errorMessage) internal { bytes memory returndata = _functionCall(underlying, data, errorMessage); if (returndata.length > 0) require(abi.decode(returndata, (bool)), errorMessage); } /** * @notice Admin call to delegate the votes of the COMP-like underlying * @param compLikeDelegatee The address to delegate votes to * @dev CTokens whose underlying are not CompLike should revert here */ function _delegateCompLikeTo(address compLikeDelegatee) external { require(hasAdminRights(), "only the admin may set the comp-like delegate"); CompLike(underlying).delegate(compLikeDelegatee); } }
pragma solidity ^0.5.16; import "./CErc20.sol"; /** * @title Compound's CErc20Delegate Contract * @notice CTokens which wrap an EIP-20 underlying and are delegated to * @author Compound */ contract CErc20Delegate is CDelegateInterface, CErc20 { /** * @notice Construct an empty delegate */ constructor() public {} /** * @notice Called by the delegator on a delegate to initialize it for duty * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes calldata data) external { // Shh -- currently unused data; // Shh -- we don't ever want this hook to be marked pure if (false) { implementation = address(0); } require(msg.sender == address(this) || hasAdminRights(), "!self"); // Make sure admin storage is set up correctly __admin = address(0); __adminHasRights = false; __fuseAdminHasRights = false; } /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() internal { // Shh -- we don't ever want this hook to be marked pure if (false) { implementation = address(0); } } /** * @dev Internal function to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationInternal(address implementation_, bool allowResign, bytes memory becomeImplementationData) internal { // Check whitelist require(fuseAdmin.cErc20DelegateWhitelist(implementation, implementation_, allowResign), "!impl"); // Call _resignImplementation internally (this delegate's code) if (allowResign) _resignImplementation(); // Get old implementation address oldImplementation = implementation; // Store new implementation implementation = implementation_; // Call _becomeImplementation externally (delegating to new delegate's code) _functionCall(address(this), abi.encodeWithSignature("_becomeImplementation(bytes)", becomeImplementationData), "!become"); // Emit event emit NewImplementation(oldImplementation, implementation); } /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationSafe(address implementation_, bool allowResign, bytes calldata becomeImplementationData) external { // Check admin rights require(hasAdminRights(), "!admin"); // Set implementation _setImplementationInternal(implementation_, allowResign, becomeImplementationData); } /** * @notice Function called before all delegator functions * @dev Checks comptroller.autoImplementation and upgrades the implementation if necessary */ function _prepare() external payable { if (msg.sender != address(this) && ComptrollerV3Storage(address(comptroller)).autoImplementation()) { (address latestCErc20Delegate, bool allowResign, bytes memory becomeImplementationData) = fuseAdmin.latestCErc20Delegate(implementation); if (implementation != latestCErc20Delegate) _setImplementationInternal(latestCErc20Delegate, allowResign, becomeImplementationData); } } }
pragma solidity ^0.5.16; import "./CTokenInterfaces.sol"; import "./ComptrollerStorage.sol"; /** * @title Compound's CErc20Delegator Contract * @notice CTokens which wrap an EIP-20 underlying and delegate to an implementation * @author Compound */ contract CErc20Delegator is CDelegationStorage { /** * @notice Construct a new money market * @param underlying_ The address of the underlying asset * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token * @param implementation_ The address of the implementation the contract delegates to * @param becomeImplementationData The encoded args for becomeImplementation */ constructor(address underlying_, ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, string memory name_, string memory symbol_, address implementation_, bytes memory becomeImplementationData, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) public { // First delegate gets to initialize the delegator (i.e. storage contract) delegateTo(implementation_, abi.encodeWithSignature("initialize(address,address,address,string,string,uint256,uint256)", underlying_, comptroller_, interestRateModel_, name_, symbol_, reserveFactorMantissa_, adminFeeMantissa_)); // New implementations always get set via the settor (post-initialize) delegateTo(implementation_, abi.encodeWithSignature("_setImplementationSafe(address,bool,bytes)", implementation_, false, becomeImplementationData)); } /** * @notice Internal method to delegate execution to another contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts * @param callee The contract to delegatecall * @param data The raw data to delegatecall * @return The returned bytes from the delegatecall */ function delegateTo(address callee, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returnData) = callee.delegatecall(data); assembly { if eq(success, 0) { revert(add(returnData, 0x20), returndatasize) } } return returnData; } /** * @notice Delegates execution to an implementation contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts */ function () external payable { // Cannot send value to CErc20Delegator require(msg.value == 0, "CErc20Delegator:fallback: cannot send value to fallback"); // Check for automatic implementation delegateTo(implementation, abi.encodeWithSignature("_prepare()")); // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
pragma solidity ^0.5.16; import "./CToken.sol"; /** * @title Compound's CEther Contract * @notice CToken which wraps Ether * @dev This contract should not to be deployed on its own; instead, deploy `CEtherDelegator` (proxy contract) and `CEtherDelegate` (logic/implementation contract). * @author Compound */ contract CEther is CToken, CEtherInterface { /** * @notice Initialize the new money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token */ function initialize(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, string memory name_, string memory symbol_, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) public { // CToken initialize does the bulk of the work uint256 initialExchangeRateMantissa_ = 0.2e18; uint8 decimals_ = 18; super.initialize(comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_, reserveFactorMantissa_, adminFeeMantissa_); } /*** User Interface ***/ /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Reverts upon any failure */ function mint() external payable { (uint err,) = mintInternal(msg.value); requireNoError(err, "mint failed"); } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeem(uint redeemTokens) external returns (uint) { return redeemInternal(redeemTokens); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to redeem * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlying(uint redeemAmount) external returns (uint) { return redeemUnderlyingInternal(redeemAmount); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrow(uint borrowAmount) external returns (uint) { return borrowInternal(borrowAmount); } /** * @notice Sender repays their own borrow * @dev Reverts upon any failure */ function repayBorrow() external payable { (uint err,) = repayBorrowInternal(msg.value); requireNoError(err, "repayBorrow failed"); } /** * @notice Sender repays a borrow belonging to borrower * @dev Reverts upon any failure * @param borrower the account with the debt being payed off */ function repayBorrowBehalf(address borrower) external payable { (uint err,) = repayBorrowBehalfInternal(borrower, msg.value); requireNoError(err, "repayBorrowBehalf failed"); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @dev Reverts upon any failure * @param borrower The borrower of this cToken to be liquidated * @param cTokenCollateral The market in which to seize collateral from the borrower */ function liquidateBorrow(address borrower, CToken cTokenCollateral) external payable { (uint err,) = liquidateBorrowInternal(borrower, msg.value, cTokenCollateral); requireNoError(err, "liquidateBorrow failed"); } /** * @notice Send Ether to CEther to mint */ function () external payable { (uint err,) = mintInternal(msg.value); requireNoError(err, "mint failed"); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of Ether, before this message * @dev This excludes the value of the current message, if any * @return The quantity of Ether owned by this contract */ function getCashPrior() internal view returns (uint) { (MathError err, uint startingBalance) = subUInt(address(this).balance, msg.value); require(err == MathError.NO_ERROR); return startingBalance; } /** * @notice Perform the actual transfer in, which is a no-op * @param from Address sending the Ether * @param amount Amount of Ether being sent * @return The actual amount of Ether transferred */ function doTransferIn(address from, uint amount) internal returns (uint) { // Sanity checks require(msg.sender == from, "sender mismatch"); require(msg.value == amount, "value mismatch"); return amount; } function doTransferOut(address payable to, uint amount) internal { // Send the Ether and revert on failure (bool success, ) = to.call.value(amount)(""); require(success, "doTransferOut failed"); } function requireNoError(uint errCode, string memory message) internal pure { if (errCode == uint(Error.NO_ERROR)) { return; } bytes memory fullMessage = new bytes(bytes(message).length + 7); uint i; for (i = 0; i < bytes(message).length; i++) { fullMessage[i] = bytes(message)[i]; } fullMessage[i+0] = byte(uint8(32)); fullMessage[i+1] = byte(uint8(40)); fullMessage[i+2] = byte(uint8(48 + ( errCode / 1000 ))); fullMessage[i+3] = byte(uint8(48 + ( errCode / 100 % 10 ))); fullMessage[i+4] = byte(uint8(48 + ( errCode / 10 % 10 ))); fullMessage[i+5] = byte(uint8(48 + ( errCode % 10 ))); fullMessage[i+6] = byte(uint8(41)); require(errCode == uint(Error.NO_ERROR), string(fullMessage)); } }
pragma solidity ^0.5.16; import "./CEther.sol"; /** * @title Compound's CEtherDelegate Contract * @notice CTokens which wrap Ether and are delegated to * @author Compound */ contract CEtherDelegate is CDelegateInterface, CEther { /** * @notice Construct an empty delegate */ constructor() public {} /** * @notice Called by the delegator on a delegate to initialize it for duty * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes calldata data) external { // Shh -- currently unused data; // Shh -- we don't ever want this hook to be marked pure if (false) { implementation = address(0); } require(msg.sender == address(this) || hasAdminRights(), "!self"); // Make sure admin storage is set up correctly __admin = address(0); __adminHasRights = false; __fuseAdminHasRights = false; } /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() internal { // Shh -- we don't ever want this hook to be marked pure if (false) { implementation = address(0); } } /** * @dev Internal function to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationInternal(address implementation_, bool allowResign, bytes memory becomeImplementationData) internal { // Check whitelist require(fuseAdmin.cEtherDelegateWhitelist(implementation, implementation_, allowResign), "!impl"); // Call _resignImplementation internally (this delegate's code) if (allowResign) _resignImplementation(); // Get old implementation address oldImplementation = implementation; // Store new implementation implementation = implementation_; // Call _becomeImplementation externally (delegating to new delegate's code) _functionCall(address(this), abi.encodeWithSignature("_becomeImplementation(bytes)", becomeImplementationData), "!become"); // Emit event emit NewImplementation(oldImplementation, implementation); } /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationSafe(address implementation_, bool allowResign, bytes calldata becomeImplementationData) external { // Check admin rights require(hasAdminRights(), "!admin"); // Set implementation _setImplementationInternal(implementation_, allowResign, becomeImplementationData); } /** * @notice Function called before all delegator functions * @dev Checks comptroller.autoImplementation and upgrades the implementation if necessary */ function _prepare() external payable { if (msg.sender != address(this) && ComptrollerV3Storage(address(comptroller)).autoImplementation()) { (address latestCEtherDelegate, bool allowResign, bytes memory becomeImplementationData) = fuseAdmin.latestCEtherDelegate(implementation); if (implementation != latestCEtherDelegate) _setImplementationInternal(latestCEtherDelegate, allowResign, becomeImplementationData); } } }
pragma solidity ^0.5.16; import "./CTokenInterfaces.sol"; import "./ComptrollerStorage.sol"; /** * @title Compound's CEtherDelegator Contract * @notice CTokens which wrap Ether and delegate to an implementation * @author Compound */ contract CEtherDelegator is CDelegationStorage { /** * @notice Construct a new CEther money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token * @param implementation_ The address of the implementation the contract delegates to * @param becomeImplementationData The encoded args for becomeImplementation */ constructor(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, string memory name_, string memory symbol_, address implementation_, bytes memory becomeImplementationData, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) public { // First delegate gets to initialize the delegator (i.e. storage contract) delegateTo(implementation_, abi.encodeWithSignature("initialize(address,address,string,string,uint256,uint256)", comptroller_, interestRateModel_, name_, symbol_, reserveFactorMantissa_, adminFeeMantissa_)); // New implementations always get set via the settor (post-initialize) delegateTo(implementation_, abi.encodeWithSignature("_setImplementationSafe(address,bool,bytes)", implementation_, false, becomeImplementationData)); } /** * @notice Internal method to delegate execution to another contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts * @param callee The contract to delegatecall * @param data The raw data to delegatecall * @return The returned bytes from the delegatecall */ function delegateTo(address callee, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returnData) = callee.delegatecall(data); assembly { if eq(success, 0) { revert(add(returnData, 0x20), returndatasize) } } return returnData; } /** * @notice Delegates execution to an implementation contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts */ function () external payable { // Check for automatic implementation delegateTo(implementation, abi.encodeWithSignature("_prepare()")); // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
pragma solidity ^0.5.16; import "./CToken.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./PriceOracle.sol"; import "./ComptrollerInterface.sol"; import "./ComptrollerStorage.sol"; import "./Unitroller.sol"; /** * @title Compound's Comptroller Contract * @author Compound * @dev This was the first version of the Comptroller brains. * We keep it so our tests can continue to do the real-life behavior of upgrading from this logic forward. */ contract ComptrollerG1 is ComptrollerV1Storage, ComptrollerInterface, ComptrollerErrorReporter, Exponential { struct Market { /** * @notice Whether or not this market is listed */ bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint collateralFactorMantissa; /** * @notice Per-market mapping of "accounts in this asset" */ mapping(address => bool) accountMembership; } /** * @notice Official mapping of cTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /** * @notice Emitted when an admin supports a market */ event MarketListed(CToken cToken); /** * @notice Emitted when an account enters a market */ event MarketEntered(CToken cToken, address account); /** * @notice Emitted when an account exits a market */ event MarketExited(CToken cToken, address account); /** * @notice Emitted when close factor is changed by admin */ event NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa); /** * @notice Emitted when a collateral factor is changed by admin */ event NewCollateralFactor(CToken cToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa); /** * @notice Emitted when liquidation incentive is changed by admin */ event NewLiquidationIncentive(uint oldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa); /** * @notice Emitted when maxAssets is changed by admin */ event NewMaxAssets(uint oldMaxAssets, uint newMaxAssets); /** * @notice Emitted when price oracle is changed */ event NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle); // closeFactorMantissa must be strictly greater than this value uint constant closeFactorMinMantissa = 5e16; // 0.05 // closeFactorMantissa must not exceed this value uint constant closeFactorMaxMantissa = 9e17; // 0.9 // No collateralFactorMantissa may exceed this value uint constant collateralFactorMaxMantissa = 9e17; // 0.9 // liquidationIncentiveMantissa must be no less than this value uint constant liquidationIncentiveMinMantissa = mantissaOne; // liquidationIncentiveMantissa must be no greater than this value uint constant liquidationIncentiveMaxMantissa = 15e17; // 1.5 constructor() public { admin = msg.sender; } /*** Assets You Are In ***/ /** * @notice Returns the assets an account has entered * @param account The address of the account to pull assets for * @return A dynamic list with the assets the account has entered */ function getAssetsIn(address account) external view returns (CToken[] memory) { CToken[] memory assetsIn = accountAssets[account]; return assetsIn; } /** * @notice Returns whether the given account is entered in the given asset * @param account The address of the account to check * @param cToken The cToken to check * @return True if the account is in the asset, otherwise false. */ function checkMembership(address account, CToken cToken) external view returns (bool) { return markets[address(cToken)].accountMembership[account]; } /** * @notice Add assets to be included in account liquidity calculation * @param cTokens The list of addresses of the cToken markets to be enabled * @return Success indicator for whether each corresponding market was entered */ function enterMarkets(address[] memory cTokens) public returns (uint[] memory) { uint len = cTokens.length; uint[] memory results = new uint[](len); for (uint i = 0; i < len; i++) { CToken cToken = CToken(cTokens[i]); Market storage marketToJoin = markets[address(cToken)]; if (!marketToJoin.isListed) { // if market is not listed, cannot join move along results[i] = uint(Error.MARKET_NOT_LISTED); continue; } if (marketToJoin.accountMembership[msg.sender] == true) { // if already joined, move along results[i] = uint(Error.NO_ERROR); continue; } if (accountAssets[msg.sender].length >= maxAssets) { // if no space, cannot join, move along results[i] = uint(Error.TOO_MANY_ASSETS); continue; } // 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[msg.sender] = true; accountAssets[msg.sender].push(cToken); emit MarketEntered(cToken, msg.sender); results[i] = uint(Error.NO_ERROR); } return results; } /** * @notice Removes asset from sender's account liquidity calculation * @dev Sender must not have an outstanding borrow balance in the asset, * or be providing neccessary collateral for an outstanding borrow. * @param cTokenAddress The address of the asset to be removed * @return Whether or not the account successfully exited the market */ function exitMarket(address cTokenAddress) external returns (uint) { CToken cToken = CToken(cTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the cToken */ (uint oErr, uint tokensHeld, uint amountOwed, ) = cToken.getAccountSnapshot(msg.sender); require(oErr == 0, "exitMarket: getAccountSnapshot failed"); // semi-opaque error code /* Fail if the sender has a borrow balance */ if (amountOwed != 0) { return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED); } /* Fail if the sender is not permitted to redeem all of their tokens */ uint allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[address(cToken)]; /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint(Error.NO_ERROR); } /* Set cToken account membership to false */ delete marketToExit.accountMembership[msg.sender]; /* Delete cToken from the account’s list of assets */ // load into memory for faster iteration CToken[] memory userAssetList = accountAssets[msg.sender]; uint len = userAssetList.length; uint assetIndex = len; for (uint i = 0; i < len; i++) { if (userAssetList[i] == cToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 CToken[] storage storedList = accountAssets[msg.sender]; storedList[assetIndex] = storedList[storedList.length - 1]; storedList.length--; emit MarketExited(cToken, msg.sender); return uint(Error.NO_ERROR); } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param cToken The market to verify the mint against * @param minter The account which would get the minted tokens * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint) { minter; // currently unused mintAmount; // currently unused if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // *may include Policy Hook-type checks return uint(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 mintAmount The amount of the underlying asset being minted * @param mintTokens The number of tokens being minted */ function mintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) external { cToken; // currently unused minter; // currently unused mintAmount; // currently unused mintTokens; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /** * @notice Checks if the account should be allowed to redeem tokens in the given market * @param cToken The market to verify the redeem against * @param redeemer The account which would redeem the tokens * @param redeemTokens The number of cTokens to exchange for the underlying asset in the market * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint) { return redeemAllowedInternal(cToken, redeemer, redeemTokens); } function redeemAllowedInternal(address cToken, address redeemer, uint redeemTokens) internal view returns (uint) { if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // *may include Policy Hook-type checks /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */ if (!markets[cToken].accountMembership[redeemer]) { return uint(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(redeemer, CToken(cToken), redeemTokens, 0); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates redeem and reverts on rejection. May emit logs. * @param cToken Asset being redeemed * @param redeemer The address redeeming the tokens * @param redeemAmount The amount of the underlying asset being redeemed * @param redeemTokens The number of tokens being redeemed */ function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external { cToken; // currently unused redeemer; // currently unused redeemAmount; // currently unused redeemTokens; // currently unused // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("redeemTokens zero"); } } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param cToken The market to verify the borrow against * @param borrower The account which would borrow the asset * @param borrowAmount The amount of underlying the account would borrow * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint) { if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // *may include Policy Hook-type checks if (!markets[cToken].accountMembership[borrower]) { return uint(Error.MARKET_NOT_ENTERED); } if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { return uint(Error.PRICE_ERROR); } (Error err, , uint shortfall) = getHypotheticalAccountLiquidityInternal(borrower, CToken(cToken), 0, borrowAmount); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall > 0) { return uint(Error.INSUFFICIENT_LIQUIDITY); } return uint(Error.NO_ERROR); } /** * @notice Validates borrow and reverts on rejection. May emit logs. * @param cToken Asset whose underlying is being borrowed * @param borrower The address borrowing the underlying * @param borrowAmount The amount of the underlying asset requested to borrow */ function borrowVerify(address cToken, address borrower, uint borrowAmount) external { cToken; // currently unused borrower; // currently unused borrowAmount; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /** * @notice Checks if the account should be allowed to repay a borrow in the given market * @param cToken The market to verify the repay against * @param payer The account which would repay the asset * @param borrower The account which would borrowed the asset * @param repayAmount The amount of the underlying asset the account would repay * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint) { payer; // currently unused borrower; // currently unused repayAmount; // currently unused if (!markets[cToken].isListed) { return uint(Error.MARKET_NOT_LISTED); } // *may include Policy Hook-type checks return uint(Error.NO_ERROR); } /** * @notice Validates repayBorrow and reverts on rejection. May emit logs. * @param cToken Asset being repaid * @param payer The address repaying the borrow * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function repayBorrowVerify( address cToken, address payer, address borrower, uint repayAmount, uint borrowerIndex) external { cToken; // currently unused payer; // currently unused borrower; // currently unused repayAmount; // currently unused borrowerIndex; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /** * @notice Checks if the liquidation should be allowed to occur * @param cTokenBorrowed Asset which was borrowed by the borrower * @param cTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint) { liquidator; // currently unused borrower; // currently unused repayAmount; // currently unused if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) { return uint(Error.MARKET_NOT_LISTED); } // *may include Policy Hook-type checks /* The borrower must have shortfall in order to be liquidatable */ (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower); if (err != Error.NO_ERROR) { return uint(err); } if (shortfall == 0) { return uint(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint borrowBalance = CToken(cTokenBorrowed).borrowBalanceStored(borrower); (MathError mathErr, uint maxClose) = mulScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance); if (mathErr != MathError.NO_ERROR) { return uint(Error.MATH_ERROR); } if (repayAmount > maxClose) { return uint(Error.TOO_MUCH_REPAY); } return uint(Error.NO_ERROR); } /** * @notice Validates liquidateBorrow and reverts on rejection. May emit logs. * @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 liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount, uint seizeTokens) external { cTokenBorrowed; // currently unused cTokenCollateral; // currently unused liquidator; // currently unused borrower; // currently unused repayAmount; // currently unused seizeTokens; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /** * @notice Checks if the seizing of assets should be allowed to occur * @param cTokenCollateral Asset which was used as collateral and will be seized * @param cTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint) { liquidator; // currently unused borrower; // currently unused seizeTokens; // currently unused if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) { return uint(Error.MARKET_NOT_LISTED); } if (CToken(cTokenCollateral).comptroller() != CToken(cTokenBorrowed).comptroller()) { return uint(Error.COMPTROLLER_MISMATCH); } // *may include Policy Hook-type checks return uint(Error.NO_ERROR); } /** * @notice Validates seize and reverts on rejection. May emit logs. * @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 seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external { cTokenCollateral; // currently unused cTokenBorrowed; // currently unused liquidator; // currently unused borrower; // currently unused seizeTokens; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param cToken The market to verify the transfer against * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint) { cToken; // currently unused src; // currently unused dst; // currently unused transferTokens; // currently unused // *may include Policy Hook-type checks // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens return redeemAllowedInternal(cToken, src, transferTokens); } /** * @notice Validates transfer and reverts on rejection. May emit logs. * @param cToken Asset being transferred * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of cTokens to transfer */ function transferVerify(address cToken, address src, address dst, uint transferTokens) external { cToken; // currently unused src; // currently unused dst; // currently unused transferTokens; // currently unused if (false) { maxAssets = maxAssets; // not pure } } /*** Liquidity/Liquidation Calculations ***/ /** * @dev Local vars for avoiding stack-depth limits in calculating account liquidity. * Note that `cTokenBalance` is the number of cTokens the account owns in the market, * whereas `borrowBalance` is the amount of underlying that the account has borrowed. */ struct AccountLiquidityLocalVars { uint sumCollateral; uint sumBorrowPlusEffects; uint cTokenBalance; uint borrowBalance; uint exchangeRateMantissa; uint oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToEther; } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code (semi-opaque), account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidity(address account) public view returns (uint, uint, uint) { (Error err, uint liquidity, uint shortfall) = getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); return (uint(err), liquidity, shortfall); } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code, account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) { return getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param cTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @dev Note that we calculate the exchangeRateStored for each collateral cToken using stored data, * without calculating accumulated interest. * @return (possible error code, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, CToken cTokenModify, uint redeemTokens, uint borrowAmount) internal view returns (Error, uint, uint) { AccountLiquidityLocalVars memory vars; // Holds all our calculation results uint oErr; MathError mErr; // For each asset the account is in CToken[] memory assets = accountAssets[account]; for (uint i = 0; i < assets.length; i++) { CToken asset = assets[i]; // Read the balances and exchange rate from the cToken (oErr, vars.cTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot(account); if (oErr != 0) { // semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades return (Error.SNAPSHOT_ERROR, 0, 0); } vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa}); vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa}); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0); } vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa}); // Pre-compute a conversion factor from tokens -> ether (normalized price value) (mErr, vars.tokensToEther) = mulExp3(vars.collateralFactor, vars.exchangeRate, vars.oraclePrice); if (mErr != MathError.NO_ERROR) { return (Error.MATH_ERROR, 0, 0); } // sumCollateral += tokensToEther * cTokenBalance (mErr, vars.sumCollateral) = mulScalarTruncateAddUInt(vars.tokensToEther, vars.cTokenBalance, vars.sumCollateral); if (mErr != MathError.NO_ERROR) { return (Error.MATH_ERROR, 0, 0); } // sumBorrowPlusEffects += oraclePrice * borrowBalance (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects); if (mErr != MathError.NO_ERROR) { return (Error.MATH_ERROR, 0, 0); } // Calculate effects of interacting with cTokenModify if (asset == cTokenModify) { // redeem effect // sumBorrowPlusEffects += tokensToEther * redeemTokens (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.tokensToEther, redeemTokens, vars.sumBorrowPlusEffects); if (mErr != MathError.NO_ERROR) { return (Error.MATH_ERROR, 0, 0); } // borrow effect // sumBorrowPlusEffects += oraclePrice * borrowAmount (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects); if (mErr != MathError.NO_ERROR) { return (Error.MATH_ERROR, 0, 0); } } } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral); } } /** * @notice Calculate number of tokens of collateral asset to seize given an underlying amount * @dev Used in liquidation (called in cToken.liquidateBorrowFresh) * @param cTokenBorrowed The address of the borrowed cToken * @param cTokenCollateral The address of the collateral cToken * @param repayAmount The amount of cTokenBorrowed underlying to convert into cTokenCollateral tokens * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation) */ function liquidateCalculateSeizeTokens(address cTokenBorrowed, address cTokenCollateral, uint repayAmount) external view returns (uint, uint) { /* Read oracle prices for borrowed and collateral markets */ uint priceBorrowedMantissa = oracle.getUnderlyingPrice(CToken(cTokenBorrowed)); uint priceCollateralMantissa = oracle.getUnderlyingPrice(CToken(cTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint(Error.PRICE_ERROR), 0); } /* * Get the exchange rate and calculate the number of collateral tokens to seize: * seizeAmount = repayAmount * liquidationIncentive * priceBorrowed / priceCollateral * seizeTokens = seizeAmount / exchangeRate * = repayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate) */ uint exchangeRateMantissa = CToken(cTokenCollateral).exchangeRateStored(); // Note: reverts on error uint seizeTokens; Exp memory numerator; Exp memory denominator; Exp memory ratio; MathError mathErr; (mathErr, numerator) = mulExp(liquidationIncentiveMantissa, priceBorrowedMantissa); if (mathErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0); } (mathErr, denominator) = mulExp(priceCollateralMantissa, exchangeRateMantissa); if (mathErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0); } (mathErr, ratio) = divExp(numerator, denominator); if (mathErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0); } (mathErr, seizeTokens) = mulScalarTruncate(ratio, repayAmount); if (mathErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0); } return (uint(Error.NO_ERROR), seizeTokens); } /*** Admin Functions ***/ /** * @notice Sets a new price oracle for the comptroller * @dev Admin function to set a new price oracle * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPriceOracle(PriceOracle newOracle) public returns (uint) { // Check caller is admin OR currently initialzing as new unitroller implementation if (!adminOrInitializing()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the comptroller PriceOracle oldOracle = oracle; // Ensure invoke newOracle.isPriceOracle() returns true // require(newOracle.isPriceOracle(), "oracle method isPriceOracle returned false"); // Set comptroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint(Error.NO_ERROR); } /** * @notice Sets the closeFactor used when liquidating borrows * @dev Admin function to set closeFactor * @param newCloseFactorMantissa New close factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCloseFactor(uint newCloseFactorMantissa) external returns (uint256) { // Check caller is admin OR currently initialzing as new unitroller implementation if (!adminOrInitializing()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_CLOSE_FACTOR_OWNER_CHECK); } 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); } uint oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets the collateralFactor for a market * @dev Admin function to set per-market collateralFactor * @param cToken The market to set the factor on * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCollateralFactor(CToken cToken, uint newCollateralFactorMantissa) external returns (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 uint oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(cToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Sets maxAssets which controls how many markets can be entered * @dev Admin function to set maxAssets * @param newMaxAssets New max assets * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setMaxAssets(uint newMaxAssets) external returns (uint) { // Check caller is admin OR currently initialzing as new unitroller implementation if (!adminOrInitializing()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_MAX_ASSETS_OWNER_CHECK); } uint oldMaxAssets = maxAssets; maxAssets = newMaxAssets; emit NewMaxAssets(oldMaxAssets, newMaxAssets); return uint(Error.NO_ERROR); } /** * @notice Sets liquidationIncentive * @dev Admin function to set liquidationIncentive * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external returns (uint) { // Check caller is admin OR currently initialzing as new unitroller implementation if (!adminOrInitializing()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK); } // Check de-scaled 1 <= newLiquidationDiscount <= 1.5 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 uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint(Error.NO_ERROR); } /** * @notice Add the market to the markets mapping and set it as listed * @dev Admin function to set isListed and add support for the market * @param cToken The address of the market (token) to list * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _supportMarket(CToken cToken) external returns (uint) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK); } if (markets[address(cToken)].isListed) { return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS); } cToken.isCToken(); // Sanity check to make sure its really a CToken markets[address(cToken)] = Market({isListed: true, collateralFactorMantissa: 0}); emit MarketListed(cToken); return uint(Error.NO_ERROR); } function _become(Unitroller unitroller, PriceOracle _oracle, uint _closeFactorMantissa, uint _maxAssets, bool reinitializing) public { require(msg.sender == unitroller.admin(), "only unitroller admin can change brains"); uint changeStatus = unitroller._acceptImplementation(); require(changeStatus == 0, "change not authorized"); if (!reinitializing) { ComptrollerG1 freshBrainedComptroller = ComptrollerG1(address(unitroller)); // Ensure invoke _setPriceOracle() = 0 uint err = freshBrainedComptroller._setPriceOracle(_oracle); require (err == uint(Error.NO_ERROR), "set price oracle error"); // Ensure invoke _setCloseFactor() = 0 err = freshBrainedComptroller._setCloseFactor(_closeFactorMantissa); require (err == uint(Error.NO_ERROR), "set close factor error"); // Ensure invoke _setMaxAssets() = 0 err = freshBrainedComptroller._setMaxAssets(_maxAssets); require (err == uint(Error.NO_ERROR), "set max asssets error"); // Ensure invoke _setLiquidationIncentive(liquidationIncentiveMinMantissa) = 0 err = freshBrainedComptroller._setLiquidationIncentive(liquidationIncentiveMinMantissa); require (err == uint(Error.NO_ERROR), "set liquidation incentive error"); } } /** * @dev Check that caller is admin or this contract is initializing itself as * the new implementation. * There should be no way to satisfy msg.sender == comptrollerImplementaiton * without tx.origin also being admin, but both are included for extra safety */ function adminOrInitializing() internal view returns (bool) { bool initializing = ( msg.sender == comptrollerImplementation && //solium-disable-next-line security/no-tx-origin tx.origin == admin ); bool isAdmin = hasAdminRights(); return isAdmin || initializing; } }
pragma solidity ^0.5.16; contract ComptrollerInterface { /// @notice Indicator that this is a Comptroller contract (for inspection) bool public constant isComptroller = true; /*** Assets You Are In ***/ function enterMarkets(address[] calldata cTokens) external returns (uint[] memory); function exitMarket(address cToken) external returns (uint); /*** Policy Hooks ***/ function mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint); function mintWithinLimits(address cToken, uint exchangeRateMantissa, uint accountTokens, uint mintAmount) external returns (uint); function mintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) external; function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint); function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external; function borrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint); function borrowWithinLimits(address cToken, uint accountBorrowsNew) external returns (uint); function borrowVerify(address cToken, address borrower, uint borrowAmount) external; function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) external returns (uint); function repayBorrowVerify( address cToken, address payer, address borrower, uint repayAmount, uint borrowerIndex) external; function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint); function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount, uint seizeTokens) external; function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint); function seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external; function transferAllowed(address cToken, address src, address dst, uint transferTokens) external returns (uint); function transferVerify(address cToken, address src, address dst, uint transferTokens) external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint repayAmount) external view returns (uint, uint); /*** Pool-Wide/Cross-Asset Reentrancy Prevention ***/ function _beforeNonReentrant() external; function _afterNonReentrant() external; }
pragma solidity ^0.5.16; import "./IFuseFeeDistributor.sol"; import "./CToken.sol"; import "./PriceOracle.sol"; contract UnitrollerAdminStorage { /** * @notice Administrator for Fuse */ IFuseFeeDistributor internal constant fuseAdmin = IFuseFeeDistributor(0x4AFB2B3DC111D091ca6C46C024d1d2f17BF477e1); /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Whether or not the Fuse admin has admin rights */ bool public fuseAdminHasRights = 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(fuseAdmin) && fuseAdminHasRights); } /** * @notice Active brains of Unitroller */ address public comptrollerImplementation; /** * @notice Pending brains of Unitroller */ address public pendingComptrollerImplementation; } contract ComptrollerV1Storage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ PriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint public liquidationIncentiveMantissa; /** * @notice UNUSED AFTER UPGRADE: Max number of assets a single account can participate in (borrow or use as collateral) */ uint internal maxAssets; /** * @notice Per-account mapping of "assets you are in", capped by maxAssets */ mapping(address => CToken[]) public accountAssets; } contract ComptrollerV2Storage is ComptrollerV1Storage { struct Market { /** * @notice Whether or not this market is listed */ bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint collateralFactorMantissa; /** * @notice Per-market mapping of "accounts in this asset" */ mapping(address => bool) accountMembership; } /** * @notice Official mapping of cTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /// @notice A list of all markets CToken[] 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; /// @notice 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 => CToken) 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; /// @notice 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 { /** * @dev Whether or not the implementation should be auto-upgraded. */ bool public autoImplementation; /// @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market. address public borrowCapGuardian; /// @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing. mapping(address => uint) public borrowCaps; /// @notice Supply caps enforced by mintAllowed for each cToken address. Defaults to zero which corresponds to unlimited supplying. mapping(address => uint) 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; }
pragma solidity ^0.5.16; import "./ComptrollerInterface.sol"; import "./CTokenInterfaces.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./EIP20Interface.sol"; import "./EIP20NonStandardInterface.sol"; import "./InterestRateModel.sol"; /** * @title Compound's CToken Contract * @notice Abstract base for CTokens * @author Compound */ contract CToken is CTokenInterface, Exponential, TokenErrorReporter { /** * @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(fuseAdmin) && comptrollerStorage.fuseAdminHasRights()); } /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) public { require(msg.sender == address(fuseAdmin), "only Fuse admin may initialize the market"); require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the comptroller uint err = _setComptroller(comptroller_); require(err == uint(Error.NO_ERROR), "setting comptroller failed"); // Initialize block number and borrow index (block number mocks depend on comptroller being set) accrualBlockNumber = getBlockNumber(); borrowIndex = mantissaOne; // Set the interest rate model (depends on block number / borrow index) err = _setInterestRateModelFresh(interestRateModel_); require(err == uint(Error.NO_ERROR), "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // Set reserve factor err = _setReserveFactorFresh(reserveFactorMantissa_); require(err == uint(Error.NO_ERROR), "setting reserve factor failed"); // Set admin fee err = _setAdminFeeFresh(adminFeeMantissa_); require(err == uint(Error.NO_ERROR), "setting admin fee failed"); // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @dev Returns latest pending Fuse fee (to be set with `_setFuseFeeFresh`) */ function getPendingFuseFeeFromAdmin() internal view returns (uint) { return fuseAdmin.interestFeeRate(); } /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally * @param spender The address of the account performing the transfer * @param src The address of the source account * @param dst The address of the destination account * @param tokens The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) { /* Fail if transfer not allowed */ uint allowed = comptroller.transferAllowed(address(this), src, dst, tokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed); } /* Do not allow self-transfers */ if (src == dst) { return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED); } /* Get the allowance, infinite for the account owner */ uint startingAllowance = 0; if (spender == src) { startingAllowance = uint(-1); } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ MathError mathErr; uint allowanceNew; uint srcTokensNew; uint dstTokensNew; (mathErr, allowanceNew) = subUInt(startingAllowance, tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED); } (mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH); } (mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens); if (mathErr != MathError.NO_ERROR) { return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) accountTokens[src] = srcTokensNew; accountTokens[dst] = dstTokensNew; /* Eat some of the allowance (if necessary) */ if (startingAllowance != uint(-1)) { transferAllowances[src][spender] = allowanceNew; } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); /* We call the defense hook */ // unused function // comptroller.transferVerify(address(this), src, dst, tokens); return uint(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external nonReentrant(false) returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external nonReentrant(false) returns (bool) { return transferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR); } /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool) { address src = msg.sender; transferAllowances[src][spender] = amount; emit Approval(src, spender, amount); return true; } /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256) { return transferAllowances[owner][spender]; } /** * @notice Get the token balance of the `owner` * @param owner The address of the account to query * @return The number of tokens owned by `owner` */ function balanceOf(address owner) external view returns (uint256) { return accountTokens[owner]; } /** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */ function balanceOfUnderlying(address owner) external returns (uint) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); (MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]); require(mErr == MathError.NO_ERROR, "balance could not be calculated"); return balance; } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by comptroller to more efficiently perform liquidity checks. * @param account Address of the account to snapshot * @return (possible error, token balance, borrow balance, exchange rate mantissa) */ function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint) { uint cTokenBalance = accountTokens[account]; uint borrowBalance; uint exchangeRateMantissa; MathError mErr; (mErr, borrowBalance) = borrowBalanceStoredInternal(account); if (mErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0, 0, 0); } (mErr, exchangeRateMantissa) = exchangeRateStoredInternal(); if (mErr != MathError.NO_ERROR) { return (uint(Error.MATH_ERROR), 0, 0, 0); } return (uint(Error.NO_ERROR), cTokenBalance, borrowBalance, exchangeRateMantissa); } /** * @dev Function to simply retrieve block number * This exists mainly for inheriting test contracts to stub this result. */ function getBlockNumber() internal view returns (uint) { return block.number; } /** * @notice Returns the current per-block borrow interest rate for this cToken * @return The borrow interest rate per block, scaled by 1e18 */ function borrowRatePerBlock() external view returns (uint) { return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, add_(totalReserves, add_(totalAdminFees, totalFuseFees))); } /** * @notice Returns the current per-block supply interest rate for this cToken * @return The supply interest rate per block, scaled by 1e18 */ function supplyRatePerBlock() external view returns (uint) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, add_(totalReserves, add_(totalAdminFees, totalFuseFees)), reserveFactorMantissa + fuseFeeMantissa + adminFeeMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external nonReentrant(false) returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return totalBorrows; } /** * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex * @param account The address whose balance should be calculated after updating borrowIndex * @return The calculated balance */ function borrowBalanceCurrent(address account) external nonReentrant(false) returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return borrowBalanceStored(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return The calculated balance */ function borrowBalanceStored(address account) public view returns (uint) { (MathError err, uint result) = borrowBalanceStoredInternal(account); require(err == MathError.NO_ERROR, "borrowBalanceStored: borrowBalanceStoredInternal failed"); return result; } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return (error code, the calculated balance or 0 if error code is non-zero) */ function borrowBalanceStoredInternal(address account) internal view returns (MathError, uint) { /* Note: we do not assert that the market is up to date */ MathError mathErr; uint principalTimesIndex; uint result; /* Get borrowBalance and borrowIndex */ BorrowSnapshot storage borrowSnapshot = accountBorrows[account]; /* If borrowBalance = 0 then borrowIndex is likely also 0. * Rather than failing the calculation with a division by 0, we immediately return 0 in this case. */ if (borrowSnapshot.principal == 0) { return (MathError.NO_ERROR, 0); } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ (mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal, borrowIndex); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, result); } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public nonReentrant(false) returns (uint) { require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed"); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view returns (uint) { (MathError err, uint result) = exchangeRateStoredInternal(); require(err == MathError.NO_ERROR, "exchangeRateStored: exchangeRateStoredInternal failed"); return result; } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return (error code, calculated exchange rate scaled by 1e18) */ function exchangeRateStoredInternal() internal view returns (MathError, uint) { uint _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return (MathError.NO_ERROR, initialExchangeRateMantissa); } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - (totalReserves + totalFuseFees + totalAdminFees)) / totalSupply */ uint totalCash = getCashPrior(); uint cashPlusBorrowsMinusReserves; Exp memory exchangeRate; MathError mathErr; (mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, add_(totalReserves, add_(totalAdminFees, totalFuseFees))); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, _totalSupply); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, exchangeRate.mantissa); } } /** * @notice Get cash balance of this cToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view returns (uint) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public returns (uint) { /* Remember the initial block number */ uint currentBlockNumber = getBlockNumber(); /* Short-circuit accumulating 0 interest */ if (accrualBlockNumber == currentBlockNumber) { return uint(Error.NO_ERROR); } /* Read the previous values out of storage */ uint cashPrior = getCashPrior(); /* Calculate the current borrow interest rate */ uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, totalBorrows, add_(totalReserves, add_(totalAdminFees, totalFuseFees))); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of blocks elapsed since the last accrual */ (MathError mathErr, uint blockDelta) = subUInt(currentBlockNumber, accrualBlockNumber); require(mathErr == MathError.NO_ERROR, "could not calculate block delta"); return finishInterestAccrual(currentBlockNumber, cashPrior, borrowRateMantissa, blockDelta); } /** * @dev Split off from `accrueInterest` to avoid "stack too deep" error". */ function finishInterestAccrual(uint currentBlockNumber, uint cashPrior, uint borrowRateMantissa, uint blockDelta) private returns (uint) { /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * blockDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * totalFuseFeesNew = interestAccumulated * fuseFee + totalFuseFees * totalAdminFeesNew = interestAccumulated * adminFee + totalAdminFees * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor = mul_(Exp({mantissa: borrowRateMantissa}), blockDelta); uint interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, totalBorrows); uint totalBorrowsNew = add_(interestAccumulated, totalBorrows); uint totalReservesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, totalReserves); uint totalFuseFeesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: fuseFeeMantissa}), interestAccumulated, totalFuseFees); uint totalAdminFeesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: adminFeeMantissa}), interestAccumulated, totalAdminFees); uint borrowIndexNew = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndex, borrowIndex); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accrualBlockNumber = currentBlockNumber; borrowIndex = borrowIndexNew; totalBorrows = totalBorrowsNew; totalReserves = totalReservesNew; totalFuseFees = totalFuseFeesNew; totalAdminFees = totalAdminFeesNew; /* We emit an AccrueInterest event */ emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew); // Attempt to add interest checkpoint address(interestRateModel).call(abi.encodeWithSignature("checkpointInterest(uint256)", borrowRateMantissa)); return uint(Error.NO_ERROR); } /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint mintAmount) internal nonReentrant(false) returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0); } // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to return mintFresh(msg.sender, mintAmount); } struct MintLocalVars { Error err; MathError mathErr; uint exchangeRateMantissa; uint mintTokens; uint totalSupplyNew; uint accountTokensNew; uint actualMintAmount; } /** * @notice User supplies assets into the market and receives cTokens in exchange * @dev Assumes interest has already been accrued up to the current block * @param minter The address of the account which is supplying the assets * @param mintAmount The amount of the underlying asset to supply * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintFresh(address minter, uint mintAmount) internal returns (uint, uint) { /* Fail if mint not allowed */ uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK), 0); } MintLocalVars memory vars; (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return (failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)), 0); } // Check max supply // unused function /* allowed = comptroller.mintWithinLimits(address(this), vars.exchangeRateMantissa, accountTokens[minter], mintAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed), 0); } */ ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call `doTransferIn` for the minter and the mintAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * `doTransferIn` reverts if anything goes wrong, since we can't be sure if * side-effects occurred. The function returns the amount actually transferred, * in case of a fee. On success, the cToken holds an additional `actualMintAmount` * of cash. */ vars.actualMintAmount = doTransferIn(minter, mintAmount); /* * We get the current exchange rate and calculate the number of cTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ (vars.mathErr, vars.mintTokens) = divScalarByExpTruncate(vars.actualMintAmount, Exp({mantissa: vars.exchangeRateMantissa})); require(vars.mathErr == MathError.NO_ERROR, "MINT_EXCHANGE_CALCULATION_FAILED"); /* * We calculate the new total supply of cTokens and minter token balance, checking for overflow: * totalSupplyNew = totalSupply + mintTokens * accountTokensNew = accountTokens[minter] + mintTokens */ vars.totalSupplyNew = add_(totalSupply, vars.mintTokens); vars.accountTokensNew = add_(accountTokens[minter], vars.mintTokens); /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[minter] = vars.accountTokensNew; /* We emit a Mint event, and a Transfer event */ emit Mint(minter, vars.actualMintAmount, vars.mintTokens); emit Transfer(address(this), minter, vars.mintTokens); /* We call the defense hook */ comptroller.mintVerify(address(this), minter, vars.actualMintAmount, vars.mintTokens); return (uint(Error.NO_ERROR), vars.actualMintAmount); } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint redeemTokens) internal nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, redeemTokens, 0); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming cTokens * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, 0, redeemAmount); } struct RedeemLocalVars { Error err; MathError mathErr; uint exchangeRateMantissa; uint redeemTokens; uint redeemAmount; uint totalSupplyNew; uint accountTokensNew; } /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of cTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @param redeemAmountIn The number of underlying tokens to receive from redeeming cTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal returns (uint) { require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero"); RedeemLocalVars memory vars; /* exchangeRate = invoke Exchange Rate Stored() */ (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr)); } /* If redeemTokensIn > 0: */ if (redeemTokensIn > 0) { /* * We calculate the exchange rate and the amount of underlying to be redeemed: * redeemTokens = redeemTokensIn * redeemAmount = redeemTokensIn x exchangeRateCurrent */ vars.redeemTokens = redeemTokensIn; (vars.mathErr, vars.redeemAmount) = mulScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), redeemTokensIn); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint(vars.mathErr)); } } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ (vars.mathErr, vars.redeemTokens) = divScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa})); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, uint(vars.mathErr)); } vars.redeemAmount = redeemAmountIn; } /* Fail if redeem not allowed */ uint allowed = comptroller.redeemAllowed(address(this), redeemer, vars.redeemTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REDEEM_COMPTROLLER_REJECTION, allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK); } /* * We calculate the new total supply and redeemer balance, checking for underflow: * totalSupplyNew = totalSupply - redeemTokens * accountTokensNew = accountTokens[redeemer] - redeemTokens */ (vars.mathErr, vars.totalSupplyNew) = subUInt(totalSupply, vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr)); } (vars.mathErr, vars.accountTokensNew) = subUInt(accountTokens[redeemer], vars.redeemTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } /* Fail gracefully if protocol has insufficient cash */ if (getCashPrior() < vars.redeemAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the redeemer and the redeemAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken has redeemAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(redeemer, vars.redeemAmount); /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[redeemer] = vars.accountTokensNew; /* We emit a Transfer event, and a Redeem event */ emit Transfer(redeemer, address(this), vars.redeemTokens); emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens); /* We call the defense hook */ comptroller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens); return uint(Error.NO_ERROR); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowInternal(uint borrowAmount) internal nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED); } // borrowFresh emits borrow-specific logs on errors, so we don't need to return borrowFresh(msg.sender, borrowAmount); } struct BorrowLocalVars { MathError mathErr; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowFresh(address payable borrower, uint borrowAmount) internal returns (uint) { /* Fail if borrow not allowed */ uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK); } /* Fail gracefully if protocol has insufficient underlying cash */ uint cashPrior = getCashPrior(); if (cashPrior < borrowAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE); } BorrowLocalVars memory vars; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } (vars.mathErr, vars.accountBorrowsNew) = addUInt(vars.accountBorrows, borrowAmount); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } // Check min borrow for this user for this asset allowed = comptroller.borrowWithinLimits(address(this), vars.accountBorrowsNew); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed); } (vars.mathErr, vars.totalBorrowsNew) = addUInt(totalBorrows, borrowAmount); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.borrowVerify(address(this), borrower, borrowAmount); return uint(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint repayAmount) internal nonReentrant(false) returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, msg.sender, repayAmount); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal(address borrower, uint repayAmount) internal nonReentrant(false) returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, borrower, repayAmount); } struct RepayBorrowLocalVars { Error err; MathError mathErr; uint repayAmount; uint borrowerIndex; uint accountBorrows; uint accountBorrowsNew; uint totalBorrowsNew; uint actualRepayAmount; } /** * @notice Borrows are repaid by another user (possibly the borrower). * @param payer the account paying off the borrow * @param borrower the account with the debt being payed off * @param repayAmount the amount of undelrying tokens being returned * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowFresh(address payer, address borrower, uint repayAmount) internal returns (uint, uint) { /* Fail if repayBorrow not allowed */ uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0); } RepayBorrowLocalVars memory vars; /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower); if (vars.mathErr != MathError.NO_ERROR) { return (failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr)), 0); } /* If repayAmount == -1, repayAmount = accountBorrows */ if (repayAmount == uint(-1)) { vars.repayAmount = vars.accountBorrows; } else { vars.repayAmount = repayAmount; } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the payer and the repayAmount * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken holds an additional repayAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ (vars.mathErr, vars.accountBorrowsNew) = subUInt(vars.accountBorrows, vars.actualRepayAmount); require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED"); (vars.mathErr, vars.totalBorrowsNew) = subUInt(totalBorrows, vars.actualRepayAmount); require(vars.mathErr == MathError.NO_ERROR, "REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED"); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.repayBorrowVerify(address(this), payer, borrower, vars.actualRepayAmount, vars.borrowerIndex); return (uint(Error.NO_ERROR), vars.actualRepayAmount); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowInternal(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal nonReentrant(false) returns (uint, uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0); } error = cTokenCollateral.accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal returns (uint, uint) { /* Fail if liquidate not allowed */ uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0); } /* Verify cTokenCollateral market's block number equals current block number */ if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0); } /* Fail if repayAmount = -1 */ if (repayAmount == uint(-1)) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0); } /* Fail if repayBorrow fails */ (uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount); if (repayBorrowError != uint(Error.NO_ERROR)) { return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), actualRepayAmount); require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED"); /* Revert if borrower collateral token balance < seizeTokens */ require(cTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH"); // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call uint seizeError; if (address(cTokenCollateral) == address(this)) { seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { seizeError = cTokenCollateral.seize(liquidator, borrower, seizeTokens); } /* Revert if seize tokens fails (since we cannot be sure of side effects) */ require(seizeError == uint(Error.NO_ERROR), "token seizure failed"); /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens); /* We call the defense hook */ // unused function // comptroller.liquidateBorrowVerify(address(this), address(cTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens); return (uint(Error.NO_ERROR), actualRepayAmount); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another cToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize(address liquidator, address borrower, uint seizeTokens) external nonReentrant(true) returns (uint) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } struct SeizeInternalLocalVars { MathError mathErr; uint borrowerTokensNew; uint liquidatorTokensNew; uint liquidatorSeizeTokens; uint protocolSeizeTokens; uint protocolSeizeAmount; uint exchangeRateMantissa; uint totalReservesNew; uint totalSupplyNew; } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken. * Its absolutely critical to use msg.sender as the seizer cToken and not a parameter. * @param seizerToken The contract seizing the collateral (i.e. borrowed cToken) * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal returns (uint) { /* Fail if seize not allowed */ uint allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER); } SeizeInternalLocalVars memory vars; /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ (vars.mathErr, vars.borrowerTokensNew) = subUInt(accountTokens[borrower], seizeTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, uint(vars.mathErr)); } vars.protocolSeizeTokens = mul_(seizeTokens, Exp({mantissa: protocolSeizeShareMantissa})); vars.liquidatorSeizeTokens = sub_(seizeTokens, vars.protocolSeizeTokens); (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal(); require(vars.mathErr == MathError.NO_ERROR, "exchange rate math error"); vars.protocolSeizeAmount = mul_ScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), vars.protocolSeizeTokens); vars.totalReservesNew = add_(totalReserves, vars.protocolSeizeAmount); vars.totalSupplyNew = sub_(totalSupply, vars.protocolSeizeTokens); (vars.mathErr, vars.liquidatorTokensNew) = addUInt(accountTokens[liquidator], vars.liquidatorSeizeTokens); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, uint(vars.mathErr)); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ totalReserves = vars.totalReservesNew; totalSupply = vars.totalSupplyNew; accountTokens[borrower] = vars.borrowerTokensNew; accountTokens[liquidator] = vars.liquidatorTokensNew; /* Emit a Transfer event */ emit Transfer(borrower, liquidator, vars.liquidatorSeizeTokens); emit Transfer(borrower, address(this), vars.protocolSeizeTokens); emit ReservesAdded(address(this), vars.protocolSeizeAmount, vars.totalReservesNew); /* We call the defense hook */ // unused function // comptroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens); return uint(Error.NO_ERROR); } /*** Admin Functions ***/ /** * @notice Sets a new comptroller for the market * @dev Internal function to set a new comptroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setComptroller(ComptrollerInterface newComptroller) internal returns (uint) { ComptrollerInterface oldComptroller = comptroller; // Ensure invoke comptroller.isComptroller() returns true require(newComptroller.isComptroller(), "marker method returned false"); // Set market's comptroller to newComptroller comptroller = newComptroller; // Emit NewComptroller(oldComptroller, newComptroller) emit NewComptroller(oldComptroller, newComptroller); return uint(Error.NO_ERROR); } /** * @notice accrues interest and sets a new admin fee for the protocol using _setAdminFeeFresh * @dev Admin function to accrue interest and set a new admin fee * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setAdminFee(uint newAdminFeeMantissa) external nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted admin fee change failed. return fail(Error(error), FailureInfo.SET_ADMIN_FEE_ACCRUE_INTEREST_FAILED); } // _setAdminFeeFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setAdminFeeFresh(newAdminFeeMantissa); } /** * @notice Sets a new admin fee for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new admin fee * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setAdminFeeFresh(uint newAdminFeeMantissa) internal returns (uint) { // Verify market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_ADMIN_FEE_FRESH_CHECK); } // Sanitize newAdminFeeMantissa if (newAdminFeeMantissa == uint(-1)) newAdminFeeMantissa = adminFeeMantissa; // Get latest Fuse fee uint newFuseFeeMantissa = getPendingFuseFeeFromAdmin(); // Check reserveFactorMantissa + newAdminFeeMantissa + newFuseFeeMantissa ≤ reserveFactorPlusFeesMaxMantissa if (add_(add_(reserveFactorMantissa, newAdminFeeMantissa), newFuseFeeMantissa) > reserveFactorPlusFeesMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_ADMIN_FEE_BOUNDS_CHECK); } // If setting admin fee if (adminFeeMantissa != newAdminFeeMantissa) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_ADMIN_FEE_ADMIN_CHECK); } // Set admin fee uint oldAdminFeeMantissa = adminFeeMantissa; adminFeeMantissa = newAdminFeeMantissa; // Emit event emit NewAdminFee(oldAdminFeeMantissa, newAdminFeeMantissa); } // If setting Fuse fee if (fuseFeeMantissa != newFuseFeeMantissa) { // Set Fuse fee uint oldFuseFeeMantissa = fuseFeeMantissa; fuseFeeMantissa = newFuseFeeMantissa; // Emit event emit NewFuseFee(oldFuseFeeMantissa, newFuseFeeMantissa); } return uint(Error.NO_ERROR); } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint newReserveFactorMantissa) external nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed. return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED); } // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) { // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK); } // Verify market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK); } // Check newReserveFactor ≤ maxReserveFactor if (add_(add_(newReserveFactorMantissa, adminFeeMantissa), fuseFeeMantissa) > reserveFactorPlusFeesMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK); } uint oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return uint(Error.NO_ERROR); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint reduceAmount) external nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED); } // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint reduceAmount) internal returns (uint) { // totalReserves - reduceAmount uint totalReservesNew; // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) // We checked reduceAmount <= totalReserves above, so this should never revert. totalReservesNew = sub_(totalReserves, reduceAmount); // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. doTransferOut(msg.sender, reduceAmount); emit ReservesReduced(msg.sender, reduceAmount, totalReservesNew); return uint(Error.NO_ERROR); } /** * @notice Accrues interest and reduces Fuse fees by transferring to Fuse * @param withdrawAmount Amount of fees to withdraw * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _withdrawFuseFees(uint withdrawAmount) external nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted Fuse fee withdrawal failed. return fail(Error(error), FailureInfo.WITHDRAW_FUSE_FEES_ACCRUE_INTEREST_FAILED); } // _withdrawFuseFeesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _withdrawFuseFeesFresh(withdrawAmount); } /** * @notice Reduces Fuse fees by transferring to Fuse * @dev Requires fresh interest accrual * @param withdrawAmount Amount of fees to withdraw * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _withdrawFuseFeesFresh(uint withdrawAmount) internal returns (uint) { // totalFuseFees - reduceAmount uint totalFuseFeesNew; // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.WITHDRAW_FUSE_FEES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < withdrawAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.WITHDRAW_FUSE_FEES_CASH_NOT_AVAILABLE); } // Check withdrawAmount ≤ fuseFees[n] (totalFuseFees) if (withdrawAmount > totalFuseFees) { return fail(Error.BAD_INPUT, FailureInfo.WITHDRAW_FUSE_FEES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) // We checked withdrawAmount <= totalFuseFees above, so this should never revert. totalFuseFeesNew = sub_(totalFuseFees, withdrawAmount); // Store fuseFees[n+1] = fuseFees[n] - withdrawAmount totalFuseFees = totalFuseFeesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. doTransferOut(address(fuseAdmin), withdrawAmount); return uint(Error.NO_ERROR); } /** * @notice Accrues interest and reduces admin fees by transferring to admin * @param withdrawAmount Amount of fees to withdraw * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _withdrawAdminFees(uint withdrawAmount) external nonReentrant(false) returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted admin fee withdrawal failed. return fail(Error(error), FailureInfo.WITHDRAW_ADMIN_FEES_ACCRUE_INTEREST_FAILED); } // _withdrawAdminFeesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _withdrawAdminFeesFresh(withdrawAmount); } /** * @notice Reduces admin fees by transferring to admin * @dev Requires fresh interest accrual * @param withdrawAmount Amount of fees to withdraw * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _withdrawAdminFeesFresh(uint withdrawAmount) internal returns (uint) { // totalAdminFees - reduceAmount uint totalAdminFeesNew; // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.WITHDRAW_ADMIN_FEES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < withdrawAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.WITHDRAW_ADMIN_FEES_CASH_NOT_AVAILABLE); } // Check withdrawAmount ≤ adminFees[n] (totalAdminFees) if (withdrawAmount > totalAdminFees) { return fail(Error.BAD_INPUT, FailureInfo.WITHDRAW_ADMIN_FEES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) // We checked withdrawAmount <= totalAdminFees above, so this should never revert. totalAdminFeesNew = sub_(totalAdminFees, withdrawAmount); // Store adminFees[n+1] = adminFees[n] - withdrawAmount totalAdminFees = totalAdminFeesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. doTransferOut(address(uint160(UnitrollerAdminStorage(address(comptroller)).admin())), withdrawAmount); return uint(Error.NO_ERROR); } /** * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh * @dev Admin function to accrue interest and update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint) { uint error = accrueInterest(); if (error != uint(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED); } // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK); } // Track the market's current interest rate model oldInterestRateModel = interestRateModel; // Ensure invoke newInterestRateModel.isInterestRateModel() returns true require(newInterestRateModel.isInterestRateModel(), "marker method returned false"); // Set the interest rate model to newInterestRateModel interestRateModel = newInterestRateModel; // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel) emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel); // Attempt to reset interest checkpoints on old IRM if (address(oldInterestRateModel) != address(0)) address(oldInterestRateModel).call(abi.encodeWithSignature("resetInterestCheckpoints()")); // Attempt to add first interest checkpoint on new IRM address(newInterestRateModel).call(abi.encodeWithSignature("checkpointInterest()")); return uint(Error.NO_ERROR); } /** * @notice updates the cToken ERC20 name and symbol * @dev Admin function to update the cToken ERC20 name and symbol * @param _name the new ERC20 token name to use * @param _symbol the new ERC20 token symbol to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setNameAndSymbol(string calldata _name, string calldata _symbol) external { // Check caller is admin require(hasAdminRights(), "caller not admin"); // Set ERC20 name and symbol name = _name; symbol = _symbol; } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying owned by this contract */ function getCashPrior() internal view returns (uint); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn(address from, uint amount) internal returns (uint); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut(address payable to, uint amount) internal; /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant(bool localOnly) { _beforeNonReentrant(localOnly); _; _afterNonReentrant(localOnly); } /** * @dev Split off from `nonReentrant` to keep contract below the 24 KB size limit. * Saves space because function modifier code is "inlined" into every function with the modifier). * In this specific case, the optimization saves around 1500 bytes of that valuable 24 KB limit. */ function _beforeNonReentrant(bool localOnly) private { require(_notEntered, "re-entered"); if (!localOnly) comptroller._beforeNonReentrant(); _notEntered = false; } /** * @dev Split off from `nonReentrant` to keep contract below the 24 KB size limit. * Saves space because function modifier code is "inlined" into every function with the modifier). * In this specific case, the optimization saves around 150 bytes of that valuable 24 KB limit. */ function _afterNonReentrant(bool localOnly) private { _notEntered = true; // get a gas-refund post-Istanbul if (!localOnly) comptroller._afterNonReentrant(); } /** * @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`]. * @param data The call data (encoded using abi.encode or one of its variants). * @param errorMessage The revert string to return on failure. */ 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; } }
pragma solidity ^0.5.16; import "./IFuseFeeDistributor.sol"; import "./ComptrollerStorage.sol"; import "./ComptrollerInterface.sol"; import "./InterestRateModel.sol"; contract CTokenAdminStorage { /** * @notice Administrator for Fuse */ IFuseFeeDistributor internal constant fuseAdmin = IFuseFeeDistributor(0x4AFB2B3DC111D091ca6C46C024d1d2f17BF477e1); /** * @dev LEGACY USE ONLY: Administrator for this contract */ address payable internal __admin; /** * @dev LEGACY USE ONLY: Whether or not the Fuse admin has admin rights */ bool internal __fuseAdminHasRights; /** * @dev LEGACY USE ONLY: Whether or not the admin has admin rights */ bool internal __adminHasRights; } contract CTokenStorage 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; /** * @notice Maximum borrow rate that can ever be applied (.0005% / block) */ uint internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves + fees */ uint internal constant reserveFactorPlusFeesMaxMantissa = 1e18; /** * @notice LEGACY USE ONLY: Pending administrator for this contract */ address payable private __pendingAdmin; /** * @notice Contract which oversees inter-cToken operations */ ComptrollerInterface public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) */ uint internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for admin fees */ uint public adminFeeMantissa; /** * @notice Fraction of interest currently set aside for Fuse fees */ uint public fuseFeeMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint public accrualBlockNumber; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint public totalReserves; /** * @notice Total amount of admin fees of the underlying held in this market */ uint public totalAdminFees; /** * @notice Total amount of Fuse fees of the underlying held in this market */ uint public totalFuseFees; /** * @notice Total number of tokens in circulation */ uint public totalSupply; /** * @notice Official record of token balances for each account */ mapping (address => uint) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping (address => mapping (address => uint)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint principal; uint interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; /** * @notice Share of seized collateral that is added to reserves */ uint public constant protocolSeizeShareMantissa = 2.8e16; //2.8% } contract CTokenInterface is CTokenStorage { /** * @notice Indicator that this is a CToken contract (for inspection) */ bool public constant isCToken = true; /** * @notice Indicator that this is or is not a CEther contract (for inspection) */ bool public constant isCEther = false; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint mintAmount, uint mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint redeemAmount, uint redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens); /*** Admin Events ***/ /** * @notice Event emitted when comptroller is changed */ event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves); /** * @notice Event emitted when the admin fee is changed */ event NewAdminFee(uint oldAdminFeeMantissa, uint newAdminFeeMantissa); /** * @notice Event emitted when the Fuse fee is changed */ event NewFuseFee(uint oldFuseFeeMantissa, uint newFuseFeeMantissa); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint amount); /** * @notice Failure event */ event Failure(uint error, uint info, uint detail); /*** User Interface ***/ function transfer(address dst, uint amount) external returns (bool); function transferFrom(address src, address dst, uint amount) external returns (bool); function approve(address spender, uint amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint); function balanceOf(address owner) external view returns (uint); function balanceOfUnderlying(address owner) external returns (uint); function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint); function borrowRatePerBlock() external view returns (uint); function supplyRatePerBlock() external view returns (uint); function totalBorrowsCurrent() external returns (uint); function borrowBalanceCurrent(address account) external returns (uint); function borrowBalanceStored(address account) public view returns (uint); function exchangeRateCurrent() public returns (uint); function exchangeRateStored() public view returns (uint); function getCash() external view returns (uint); function accrueInterest() public returns (uint); function seize(address liquidator, address borrower, uint seizeTokens) external returns (uint); /*** Admin Functions ***/ function _setReserveFactor(uint newReserveFactorMantissa) external returns (uint); function _reduceReserves(uint reduceAmount) external returns (uint); function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint); } contract CErc20Storage { /** * @notice Underlying asset for this CToken */ address public underlying; } contract CErc20Interface is CErc20Storage { /*** User Interface ***/ function mint(uint mintAmount) external returns (uint); function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow(uint repayAmount) external returns (uint); function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint); } contract CEtherInterface is CErc20Storage { /** * @notice Indicator that this is a CEther contract (for inspection) */ bool public constant isCEther = true; } contract CDelegationStorage { /** * @notice Implementation address for this contract */ address public implementation; } contract CDelegateInterface is CDelegationStorage { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementationSafe(address implementation_, bool allowResign, bytes calldata becomeImplementationData) external; /** * @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; /** * @notice Function called before all delegator functions * @dev Checks comptroller.autoImplementation and upgrades the implementation if necessary */ function _prepare() external payable; }
pragma solidity ^0.5.16; import "./JumpRateModel.sol"; import "./SafeMath.sol"; /** * @title Compound's DAIInterestRateModel Contract (version 2) * @author Compound (modified by Dharma Labs) * @notice The parameterized model described in section 2.4 of the original Compound Protocol whitepaper. * Version 2 modifies the original interest rate model by increasing the "gap" or slope of the model prior * to the "kink" from 0.05% to 2% with the goal of "smoothing out" interest rate changes as the utilization * rate increases. */ contract DAIInterestRateModelV2 is JumpRateModel { using SafeMath for uint; /** * @notice The additional margin per block separating the base borrow rate from the roof (2% / block). * Note that this value has been increased from the original value of 0.05% per block. */ uint public constant gapPerBlock = 2e16 / blocksPerYear; /** * @notice The assumed (1 - reserve factor) used to calculate the minimum borrow rate (reserve factor = 0.05) */ uint public constant assumedOneMinusReserveFactorMantissa = 0.95e18; PotLike pot; JugLike jug; /** * @notice Construct an interest rate model * @param jumpMultiplierPerYear The multiplierPerBlock after hitting a specified utilization point * @param kink_ The utilization point at which the jump multiplier is applied * @param pot_ The address of the Dai pot (where DSR is earned) * @param jug_ The address of the Dai jug (where SF is kept) */ constructor(uint jumpMultiplierPerYear, uint kink_, address pot_, address jug_) JumpRateModel(0, 0, jumpMultiplierPerYear, kink_) public { pot = PotLike(pot_); jug = JugLike(jug_); poke(); } /** * @notice Calculates the current supply interest rate per block including the Dai savings rate * @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 amnount 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(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) public view returns (uint) { uint protocolRate = super.getSupplyRate(cash, borrows, reserves, reserveFactorMantissa); uint underlying = cash.add(borrows).sub(reserves); if (underlying == 0) { return protocolRate; } else { uint cashRate = cash.mul(dsrPerBlock()).div(underlying); return cashRate.add(protocolRate); } } /** * @notice Calculates the Dai savings rate per block * @return The Dai savings rate per block (as a percentage, and scaled by 1e18) */ function dsrPerBlock() public view returns (uint) { return pot .dsr().sub(1e27) // scaled 1e27 aka RAY, and includes an extra "ONE" before subraction .div(1e9) // descale to 1e18 .mul(15); // 15 seconds per block } /** * @notice Resets the baseRate and multiplier per block based on the stability fee and Dai savings rate */ function poke() public { (uint duty, ) = jug.ilks("ETH-A"); uint stabilityFeePerBlock = duty.add(jug.base()).sub(1e27).mul(1e18).div(1e27).mul(15); // We ensure the minimum borrow rate >= DSR / (1 - reserve factor) baseRatePerBlock = dsrPerBlock().mul(1e18).div(assumedOneMinusReserveFactorMantissa); // The roof borrow rate is max(base rate, stability fee) + gap, from which we derive the slope if (baseRatePerBlock < stabilityFeePerBlock) { multiplierPerBlock = stabilityFeePerBlock.sub(baseRatePerBlock).add(gapPerBlock).mul(1e18).div(kink); } else { multiplierPerBlock = gapPerBlock.mul(1e18).div(kink); } emit NewInterestParams(baseRatePerBlock, multiplierPerBlock, jumpMultiplierPerBlock, kink); } } /*** Maker Interfaces ***/ contract PotLike { function chi() external view returns (uint); function dsr() external view returns (uint); function rho() external view returns (uint); function pie(address) external view returns (uint); function drip() external returns (uint); function join(uint) external; function exit(uint) external; } contract JugLike { // --- Data --- struct Ilk { uint256 duty; uint256 rho; } mapping (bytes32 => Ilk) public ilks; uint256 public base; }
pragma solidity ^0.5.16; /** * @title ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface EIP20Interface { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external returns (bool success); /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom(address src, address dst, uint256 amount) external returns (bool success); /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
pragma solidity ^0.5.16; /** * @title EIP20NonStandardInterface * @dev Version of ERC20 with no return values for `transfer` and `transferFrom` * See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ interface EIP20NonStandardInterface { /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transfer(address dst, uint256 amount) external; /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transferFrom(address src, address dst, uint256 amount) external; /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
pragma solidity ^0.5.16; contract ComptrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, COMPTROLLER_MISMATCH, INSUFFICIENT_SHORTFALL, INSUFFICIENT_LIQUIDITY, INVALID_CLOSE_FACTOR, INVALID_COLLATERAL_FACTOR, INVALID_LIQUIDATION_INCENTIVE, MARKET_NOT_ENTERED, // no longer possible 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_MAX_ASSETS_OWNER_CHECK, 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(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } } contract TokenErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, BAD_INPUT, COMPTROLLER_REJECTION, COMPTROLLER_CALCULATION_ERROR, INTEREST_RATE_MODEL_ERROR, INVALID_ACCOUNT_PAIR, INVALID_CLOSE_AMOUNT_REQUESTED, INVALID_COLLATERAL_FACTOR, MATH_ERROR, MARKET_NOT_FRESH, MARKET_NOT_LISTED, TOKEN_INSUFFICIENT_ALLOWANCE, TOKEN_INSUFFICIENT_BALANCE, TOKEN_INSUFFICIENT_CASH, TOKEN_TRANSFER_IN_FAILED, TOKEN_TRANSFER_OUT_FAILED, 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_FUSE_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_FUSE_FEES_ACCRUE_INTEREST_FAILED, WITHDRAW_FUSE_FEES_CASH_NOT_AVAILABLE, WITHDRAW_FUSE_FEES_FRESH_CHECK, WITHDRAW_FUSE_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, SET_MAX_ASSETS_OWNER_CHECK, SET_ORACLE_MARKET_NOT_LISTED, 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_FUSE_FEE_ACCRUE_INTEREST_FAILED, SET_FUSE_FEE_FRESH_CHECK, SET_FUSE_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(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return err == Error.COMPTROLLER_REJECTION ? 1000 + opaqueError : uint(err); } }
pragma solidity ^0.5.16; 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(uint num, uint denom) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint rational) = divUInt(scaledNumerator, denom); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: rational})); } /** * @dev Adds two exponentials, returning a new exponential. */ function addExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError error, uint result) = addUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Subtracts two exponentials, returning a new exponential. */ function subExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError error, uint result) = subUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Multiply an Exp by a scalar, returning a new Exp. */ function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa})); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa})); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ (MathError err0, uint numerator) = mulUInt(expScale, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return getExp(numerator, divisor.mantissa); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } // We add half the scale before dividing so that we get rounding instead of truncation. // See "Listing 6" and text above it at https://accu.org/index.php/journals/1717 // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18. (MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale); // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero. assert(err2 == MathError.NO_ERROR); return (MathError.NO_ERROR, Exp({mantissa: product})); } /** * @dev Multiplies two exponentials given their mantissas, returning a new exponential. */ function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) { return mulExp(Exp({mantissa: a}), Exp({mantissa: b})); } /** * @dev Multiplies three exponentials, returning a new exponential. */ function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) { (MathError err, Exp memory ab) = mulExp(a, b); if (err != MathError.NO_ERROR) { return (err, ab); } return mulExp(ab, c); } /** * @dev Divides two exponentials, returning a new exponential. * (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, * which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa) */ function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } }
pragma solidity ^0.5.16; /** * @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 { uint constant expScale = 1e18; uint constant doubleScale = 1e36; uint constant halfExpScale = expScale/2; uint constant mantissaOne = expScale; struct Exp { uint mantissa; } struct Double { uint mantissa; } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) pure internal returns (uint) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint scalar) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev Checks if left Exp > right Exp. */ function greaterThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa > right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) pure internal returns (bool) { return value.mantissa == 0; } function safe224(uint n, string memory errorMessage) pure internal returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint n, string memory errorMessage) pure internal returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint a, uint b) pure internal returns (uint) { return add_(a, b, "addition overflow"); } function add_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { uint c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint a, uint b) pure internal returns (uint) { return sub_(a, b, "subtraction underflow"); } function sub_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Exp memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Double memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint a, uint b) pure internal returns (uint) { return mul_(a, b, "multiplication overflow"); } function mul_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { if (a == 0 || b == 0) { return 0; } uint c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Exp memory b) pure internal returns (uint) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Double memory b) pure internal returns (uint) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint a, uint b) pure internal returns (uint) { return div_(a, b, "divide by zero"); } function div_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { require(b > 0, errorMessage); return a / b; } function fraction(uint a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } }
pragma solidity ^0.5.16; interface IFuseFeeDistributor { function minBorrowEth() external view returns (uint256); function maxSupplyEth() external view returns (uint256); function maxUtilizationRate() external view returns (uint256); function interestFeeRate() external view returns (uint256); function comptrollerImplementationWhitelist(address oldImplementation, address newImplementation) external view returns (bool); function cErc20DelegateWhitelist(address oldImplementation, address newImplementation, bool allowResign) external view returns (bool); function cEtherDelegateWhitelist(address oldImplementation, address newImplementation, bool allowResign) external view returns (bool); function latestComptrollerImplementation(address oldImplementation) external view returns (address); function latestCErc20Delegate(address oldImplementation) external view returns (address cErc20Delegate, bool allowResign, bytes memory becomeImplementationData); function latestCEtherDelegate(address oldImplementation) external view returns (address cEtherDelegate, bool allowResign, bytes memory becomeImplementationData); function deployCEther(bytes calldata constructorData) external returns (address); function deployCErc20(bytes calldata constructorData) external returns (address); function () external payable; }
pragma solidity ^0.5.16; /** * @title Compound's InterestRateModel Interface * @author Compound */ 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(uint cash, uint borrows, uint reserves) external view returns (uint); /** * @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(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view returns (uint); }
pragma solidity ^0.5.16; import "./InterestRateModel.sol"; import "./SafeMath.sol"; /** * @title Compound's JumpRateModel Contract * @author Compound */ contract JumpRateModel is InterestRateModel { using SafeMath for uint; event NewInterestParams(uint baseRatePerBlock, uint multiplierPerBlock, uint jumpMultiplierPerBlock, uint kink); /** * @notice The approximate number of blocks per year that is assumed by the interest rate model */ uint public constant blocksPerYear = 2102400; /** * @notice The multiplier of utilization rate that gives the slope of the interest rate */ uint public multiplierPerBlock; /** * @notice The base interest rate which is the y-intercept when utilization rate is 0 */ uint public baseRatePerBlock; /** * @notice The multiplierPerBlock after hitting a specified utilization point */ uint public jumpMultiplierPerBlock; /** * @notice The utilization point at which the jump multiplier is applied */ uint public kink; /** * @notice Construct an interest rate model * @param baseRatePerYear The approximate target base APR, as a mantissa (scaled by 1e18) * @param multiplierPerYear The rate of increase in interest rate wrt utilization (scaled by 1e18) * @param jumpMultiplierPerYear The multiplierPerBlock after hitting a specified utilization point * @param kink_ The utilization point at which the jump multiplier is applied */ constructor(uint baseRatePerYear, uint multiplierPerYear, uint jumpMultiplierPerYear, uint kink_) public { baseRatePerBlock = baseRatePerYear.div(blocksPerYear); multiplierPerBlock = multiplierPerYear.div(blocksPerYear); jumpMultiplierPerBlock = jumpMultiplierPerYear.div(blocksPerYear); kink = kink_; emit NewInterestParams(baseRatePerBlock, multiplierPerBlock, jumpMultiplierPerBlock, kink); } /** * @notice Calculates the utilization rate of the market: `borrows / (cash + borrows - reserves)` * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market (currently unused) * @return The utilization rate as a mantissa between [0, 1e18] */ function utilizationRate(uint cash, uint borrows, uint reserves) public pure returns (uint) { // Utilization rate is 0 when there are no borrows if (borrows == 0) { return 0; } return borrows.mul(1e18).div(cash.add(borrows).sub(reserves)); } /** * @notice Calculates the current borrow rate per block, with the error code expected by the market * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market * @return The borrow rate percentage per block as a mantissa (scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) public view returns (uint) { uint util = utilizationRate(cash, borrows, reserves); if (util <= kink) { return util.mul(multiplierPerBlock).div(1e18).add(baseRatePerBlock); } else { uint normalRate = kink.mul(multiplierPerBlock).div(1e18).add(baseRatePerBlock); uint excessUtil = util.sub(kink); return excessUtil.mul(jumpMultiplierPerBlock).div(1e18).add(normalRate); } } /** * @notice Calculates the current supply rate per block * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market * @param reserveFactorMantissa The current reserve factor for the market * @return The supply rate percentage per block as a mantissa (scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) public view returns (uint) { uint oneMinusReserveFactor = uint(1e18).sub(reserveFactorMantissa); uint borrowRate = getBorrowRate(cash, borrows, reserves); uint rateToPool = borrowRate.mul(oneMinusReserveFactor).div(1e18); return utilizationRate(cash, borrows, reserves).mul(rateToPool).div(1e18); } }
pragma solidity ^0.5.16; import "./CEther.sol"; /** * @title Compound's Maximillion Contract * @author Compound */ contract Maximillion { /** * @notice The default cEther market to repay in */ CEther public cEther; /** * @notice Construct a Maximillion to repay max in a CEther market */ constructor(CEther cEther_) public { cEther = cEther_; } /** * @notice msg.sender sends Ether to repay an account's borrow in the cEther market * @dev The provided Ether is applied towards the borrow balance, any excess is refunded * @param borrower The address of the borrower account to repay on behalf of */ function repayBehalf(address borrower) public payable { repayBehalfExplicit(borrower, cEther); } /** * @notice msg.sender sends Ether to repay an account's borrow in a cEther market * @dev The provided Ether is applied towards the borrow balance, any excess is refunded * @param borrower The address of the borrower account to repay on behalf of * @param cEther_ The address of the cEther contract to repay in */ function repayBehalfExplicit(address borrower, CEther cEther_) public payable { uint received = msg.value; uint borrows = cEther_.borrowBalanceCurrent(borrower); if (received > borrows) { cEther_.repayBorrowBehalf.value(borrows)(borrower); msg.sender.transfer(received - borrows); } else { cEther_.repayBorrowBehalf.value(received)(borrower); } } }
pragma solidity ^0.5.16; import "./CToken.sol"; contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /** * @notice Get the underlying price of a cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(CToken cToken) external view returns (uint); }
pragma solidity ^0.5.16; /** * @title Reservoir Contract * @notice Distributes a token to a different contract at a fixed rate. * @dev This contract must be poked via the `drip()` function every so often. * @author Compound */ contract Reservoir { /// @notice The block number when the Reservoir started (immutable) uint public dripStart; /// @notice Tokens per block that to drip to target (immutable) uint public dripRate; /// @notice Reference to token to drip (immutable) EIP20Interface public token; /// @notice Target to receive dripped tokens (immutable) address public target; /// @notice Amount that has already been dripped uint public dripped; /** * @notice Constructs a Reservoir * @param dripRate_ Numer of tokens per block to drip * @param token_ The token to drip * @param target_ The recipient of dripped tokens */ constructor(uint dripRate_, EIP20Interface token_, address target_) public { dripStart = block.number; dripRate = dripRate_; token = token_; target = target_; dripped = 0; } /** * @notice Drips the maximum amount of tokens to match the drip rate since inception * @dev Note: this will only drip up to the amount of tokens available. * @return The amount of tokens dripped in this call */ function drip() public returns (uint) { // First, read storage into memory EIP20Interface token_ = token; uint reservoirBalance_ = token_.balanceOf(address(this)); // TODO: Verify this is a static call uint dripRate_ = dripRate; uint dripStart_ = dripStart; uint dripped_ = dripped; address target_ = target; uint blockNumber_ = block.number; // Next, calculate intermediate values uint dripTotal_ = mul(dripRate_, blockNumber_ - dripStart_, "dripTotal overflow"); uint deltaDrip_ = sub(dripTotal_, dripped_, "deltaDrip underflow"); uint toDrip_ = min(reservoirBalance_, deltaDrip_); uint drippedNext_ = add(dripped_, toDrip_, "tautological"); // Finally, write new `dripped` value and transfer tokens to target dripped = drippedNext_; token_.transfer(target_, toDrip_); return toDrip_; } /* Internal helper functions for safe math */ function add(uint a, uint b, string memory errorMessage) internal pure returns (uint) { uint c = a + b; require(c >= a, errorMessage); return c; } function sub(uint a, uint b, string memory errorMessage) internal pure returns (uint) { require(b <= a, errorMessage); uint c = a - b; return c; } function mul(uint a, uint b, string memory errorMessage) internal pure returns (uint) { if (a == 0) { return 0; } uint c = a * b; require(c / a == b, errorMessage); return c; } function min(uint a, uint b) internal pure returns (uint) { if (a <= b) { return a; } else { return b; } } } import "./EIP20Interface.sol";
pragma solidity ^0.5.16; import "./CToken.sol"; import "./ExponentialNoError.sol"; import "./Comptroller.sol"; import "./RewardsDistributorStorage.sol"; /** * @title RewardsDistributorDelegate (COMP distribution logic extracted from `Comptroller`) * @author Compound */ contract RewardsDistributorDelegate is RewardsDistributorDelegateStorageV1, ExponentialNoError { /// @dev Notice that this contract is a RewardsDistributor bool public constant isRewardsDistributor = true; /// @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); /// @notice Emitted when a new COMP speed is calculated for a market event CompSupplySpeedUpdated(CToken indexed cToken, uint newSpeed); /// @notice Emitted when a new COMP speed is calculated for a market event CompBorrowSpeedUpdated(CToken indexed cToken, uint newSpeed); /// @notice Emitted when a new COMP speed is set for a contributor event ContributorCompSpeedUpdated(address indexed contributor, uint newSpeed); /// @notice Emitted when COMP is distributed to a supplier event DistributedSupplierComp(CToken indexed cToken, address indexed supplier, uint compDelta, uint compSupplyIndex); /// @notice Emitted when COMP is distributed to a borrower event DistributedBorrowerComp(CToken indexed cToken, address indexed borrower, uint compDelta, uint compBorrowIndex); /// @notice Emitted when COMP is granted by admin event CompGranted(address recipient, uint amount); /// @notice The initial COMP index for a market uint224 public constant compInitialIndex = 1e36; /// @dev Intitializer to set admin to caller and set reward token function initialize(address _rewardToken) external { require(msg.sender == admin, "Only admin can initialize."); require(rewardToken == address(0), "Already initialized."); require(_rewardToken != address(0), "Cannot initialize reward token to the zero address."); rewardToken = _rewardToken; } /*** Set Admin ***/ /** * @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. */ function _setPendingAdmin(address newPendingAdmin) external { // Check caller = admin require(msg.sender == admin, "RewardsDistributor:_setPendingAdmin: admin only"); // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin() external { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) require(msg.sender == pendingAdmin && msg.sender != address(0), "RewardsDistributor:_acceptAdmin: pending admin only"); // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); } /*** Comp Distribution ***/ /** * @notice Check the cToken before adding * @param cToken The market to add */ function checkCToken(CToken cToken) internal view { // Make sure cToken is listed Comptroller comptroller = Comptroller(address(cToken.comptroller())); (bool isListed, ) = comptroller.markets(address(cToken)); require(isListed == true, "comp market is not listed"); // Make sure distributor is added bool distributorAdded = false; address[] memory distributors = comptroller.getRewardsDistributors(); for (uint256 i = 0; i < distributors.length; i++) if (distributors[i] == address(this)) distributorAdded = true; require(distributorAdded == true, "distributor not added"); } /** * @notice Set COMP speed for a single market * @param cToken The market whose COMP speed to update * @param compSpeed New COMP speed for market */ function setCompSupplySpeedInternal(CToken cToken, uint compSpeed) internal { uint currentCompSpeed = compSupplySpeeds[address(cToken)]; if (currentCompSpeed != 0) { // note that COMP speed could be set to 0 to halt liquidity rewards for a market updateCompSupplyIndex(address(cToken)); } else if (compSpeed != 0) { // Make sure cToken is listed and distributor is added checkCToken(cToken); // Add the COMP market if (compSupplyState[address(cToken)].index == 0) { compSupplyState[address(cToken)] = CompMarketState({ index: compInitialIndex, block: safe32(getBlockNumber(), "block number exceeds 32 bits") }); // Add to allMarkets array if not already there if (compBorrowState[address(cToken)].index == 0) { allMarkets.push(cToken); } } else { // Update block number to ensure extra interest is not accrued during the prior period compSupplyState[address(cToken)].block = safe32(getBlockNumber(), "block number exceeds 32 bits"); } } if (currentCompSpeed != compSpeed) { compSupplySpeeds[address(cToken)] = compSpeed; emit CompSupplySpeedUpdated(cToken, compSpeed); } } /** * @notice Set COMP speed for a single market * @param cToken The market whose COMP speed to update * @param compSpeed New COMP speed for market */ function setCompBorrowSpeedInternal(CToken cToken, uint compSpeed) internal { uint currentCompSpeed = compBorrowSpeeds[address(cToken)]; if (currentCompSpeed != 0) { // note that COMP speed could be set to 0 to halt liquidity rewards for a market Exp memory borrowIndex = Exp({mantissa: cToken.borrowIndex()}); updateCompBorrowIndex(address(cToken), borrowIndex); } else if (compSpeed != 0) { // Make sure cToken is listed and distributor is added checkCToken(cToken); // Add the COMP market if (compBorrowState[address(cToken)].index == 0) { compBorrowState[address(cToken)] = CompMarketState({ index: compInitialIndex, block: safe32(getBlockNumber(), "block number exceeds 32 bits") }); // Add to allMarkets array if not already there if (compSupplyState[address(cToken)].index == 0) { allMarkets.push(cToken); } } else { // Update block number to ensure extra interest is not accrued during the prior period compBorrowState[address(cToken)].block = safe32(getBlockNumber(), "block number exceeds 32 bits"); } } if (currentCompSpeed != compSpeed) { compBorrowSpeeds[address(cToken)] = compSpeed; emit CompBorrowSpeedUpdated(cToken, compSpeed); } } /** * @notice Accrue COMP to the market by updating the supply index * @param cToken The market whose supply index to update */ function updateCompSupplyIndex(address cToken) internal { CompMarketState storage supplyState = compSupplyState[cToken]; uint supplySpeed = compSupplySpeeds[cToken]; uint blockNumber = getBlockNumber(); uint deltaBlocks = sub_(blockNumber, uint(supplyState.block)); if (deltaBlocks > 0 && supplySpeed > 0) { uint supplyTokens = CToken(cToken).totalSupply(); uint compAccrued_ = mul_(deltaBlocks, supplySpeed); Double memory ratio = supplyTokens > 0 ? fraction(compAccrued_, supplyTokens) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: supplyState.index}), ratio); compSupplyState[cToken] = CompMarketState({ index: safe224(index.mantissa, "new index exceeds 224 bits"), block: safe32(blockNumber, "block number exceeds 32 bits") }); } else if (deltaBlocks > 0 && supplyState.index > 0) { supplyState.block = safe32(blockNumber, "block number exceeds 32 bits"); } } /** * @notice Accrue COMP to the market by updating the borrow index * @param cToken The market whose borrow index to update */ function updateCompBorrowIndex(address cToken, Exp memory marketBorrowIndex) internal { CompMarketState storage borrowState = compBorrowState[cToken]; uint borrowSpeed = compBorrowSpeeds[cToken]; uint blockNumber = getBlockNumber(); uint deltaBlocks = sub_(blockNumber, uint(borrowState.block)); if (deltaBlocks > 0 && borrowSpeed > 0) { uint borrowAmount = div_(CToken(cToken).totalBorrows(), marketBorrowIndex); uint compAccrued_ = mul_(deltaBlocks, borrowSpeed); Double memory ratio = borrowAmount > 0 ? fraction(compAccrued_, borrowAmount) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: borrowState.index}), ratio); compBorrowState[cToken] = CompMarketState({ index: safe224(index.mantissa, "new index exceeds 224 bits"), block: safe32(blockNumber, "block number exceeds 32 bits") }); } else if (deltaBlocks > 0 && borrowState.index > 0) { borrowState.block = safe32(blockNumber, "block number exceeds 32 bits"); } } /** * @notice Calculate COMP accrued by a supplier and possibly transfer it to them * @param cToken The market in which the supplier is interacting * @param supplier The address of the supplier to distribute COMP to */ function distributeSupplierComp(address cToken, address supplier) internal { CompMarketState storage supplyState = compSupplyState[cToken]; Double memory supplyIndex = Double({mantissa: supplyState.index}); Double memory supplierIndex = Double({mantissa: compSupplierIndex[cToken][supplier]}); compSupplierIndex[cToken][supplier] = supplyIndex.mantissa; if (supplierIndex.mantissa == 0 && supplyIndex.mantissa > 0) { supplierIndex.mantissa = compInitialIndex; } Double memory deltaIndex = sub_(supplyIndex, supplierIndex); uint supplierTokens = CToken(cToken).balanceOf(supplier); uint supplierDelta = mul_(supplierTokens, deltaIndex); uint supplierAccrued = add_(compAccrued[supplier], supplierDelta); compAccrued[supplier] = supplierAccrued; emit DistributedSupplierComp(CToken(cToken), supplier, supplierDelta, supplyIndex.mantissa); } /** * @notice Calculate COMP accrued by a borrower and possibly transfer it to them * @param cToken The market in which the borrower is interacting * @param borrower The address of the borrower to distribute COMP to */ function distributeBorrowerComp(address cToken, address borrower, Exp memory marketBorrowIndex) internal { CompMarketState storage borrowState = compBorrowState[cToken]; Double memory borrowIndex = Double({mantissa: borrowState.index}); Double memory borrowerIndex = Double({mantissa: compBorrowerIndex[cToken][borrower]}); compBorrowerIndex[cToken][borrower] = borrowIndex.mantissa; if (borrowerIndex.mantissa == 0 && borrowIndex.mantissa > 0) { borrowerIndex.mantissa = compInitialIndex; } Double memory deltaIndex = sub_(borrowIndex, borrowerIndex); uint borrowerAmount = div_(CToken(cToken).borrowBalanceStored(borrower), marketBorrowIndex); uint borrowerDelta = mul_(borrowerAmount, deltaIndex); uint borrowerAccrued = add_(compAccrued[borrower], borrowerDelta); compAccrued[borrower] = borrowerAccrued; emit DistributedBorrowerComp(CToken(cToken), borrower, borrowerDelta, borrowIndex.mantissa); } /** * @notice Keeps the flywheel moving pre-mint and pre-redeem * @dev Called by the Comptroller * @param cToken The relevant market * @param supplier The minter/redeemer */ function flywheelPreSupplierAction(address cToken, address supplier) external { if (compSupplyState[cToken].index > 0) { updateCompSupplyIndex(cToken); distributeSupplierComp(cToken, supplier); } } /** * @notice Keeps the flywheel moving pre-borrow and pre-repay * @dev Called by the Comptroller * @param cToken The relevant market * @param borrower The borrower */ function flywheelPreBorrowerAction(address cToken, address borrower) external { if (compBorrowState[cToken].index > 0) { Exp memory borrowIndex = Exp({mantissa: CToken(cToken).borrowIndex()}); updateCompBorrowIndex(cToken, borrowIndex); distributeBorrowerComp(cToken, borrower, borrowIndex); } } /** * @notice Keeps the flywheel moving pre-transfer and pre-seize * @dev Called by the Comptroller * @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) external { if (compSupplyState[cToken].index > 0) { updateCompSupplyIndex(cToken); distributeSupplierComp(cToken, src); distributeSupplierComp(cToken, dst); } } /** * @notice Calculate additional accrued COMP for a contributor since last accrual * @param contributor The address to calculate contributor rewards for */ function updateContributorRewards(address contributor) public { uint compSpeed = compContributorSpeeds[contributor]; uint blockNumber = getBlockNumber(); uint deltaBlocks = sub_(blockNumber, lastContributorBlock[contributor]); if (deltaBlocks > 0 && compSpeed > 0) { uint newAccrued = mul_(deltaBlocks, compSpeed); uint contributorAccrued = add_(compAccrued[contributor], newAccrued); compAccrued[contributor] = contributorAccrued; lastContributorBlock[contributor] = blockNumber; } } /** * @notice Claim all the comp accrued by holder in all markets * @param holder The address to claim COMP for */ function claimRewards(address holder) public { return claimRewards(holder, allMarkets); } /** * @notice Claim all the comp accrued by holder in the specified markets * @param holder The address to claim COMP for * @param cTokens The list of markets to claim COMP in */ function claimRewards(address holder, CToken[] memory cTokens) public { address[] memory holders = new address[](1); holders[0] = holder; claimRewards(holders, cTokens, true, true); } /** * @notice Claim all comp accrued by the holders * @param holders The addresses to claim COMP for * @param cTokens The list of markets to claim COMP in * @param borrowers Whether or not to claim COMP earned by borrowing * @param suppliers Whether or not to claim COMP earned by supplying */ function claimRewards(address[] memory holders, CToken[] memory cTokens, bool borrowers, bool suppliers) public { for (uint i = 0; i < cTokens.length; i++) { CToken cToken = cTokens[i]; if (borrowers == true && compBorrowState[address(cToken)].index > 0) { Exp memory borrowIndex = Exp({mantissa: cToken.borrowIndex()}); updateCompBorrowIndex(address(cToken), borrowIndex); for (uint j = 0; j < holders.length; j++) { distributeBorrowerComp(address(cToken), holders[j], borrowIndex); } } if (suppliers == true && compSupplyState[address(cToken)].index > 0) { updateCompSupplyIndex(address(cToken)); for (uint j = 0; j < holders.length; j++) { distributeSupplierComp(address(cToken), holders[j]); } } } for (uint j = 0; j < holders.length; j++) { compAccrued[holders[j]] = grantCompInternal(holders[j], compAccrued[holders[j]]); } } /** * @notice Transfer COMP to the user * @dev Note: If there is not enough COMP, we do not perform the transfer all. * @param user The address of the user to transfer COMP to * @param amount The amount of COMP to (possibly) transfer * @return The amount of COMP which was NOT transferred to the user */ function grantCompInternal(address user, uint amount) internal returns (uint) { EIP20NonStandardInterface comp = EIP20NonStandardInterface(rewardToken); uint compRemaining = comp.balanceOf(address(this)); if (amount > 0 && amount <= compRemaining) { comp.transfer(user, amount); return 0; } return amount; } /*** Comp Distribution Admin ***/ /** * @notice Transfer COMP to the recipient * @dev Note: If there is not enough COMP, we do not perform the transfer all. * @param recipient The address of the recipient to transfer COMP to * @param amount The amount of COMP to (possibly) transfer */ function _grantComp(address recipient, uint amount) public { require(msg.sender == admin, "only admin can grant comp"); uint amountLeft = grantCompInternal(recipient, amount); require(amountLeft == 0, "insufficient comp for grant"); emit CompGranted(recipient, amount); } /** * @notice Set COMP speed for a single market * @param cToken The market whose COMP speed to update * @param compSpeed New COMP speed for market */ function _setCompSupplySpeed(CToken cToken, uint compSpeed) public { require(msg.sender == admin, "only admin can set comp speed"); setCompSupplySpeedInternal(cToken, compSpeed); } /** * @notice Set COMP speed for a single market * @param cToken The market whose COMP speed to update * @param compSpeed New COMP speed for market */ function _setCompBorrowSpeed(CToken cToken, uint compSpeed) public { require(msg.sender == admin, "only admin can set comp speed"); setCompBorrowSpeedInternal(cToken, compSpeed); } /** * @notice Set COMP borrow and supply speeds for the specified markets. * @param cTokens The markets whose COMP speed to update. * @param supplySpeeds New supply-side COMP speed for the corresponding market. * @param borrowSpeeds New borrow-side COMP speed for the corresponding market. */ function _setCompSpeeds(CToken[] memory cTokens, uint[] memory supplySpeeds, uint[] memory borrowSpeeds) public { require(msg.sender == admin, "only admin can set comp speed"); uint numTokens = cTokens.length; require(numTokens == supplySpeeds.length && numTokens == borrowSpeeds.length, "RewardsDistributor::_setCompSpeeds invalid input"); for (uint i = 0; i < numTokens; ++i) { setCompSupplySpeedInternal(cTokens[i], supplySpeeds[i]); setCompBorrowSpeedInternal(cTokens[i], borrowSpeeds[i]); } } /** * @notice Set COMP speed for a single contributor * @param contributor The contributor whose COMP speed to update * @param compSpeed New COMP speed for contributor */ function _setContributorCompSpeed(address contributor, uint compSpeed) public { require(msg.sender == admin, "only admin can set comp speed"); // note that COMP speed could be set to 0 to halt liquidity rewards for a contributor updateContributorRewards(contributor); if (compSpeed == 0) { // release storage delete lastContributorBlock[contributor]; } else { lastContributorBlock[contributor] = getBlockNumber(); } compContributorSpeeds[contributor] = compSpeed; emit ContributorCompSpeedUpdated(contributor, compSpeed); } /*** Helper Functions */ function getBlockNumber() public view returns (uint) { return block.number; } /** * @notice Returns an array of all markets. */ function getAllMarkets() external view returns (CToken[] memory) { return allMarkets; } }
pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; import "./RewardsDistributorStorage.sol"; contract RewardsDistributorDelegator is RewardsDistributorDelegatorStorage { /// @notice Emitted when implementation is changed event NewImplementation(address oldImplementation, address newImplementation); constructor( address admin_, address rewardToken_, address implementation_) public { // Admin set to msg.sender for initialization admin = msg.sender; delegateTo(implementation_, abi.encodeWithSignature("initialize(address)", rewardToken_)); _setImplementation(implementation_); admin = admin_; } /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation */ function _setImplementation(address implementation_) public { require(msg.sender == admin, "RewardsDistributorDelegator::_setImplementation: admin only"); require(implementation_ != address(0), "RewardsDistributorDelegator::_setImplementation: invalid implementation address"); address oldImplementation = implementation; implementation = implementation_; emit NewImplementation(oldImplementation, implementation); } /** * @notice Internal method to delegate execution to another contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts * @param callee The contract to delegatecall * @param data The raw data to delegatecall */ function delegateTo(address callee, bytes memory data) internal { (bool success, bytes memory returnData) = callee.delegatecall(data); assembly { if eq(success, 0) { revert(add(returnData, 0x20), returndatasize) } } } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () external payable { // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; import "./CToken.sol"; contract RewardsDistributorDelegatorStorage { /// @notice Administrator for this contract address public admin; /// @notice Pending administrator for this contract address public pendingAdmin; /// @notice Active brains of RewardsDistributor address public implementation; } /** * @title Storage for RewardsDistributorDelegate * @notice For future upgrades, do not change RewardsDistributorDelegateStorageV1. Create a new * contract which implements RewardsDistributorDelegateStorageV1 and following the naming convention * RewardsDistributorDelegateStorageVX. */ contract RewardsDistributorDelegateStorageV1 is RewardsDistributorDelegatorStorage { /// @dev The token to reward (i.e., COMP) address public rewardToken; struct CompMarketState { /// @notice The market's last updated compBorrowIndex or compSupplyIndex uint224 index; /// @notice The block number the index was last updated at uint32 block; } /// @notice A list of all markets CToken[] public allMarkets; /// @notice The portion of compRate that each market currently receives mapping(address => uint) public compSupplySpeeds; /// @notice The portion of compRate that each market currently receives mapping(address => uint) public compBorrowSpeeds; /// @notice The COMP market supply state for each market mapping(address => CompMarketState) public compSupplyState; /// @notice The COMP market borrow state for each market mapping(address => CompMarketState) public compBorrowState; /// @notice The COMP borrow index for each market for each supplier as of the last time they accrued COMP mapping(address => mapping(address => uint)) public compSupplierIndex; /// @notice The COMP borrow index for each market for each borrower as of the last time they accrued COMP mapping(address => mapping(address => uint)) public compBorrowerIndex; /// @notice The COMP accrued but not yet transferred to each user mapping(address => uint) public compAccrued; /// @notice The portion of COMP that each contributor receives per block mapping(address => uint) public compContributorSpeeds; /// @notice Last block at which a contributor's COMP rewards have been allocated mapping(address => uint) public lastContributorBlock; }
pragma solidity ^0.5.16; // From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/Math.sol // Subject to the MIT license. /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the addition of two unsigned integers, reverting with custom message on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction underflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } /** * @dev Returns the integer division of two unsigned integers. * Reverts on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. * Reverts with custom message on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
pragma solidity ^0.5.16; import "./PriceOracle.sol"; import "./CErc20.sol"; contract SimplePriceOracle is PriceOracle { mapping(address => uint) prices; event PricePosted(address asset, uint previousPriceMantissa, uint requestedPriceMantissa, uint newPriceMantissa); function getUnderlyingPrice(CToken cToken) public view returns (uint) { if (compareStrings(cToken.symbol(), "cETH")) { return 1e18; } else { return prices[address(CErc20(address(cToken)).underlying())]; } } function setUnderlyingPrice(CToken cToken, uint underlyingPriceMantissa) public { address asset = address(CErc20(address(cToken)).underlying()); emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa); prices[asset] = underlyingPriceMantissa; } function setDirectPrice(address asset, uint price) public { emit PricePosted(asset, prices[asset], price, price); prices[asset] = price; } // v1 price oracle interface for use as backing of proxy function assetPrices(address asset) external view returns (uint) { return prices[asset]; } function compareStrings(string memory a, string memory b) internal pure returns (bool) { return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b)))); } }
pragma solidity ^0.5.16; import "./SafeMath.sol"; contract Timelock { using SafeMath for uint; event NewAdmin(address indexed newAdmin); event NewPendingAdmin(address indexed newPendingAdmin); event NewDelay(uint indexed newDelay); event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); uint public constant GRACE_PERIOD = 14 days; uint public constant MINIMUM_DELAY = 2 days; uint public constant MAXIMUM_DELAY = 30 days; address public admin; address public pendingAdmin; uint public delay; mapping (bytes32 => bool) public queuedTransactions; constructor(address admin_, uint delay_) public { require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay."); require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); admin = admin_; delay = delay_; } function() external payable { } function setDelay(uint delay_) public { require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock."); require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay."); require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); delay = delay_; emit NewDelay(delay); } function acceptAdmin() public { require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin."); admin = msg.sender; pendingAdmin = address(0); emit NewAdmin(admin); } function setPendingAdmin(address pendingAdmin_) public { require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock."); pendingAdmin = pendingAdmin_; emit NewPendingAdmin(pendingAdmin); } function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) { require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin."); require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = true; emit QueueTransaction(txHash, target, value, signature, data, eta); return txHash; } function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public { require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = false; emit CancelTransaction(txHash, target, value, signature, data, eta); } function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) { require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued."); require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock."); require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale."); queuedTransactions[txHash] = false; bytes memory callData; if (bytes(signature).length == 0) { callData = data; } else { callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data); } // solium-disable-next-line security/no-call-value (bool success, bytes memory returnData) = target.call.value(value)(callData); require(success, "Timelock::executeTransaction: Transaction execution reverted."); emit ExecuteTransaction(txHash, target, value, signature, data, eta); return returnData; } function getBlockTimestamp() internal view returns (uint) { // solium-disable-next-line security/no-block-members return block.timestamp; } }
pragma solidity ^0.5.16; import "./ErrorReporter.sol"; import "./ComptrollerStorage.sol"; /** * @title Unitroller * @dev Storage for the comptroller is at this address, while execution is delegated to the `comptrollerImplementation`. * CTokens should reference this contract as their comptroller. */ contract Unitroller is UnitrollerAdminStorage, ComptrollerErrorReporter { /** * @notice Emitted when pendingComptrollerImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingComptrollerImplementation is accepted, which means comptroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Event emitted when the Fuse admin rights are changed */ event FuseAdminRightsToggled(bool hasRights); /** * @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() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint) { if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } if (!fuseAdmin.comptrollerImplementationWhitelist(comptrollerImplementation, newPendingImplementation)) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_CONTRACT_CHECK); } address oldPendingImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Accepts new implementation of comptroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingComptrollerImplementation || pendingComptrollerImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = comptrollerImplementation; address oldPendingImplementation = pendingComptrollerImplementation; comptrollerImplementation = pendingComptrollerImplementation; pendingComptrollerImplementation = address(0); emit NewImplementation(oldImplementation, comptrollerImplementation); emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation); return uint(Error.NO_ERROR); } /** * @notice Toggles Fuse admin rights. * @param hasRights Boolean indicating if the Fuse admin is to have rights. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _toggleFuseAdminRights(bool hasRights) external returns (uint) { // Check caller = admin 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 (fuseAdminHasRights == hasRights) return uint(Error.NO_ERROR); // Set fuseAdminHasRights fuseAdminHasRights = hasRights; // Emit FuseAdminRightsToggled() emit FuseAdminRightsToggled(fuseAdminHasRights); return uint(Error.NO_ERROR); } /** * @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 (uint) { // Check caller = admin 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 uint(Error.NO_ERROR); // Set adminHasRights adminHasRights = hasRights; // Emit AdminRightsToggled() emit AdminRightsToggled(hasRights); return uint(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint) { // Check caller = admin if (!hasAdminRights()) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function () payable external { // Check for automatic implementation if (msg.sender != address(this)) { (bool callSuccess, bytes memory data) = address(this).staticcall(abi.encodeWithSignature("autoImplementation()")); bool autoImplementation; if (callSuccess) (autoImplementation) = abi.decode(data, (bool)); if (autoImplementation) { address latestComptrollerImplementation = fuseAdmin.latestComptrollerImplementation(comptrollerImplementation); if (comptrollerImplementation != latestComptrollerImplementation) { address oldImplementation = comptrollerImplementation; // Save current value for inclusion in log comptrollerImplementation = latestComptrollerImplementation; emit NewImplementation(oldImplementation, comptrollerImplementation); } } } // delegate all other functions to current implementation (bool success, ) = comptrollerImplementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } }
pragma solidity ^0.5.16; import "./InterestRateModel.sol"; import "./SafeMath.sol"; /** * @title Compound's WhitePaperInterestRateModel Contract * @author Compound * @notice The parameterized model described in section 2.4 of the original Compound Protocol whitepaper */ contract WhitePaperInterestRateModel is InterestRateModel { using SafeMath for uint; event NewInterestParams(uint baseRatePerBlock, uint multiplierPerBlock); /** * @notice The approximate number of blocks per year that is assumed by the interest rate model */ uint public constant blocksPerYear = 2102400; /** * @notice The multiplier of utilization rate that gives the slope of the interest rate */ uint public multiplierPerBlock; /** * @notice The base interest rate which is the y-intercept when utilization rate is 0 */ uint public baseRatePerBlock; /** * @notice Construct an interest rate model * @param baseRatePerYear The approximate target base APR, as a mantissa (scaled by 1e18) * @param multiplierPerYear The rate of increase in interest rate wrt utilization (scaled by 1e18) */ constructor(uint baseRatePerYear, uint multiplierPerYear) public { baseRatePerBlock = baseRatePerYear.div(blocksPerYear); multiplierPerBlock = multiplierPerYear.div(blocksPerYear); emit NewInterestParams(baseRatePerBlock, multiplierPerBlock); } /** * @notice Calculates the utilization rate of the market: `borrows / (cash + borrows - reserves)` * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market (currently unused) * @return The utilization rate as a mantissa between [0, 1e18] */ function utilizationRate(uint cash, uint borrows, uint reserves) public pure returns (uint) { // Utilization rate is 0 when there are no borrows if (borrows == 0) { return 0; } return borrows.mul(1e18).div(cash.add(borrows).sub(reserves)); } /** * @notice Calculates the current borrow rate per block, with the error code expected by the market * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market * @return The borrow rate percentage per block as a mantissa (scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) public view returns (uint) { uint ur = utilizationRate(cash, borrows, reserves); return ur.mul(multiplierPerBlock).div(1e18).add(baseRatePerBlock); } /** * @notice Calculates the current supply rate per block * @param cash The amount of cash in the market * @param borrows The amount of borrows in the market * @param reserves The amount of reserves in the market * @param reserveFactorMantissa The current reserve factor for the market * @return The supply rate percentage per block as a mantissa (scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) public view returns (uint) { uint oneMinusReserveFactor = uint(1e18).sub(reserveFactorMantissa); uint borrowRate = getBorrowRate(cash, borrows, reserves); uint rateToPool = borrowRate.mul(oneMinusReserveFactor).div(1e18); return utilizationRate(cash, borrows, reserves).mul(rateToPool).div(1e18); } }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"action","type":"string"},{"indexed":false,"internalType":"bool","name":"pauseState","type":"bool"}],"name":"ActionPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract CToken","name":"cToken","type":"address"},{"indexed":false,"internalType":"string","name":"action","type":"string"},{"indexed":false,"internalType":"bool","name":"pauseState","type":"bool"}],"name":"ActionPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"rewardsDistributor","type":"address"}],"name":"AddedRewardsDistributor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"AutoImplementationsToggled","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 CToken","name":"cToken","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"MarketEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract CToken","name":"cToken","type":"address"},{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"MarketExited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"MarketListed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"MarketUnlisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract CToken","name":"cToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"newBorrowCap","type":"uint256"}],"name":"NewBorrowCap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldBorrowCapGuardian","type":"address"},{"indexed":false,"internalType":"address","name":"newBorrowCapGuardian","type":"address"}],"name":"NewBorrowCapGuardian","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 CToken","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":"address","name":"oldPauseGuardian","type":"address"},{"indexed":false,"internalType":"address","name":"newPauseGuardian","type":"address"}],"name":"NewPauseGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract PriceOracle","name":"oldPriceOracle","type":"address"},{"indexed":false,"internalType":"contract PriceOracle","name":"newPriceOracle","type":"address"}],"name":"NewPriceOracle","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract CToken","name":"cToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"newSupplyCap","type":"uint256"}],"name":"NewSupplyCap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enforce","type":"bool"}],"name":"WhitelistEnforcementChanged","type":"event"},{"constant":false,"inputs":[{"internalType":"address","name":"distributor","type":"address"}],"name":"_addRewardsDistributor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"_afterNonReentrant","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract Unitroller","name":"unitroller","type":"address"}],"name":"_become","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"_becomeImplementation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"_beforeNonReentrant","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"_borrowGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"isCEther","type":"bool"},{"internalType":"bytes","name":"constructorData","type":"bytes"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"}],"name":"_deployMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"_mintGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newBorrowCapGuardian","type":"address"}],"name":"_setBorrowCapGuardian","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"},{"internalType":"bool","name":"state","type":"bool"}],"name":"_setBorrowPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newCloseFactorMantissa","type":"uint256"}],"name":"_setCloseFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"},{"internalType":"uint256","name":"newCollateralFactorMantissa","type":"uint256"}],"name":"_setCollateralFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"newLiquidationIncentiveMantissa","type":"uint256"}],"name":"_setLiquidationIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken[]","name":"cTokens","type":"address[]"},{"internalType":"uint256[]","name":"newBorrowCaps","type":"uint256[]"}],"name":"_setMarketBorrowCaps","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken[]","name":"cTokens","type":"address[]"},{"internalType":"uint256[]","name":"newSupplyCaps","type":"uint256[]"}],"name":"_setMarketSupplyCaps","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"},{"internalType":"bool","name":"state","type":"bool"}],"name":"_setMintPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newPauseGuardian","type":"address"}],"name":"_setPauseGuardian","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract PriceOracle","name":"newOracle","type":"address"}],"name":"_setPriceOracle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setSeizePaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"state","type":"bool"}],"name":"_setTransferPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"enforce","type":"bool"}],"name":"_setWhitelistEnforcement","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"suppliers","type":"address[]"},{"internalType":"bool[]","name":"statuses","type":"bool[]"}],"name":"_setWhitelistStatuses","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"enabled","type":"bool"}],"name":"_toggleAutoImplementations","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"_unsupportMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"accountAssets","outputs":[{"internalType":"contract CToken","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"adminHasRights","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allBorrowers","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allMarkets","outputs":[{"internalType":"contract CToken","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"autoImplementation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"borrowCapGuardian","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"borrowCaps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"borrowGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"name":"borrowVerify","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"uint256","name":"accountBorrowsNew","type":"uint256"}],"name":"borrowWithinLimits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"cTokensByUnderlying","outputs":[{"internalType":"contract CToken","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"checkMembership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"closeFactorMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"comptrollerImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"enforceWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"cTokens","type":"address[]"}],"name":"enterMarkets","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cTokenAddress","type":"address"}],"name":"exitMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"fuseAdminHasRights","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"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"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAllBorrowers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAllMarkets","outputs":[{"internalType":"contract CToken[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAssetsIn","outputs":[{"internalType":"contract CToken[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"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"}],"name":"getHypotheticalAccountLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getRewardsDistributors","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getWhitelist","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isComptroller","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"isDeprecated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"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":"actualRepayAmount","type":"uint256"},{"internalType":"uint256","name":"seizeTokens","type":"uint256"}],"name":"liquidateBorrowVerify","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"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"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"liquidationIncentiveMantissa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"markets","outputs":[{"internalType":"bool","name":"isListed","type":"bool"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"minter","type":"address"},{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"mintAllowed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"uint256","name":"exchangeRateMantissa","type":"uint256"},{"internalType":"uint256","name":"accountTokens","type":"uint256"},{"internalType":"uint256","name":"mintAmount","type":"uint256"}],"name":"mintWithinLimits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"oracle","outputs":[{"internalType":"contract PriceOracle","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pauseGuardian","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pendingComptrollerImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"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":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"cToken","type":"address"},{"internalType":"address","name":"payer","type":"address"},{"internalType":"address","name":"borrower","type":"address"},{"internalType":"uint256","name":"actualRepayAmount","type":"uint256"},{"internalType":"uint256","name":"borrowerIndex","type":"uint256"}],"name":"repayBorrowVerify","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardsDistributors","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"seizeGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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":"seizeVerify","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"suppliers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"supplyCaps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"transferGuardianPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"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":"transferVerify","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"whitelistArray","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040526001805460ff60a81b1960ff60a01b19909116600160a01b1716600160a81b17905534801561003257600080fd5b50615db380620000436000396000f3fe608060405234801561001057600080fd5b506004361061048a5760003560e01c80636d154ea511610262578063bb82aa5e11610151578063d5333166116100ce578063e4028eee11610092578063e4028eee146111e1578063e6653f3d1461120d578063e875544614611215578063eabe7d911461121d578063ede4edd014611253578063f851a440146112795761048a565b8063d533316614611150578063da3d454c1461116f578063dce15449146111a5578063dcfbc0c7146111d1578063dd5cd22c146111d95761048a565b8063c8c9c97511610115578063c8c9c9751461101f578063c90c20b1146110dd578063d01f63f5146110e5578063d02f7351146110ed578063d251fefc146111335761048a565b8063bb82aa5e14610ece578063bdcdc25814610ed6578063c299823814610f12578063c488847b14610fb3578063c6c5b0dd146110025761048a565b8063929fe9a1116101df578063abfceffc116101a3578063abfceffc14610e6a578063ac0b0bb714610e90578063b0772d0b14610e98578063b095721014610ea0578063b9b5b15314610ea85761048a565b8063929fe9a114610d5a57806394543c1514610d88578063952adf5a14610dae5780639b19251a14610dcd578063aba35b9814610df35761048a565b80637dc0d1d0116102265780637dc0d1d014610cc4578063819605a814610ccc57806387f7630314610cf25780638e8f294b14610cfa5780638ebf636414610d3b5761048a565b80636d154ea514610be95780636d35bf9114610c0f578063731f0c2b14610c555780637515bafa14610c7b578063779b229414610c985761048a565b80633c94786f1161037e57806352d84d1e116102fb5780635f5af1aa116102bf5780635f5af1aa14610a7b5780635fc7e71e14610aa1578063607ef6c114610ae7578063632e514214610ba55780636a56947e14610bad5761048a565b806352d84d1e146109d457806355ee1fe1146109f15780635c77860514610a175780635d72de6214610a4d5780635ec88c7914610a555761048a565b80634e79238f116103425780634e79238f1461082d5780634ef4c3e1146108875780634fd42e17146108bd57806351a485e4146108da57806351dff989146109985761048a565b80633c94786f1461076f57806341c728b91461077757806347ef3b3b146107b35780634a584432146107ff5780634ada90af146108255761048a565b806324a3d6221161040c57806331ff47fa116103d057806331ff47fa1461069557806332abcdbe146106bb5780633605b51b14610713578063391957d71461071b5780633bcf7ec1146107415761048a565b806324a3d6221461064157806326782247146106495780632d70db78146106515780632f1069ba14610670578063317b0b77146106785761048a565b80631d504dc6116104535780631d504dc61461053f5780631ededc911461056757806321af4569146105a95780632259192a146105cd57806324008a62146106055761048a565b80627e3dd21461048f57806302c3bcbb146104ab5780630a755ec2146104e357806316dc15fe146104eb57806318c882a514610511575b600080fd5b610497611281565b604080519115158252519081900360200190f35b6104d1600480360360208110156104c157600080fd5b50356001600160a01b0316611286565b60408051918252519081900360200190f35b610497611298565b6104976004803603602081101561050157600080fd5b50356001600160a01b03166112a8565b6104976004803603604081101561052757600080fd5b506001600160a01b03813516906020013515156112bd565b6105656004803603602081101561055557600080fd5b50356001600160a01b0316611450565b005b610565600480360360a081101561057d57600080fd5b506001600160a01b038135811691602081013582169160408201351690606081013590608001356116ff565b6105b1611706565b604080516001600160a01b039092168252519081900360200190f35b6104d1600480360360808110156105e357600080fd5b506001600160a01b03813516906020810135906040810135906060013561171a565b6104d16004803603608081101561061b57600080fd5b506001600160a01b03813581169160208101358216916040820135169060600135611729565b6105b1611764565b6105b1611773565b6104976004803603602081101561066757600080fd5b50351515611782565b6104976118af565b6104d16004803603602081101561068e57600080fd5b50356118bf565b6105b1600480360360208110156106ab57600080fd5b50356001600160a01b03166119cd565b6106c36119e8565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156106ff5781810151838201526020016106e7565b505050509050019250505060405180910390f35b6106c3611a4b565b6105656004803603602081101561073157600080fd5b50356001600160a01b0316611aab565b6104976004803603604081101561075757600080fd5b506001600160a01b0381351690602001351515611b5b565b610497611ce9565b6105656004803603608081101561078d57600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135611cf9565b610565600480360360c08110156107c957600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359091169060808101359060a00135611d20565b6104d16004803603602081101561081557600080fd5b50356001600160a01b0316611d25565b6104d1611d37565b6108696004803603608081101561084357600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135611d3d565b60408051938452602084019290925282820152519081900360600190f35b6104d16004803603606081101561089d57600080fd5b506001600160a01b03813581169160208101359091169060400135611d77565b6104d1600480360360208110156108d357600080fd5b503561217b565b610565600480360360408110156108f057600080fd5b810190602081018135600160201b81111561090a57600080fd5b82018360208201111561091c57600080fd5b803590602001918460208302840111600160201b8311171561093d57600080fd5b919390929091602081019035600160201b81111561095a57600080fd5b82018360208201111561096c57600080fd5b803590602001918460208302840111600160201b8311171561098d57600080fd5b50909250905061226a565b610565600480360360808110156109ae57600080fd5b506001600160a01b038135811691602081013590911690604081013590606001356123f9565b6105b1600480360360208110156109ea57600080fd5b5035612453565b6104d160048036036020811015610a0757600080fd5b50356001600160a01b031661247a565b61056560048036036060811015610a2d57600080fd5b506001600160a01b038135811691602081013590911690604001356124fc565b610565612501565b61086960048036036020811015610a6b57600080fd5b50356001600160a01b0316612574565b6104d160048036036020811015610a9157600080fd5b50356001600160a01b03166125a9565b6104d1600480360360a0811015610ab757600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359091169060800135612628565b61056560048036036040811015610afd57600080fd5b810190602081018135600160201b811115610b1757600080fd5b820183602082011115610b2957600080fd5b803590602001918460208302840111600160201b83111715610b4a57600080fd5b919390929091602081019035600160201b811115610b6757600080fd5b820183602082011115610b7957600080fd5b803590602001918460208302840111600160201b83111715610b9a57600080fd5b5090925090506127df565b610565612965565b61056560048036036080811015610bc357600080fd5b506001600160a01b038135811691602081013582169160408201351690606001356129c2565b61049760048036036020811015610bff57600080fd5b50356001600160a01b03166129c7565b610565600480360360a0811015610c2557600080fd5b506001600160a01b03813581169160208101358216916040820135811691606081013590911690608001356116ff565b61049760048036036020811015610c6b57600080fd5b50356001600160a01b03166129dc565b6105b160048036036020811015610c9157600080fd5b50356129f1565b6104d160048036036040811015610cae57600080fd5b506001600160a01b0381351690602001356129fe565b6105b1612b71565b6104d160048036036020811015610ce257600080fd5b50356001600160a01b0316612b80565b610497612eda565b610d2060048036036020811015610d1057600080fd5b50356001600160a01b0316612eea565b60408051921515835260208301919091528051918290030190f35b61049760048036036020811015610d5157600080fd5b50351515612f09565b61049760048036036040811015610d7057600080fd5b506001600160a01b0381358116916020013516613035565b61049760048036036020811015610d9e57600080fd5b50356001600160a01b0316613068565b6104d160048036036020811015610dc457600080fd5b503515156131da565b61049760048036036020811015610de357600080fd5b50356001600160a01b0316613257565b6104d160048036036060811015610e0957600080fd5b813515159190810190604081016020820135600160201b811115610e2c57600080fd5b820183602082011115610e3e57600080fd5b803590602001918460018302840111600160201b83111715610e5f57600080fd5b91935091503561326c565b6106c360048036036020811015610e8057600080fd5b50356001600160a01b031661344b565b6104976134d4565b6106c36134e4565b610497613544565b6104d160048036036020811015610ebe57600080fd5b50356001600160a01b031661354d565b6105b161371e565b6104d160048036036080811015610eec57600080fd5b506001600160a01b0381358116916020810135821691604082013516906060013561372d565b6106c360048036036020811015610f2857600080fd5b810190602081018135600160201b811115610f4257600080fd5b820183602082011115610f5457600080fd5b803590602001918460208302840111600160201b83111715610f7557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506137b7945050505050565b610fe960048036036060811015610fc957600080fd5b506001600160a01b0381358116916020810135909116906040013561384e565b6040805192835260208301919091528051918290030190f35b6105b16004803603602081101561101857600080fd5b5035613a76565b6104d16004803603604081101561103557600080fd5b810190602081018135600160201b81111561104f57600080fd5b82018360208201111561106157600080fd5b803590602001918460208302840111600160201b8311171561108257600080fd5b919390929091602081019035600160201b81111561109f57600080fd5b8201836020820111156110b157600080fd5b803590602001918460208302840111600160201b831117156110d257600080fd5b509092509050613a83565b610565613c96565b6106c3613d47565b6104d1600480360360a081101561110357600080fd5b506001600160a01b0381358116916020810135821691604082013581169160608101359091169060800135613da7565b6105b16004803603602081101561114957600080fd5b5035613f3d565b6104d16004803603602081101561116657600080fd5b50351515613f4a565b6104d16004803603606081101561118557600080fd5b506001600160a01b03813581169160208101359091169060400135613fc7565b6105b1600480360360408110156111bb57600080fd5b506001600160a01b038135169060200135614375565b6105b16143aa565b6104976143b9565b6104d1600480360360408110156111f757600080fd5b506001600160a01b0381351690602001356143c2565b61049761456d565b6104d161457d565b6104d16004803603606081101561123357600080fd5b506001600160a01b03813581169160208101359091169060400135614583565b6104d16004803603602081101561126957600080fd5b50356001600160a01b03166145a0565b6105b161498b565b600181565b60196020526000908152604090205481565b600154600160a81b900460ff1681565b600e6020526000908152604090205460ff1681565b6001600160a01b03821660009081526009602052604081205460ff166113145760405162461bcd60e51b8152600401808060200182810382526028815260200180615b4e6028913960400191505060405180910390fd5b6014546001600160a01b0316331480611330575061133061499a565b61136b5760405162461bcd60e51b8152600401808060200182810382526027815260200180615bd96027913960400191505060405180910390fd5b61137361499a565b8061138057506001821515145b6113ca576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b6001600160a01b038316600081815260166020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260069083015265426f72726f7760d01b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150805b92915050565b33734afb2b3dc111d091ca6c46c024d1d2f17bf477e11480156114d45750806001600160a01b0316632f1069ba6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114a757600080fd5b505afa1580156114bb573d6000803e3d6000fd5b505050506040513d60208110156114d157600080fd5b50515b806115b75750806001600160a01b031663f851a4406040518163ffffffff1660e01b815260040160206040518083038186803b15801561151357600080fd5b505afa158015611527573d6000803e3d6000fd5b505050506040513d602081101561153d57600080fd5b50516001600160a01b0316331480156115b75750806001600160a01b0316630a755ec26040518163ffffffff1660e01b815260040160206040518083038186803b15801561158a57600080fd5b505afa15801561159e573d6000803e3d6000fd5b505050506040513d60208110156115b457600080fd5b50515b6115f25760405162461bcd60e51b8152600401808060200182810382526027815260200180615d586027913960400191505060405180910390fd5b6000816001600160a01b031663c1e803346040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561162f57600080fd5b505af1158015611643573d6000803e3d6000fd5b505050506040513d602081101561165957600080fd5b5051905080156116a8576040805162461bcd60e51b815260206004820152601560248201527418da185b99d9481b9bdd08185d5d1a1bdc9a5e9959605a1b604482015290519081900360640190fd5b816001600160a01b0316635d72de626040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156116e357600080fd5b505af11580156116f7573d6000803e3d6000fd5b505050505050565b5050505050565b60175461010090046001600160a01b031681565b6000805b90505b949350505050565b6001600160a01b03841660009081526009602052604081205460ff166117535760095b9050611721565b61175d85846149f5565b600061171e565b6014546001600160a01b031681565b6001546001600160a01b031681565b6014546000906001600160a01b03163314806117a157506117a161499a565b6117dc5760405162461bcd60e51b8152600401808060200182810382526027815260200180615bd96027913960400191505060405180910390fd5b6117e461499a565b806117f157506001821515145b61183b576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b60148054831515600160b81b810260ff60b81b1990921691909117909155604080516020810192909252808252600582820152645365697a6560d81b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a150805b919050565b600154600160a01b900460ff1681565b60006118c961499a565b6118e0576118d960016007614a8d565b90506118aa565b6118e8615a65565b5060408051602081019091528281526118ff615a65565b50604080516020810190915266b1a2bc2ec50000815261191f8282614af3565b156119395761193060056008614a8d565b925050506118aa565b611941615a65565b506040805160208101909152670c7d713b49da000081526119628184614afb565b1561197d5761197360056008614a8d565b93505050506118aa565b6005805490869055604080518281526020810188905281517f3b9670cf975d26958e754b57098eaa2ac914d8d2a31b83257997b9f346110fd9929181900390910190a160005b9695505050505050565b600f602052600090815260409020546001600160a01b031681565b6060600c805480602002602001604051908101604052809291908181526020018280548015611a4057602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611a22575b505050505090505b90565b6060601a805480602002602001604051908101604052809291908181526020018280548015611a40576020028201919060005260206000209081546001600160a01b03168152600190910190602001808311611a22575050505050905090565b611ab361499a565b611aee5760405162461bcd60e51b8152600401808060200182810382526026815260200180615c006026913960400191505060405180910390fd5b601780546001600160a01b03838116610100818102610100600160a81b03198516179094556040805194909304919091168084526020840191909152815190927feda98690e518e9a05f8ec6837663e188211b2da8f4906648b323f2c1d4434e2992908290030190a15050565b6001600160a01b03821660009081526009602052604081205460ff16611bb25760405162461bcd60e51b8152600401808060200182810382526028815260200180615b4e6028913960400191505060405180910390fd5b6014546001600160a01b0316331480611bce5750611bce61499a565b611c095760405162461bcd60e51b8152600401808060200182810382526027815260200180615bd96027913960400191505060405180910390fd5b611c1161499a565b80611c1e57506001821515145b611c68576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b6001600160a01b038316600081815260156020908152604091829020805486151560ff199091168117909155825193845283830152606090830181905260049083015263135a5b9d60e21b6080830152517f71aec636243f9709bb0007ae15e9afb8150ab01716d75fd7573be5cc096e03b09181900360a00190a150919050565b601454600160a01b900460ff1681565b50506001600160a01b03166000908152600e60205260409020805460ff1916600117905550565b6116f7565b60186020526000908152604090205481565b60065481565b600080600080600080611d528a8a8a8a614b02565b925092509250826015811115611d6457fe5b95509093509150505b9450945094915050565b6001600160a01b03831660009081526015602052604081205460ff1615611dd6576040805162461bcd60e51b815260206004820152600e60248201526d1b5a5b9d081a5cc81c185d5cd95960921b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff16611e005760095b9050612174565b60105460ff168015611e2b57506001600160a01b03831660009081526011602052604090205460ff16155b15611e37576012611df9565b6001600160a01b0384166000908152601960205260409020548015612163576000856001600160a01b0316633b1d21a26040518163ffffffff1660e01b815260040160206040518083038186803b158015611e9157600080fd5b505afa158015611ea5573d6000803e3d6000fd5b505050506040513d6020811015611ebb57600080fd5b5051604080516308f7a6e360e31b815290519192506000916001600160a01b038916916347bd3718916004808301926020929190829003018186803b158015611f0357600080fd5b505afa158015611f17573d6000803e3d6000fd5b505050506040513d6020811015611f2d57600080fd5b505160408051638f840ddd60e01b815290519192506000916001600160a01b038a1691638f840ddd916004808301926020929190829003018186803b158015611f7557600080fd5b505afa158015611f89573d6000803e3d6000fd5b505050506040513d6020811015611f9f57600080fd5b50516040805163dc028ab160e01b815290519192506000916001600160a01b038b169163dc028ab1916004808301926020929190829003018186803b158015611fe757600080fd5b505afa158015611ffb573d6000803e3d6000fd5b505050506040513d602081101561201157600080fd5b5051604080516361feacff60e01b815290519192506000916001600160a01b038c16916361feacff916004808301926020929190829003018186803b15801561205957600080fd5b505afa15801561206d573d6000803e3d6000fd5b505050506040513d602081101561208357600080fd5b505190506000806120a787876120a261209c8989614e3a565b87614e3a565b614e70565b909250905060008260038111156120ba57fe5b146120d057600b98505050505050505050612174565b60006120dc828c614ebc565b909350905060008360038111156120ef57fe5b1461210657600b9950505050505050505050612174565b88811061215a576040805162461bcd60e51b815260206004820152601960248201527f6d61726b657420737570706c7920636170207265616368656400000000000000604482015290519081900360640190fd5b50505050505050505b61216d8585614ee5565b60005b9150505b9392505050565b600061218561499a565b612195576118d96001600d614a8d565b61219d615a65565b5060408051602081019091528281526121b4615a65565b506040805160208101909152670de0b6b3a764000081526121d58282614afb565b156121e6576119306007600e614a8d565b6121ee615a65565b5060408051602081019091526714d1120d7b160000815261220f8184614afb565b15612220576119736007600e614a8d565b6006805490869055604080518281526020810188905281517faeba5a6c40a8ac138134bff1aaa65debf25971188a58804bad717f82f0ec1316929181900390910190a160006119c3565b61227261499a565b8061228c575060175461010090046001600160a01b031633145b6122c75760405162461bcd60e51b8152600401808060200182810382526035815260200180615cee6035913960400191505060405180910390fd5b828181158015906122d757508082145b612318576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081a5b9c1d5d609a1b604482015290519081900360640190fd5b60005b828110156123f05784848281811061232f57fe5b905060200201356019600089898581811061234657fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b031681526020019081526020016000208190555086868281811061238657fe5b905060200201356001600160a01b03166001600160a01b03167f9e0ad9cee10bdf36b7fbd38910c0bdff0f275ace679b45b922381c2723d676f88686848181106123cc57fe5b905060200201356040518082815260200191505060405180910390a260010161231b565b50505050505050565b801580156124075750600082115b1561244d576040805162461bcd60e51b815260206004820152601160248201527072656465656d546f6b656e73207a65726f60781b604482015290519081900360640190fd5b50505050565b600a818154811061246057fe5b6000918252602090912001546001600160a01b0316905081565b600061248461499a565b612494576118d960016013614a8d565b600480546001600160a01b038481166001600160a01b0319831681179093556040805191909216808252602082019390935281517fd52b2b9b7e9ee655fcb95d2e5b9e0c9f69e7ef2b8e9d2d0ea78402d576d22e22929181900390910190a160009392505050565b505050565b6002546001600160a01b0316331461254a5760405162461bcd60e51b8152600401808060200182810382526032815260200180615c266032913960400191505060405180910390fd5b601b54610100900460ff1661257257601b805461ff001960ff19909116600117166101001790555b565b60008060008060008061258b876000806000614b02565b92509250925082601581111561259d57fe5b97919650945092505050565b60006125b361499a565b6125c3576118d960016018614a8d565b601480546001600160a01b038481166001600160a01b0319831617928390556040805192821680845293909116602083015280517f0613b6ee6a04f0d09f390e4d9318894b9f6ac7fd83897cd8d18896ba579c401e9281900390910190a16000612174565b6001600160a01b03851660009081526009602052604081205460ff16158061266957506001600160a01b03851660009081526009602052604090205460ff16155b156126785760095b90506127d6565b6000866001600160a01b03166395dd9193856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156126d057600080fd5b505afa1580156126e4573d6000803e3d6000fd5b505050506040513d60208110156126fa57600080fd5b5051905061270787613068565b15612750578281101561274b5760405162461bcd60e51b8152600401808060200182810382526028815260200180615b766028913960400191505060405180910390fd5b6127d0565b60008061275c86614f7c565b9193509091506000905082601581111561277257fe5b1461278d5781601581111561278357fe5b93505050506127d6565b80612799576003612783565b60006127b5604051806020016040528060055481525085614f9c565b9050808611156127cc5760119450505050506127d6565b5050505b60009150505b95945050505050565b6127e761499a565b80612801575060175461010090046001600160a01b031633145b61283c5760405162461bcd60e51b8152600401808060200182810382526035815260200180615c946035913960400191505060405180910390fd5b8281811580159061284c57508082145b61288d576040805162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081a5b9c1d5d609a1b604482015290519081900360640190fd5b60005b828110156123f0578484828181106128a457fe5b90506020020135601860008989858181106128bb57fe5b905060200201356001600160a01b03166001600160a01b03166001600160a01b03168152602001908152602001600020819055508686828181106128fb57fe5b905060200201356001600160a01b03166001600160a01b03167f6f1951b2aad10f3fc81b86d91105b413a5b3f847a34bbc5ce1904201b14438f686868481811061294157fe5b905060200201356040518082815260200191505060405180910390a2600101612890565b3360009081526009602052604090205460ff166129b35760405162461bcd60e51b815260040180806020018281038252603b815260200180615b9e603b913960400191505060405180910390fd5b601b805460ff19166001179055565b61244d565b60166020526000908152604090205460ff1681565b60156020526000908152604090205460ff1681565b600c818154811061246057fe5b600080734afb2b3dc111d091ca6c46c024d1d2f17bf477e16001600160a01b031663fdb25fb16040518163ffffffff1660e01b815260040160206040518083038186803b158015612a4e57600080fd5b505afa158015612a62573d6000803e3d6000fd5b505050506040513d6020811015612a7857600080fd5b505190508015612b6757600480546040805163fc57d4df60e01b81526001600160a01b038881169482019490945290516000939092169163fc57d4df91602480820192602092909190829003018186803b158015612ad557600080fd5b505afa158015612ae9573d6000803e3d6000fd5b505050506040513d6020811015612aff57600080fd5b5051905080612b1357600d9250505061144a565b600080612b2e60405180602001604052808581525087614fbb565b90925090506000826003811115612b4157fe5b14612b5457600b5b94505050505061144a565b83811015612b63576013612b49565b5050505b6000949350505050565b6004546001600160a01b031681565b6000612b8a61499a565b612b9a576118d960016019614a8d565b6001600160a01b03821660009081526009602052604090205460ff16612bc6576118d96009601a614a8d565b6000826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612c0157600080fd5b505afa158015612c15573d6000803e3d6000fd5b505050506040513d6020811015612c2b57600080fd5b50511115612c3f576118d96015601b614a8d565b6001600160a01b0382166000908152600960209081526040808320805460ff1916815560010192909255600a805483518184028101840190945280845260609392830182828015612cb957602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612c9b575b5050835193945083925060009150505b82811015612d0e57856001600160a01b0316848281518110612ce757fe5b60200260200101516001600160a01b03161415612d0657809150612d0e565b600101612cc9565b50818110612d1857fe5b600a80546000198101908110612d2a57fe5b600091825260209091200154600a80546001600160a01b039092169183908110612d5057fe5b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055600a805490612d8c906000198301615a78565b506000600f6000876001600160a01b031663ac784ddc6040518163ffffffff1660e01b815260040160206040518083038186803b158015612dcc57600080fd5b505afa158015612de0573d6000803e3d6000fd5b505050506040513d6020811015612df657600080fd5b5051612e6657876001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b158015612e3557600080fd5b505afa158015612e49573d6000803e3d6000fd5b505050506040513d6020811015612e5f57600080fd5b5051612e69565b60005b6001600160a01b039081168252602080830193909352604091820160002080546001600160a01b0319169482169490941790935580519288168352517f302feb03efd5741df80efe7f97f5d93d74d46a542a3d312d0faae64fa1f3e0e99281900390910190a1600095945050505050565b601454600160b01b900460ff1681565b6009602052600090815260409020805460019091015460ff9091169082565b6014546000906001600160a01b0316331480612f285750612f2861499a565b612f635760405162461bcd60e51b8152600401808060200182810382526027815260200180615bd96027913960400191505060405180910390fd5b612f6b61499a565b80612f7857506001821515145b612fc2576040805162461bcd60e51b81526020600482015260166024820152756f6e6c792061646d696e2063616e20756e706175736560501b604482015290519081900360640190fd5b60148054831515600160b01b810260ff60b01b1990921691909117909155604080516020810192909252808252600882820152672a3930b739b332b960c11b6060830152517fef159d9a32b2472e32b098f954f3ce62d232939f1c207070b584df1814de2de09181900360800190a15090565b6001600160a01b038082166000908152600960209081526040808320938616835260029093019052205460ff1692915050565b6001600160a01b0381166000908152600960205260408120600101541580156130ae57506001600160a01b03821660009081526016602052604090205460ff1615156001145b801561144a57506131ca613191836001600160a01b031663173b99046040518163ffffffff1660e01b815260040160206040518083038186803b1580156130f457600080fd5b505afa158015613108573d6000803e3d6000fd5b505050506040513d602081101561311e57600080fd5b505160408051638d02d9a160e01b815290516001600160a01b03871691638d02d9a1916004808301926020929190829003018186803b15801561316057600080fd5b505afa158015613174573d6000803e3d6000fd5b505050506040513d602081101561318a57600080fd5b5051614e3a565b836001600160a01b031663dbfe7c196040518163ffffffff1660e01b815260040160206040518083038186803b15801561316057600080fd5b670de0b6b3a76400001492915050565b60006131e461499a565b6131f4576118d960016014614a8d565b60105460ff161515821515141561320c5760006118d9565b6010805483151560ff19909116811790915560408051918252517f84c7d948374a180eddab35d27d2f7a94167a1ff4e79467f1e89c061984190a1e9181900360200190a1600061144a565b60116020526000908152604090205460ff1681565b600061327661499a565b6132865761174c60016017614a8d565b60018054600160a01b60ff60a01b19821681179092550460ff1660008661335757604051638754e4fd60e01b815260206004820190815260248201879052734afb2b3dc111d091ca6c46c024d1d2f17bf477e191638754e4fd9189918991908190604401848480828437600081840152601f19601f8201169050808301925050509350505050602060405180830381600087803b15801561332657600080fd5b505af115801561333a573d6000803e3d6000fd5b505050506040513d602081101561335057600080fd5b5051613403565b604051639b86a9b560e01b815260206004820190815260248201879052734afb2b3dc111d091ca6c46c024d1d2f17bf477e191639b86a9b59189918991908190604401848480828437600081840152601f19601f8201169050808301925050509350505050602060405180830381600087803b1580156133d657600080fd5b505af11580156133ea573d6000803e3d6000fd5b505050506040513d602081101561340057600080fd5b50515b6001805460ff60a01b1916600160a01b85151502179055905060006134278261500e565b90508015613435578061343f565b61343f82866143c2565b98975050505050505050565b60608060086000846001600160a01b03166001600160a01b031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156134c757602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116134a9575b5093979650505050505050565b601454600160b81b900460ff1681565b6060600a805480602002602001604051908101604052809291908181526020018280548015611a40576020028201919060005260206000209081546001600160a01b03168152600190910190602001808311611a22575050505050905090565b60105460ff1681565b600061355761499a565b613567576118d960016002614a8d565b816001600160a01b031663abc6d72d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156135a057600080fd5b505afa1580156135b4573d6000803e3d6000fd5b505050506040513d60208110156135ca57600080fd5b505161361d576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b60005b601a5481101561369557601a818154811061363757fe5b6000918252602090912001546001600160a01b038481169116141561368d5760405162461bcd60e51b8152600401808060200182810382526029815260200180615b256029913960400191505060405180910390fd5b600101613620565b50601a80546001810182556000919091527f057c384a7d1c54f3a1b2e5e67b2617b8224fdfd1ea7234eea573a6ff665ff63e0180546001600160a01b0384166001600160a01b0319909116811790915560408051918252517f98ef1187fb6fd2bc85f8996489877eb2b5428f9e9bdfc068c9ad6c2ea82eacc79181900360200190a1600061144a565b6002546001600160a01b031681565b601454600090600160b01b900460ff1615613784576040805162461bcd60e51b81526020600482015260126024820152711d1c985b9cd9995c881a5cc81c185d5cd95960721b604482015290519081900360640190fd5b60006137918686856153a1565b905080156137a0579050611721565b6137ab86868661544d565b60009695505050505050565b60606000825190506060816040519080825280602002602001820160405280156137eb578160200160208202803883390190505b50905060005b8281101561384657600085828151811061380757fe5b6020026020010151905061381b81336154ed565b601581111561382657fe5b83838151811061383257fe5b6020908102919091010152506001016137f1565b509392505050565b600480546040805163fc57d4df60e01b81526001600160a01b038781169482019490945290516000938493849391169163fc57d4df91602480820192602092909190829003018186803b1580156138a457600080fd5b505afa1580156138b8573d6000803e3d6000fd5b505050506040513d60208110156138ce57600080fd5b5051600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051939450600093929091169163fc57d4df91602480820192602092909190829003018186803b15801561392757600080fd5b505afa15801561393b573d6000803e3d6000fd5b505050506040513d602081101561395157600080fd5b50519050811580613960575080155b1561397557600d935060009250613a6e915050565b6000866001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b1580156139b057600080fd5b505afa1580156139c4573d6000803e3d6000fd5b505050506040513d60208110156139da57600080fd5b5051905060006139e8615a65565b6139f0615a65565b6139f8615a65565b613a20604051806020016040528060065481525060405180602001604052808a81525061567a565b9250613a4860405180602001604052808881525060405180602001604052808881525061567a565b9150613a5483836156b9565b9050613a60818b614f9c565b600099509750505050505050505b935093915050565b601a818154811061246057fe5b6000613a8d61499a565b613a9d5761174c60016015614a8d565b60005b84811015613c8e576000868683818110613ab657fe5b905060200201356001600160a01b03169050848483818110613ad457fe5b9050602002013515613b80576001600160a01b03811660009081526011602052604090205460ff16613b7b576001600160a01b0381166000818152601160209081526040808320805460ff191660019081179091556012805491820181557fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec344490910180546001600160a01b0319168617905554938352601390915290206000199190910190555b613c85565b6001600160a01b03811660009081526011602052604090205460ff1615613c85576001600160a01b03811660009081526013602052604090205460125460001901811015613c425760128054600091906000198101908110613bde57fe5b600091825260209091200154601280546001600160a01b039092169250829184908110613c0757fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559290911681526013909152604090208190555b6012805490613c55906000198301615a78565b50506001600160a01b038116600090815260136020908152604080832083905560119091529020805460ff191690555b50600101613aa0565b50600061171e565b3360009081526009602052604090205460ff16613ce45760405162461bcd60e51b815260040180806020018281038252603c815260200180615c58603c913960400191505060405180910390fd5b601b5460ff16613d3b576040805162461bcd60e51b815260206004820152601860248201527f72652d656e7465726564206163726f7373206173736574730000000000000000604482015290519081900360640190fd5b601b805460ff19169055565b60606012805480602002602001604051908101604052809291908181526020018280548015611a40576020028201919060005260206000209081546001600160a01b03168152600190910190602001808311611a22575050505050905090565b601454600090600160b81b900460ff1615613dfb576040805162461bcd60e51b815260206004820152600f60248201526e1cd95a5e99481a5cc81c185d5cd959608a1b604482015290519081900360640190fd5b6001600160a01b03861660009081526009602052604090205460ff161580613e3c57506001600160a01b03851660009081526009602052604090205460ff16155b15613e48576009612671565b846001600160a01b0316635fe3b5676040518163ffffffff1660e01b815260040160206040518083038186803b158015613e8157600080fd5b505afa158015613e95573d6000803e3d6000fd5b505050506040513d6020811015613eab57600080fd5b505160408051635fe3b56760e01b815290516001600160a01b0392831692891691635fe3b567916004808301926020929190829003018186803b158015613ef157600080fd5b505afa158015613f05573d6000803e3d6000fd5b505050506040513d6020811015613f1b57600080fd5b50516001600160a01b031614613f32576002612671565b6137ab86848661544d565b6012818154811061246057fe5b6000613f5461499a565b613f64576118d960016006614a8d565b60175460ff1615158215151415613f7c5760006118d9565b6017805483151560ff19909116811790915560408051918252517faa40ee94af55250363b91641a0a615c47690148901505f89b01dafae03fff2819181900360200190a1600061144a565b6001600160a01b03831660009081526016602052604081205460ff1615614028576040805162461bcd60e51b815260206004820152601060248201526f189bdc9c9bddc81a5cc81c185d5cd95960821b604482015290519081900360640190fd5b6001600160a01b03841660009081526009602052604090205460ff1661404f576009611df9565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff1661413f57336001600160a01b038516146140d5576040805162461bcd60e51b815260206004820152601560248201527439b2b73232b91036bab9ba1031329031aa37b5b2b760591b604482015290519081900360640190fd5b60006140e133856154ed565b905060008160158111156140f157fe5b1461410a5780601581111561410257fe5b915050612174565b6001600160a01b038086166000908152600960209081526040808320938816835260029093019052205460ff1661413d57fe5b505b600480546040805163fc57d4df60e01b81526001600160a01b03888116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b15801561419057600080fd5b505afa1580156141a4573d6000803e3d6000fd5b505050506040513d60208110156141ba57600080fd5b50516141c757600d611df9565b60105460ff1680156141f257506001600160a01b03831660009081526011602052604090205460ff16155b156141fe576012611df9565b6001600160a01b0384166000908152601860205260409020548015614310576000856001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561425857600080fd5b505afa15801561426c573d6000803e3d6000fd5b505050506040513d602081101561428257600080fd5b505190506000806142938387614ebc565b909250905060008260038111156142a657fe5b146142b857600b945050505050612174565b83811061430c576040805162461bcd60e51b815260206004820152601960248201527f6d61726b657420626f72726f7720636170207265616368656400000000000000604482015290519081900360640190fd5b5050505b61431a85856149f5565b60008061432a8688600088614b02565b9193509091506000905082601581111561434057fe5b1461435b5781601581111561435157fe5b9350505050612174565b8015614368576004614351565b6000979650505050505050565b6008602052816000526040600020818154811061438e57fe5b6000918252602090912001546001600160a01b03169150829050565b6003546001600160a01b031681565b60175460ff1681565b60006143cc61499a565b6143e3576143dc60016009614a8d565b905061144a565b6001600160a01b0383166000908152600960205260409020805460ff16614418576144106009600a614a8d565b91505061144a565b614420615a65565b506040805160208101909152838152614437615a65565b506040805160208101909152670c7d713b49da000081526144588183614afb565b15614473576144696006600b614a8d565b935050505061144a565b84158015906144fc5750600480546040805163fc57d4df60e01b81526001600160a01b038a8116948201949094529051929091169163fc57d4df91602480820192602092909190829003018186803b1580156144ce57600080fd5b505afa1580156144e2573d6000803e3d6000fd5b505050506040513d60208110156144f857600080fd5b5051155b1561450d57614469600d600c614a8d565b60018301805490869055604080516001600160a01b03891681526020810183905280820188905290517f70483e6592cd5182d45ac970e05bc62cdcc90e9d8ef2c2dbe686cf383bcd7fc59181900360600190a16000979650505050505050565b601454600160a81b900460ff1681565b60055481565b6000806145918585856153a1565b90508015612163579050612174565b6000808290506000806000836001600160a01b031663c37f68e2336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b15801561460157600080fd5b505afa158015614615573d6000803e3d6000fd5b505050506040513d608081101561462b57600080fd5b50805160208201516040909201519094509092509050821561467e5760405162461bcd60e51b8152600401808060200182810382526025815260200180615cc96025913960400191505060405180910390fd5b801561469b57614690600c6003614a8d565b9450505050506118aa565b60006146a88733856153a1565b905080156146c9576146bd600e6004836156f5565b955050505050506118aa565b6001600160a01b0385166000908152600960209081526040808320338452600281019092529091205460ff1661470857600096505050505050506118aa565b3360009081526002820160209081526040808320805460ff19169055600882529182902080548351818402810184019094528084526060939283018282801561477a57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161475c575b5050835193945083925060009150505b828110156147cf57896001600160a01b03168482815181106147a857fe5b60200260200101516001600160a01b031614156147c7578091506147cf565b60010161478a565b508181106147d957fe5b3360009081526008602052604090208054819060001981019081106147fa57fe5b9060005260206000200160009054906101000a90046001600160a01b031681838154811061482457fe5b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055805461485d826000198301615a78565b50805461493657336000908152600d6020526040902054600c54600019018110156148fc57600c805460009190600019810190811061489857fe5b600091825260209091200154600c80546001600160a01b0390921692508291849081106148c157fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b03948516179055929091168152600d909152604090208190555b600c80549061490f906000198301615a78565b5050336000908152600d60209081526040808320839055600b9091529020805460ff191690555b604080516001600160a01b038c16815233602082015281517fe699a64c18b07ac5b7301aa273f36a2287239eb9501d81950672794afba29a0d929181900390910190a160009c9b505050505050505050505050565b6000546001600160a01b031681565b600080546001600160a01b0316331480156149be5750600154600160a81b900460ff165b806149f0575033734afb2b3dc111d091ca6c46c024d1d2f17bf477e11480156149f05750600154600160a01b900460ff165b905090565b60005b601a548110156124fc57601a8181548110614a0f57fe5b600091825260208220015460408051631cdc2c5d60e31b81526001600160a01b03878116600483015286811660248301529151919092169263e6e162e8926044808201939182900301818387803b158015614a6957600080fd5b505af1158015614a7d573d6000803e3d6000fd5b5050600190920191506149f89050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0836015811115614abc57fe5b83601b811115614ac857fe5b604080519283526020830191909152600082820152519081900360600190a182601581111561217457fe5b519051111590565b5190511090565b6000806000614b0f615a9c565b6001600160a01b03881660009081526008602090815260408083208054825181850281018501909352808352606093830182828015614b7757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311614b59575b50939450600093505050505b8151811015614dfb576000828281518110614b9a57fe5b60200260200101519050806001600160a01b031663c37f68e28d6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060806040518083038186803b158015614bfa57600080fd5b505afa158015614c0e573d6000803e3d6000fd5b505050506040513d6080811015614c2457600080fd5b508051602082015160408084015160609485015160808b0152938901939093529187019190915293508315614c695750600f965060009550859450611d6d9350505050565b60408051602080820183526001600160a01b0380851660008181526009845285902060010154845260c08a01939093528351808301855260808a0151815260e08a015260048054855163fc57d4df60e01b815291820194909452935192169263fc57d4df9260248083019392829003018186803b158015614ce957600080fd5b505afa158015614cfd573d6000803e3d6000fd5b505050506040513d6020811015614d1357600080fd5b505160a08601819052614d365750600d965060009550859450611d6d9350505050565b604080516020810190915260a0860151815261010086015260c085015160e0860151614d7091614d659161567a565b86610100015161567a565b610120860181905260408601518651614d8a92919061575b565b855261010085015160608601516020870151614da792919061575b565b60208601526001600160a01b03818116908c161415614df257614dd48561012001518b876020015161575b565b60208601819052610100860151614dec918b9061575b565b60208601525b50600101614b83565b50602083015183511115614e215750506020810151905160009450039150829050611d6d565b5050805160209091015160009450849350039050611d6d565b60006121748383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250615783565b600080600080614e808787614ebc565b90925090506000826003811115614e9357fe5b14614ea45750915060009050613a6e565b614eae818661581e565b935093505050935093915050565b600080838301848110614ed457600092509050614ede565b5060029150600090505b9250929050565b60005b601a548110156124fc57601a8181548110614eff57fe5b60009182526020822001546040805162e48b0f60e51b81526001600160a01b038781166004830152868116602483015291519190921692631c9161e0926044808201939182900301818387803b158015614f5857600080fd5b505af1158015614f6c573d6000803e3d6000fd5b505060019092019150614ee89050565b6000806000614f8f846000806000614b02565b9250925092509193909250565b6000614fa6615a65565b614fb08484615841565b905061172181615862565b6000806000614fc8615a65565b614fd28686615871565b90925090506000826003811115614fe557fe5b14614ff65750915060009050614ede565b600061500182615862565b9350935050509250929050565b600061501861499a565b615028576118d960016017614a8d565b6001600160a01b03821660009081526009602052604090205460ff1615615055576118d9600a6016614a8d565b816001600160a01b031663fe9c44ae6040518163ffffffff1660e01b815260040160206040518083038186803b15801561508e57600080fd5b505afa1580156150a2573d6000803e3d6000fd5b505050506040513d60208110156150b857600080fd5b505161510b576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b306001600160a01b0316826001600160a01b0316635fe3b5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561514e57600080fd5b505afa158015615162573d6000803e3d6000fd5b505050506040513d602081101561517857600080fd5b50516001600160a01b0316146151bf5760405162461bcd60e51b8152600401808060200182810382526035815260200180615d236035913960400191505060405180910390fd5b6000826001600160a01b031663ac784ddc6040518163ffffffff1660e01b815260040160206040518083038186803b1580156151fa57600080fd5b505afa15801561520e573d6000803e3d6000fd5b505050506040513d602081101561522457600080fd5b505161529457826001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561526357600080fd5b505afa158015615277573d6000803e3d6000fd5b505050506040513d602081101561528d57600080fd5b5051615297565b60005b6001600160a01b038082166000908152600f602052604090205491925016156152ce576152c6600a6016614a8d565b9150506118aa565b6040805180820182526001808252600060208084018281526001600160a01b03898116808552600984528785209651875460ff1916901515178755915195850195909555600a805494850190557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a890930180546001600160a01b031990811685179091559386168252600f81529084902080549093168217909255825190815291517fcf583bb0c569eb967f806b11601c4cb93c10310485c67add5f8362c2f212321f9281900390910190a16000612174565b6001600160a01b03831660009081526009602052604081205460ff166153c8576009611df9565b6001600160a01b038085166000908152600960209081526040808320938716835260029093019052205460ff16615400576000611df9565b6000806154108587866000614b02565b9193509091506000905082601581111561542657fe5b146154405781601581111561543757fe5b92505050612174565b80156137ab576004615437565b60005b601a5481101561244d57601a818154811061546757fe5b600091825260208220015460408051634e081c9560e01b81526001600160a01b0388811660048301528781166024830152868116604483015291519190921692634e081c95926064808201939182900301818387803b1580156154c957600080fd5b505af11580156154dd573d6000803e3d6000fd5b5050600190920191506154509050565b6001600160a01b0382166000908152600960205260408120805460ff1661551857600991505061144a565b6001600160a01b038316600090815260028201602052604090205460ff1615156001141561554a57600091505061144a565b6001600160a01b03838116600081815260028401602090815260408083208054600160ff199091168117909155600883528184208054918201815584528284200180546001600160a01b031916958a1695909517909455918152600b909152205460ff1661562b57600c8054600180820183557fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c790910180546001600160a01b0319166001600160a01b0387169081179091556000908152600b60209081526040808320805460ff19169094179093559254600d9093522060001990910190555b604080516001600160a01b0380871682528516602082015281517f3ab23ab0d51cccc0c3085aec51f99228625aa1a922b3a8ca89a26b0f2027a1a5929181900390910190a15060009392505050565b615682615a65565b6040518060200160405280670de0b6b3a76400006156a8866000015186600001516158d9565b816156af57fe5b0490529392505050565b6156c1615a65565b60405180602001604052806156ec6156e58660000151670de0b6b3a76400006158d9565b855161591b565b90529392505050565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa084601581111561572457fe5b84601b81111561573057fe5b604080519283526020830191909152818101859052519081900360600190a183601581111561172157fe5b6000615765615a65565b61576f8585615841565b905061217061577d82615862565b84614e3a565b600083830182858210156158155760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156157da5781810151838201526020016157c2565b50505050905090810190601f1680156158075780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50949350505050565b600080838311615835575060009050818303614ede565b50600390506000614ede565b615849615a65565b60405180602001604052806156ec8560000151856158d9565b51670de0b6b3a7640000900490565b600061587b615a65565b60008061588c86600001518661594e565b9092509050600082600381111561589f57fe5b146158be57506040805160208101909152600081529092509050614ede565b60408051602081019091529081526000969095509350505050565b600061217483836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f7700000000000000000081525061598d565b600061217483836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250615a03565b6000808361596157506000905080614ede565b8383028385828161596e57fe5b041461598257506002915060009050614ede565b600092509050614ede565b600083158061599a575082155b156159a757506000612174565b838302838582816159b457fe5b041483906158155760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156157da5781810151838201526020016157c2565b60008183615a525760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156157da5781810151838201526020016157c2565b50828481615a5c57fe5b04949350505050565b6040518060200160405280600081525090565b8154818355818111156124fc576000838152602090206124fc918101908301615b06565b604051806101400160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001615ada615a65565b8152602001615ae7615a65565b8152602001615af4615a65565b8152602001615b01615a65565b905290565b611a4891905b80821115615b205760008155600101615b0c565b509056fe526577617264734469737472696275746f7220636f6e747261637420616c726561647920616464656463616e6e6f742070617573652061206d61726b65742074686174206973206e6f74206c697374656443616e206e6f74207265706179206d6f7265207468616e2074686520746f74616c20626f72726f77436f6d7074726f6c6c65723a5f61667465724e6f6e5265656e7472616e743a2063616c6c6572206e6f74206c6973746564206173206d61726b65746f6e6c7920706175736520677561726469616e20616e642061646d696e2063616e2070617573656f6e6c792061646d696e2063616e2073657420626f72726f772063617020677561726469616e6f6e6c7920696d706c656d656e746174696f6e206d61792063616c6c205f6265636f6d65496d706c656d656e746174696f6e436f6d7074726f6c6c65723a5f6265666f72654e6f6e5265656e7472616e743a2063616c6c6572206e6f74206c6973746564206173206d61726b65746f6e6c792061646d696e206f7220626f72726f772063617020677561726469616e2063616e2073657420626f72726f772063617073657869744d61726b65743a206765744163636f756e74536e617073686f74206661696c65646f6e6c792061646d696e206f7220626f72726f772063617020677561726469616e2063616e2073657420737570706c79206361707343616e6e6f7420737570706f72742061206d61726b65742077697468206120646966666572656e7420436f6d7074726f6c6c65722e6f6e6c7920756e6974726f6c6c65722061646d696e2063616e206368616e676520627261696e73a265627a7a72315820fbf27f05c82565752ceab138f2e7c90df743ae2aadc8ff401398698d6d3e1e3d64736f6c63430005110032
Deployed ByteCode Sourcemap
551:64967:10:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;551:64967:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;145:41:12;;;:::i;:::-;;;;;;;;;;;;;;;;;;5542:42:13;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;5542:42:13;-1:-1:-1;;;;;5542:42:13;;:::i;:::-;;;;;;;;;;;;;;;;742:33;;;:::i;3557:41::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3557:41:13;-1:-1:-1;;;;;3557:41:13;;:::i;60809:503:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;60809:503:10;;;;;;;;;;:::i;62071:454::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;62071:454:10;-1:-1:-1;;;;;62071:454:10;;:::i;:::-;;22577:458;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;22577:458:10;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;5174:32:13:-;;;:::i;:::-;;;;-1:-1:-1;;;;;5174:32:13;;;;;;;;;;;;;;20391:204:10;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;20391:204:10;;;;;;;;;;;;;;;;;;:::i;21721:534::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;21721:534:10;;;;;;;;;;;;;;;;;;;;;;:::i;4518:28:13:-;;;:::i;503:27::-;;;:::i;61700:363:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;61700:363:10;;;;:::i;620:37:13:-;;;:::i;45664:1176:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;45664:1176:10;;:::i;3689:53:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3689:53:13;-1:-1:-1;;;;;3689:53:13;;:::i;63355:104:10:-;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:100:-1;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;12:14;63355:104:10;;;;;;;;;;;;;;;;;63863:120;;;:::i;58899:554::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;58899:554:10;-1:-1:-1;;;;;58899:554:10;;:::i;60304:497::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;60304:497:10;;;;;;;;;;:::i;4553:31:13:-;;;:::i;13175:443:10:-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;13175:443:10;;;;;;;;;;;;;;;;;;;;;;:::i;25539:546::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;25539:546:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;5354:42:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;5354:42:13;-1:-1:-1;;;;;5354:42:13;;:::i;1735:40::-;;;:::i;34081:408:10:-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;34081:408:10;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;10892:1951;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;10892:1951:10;;;;;;;;;;;;;;;;;:::i;49153:1502::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;49153:1502:10;;:::i;57005:601::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;57005:601:10;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;57005:601:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;57005:601:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;57005:601:10;;;;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;57005:601:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;57005:601:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;-1:-1;57005:601:10;;-1:-1:-1;57005:601:10;-1:-1:-1;57005:601:10;:::i;15698:349::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;15698:349:10;;;;;;;;;;;;;;;;;;;;;;:::i;3009:26:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3009:26:13;;:::i;44793:570:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;44793:570:10;-1:-1:-1;;;;;44793:570:10;;:::i;20902:322::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;20902:322:10;;;;;;;;;;;;;;;;;:::i;62533:293::-;;;:::i;32702:268::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;32702:268:10;-1:-1:-1;;;;;32702:268:10;;:::i;59691:605::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;59691:605:10;-1:-1:-1;;;;;59691:605:10;;:::i;23489:1576::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;23489:1576:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;58128:601::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;58128:601:10;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;58128:601:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;58128:601:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;58128:601:10;;;;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;58128:601:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;58128:601:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;-1:-1;58128:601:10;;-1:-1:-1;58128:601:10;-1:-1:-1;58128:601:10;:::i;65294:221::-;;;:::i;29973:345::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;29973:345:10;;;;;;;;;;;;;;;;;;;;;;:::i;4767:52:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;4767:52:13;-1:-1:-1;;;;;4767:52:13;;:::i;28020:475:10:-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;28020:475:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;4710:50:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;4710:50:13;-1:-1:-1;;;;;4710:50:13;;:::i;3264:29::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3264:29:13;;:::i;19126:886:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;19126:886:10;;;;;;;;:::i;1436:25:13:-;;;:::i;54096:1544:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;54096:1544:10;-1:-1:-1;;;;;54096:1544:10;;:::i;4631:34:13:-;;;:::i;2920:41::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;2920:41:13;-1:-1:-1;;;;;2920:41:13;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;61320:372:10;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;61320:372:10;;;;:::i;4366:163::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;4366:163:10;;;;;;;;;;:::i;64226:351::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;64226:351:10;-1:-1:-1;;;;;64226:351:10;;:::i;41626:675::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;41626:675:10;;;;:::i;3968:41:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3968:41:13;-1:-1:-1;;;;;3968:41:13;;:::i;52683:1047:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;52683:1047:10;;;;;;;;;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;52683:1047:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;52683:1047:10;;;;;;100:9:-1;95:1;81:12;77:20;67:8;63:35;60:50;-1:-1;;;25:12;22:29;11:107;8:2;;;131:1;128;121:12;8:2;52683:1047:10;;-1:-1:-1;52683:1047:10;-1:-1:-1;52683:1047:10;;:::i;3915:174::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;3915:174:10;-1:-1:-1;;;;;3915:174:10;;:::i;4672:31:13:-;;;:::i;63051:99:10:-;;;:::i;3818:28:13:-;;;:::i;40569:801:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;40569:801:10;-1:-1:-1;;;;;40569:801:10;;:::i;1126:40:13:-;;;:::i;28962:686:10:-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;28962:686:10;;;;;;;;;;;;;;;;;;;;;;:::i;4795:379::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;4795:379:10;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;4795:379:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;4795:379:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;4795:379:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;4795:379:10;;-1:-1:-1;4795:379:10;;-1:-1:-1;;;;;4795:379:10:i;38747:1554::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;38747:1554:10;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;5670:36:13;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;5670:36:13;;:::i;42557:2004:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;42557:2004:10;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;42557:2004:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;42557:2004:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;42557:2004:10;;;;;;;;;;;-1:-1:-1;;;5:28;;2:2;;;46:1;43;36:12;2:2;42557:2004:10;;35:9:-1;28:4;12:14;8:25;5:40;2:2;;;58:1;55;48:12;2:2;42557:2004:10;;;;;;101:9:-1;95:2;81:12;77:21;67:8;63:36;60:51;-1:-1;;;25:12;22:29;11:108;8:2;;;132:1;129;122:12;8:2;-1:-1;42557:2004:10;;-1:-1:-1;42557:2004:10;-1:-1:-1;42557:2004:10;:::i;64842:249::-;;;:::i;63672:105::-;;;:::i;26548:1011::-;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;;;;;;26548:1011:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;4072:31:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;4072:31:13;;:::i;55859:614:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;55859:614:10;;;;:::i;16488:2355::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;16488:2355:10;;;;;;;;;;;;;;;;;:::i;2057:49:13:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;2057:49:13;;;;;;;;:::i;1236:47::-;;;:::i;4978:30::-;;;:::i;47214:1638:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;47214:1638:10;;;;;;;;:::i;4591:33:13:-;;;:::i;1583:31::-;;;:::i;14069:408:10:-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;;;;;;14069:408:10;;;;;;;;;;;;;;;;;:::i;7111:3302::-;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;7111:3302:10;-1:-1:-1;;;;;7111:3302:10;;:::i;402:20:13:-;;;:::i;145:41:12:-;182:4;145:41;:::o;5542:42:13:-;;;;;;;;;;;;;:::o;742:33::-;;;-1:-1:-1;;;742:33:13;;;;;:::o;3557:41::-;;;;;;;;;;;;;;;:::o;60809:503:10:-;-1:-1:-1;;;;;60903:24:10;;60878:4;60903:24;;;:7;:24;;;;;:33;;;60895:86;;;;-1:-1:-1;;;60895:86:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61014:13;;-1:-1:-1;;;;;61014:13:10;61000:10;:27;;:47;;;61031:16;:14;:16::i;:::-;60992:99;;;;-1:-1:-1;;;60992:99:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61110:16;:14;:16::i;:::-;:33;;;-1:-1:-1;61139:4:10;61130:13;;;;61110:33;61102:68;;;;;-1:-1:-1;;;61102:68:10;;;;;;;;;;;;-1:-1:-1;;;61102:68:10;;;;;;;;;;;;;;;-1:-1:-1;;;;;61183:37:10;;;;;;:20;:37;;;;;;;;;:45;;;;;-1:-1:-1;;61183:45:10;;;;;;;;61244:37;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;61244:37:10;;;;;;;;;;;;;;-1:-1:-1;61299:5:10;60809:503;;;;;:::o;62071:454::-;62138:10;286:42:13;62138:32:10;:67;;;;;62174:10;-1:-1:-1;;;;;62174:29:10;;:31;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;62174:31:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;62174:31:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;62174:31:10;62138:67;62137:138;;;;62225:10;-1:-1:-1;;;;;62225:16:10;;:18;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;62225:18:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;62225:18:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;62225:18:10;-1:-1:-1;;;;;62211:32:10;:10;:32;:63;;;;;62247:10;-1:-1:-1;;;;;62247:25:10;;:27;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;62247:27:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;62247:27:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;62247:27:10;62211:63;62129:190;;;;-1:-1:-1;;;62129:190:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62332:17;62352:10;-1:-1:-1;;;;;62352:32:10;;:34;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;62352:34:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;62352:34:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;62352:34:10;;-1:-1:-1;62405:17:10;;62397:51;;;;;-1:-1:-1;;;62397:51:10;;;;;;;;;;;;-1:-1:-1;;;62397:51:10;;;;;;;;;;;;;;;62481:10;-1:-1:-1;;;;;62461:54:10;;:56;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;62461:56:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;62461:56:10;;;;62071:454;;:::o;22577:458::-;;;;;;:::o;5174:32:13:-;;;;;;-1:-1:-1;;;;;5174:32:13;;:::o;20391:204:10:-;20515:4;;20567:20;20560:27;;20391:204;;;;;;;:::o;21721:534::-;-1:-1:-1;;;;;22026:15:10;;21871:4;22026:15;;;:7;:15;;;;;:24;;;22021:94;;22079:23;22074:29;22067:36;;;;22021:94;22164:43;22190:6;22198:8;22164:25;:43::i;:::-;22232:14;22227:20;;4518:28:13;;;-1:-1:-1;;;;;4518:28:13;;:::o;503:27::-;;;-1:-1:-1;;;;;503:27:13;;:::o;61700:363:10:-;61792:13;;61753:4;;-1:-1:-1;;;;;61792:13:10;61778:10;:27;;:47;;;61809:16;:14;:16::i;:::-;61770:99;;;;-1:-1:-1;;;61770:99:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61888:16;:14;:16::i;:::-;:33;;;-1:-1:-1;61917:4:10;61908:13;;;;61888:33;61880:68;;;;;-1:-1:-1;;;61880:68:10;;;;;;;;;;;;-1:-1:-1;;;61880:68:10;;;;;;;;;;;;;;;61961:19;:27;;;;;-1:-1:-1;;;61961:27:10;;-1:-1:-1;;;;61961:27:10;;;;;;;;;;62004:28;;;;;;;;;;;;;;;;;;-1:-1:-1;;;62004:28:10;;;;;;;;;;;;;;-1:-1:-1;62050:5:10;61700:363;;;;:::o;620:37:13:-;;;-1:-1:-1;;;620:37:13;;;;;:::o;45664:1176:10:-;45736:7;45795:16;:14;:16::i;:::-;45790:123;;45835:66;45840:18;45860:40;45835:4;:66::i;:::-;45828:73;;;;45790:123;45950:28;;:::i;:::-;-1:-1:-1;45981:39:10;;;;;;;;;;;;46031:19;;:::i;:::-;-1:-1:-1;46053:39:10;;;;;;;;;3083:7;46053:39;;46107:47;46126:17;46053:39;46107:18;:47::i;:::-;46103:160;;;46178:73;46183:26;46211:39;46178:4;:73::i;:::-;46171:80;;;;;;46103:160;46275:20;;:::i;:::-;-1:-1:-1;46298:39:10;;;;;;;;;3210:6;46298:39;;46352:41;46298:39;46375:17;46352:11;:41::i;:::-;46348:154;;;46417:73;46422:26;46450:39;46417:4;:73::i;:::-;46410:80;;;;;;;46348:154;46618:19;;;46648:44;;;;46733:59;;;;;;;;;;;;;;;;;;;;;;;;;46817:14;46812:20;46805:27;45664:1176;-1:-1:-1;;;;;;45664:1176:10:o;3689:53:13:-;;;;;;;;;;;;-1:-1:-1;;;;;3689:53:13;;:::o;63355:104:10:-;63403:16;63439:12;63432:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;63432:19:10;;;;;;;;;;;;;;;;;;;;;;;63355:104;;:::o;63863:120::-;63920:16;63956:19;63949:26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;63949:26:10;;;;;;;;;;;;;;;;;;;;;;63863:120;:::o;58899:554::-;58988:16;:14;:16::i;:::-;58980:67;;;;-1:-1:-1;;;58980:67:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;59143:17;;;-1:-1:-1;;;;;59241:40:10;;;59143:17;59241:40;;;-1:-1:-1;;;;;;59241:40:10;;;;;;59381:64;;;59143:17;;;;;;;;59381:64;;;;;;;;;;;;59143:17;;59381:64;;;;;;;;;58899:554;;:::o;60304:497::-;-1:-1:-1;;;;;60396:24:10;;60371:4;60396:24;;;:7;:24;;;;;:33;;;60388:86;;;;-1:-1:-1;;;60388:86:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;60507:13;;-1:-1:-1;;;;;60507:13:10;60493:10;:27;;:47;;;60524:16;:14;:16::i;:::-;60485:99;;;;-1:-1:-1;;;60485:99:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;60603:16;:14;:16::i;:::-;:33;;;-1:-1:-1;60632:4:10;60623:13;;;;60603:33;60595:68;;;;;-1:-1:-1;;;60595:68:10;;;;;;;;;;;;-1:-1:-1;;;60595:68:10;;;;;;;;;;;;;;;-1:-1:-1;;;;;60676:35:10;;;;;;:18;:35;;;;;;;;;:43;;;;;-1:-1:-1;;60676:43:10;;;;;;;;60735:35;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;60735:35:10;;;;;;;;;;;;;;-1:-1:-1;60788:5:10;60304:497;-1:-1:-1;60304:497:10:o;4553:31:13:-;;;-1:-1:-1;;;4553:31:13;;;;;:::o;13175:443:10:-;-1:-1:-1;;;;;;;13586:17:10;;;;;:9;:17;;;;;:24;;-1:-1:-1;;13586:24:10;13606:4;13586:24;;;-1:-1:-1;13175:443:10:o;25539:546::-;26019:59;;5354:42:13;;;;;;;;;;;;;:::o;1735:40::-;;;;:::o;34081:408:10:-;34257:4;34263;34269;34287:9;34298:14;34314;34332:98;34372:7;34388:12;34403;34417;34332:39;:98::i;:::-;34286:144;;;;;;34454:3;34449:9;;;;;;;;34441:40;-1:-1:-1;34460:9:10;;-1:-1:-1;34471:9:10;-1:-1:-1;;34081:408:10;;;;;;;;;:::o;10892:1951::-;-1:-1:-1;;;;;11086:26:10;;10980:4;11086:26;;;:18;:26;;;;;;;;11085:27;11077:54;;;;;-1:-1:-1;;;11077:54:10;;;;;;;;;;;;-1:-1:-1;;;11077:54:10;;;;;;;;;;;;;;;-1:-1:-1;;;;;11263:15:10;;;;;;:7;:15;;;;;:24;;;11258:94;;11316:23;11311:29;11304:36;;;;11258:94;11420:16;;;;:38;;;;-1:-1:-1;;;;;;11441:17:10;;;;;;:9;:17;;;;;;;;11440:18;11420:38;11416:114;;;11487:30;11482:36;;11416:114;-1:-1:-1;;;;;11588:18:10;;11571:14;11588:18;;;:10;:18;;;;;;11684:14;;11680:1025;;11715:14;11739:6;-1:-1:-1;;;;;11732:22:10;;:24;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;11732:24:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;11732:24:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;11732:24:10;11791:29;;;-1:-1:-1;;;11791:29:10;;;;11732:24;;-1:-1:-1;11771:17:10;;-1:-1:-1;;;;;11791:27:10;;;;;:29;;;;;11732:24;;11791:29;;;;;;;:27;:29;;;5:2:-1;;;;30:1;27;20:12;5:2;11791:29:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;11791:29:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;11791:29:10;11856:30;;;-1:-1:-1;;;11856:30:10;;;;11791:29;;-1:-1:-1;11835:18:10;;-1:-1:-1;;;;;11856:28:10;;;;;:30;;;;;11791:29;;11856:30;;;;;;;:28;:30;;;5:2:-1;;;;30:1;27;20:12;5:2;11856:30:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;11856:30:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;11856:30:10;11922;;;-1:-1:-1;;;11922:30:10;;;;11856;;-1:-1:-1;11901:18:10;;-1:-1:-1;;;;;11922:28:10;;;;;:30;;;;;11856;;11922;;;;;;;:28;:30;;;5:2:-1;;;;30:1;27;20:12;5:2;11922:30:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;11922:30:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;11922:30:10;11989:31;;;-1:-1:-1;;;11989:31:10;;;;11922:30;;-1:-1:-1;11967:19:10;;-1:-1:-1;;;;;11989:29:10;;;;;:31;;;;;11922:30;;11989:31;;;;;;;:29;:31;;;5:2:-1;;;;30:1;27;20:12;5:2;11989:31:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;11989:31:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;11989:31:10;;-1:-1:-1;12154:17:10;;12203:97;12218:9;12229:12;12243:56;12248:34;12253:13;12268;12248:4;:34::i;:::-;12284:14;12243:4;:56::i;:::-;12203:14;:97::i;:::-;12153:147;;-1:-1:-1;12153:147:10;-1:-1:-1;12330:18:10;12319:7;:29;;;;;;;;;12315:64;;12362:16;12350:29;;;;;;;;;;;;12315:64;12396:30;12480:42;12488:21;12511:10;12480:7;:42::i;:::-;12441:81;;-1:-1:-1;12441:81:10;-1:-1:-1;12552:18:10;12541:7;:29;;;;;;;;;12537:64;;12584:16;12572:29;;;;;;;;;;;;;12537:64;12654:9;12626:25;:37;12618:75;;;;;-1:-1:-1;;;12618:75:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;11680:1025;;;;;;;;;12754:41;12780:6;12788;12754:25;:41::i;:::-;12820:14;12815:20;12808:27;;;10892:1951;;;;;;:::o;49153:1502::-;49243:4;49299:16;:14;:16::i;:::-;49294:132;;49339:75;49344:18;49364:49;49339:4;:75::i;49294:132::-;49504:34;;:::i;:::-;-1:-1:-1;49541:48:10;;;;;;;;;;;;49600:34;;:::i;:::-;-1:-1:-1;49637:48:10;;;;;;;;;3491:6;49637:48;;49700:61;49712:23;49637:48;49700:11;:61::i;:::-;49696:192;;;49785:91;49790:35;49827:48;49785:4;:91::i;49696:192::-;49900:34;;:::i;:::-;-1:-1:-1;49937:48:10;;;;;;;;;3642:6;49937:48;;50000:61;49937:48;50037:23;50000:11;:61::i;:::-;49996:192;;;50085:91;50090:35;50127:48;50085:4;:91::i;49996:192::-;50285:28;;;50381:62;;;;50518:89;;;;;;;;;;;;;;;;;;;;;;;;;50632:14;50627:20;;57005:601;57118:16;:14;:16::i;:::-;:51;;;-1:-1:-1;57152:17:10;;;;;-1:-1:-1;;;;;57152:17:10;57138:10;:31;57118:51;57110:117;;;;-1:-1:-1;;;57110:117:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;57259:7;57305:13;57346:15;;;;;:46;;;57379:13;57365:10;:27;57346:46;57338:72;;;;;-1:-1:-1;;;57338:72:10;;;;;;;;;;;;-1:-1:-1;;;57338:72:10;;;;;;;;;;;;;;;57427:6;57423:176;57443:10;57439:1;:14;57423:176;;;57509:13;;57523:1;57509:16;;;;;;;;;;;;;57475:10;:31;57494:7;;57502:1;57494:10;;;;;;;;;;;;;-1:-1:-1;;;;;57494:10:10;-1:-1:-1;;;;;57475:31:10;-1:-1:-1;;;;;57475:31:10;;;;;;;;;;;;:50;;;;57558:7;;57566:1;57558:10;;;;;;;;;;;;;-1:-1:-1;;;;;57558:10:10;-1:-1:-1;;;;;57545:42:10;;57570:13;;57584:1;57570:16;;;;;;;;;;;;;57545:42;;;;;;;;;;;;;;;;;;57455:3;;57423:176;;;;57005:601;;;;;;:::o;15698:349::-;15947:17;;:37;;;;;15983:1;15968:12;:16;15947:37;15943:97;;;16001:27;;;-1:-1:-1;;;16001:27:10;;;;;;;;;;;;-1:-1:-1;;;16001:27:10;;;;;;;;;;;;;;15943:97;15698:349;;;;:::o;3009:26:13:-;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;3009:26:13;;-1:-1:-1;3009:26:13;:::o;44793:570:10:-;44857:4;44913:16;:14;:16::i;:::-;44908:123;;44953:66;44958:18;44978:40;44953:4;:66::i;44908:123::-;45120:6;;;-1:-1:-1;;;;;45189:18:10;;;-1:-1:-1;;;;;;45189:18:10;;;;;;;45279:36;;;45120:6;;;;45279:36;;;;;;;;;;;;;;;;;;;;;;;45340:14;45328:27;44793:570;-1:-1:-1;;;44793:570:10:o;20902:322::-;;;;:::o;62533:293::-;62608:25;;-1:-1:-1;;;;;62608:25:10;62594:10;:39;62586:102;;;;-1:-1:-1;;;62586:102:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;62706:22;;;;;;;62701:118;;62745:11;:18;;-1:-1:-1;;;;62745:18:10;;;62759:4;62745:18;62778:29;62745:18;62778:29;;;62701:118;62533:293::o;32702:268::-;32769:4;32775;32781;32799:9;32810:14;32826;32844:65;32884:7;32900:1;32904;32907;32844:39;:65::i;:::-;32798:111;;;;;;32935:3;32930:9;;;;;;;;32922:40;32941:9;;-1:-1:-1;32941:9:10;-1:-1:-1;32702:268:10;-1:-1:-1;;;32702:268:10:o;59691:605::-;59760:4;59782:16;:14;:16::i;:::-;59777:125;;59822:68;59827:18;59847:42;59822:4;:68::i;59777:125::-;59993:13;;;-1:-1:-1;;;;;60079:32:10;;;-1:-1:-1;;;;;;60079:32:10;;;;;;;60199:49;;;59993:13;;;60199:49;;;60234:13;;;;60199:49;;;;;;;;;;;;;;;;60273:14;60268:20;;23489:1576;-1:-1:-1;;;;;23812:23:10;;23691:4;23812:23;;;:7;:23;;;;;:32;;;23811:33;;:72;;-1:-1:-1;;;;;;23849:25:10;;;;;;:7;:25;;;;;:34;;;23848:35;23811:72;23807:141;;;23912:23;23907:29;23900:36;;;;23807:141;24014:18;24042:14;-1:-1:-1;;;;;24035:42:10;;24078:8;24035:52;;;;;;;;;;;;;-1:-1:-1;;;;;24035:52:10;-1:-1:-1;;;;;24035:52:10;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;24035:52:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;24035:52:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;24035:52:10;;-1:-1:-1;24179:36:10;24199:14;24179:12;:36::i;:::-;24175:843;;;24257:11;24240:13;:28;;24232:81;;;;-1:-1:-1;;;24232:81:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;24175:843;;;24427:9;24440:14;24458:37;24486:8;24458:27;:37::i;:::-;24426:69;;-1:-1:-1;24426:69:10;;-1:-1:-1;24521:14:10;;-1:-1:-1;24514:3:10;:21;;;;;;;;;24510:78;;24568:3;24563:9;;;;;;;;24556:16;;;;;;;24510:78;24608:14;24604:96;;24655:28;24650:34;;24604:96;24809:13;24825:71;24844:36;;;;;;;;24859:19;;24844:36;;;24882:13;24825:18;:71::i;:::-;24809:87;;24929:8;24915:11;:22;24911:96;;;24970:20;24958:33;;;;;;;;24911:96;24175:843;;;;25042:14;25030:27;;;23489:1576;;;;;;;;:::o;58128:601::-;58241:16;:14;:16::i;:::-;:51;;;-1:-1:-1;58275:17:10;;;;;-1:-1:-1;;;;;58275:17:10;58261:10;:31;58241:51;58233:117;;;;-1:-1:-1;;;58233:117:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;58382:7;58428:13;58469:15;;;;;:46;;;58502:13;58488:10;:27;58469:46;58461:72;;;;;-1:-1:-1;;;58461:72:10;;;;;;;;;;;;-1:-1:-1;;;58461:72:10;;;;;;;;;;;;;;;58550:6;58546:176;58566:10;58562:1;:14;58546:176;;;58632:13;;58646:1;58632:16;;;;;;;;;;;;;58598:10;:31;58617:7;;58625:1;58617:10;;;;;;;;;;;;;-1:-1:-1;;;;;58617:10:10;-1:-1:-1;;;;;58598:31:10;-1:-1:-1;;;;;58598:31:10;;;;;;;;;;;;:50;;;;58681:7;;58689:1;58681:10;;;;;;;;;;;;;-1:-1:-1;;;;;58681:10:10;-1:-1:-1;;;;;58668:42:10;;58693:13;;58707:1;58693:16;;;;;;;;;;;;;58668:42;;;;;;;;;;;;;;;;;;58578:3;;58546:176;;65294:221;65360:10;65352:19;;;;:7;:19;;;;;:28;;;65344:100;;;;-1:-1:-1;;;65344:100:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;65455:11;:18;;-1:-1:-1;;65455:18:10;65469:4;65455:18;;;65294:221::o;29973:345::-;30252:59;;4767:52:13;;;;;;;;;;;;;;;:::o;4710:50::-;;;;;;;;;;;;;;;:::o;3264:29::-;;;;;;;;;;19126:886:10;19212:4;19268:17;286:42:13;-1:-1:-1;;;;;19288:22:10;;:24;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;19288:24:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;19288:24:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;19288:24:10;;-1:-1:-1;19329:16:10;;19325:612;;19466:6;;;:41;;;-1:-1:-1;;;19466:41:10;;-1:-1:-1;;;;;19466:41:10;;;;;;;;;;;;19439:24;;19466:6;;;;:25;;:41;;;;;;;;;;;;;;;:6;:41;;;5:2:-1;;;;30:1;27;20:12;5:2;19466:41:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;19466:41:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;19466:41:10;;-1:-1:-1;19526:24:10;19522:60;;19564:17;19552:30;;;;;;19522:60;19598:17;19617:21;19642:74;19660:36;;;;;;;;19675:19;19660:36;;;19698:17;19642;:74::i;:::-;19597:119;;-1:-1:-1;19597:119:10;-1:-1:-1;19746:18:10;19735:7;:29;;;;;;;;;19731:64;;19778:16;19773:22;19766:29;;;;;;;;19731:64;19876:12;19857:16;:31;19853:72;;;19902:22;19897:28;;19853:72;19325:612;;;;19989:14;19977:27;19126:886;-1:-1:-1;;;;19126:886:10:o;1436:25:13:-;;;-1:-1:-1;;;;;1436:25:13;;:::o;54096:1544:10:-;54155:4;54208:16;:14;:16::i;:::-;54203:96;;54233:66;54238:18;54258:40;54233:4;:66::i;54203:96::-;-1:-1:-1;;;;;54365:24:10;;;;;;:7;:24;;;;;:33;;;54360:121;;54407:74;54412:23;54437:43;54407:4;:74::i;54360:121::-;54559:1;54536:6;-1:-1:-1;;;;;54536:18:10;;:20;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;54536:20:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;54536:20:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;54536:20:10;:24;54532:106;;;54569:69;54574:26;54602:35;54569:4;:69::i;54532:106::-;-1:-1:-1;;;;;54684:24:10;;;;;;:7;:24;;;;;;;;54677:31;;-1:-1:-1;;54677:31:10;;;;;;;;;54854:10;54824:40;;;;;;;;;;;;;;;;;:27;;:40;;;54854:10;54824:40;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;54824:40:10;;;;;;;;;;;;;;;;-1:-1:-1;;54886:18:10;;54824:40;;-1:-1:-1;54886:18:10;;-1:-1:-1;54875:8:10;;-1:-1:-1;;54947:160:10;54968:3;54964:1;:7;54947:160;;;55015:6;-1:-1:-1;;;;;54997:24:10;:11;55009:1;54997:14;;;;;;;;;;;;;;-1:-1:-1;;;;;54997:24:10;;54993:103;;;55055:1;55042:14;;55075:5;;54993:103;54973:3;;54947:160;;;;55236:3;55223:10;:16;55216:24;;;;55367:10;55378:17;;-1:-1:-1;;55378:21:10;;;55367:33;;;;;;;;;;;;;;;;55342:10;:22;;-1:-1:-1;;;;;55367:33:10;;;;55353:10;;55342:22;;;;;;;;;;;;;;;:58;;-1:-1:-1;;;;;;55342:58:10;-1:-1:-1;;;;;55342:58:10;;;;;;;;;;55411:10;:19;;;;;-1:-1:-1;;55411:19:10;;;:::i;:::-;;55551:1;55443:19;:90;55463:6;-1:-1:-1;;;;;55463:15:10;;:17;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;55463:17:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;55463:17:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;55463:17:10;:69;;55511:6;-1:-1:-1;;;;;55496:34:10;;:36;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;55496:36:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;55496:36:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;55496:36:10;55463:69;;;55491:1;55463:69;-1:-1:-1;;;;;55443:90:10;;;;;;;;;;;;;;;;;-1:-1:-1;55443:90:10;:111;;-1:-1:-1;;;;;;55443:111:10;;;;;;;;;;;55570:22;;;;;;;;;;;;;;;;;;55617:14;55605:27;54096:1544;-1:-1:-1;;;;;54096:1544:10:o;4631:34:13:-;;;-1:-1:-1;;;4631:34:13;;;;;:::o;2920:41::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;61320:372:10:-;61415:13;;61376:4;;-1:-1:-1;;;;;61415:13:10;61401:10;:27;;:47;;;61432:16;:14;:16::i;:::-;61393:99;;;;-1:-1:-1;;;61393:99:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;61511:16;:14;:16::i;:::-;:33;;;-1:-1:-1;61540:4:10;61531:13;;;;61511:33;61503:68;;;;;-1:-1:-1;;;61503:68:10;;;;;;;;;;;;-1:-1:-1;;;61503:68:10;;;;;;;;;;;;;;;61584:22;:30;;;;;-1:-1:-1;;;61584:30:10;;-1:-1:-1;;;;61584:30:10;;;;;;;;;;61630:31;;;;;;;;;;;;;;;;;;-1:-1:-1;;;61630:31:10;;;;;;;;;;;;;;-1:-1:-1;61679:5:10;61320:372::o;4366:163::-;-1:-1:-1;;;;;4470:24:10;;;4446:4;4470:24;;;:7;:24;;;;;;;;:51;;;;;:42;;;;:51;;;;;;4366:163;;;;:::o;64226:351::-;-1:-1:-1;;;;;64321:24:10;;64284:4;64321:24;;;:7;:24;;;;;:49;;;:54;:117;;;;-1:-1:-1;;;;;;64393:37:10;;;;;;:20;:37;;;;;;;;:45;;:37;:45;64321:117;:238;;;;;64456:95;64461:63;64466:6;-1:-1:-1;;;;;64466:28:10;;:30;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;64466:30:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;64466:30:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;64466:30:10;64498:25;;;-1:-1:-1;;;64498:25:10;;;;-1:-1:-1;;;;;64498:23:10;;;;;:25;;;;;64466:30;;64498:25;;;;;;;:23;:25;;;5:2:-1;;;;30:1;27;20:12;5:2;64498:25:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;64498:25:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;64498:25:10;64461:4;:63::i;:::-;64526:6;-1:-1:-1;;;;;64526:22:10;;:24;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;64456:95:10;64555:4;64456:103;64301:258;64226:351;-1:-1:-1;;64226:351:10:o;41626:675::-;41692:4;41748:16;:14;:16::i;:::-;41743:132;;41788:75;41793:18;41813:49;41788:4;:75::i;41743:132::-;41956:16;;;;:27;;;;;;41952:87;;;42012:14;42007:20;;41952:87;42113:16;:26;;;;;-1:-1:-1;;42113:26:10;;;;;;;;42217:36;;;;;;;;;;;;;;;;42278:14;42273:20;;3968:41:13;;;;;;;;;;;;;;;:::o;52683:1047:10:-;52836:4;52892:16;:14;:16::i;:::-;52887:121;;52932:64;52937:18;52957:38;52932:4;:64::i;52887:121::-;53148:18;;;-1:-1:-1;;;;;;;53177:25:10;;;;;;;53148:18;;;-1:-1:-1;53272:8:10;:92;;53325:39;;-1:-1:-1;;;53325:39:10;;;;;;;;;;;;;;;286:42:13;;53325:22:10;;53348:15;;;;53325:39;;;;;53348:15;;;;53325:39;1:33:-1;99:1;93:3;85:6;81:16;74:27;137:4;133:9;126:4;121:3;117:14;113:30;106:37;;169:3;161:6;157:16;147:26;;53325:39:10;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;53325:39:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;53325:39:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;53325:39:10;53272:92;;;53283:39;;-1:-1:-1;;;53283:39:10;;;;;;;;;;;;;;;286:42:13;;53283:22:10;;53306:15;;;;53283:39;;;;;53306:15;;;;53283:39;1:33:-1;99:1;93:3;85:6;81:16;74:27;137:4;133:9;126:4;121:3;117:14;113:30;106:37;;169:3;161:6;157:16;147:26;;53283:39:10;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;53283:39:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;53283:39:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;53283:39:10;53272:92;53436:18;:42;;-1:-1:-1;;;;53436:42:10;-1:-1:-1;;;53436:42:10;;;;;;;53249:116;-1:-1:-1;;53556:22:10;53249:116;53556:14;:22::i;:::-;53542:36;-1:-1:-1;53632:27:10;;:90;;53719:3;53632:90;;;53662:54;53683:6;53691:24;53662:20;:54::i;:::-;53625:97;52683:1047;-1:-1:-1;;;;;;;;52683:1047:10:o;3915:174::-;3976:15;4004:24;4031:13;:22;4045:7;-1:-1:-1;;;;;4031:22:10;-1:-1:-1;;;;;4031:22:10;;;;;;;;;;;;4004:49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;4004:49:10;;;;;;;;;;;;;;;;-1:-1:-1;4004:49:10;;3915:174;-1:-1:-1;;;;;;;3915:174:10:o;4672:31:13:-;;;-1:-1:-1;;;4672:31:13;;;;;:::o;63051:99:10:-;63097:15;63132:10;63125:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;63125:17:10;;;;;;;;;;;;;;;;;;;;;;63051:99;:::o;3818:28:13:-;;;;;;:::o;40569:801:10:-;40640:4;40696:16;:14;:16::i;:::-;40691:130;;40736:73;40741:18;40761:47;40736:4;:73::i;40691:130::-;40900:11;-1:-1:-1;;;;;40873:60:10;;:62;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;40873:62:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;40873:62:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;40873:62:10;40865:103;;;;;-1:-1:-1;;;40865:103:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;41036:6;41031:145;41052:19;:26;41048:30;;41031:145;;;41108:19;41128:1;41108:22;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;41093:37:10;;;41108:22;;41093:37;;41085:91;;;;-1:-1:-1;;;41085:91:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;41080:3;;41031:145;;;-1:-1:-1;41233:19:10;27:10:-1;;39:1;23:18;;45:23;;-1:-1;41233:37:10;;;;;;;;-1:-1:-1;;;;;41233:37:10;;-1:-1:-1;;;;;;41233:37:10;;;;;;;;41286:36;;;;;;;;;;;;41233:37;41286:36;;;41347:14;41342:20;;1126:40:13;;;-1:-1:-1;;;;;1126:40:13;;:::o;28962:686:10:-;29174:22;;29068:4;;-1:-1:-1;;;29174:22:10;;;;29173:23;29165:54;;;;;-1:-1:-1;;;29165:54:10;;;;;;;;;;;;-1:-1:-1;;;29165:54:10;;;;;;;;;;;;;;;29354:12;29369:50;29391:6;29399:3;29404:14;29369:21;:50::i;:::-;29354:65;-1:-1:-1;29434:31:10;;29430:78;;29489:7;-1:-1:-1;29482:14:10;;29430:78;29557:43;29583:6;29591:3;29596;29557:25;:43::i;:::-;29625:14;29613:27;28962:686;-1:-1:-1;;;;;;28962:686:10:o;4795:379::-;4859:13;4885:8;4896:7;:14;4885:25;;4923:21;4958:3;4947:15;;;;;;;;;;;;;;;;;;;;;;29:2:-1;21:6;17:15;117:4;105:10;97:6;88:34;136:17;;-1:-1;4947:15:10;-1:-1:-1;4923:39:10;-1:-1:-1;4978:6:10;4973:167;4994:3;4990:1;:7;4973:167;;;5019:13;5042:7;5050:1;5042:10;;;;;;;;;;;;;;5019:34;;5088:39;5108:6;5116:10;5088:19;:39::i;:::-;5083:45;;;;;;;;5070:7;5078:1;5070:10;;;;;;;;;;;;;;;;;:58;-1:-1:-1;4999:3:10;;4973:167;;;-1:-1:-1;5159:7:10;4795:379;-1:-1:-1;;;4795:379:10:o;38747:1554::-;39005:6;;;:49;;;-1:-1:-1;;;39005:49:10;;-1:-1:-1;;;;;39005:49:10;;;;;;;;;;;;38883:4;;;;;;39005:6;;;:25;;:49;;;;;;;;;;;;;;;:6;:49;;;5:2:-1;;;;30:1;27;20:12;5:2;39005:49:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;39005:49:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;39005:49:10;39096:6;;;:51;;;-1:-1:-1;;;39096:51:10;;-1:-1:-1;;;;;39096:51:10;;;;;;;;;;;;39005:49;;-1:-1:-1;39065:28:10;;39096:6;;;;;:25;;:51;;;;;39005:49;;39096:51;;;;;;;;:6;:51;;;5:2:-1;;;;30:1;27;20:12;5:2;39096:51:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;39096:51:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;39096:51:10;;-1:-1:-1;39162:26:10;;;:58;;-1:-1:-1;39192:28:10;;39162:58;39158:126;;;39250:17;39237:35;-1:-1:-1;39270:1:10;;-1:-1:-1;39237:35:10;;-1:-1:-1;;39237:35:10;39158:126;39677:25;39712:16;-1:-1:-1;;;;;39705:43:10;;:45;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;39705:45:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;39705:45:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;39705:45:10;;-1:-1:-1;39787:16:10;39814:20;;:::i;:::-;39845:22;;:::i;:::-;39878:16;;:::i;:::-;39919:91;39924:45;;;;;;;;39939:28;;39924:45;;;39971:38;;;;;;;;39986:21;39971:38;;;39919:4;:91::i;:::-;39907:103;;40035:85;40040:40;;;;;;;;40055:23;40040:40;;;40082:37;;;;;;;;40097:20;40082:37;;;40035:4;:85::i;:::-;40021:99;;40139:28;40144:9;40155:11;40139:4;:28::i;:::-;40131:36;;40194:44;40213:5;40220:17;40194:18;:44::i;:::-;40264:14;;-1:-1:-1;40180:58:10;-1:-1:-1;;;;;;;;38747:1554:10;;;;;;;:::o;5670:36:13:-;;;;;;;;;;42557:2004:10;42662:4;42718:16;:14;:16::i;:::-;42713:127;;42758:70;42763:18;42783:44;42758:4;:70::i;42713:127::-;42906:6;42901:1613;42918:20;;;42901:1613;;;42960:16;42979:9;;42989:1;42979:12;;;;;;;;;;;;;-1:-1:-1;;;;;42979:12:10;42960:31;;43012:8;;43021:1;43012:11;;;;;;;;;;;;;;43008:1495;;-1:-1:-1;;;;;43114:19:10;;;;;;:9;:19;;;;;;;;43109:224;;-1:-1:-1;;;;;43158:19:10;;;;;;:9;:19;;;;;;;;:26;;-1:-1:-1;;43158:26:10;43180:4;43158:26;;;;;;43207:14;27:10:-1;;23:18;;;45:23;;43207:29:10;;;;;;-1:-1:-1;;;;;;43207:29:10;;;;;43288:21;43259:26;;;:16;:26;;;;;-1:-1:-1;;43288:25:10;;;;43259:54;;43109:224;43008:1495;;;-1:-1:-1;;;;;43435:19:10;;;;;;:9;:19;;;;;;;;43431:1057;;;-1:-1:-1;;;;;43503:26:10;;43479:21;43503:26;;;:16;:26;;;;;;43708:14;:21;-1:-1:-1;;43708:25:10;43692:41;;43688:417;;;43784:14;43799:21;;43762:19;;43784:14;-1:-1:-1;;43799:25:10;;;43784:41;;;;;;;;;;;;;;;;43852:14;:29;;-1:-1:-1;;;;;43784:41:10;;;;-1:-1:-1;43784:41:10;;43867:13;;43852:29;;;;;;;;;;;;;;;;;;:43;;-1:-1:-1;;;;;;43852:43:10;-1:-1:-1;;;;;43852:43:10;;;;;;43982:29;;;;;;:16;:29;;;;;;:45;;;43688:417;44200:14;:23;;;;;-1:-1:-1;;44200:23:10;;;:::i;:::-;-1:-1:-1;;;;;;;44268:26:10;;44297:1;44268:26;;;:16;:26;;;;;;;;:30;;;44377:9;:19;;;;;:27;;-1:-1:-1;;44377:27:10;;;43431:1057;-1:-1:-1;42940:3:10;;42901:1613;;;-1:-1:-1;44538:14:10;44533:20;;64842:249;64909:10;64901:19;;;;:7;:19;;;;;:28;;;64893:101;;;;-1:-1:-1;;;64893:101:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;65013:11;;;;65005:48;;;;;-1:-1:-1;;;65005:48:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;65064:11;:19;;-1:-1:-1;;65064:19:10;;;64842:249::o;63672:105::-;63719:16;63755:14;63748:21;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;63748:21:10;;;;;;;;;;;;;;;;;;;;;;63672:105;:::o;26548:1011::-;26846:19;;26740:4;;-1:-1:-1;;;26846:19:10;;;;26845:20;26837:48;;;;;-1:-1:-1;;;26837:48:10;;;;;;;;;;;;-1:-1:-1;;;26837:48:10;;;;;;;;;;;;;;;-1:-1:-1;;;;;27043:25:10;;;;;;:7;:25;;;;;:34;;;27042:35;;:72;;-1:-1:-1;;;;;;27082:23:10;;;;;;:7;:23;;;;;:32;;;27081:33;27042:72;27038:141;;;27143:23;27138:29;;27038:141;27300:14;-1:-1:-1;;;;;27293:34:10;;:36;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;27293:36:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;27293:36:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;27293:36:10;27251:38;;;-1:-1:-1;;;27251:38:10;;;;-1:-1:-1;;;;;27251:78:10;;;;:36;;;;;:38;;;;;27293:36;;27251:38;;;;;;;:36;:38;;;5:2:-1;;;;30:1;27;20:12;5:2;27251:38:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;27251:38:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;27251:38:10;-1:-1:-1;;;;;27251:78:10;;27247:150;;27358:26;27353:32;;27247:150;27446:65;27472:16;27490:8;27500:10;27446:25;:65::i;4072:31:13:-;;;;;;;;;;55859:614:10;55925:4;55947:16;:14;:16::i;:::-;55942:142;;55987:85;55992:18;56012:59;55987:4;:85::i;55942:142::-;56164:18;;;;:29;;;;;;56160:62;;;56207:14;56202:20;;56160:62;56291:18;:28;;;;;-1:-1:-1;;56291:28:10;;;;;;;;56390:35;;;;;;;;;;;;;;;;56450:14;56445:20;;16488:2355;-1:-1:-1;;;;;16688:28:10;;16582:4;16688:28;;;:20;:28;;;;;;;;16687:29;16679:58;;;;;-1:-1:-1;;;16679:58:10;;;;;;;;;;;;-1:-1:-1;;;16679:58:10;;;;;;;;;;;;;;;-1:-1:-1;;;;;16794:15:10;;;;;;:7;:15;;;;;:24;;;16789:94;;16847:23;16842:29;;16789:94;-1:-1:-1;;;;;16900:15:10;;;;;;;:7;:15;;;;;;;;:43;;;;;:33;;;;:43;;;;;;16895:574;;17046:10;-1:-1:-1;;;;;17046:20:10;;;17038:54;;;;;-1:-1:-1;;;17038:54:10;;;;;;;;;;;;-1:-1:-1;;;17038:54:10;;;;;;;;;;;;;;;17163:9;17175:49;17202:10;17215:8;17175:19;:49::i;:::-;17163:61;-1:-1:-1;17250:14:10;17243:3;:21;;;;;;;;;17239:78;;17297:3;17292:9;;;;;;;;17285:16;;;;;17239:78;-1:-1:-1;;;;;17413:15:10;;;;;;;:7;:15;;;;;;;;:43;;;;;:33;;;;:43;;;;;;17406:51;;;;16895:574;;17533:6;;;:41;;;-1:-1:-1;;;17533:41:10;;-1:-1:-1;;;;;17533:41:10;;;;;;;;;;;;:6;;;;;:25;;:41;;;;;;;;;;;;;;;:6;:41;;;5:2:-1;;;;30:1;27;20:12;5:2;17533:41:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;17533:41:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;17533:41:10;17529:109;;17608:17;17603:23;;17529:109;17708:16;;;;:40;;;;-1:-1:-1;;;;;;17729:19:10;;;;;;:9;:19;;;;;;;;17728:20;17708:40;17704:116;;;17777:30;17772:36;;17704:116;-1:-1:-1;;;;;17878:18:10;;17861:14;17878:18;;;:10;:18;;;;;;17974:14;;17970:351;;18005:17;18032:6;-1:-1:-1;;;;;18025:27:10;;:29;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;18025:29:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;18025:29:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;18025:29:10;;-1:-1:-1;18070:17:10;;18114:35;18025:29;18136:12;18114:7;:35::i;:::-;18069:80;;-1:-1:-1;18069:80:10;-1:-1:-1;18179:18:10;18168:7;:29;;;;;;;;;18164:64;;18211:16;18199:29;;;;;;;;18164:64;18270:9;18251:16;:28;18243:66;;;;;-1:-1:-1;;;18243:66:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;17970:351;;;;18370:43;18396:6;18404:8;18370:25;:43::i;:::-;18505:9;18518:14;18536:82;18576:8;18593:6;18602:1;18605:12;18536:39;:82::i;:::-;18504:114;;-1:-1:-1;18504:114:10;;-1:-1:-1;18640:14:10;;-1:-1:-1;18633:3:10;:21;;;;;;;;;18629:70;;18683:3;18678:9;;;;;;;;18671:16;;;;;;;18629:70;18713:13;;18709:87;;18755:28;18750:34;;18709:87;18820:14;18808:27;16488:2355;-1:-1:-1;;;;;;;16488:2355:10:o;2057:49:13:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2057:49:13;;-1:-1:-1;2057:49:13;;-1:-1:-1;2057:49:13:o;1236:47::-;;;-1:-1:-1;;;;;1236:47:13;;:::o;4978:30::-;;;;;;:::o;47214:1638:10:-;47309:7;47368:16;:14;:16::i;:::-;47363:128;;47408:71;47413:18;47433:45;47408:4;:71::i;:::-;47401:78;;;;47363:128;-1:-1:-1;;;;;47563:24:10;;47539:21;47563:24;;;:7;:24;;;;;47603:15;;;;47598:130;;47642:74;47647:23;47672:43;47642:4;:74::i;:::-;47635:81;;;;;47598:130;47740:33;;:::i;:::-;-1:-1:-1;47776:44:10;;;;;;;;;;;;47876:20;;:::i;:::-;-1:-1:-1;47899:44:10;;;;;;;;;3343:6;47899:44;;47958:46;47899:44;47981:22;47958:11;:46::i;:::-;47954:169;;;48028:83;48033:31;48066:44;48028:4;:83::i;:::-;48021:90;;;;;;;47954:169;48197:32;;;;;:74;;-1:-1:-1;48233:6:10;;;:33;;;-1:-1:-1;;;48233:33:10;;-1:-1:-1;;;;;48233:33:10;;;;;;;;;;;;:6;;;;;:25;;:33;;;;;;;;;;;;;;;:6;:33;;;5:2:-1;;;;30:1;27;20:12;5:2;48233:33:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;48233:33:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;48233:33:10;:38;48197:74;48193:186;;;48295:72;48300:17;48319:47;48295:4;:72::i;48193:186::-;48514:31;;;;;48556:61;;;;48719:85;;;-1:-1:-1;;;;;48719:85:10;;;;;;;;;;;;;;;;;;;;;;;;;;;48829:14;48817:27;47214:1638;-1:-1:-1;;;;;;;47214:1638:10:o;4591:33:13:-;;;-1:-1:-1;;;4591:33:13;;;;;:::o;1583:31::-;;;;:::o;14069:408:10:-;14163:4;14180:12;14195:53;14217:6;14225:8;14235:12;14195:21;:53::i;:::-;14180:68;-1:-1:-1;14263:31:10;;14259:78;;14318:7;-1:-1:-1;14311:14:10;;7111:3302;7172:4;7189:13;7212;7189:37;;7317:9;7328:15;7345;7366:6;-1:-1:-1;;;;;7366:25:10;;7392:10;7366:37;;;;;;;;;;;;;-1:-1:-1;;;;;7366:37:10;-1:-1:-1;;;;;7366:37:10;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;7366:37:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;7366:37:10;;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;7366:37:10;;;;;;;;;;;;;-1:-1:-1;7366:37:10;;-1:-1:-1;7366:37:10;-1:-1:-1;7422:9:10;;7414:59;;;;-1:-1:-1;;;7414:59:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;7571:15;;7567:127;;7610:72;7615:28;7645:36;7610:4;:72::i;:::-;7603:79;;;;;;;;7567:127;7787:12;7802:60;7824:13;7839:10;7851;7802:21;:60::i;:::-;7787:75;-1:-1:-1;7877:12:10;;7873:123;;7913:71;7924:15;7941:33;7976:7;7913:10;:71::i;:::-;7906:78;;;;;;;;;7873:123;-1:-1:-1;;;;;8038:24:10;;8008:27;8038:24;;;:7;:24;;;;;;;;8187:10;8156:42;;:30;;;:42;;;;;;;;;8151:103;;8227:14;8215:27;;;;;;;;;;8151:103;8358:10;8327:42;;;;:30;;;:42;;;;;;;;8320:49;;-1:-1:-1;;8320:49:10;;;8529:13;:25;;;;;;8497:57;;;;;;;;;;;;;;;;;:29;;:57;;;8529:25;8497:57;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;8497:57:10;;;;;;;;;;;;;;;;-1:-1:-1;;8576:20:10;;8497:57;;-1:-1:-1;8576:20:10;;-1:-1:-1;8565:8:10;;-1:-1:-1;;8639:162:10;8660:3;8656:1;:7;8639:162;;;8709:6;-1:-1:-1;;;;;8689:26:10;:13;8703:1;8689:16;;;;;;;;;;;;;;-1:-1:-1;;;;;8689:26:10;;8685:105;;;8749:1;8736:14;;8769:5;;8685:105;8665:3;;8639:162;;;;8930:3;8917:10;:16;8910:24;;;;9080:10;9036:27;9066:25;;;:13;:25;;;;;9138:17;;9066:25;;-1:-1:-1;;9138:21:10;;;9127:33;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;9127:33:10;9102:10;9113;9102:22;;;;;;;;;;;;;;;;;:58;;-1:-1:-1;;;;;;9102:58:10;-1:-1:-1;;;;;9102:58:10;;;;;;;;;;9171:19;;;;-1:-1:-1;;9171:19:10;;;:::i;:::-;-1:-1:-1;9297:17:10;;9293:1023;;9376:10;9336:21;9360:27;;;:15;:27;;;;;;9548:12;:19;-1:-1:-1;;9548:23:10;9532:39;;9528:375;;;9614:12;9627:19;;9592;;9614:12;-1:-1:-1;;9627:23:10;;;9614:37;;;;;;;;;;;;;;;;9670:12;:27;;-1:-1:-1;;;;;9614:37:10;;;;-1:-1:-1;9614:37:10;;9683:13;;9670:27;;;;;;;;;;;;;;;;;;:41;;-1:-1:-1;;;;;;9670:41:10;-1:-1:-1;;;;;9670:41:10;;;;;;9790:28;;;;;;:15;:28;;;;;;:44;;;9528:375;9981:12;:21;;;;;-1:-1:-1;;9981:21:10;;;:::i;:::-;-1:-1:-1;;10055:10:10;10069:1;10039:27;;;:15;:27;;;;;;;;:31;;;10138:9;:21;;;;;:29;;-1:-1:-1;;10138:29:10;;;9293:1023;10333:32;;;-1:-1:-1;;;;;10333:32:10;;;;10354:10;10333:32;;;;;;;;;;;;;;;;;10390:14;10378:27;7111:3302;-1:-1:-1;;;;;;;;;;;;7111:3302:10:o;402:20:13:-;;;-1:-1:-1;;;;;402:20:13;;:::o;878:180::-;927:4;966:5;;-1:-1:-1;;;;;966:5:13;952:10;:19;:37;;;;-1:-1:-1;975:14:13;;-1:-1:-1;;;975:14:13;;;;952:37;951:99;;;-1:-1:-1;995:10:13;286:42;995:32;:54;;;;-1:-1:-1;1031:18:13;;-1:-1:-1;;;1031:18:13;;;;995:54;944:106;;878:180;:::o;30948:248:10:-;31042:9;31037:151;31061:19;:26;31057:30;;31037:151;;;31121:19;31141:1;31121:22;;;;;;;;;;;;;;;;;31094:94;;;-1:-1:-1;;;31094:94:10;;-1:-1:-1;;;;;31094:94:10;;;;;;;;;;;;;;;;31121:22;;;;;31094:76;;:94;;;;;;;;;;;31121:22;;31094:94;;;5:2:-1;;;;30:1;27;20:12;5:2;31094:94:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;31089:3:10;;;;;-1:-1:-1;31037:151:10;;-1:-1:-1;31037:151:10;2394:153:17;2455:4;2477:33;2490:3;2485:9;;;;;;;;2501:4;2496:10;;;;;;;;2477:33;;;;;;;;;;;;;2508:1;2477:33;;;;;;;;;;;;;2535:3;2530:9;;;;;;;1966:149:19;2093:14;2076:13;;:31;;;1966:149::o;1753:141::-;1872:14;1856:13;;:30;;1753:141::o;35268:2941:10:-;35453:5;35460:4;35466;35485:37;;:::i;:::-;-1:-1:-1;;;;;35662:22:10;;35570:9;35662:22;;;:13;:22;;;;;;;;35637:47;;;;;;;;;;;;;;;;;:22;;:47;;35662:22;35637:47;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;35637:47:10;;;;;;;;;;;;;;;;-1:-1:-1;35637:47:10;;-1:-1:-1;35700:6:10;;-1:-1:-1;;;;35695:2163:10;35716:6;:13;35712:1;:17;35695:2163;;;35751:12;35766:6;35773:1;35766:9;;;;;;;;;;;;;;35751:24;;35936:5;-1:-1:-1;;;;;35936:24:10;;35961:7;35936:33;;;;;;;;;;;;;-1:-1:-1;;;;;35936:33:10;-1:-1:-1;;;;;35936:33:10;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;35936:33:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;35936:33:10;;;;;;;13:3:-1;8;5:12;2:2;;;30:1;27;20:12;2:2;-1:-1;35936:33:10;;;;;;;;;;;;;;;;;35907:25;;35860:109;35887:18;;;35860:109;;;;35867:18;;;35860:109;;;;35936:33;-1:-1:-1;35988:9:10;;35984:166;;-1:-1:-1;36107:20:10;;-1:-1:-1;36129:1:10;;-1:-1:-1;36129:1:10;;-1:-1:-1;36099:35:10;;-1:-1:-1;;;;36099:35:10;35984:166;36188:65;;;;;;;;;-1:-1:-1;;;;;36203:23:10;;;-1:-1:-1;36203:23:10;;;:7;:23;;;;;:48;;;36188:65;;36164:21;;;:89;;;;36288:42;;;;;;;-1:-1:-1;;;36303:25:10;36288:42;;36268:17;;;:62;36428:6;;;:32;;-1:-1:-1;;;36428:32:10;;;;;;;;;;;:6;;;:25;;:32;;;;;36188:65;36428:32;;;;;:6;:32;;;5:2:-1;;;;30:1;27;20:12;5:2;36428:32:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;36428:32:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;36428:32:10;36401:24;;;:59;;;36475:102;;-1:-1:-1;36537:17:10;;-1:-1:-1;36556:1:10;;-1:-1:-1;36556:1:10;;-1:-1:-1;36529:32:10;;-1:-1:-1;;;;36529:32:10;36475:102;36610:41;;;;;;;;;36625:24;;;;36610:41;;36591:16;;;:60;36793:21;;;;36816:17;;;;36783:70;;36788:46;;:4;:46::i;:::-;36836:4;:16;;;36783:4;:70::i;:::-;36762:18;;;:91;;;37000:18;;;;37020;;36954:85;;36762:91;37000:18;36954:25;:85::i;:::-;36933:106;;37178:16;;;;37196:18;;;;37216:25;;;;37152:90;;37178:16;37196:18;37152:25;:90::i;:::-;37124:25;;;:118;-1:-1:-1;;;;;37330:21:10;;;;;;;37326:521;;;37507:86;37533:4;:18;;;37553:12;37567:4;:25;;;37507;:86::i;:::-;37479:25;;;:114;;;37773:16;;;;37747:84;;37791:12;;37747:25;:84::i;:::-;37719:25;;;:112;37326:521;-1:-1:-1;35731:3:10;;35695:2163;;;-1:-1:-1;37967:25:10;;;;37946:18;;:46;37942:260;;;-1:-1:-1;;38054:25:10;;;;38033:18;;38017:14;;-1:-1:-1;38033:46:10;;-1:-1:-1;38017:14:10;;-1:-1:-1;38009:74:10;;37942:260;-1:-1:-1;;38171:18:10;;38143:25;;;;;38124:14;;-1:-1:-1;38124:14:10;;-1:-1:-1;38143:46:10;;-1:-1:-1;38116:74:10;;3190:116:19;3243:4;3267:31;3272:1;3275;3267:31;;;;;;;;;;;;;-1:-1:-1;;;3267:31:19;;;:4;:31::i;2002:271:9:-;2073:9;2084:4;2102:14;2118:8;2130:13;2138:1;2141;2130:7;:13::i;:::-;2101:42;;-1:-1:-1;2101:42:9;-1:-1:-1;2168:18:9;2160:4;:26;;;;;;;;;2156:75;;-1:-1:-1;2211:4:9;-1:-1:-1;2217:1:9;;-1:-1:-1;2203:16:9;;2156:75;2250:15;2258:3;2263:1;2250:7;:15::i;:::-;2243:22;;;;;;2002:271;;;;;;:::o;1675:258::-;1731:9;;1768:5;;;1790:6;;;1786:140;;1821:18;;-1:-1:-1;1841:1:9;-1:-1:-1;1813:30:9;;1786:140;-1:-1:-1;1884:26:9;;-1:-1:-1;1912:1:9;;-1:-1:-1;1675:258:9;;;;;;:::o;30528:248:10:-;30622:9;30617:151;30641:19;:26;30637:30;;30617:151;;;30701:19;30721:1;30701:22;;;;;;;;;;;;;;;;;30674:94;;;-1:-1:-1;;;30674:94:10;;-1:-1:-1;;;;;30674:94:10;;;;;;;;;;;;;;;;30701:22;;;;;30674:76;;:94;;;;;;;;;;;30701:22;;30674:94;;;5:2:-1;;;;30:1;27;20:12;5:2;30674:94:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;30669:3:10;;;;;-1:-1:-1;30617:151:10;;-1:-1:-1;30617:151:10;33257:187;33334:5;33341:4;33347;33371:65;33411:7;33427:1;33431;33434;33371:39;:65::i;:::-;33364:72;;;;;;33257:187;;;;;:::o;1142:174:19:-;1220:4;1237:18;;:::i;:::-;1258:15;1263:1;1266:6;1258:4;:15::i;:::-;1237:36;;1291:17;1300:7;1291:8;:17::i;2498:313:18:-;2575:9;2586:4;2604:13;2619:18;;:::i;:::-;2641:20;2651:1;2654:6;2641:9;:20::i;:::-;2603:58;;-1:-1:-1;2603:58:18;-1:-1:-1;2683:18:18;2676:3;:25;;;;;;;;;2672:73;;-1:-1:-1;2726:3:18;-1:-1:-1;2731:1:18;;-1:-1:-1;2718:15:18;;2672:73;2765:18;2785:17;2794:7;2785:8;:17::i;:::-;2757:46;;;;;;2498:313;;;;;:::o;50982:1347:10:-;51039:4;51095:16;:14;:16::i;:::-;51090:121;;51135:64;51140:18;51160:38;51135:4;:64::i;51090:121::-;-1:-1:-1;;;;;51265:24:10;;;;;;:7;:24;;;;;:33;;;51261:141;;;51322:68;51327:27;51356:33;51322:4;:68::i;51261:141::-;51480:6;-1:-1:-1;;;;;51480:15:10;;:17;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;51480:17:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;51480:17:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;51480:17:10;51472:58;;;;;-1:-1:-1;;;51472:58:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;51637:4;-1:-1:-1;;;;;51596:46:10;51604:6;-1:-1:-1;;;;;51604:18:10;;:20;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;51604:20:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;51604:20:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;51604:20:10;-1:-1:-1;;;;;51596:46:10;;51588:112;;;;-1:-1:-1;;;51588:112:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;51764:18;51785:6;-1:-1:-1;;;;;51785:15:10;;:17;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;51785:17:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;51785:17:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;51785:17:10;:69;;51833:6;-1:-1:-1;;;;;51818:34:10;;:36;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;51818:36:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;51818:36:10;;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;-1:-1;51818:36:10;51785:69;;;51813:1;51785:69;-1:-1:-1;;;;;51879:31:10;;;51923:1;51879:31;;;:19;:31;;;;;;51764:90;;-1:-1:-1;51879:31:10;51871:54;51867:162;;51949:68;51954:27;51983:33;51949:4;:68::i;:::-;51942:75;;;;;51867:162;52107:53;;;;;;;;52125:4;52107:53;;;-1:-1:-1;52107:53:10;;;;;;;-1:-1:-1;;;;;52080:24:10;;;;;;:7;:24;;;;;:80;;;;-1:-1:-1;;52080:80:10;;;;;;;;;;;;;;;;52171:10;27::-1;;23:18;;;45:23;;52171::10;;;;;;-1:-1:-1;;;;;;52171:23:10;;;;;;;;52205:31;;;;;:19;:31;;;;;;:40;;;;;;;;;;52261:20;;;;;;;;;;;;;;;;;52306:14;52301:20;;14485:871;-1:-1:-1;;;;;14614:15:10;;14592:4;14614:15;;;:7;:15;;;;;:24;;;14609:94;;14667:23;14662:29;;14609:94;-1:-1:-1;;;;;14814:15:10;;;;;;;:7;:15;;;;;;;;:43;;;;;:33;;;;:43;;;;;;14809:104;;14886:14;14881:20;;14809:104;15018:9;15031:14;15049:82;15089:8;15106:6;15115:12;15129:1;15049:39;:82::i;:::-;15017:114;;-1:-1:-1;15017:114:10;;-1:-1:-1;15153:14:10;;-1:-1:-1;15146:3:10;:21;;;;;;;;;15142:70;;15196:3;15191:9;;;;;;;;15184:16;;;;;;15142:70;15226:13;;15222:87;;15268:28;15263:34;;31446:256;31548:9;31543:151;31567:19;:26;31563:30;;31543:151;;;31627:19;31647:1;31627:22;;;;;;;;;;;;;;;;;31600:94;;;-1:-1:-1;;;31600:94:10;;-1:-1:-1;;;;;31600:94:10;;;;;;;;;;;;;;;;;;;;;;;31627:22;;;;;31600:76;;:94;;;;;;;;;;;31627:22;;31600:94;;;5:2:-1;;;;30:1;27;20:12;5:2;31600:94:10;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;31595:3:10;;;;;-1:-1:-1;31543:151:10;;-1:-1:-1;31543:151:10;5460:1257;-1:-1:-1;;;;;5588:24:10;;5540:5;5588:24;;;:7;:24;;;;;5630:21;;;;5625:135;;5725:23;5718:30;;;;;5625:135;-1:-1:-1;;;;;5776:40:10;;;;;;:30;;;:40;;;;;;;;:48;;:40;:48;5772:133;;;5879:14;5872:21;;;;;5772:133;-1:-1:-1;;;;;6293:40:10;;;;;;;:30;;;:40;;;;;;;;:47;;6336:4;-1:-1:-1;;6293:47:10;;;;;;;;6351:13;:23;;;;;27:10:-1;;23:18;;;45:23;;6351:36:10;;;;;;;;-1:-1:-1;;;;;;6351:36:10;;;;;;;;;;;6445:19;;;:9;:19;;;;;6293:47;6445:19;6440:187;;6481:12;27:10:-1;;39:1;23:18;;;45:23;;6481:27:10;;;;;;-1:-1:-1;;;;;;6481:27:10;-1:-1:-1;;;;;6481:27:10;;;;;;;;-1:-1:-1;6523:19:10;;;:9;6481:27;6523:19;;;;;;;:26;;-1:-1:-1;;6523:26:10;;;;;;;6592:19;;6564:15;:25;;;;-1:-1:-1;;6592:23:10;;;6564:51;;6440:187;6644:31;;;-1:-1:-1;;;;;6644:31:10;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;6695:14:10;;5460:1257;-1:-1:-1;;;5460:1257:10:o;4119:159:19:-;4184:10;;:::i;:::-;4214:56;;;;;;;;420:4;4229:28;4234:1;:10;;;4246:1;:10;;;4229:4;:28::i;:::-;:39;;;;;;4214:56;;4207:63;4119:159;-1:-1:-1;;;4119:159:19:o;5411:164::-;5476:10;;:::i;:::-;5506:61;;;;;;;;5521:44;5526:26;5531:1;:10;;;420:4;5526;:26::i;:::-;5554:10;;5521:4;:44::i;:::-;5506:61;;5499:68;5411:164;-1:-1:-1;;;5411:164:19:o;2670:187:17:-;2755:4;2777:43;2790:3;2785:9;;;;;;;;2801:4;2796:10;;;;;;;;2777:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;2845:3;2840:9;;;;;;;1461:208:19;1559:4;1576:18;;:::i;:::-;1597:15;1602:1;1605:6;1597:4;:15::i;:::-;1576:36;;1630:31;1635:17;1644:7;1635:8;:17::i;:::-;1654:6;1630:4;:31::i;3314:179::-;3395:4;3421:5;;;3453:12;3445:6;;;;3437:29;;;;-1:-1:-1;;;3437:29:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;23:1:-1;8:100;33:3;30:1;27:10;8:100;;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;;12:14;3437:29:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3484:1:19;3314:179;-1:-1:-1;;;;3314:179:19:o;1354:236:9:-;1410:9;1421:4;1447:1;1442;:6;1438:145;;-1:-1:-1;1473:18:9;;-1:-1:-1;1493:5:9;;;1465:34;;1438:145;-1:-1:-1;1540:27:9;;-1:-1:-1;1569:1:9;1532:39;;4286:133:19;4345:10;;:::i;:::-;4375:36;;;;;;;;4390:19;4395:1;:10;;;4407:1;4390:4;:19::i;816:213::-;998:12;420:4;998:23;;;816:213::o;2032:353:18:-;2101:9;2112:10;;:::i;:::-;2136:14;2152:19;2175:27;2183:1;:10;;;2195:6;2175:7;:27::i;:::-;2135:67;;-1:-1:-1;2135:67:18;-1:-1:-1;2225:18:18;2217:4;:26;;;;;;;;;2213:92;;-1:-1:-1;2274:18:18;;;;;;;;;-1:-1:-1;2274:18:18;;2268:4;;-1:-1:-1;2274:18:18;-1:-1:-1;2260:33:18;;2213:92;2345:31;;;;;;;;;;;;-1:-1:-1;;2345:31:18;;-1:-1:-1;2032:353:18;-1:-1:-1;;;;2032:353:18:o;5023:122:19:-;5076:4;5100:37;5105:1;5108;5100:37;;;;;;;;;;;;;;;;;:4;:37::i;6335:113::-;6388:4;6412:28;6417:1;6420;6412:28;;;;;;;;;;;;;-1:-1:-1;;;6412:28:19;;;:4;:28::i;566:343:9:-;622:9;;654:6;650:69;;-1:-1:-1;685:18:9;;-1:-1:-1;685:18:9;677:30;;650:69;740:5;;;744:1;740;:5;:1;762:5;;;;;:10;758:144;;-1:-1:-1;797:26:9;;-1:-1:-1;825:1:9;;-1:-1:-1;789:38:9;;758:144;868:18;;-1:-1:-1;888:1:9;-1:-1:-1;860:30:9;;5153:250:19;5234:4;5255:6;;;:16;;-1:-1:-1;5265:6:19;;5255:16;5251:57;;;-1:-1:-1;5295:1:19;5288:8;;5251:57;5327:5;;;5331:1;5327;:5;:1;5351:5;;;;;:10;5363:12;5343:33;;;;;-1:-1:-1;;;5343:33:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;27:10:-1;;8:100;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;6456:157:19;6537:4;6569:12;6562:5;6554:28;;;;-1:-1:-1;;;6554:28:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;27:10:-1;;8:100;;90:11;;;84:18;71:11;;;64:39;52:2;45:10;8:100;;6554:28:19;;6604:1;6600;:5;;;;;;;6456:157;-1:-1:-1;;;;6456:157:19:o;551:64967:10:-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;
Swarm Source
bzzr://fbf27f05c82565752ceab138f2e7c90df743ae2aadc8ff401398698d6d3e1e3d
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.