Transaction Hash:
Block:
8249967 at Jul-30-2019 05:02:39 AM +UTC
Transaction Fee:
0.0002759352 ETH
$0.68
Gas Used:
114,973 Gas / 2.4 Gwei
Emitted Events:
109 |
CErc20.AccrueInterest( interestAccumulated=9683669633837251016, borrowIndex=1034970556650291066, totalBorrows=27740659148136081089825772 )
|
110 |
DSToken.Transfer( src=[Sender] 0xc1a0a697990d56af43fb7738da38b3c174e4e49d, dst=[Receiver] CErc20, wad=60000000000000000 )
|
111 |
CErc20.Mint( minter=[Sender] 0xc1a0a697990d56af43fb7738da38b3c174e4e49d, mintAmount=60000000000000000, mintTokens=293401650 )
|
112 |
CErc20.Transfer( from=[Receiver] CErc20, to=[Sender] 0xc1a0a697990d56af43fb7738da38b3c174e4e49d, amount=293401650 )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x89d24A6b...a23260359 | |||||
0xc1a0a697...174e4e49d |
0.01267019 Eth
Nonce: 3
|
0.0123942548 Eth
Nonce: 4
| 0.0002759352 | ||
0xEA674fdD...16B898ec8
Miner
| (Ethermine) | 313.654533290312021739 Eth | 313.654809225512021739 Eth | 0.0002759352 | |
0xF5DCe572...Fcac444dC |
Execution Trace
CErc20.mint( mintAmount=60000000000000000 ) => ( 0 )

-
DSToken.balanceOf( src=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC ) => ( 3434279987138317709419511 )
-
WhitePaperInterestRateModel.getBorrowRate( cash=3434279987138317709419511, borrows=27740649464466447252574756, _reserves=34227247350076861479378 ) => ( 0, 87269673032 )
Unitroller.4ef4c3e1( )
-
Comptroller.mintAllowed( cToken=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC, minter=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, mintAmount=60000000000000000 ) => ( 0 )
-
-
DSToken.allowance( src=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, guy=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC ) => ( 115792089237316195423570985008687907853269984665640564039457584007913129639935 )
-
DSToken.balanceOf( src=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d ) => ( 60000000000000000 )
-
DSToken.balanceOf( src=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC ) => ( 3434279987138317709419511 )
-
DSToken.transferFrom( src=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, dst=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC, wad=60000000000000000 ) => ( True )
Unitroller.41c728b9( )
-
Comptroller.mintVerify( cToken=0xF5DCe57282A584D2746FaF1593d3121Fcac444dC, minter=0xc1a0a697990D56af43fB7738dA38b3C174e4e49d, mintAmount=60000000000000000, mintTokens=293401650 )
-
mint[CErc20 (ln:2420)]
mintInternal[CErc20 (ln:2421)]
File 1 of 5: CErc20
File 2 of 5: DSToken
File 3 of 5: WhitePaperInterestRateModel
File 4 of 5: Unitroller
File 5 of 5: Comptroller
12345678910111213141516// File: contracts/ComptrollerInterface.solpragma solidity ^0.5.8;interface ComptrollerInterface {/*** @notice Marker function used for light validation when updating the comptroller of a market* @dev Implementations should simply return true.* @return true*/function isComptroller() external view returns (bool);/*** Assets You Are In ***/function enterMarkets(address[] calldata cTokens) external returns (uint[] memory);function exitMarket(address cToken) external returns (uint);
File 2 of 5: DSToken
12345678910111213141516pragma solidity ^0.4.13;////// lib/ds-math/src/math.sol/// math.sol -- mixin for inline numerical wizardry// This program is free software: you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation, either version 3 of the License, or// (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License
File 3 of 5: WhitePaperInterestRateModel
12345678910111213141516// File: contracts/CarefulMath.solpragma solidity ^0.5.8;/*** @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 {
File 4 of 5: Unitroller
12345678910111213141516// File: contracts/ErrorReporter.solpragma solidity ^0.5.8;contract ComptrollerErrorReporter {enum Error {NO_ERROR,UNAUTHORIZED,COMPTROLLER_MISMATCH,INSUFFICIENT_SHORTFALL,INSUFFICIENT_LIQUIDITY,INVALID_CLOSE_FACTOR,INVALID_COLLATERAL_FACTOR,INVALID_LIQUIDATION_INCENTIVE,MARKET_NOT_ENTERED,MARKET_NOT_LISTED,
File 5 of 5: Comptroller
1{"CarefulMath.sol":{"content":"pragma solidity ^0.5.8;\n\n/**\n * @title Careful Math\n * @author Compound\n * @notice Derived fromOpenZeppelin\u0027s SafeMath library\n * https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol\n*/\ncontract CarefulMath {\n\n /**\n * @dev Possible error codes that we can return\n */\n enum MathError {\n NO_ERROR,\nDIVISION_BY_ZERO,\n INTEGER_OVERFLOW,\n INTEGER_UNDERFLOW\n }\n\n /**\n * @dev Multiplies two numbers, returns an erroron overflow.\n */\n function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {\n if (a == 0) {\n return(MathError.NO_ERROR, 0);\n }\n\n uint c = a * b;\n\n if (c / a != b) {\n return (MathError.INTEGER_OVERFLOW, 0);\n} else {\n return (MathError.NO_ERROR, c);\n }\n }\n\n /**\n * @dev Integer division of two numbers, truncatingthe quotient.\n */\n function divUInt(uint a, uint b) internal pure returns (MathError, uint) {\n if (b == 0) {\n return(MathError.DIVISION_BY_ZERO, 0);\n }\n\n return (MathError.NO_ERROR, a / b);\n }\n\n /**\n * @dev Subtracts two numbers,returns an error on overflow (i.e. if subtrahend is greater than minuend).\n */\n function subUInt(uint a, uint b) internal pure returns(MathError, uint) {\n if (b \u003c= a) {\n return (MathError.NO_ERROR, a - b);\n } else {\n return (MathError.INTEGER_UNDERFLOW, 0);\n }\n }\n\n /**\n * @dev Adds two numbers, returns an error on overflow.\n */\n function addUInt(uinta, uint b) internal pure returns (MathError, uint) {\n uint c = a + b;\n\n if (c \u003e= a) {\n return (MathError.NO_ERROR, c);\n } else {\n return (MathError.INTEGER_OVERFLOW, 0);\n }\n }\n\n /**\n * @dev add a and b and then subtractc\n */\n function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {\n (MathError err0, uint sum) =addUInt(a, b);\n\n if (err0 != MathError.NO_ERROR) {\n return (err0, 0);\n }\n\n return subUInt(sum, c);\n}\n}"},"CErc20.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CToken.sol\";\n\n/**\n * @title Compound\u0027s CErc20 Contract\n * @noticeCTokens which wrap an EIP-20 underlying\n * @author Compound\n */\ncontract CErc20 is CToken {\n\n /**\n * @notice Underlying asset for thisCToken\n */\n address public underlying;\n\n /**\n * @notice Construct a new money market\n * @param underlying_ The address ofthe underlying asset\n * @param comptroller_ The address of the Comptroller\n * @param interestRateModel_ The address of the interest ratemodel\n * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18\n * @param name_ ERC-20 name of this token\n *@param symbol_ ERC-20 symbol of this token\n * @param decimals_ ERC-20 decimal precision of this token\n */\n constructor(addressunderlying_,\n ComptrollerInterface comptroller_,\n InterestRateModel interestRateModel_,\n uintinitialExchangeRateMantissa_,\n string memory name_,\n string memory symbol_,\n uint decimals_)public\n CToken(comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_) {\n // Set underlying\nunderlying = underlying_;\n EIP20Interface(underlying).totalSupply(); // Sanity check the underlying\n }\n\n /*** User Interface***/\n\n /**\n * @notice Sender supplies assets into the market and receives cTokens in exchange\n * @dev Accrues interest whether ornot the operation succeeds, unless reverted\n * @param mintAmount The amount of the underlying asset to supply\n * @return uint 0=success,otherwise a failure (see ErrorReporter.sol for details)\n */\n function mint(uint mintAmount) external returns (uint) {\n returnmintInternal(mintAmount);\n }\n\n /**\n * @notice Sender redeems cTokens in exchange for the underlying asset\n * @dev Accruesinterest whether or not the operation succeeds, unless reverted\n * @param redeemTokens The number of cTokens to redeem into underlying\n *@return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function redeem(uint redeemTokens) external returns(uint) {\n return redeemInternal(redeemTokens);\n }\n\n /**\n * @notice Sender redeems cTokens in exchange for a specified amountof underlying asset\n * @dev Accrues interest whether or not the operation succeeds, unless reverted\n * @param redeemAmount The amount ofunderlying to redeem\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n functionredeemUnderlying(uint redeemAmount) external returns (uint) {\n return redeemUnderlyingInternal(redeemAmount);\n }\n\n /**\n *@notice Sender borrows assets from the protocol to their own address\n * @param borrowAmount The amount of the underlying asset to borrow\n* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function borrow(uint borrowAmount) externalreturns (uint) {\n return borrowInternal(borrowAmount);\n }\n\n /**\n * @notice Sender repays their own borrow\n * @paramrepayAmount The amount to repay\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n functionrepayBorrow(uint repayAmount) external returns (uint) {\n return repayBorrowInternal(repayAmount);\n }\n\n /**\n * @notice Senderrepays a borrow belonging to borrower\n * @param borrower the account with the debt being payed off\n * @param repayAmount The amount torepay\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function repayBorrowBehalf(addressborrower, uint repayAmount) external returns (uint) {\n return repayBorrowBehalfInternal(borrower, repayAmount);\n }\n\n /**\n *@notice The sender liquidates the borrowers collateral.\n * The collateral seized is transferred to the liquidator.\n * @param borrowerThe borrower of this cToken to be liquidated\n * @param cTokenCollateral The market in which to seize collateral from the borrower\n *@param repayAmount The amount of the underlying borrowed asset to repay\n * @return uint 0=success, otherwise a failure (see ErrorReporter.solfor details)\n */\n function liquidateBorrow(address borrower, uint repayAmount, CToken cTokenCollateral) external returns (uint) {\nreturn liquidateBorrowInternal(borrower, repayAmount, cTokenCollateral);\n }\n\n /*** Safe Token ***/\n\n /**\n * @notice Getsbalance of this contract in terms of the underlying\n * @dev This excludes the value of the current message, if any\n * @return Thequantity of underlying tokens owned by this contract\n */\n function getCashPrior() internal view returns (uint) {\n EIP20Interfacetoken = EIP20Interface(underlying);\n return token.balanceOf(address(this));\n }\n\n /**\n * @dev Checks whether or not there issufficient allowance for this contract to move amount from `from` and\n * whether or not `from` has a balance of at least `amount`. DoesNOT do a transfer.\n */\n function checkTransferIn(address from, uint amount) internal view returns (Error) {\n EIP20Interface token= EIP20Interface(underlying);\n\n if (token.allowance(from, address(this)) \u003c amount) {\n return Error.TOKEN_INSUFFICIENT_ALLOWANCE;\n }\n\n if (token.balanceOf(from) \u003c amount) {\n return Error.TOKEN_INSUFFICIENT_BALANCE;\n }\n\n return Error.NO_ERROR;\n }\n\n /**\n * @dev Similar to EIP20 transfer, except ithandles a False result from `transferFrom` and returns an explanatory\n * error code rather than reverting. If caller has not called`checkTransferIn`, this may revert due to\n * insufficient balance or insufficient allowance. If caller has called `checkTransferIn` priorto this call,\n * and it returned Error.NO_ERROR, this should not revert in normal conditions.\n *\n * Note: This wrappersafely handles non-standard ERC-20 tokens that do not return a value.\n * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n */\n function doTransferIn(address from, uint amount) internal returns (Error) {\nEIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);\n bool result;\n\n token.transferFrom(from, address(this), amount);\n\n // solium-disable-next-line security/no-inline-assembly\n assembly {\n switch returndatasize()\ncase 0 { // This is a non-standard ERC-20\n result := not(0) // set result to true\n}\n case 32 { // This is a complaint ERC-20\n returndatacopy(0, 0, 32)\nresult := mload(0) // Set `result = returndata` of external call\n }\n default {// This is an excessively non-compliant ERC-20, revert.\n revert(0, 0)\n }\n }\n\n if (!result){\n return Error.TOKEN_TRANSFER_IN_FAILED;\n }\n\n return Error.NO_ERROR;\n }\n\n /**\n * @dev Similar to EIP20transfer, except it handles a False result from `transfer` and returns an explanatory\n * error code rather than reverting. If caller hasnot called checked protocol\u0027s balance, this may revert due to\n * insufficient cash held in this contract. If caller has checkedprotocol\u0027s balance prior to this call, and verified\n * it is \u003e= amount, this should not revert in normal conditions.\n *\n* Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.\n * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n */\n function doTransferOut(address payable to, uint amount)internal returns (Error) {\n EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);\n bool result;\n\n token.transfer(to, amount);\n\n // solium-disable-next-line security/no-inline-assembly\n assembly {\n switch returndatasize()\n case 0 { // This is a non-standard ERC-20\n result := not(0) // set result totrue\n }\n case 32 { // This is a complaint ERC-20\n returndatacopy(0, 0, 32)\n result := mload(0) // Set `result = returndata` of external call\n }\n default {// This is an excessively non-compliant ERC-20, revert.\n revert(0, 0)\n }\n }\n\n if(!result) {\n return Error.TOKEN_TRANSFER_OUT_FAILED;\n }\n\n return Error.NO_ERROR;\n }\n}\n"},"CEther.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CToken.sol\";\n\n/**\n * @title Compound\u0027s CEther Contract\n * @notice CToken which wraps Ether\n *@author Compound\n */\ncontract CEther is CToken {\n /**\n * @notice Construct a new CEther money market\n * @param comptroller_ Theaddress of the Comptroller\n * @param interestRateModel_ The address of the interest rate model\n * @param initialExchangeRateMantissa_ Theinitial exchange rate, scaled by 1e18\n * @param name_ ERC-20 name of this token\n * @param symbol_ ERC-20 symbol of this token\n *@param decimals_ ERC-20 decimal precision of this token\n */\n constructor(ComptrollerInterface comptroller_,\nInterestRateModel interestRateModel_,\n uint initialExchangeRateMantissa_,\n string memory name_,\nstring memory symbol_,\n uint decimals_) public\n CToken(comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_,symbol_, decimals_) {}\n\n /*** User Interface ***/\n\n /**\n * @notice Sender supplies assets into the market and receives cTokens inexchange\n * @dev Reverts upon any failure\n */\n function mint() external payable {\n requireNoError(mintInternal(msg.value),\"mint failed\");\n }\n\n /**\n * @notice Sender redeems cTokens in exchange for the underlying asset\n * @dev Accrues interestwhether or not the operation succeeds, unless reverted\n * @param redeemTokens The number of cTokens to redeem into underlying\n * @returnuint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function redeem(uint redeemTokens) external returns (uint){\n return redeemInternal(redeemTokens);\n }\n\n /**\n * @notice Sender redeems cTokens in exchange for a specified amount ofunderlying asset\n * @dev Accrues interest whether or not the operation succeeds, unless reverted\n * @param redeemAmount The amount ofunderlying to redeem\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n functionredeemUnderlying(uint redeemAmount) external returns (uint) {\n return redeemUnderlyingInternal(redeemAmount);\n }\n\n /**\n *@notice Sender borrows assets from the protocol to their own address\n * @param borrowAmount The amount of the underlying asset to borrow\n* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function borrow(uint borrowAmount) externalreturns (uint) {\n return borrowInternal(borrowAmount);\n }\n\n /**\n * @notice Sender repays their own borrow\n * @devReverts upon any failure\n */\n function repayBorrow() external payable {\n requireNoError(repayBorrowInternal(msg.value),\"repayBorrow failed\");\n }\n\n /**\n * @notice Sender repays a borrow belonging to borrower\n * @dev Reverts upon any failure\n* @param borrower the account with the debt being payed off\n */\n function repayBorrowBehalf(address borrower) external payable {\nrequireNoError(repayBorrowBehalfInternal(borrower, msg.value), \"repayBorrowBehalf failed\");\n }\n\n /**\n * @notice The senderliquidates the borrowers collateral.\n * The collateral seized is transferred to the liquidator.\n * @dev Reverts upon any failure\n *@param borrower The borrower of this cToken to be liquidated\n * @param cTokenCollateral The market in which to seize collateral from theborrower\n */\n function liquidateBorrow(address borrower, CToken cTokenCollateral) external payable {\n requireNoError(liquidateBorrowInternal(borrower, msg.value, cTokenCollateral), \"liquidateBorrow failed\");\n }\n\n /**\n * @notice Send Ether toCEther to mint\n */\n function () external payable {\n requireNoError(mintInternal(msg.value), \"mint failed\");\n }\n\n /***Safe Token ***/\n\n /**\n * @notice Gets balance of this contract in terms of Ether, before this message\n * @dev This excludes thevalue of the current message, if any\n * @return The quantity of Ether owned by this contract\n */\n function getCashPrior() internalview returns (uint) {\n (MathError err, uint startingBalance) = subUInt(address(this).balance, msg.value);\n require(err == MathError.NO_ERROR);\n return startingBalance;\n }\n\n /**\n * @notice Checks whether the requested transfer matches the `msg`\n * @devDoes NOT do a transfer\n * @param from Address sending the Ether\n * @param amount Amount of Ether being sent\n * @return Whether ornot the transfer checks out\n */\n function checkTransferIn(address from, uint amount) internal view returns (Error) {\n // Sanitychecks\n require(msg.sender == from, \"sender mismatch\");\n require(msg.value == amount, \"value mismatch\");\n return Error.NO_ERROR;\n }\n\n /**\n * @notice Perform the actual transfer in, which is a no-op\n * @param from Address sending the Ether\n *@param amount Amount of Ether being sent\n * @return Success\n */\n function doTransferIn(address from, uint amount) internal returns(Error) {\n // Sanity checks\n require(msg.sender == from, \"sender mismatch\");\n require(msg.value == amount, \"valuemismatch\");\n return Error.NO_ERROR;\n }\n\n function doTransferOut(address payable to, uint amount) internal returns (Error) {\n/* Send the Ether, with minimal gas and revert on failure */\n to.transfer(amount);\n return Error.NO_ERROR;\n }\n\nfunction requireNoError(uint errCode, string memory message) internal pure {\n if (errCode == uint(Error.NO_ERROR)) {\n return;\n}\n\n bytes memory fullMessage = new bytes(bytes(message).length + 5);\n uint i;\n\n for (i = 0; i \u003c bytes(message).length; i++) {\n fullMessage[i] = bytes(message)[i];\n }\n\n fullMessage[i+0] = byte(uint8(32));\n fullMessage[i+1] = byte(uint8(40));\n fullMessage[i+2] = byte(uint8(48 + ( errCode / 10 )));\n fullMessage[i+3] = byte(uint8(48 + ( errCode % 10)));\n fullMessage[i+4] = byte(uint8(41));\n\n require(errCode == uint(Error.NO_ERROR), string(fullMessage));\n }\n}\n"},"Comptroller.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CToken.sol\";\nimport \"./ErrorReporter.sol\";\nimport \"./Exponential.sol\";\nimport \"./PriceOracle.sol\";\nimport \"./ComptrollerInterface.sol\";\nimport \"./ComptrollerStorage.sol\";\nimport \"./Unitroller.sol\";\n\n/**\n * @title Compound\u0027s Comptroller Contract\n * @author Compound\n */\ncontract Comptroller is ComptrollerV1Storage, ComptrollerInterface,ComptrollerErrorReporter, Exponential {\n struct Market {\n /**\n * @notice Whether or not this market is listed\n */\nbool isListed;\n\n /**\n * @notice Multiplier representing the most one can borrow against their collateral in this market.\n* For instance, 0.9 to allow borrowing 90% of collateral value.\n * Must be between 0 and 1, and stored as a mantissa.\n*/\n uint collateralFactorMantissa;\n\n /**\n * @notice Per-market mapping of \"accounts in this asset\"\n */\nmapping(address =\u003e bool) accountMembership;\n }\n\n /**\n * @notice Official mapping of cTokens -\u003e Market metadata\n *@dev Used e.g. to determine if a market is supported\n */\n mapping(address =\u003e Market) public markets;\n\n /**\n * @noticeEmitted when an admin supports a market\n */\n event MarketListed(CToken cToken);\n\n /**\n * @notice Emitted when an account entersa market\n */\n event MarketEntered(CToken cToken, address account);\n\n /**\n * @notice Emitted when an account exits a market\n*/\n event MarketExited(CToken cToken, address account);\n\n /**\n * @notice Emitted when close factor is changed by admin\n */\nevent NewCloseFactor(uint oldCloseFactorMantissa, uint newCloseFactorMantissa);\n\n /**\n * @notice Emitted when a collateral factor ischanged by admin\n */\n event NewCollateralFactor(CToken cToken, uint oldCollateralFactorMantissa, uint newCollateralFactorMantissa);\n\n/**\n * @notice Emitted when liquidation incentive is changed by admin\n */\n event NewLiquidationIncentive(uintoldLiquidationIncentiveMantissa, uint newLiquidationIncentiveMantissa);\n\n /**\n * @notice Emitted when maxAssets is changed by admin\n*/\n event NewMaxAssets(uint oldMaxAssets, uint newMaxAssets);\n\n /**\n * @notice Emitted when price oracle is changed\n */\nevent NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle);\n\n /**\n * @notice Indicator that this is a Comptrollercontract (for inspection)\n */\n bool public constant isComptroller = true;\n\n // closeFactorMantissa must be strictly greater than thisvalue\n uint constant closeFactorMinMantissa = 5e16; // 0.05\n\n // closeFactorMantissa must not exceed this value\n uint constantcloseFactorMaxMantissa = 9e17; // 0.9\n\n // No collateralFactorMantissa may exceed this value\n uint constant collateralFactorMaxMantissa =9e17; // 0.9\n\n // liquidationIncentiveMantissa must be no less than this value\n uint constant liquidationIncentiveMinMantissa =mantissaOne;\n\n // liquidationIncentiveMantissa must be no greater than this value\n uint constant liquidationIncentiveMaxMantissa = 15e17;// 1.5\n\n constructor() public {\n admin = msg.sender;\n }\n\n /*** Assets You Are In ***/\n\n /**\n * @notice Returns theassets an account has entered\n * @param account The address of the account to pull assets for\n * @return A dynamic list with the assetsthe account has entered\n */\n function getAssetsIn(address account) external view returns (CToken[] memory) {\n CToken[] memoryassetsIn = accountAssets[account];\n\n return assetsIn;\n }\n\n /**\n * @notice Returns whether the given account is entered inthe given asset\n * @param account The address of the account to check\n * @param cToken The cToken to check\n * @return True if theaccount is in the asset, otherwise false.\n */\n function checkMembership(address account, CToken cToken) external view returns (bool) {\nreturn markets[address(cToken)].accountMembership[account];\n }\n\n /**\n * @notice Add assets to be included in account liquiditycalculation\n * @param cTokens The list of addresses of the cToken markets to be enabled\n * @return Success indicator for whether eachcorresponding market was entered\n */\n function enterMarkets(address[] memory cTokens) public returns (uint[] memory) {\n uint len =cTokens.length;\n\n uint[] memory results = new uint[](len);\n for (uint i = 0; i \u003c len; i++) {\n CToken cToken =CToken(cTokens[i]);\n Market storage marketToJoin = markets[address(cToken)];\n\n if (!marketToJoin.isListed) {\n// if market is not listed, cannot join move along\n results[i] = uint(Error.MARKET_NOT_LISTED);\n continue;\n}\n\n if (marketToJoin.accountMembership[msg.sender] == true) {\n // if already joined, move along\nresults[i] = uint(Error.NO_ERROR);\n continue;\n }\n\n if (accountAssets[msg.sender].length \u003e=maxAssets) {\n // if no space, cannot join, move along\n results[i] = uint(Error.TOO_MANY_ASSETS);\ncontinue;\n }\n\n // survived the gauntlet, add to list\n // NOTE: we store these somewhat redundantly as asignificant optimization\n // this avoids having to iterate through the list for the most common use cases\n // that is,only when we need to perform liquidity checks\n // and not whenever we want to check if an account is in a particular market\nmarketToJoin.accountMembership[msg.sender] = true;\n accountAssets[msg.sender].push(cToken);\n\n emit MarketEntered(cToken, msg.sender);\n\n results[i] = uint(Error.NO_ERROR);\n }\n\n return results;\n }\n\n /**\n * @noticeRemoves asset from sender\u0027s account liquidity calculation\n * @dev Sender must not have an outstanding borrow balance in the asset,\n* or be providing neccessary collateral for an outstanding borrow.\n * @param cTokenAddress The address of the asset to be removed\n *@return Whether or not the account successfully exited the market\n */\n function exitMarket(address cTokenAddress) external returns (uint){\n CToken cToken = CToken(cTokenAddress);\n /* Get sender tokensHeld and amountOwed underlying from the cToken */\n (uintoErr, uint tokensHeld, uint amountOwed, ) = cToken.getAccountSnapshot(msg.sender);\n require(oErr == 0, \"exitMarket: getAccountSnapshotfailed\"); // semi-opaque error code\n\n /* Fail if the sender has a borrow balance */\n if (amountOwed != 0) {\n returnfail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED);\n }\n\n /* Fail if the sender is not permitted to redeemall of their tokens */\n uint allowed = redeemAllowedInternal(cTokenAddress, msg.sender, tokensHeld);\n if (allowed != 0) {\nreturn failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed);\n }\n\n Market storage marketToExit =markets[address(cToken)];\n\n /* Return true if the sender is not already ‘in’ the market */\n if (!marketToExit.accountMembership[msg.sender]) {\n return uint(Error.NO_ERROR);\n }\n\n /* Set cToken account membership to false */\ndelete marketToExit.accountMembership[msg.sender];\n\n /* Delete cToken from the account’s list of assets */\n // load intomemory for faster iteration\n CToken[] memory userAssetList = accountAssets[msg.sender];\n uint len = userAssetList.length;\nuint assetIndex = len;\n for (uint i = 0; i \u003c len; i++) {\n if (userAssetList[i] == cToken) {\n assetIndex =i;\n break;\n }\n }\n\n // We *must* have found the asset in the list or our redundant data structure isbroken\n assert(assetIndex \u003c len);\n\n // copy last item in list to location of item to be removed, reduce length by 1\nCToken[] storage storedList = accountAssets[msg.sender];\n storedList[assetIndex] = storedList[storedList.length - 1];\n storedList.length--;\n\n emit MarketExited(cToken, msg.sender);\n\n return uint(Error.NO_ERROR);\n }\n\n /*** Policy Hooks ***/\n\n/**\n * @notice Checks if the account should be allowed to mint tokens in the given market\n * @param cToken The market to verify the mintagainst\n * @param minter The account which would get the minted tokens\n * @param mintAmount The amount of underlying being supplied tothe market in exchange for tokens\n * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)\n */\nfunction mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint) {\n minter; // currently unused\nmintAmount; // currently unused\n\n if (!markets[cToken].isListed) {\n return uint(Error.MARKET_NOT_LISTED);\n }\n\n// *may include Policy Hook-type checks\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates mint and revertson rejection. May emit logs.\n * @param cToken Asset being minted\n * @param minter The address minting the tokens\n * @parammintAmount The amount of the underlying asset being minted\n * @param mintTokens The number of tokens being minted\n */\n functionmintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) external {\n cToken; // currently unused\n minter;// currently unused\n mintAmount; // currently unused\n mintTokens; // currently unused\n\n if (false) {\nmaxAssets = maxAssets; // not pure\n }\n }\n\n /**\n * @notice Checks if the account should be allowed to redeem tokens in thegiven market\n * @param cToken The market to verify the redeem against\n * @param redeemer The account which would redeem the tokens\n* @param redeemTokens The number of cTokens to exchange for the underlying asset in the market\n * @return 0 if the redeem is allowed,otherwise a semi-opaque error code (See ErrorReporter.sol)\n */\n function redeemAllowed(address cToken, address redeemer, uint redeemTokens) external returns (uint) {\n return redeemAllowedInternal(cToken, redeemer, redeemTokens);\n }\n\n function redeemAllowedInternal(address cToken, address redeemer, uint redeemTokens) internal view returns (uint) {\n if (!markets[cToken].isListed) {\n returnuint(Error.MARKET_NOT_LISTED);\n }\n\n // *may include Policy Hook-type checks\n\n /* If the redeemer is not \u0027in\u0027the market, then we can bypass the liquidity check */\n if (!markets[cToken].accountMembership[redeemer]) {\n return uint(Error.NO_ERROR);\n }\n\n /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */\n (Error err, , uintshortfall) = getHypotheticalAccountLiquidityInternal(redeemer, CToken(cToken), redeemTokens, 0);\n if (err != Error.NO_ERROR) {\nreturn uint(err);\n }\n if (shortfall \u003e 0) {\n return uint(Error.INSUFFICIENT_LIQUIDITY);\n }\n\nreturn uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates redeem and reverts on rejection. May emit logs.\n * @param cTokenAsset being redeemed\n * @param redeemer The address redeeming the tokens\n * @param redeemAmount The amount of the underlying asset beingredeemed\n * @param redeemTokens The number of tokens being redeemed\n */\n function redeemVerify(address cToken, address redeemer, uintredeemAmount, uint redeemTokens) external {\n cToken; // currently unused\n redeemer; // currently unused\nredeemAmount; // currently unused\n redeemTokens; // currently unused\n\n // Require tokens is zero or amount is also zero\nif (redeemTokens == 0 \u0026\u0026 redeemAmount \u003e 0) {\n revert(\"redeemTokens zero\");\n }\n }\n\n /**\n *@notice Checks if the account should be allowed to borrow the underlying asset of the given market\n * @param cToken The market to verify theborrow against\n * @param borrower The account which would borrow the asset\n * @param borrowAmount The amount of underlying the accountwould borrow\n * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)\n */\n functionborrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint) {\n if (!markets[cToken].isListed) {\nreturn uint(Error.MARKET_NOT_LISTED);\n }\n\n // *may include Policy Hook-type checks\n\n if (!markets[cToken].accountMembership[borrower]) {\n return uint(Error.MARKET_NOT_ENTERED);\n }\n\n if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) {\n return uint(Error.PRICE_ERROR);\n }\n\n (Error err, , uint shortfall) =getHypotheticalAccountLiquidityInternal(borrower, CToken(cToken), 0, borrowAmount);\n if (err != Error.NO_ERROR) {\n return uint(err);\n }\n if (shortfall \u003e 0) {\n return uint(Error.INSUFFICIENT_LIQUIDITY);\n }\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates borrow and reverts on rejection. May emit logs.\n * @param cToken Asset whoseunderlying is being borrowed\n * @param borrower The address borrowing the underlying\n * @param borrowAmount The amount of the underlyingasset requested to borrow\n */\n function borrowVerify(address cToken, address borrower, uint borrowAmount) external {\n cToken;// currently unused\n borrower; // currently unused\n borrowAmount; // currently unused\n\n if (false) {\nmaxAssets = maxAssets; // not pure\n }\n }\n\n /**\n * @notice Checks if the account should be allowed to repay a borrow inthe given market\n * @param cToken The market to verify the repay against\n * @param payer The account which would repay the asset\n *@param borrower The account which would borrowed the asset\n * @param repayAmount The amount of the underlying asset the account would repay\n* @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol)\n */\n function repayBorrowAllowed(\naddress cToken,\n address payer,\n address borrower,\n uint repayAmount) external returns (uint) {\n payer;// currently unused\n borrower; // currently unused\n repayAmount; // currently unused\n\n if (!markets[cToken].isListed) {\n return uint(Error.MARKET_NOT_LISTED);\n }\n\n // *may include Policy Hook-type checks\n\n returnuint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates repayBorrow and reverts on rejection. May emit logs.\n * @param cToken Assetbeing repaid\n * @param payer The address repaying the borrow\n * @param borrower The address of the borrower\n * @param repayAmountThe amount of underlying being repaid\n */\n function repayBorrowVerify(\n address cToken,\n address payer,\n addressborrower,\n uint repayAmount,\n uint borrowerIndex) external {\n cToken; // currently unused\n payer; //currently unused\n borrower; // currently unused\n repayAmount; // currently unused\n borrowerIndex; // currentlyunused\n\n if (false) {\n maxAssets = maxAssets; // not pure\n }\n }\n\n /**\n * @notice Checks if theliquidation should be allowed to occur\n * @param cTokenBorrowed Asset which was borrowed by the borrower\n * @param cTokenCollateral Assetwhich was used as collateral and will be seized\n * @param liquidator The address repaying the borrow and seizing the collateral\n * @paramborrower The address of the borrower\n * @param repayAmount The amount of underlying being repaid\n */\n function liquidateBorrowAllowed(\n address cTokenBorrowed,\n address cTokenCollateral,\n address liquidator,\n address borrower,\n uintrepayAmount) external returns (uint) {\n liquidator; // currently unused\n borrower; // currently unused\n repayAmount;// currently unused\n\n if (!markets[cTokenBorrowed].isListed || !markets[cTokenCollateral].isListed) {\n return uint(Error.MARKET_NOT_LISTED);\n }\n\n // *may include Policy Hook-type checks\n\n /* The borrower must have shortfall in order to beliquidatable */\n (Error err, , uint shortfall) = getAccountLiquidityInternal(borrower);\n if (err != Error.NO_ERROR) {\nreturn uint(err);\n }\n if (shortfall == 0) {\n return uint(Error.INSUFFICIENT_SHORTFALL);\n }\n\n /* Theliquidator may not repay more than what is allowed by the closeFactor */\n uint borrowBalance = CToken(cTokenBorrowed).borrowBalanceStored(borrower);\n (MathError mathErr, uint maxClose) = mulScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance);\n if(mathErr != MathError.NO_ERROR) {\n return uint(Error.MATH_ERROR);\n }\n if (repayAmount \u003e maxClose) {\nreturn uint(Error.TOO_MUCH_REPAY);\n }\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates liquidateBorrowand reverts on rejection. May emit logs.\n * @param cTokenBorrowed Asset which was borrowed by the borrower\n * @param cTokenCollateralAsset which was used as collateral and will be seized\n * @param liquidator The address repaying the borrow and seizing the collateral\n *@param borrower The address of the borrower\n * @param repayAmount The amount of underlying being repaid\n */\n functionliquidateBorrowVerify(\n address cTokenBorrowed,\n address cTokenCollateral,\n address liquidator,\n address borrower,\n uint repayAmount,\n uint seizeTokens) external {\n cTokenBorrowed; // currently unused\n cTokenCollateral; //currently unused\n liquidator; // currently unused\n borrower; // currently unused\n repayAmount; //currently unused\n seizeTokens; // currently unused\n\n if (false) {\n maxAssets = maxAssets; // not pure\n}\n }\n\n /**\n * @notice Checks if the seizing of assets should be allowed to occur\n * @param cTokenCollateral Asset which was usedas collateral and will be seized\n * @param cTokenBorrowed Asset which was borrowed by the borrower\n * @param liquidator The addressrepaying the borrow and seizing the collateral\n * @param borrower The address of the borrower\n * @param seizeTokens The number ofcollateral tokens to seize\n */\n function seizeAllowed(\n address cTokenCollateral,\n address cTokenBorrowed,\naddress liquidator,\n address borrower,\n uint seizeTokens) external returns (uint) {\n liquidator; // currentlyunused\n borrower; // currently unused\n seizeTokens; // currently unused\n\n if (!markets[cTokenCollateral].isListed || !markets[cTokenBorrowed].isListed) {\n return uint(Error.MARKET_NOT_LISTED);\n }\n\n if (CToken(cTokenCollateral).comptroller() != CToken(cTokenBorrowed).comptroller()) {\n return uint(Error.COMPTROLLER_MISMATCH);\n }\n\n// *may include Policy Hook-type checks\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Validates seize and revertson rejection. May emit logs.\n * @param cTokenCollateral Asset which was used as collateral and will be seized\n * @param cTokenBorrowedAsset which was borrowed by the borrower\n * @param liquidator The address repaying the borrow and seizing the collateral\n * @paramborrower The address of the borrower\n * @param seizeTokens The number of collateral tokens to seize\n */\n function seizeVerify(\naddress cTokenCollateral,\n address cTokenBorrowed,\n address liquidator,\n address borrower,\n uint seizeTokens)external {\n cTokenCollateral; // currently unused\n cTokenBorrowed; // currently unused\n liquidator; // currentlyunused\n borrower; // currently unused\n seizeTokens; // currently unused\n\n if (false) {\n maxAssets= maxAssets; // not pure\n }\n }\n\n /**\n * @notice Checks if the account should be allowed to transfer tokens in the givenmarket\n * @param cToken The market to verify the transfer against\n * @param src The account which sources the tokens\n * @param dstThe account which receives the tokens\n * @param transferTokens The number of cTokens to transfer\n * @return 0 if the transfer is allowed,otherwise a semi-opaque error code (See ErrorReporter.sol)\n */\n function transferAllowed(address cToken, address src, address dst, uinttransferTokens) external returns (uint) {\n cToken; // currently unused\n src; // currently unused\n dst;// currently unused\n transferTokens; // currently unused\n\n // *may include Policy Hook-type checks\n\n //Currently the only consideration is whether or not\n // the src is allowed to redeem this many tokens\n return redeemAllowedInternal(cToken, src, transferTokens);\n }\n\n /**\n * @notice Validates transfer and reverts on rejection. May emit logs.\n * @param cTokenAsset being transferred\n * @param src The account which sources the tokens\n * @param dst The account which receives the tokens\n *@param transferTokens The number of cTokens to transfer\n */\n function transferVerify(address cToken, address src, address dst, uinttransferTokens) external {\n cToken; // currently unused\n src; // currently unused\n dst; //currently unused\n transferTokens; // currently unused\n\n if (false) {\n maxAssets = maxAssets; // not pure\n }\n}\n\n /*** Liquidity/Liquidation Calculations ***/\n\n /**\n * @dev Local vars for avoiding stack-depth limits in calculating accountliquidity.\n * Note that `cTokenBalance` is the number of cTokens the account owns in the market,\n * whereas `borrowBalance` is theamount of underlying that the account has borrowed.\n */\n struct AccountLiquidityLocalVars {\n uint sumCollateral;\n uintsumBorrowPlusEffects;\n uint cTokenBalance;\n uint borrowBalance;\n uint exchangeRateMantissa;\n uintoraclePriceMantissa;\n Exp collateralFactor;\n Exp exchangeRate;\n Exp oraclePrice;\n Exp tokensToEther;\n }\n\n/**\n * @notice Determine the current account liquidity wrt collateral requirements\n * @return (possible error code (semi-opaque),\naccount liquidity in excess of collateral requirements,\n * account shortfall below collateral requirements)\n */\nfunction getAccountLiquidity(address account) public view returns (uint, uint, uint) {\n (Error err, uint liquidity, uint shortfall) =getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0);\n\n return (uint(err), liquidity, shortfall);\n }\n\n /**\n *@notice Determine the current account liquidity wrt collateral requirements\n * @return (possible error code,\n accountliquidity in excess of collateral requirements,\n * account shortfall below collateral requirements)\n */\n functiongetAccountLiquidityInternal(address account) internal view returns (Error, uint, uint) {\n return getHypotheticalAccountLiquidityInternal(account, CToken(0), 0, 0);\n }\n\n /**\n * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed\n * @param cTokenModify The market to hypothetically redeem/borrow in\n * @param account The account to determine liquidity for\n* @param redeemTokens The number of tokens to hypothetically redeem\n * @param borrowAmount The amount of underlying to hypotheticallyborrow\n * @dev Note that we calculate the exchangeRateStored for each collateral cToken using stored data,\n * without calculatingaccumulated interest.\n * @return (possible error code,\n hypothetical account liquidity in excess of collateral requirements,\n* hypothetical account shortfall below collateral requirements)\n */\n function getHypotheticalAccountLiquidityInternal(\naddress account,\n CToken cTokenModify,\n uint redeemTokens,\n uint borrowAmount) internal view returns (Error, uint, uint){\n\n AccountLiquidityLocalVars memory vars; // Holds all our calculation results\n uint oErr;\n MathError mErr;\n\n //For each asset the account is in\n CToken[] memory assets = accountAssets[account];\n for (uint i = 0; i \u003c assets.length; i++){\n CToken asset = assets[i];\n\n // Read the balances and exchange rate from the cToken\n (oErr, vars.cTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot(account);\n if (oErr != 0) { // semi-opaqueerror code, we assume NO_ERROR == 0 is invariant between upgrades\n return (Error.SNAPSHOT_ERROR, 0, 0);\n }\nvars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa});\n vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa});\n\n // Get the normalized price of the asset\n vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset);\n if (vars.oraclePriceMantissa == 0) {\n return (Error.PRICE_ERROR, 0, 0);\n }\n vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa});\n\n // Pre-compute a conversion factor from tokens -\u003e ether (normalizedprice value)\n (mErr, vars.tokensToEther) = mulExp3(vars.collateralFactor, vars.exchangeRate, vars.oraclePrice);\n if (mErr != MathError.NO_ERROR) {\n return (Error.MATH_ERROR, 0, 0);\n }\n\n // sumCollateral += tokensToEther *cTokenBalance\n (mErr, vars.sumCollateral) = mulScalarTruncateAddUInt(vars.tokensToEther, vars.cTokenBalance, vars.sumCollateral);\nif (mErr != MathError.NO_ERROR) {\n return (Error.MATH_ERROR, 0, 0);\n }\n\n // sumBorrowPlusEffects+= oraclePrice * borrowBalance\n (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects);\n if (mErr != MathError.NO_ERROR) {\n return (Error.MATH_ERROR, 0, 0);\n }\n\n// Calculate effects of interacting with cTokenModify\n if (asset == cTokenModify) {\n // redeem effect\n// sumBorrowPlusEffects += tokensToEther * redeemTokens\n (mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.tokensToEther, redeemTokens, vars.sumBorrowPlusEffects);\n if (mErr != MathError.NO_ERROR) {\n return (Error.MATH_ERROR, 0, 0);\n }\n\n // borrow effect\n // sumBorrowPlusEffects += oraclePrice * borrowAmount\n(mErr, vars.sumBorrowPlusEffects) = mulScalarTruncateAddUInt(vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects);\nif (mErr != MathError.NO_ERROR) {\n return (Error.MATH_ERROR, 0, 0);\n }\n }\n }\n\n// These are safe, as the underflow condition is checked first\n if (vars.sumCollateral \u003e vars.sumBorrowPlusEffects) {\nreturn (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0);\n } else {\n return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral);\n }\n }\n\n /**\n * @notice Calculate number of tokens of collateral asset to seizegiven an underlying amount\n * @dev Used in liquidation (called in cToken.liquidateBorrowFresh)\n * @param cTokenBorrowed The address ofthe borrowed cToken\n * @param cTokenCollateral The address of the collateral cToken\n * @param repayAmount The amount of cTokenBorrowedunderlying to convert into cTokenCollateral tokens\n * @return (errorCode, number of cTokenCollateral tokens to be seized in a liquidation)\n*/\n function liquidateCalculateSeizeTokens(address cTokenBorrowed, address cTokenCollateral, uint repayAmount) external view returns (uint,uint) {\n /* Read oracle prices for borrowed and collateral markets */\n uint priceBorrowedMantissa = oracle.getUnderlyingPrice(CToken(cTokenBorrowed));\n uint priceCollateralMantissa = oracle.getUnderlyingPrice(CToken(cTokenCollateral));\n if(priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) {\n return (uint(Error.PRICE_ERROR), 0);\n }\n\n /*\n* Get the exchange rate and calculate the number of collateral tokens to seize:\n * seizeAmount = repayAmount * liquidationIncentive *priceBorrowed / priceCollateral\n * seizeTokens = seizeAmount / exchangeRate\n * = repayAmount * (liquidationIncentive *priceBorrowed) / (priceCollateral * exchangeRate)\n */\n uint exchangeRateMantissa = CToken(cTokenCollateral).exchangeRateStored();// Note: reverts on error\n uint seizeTokens;\n Exp memory numerator;\n Exp memory denominator;\n Exp memory ratio;\nMathError mathErr;\n\n (mathErr, numerator) = mulExp(liquidationIncentiveMantissa, priceBorrowedMantissa);\n if (mathErr !=MathError.NO_ERROR) {\n return (uint(Error.MATH_ERROR), 0);\n }\n\n (mathErr, denominator) = mulExp(priceCollateralMantissa, exchangeRateMantissa);\n if (mathErr != MathError.NO_ERROR) {\n return (uint(Error.MATH_ERROR), 0);\n}\n\n (mathErr, ratio) = divExp(numerator, denominator);\n if (mathErr != MathError.NO_ERROR) {\n return (uint(Error.MATH_ERROR), 0);\n }\n\n (mathErr, seizeTokens) = mulScalarTruncate(ratio, repayAmount);\n if (mathErr != MathError.NO_ERROR){\n return (uint(Error.MATH_ERROR), 0);\n }\n\n return (uint(Error.NO_ERROR), seizeTokens);\n }\n\n /*** AdminFunctions ***/\n\n /**\n * @notice Sets a new price oracle for the comptroller\n * @dev Admin function to set a new price oracle\n* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _setPriceOracle(PriceOracle newOracle)public returns (uint) {\n // Check caller is admin OR currently initialzing as new unitroller implementation\n if(!adminOrInitializing()) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK);\n }\n\n // Trackthe old oracle for the comptroller\n PriceOracle oldOracle = oracle;\n\n // Ensure invoke newOracle.isPriceOracle() returns true\n// require(newOracle.isPriceOracle(), \"oracle method isPriceOracle returned false\");\n\n // Set comptroller\u0027s oracle tonewOracle\n oracle = newOracle;\n\n // Emit NewPriceOracle(oldOracle, newOracle)\n emit NewPriceOracle(oldOracle, newOracle);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sets the closeFactor used when liquidating borrows\n * @devAdmin function to set closeFactor\n * @param newCloseFactorMantissa New close factor, scaled by 1e18\n * @return uint 0=success,otherwise a failure. (See ErrorReporter for details)\n */\n function _setCloseFactor(uint newCloseFactorMantissa) external returns (uint256) {\n // Check caller is admin OR currently initialzing as new unitroller implementation\n if (!adminOrInitializing()) {\nreturn fail(Error.UNAUTHORIZED, FailureInfo.SET_CLOSE_FACTOR_OWNER_CHECK);\n }\n\n Exp memory newCloseFactorExp = Exp({mantissa:newCloseFactorMantissa});\n Exp memory lowLimit = Exp({mantissa: closeFactorMinMantissa});\n if (lessThanOrEqualExp(newCloseFactorExp, lowLimit)) {\n return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION);\n }\n\n Exp memoryhighLimit = Exp({mantissa: closeFactorMaxMantissa});\n if (lessThanExp(highLimit, newCloseFactorExp)) {\n return fail(Error.INVALID_CLOSE_FACTOR, FailureInfo.SET_CLOSE_FACTOR_VALIDATION);\n }\n\n uint oldCloseFactorMantissa = closeFactorMantissa;\ncloseFactorMantissa = newCloseFactorMantissa;\n emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sets the collateralFactor for a market\n * @dev Admin function to set per-marketcollateralFactor\n * @param cToken The market to set the factor on\n * @param newCollateralFactorMantissa The new collateral factor,scaled by 1e18\n * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)\n */\n function _setCollateralFactor(CToken cToken, uint newCollateralFactorMantissa) external returns (uint256) {\n // Check caller is admin\n if (msg.sender != admin){\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_COLLATERAL_FACTOR_OWNER_CHECK);\n }\n\n // Verify market is listed\nMarket storage market = markets[address(cToken)];\n if (!market.isListed) {\n return fail(Error.MARKET_NOT_LISTED,FailureInfo.SET_COLLATERAL_FACTOR_NO_EXISTS);\n }\n\n Exp memory newCollateralFactorExp = Exp({mantissa: newCollateralFactorMantissa});\n\n // Check collateral factor \u003c= 0.9\n Exp memory highLimit = Exp({mantissa: collateralFactorMaxMantissa});\n if(lessThanExp(highLimit, newCollateralFactorExp)) {\n return fail(Error.INVALID_COLLATERAL_FACTOR, FailureInfo.SET_COLLATERAL_FACTOR_VALIDATION);\n }\n\n // If collateral factor != 0, fail if price == 0\n if (newCollateralFactorMantissa!= 0 \u0026\u0026 oracle.getUnderlyingPrice(cToken) == 0) {\n return fail(Error.PRICE_ERROR, FailureInfo.SET_COLLATERAL_FACTOR_WITHOUT_PRICE);\n }\n\n // Set market\u0027s collateral factor to new collateral factor, remember old value\nuint oldCollateralFactorMantissa = market.collateralFactorMantissa;\n market.collateralFactorMantissa = newCollateralFactorMantissa;\n\n // Emit event with asset, old collateral factor, and new collateral factor\n emit NewCollateralFactor(cToken,oldCollateralFactorMantissa, newCollateralFactorMantissa);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice SetsmaxAssets which controls how many markets can be entered\n * @dev Admin function to set maxAssets\n * @param newMaxAssets New maxassets\n * @return uint 0=success, otherwise a failure. (See ErrorReporter for details)\n */\n function _setMaxAssets(uintnewMaxAssets) external returns (uint) {\n // Check caller is admin OR currently initialzing as new unitroller implementation\n if(!adminOrInitializing()) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_MAX_ASSETS_OWNER_CHECK);\n }\n\n uintoldMaxAssets = maxAssets;\n maxAssets = newMaxAssets;\n emit NewMaxAssets(oldMaxAssets, newMaxAssets);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sets liquidationIncentive\n * @dev Admin function to set liquidationIncentive\n * @paramnewLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18\n * @return uint 0=success, otherwise a failure. (See ErrorReporterfor details)\n */\n function _setLiquidationIncentive(uint newLiquidationIncentiveMantissa) external returns (uint) {\n // Checkcaller is admin OR currently initialzing as new unitroller implementation\n if (!adminOrInitializing()) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK);\n }\n\n // Check de-scaled 1 \u003c= newLiquidationDiscount \u003c= 1.5\n Exp memory newLiquidationIncentive = Exp({mantissa: newLiquidationIncentiveMantissa});\n Exp memory minLiquidationIncentive =Exp({mantissa: liquidationIncentiveMinMantissa});\n if (lessThanExp(newLiquidationIncentive, minLiquidationIncentive)) {\n returnfail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION);\n }\n\n Exp memorymaxLiquidationIncentive = Exp({mantissa: liquidationIncentiveMaxMantissa});\n if (lessThanExp(maxLiquidationIncentive,newLiquidationIncentive)) {\n return fail(Error.INVALID_LIQUIDATION_INCENTIVE, FailureInfo.SET_LIQUIDATION_INCENTIVE_VALIDATION);\n}\n\n // Save current value for use in log\n uint oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa;\n\n //Set liquidation incentive to new incentive\n liquidationIncentiveMantissa = newLiquidationIncentiveMantissa;\n\n // Emit event withold incentive, new incentive\n emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa);\n\nreturn uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Add the market to the markets mapping and set it as listed\n * @dev Adminfunction to set isListed and add support for the market\n * @param cToken The address of the market (token) to list\n * @return uint 0=success, otherwise a failure. (See enum Error for details)\n */\n function _supportMarket(CToken cToken) external returns (uint) {\nif (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SUPPORT_MARKET_OWNER_CHECK);\n }\n\n if(markets[address(cToken)].isListed) {\n return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS);\n }\n\ncToken.isCToken(); // Sanity check to make sure its really a CToken\n\n markets[address(cToken)] = Market({isListed: true,collateralFactorMantissa: 0});\n emit MarketListed(cToken);\n\n return uint(Error.NO_ERROR);\n }\n\n function _become(Unitroller unitroller, PriceOracle _oracle, uint _closeFactorMantissa, uint _maxAssets, bool reinitializing) public {\n require(msg.sender== unitroller.admin(), \"only unitroller admin can change brains\");\n uint changeStatus = unitroller._acceptImplementation();\n\nrequire(changeStatus == 0, \"change not authorized\");\n\n if (!reinitializing) {\n Comptroller freshBrainedComptroller =Comptroller(address(unitroller));\n\n // Ensure invoke _setPriceOracle() = 0\n uint err = freshBrainedComptroller._setPriceOracle(_oracle);\n require (err == uint(Error.NO_ERROR), \"set price oracle error\");\n\n // Ensure invoke_setCloseFactor() = 0\n err = freshBrainedComptroller._setCloseFactor(_closeFactorMantissa);\n require (err == uint(Error.NO_ERROR), \"set close factor error\");\n\n // Ensure invoke _setMaxAssets() = 0\n err = freshBrainedComptroller._setMaxAssets(_maxAssets);\n require (err == uint(Error.NO_ERROR), \"set max asssets error\");\n\n // Ensure invoke_setLiquidationIncentive(liquidationIncentiveMinMantissa) = 0\n err = freshBrainedComptroller._setLiquidationIncentive(liquidationIncentiveMinMantissa);\n require (err == uint(Error.NO_ERROR), \"set liquidation incentive error\");\n }\n }\n\n/**\n * @dev Check that caller is admin or this contract is initializing itself as\n * the new implementation.\n * There should be noway to satisfy msg.sender == comptrollerImplementaiton\n * without tx.origin also being admin, but both are included for extra safety\n*/\n function adminOrInitializing() internal view returns (bool) {\n bool initializing = (\n msg.sender ==comptrollerImplementation\n \u0026\u0026\n //solium-disable-next-line security/no-tx-origin\n tx.origin == admin\n );\n bool isAdmin = msg.sender == admin;\n return isAdmin || initializing;\n }\n}\n"},"ComptrollerInterface.sol":{"content":"pragma solidity ^0.5.8;\n\ninterface ComptrollerInterface {\n /**\n * @notice Marker function usedfor light validation when updating the comptroller of a market\n * @dev Implementations should simply return true.\n * @return true\n*/\n function isComptroller() external view returns (bool);\n\n /*** Assets You Are In ***/\n\n function enterMarkets(address[] calldatacTokens) external returns (uint[] memory);\n function exitMarket(address cToken) external returns (uint);\n\n /*** Policy Hooks ***/\n\nfunction mintAllowed(address cToken, address minter, uint mintAmount) external returns (uint);\n function mintVerify(address cToken, addressminter, uint mintAmount, uint mintTokens) external;\n\n function redeemAllowed(address cToken, address redeemer, uint redeemTokens) externalreturns (uint);\n function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) external;\n\n functionborrowAllowed(address cToken, address borrower, uint borrowAmount) external returns (uint);\n function borrowVerify(address cToken, addressborrower, uint borrowAmount) external;\n\n function repayBorrowAllowed(\n address cToken,\n address payer,\n addressborrower,\n uint repayAmount) external returns (uint);\n function repayBorrowVerify(\n address cToken,\n address payer,\naddress borrower,\n uint repayAmount,\n uint borrowerIndex) external;\n\n function liquidateBorrowAllowed(\n addresscTokenBorrowed,\n address cTokenCollateral,\n address liquidator,\n address borrower,\n uint repayAmount) externalreturns (uint);\n function liquidateBorrowVerify(\n address cTokenBorrowed,\n address cTokenCollateral,\n addressliquidator,\n address borrower,\n uint repayAmount,\n uint seizeTokens) external;\n\n function seizeAllowed(\naddress cTokenCollateral,\n address cTokenBorrowed,\n address liquidator,\n address borrower,\n uint seizeTokens)external returns (uint);\n function seizeVerify(\n address cTokenCollateral,\n address cTokenBorrowed,\n address liquidator,\n address borrower,\n uint seizeTokens) external;\n\n function transferAllowed(address cToken, address src, address dst, uinttransferTokens) external returns (uint);\n function transferVerify(address cToken, address src, address dst, uint transferTokens) external;\n\n/*** Liquidity/Liquidation Calculations ***/\n\n function liquidateCalculateSeizeTokens(\n address cTokenBorrowed,\n addresscTokenCollateral,\n uint repayAmount) external view returns (uint, uint);\n}\n"},"ComptrollerStorage.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CToken.sol\";\nimport \"./PriceOracle.sol\";\n\ncontract UnitrollerAdminStorage {\n /**\n * @notice Administrator for thiscontract\n */\n address public admin;\n\n /**\n * @notice Pending administrator for this contract\n */\n address publicpendingAdmin;\n\n /**\n * @notice Active brains of Unitroller\n */\n address public comptrollerImplementation;\n\n /**\n *@notice Pending brains of Unitroller\n */\n address public pendingComptrollerImplementation;\n}\n\ncontract ComptrollerV1Storage isUnitrollerAdminStorage {\n\n /**\n * @notice Oracle which gives the price of any given asset\n */\n PriceOracle public oracle;\n\n/**\n * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow\n */\n uint public closeFactorMantissa;\n\n /**\n * @notice Multiplier representing the discount on collateral that a liquidator receives\n */\n uint publicliquidationIncentiveMantissa;\n\n /**\n * @notice Max number of assets a single account can participate in (borrow or use as collateral)\n*/\n uint public maxAssets;\n\n /**\n * @notice Per-account mapping of \"assets you are in\", capped by maxAssets\n */\nmapping(address =\u003e CToken[]) public accountAssets;\n\n}\n"},"CToken.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./ComptrollerInterface.sol\";\nimport \"./ErrorReporter.sol\";\nimport \"./Exponential.sol\";\nimport \"./EIP20Interface.sol\";\nimport \"./EIP20NonStandardInterface.sol\";\nimport \"./ReentrancyGuard.sol\";\nimport \"./InterestRateModel.sol\";\n\n/**\n * @title Compound\u0027s CTokenContract\n * @notice Abstract base for CTokens\n * @author Compound\n */\ncontract CToken is EIP20Interface, Exponential, TokenErrorReporter,ReentrancyGuard {\n /**\n * @notice Indicator that this is a CToken contract (for inspection)\n */\n bool public constant isCToken =true;\n\n /**\n * @notice EIP-20 token name for this token\n */\n string public name;\n\n /**\n * @notice EIP-20 token symbolfor this token\n */\n string public symbol;\n\n /**\n * @notice EIP-20 token decimals for this token\n */\n uint publicdecimals;\n\n /**\n * @notice Maximum borrow rate that can ever be applied (.0005% / block)\n */\n uint constantborrowRateMaxMantissa = 5e14;\n\n /**\n * @notice Maximum fraction of interest that can be set aside for reserves\n */\n uintconstant reserveFactorMaxMantissa = 1e18;\n\n /**\n * @notice Administrator for this contract\n */\n address payable public admin;\n\n /**\n * @notice Pending administrator for this contract\n */\n address payable public pendingAdmin;\n\n /**\n * @noticeContract which oversees inter-cToken operations\n */\n ComptrollerInterface public comptroller;\n\n /**\n * @notice Model which tellswhat the current interest rate should be\n */\n InterestRateModel public interestRateModel;\n\n /**\n * @notice Initial exchange rateused when minting the first CTokens (used when totalSupply = 0)\n */\n uint public initialExchangeRateMantissa;\n\n /**\n * @noticeFraction of interest currently set aside for reserves\n */\n uint public reserveFactorMantissa;\n\n /**\n * @notice Block number thatinterest was last accrued at\n */\n uint public accrualBlockNumber;\n\n /**\n * @notice Accumulator of total earned interest sincethe opening of the market\n */\n uint public borrowIndex;\n\n /**\n * @notice Total amount of outstanding borrows of the underlyingin this market\n */\n uint public totalBorrows;\n\n /**\n * @notice Total amount of reserves of the underlying held in this market\n*/\n uint public totalReserves;\n\n /**\n * @notice Total number of tokens in circulation\n */\n uint256 public totalSupply;\n\n /**\n * @notice Official record of token balances for each account\n */\n mapping (address =\u003e uint256) accountTokens;\n\n/**\n * @notice Approved token transfer amounts on behalf of others\n */\n mapping (address =\u003e mapping (address =\u003e uint256)) transferAllowances;\n\n /**\n * @notice Container for borrow balance information\n * @member principal Total balance (with accruedinterest), after applying the most recent balance-changing action\n * @member interestIndex Global borrowIndex as of the most recent balance-changing action\n */\n struct BorrowSnapshot {\n uint principal;\n uint interestIndex;\n }\n\n /**\n * @noticeMapping of account addresses to outstanding borrow balances\n */\n mapping(address =\u003e BorrowSnapshot) accountBorrows;\n\n\n /***Market Events ***/\n\n /**\n * @notice Event emitted when interest is accrued\n */\n event AccrueInterest(uint interestAccumulated,uint borrowIndex, uint totalBorrows);\n\n /**\n * @notice Event emitted when tokens are minted\n */\n event Mint(address minter, uintmintAmount, uint mintTokens);\n\n /**\n * @notice Event emitted when tokens are redeemed\n */\n event Redeem(address redeemer, uintredeemAmount, uint redeemTokens);\n\n /**\n * @notice Event emitted when underlying is borrowed\n */\n event Borrow(address borrower,uint borrowAmount, uint accountBorrows, uint totalBorrows);\n\n /**\n * @notice Event emitted when a borrow is repaid\n */\n eventRepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);\n\n /**\n * @notice Event emittedwhen a borrow is liquidated\n */\n event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral,uint seizeTokens);\n\n\n /*** Admin Events ***/\n\n /**\n * @notice Event emitted when pendingAdmin is changed\n */\n eventNewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);\n\n /**\n * @notice Event emitted when pendingAdmin is accepted, whichmeans admin is updated\n */\n event NewAdmin(address oldAdmin, address newAdmin);\n\n /**\n * @notice Event emitted when comptrolleris changed\n */\n event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller);\n\n /**\n * @noticeEvent emitted when interestRateModel is changed\n */\n event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel,InterestRateModel newInterestRateModel);\n\n /**\n * @notice Event emitted when the reserve factor is changed\n */\n eventNewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);\n\n /**\n * @notice Event emitted when the reserves arereduced\n */\n event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);\n\n\n /**\n * @notice Construct a newmoney market\n * @param comptroller_ The address of the Comptroller\n * @param interestRateModel_ The address of the interest rate model\n* @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18\n * @param name_ EIP-20 name of this token\n * @paramsymbol_ EIP-20 symbol of this token\n * @param decimals_ EIP-20 decimal precision of this token\n */\n constructor(ComptrollerInterfacecomptroller_,\n InterestRateModel interestRateModel_,\n uint initialExchangeRateMantissa_,\n stringmemory name_,\n string memory symbol_,\n uint decimals_) internal {\n // Set admin to msg.sender\nadmin = msg.sender;\n\n // Set initial exchange rate\n initialExchangeRateMantissa = initialExchangeRateMantissa_;\n require(initialExchangeRateMantissa \u003e 0, \"Initial exchange rate must be greater than zero.\");\n\n // Set the comptroller\n uint err =_setComptroller(comptroller_);\n require(err == uint(Error.NO_ERROR), \"Setting comptroller failed\");\n\n // Initialize block numberand borrow index (block number mocks depend on comptroller being set)\n accrualBlockNumber = getBlockNumber();\n borrowIndex =mantissaOne;\n\n // Set the interest rate model (depends on block number / borrow index)\n err = _setInterestRateModelFresh(interestRateModel_);\n require(err == uint(Error.NO_ERROR), \"Setting interest rate model failed\");\n\n name = name_;\nsymbol = symbol_;\n decimals = decimals_;\n }\n\n /**\n * @notice Transfer `tokens` tokens from `src` to `dst` by `spender`\n* @dev Called by both `transfer` and `transferFrom` internally\n * @param spender The address of the account performing the transfer\n *@param src The address of the source account\n * @param dst The address of the destination account\n * @param tokens The number of tokensto transfer\n * @return Whether or not the transfer succeeded\n */\n function transferTokens(address spender, address src, address dst,uint tokens) internal returns (uint) {\n /* Fail if transfer not allowed */\n uint allowed = comptroller.transferAllowed(address(this), src, dst, tokens);\n if (allowed != 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed);\n }\n\n /* Do not allow self-transfers */\n if (src == dst) {\n returnfail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED);\n }\n\n /* Get the allowance, infinite for the account owner */\nuint startingAllowance = 0;\n if (spender == src) {\n startingAllowance = uint(-1);\n } else {\nstartingAllowance = transferAllowances[src][spender];\n }\n\n /* Do the calculations, checking for {under,over}flow */\nMathError mathErr;\n uint allowanceNew;\n uint srcTokensNew;\n uint dstTokensNew;\n\n (mathErr, allowanceNew) = subUInt(startingAllowance, tokens);\n if (mathErr != MathError.NO_ERROR) {\n return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED);\n }\n\n (mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens);\n if (mathErr != MathError.NO_ERROR) {\n return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH);\n }\n\n (mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens);\n if (mathErr != MathError.NO_ERROR) {\n return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH);\n }\n\n /////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failures beyondthis point)\n\n accountTokens[src] = srcTokensNew;\n accountTokens[dst] = dstTokensNew;\n\n /* Eat some of the allowance (ifnecessary) */\n if (startingAllowance != uint(-1)) {\n transferAllowances[src][spender] = allowanceNew;\n }\n\n /*We emit a Transfer event */\n emit Transfer(src, dst, tokens);\n\n /* We call the defense hook (which checks for under-collateralization) */\n comptroller.transferVerify(address(this), src, dst, tokens);\n\n return uint(Error.NO_ERROR);\n }\n\n/**\n * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n * @param dst The address of the destination account\n * @paramamount The number of tokens to transfer\n * @return Whether or not the transfer succeeded\n */\n function transfer(address dst, uint256amount) external nonReentrant returns (bool) {\n return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR);\n}\n\n /**\n * @notice Transfer `amount` tokens from `src` to `dst`\n * @param src The address of the source account\n * @param dstThe address of the destination account\n * @param amount The number of tokens to transfer\n * @return Whether or not the transfersucceeded\n */\n function transferFrom(address src, address dst, uint256 amount) external nonReentrant returns (bool) {\n returntransferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Approve `spender` to transfer up to`amount` from `src`\n * @dev This will overwrite the approval amount for `spender`\n * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n * @param spender The address of the account which may transfer tokens\n * @param amount The number oftokens that are approved (-1 means infinite)\n * @return Whether or not the approval succeeded\n */\n function approve(address spender,uint256 amount) external returns (bool) {\n address src = msg.sender;\n transferAllowances[src][spender] = amount;\n emitApproval(src, spender, amount);\n return true;\n }\n\n /**\n * @notice Get the current allowance from `owner` for `spender`\n* @param owner The address of the account which owns the tokens to be spent\n * @param spender The address of the account which may transfertokens\n * @return The number of tokens allowed to be spent (-1 means infinite)\n */\n function allowance(address owner, address spender) external view returns (uint256) {\n return transferAllowances[owner][spender];\n }\n\n /**\n * @notice Get the token balance ofthe `owner`\n * @param owner The address of the account to query\n * @return The number of tokens owned by `owner`\n */\n functionbalanceOf(address owner) external view returns (uint256) {\n return accountTokens[owner];\n }\n\n /**\n * @notice Get theunderlying balance of the `owner`\n * @dev This also accrues interest in a transaction\n * @param owner The address of the account toquery\n * @return The amount of underlying owned by `owner`\n */\n function balanceOfUnderlying(address owner) external returns (uint){\n Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()});\n (MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]);\n require(mErr == MathError.NO_ERROR);\n return balance;\n }\n\n /**\n * @notice Geta snapshot of the account\u0027s balances, and the cached exchange rate\n * @dev This is used by comptroller to more efficiently performliquidity checks.\n * @param account Address of the account to snapshot\n * @return (possible error, token balance, borrow balance,exchange rate mantissa)\n */\n function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint) {\n uintcTokenBalance = accountTokens[account];\n uint borrowBalance;\n uint exchangeRateMantissa;\n\n MathError mErr;\n\n(mErr, borrowBalance) = borrowBalanceStoredInternal(account);\n if (mErr != MathError.NO_ERROR) {\n return (uint(Error.MATH_ERROR), 0, 0, 0);\n }\n\n (mErr, exchangeRateMantissa) = exchangeRateStoredInternal();\n if (mErr != MathError.NO_ERROR) {\nreturn (uint(Error.MATH_ERROR), 0, 0, 0);\n }\n\n return (uint(Error.NO_ERROR), cTokenBalance, borrowBalance,exchangeRateMantissa);\n }\n\n /**\n * @dev Function to simply retrieve block number\n * This exists mainly for inheriting testcontracts to stub this result.\n */\n function getBlockNumber() internal view returns (uint) {\n return block.number;\n }\n\n/**\n * @notice Returns the current per-block borrow interest rate for this cToken\n * @return The borrow interest rate per block, scaledby 1e18\n */\n function borrowRatePerBlock() external view returns (uint) {\n (uint opaqueErr, uint borrowRateMantissa) =interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);\n require(opaqueErr == 0, \"borrowRatePerBlock:interestRateModel.borrowRate failed\"); // semi-opaque\n return borrowRateMantissa;\n }\n\n /**\n * @notice Returns the currentper-block supply interest rate for this cToken\n * @return The supply interest rate per block, scaled by 1e18\n */\n functionsupplyRatePerBlock() external view returns (uint) {\n /* We calculate the supply rate:\n * underlying = totalSupply ×exchangeRate\n * borrowsPer = totalBorrows ÷ underlying\n * supplyRate = borrowRate × (1-reserveFactor) × borrowsPer\n*/\n uint exchangeRateMantissa = exchangeRateStored();\n\n (uint e0, uint borrowRateMantissa) = interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);\n require(e0 == 0, \"supplyRatePerBlock: calculating borrowRate failed\"); // semi-opaque\n\n(MathError e1, Exp memory underlying) = mulScalar(Exp({mantissa: exchangeRateMantissa}), totalSupply);\n require(e1 == MathError.NO_ERROR, \"supplyRatePerBlock: calculating underlying failed\");\n\n (MathError e2, Exp memory borrowsPer) = divScalarByExp(totalBorrows,underlying);\n require(e2 == MathError.NO_ERROR, \"supplyRatePerBlock: calculating borrowsPer failed\");\n\n (MathError e3, Expmemory oneMinusReserveFactor) = subExp(Exp({mantissa: mantissaOne}), Exp({mantissa: reserveFactorMantissa}));\n require(e3 == MathError.NO_ERROR, \"supplyRatePerBlock: calculating oneMinusReserveFactor failed\");\n\n (MathError e4, Exp memory supplyRate) = mulExp3(Exp({mantissa: borrowRateMantissa}), oneMinusReserveFactor, borrowsPer);\n require(e4 == MathError.NO_ERROR, \"supplyRatePerBlock: calculatingsupplyRate failed\");\n\n return supplyRate.mantissa;\n }\n\n /**\n * @notice Returns the current total borrows plus accruedinterest\n * @return The total borrows with interest\n */\n function totalBorrowsCurrent() external nonReentrant returns (uint) {\nrequire(accrueInterest() == uint(Error.NO_ERROR), \"accrue interest failed\");\n return totalBorrows;\n }\n\n /**\n * @noticeAccrue interest to updated borrowIndex and then calculate account\u0027s borrow balance using the updated borrowIndex\n * @param account Theaddress whose balance should be calculated after updating borrowIndex\n * @return The calculated balance\n */\n functionborrowBalanceCurrent(address account) external nonReentrant returns (uint) {\n require(accrueInterest() == uint(Error.NO_ERROR), \"accrueinterest failed\");\n return borrowBalanceStored(account);\n }\n\n /**\n * @notice Return the borrow balance of account based onstored data\n * @param account The address whose balance should be calculated\n * @return The calculated balance\n */\n functionborrowBalanceStored(address account) public view returns (uint) {\n (MathError err, uint result) = borrowBalanceStoredInternal(account);\nrequire(err == MathError.NO_ERROR, \"borrowBalanceStored: borrowBalanceStoredInternal failed\");\n return result;\n }\n\n /**\n* @notice Return the borrow balance of account based on stored data\n * @param account The address whose balance should be calculated\n* @return (error code, the calculated balance or 0 if error code is non-zero)\n */\n function borrowBalanceStoredInternal(address account)internal view returns (MathError, uint) {\n /* Note: we do not assert that the market is up to date */\n MathError mathErr;\nuint principalTimesIndex;\n uint result;\n\n /* Get borrowBalance and borrowIndex */\n BorrowSnapshot storage borrowSnapshot =accountBorrows[account];\n\n /* If borrowBalance = 0 then borrowIndex is likely also 0.\n * Rather than failing the calculation witha division by 0, we immediately return 0 in this case.\n */\n if (borrowSnapshot.principal == 0) {\n return (MathError.NO_ERROR, 0);\n }\n\n /* Calculate new borrow balance using the interest index:\n * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex\n */\n (mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal,borrowIndex);\n if (mathErr != MathError.NO_ERROR) {\n return (mathErr, 0);\n }\n\n (mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex);\n if (mathErr != MathError.NO_ERROR) {\n return (mathErr, 0);\n }\n\nreturn (MathError.NO_ERROR, result);\n }\n\n /**\n * @notice Accrue interest then return the up-to-date exchange rate\n *@return Calculated exchange rate scaled by 1e18\n */\n function exchangeRateCurrent() public nonReentrant returns (uint) {\n require(accrueInterest() == uint(Error.NO_ERROR), \"accrue interest failed\");\n return exchangeRateStored();\n }\n\n /**\n * @noticeCalculates the exchange rate from the underlying to the CToken\n * @dev This function does not accrue interest before calculating the exchangerate\n * @return Calculated exchange rate scaled by 1e18\n */\n function exchangeRateStored() public view returns (uint) {\n(MathError err, uint result) = exchangeRateStoredInternal();\n require(err == MathError.NO_ERROR, \"exchangeRateStored:exchangeRateStoredInternal failed\");\n return result;\n }\n\n /**\n * @notice Calculates the exchange rate from the underlying tothe CToken\n * @dev This function does not accrue interest before calculating the exchange rate\n * @return (error code, calculatedexchange rate scaled by 1e18)\n */\n function exchangeRateStoredInternal() internal view returns (MathError, uint) {\n if(totalSupply == 0) {\n /*\n * If there are no tokens minted:\n * exchangeRate = initialExchangeRate\n*/\n return (MathError.NO_ERROR, initialExchangeRateMantissa);\n } else {\n /*\n * Otherwise:\n* exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply\n */\n uint totalCash = getCashPrior();\nuint cashPlusBorrowsMinusReserves;\n Exp memory exchangeRate;\n MathError mathErr;\n\n (mathErr,cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, totalReserves);\n if (mathErr != MathError.NO_ERROR) {\nreturn (mathErr, 0);\n }\n\n (mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, totalSupply);\nif (mathErr != MathError.NO_ERROR) {\n return (mathErr, 0);\n }\n\n return (MathError.NO_ERROR, exchangeRate.mantissa);\n }\n }\n\n /**\n * @notice Get cash balance of this cToken in the underlying asset\n * @return The quantity ofunderlying asset owned by this contract\n */\n function getCash() external view returns (uint) {\n return getCashPrior();\n }\n\nstruct AccrueInterestLocalVars {\n MathError mathErr;\n uint opaqueErr;\n uint borrowRateMantissa;\n uintcurrentBlockNumber;\n uint blockDelta;\n\n Exp simpleInterestFactor;\n\n uint interestAccumulated;\n uinttotalBorrowsNew;\n uint totalReservesNew;\n uint borrowIndexNew;\n }\n\n /**\n * @notice Applies accrued interest to totalborrows and reserves.\n * @dev This calculates interest accrued from the last checkpointed block\n * up to the current block andwrites new checkpoint to storage.\n */\n function accrueInterest() public returns (uint) {\n AccrueInterestLocalVars memory vars;\n\n /* Calculate the current borrow interest rate */\n (vars.opaqueErr, vars.borrowRateMantissa) = interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);\n require(vars.borrowRateMantissa \u003c= borrowRateMaxMantissa, \"borrow rate is absurdlyhigh\");\n if (vars.opaqueErr != 0) {\n return failOpaque(Error.INTEREST_RATE_MODEL_ERROR, FailureInfo.ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, vars.opaqueErr);\n }\n\n /* Remember the initial block number */\n vars.currentBlockNumber = getBlockNumber();\n\n /* Calculate the number of blocks elapsed since the last accrual */\n (vars.mathErr, vars.blockDelta) = subUInt(vars.currentBlockNumber, accrualBlockNumber);\n assert(vars.mathErr == MathError.NO_ERROR); // Block delta shouldalways succeed and if it doesn\u0027t, blow up.\n\n /*\n * Calculate the interest accumulated into borrows and reserves and the newindex:\n * simpleInterestFactor = borrowRate * blockDelta\n * interestAccumulated = simpleInterestFactor * totalBorrows\n* totalBorrowsNew = interestAccumulated + totalBorrows\n * totalReservesNew = interestAccumulated * reserveFactor + totalReserves\n* borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex\n */\n (vars.mathErr, vars.simpleInterestFactor) =mulScalar(Exp({mantissa: vars.borrowRateMantissa}), vars.blockDelta);\n if (vars.mathErr != MathError.NO_ERROR) {\n returnfailOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n(vars.mathErr, vars.interestAccumulated) = mulScalarTruncate(vars.simpleInterestFactor, totalBorrows);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.totalBorrowsNew) = addUInt(vars.interestAccumulated, totalBorrows);\n if (vars.mathErr!= MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.totalReservesNew) = mulScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}),vars.interestAccumulated, totalReserves);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR,FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.borrowIndexNew) =mulScalarTruncateAddUInt(vars.simpleInterestFactor, borrowIndex, borrowIndex);\n if (vars.mathErr != MathError.NO_ERROR) {\nreturn failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n/////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failures beyond this point)\n\n /* We write thepreviously calculated values into storage */\n accrualBlockNumber = vars.currentBlockNumber;\n borrowIndex = vars.borrowIndexNew;\ntotalBorrows = vars.totalBorrowsNew;\n totalReserves = vars.totalReservesNew;\n\n /* We emit an AccrueInterest event */\nemit AccrueInterest(vars.interestAccumulated, vars.borrowIndexNew, totalBorrows);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n* @notice Sender supplies assets into the market and receives cTokens in exchange\n * @dev Accrues interest whether or not the operationsucceeds, unless reverted\n * @param mintAmount The amount of the underlying asset to supply\n * @return uint 0=success, otherwise afailure (see ErrorReporter.sol for details)\n */\n function mintInternal(uint mintAmount) internal nonReentrant returns (uint) {\nuint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors, but we still wantto log the fact that an attempted borrow failed\n return fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED);\n }\n// mintFresh emits the actual Mint event if successful and logs on errors, so we don\u0027t need to\n return mintFresh(msg.sender,mintAmount);\n }\n\n struct MintLocalVars {\n Error err;\n MathError mathErr;\n uint exchangeRateMantissa;\n uintmintTokens;\n uint totalSupplyNew;\n uint accountTokensNew;\n }\n\n /**\n * @notice User supplies assets into the marketand receives cTokens in exchange\n * @dev Assumes interest has already been accrued up to the current block\n * @param minter The addressof the account which is supplying the assets\n * @param mintAmount The amount of the underlying asset to supply\n * @return uint 0=success,otherwise a failure (see ErrorReporter.sol for details)\n */\n function mintFresh(address minter, uint mintAmount) internal returns (uint){\n /* Fail if mint not allowed */\n uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount);\n if (allowed!= 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed);\n }\n\n /*Verify market\u0027s block number equals current block number */\n if (accrualBlockNumber != getBlockNumber()) {\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK);\n }\n\n MintLocalVars memory vars;\n\n /* Fail if checkTransferInfails */\n vars.err = checkTransferIn(minter, mintAmount);\n if (vars.err != Error.NO_ERROR) {\n return fail(vars.err,FailureInfo.MINT_TRANSFER_IN_NOT_POSSIBLE);\n }\n\n /*\n * We get the current exchange rate and calculate the number ofcTokens to be minted:\n * mintTokens = mintAmount / exchangeRate\n */\n (vars.mathErr, vars.exchangeRateMantissa) =exchangeRateStoredInternal();\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.mintTokens) = divScalarByExpTruncate(mintAmount,Exp({mantissa: vars.exchangeRateMantissa}));\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR,FailureInfo.MINT_EXCHANGE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n /*\n * We calculate the new total supply ofcTokens and minter token balance, checking for overflow:\n * totalSupplyNew = totalSupply + mintTokens\n * accountTokensNew =accountTokens[minter] + mintTokens\n */\n (vars.mathErr, vars.totalSupplyNew) = addUInt(totalSupply, vars.mintTokens);\n if(vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.accountTokensNew) = addUInt(accountTokens[minter], vars.mintTokens);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n /////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failures beyond thispoint)\n\n /*\n * We call doTransferIn for the minter and the mintAmount\n * Note: The cToken must handle variationsbetween ERC-20 and ETH underlying.\n * On success, the cToken holds an additional mintAmount of cash.\n * If doTransferIn failsdespite the fact we checked pre-conditions,\n * we revert because we can\u0027t be sure if side effects occurred.\n */\nvars.err = doTransferIn(minter, mintAmount);\n if (vars.err != Error.NO_ERROR) {\n return fail(vars.err, FailureInfo.MINT_TRANSFER_IN_FAILED);\n }\n\n /* We write previously calculated values into storage */\n totalSupply = vars.totalSupplyNew;\n accountTokens[minter] = vars.accountTokensNew;\n\n /* We emit a Mint event, and a Transfer event */\n emitMint(minter, mintAmount, vars.mintTokens);\n emit Transfer(address(this), minter, vars.mintTokens);\n\n /* We call the defense hook*/\n comptroller.mintVerify(address(this), minter, mintAmount, vars.mintTokens);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n* @notice Sender redeems cTokens in exchange for the underlying asset\n * @dev Accrues interest whether or not the operation succeeds,unless reverted\n * @param redeemTokens The number of cTokens to redeem into underlying\n * @return uint 0=success, otherwise a failure(see ErrorReporter.sol for details)\n */\n function redeemInternal(uint redeemTokens) internal nonReentrant returns (uint) {\n uinterror = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors, but we still want tolog the fact that an attempted redeem failed\n return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED);\n }\n// redeemFresh emits redeem-specific logs on errors, so we don\u0027t need to\n return redeemFresh(msg.sender, redeemTokens, 0);\n }\n\n/**\n * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset\n * @dev Accrues interest whether or notthe operation succeeds, unless reverted\n * @param redeemAmount The amount of underlying to redeem\n * @return uint 0=success, otherwise afailure (see ErrorReporter.sol for details)\n */\n function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant returns (uint){\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors, but westill want to log the fact that an attempted redeem failed\n return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED);\n}\n // redeemFresh emits redeem-specific logs on errors, so we don\u0027t need to\n return redeemFresh(msg.sender, 0,redeemAmount);\n }\n\n struct RedeemLocalVars {\n Error err;\n MathError mathErr;\n uint exchangeRateMantissa;\nuint redeemTokens;\n uint redeemAmount;\n uint totalSupplyNew;\n uint accountTokensNew;\n }\n\n /**\n * @notice Userredeems cTokens in exchange for the underlying asset\n * @dev Assumes interest has already been accrued up to the current block\n * @paramredeemer The address of the account which is redeeming the tokens\n * @param redeemTokensIn The number of cTokens to redeem into underlying(only one of redeemTokensIn or redeemAmountIn may be zero)\n * @param redeemAmountIn The number of cTokens to redeem into underlying (only oneof redeemTokensIn or redeemAmountIn may be zero)\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\nfunction redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal returns (uint) {\n require(redeemTokensIn == 0 || redeemAmountIn == 0, \"one of redeemTokensIn or redeemAmountIn must be zero\");\n\n RedeemLocalVars memory vars;\n\n/* exchangeRate = invoke Exchange Rate Stored() */\n (vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal();\nif (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr));\n }\n\n /* If redeemTokensIn \u003e 0: */\n if (redeemTokensIn \u003e 0) {\n /*\n * Wecalculate the exchange rate and the amount of underlying to be redeemed:\n * redeemTokens = redeemTokensIn\n *redeemAmount = redeemTokensIn x exchangeRateCurrent\n */\n vars.redeemTokens = redeemTokensIn;\n\n (vars.mathErr,vars.redeemAmount) = mulScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), redeemTokensIn);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint(vars.mathErr));\n}\n } else {\n /*\n * We get the current exchange rate and calculate the amount to be redeemed:\n* redeemTokens = redeemAmountIn / exchangeRate\n * redeemAmount = redeemAmountIn\n */\n\n (vars.mathErr, vars.redeemTokens) = divScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa}));\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, uint(vars.mathErr));\n}\n\n vars.redeemAmount = redeemAmountIn;\n }\n\n /* Fail if redeem not allowed */\n uint allowed =comptroller.redeemAllowed(address(this), redeemer, vars.redeemTokens);\n if (allowed != 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REDEEM_COMPTROLLER_REJECTION, allowed);\n }\n\n /* Verify market\u0027s block number equalscurrent block number */\n if (accrualBlockNumber != getBlockNumber()) {\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK);\n }\n\n /*\n * We calculate the new total supply and redeemer balance, checking for underflow:\n* totalSupplyNew = totalSupply - redeemTokens\n * accountTokensNew = accountTokens[redeemer] - redeemTokens\n */\n(vars.mathErr, vars.totalSupplyNew) = subUInt(totalSupply, vars.redeemTokens);\n if (vars.mathErr != MathError.NO_ERROR) {\nreturn failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.accountTokensNew) = subUInt(accountTokens[redeemer], vars.redeemTokens);\n if (vars.mathErr != MathError.NO_ERROR) {\nreturn failOpaque(Error.MATH_ERROR, FailureInfo.REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n /*Fail gracefully if protocol has insufficient cash */\n if (getCashPrior() \u003c vars.redeemAmount) {\n return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE);\n }\n\n /////////////////////////\n // EFFECTS \u0026INTERACTIONS\n // (No safe failures beyond this point)\n\n /*\n * We invoke doTransferOut for the redeemer and theredeemAmount.\n * Note: The cToken must handle variations between ERC-20 and ETH underlying.\n * On success, the cToken hasredeemAmount less of cash.\n * If doTransferOut fails despite the fact we checked pre-conditions,\n * we revert because wecan\u0027t be sure if side effects occurred.\n */\n vars.err = doTransferOut(redeemer, vars.redeemAmount);\n require(vars.err== Error.NO_ERROR, \"redeem transfer out failed\");\n\n /* We write previously calculated values into storage */\n totalSupply = vars.totalSupplyNew;\n accountTokens[redeemer] = vars.accountTokensNew;\n\n /* We emit a Transfer event, and a Redeem event */\nemit Transfer(redeemer, address(this), vars.redeemTokens);\n emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens);\n\n /* Wecall the defense hook */\n comptroller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sender borrows assets from the protocol to their own address\n * @param borrowAmount Theamount of the underlying asset to borrow\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\nfunction borrowInternal(uint borrowAmount) internal nonReentrant returns (uint) {\n uint error = accrueInterest();\n if (error !=uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed\nreturn fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED);\n }\n // borrowFresh emits borrow-specific logs onerrors, so we don\u0027t need to\n return borrowFresh(msg.sender, borrowAmount);\n }\n\n struct BorrowLocalVars {\n Error err;\n MathError mathErr;\n uint accountBorrows;\n uint accountBorrowsNew;\n uint totalBorrowsNew;\n }\n\n /**\n* @notice Users borrow assets from the protocol to their own address\n * @param borrowAmount The amount of the underlying asset to borrow\n* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function borrowFresh(address payable borrower, uint borrowAmount) internal returns (uint) {\n /* Fail if borrow not allowed */\n uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount);\n if (allowed != 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed);\n }\n\n /* Verify market\u0027s block number equals current block number */\n if(accrualBlockNumber != getBlockNumber()) {\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK);\n }\n\n/* Fail gracefully if protocol has insufficient underlying cash */\n if (getCashPrior() \u003c borrowAmount) {\n return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE);\n }\n\n BorrowLocalVars memory vars;\n\n /*\n* We calculate the new borrower and total borrow balances, failing on overflow:\n * accountBorrowsNew = accountBorrows + borrowAmount\n* totalBorrowsNew = totalBorrows + borrowAmount\n */\n (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.accountBorrowsNew) = addUInt(vars.accountBorrows, borrowAmount);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.totalBorrowsNew) = addUInt(totalBorrows, borrowAmount);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n /////////////////////////\n // EFFECTS \u0026INTERACTIONS\n // (No safe failures beyond this point)\n\n /*\n * We invoke doTransferOut for the borrower and theborrowAmount.\n * Note: The cToken must handle variations between ERC-20 and ETH underlying.\n * On success, the cTokenborrowAmount less of cash.\n * If doTransferOut fails despite the fact we checked pre-conditions,\n * we revert because wecan\u0027t be sure if side effects occurred.\n */\n vars.err = doTransferOut(borrower, borrowAmount);\n require(vars.err ==Error.NO_ERROR, \"borrow transfer out failed\");\n\n /* We write the previously calculated values into storage */\naccountBorrows[borrower].principal = vars.accountBorrowsNew;\n accountBorrows[borrower].interestIndex = borrowIndex;\n totalBorrows =vars.totalBorrowsNew;\n\n /* We emit a Borrow event */\n emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew);\n\n /* We call the defense hook */\n comptroller.borrowVerify(address(this), borrower, borrowAmount);\n\nreturn uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sender repays their own borrow\n * @param repayAmount The amount to repay\n* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function repayBorrowInternal(uint repayAmount)internal nonReentrant returns (uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n //accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed\n return fail(Error(error),FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED);\n }\n // repayBorrowFresh emits repay-borrow-specific logs on errors, so wedon\u0027t need to\n return repayBorrowFresh(msg.sender, msg.sender, repayAmount);\n }\n\n /**\n * @notice Sender repays a borrowbelonging to borrower\n * @param borrower the account with the debt being payed off\n * @param repayAmount The amount to repay\n *@return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function repayBorrowBehalfInternal(address borrower,uint repayAmount) internal nonReentrant returns (uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n// accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed\n return fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED);\n }\n // repayBorrowFresh emits repay-borrow-specific logs on errors, sowe don\u0027t need to\n return repayBorrowFresh(msg.sender, borrower, repayAmount);\n }\n\n struct RepayBorrowLocalVars {\nError err;\n MathError mathErr;\n uint repayAmount;\n uint borrowerIndex;\n uint accountBorrows;\n uintaccountBorrowsNew;\n uint totalBorrowsNew;\n }\n\n /**\n * @notice Borrows are repaid by another user (possibly the borrower).\n* @param payer the account paying off the borrow\n * @param borrower the account with the debt being payed off\n * @param repayAmountthe amount of undelrying tokens being returned\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\nfunction repayBorrowFresh(address payer, address borrower, uint repayAmount) internal returns (uint) {\n /* Fail if repayBorrow notallowed */\n uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount);\n if (allowed != 0) {\nreturn failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed);\n }\n\n /* Verifymarket\u0027s block number equals current block number */\n if (accrualBlockNumber != getBlockNumber()) {\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK);\n }\n\n RepayBorrowLocalVars memory vars;\n\n /* We remember theoriginal borrowerIndex for verification purposes */\n vars.borrowerIndex = accountBorrows[borrower].interestIndex;\n\n /* We fetchthe amount the borrower owes, with accumulated interest */\n (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal(borrower);\nif (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n /* If repayAmount == -1, repayAmount =accountBorrows */\n if (repayAmount == uint(-1)) {\n vars.repayAmount = vars.accountBorrows;\n } else {\n vars.repayAmount = repayAmount;\n }\n\n /* Fail if checkTransferIn fails */\n vars.err = checkTransferIn(payer, vars.repayAmount);\n if (vars.err != Error.NO_ERROR) {\n return fail(vars.err, FailureInfo.REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE);\n }\n\n/*\n * We calculate the new borrower and total borrow balances, failing on underflow:\n * accountBorrowsNew =accountBorrows - repayAmount\n * totalBorrowsNew = totalBorrows - repayAmount\n */\n (vars.mathErr, vars.accountBorrowsNew)= subUInt(vars.accountBorrows, vars.repayAmount);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n (vars.mathErr, vars.totalBorrowsNew) = subUInt(totalBorrows, vars.repayAmount);\n if (vars.mathErr != MathError.NO_ERROR) {\n return failOpaque(Error.MATH_ERROR, FailureInfo.REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint(vars.mathErr));\n }\n\n/////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failures beyond this point)\n\n /*\n * Wecall doTransferIn for the payer and the repayAmount\n * Note: The cToken must handle variations between ERC-20 and ETH underlying.\n* On success, the cToken holds an additional repayAmount of cash.\n * If doTransferIn fails despite the fact we checked pre-conditions,\n * we revert because we can\u0027t be sure if side effects occurred.\n */\n vars.err = doTransferIn(payer, vars.repayAmount);\n require(vars.err == Error.NO_ERROR, \"repay borrow transfer in failed\");\n\n /* We write the previously calculatedvalues into storage */\n accountBorrows[borrower].principal = vars.accountBorrowsNew;\n accountBorrows[borrower].interestIndex =borrowIndex;\n totalBorrows = vars.totalBorrowsNew;\n\n /* We emit a RepayBorrow event */\n emit RepayBorrow(payer, borrower,vars.repayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew);\n\n /* We call the defense hook */\n comptroller.repayBorrowVerify(address(this), payer, borrower, vars.repayAmount, vars.borrowerIndex);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @noticeThe sender liquidates the borrowers collateral.\n * The collateral seized is transferred to the liquidator.\n * @param borrower Theborrower of this cToken to be liquidated\n * @param cTokenCollateral The market in which to seize collateral from the borrower\n * @paramrepayAmount The amount of the underlying borrowed asset to repay\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol fordetails)\n */\n function liquidateBorrowInternal(address borrower, uint repayAmount, CToken cTokenCollateral) internal nonReentrant returns(uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors,but we still want to log the fact that an attempted liquidation failed\n return fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED);\n }\n\n error = cTokenCollateral.accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed\nreturn fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED);\n }\n\n // liquidateBorrowFresh emits borrow-specific logs on errors, so we don\u0027t need to\n return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral);\n}\n\n /**\n * @notice The liquidator liquidates the borrowers collateral.\n * The collateral seized is transferred to the liquidator.\n* @param borrower The borrower of this cToken to be liquidated\n * @param liquidator The address repaying the borrow and seizingcollateral\n * @param cTokenCollateral The market in which to seize collateral from the borrower\n * @param repayAmount The amount of theunderlying borrowed asset to repay\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n functionliquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CToken cTokenCollateral) internal returns (uint) {\n /* Fail ifliquidate not allowed */\n uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower,repayAmount);\n if (allowed != 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION,allowed);\n }\n\n /* Verify market\u0027s block number equals current block number */\n if (accrualBlockNumber !=getBlockNumber()) {\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK);\n }\n\n /* VerifycTokenCollateral market\u0027s block number equals current block number */\n if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()){\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK);\n }\n\n /* Fail if borrower =liquidator */\n if (borrower == liquidator) {\n return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER);\n }\n\n /* Fail if repayAmount = 0 */\n if (repayAmount == 0) {\n return fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO);\n }\n\n /* Fail if repayAmount = -1 */\nif (repayAmount == uint(-1)) {\n return fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX);\n}\n\n /* We calculate the number of collateral tokens that will be seized */\n (uint amountSeizeError, uint seizeTokens) =comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), repayAmount);\n if (amountSeizeError != 0) {\nreturn failOpaque(Error.COMPTROLLER_CALCULATION_ERROR, FailureInfo.LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED, amountSeizeError);\n}\n\n /* Fail if seizeTokens \u003e borrower collateral token balance */\n if (seizeTokens \u003e cTokenCollateral.balanceOf(borrower)) {\n return fail(Error.TOKEN_INSUFFICIENT_BALANCE, FailureInfo.LIQUIDATE_SEIZE_TOO_MUCH);\n }\n\n /* Fail ifrepayBorrow fails */\n uint repayBorrowError = repayBorrowFresh(liquidator, borrower, repayAmount);\n if (repayBorrowError != uint(Error.NO_ERROR)) {\n return fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED);\n }\n\n /*Revert if seize tokens fails (since we cannot be sure of side effects) */\n uint seizeError = cTokenCollateral.seize(liquidator, borrower,seizeTokens);\n require(seizeError == uint(Error.NO_ERROR), \"token seizure failed\");\n\n /* We emit a LiquidateBorrow event */\nemit LiquidateBorrow(liquidator, borrower, repayAmount, address(cTokenCollateral), seizeTokens);\n\n /* We call the defense hook */\ncomptroller.liquidateBorrowVerify(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount, seizeTokens);\n\nreturn uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Transfers collateral tokens (this market) to the liquidator.\n * @dev Will failunless called by another cToken during the process of liquidation.\n * Its absolutely critical to use msg.sender as the borrowed cToken andnot a parameter.\n * @param liquidator The account receiving seized collateral\n * @param borrower The account having collateral seized\n* @param seizeTokens The number of cTokens to seize\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n*/\n function seize(address liquidator, address borrower, uint seizeTokens) external nonReentrant returns (uint) {\n /* Fail if seizenot allowed */\n uint allowed = comptroller.seizeAllowed(address(this), msg.sender, liquidator, borrower, seizeTokens);\n if (allowed!= 0) {\n return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed);\n }\n\n/* Fail if borrower = liquidator */\n if (borrower == liquidator) {\n return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER);\n }\n\n MathError mathErr;\n uint borrowerTokensNew;\n uintliquidatorTokensNew;\n\n /*\n * We calculate the new borrower and liquidator token balances, failing on underflow/overflow:\n* borrowerTokensNew = accountTokens[borrower] - seizeTokens\n * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens\n*/\n (mathErr, borrowerTokensNew) = subUInt(accountTokens[borrower], seizeTokens);\n if (mathErr != MathError.NO_ERROR) {\nreturn failOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, uint(mathErr));\n }\n\n (mathErr,liquidatorTokensNew) = addUInt(accountTokens[liquidator], seizeTokens);\n if (mathErr != MathError.NO_ERROR) {\n returnfailOpaque(Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, uint(mathErr));\n }\n\n/////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failures beyond this point)\n\n /* We write thepreviously calculated values into storage */\n accountTokens[borrower] = borrowerTokensNew;\n accountTokens[liquidator] =liquidatorTokensNew;\n\n /* Emit a Transfer event */\n emit Transfer(borrower, liquidator, seizeTokens);\n\n /* We call thedefense hook */\n comptroller.seizeVerify(address(this), msg.sender, liquidator, borrower, seizeTokens);\n\n return uint(Error.NO_ERROR);\n }\n\n\n /*** Admin Functions ***/\n\n /**\n * @notice Begins transfer of admin rights. The newPendingAdmin must call`_acceptAdmin` to finalize the transfer.\n * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` tofinalize the transfer.\n * @param newPendingAdmin New pending admin.\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n *\n * TODO: Should we add a second arg to verify, like a checksum of `newAdmin` address?\n */\n function_setPendingAdmin(address payable newPendingAdmin) external returns (uint) {\n // Check caller = admin\n if (msg.sender != admin) {\nreturn fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK);\n }\n\n // Save current value, if any, forinclusion in log\n address oldPendingAdmin = pendingAdmin;\n\n // Store pendingAdmin with value newPendingAdmin\n pendingAdmin= newPendingAdmin;\n\n // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)\n emit NewPendingAdmin(oldPendingAdmin,newPendingAdmin);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Accepts transfer of admin rights. msg.sender must bependingAdmin\n * @dev Admin function for pending admin to accept role and update admin\n * @return uint 0=success, otherwise a failure(see ErrorReporter.sol for details)\n */\n function _acceptAdmin() external returns (uint) {\n // Check caller is pendingAdmin andpendingAdmin ≠ address(0)\n if (msg.sender != pendingAdmin || msg.sender == address(0)) {\n return fail(Error.UNAUTHORIZED,FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK);\n }\n\n // Save current values for inclusion in log\n address oldAdmin = admin;\n address oldPendingAdmin = pendingAdmin;\n\n // Store admin with value pendingAdmin\n admin = pendingAdmin;\n\n //Clear the pending value\n pendingAdmin = address(0);\n\n emit NewAdmin(oldAdmin, admin);\n emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Sets a new comptroller for the market\n* @dev Admin function to set a new comptroller\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n*/\n function _setComptroller(ComptrollerInterface newComptroller) public returns (uint) {\n // Check caller is admin\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_COMPTROLLER_OWNER_CHECK);\n }\n\nComptrollerInterface oldComptroller = comptroller;\n // Ensure invoke comptroller.isComptroller() returns true\n require(newComptroller.isComptroller(), \"marker method returned false\");\n\n // Set market\u0027s comptroller to newComptroller\ncomptroller = newComptroller;\n\n // Emit NewComptroller(oldComptroller, newComptroller)\n emit NewComptroller(oldComptroller,newComptroller);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice accrues interest and sets a new reserve factor for theprotocol using _setReserveFactorFresh\n * @dev Admin function to accrue interest and set a new reserve factor\n * @return uint 0=success,otherwise a failure (see ErrorReporter.sol for details)\n */\n function _setReserveFactor(uint newReserveFactorMantissa) externalnonReentrant returns (uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterestemits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed.\n return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED);\n }\n // _setReserveFactorFresh emits reserve-factor-specific logson errors, so we don\u0027t need to.\n return _setReserveFactorFresh(newReserveFactorMantissa);\n }\n\n /**\n * @notice Sets anew reserve factor for the protocol (*requires fresh interest accrual)\n * @dev Admin function to set a new reserve factor\n * @returnuint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _setReserveFactorFresh(uintnewReserveFactorMantissa) internal returns (uint) {\n // Check caller is admin\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK);\n }\n\n // Verify market\u0027s block number equals current blocknumber\n if (accrualBlockNumber != getBlockNumber()) {\n // TODO: static_assert + no error code?\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK);\n }\n\n // Check newReserveFactor ≤ maxReserveFactor\n if(newReserveFactorMantissa \u003e reserveFactorMaxMantissa) {\n return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK);\n }\n\n uint oldReserveFactorMantissa = reserveFactorMantissa;\n reserveFactorMantissa = newReserveFactorMantissa;\n\nemit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n *@notice Accrues interest and reduces reserves by transferring to admin\n * @param reduceAmount Amount of reduction to reserves\n * @returnuint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _reduceReserves(uint reduceAmount) externalnonReentrant returns (uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n // accrueInterestemits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed.\n return fail(Error(error),FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED);\n }\n // _reduceReservesFresh emits reserve-reduction-specific logs on errors,so we don\u0027t need to.\n return _reduceReservesFresh(reduceAmount);\n }\n\n /**\n * @notice Reduces reserves by transferring toadmin\n * @dev Requires fresh interest accrual\n * @param reduceAmount Amount of reduction to reserves\n * @return uint 0=success,otherwise a failure (see ErrorReporter.sol for details)\n */\n function _reduceReservesFresh(uint reduceAmount) internal returns (uint) {\nError err;\n // totalReserves - reduceAmount\n uint totalReservesNew;\n\n // Check caller is admin\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK);\n }\n\n // We failgracefully unless market\u0027s block number equals current block number\n if (accrualBlockNumber != getBlockNumber()) {\n //TODO: static_assert + no error code?\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK);\n }\n\n// Fail gracefully if protocol has insufficient underlying cash\n if (getCashPrior() \u003c reduceAmount) {\n return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE);\n }\n\n // Check reduceAmount ≤ reserves[n](totalReserves)\n // TODO: I\u0027m following the spec literally here but I think we should we just use SafeMath instead and fail on anerror (which would be underflow)\n if (reduceAmount \u003e totalReserves) {\n return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION);\n }\n\n /////////////////////////\n // EFFECTS \u0026 INTERACTIONS\n // (No safe failuresbeyond this point)\n\n totalReservesNew = totalReserves - reduceAmount;\n // We checked reduceAmount \u003c= totalReserves above, sothis should never revert.\n require(totalReservesNew \u003c= totalReserves, \"reduce reserves unexpected underflow\");\n\n // Storereserves[n+1] = reserves[n] - reduceAmount\n totalReserves = totalReservesNew;\n\n // invoke doTransferOut(reduceAmount, admin)\nerr = doTransferOut(admin, reduceAmount);\n // we revert on the failure of this command\n require(err == Error.NO_ERROR, \"reducereserves transfer out failed\");\n\n emit ReservesReduced(admin, reduceAmount, totalReservesNew);\n\n return uint(Error.NO_ERROR);\n}\n\n /**\n * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh\n * @dev Admin functionto accrue interest and update the interest rate model\n * @param newInterestRateModel the new interest rate model to use\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _setInterestRateModel(InterestRateModelnewInterestRateModel) public returns (uint) {\n uint error = accrueInterest();\n if (error != uint(Error.NO_ERROR)) {\n //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\nreturn fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED);\n }\n // _setInterestRateModelFresh emitsinterest-rate-model-update-specific logs on errors, so we don\u0027t need to.\n return _setInterestRateModelFresh(newInterestRateModel);\n}\n\n /**\n * @notice updates the interest rate model (*requires fresh interest accrual)\n * @dev Admin function to update theinterest rate model\n * @param newInterestRateModel the new interest rate model to use\n * @return uint 0=success, otherwise a failure (seeErrorReporter.sol for details)\n */\n function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint){\n\n // Used to store old model for use in the event that is emitted on success\n InterestRateModel oldInterestRateModel;\n\n// Check caller is admin\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK);\n }\n\n // We fail gracefully unless market\u0027s block number equals current block number\nif (accrualBlockNumber != getBlockNumber()) {\n // TODO: static_assert + no error code?\n return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK);\n }\n\n // Track the market\u0027s current interest rate model\noldInterestRateModel = interestRateModel;\n\n // Ensure invoke newInterestRateModel.isInterestRateModel() returns true\nrequire(newInterestRateModel.isInterestRateModel(), \"marker method returned false\");\n\n // Set the interest rate model tonewInterestRateModel\n interestRateModel = newInterestRateModel;\n\n // Emit NewMarketInterestRateModel(oldInterestRateModel,newInterestRateModel)\n emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel);\n\n return uint(Error.NO_ERROR);\n }\n\n /*** Safe Token ***/\n\n /**\n * @notice Gets balance of this contract in terms of the underlying\n * @dev Thisexcludes the value of the current message, if any\n * @return The quantity of underlying owned by this contract\n */\n functiongetCashPrior() internal view returns (uint);\n\n /**\n * @dev Checks whether or not there is sufficient allowance for this contract to moveamount from `from` and\n * whether or not `from` has a balance of at least `amount`. Does NOT do a transfer.\n */\n functioncheckTransferIn(address from, uint amount) internal view returns (Error);\n\n /**\n * @dev Performs a transfer in, ideally returning anexplanatory error code upon failure rather than reverting.\n * If caller has not called `checkTransferIn`, this may revert due to insufficientbalance or insufficient allowance.\n * If caller has called `checkTransferIn` successfully, this should not revert in normal conditions.\n*/\n function doTransferIn(address from, uint amount) internal returns (Error);\n\n /**\n * @dev Performs a transfer out, ideallyreturning an explanatory error code upon failure tather than reverting.\n * If caller has not called checked protocol\u0027s balance, mayrevert due to insufficient cash held in the contract.\n * If caller has checked protocol\u0027s balance, and verified it is \u003e= amount,this should not revert in normal conditions.\n */\n function doTransferOut(address payable to, uint amount) internal returns (Error);\n}\n"},"EIP20Interface.sol":{"content":"pragma solidity ^0.5.8;\n\n/**\n * @title ERC 20 Token Standard Interface\n * https://eips.ethereum.org/EIPS/eip-20\n */\ninterface EIP20Interface {\n\n /**\n * @notice Get the total number of tokens in circulation\n * @return The supply oftokens\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @notice Gets the balance of the specifiedaddress\n * @param owner The address from which the balance will be retrieved\n * @return The balance\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n *@param dst The address of the destination account\n * @param amount The number of tokens to transfer\n * @return Whether or not thetransfer succeeded\n */\n function transfer(address dst, uint256 amount) external returns (bool success);\n\n /**\n * @noticeTransfer `amount` tokens from `src` to `dst`\n * @param src The address of the source account\n * @param dst The address of thedestination account\n * @param amount The number of tokens to transfer\n * @return Whether or not the transfer succeeded\n */\nfunction transferFrom(address src, address dst, uint256 amount) external returns (bool success);\n\n /**\n * @notice Approve `spender` totransfer up to `amount` from `src`\n * @dev This will overwrite the approval amount for `spender`\n * and is subject to issues noted[here](https://eips.ethereum.org/EIPS/eip-20#approve)\n * @param spender The address of the account which may transfer tokens\n * @paramamount The number of tokens that are approved (-1 means infinite)\n * @return Whether or not the approval succeeded\n */\n functionapprove(address spender, uint256 amount) external returns (bool success);\n\n /**\n * @notice Get the current allowance from `owner` for`spender`\n * @param owner The address of the account which owns the tokens to be spent\n * @param spender The address of the accountwhich may transfer tokens\n * @return The number of tokens allowed to be spent (-1 means infinite)\n */\n function allowance(addressowner, address spender) external view returns (uint256 remaining);\n\n event Transfer(address indexed from, address indexed to, uint256 amount);\n event Approval(address indexed owner, address indexed spender, uint256 amount);\n}\n"},"EIP20NonStandardInterface.sol":{"content":"pragmasolidity ^0.5.8;\n\n/**\n * @title EIP20NonStandardInterface\n * @dev Version of ERC20 with no return values for `transfer` and `transferFrom`\n *See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n */\ninterface EIP20NonStandardInterface{\n\n /**\n * @notice Get the total number of tokens in circulation\n * @return The supply of tokens\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @notice Gets the balance of the specified address\n * @param owner The address fromwhich the balance will be retrieved\n * @return The balance\n */\n function balanceOf(address owner) external view returns (uint256balance);\n\n ///\n /// !!!!!!!!!!!!!!\n /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification\n/// !!!!!!!!!!!!!!\n ///\n\n /**\n * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n * @param dst The address ofthe destination account\n * @param amount The number of tokens to transfer\n */\n function transfer(address dst, uint256 amount)external;\n\n ///\n /// !!!!!!!!!!!!!!\n /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20specification\n /// !!!!!!!!!!!!!!\n ///\n\n /**\n * @notice Transfer `amount` tokens from `src` to `dst`\n * @param src Theaddress of the source account\n * @param dst The address of the destination account\n * @param amount The number of tokens to transfer\n*/\n function transferFrom(address src, address dst, uint256 amount) external;\n\n /**\n * @notice Approve `spender` to transfer upto `amount` from `src`\n * @dev This will overwrite the approval amount for `spender`\n * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n * @param spender The address of the account which may transfer tokens\n * @param amount Thenumber of tokens that are approved\n * @return Whether or not the approval succeeded\n */\n function approve(address spender, uint256amount) external returns (bool success);\n\n /**\n * @notice Get the current allowance from `owner` for `spender`\n * @param owner Theaddress of the account which owns the tokens to be spent\n * @param spender The address of the account which may transfer tokens\n *@return The number of tokens allowed to be spent\n */\n function allowance(address owner, address spender) external view returns (uint256remaining);\n\n event Transfer(address indexed from, address indexed to, uint256 amount);\n event Approval(address indexed owner, addressindexed spender, uint256 amount);\n}\n"},"ErrorReporter.sol":{"content":"pragma solidity ^0.5.8;\n\ncontract ComptrollerErrorReporter {\n enumError {\n NO_ERROR,\n UNAUTHORIZED,\n COMPTROLLER_MISMATCH,\n INSUFFICIENT_SHORTFALL,\n INSUFFICIENT_LIQUIDITY,\n INVALID_CLOSE_FACTOR,\n INVALID_COLLATERAL_FACTOR,\n INVALID_LIQUIDATION_INCENTIVE,\n MARKET_NOT_ENTERED,\nMARKET_NOT_LISTED,\n MARKET_ALREADY_LISTED,\n MATH_ERROR,\n NONZERO_BORROW_BALANCE,\n PRICE_ERROR,\n REJECTION,\n SNAPSHOT_ERROR,\n TOO_MANY_ASSETS,\n TOO_MUCH_REPAY\n }\n\n enum FailureInfo {\nACCEPT_ADMIN_PENDING_ADMIN_CHECK,\n ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,\n EXIT_MARKET_BALANCE_OWED,\nEXIT_MARKET_REJECTION,\n SET_CLOSE_FACTOR_OWNER_CHECK,\n SET_CLOSE_FACTOR_VALIDATION,\n SET_COLLATERAL_FACTOR_OWNER_CHECK,\nSET_COLLATERAL_FACTOR_NO_EXISTS,\n SET_COLLATERAL_FACTOR_VALIDATION,\n SET_COLLATERAL_FACTOR_WITHOUT_PRICE,\nSET_IMPLEMENTATION_OWNER_CHECK,\n SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,\n SET_LIQUIDATION_INCENTIVE_VALIDATION,\nSET_MAX_ASSETS_OWNER_CHECK,\n SET_PENDING_ADMIN_OWNER_CHECK,\n SET_PENDING_IMPLEMENTATION_OWNER_CHECK,\nSET_PRICE_ORACLE_OWNER_CHECK,\n SUPPORT_MARKET_EXISTS,\n SUPPORT_MARKET_OWNER_CHECK,\n ZUNUSED\n }\n\n /**\n * @dev`error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary\n * contract-specific code thatenables us to report opaque error codes from upgradeable contracts.\n **/\n event Failure(uint error, uint info, uint detail);\n\n /**\n* @dev use this when reporting a known error from the money market or a non-upgradeable collaborator\n */\n function fail(Error err,FailureInfo info) internal returns (uint) {\n emit Failure(uint(err), uint(info), 0);\n\n return uint(err);\n }\n\n /**\n* @dev use this when reporting an opaque error from an upgradeable collaborator contract\n */\n function failOpaque(Error err, FailureInfoinfo, uint opaqueError) internal returns (uint) {\n emit Failure(uint(err), uint(info), opaqueError);\n\n return uint(err);\n}\n}\n\ncontract TokenErrorReporter {\n enum Error {\n NO_ERROR,\n UNAUTHORIZED,\n BAD_INPUT,\nCOMPTROLLER_REJECTION,\n COMPTROLLER_CALCULATION_ERROR,\n INTEREST_RATE_MODEL_ERROR,\n INVALID_ACCOUNT_PAIR,\nINVALID_CLOSE_AMOUNT_REQUESTED,\n INVALID_COLLATERAL_FACTOR,\n MATH_ERROR,\n MARKET_NOT_FRESH,\n MARKET_NOT_LISTED,\nTOKEN_INSUFFICIENT_ALLOWANCE,\n TOKEN_INSUFFICIENT_BALANCE,\n TOKEN_INSUFFICIENT_CASH,\n TOKEN_TRANSFER_IN_FAILED,\nTOKEN_TRANSFER_OUT_FAILED\n }\n\n /*\n * Note: FailureInfo (but not Error) is kept in alphabetical order\n * This isbecause FailureInfo grows significantly faster, and\n * the order of Error has some meaning, while the order of FailureInfo\n *is entirely arbitrary.\n */\n enum FailureInfo {\n ACCEPT_ADMIN_PENDING_ADMIN_CHECK,\nACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED,\n ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED,\nACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED,\n ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED,\nACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED,\n ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED,\nBORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,\n BORROW_ACCRUE_INTEREST_FAILED,\n BORROW_CASH_NOT_AVAILABLE,\nBORROW_FRESHNESS_CHECK,\n BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,\n BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,\nBORROW_MARKET_NOT_LISTED,\n BORROW_COMPTROLLER_REJECTION,\n LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,\nLIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,\n LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,\n LIQUIDATE_COMPTROLLER_REJECTION,\nLIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED,\n LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX,\n LIQUIDATE_CLOSE_AMOUNT_IS_ZERO,\nLIQUIDATE_FRESHNESS_CHECK,\n LIQUIDATE_LIQUIDATOR_IS_BORROWER,\n LIQUIDATE_REPAY_BORROW_FRESH_FAILED,\nLIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED,\n LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED,\n LIQUIDATE_SEIZE_COMPTROLLER_REJECTION,\nLIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,\n LIQUIDATE_SEIZE_TOO_MUCH,\n MINT_ACCRUE_INTEREST_FAILED,\nMINT_COMPTROLLER_REJECTION,\n MINT_EXCHANGE_CALCULATION_FAILED,\n MINT_EXCHANGE_RATE_READ_FAILED,\n MINT_FRESHNESS_CHECK,\nMINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,\n MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,\n MINT_TRANSFER_IN_FAILED,\nMINT_TRANSFER_IN_NOT_POSSIBLE,\n REDEEM_ACCRUE_INTEREST_FAILED,\n REDEEM_COMPTROLLER_REJECTION,\nREDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED,\n REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED,\n REDEEM_EXCHANGE_RATE_READ_FAILED,\nREDEEM_FRESHNESS_CHECK,\n REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,\n REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,\nREDEEM_TRANSFER_OUT_NOT_POSSIBLE,\n REDUCE_RESERVES_ACCRUE_INTEREST_FAILED,\n REDUCE_RESERVES_ADMIN_CHECK,\nREDUCE_RESERVES_CASH_NOT_AVAILABLE,\n REDUCE_RESERVES_FRESH_CHECK,\n REDUCE_RESERVES_VALIDATION,\nREPAY_BEHALF_ACCRUE_INTEREST_FAILED,\n REPAY_BORROW_ACCRUE_INTEREST_FAILED,\n REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,\nREPAY_BORROW_COMPTROLLER_REJECTION,\n REPAY_BORROW_FRESHNESS_CHECK,\nREPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,\n REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,\nREPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE,\n SET_COLLATERAL_FACTOR_OWNER_CHECK,\n SET_COLLATERAL_FACTOR_VALIDATION,\nSET_COMPTROLLER_OWNER_CHECK,\n SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,\n SET_INTEREST_RATE_MODEL_FRESH_CHECK,\nSET_INTEREST_RATE_MODEL_OWNER_CHECK,\n SET_MAX_ASSETS_OWNER_CHECK,\n SET_ORACLE_MARKET_NOT_LISTED,\nSET_PENDING_ADMIN_OWNER_CHECK,\n SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED,\n SET_RESERVE_FACTOR_ADMIN_CHECK,\nSET_RESERVE_FACTOR_FRESH_CHECK,\n SET_RESERVE_FACTOR_BOUNDS_CHECK,\n TRANSFER_COMPTROLLER_REJECTION,\n TRANSFER_NOT_ALLOWED,\nTRANSFER_NOT_ENOUGH,\n TRANSFER_TOO_MUCH\n }\n\n /**\n * @dev `error` corresponds to enum Error; `info` corresponds toenum FailureInfo, and `detail` is an arbitrary\n * contract-specific code that enables us to report opaque error codes from upgradeablecontracts.\n **/\n event Failure(uint error, uint info, uint detail);\n\n /**\n * @dev use this when reporting a known error fromthe money market or a non-upgradeable collaborator\n */\n function fail(Error err, FailureInfo info) internal returns (uint) {\nemit Failure(uint(err), uint(info), 0);\n\n return uint(err);\n }\n\n /**\n * @dev use this when reporting an opaque error froman upgradeable collaborator contract\n */\n function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {\nemit Failure(uint(err), uint(info), opaqueError);\n\n return uint(err);\n }\n}\n"},"Exponential.sol":{"content":"pragma solidity^0.5.8;\n\nimport \"./CarefulMath.sol\";\n\n/**\n * @title Exponential module for storing fixed-decision decimals\n * @author Compound\n * @noticeExp is a struct which stores decimals with a fixed precision of 18 decimal places.\n * Thus, if we wanted to store the 5.1, mantissa wouldstore 5.1e18. That is:\n * `Exp({mantissa: 5100000000000000000})`.\n */\ncontract Exponential is CarefulMath {\n uint constant expScale= 1e18;\n uint constant halfExpScale = expScale/2;\n uint constant mantissaOne = expScale;\n\n struct Exp {\n uint mantissa;\n}\n\n /**\n * @dev Creates an exponential from numerator and denominator values.\n * Note: Returns an error if (`num` * 10e18)\u003e MAX_INT,\n * or if `denom` is zero.\n */\n function getExp(uint num, uint denom) pure internal returns (MathError, Expmemory) {\n (MathError err0, uint scaledNumerator) = mulUInt(num, expScale);\n if (err0 != MathError.NO_ERROR) {\n return(err0, Exp({mantissa: 0}));\n }\n\n (MathError err1, uint rational) = divUInt(scaledNumerator, denom);\n if (err1 != MathError.NO_ERROR) {\n return (err1, Exp({mantissa: 0}));\n }\n\n return (MathError.NO_ERROR, Exp({mantissa: rational}));\n}\n\n /**\n * @dev Adds two exponentials, returning a new exponential.\n */\n function addExp(Exp memory a, Exp memory b) pureinternal returns (MathError, Exp memory) {\n (MathError error, uint result) = addUInt(a.mantissa, b.mantissa);\n\n return (error, Exp({mantissa: result}));\n }\n\n /**\n * @dev Subtracts two exponentials, returning a new exponential.\n */\n function subExp(Expmemory a, Exp memory b) pure internal returns (MathError, Exp memory) {\n (MathError error, uint result) = subUInt(a.mantissa, b.mantissa);\n\n return (error, Exp({mantissa: result}));\n }\n\n /**\n * @dev Multiply an Exp by a scalar, returning a new Exp.\n */\nfunction mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {\n (MathError err0, uint scaledMantissa) =mulUInt(a.mantissa, scalar);\n if (err0 != MathError.NO_ERROR) {\n return (err0, Exp({mantissa: 0}));\n }\n\nreturn (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));\n }\n\n /**\n * @dev Multiply an Exp by a scalar, then truncate to returnan unsigned integer.\n */\n function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) {\n(MathError err, Exp memory product) = mulScalar(a, scalar);\n if (err != MathError.NO_ERROR) {\n return (err, 0);\n }\n\nreturn (MathError.NO_ERROR, truncate(product));\n }\n\n /**\n * @dev Multiply an Exp by a scalar, truncate, then add an to anunsigned integer, returning an unsigned integer.\n */\n function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pureinternal returns (MathError, uint) {\n (MathError err, Exp memory product) = mulScalar(a, scalar);\n if (err != MathError.NO_ERROR){\n return (err, 0);\n }\n\n return addUInt(truncate(product), addend);\n }\n\n /**\n * @dev Divide an Exp by ascalar, returning a new Exp.\n */\n function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {\n(MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar);\n if (err0 != MathError.NO_ERROR) {\n return (err0, Exp({mantissa: 0}));\n }\n\n return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));\n }\n\n /**\n * @dev Divide ascalar by an Exp, returning a new Exp.\n */\n function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Expmemory) {\n /*\n We are doing this as:\n getExp(mulUInt(expScale, scalar), divisor.mantissa)\n\n How it works:\nExp = a / b;\n Scalar = s;\n `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`\n */\n(MathError err0, uint numerator) = mulUInt(expScale, scalar);\n if (err0 != MathError.NO_ERROR) {\n return (err0, Exp({mantissa: 0}));\n }\n return getExp(numerator, divisor.mantissa);\n }\n\n /**\n * @dev Divide a scalar by an Exp, thentruncate to return an unsigned integer.\n */\n function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns(MathError, uint) {\n (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);\n if (err != MathError.NO_ERROR) {\nreturn (err, 0);\n }\n\n return (MathError.NO_ERROR, truncate(fraction));\n }\n\n /**\n * @dev Multiplies twoexponentials, returning a new exponential.\n */\n function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory){\n\n (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa);\n if (err0 != MathError.NO_ERROR) {\nreturn (err0, Exp({mantissa: 0}));\n }\n\n // We add half the scale before dividing so that we get rounding instead of truncation.\n// See \"Listing 6\" and text above it at https://accu.org/index.php/journals/1717\n // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.\n (MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct);\n if (err1 != MathError.NO_ERROR) {\n return (err1, Exp({mantissa: 0}));\n }\n\n(MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale);\n // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.\n assert(err2 == MathError.NO_ERROR);\n\n return (MathError.NO_ERROR,Exp({mantissa: product}));\n }\n\n /**\n * @dev Multiplies two exponentials given their mantissas, returning a new exponential.\n*/\n function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) {\n return mulExp(Exp({mantissa: a}), Exp({mantissa:b}));\n }\n\n /**\n * @dev Multiplies three exponentials, returning a new exponential.\n */\n function mulExp3(Exp memory a, Expmemory b, Exp memory c) pure internal returns (MathError, Exp memory) {\n (MathError err, Exp memory ab) = mulExp(a, b);\n if (err !=MathError.NO_ERROR) {\n return (err, ab);\n }\n return mulExp(ab, c);\n }\n\n /**\n * @dev Divides twoexponentials, returning a new exponential.\n * (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,\n * which we can scale as an Expby calling getExp(a.mantissa, b.mantissa)\n */\n function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory){\n return getExp(a.mantissa, b.mantissa);\n }\n\n /**\n * @dev Truncates the given exp to a whole number value.\n * Forexample, truncate(Exp{mantissa: 15 * expScale}) = 15\n */\n function truncate(Exp memory exp) pure internal returns (uint) {\n //Note: We are not using careful math here as we\u0027re performing a division that cannot fail\n return exp.mantissa / expScale;\n }\n\n/**\n * @dev Checks if first Exp is less than second Exp.\n */\n function lessThanExp(Exp memory left, Exp memory right) pure internalreturns (bool) {\n return left.mantissa \u003c right.mantissa; //TODO: Add some simple tests and this in another PR yo.\n }\n\n /**\n* @dev Checks if left Exp \u003c= right Exp.\n */\n function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns(bool) {\n return left.mantissa \u003c= right.mantissa;\n }\n\n /**\n * @dev returns true if Exp is exactly zero\n */\nfunction isZeroExp(Exp memory value) pure internal returns (bool) {\n return value.mantissa == 0;\n }\n}\n"},"InterestRateModel.sol":{"content":"pragma solidity ^0.5.8;\n\n/**\n * @title The Compound InterestRateModel Interface\n * @author Compound\n * @notice Any interestrate model should derive from this contract.\n * @dev These functions are specifically not marked `pure` as implementations of this\n *contract may read from storage variables.\n */\ninterface InterestRateModel {\n /**\n * @notice Gets the current borrow interest ratebased on the given asset, total cash, total borrows\n * and total reserves.\n * @dev The return value should be scaled by 1e18,thus a return value of\n * `(true, 1000000000000)` implies an interest rate of 0.000001 or 0.0001% *per block*.\n * @param cash Thetotal cash of the underlying asset in the CToken\n * @param borrows The total borrows of the underlying asset in the CToken\n * @paramreserves The total reserves of the underlying asset in the CToken\n * @return Success or failure and the borrow interest rate per block scaledby 10e18\n */\n function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint, uint);\n\n /**\n *@notice Marker function used for light validation when updating the interest rate model of a market\n * @dev Marker function used for lightvalidation when updating the interest rate model of a market. Implementations should simply return true.\n * @return Success or failure\n*/\n function isInterestRateModel() external view returns (bool);\n}"},"Maximillion.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CEther.sol\";\n\n/**\n * @title Compound\u0027s Maximillion Contract\n * @author Compound\n */\ncontract Maximillion {\n /**\n * @noticeThe default cEther market to repay in\n */\n CEther public cEther;\n\n /**\n * @notice Construct a Maximillion to repay max in aCEther market\n */\n constructor(CEther cEther_) public {\n cEther = cEther_;\n }\n\n /**\n * @notice msg.sender sendsEther to repay an account\u0027s borrow in the cEther market\n * @dev The provided Ether is applied towards the borrow balance, any excess isrefunded\n * @param borrower The address of the borrower account to repay on behalf of\n * @return The initial borrows before the repay\n*/\n function repayBehalf(address borrower) public payable {\n return repayBehalfExplicit(borrower, cEther);\n }\n\n /**\n *@notice msg.sender sends Ether to repay an account\u0027s borrow in a cEther market\n * @dev The provided Ether is applied towards the borrowbalance, any excess is refunded\n * @param borrower The address of the borrower account to repay on behalf of\n * @param cEther_ Theaddress of the cEther contract to repay in\n * @return The initial borrows before the repay\n */\n function repayBehalfExplicit(addressborrower, CEther cEther_) public payable {\n uint received = msg.value;\n uint borrows = cEther_.borrowBalanceCurrent(borrower);\nif (received \u003e borrows) {\n cEther_.repayBorrowBehalf.value(borrows)(borrower);\n msg.sender.transfer(received -borrows);\n } else {\n cEther_.repayBorrowBehalf.value(received)(borrower);\n }\n }\n}\n"},"PriceOracle.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CToken.sol\";\n\ninterface PriceOracle {\n /**\n * @notice Indicator that this is a PriceOraclecontract (for inspection)\n */\n function isPriceOracle() external pure returns (bool);\n\n /**\n * @notice Get the underlying priceof a cToken asset\n * @param cToken The cToken to get the underlying price of\n * @return The underlying asset price mantissa (scaled by1e18).\n * Zero means the price is unavailable.\n */\n function getUnderlyingPrice(CToken cToken) external view returns (uint);\n}\n"},"PriceOracleProxy.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./CErc20.sol\";\nimport \"./CToken.sol\";\nimport \"./PriceOracle.sol\";\nimport \"./Comptroller.sol\";\n\ninterface V1PriceOracleInterface {\n function assetPrices(address asset) external view returns (uint);\n}\n\ncontract PriceOracleProxy is PriceOracle {\n /**\n * @notice The v1 price oracle, which will continue to serve prices\n *prices for v1 assets\n */\n V1PriceOracleInterface public v1PriceOracle;\n\n /**\n * @notice The active comptroller, which will bechecked for listing status\n * to short circuit and return 0 for unlisted assets.\n *\n * @dev Listed markets are not part of thecomptroller interface used by\n * cTokens, so we assumena an instance of v1 comptroller.sol instead\n */\n Comptroller publiccomptroller;\n\n /**\n * @notice address of the cEther contract, which has a constant price\n */\n address public cEtherAddress;\n\n/**\n * @notice Indicator that this is a PriceOracle contract (for inspection)\n */\n bool public constant isPriceOracle = true;\n\n/**\n * @param comptroller_ The address of the active comptroller, which will\n * be consulted for market listing status.\n * @paramv1PriceOracle_ The address of the v1 price oracle, which will\n * continue to operate and hold prices for collateral assets.\n * @paramcEtherAddress_ The address of the cEther contract, which will\n * return a constant 1e18, since all prices relative to ether\n */\nconstructor(address comptroller_, address v1PriceOracle_, address cEtherAddress_) public {\n comptroller = Comptroller(comptroller_);\nv1PriceOracle = V1PriceOracleInterface(v1PriceOracle_);\n cEtherAddress = cEtherAddress_;\n }\n\n /**\n * @notice Get theunderlying price of a listed cToken asset\n * @param cToken The cToken to get the underlying price of\n * @return The underlying assetprice mantissa (scaled by 1e18).\n * Zero means the price is unavailable.\n */\n function getUnderlyingPrice(CToken cToken) public viewreturns (uint) {\n address cTokenAddress = address(cToken);\n (bool isListed, ) = comptroller.markets(cTokenAddress);\n\n if(!isListed) {\n // not listed, worthless\n return 0;\n } else if (cTokenAddress == cEtherAddress) {\n //ether always worth 1\n return 1e18;\n } else {\n // read from v1 oracle\n address underlying = CErc20(cTokenAddress).underlying();\n return v1PriceOracle.assetPrices(underlying);\n }\n }\n}\n"},"ReentrancyGuard.sol":{"content":"pragma solidity ^0.5.8;\n\n/**\n * @title Helps contracts guard against reentrancy attacks.\n * @author Remco Bloemen \u003cremco@2π.com\u003e,Eenae \u003calexey@mixbytes.io\u003e\n * @dev If you mark a function `nonReentrant`, you should also\n * mark it `external`.\n */\ncontractReentrancyGuard {\n /// @dev counter to allow mutex lock with only one SSTORE operation\n uint256 private _guardCounter;\n\n constructor() internal {\n // The counter starts at one to prevent changing it from zero to a non-zero\n // value, which is a more expensiveoperation.\n _guardCounter = 1;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n *Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n* by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifiernonReentrant() {\n _guardCounter += 1;\n uint256 localCounter = _guardCounter;\n _;\n require(localCounter ==_guardCounter, \"re-entered\");\n }\n}\n"},"SimplePriceOracle.sol":{"content":"pragma solidity ^0.5.8;\n\nimport \"./PriceOracle.sol\";\nimport\"./CErc20.sol\";\n\ncontract SimplePriceOracle is PriceOracle {\n mapping(address =\u003e uint) prices;\n bool public constant isPriceOracle= true;\n\n function getUnderlyingPrice(CToken cToken) public view returns (uint) {\n return prices[address(CErc20(address(cToken)).underlying())];\n }\n\n function setUnderlyingPrice(CToken cToken, uint underlyingPriceMantissa) public {\n prices[address(CErc20(address(cToken)).underlying())] = underlyingPriceMantissa;\n }\n\n // v1 price oracle interface for use as backing of proxy\n functionassetPrices(address asset) external view returns (uint) {\n return prices[asset];\n }\n}\n"},"Unitroller.sol":{"content":"pragma solidity^0.5.8;\n\nimport \"./ErrorReporter.sol\";\nimport \"./ComptrollerStorage.sol\";\n/**\n * @title ComptrollerCore\n * @dev storage for thecomptroller will be at this address, and\n * cTokens should reference this contract rather than a deployed implementation if\n *\n */\ncontractUnitroller is UnitrollerAdminStorage, ComptrollerErrorReporter {\n\n /**\n * @notice Emitted when pendingComptrollerImplementation ischanged\n */\n event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation);\n\n /**\n *@notice Emitted when pendingComptrollerImplementation is accepted, which means comptroller implementation is updated\n */\n eventNewImplementation(address oldImplementation, address newImplementation);\n\n /**\n * @notice Emitted when pendingAdmin is changed\n*/\n event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);\n\n /**\n * @notice Emitted when pendingAdmin is accepted,which means admin is updated\n */\n event NewAdmin(address oldAdmin, address newAdmin);\n\n constructor() public {\n // Set adminto caller\n admin = msg.sender;\n }\n\n /*** Admin Functions ***/\n function _setPendingImplementation(addressnewPendingImplementation) public returns (uint) {\n\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK);\n }\n\n address oldPendingImplementation = pendingComptrollerImplementation;\n\npendingComptrollerImplementation = newPendingImplementation;\n\n emit NewPendingImplementation(oldPendingImplementation,pendingComptrollerImplementation);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @notice Accepts new implementation ofcomptroller. msg.sender must be pendingImplementation\n * @dev Admin function for new implementation to accept it\u0027s role asimplementation\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _acceptImplementation()public returns (uint) {\n // Check caller is pendingImplementation and pendingImplementation ≠ address(0)\n if (msg.sender !=pendingComptrollerImplementation || pendingComptrollerImplementation == address(0)) {\n return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK);\n }\n\n // Save current values for inclusion in log\n address oldImplementation= comptrollerImplementation;\n address oldPendingImplementation = pendingComptrollerImplementation;\n\n comptrollerImplementation =pendingComptrollerImplementation;\n\n pendingComptrollerImplementation = address(0);\n\n emit NewImplementation(oldImplementation,comptrollerImplementation);\n emit NewPendingImplementation(oldPendingImplementation, pendingComptrollerImplementation);\n\n returnuint(Error.NO_ERROR);\n }\n\n\n /**\n * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` tofinalize the transfer.\n * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n * @param newPendingAdmin New pending admin.\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n*\n * TODO: Should we add a second arg to verify, like a checksum of `newAdmin` address?\n */\n function _setPendingAdmin(addressnewPendingAdmin) public returns (uint) {\n // Check caller = admin\n if (msg.sender != admin) {\n return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK);\n }\n\n // Save current value, if any, for inclusion in log\naddress oldPendingAdmin = pendingAdmin;\n\n // Store pendingAdmin with value newPendingAdmin\n pendingAdmin = newPendingAdmin;\n\n// Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)\n emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);\n\n returnuint(Error.NO_ERROR);\n }\n\n /**\n * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin\n * @dev Adminfunction for pending admin to accept role and update admin\n * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n */\n function _acceptAdmin() public returns (uint) {\n // Check caller is pendingAdmin and pendingAdmin ≠ address(0)\n if(msg.sender != pendingAdmin || msg.sender == address(0)) {\n return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK);\n }\n\n // Save current values for inclusion in log\n address oldAdmin = admin;\naddress oldPendingAdmin = pendingAdmin;\n\n // Store admin with value pendingAdmin\n admin = pendingAdmin;\n\n // Clear thepending value\n pendingAdmin = address(0);\n\n emit NewAdmin(oldAdmin, admin);\n emit NewPendingAdmin(oldPendingAdmin,pendingAdmin);\n\n return uint(Error.NO_ERROR);\n }\n\n /**\n * @dev Delegates execution to an implementation contract.\n * Itreturns to the external caller whatever the implementation returns\n * or forwards reverts.\n */\n function () payable external {\n// delegate all other functions to current implementation\n (bool success, ) = comptrollerImplementation.delegatecall(msg.data);\n\n// solium-disable-next-line security/no-inline-assembly\n assembly {\n let free_mem_ptr := mload(0x40)\nreturndatacopy(free_mem_ptr, 0, returndatasize)\n\n switch success\n case 0 { revert(free_mem_ptr, returndatasize) }\ndefault { return(free_mem_ptr, returndatasize) }\n }\n }\n}\n"},"WhitePaperInterestRateModel.sol":{"content":"pragma solidity^0.5.8;\n\nimport \"./Exponential.sol\";\nimport \"./InterestRateModel.sol\";\n\n/**\n * @title The Compound Standard Interest Rate Model withpluggable constants\n * @author Compound\n * @notice See Section 2.4 of the Compound Whitepaper\n */\ncontract WhitePaperInterestRateModel isInterestRateModel, Exponential {\n /**\n * @notice Indicator that this is an InterestRateModel contract (for inspection)\n */\n boolpublic constant isInterestRateModel = true;\n\n /**\n * @notice The multiplier of utilization rate that gives the slope of the interestrate\n */\n uint public multiplier;\n\n /**\n * @notice The base interest rate which is the y-intercept when utilization rate is 0\n*/\n uint public baseRate;\n\n /**\n * @notice The approximate number of blocks per year that is assumed by the interest rate model\n*/\n uint public constant blocksPerYear = 2102400;\n\n constructor(uint baseRate_, uint multiplier_) public {\n baseRate =baseRate_;\n multiplier = multiplier_;\n }\n\n enum IRError {\n NO_ERROR,\n FAILED_TO_ADD_CASH_PLUS_BORROWS,\nFAILED_TO_GET_EXP,\n FAILED_TO_MUL_UTILIZATION_RATE,\n FAILED_TO_ADD_BASE_RATE\n }\n\n /*\n * @dev Calculates theutilization rate (borrows / (cash + borrows)) as an Exp\n */\n function getUtilizationRate(uint cash, uint borrows) pure internal returns(IRError, Exp memory) {\n if (borrows == 0) {\n // Utilization rate is zero when there\u0027s no borrows\n return(IRError.NO_ERROR, Exp({mantissa: 0}));\n }\n\n (MathError err0, uint cashPlusBorrows) = addUInt(cash, borrows);\n if (err0 !=MathError.NO_ERROR) {\n return (IRError.FAILED_TO_ADD_CASH_PLUS_BORROWS, Exp({mantissa: 0}));\n }\n\n (MathError err1, Expmemory utilizationRate) = getExp(borrows, cashPlusBorrows);\n if (err1 != MathError.NO_ERROR) {\n return (IRError.FAILED_TO_GET_EXP, Exp({mantissa: 0}));\n }\n\n return (IRError.NO_ERROR, utilizationRate);\n }\n\n /*\n * @dev Calculatesthe utilization and borrow rates for use by getBorrowRate function\n */\n function getUtilizationAndAnnualBorrowRate(uint cash, uint borrows) view internal returns (IRError, Exp memory, Exp memory) {\n (IRError err0, Exp memory utilizationRate) = getUtilizationRate(cash, borrows);\n if (err0 != IRError.NO_ERROR) {\n return (err0, Exp({mantissa: 0}), Exp({mantissa: 0}));\n }\n\n // BorrowRate is 5% + UtilizationRate * 45% (baseRate + UtilizationRate * multiplier);\n // 45% of utilizationRate, is `rate * 45 / 100`\n(MathError err1, Exp memory utilizationRateMuled) = mulScalar(utilizationRate, multiplier);\n // `mulScalar` only overflows when the productis \u003e= 2^256.\n // utilizationRate is a real number on the interval [0,1], which means that\n // utilizationRate.mantissa is inthe interval [0e18,1e18], which means that 45 times\n // that is in the interval [0e18,45e18]. That interval has no intersection with 2^256,and therefore\n // this can never overflow for the standard rates.\n if (err1 != MathError.NO_ERROR) {\n return (IRError.FAILED_TO_MUL_UTILIZATION_RATE, Exp({mantissa: 0}), Exp({mantissa: 0}));\n }\n\n (MathError err2, Exp memory utilizationRateScaled)= divScalar(utilizationRateMuled, mantissaOne);\n // 100 is a constant, and therefore cannot be zero, which is the only error case ofdivScalar.\n assert(err2 == MathError.NO_ERROR);\n\n // Add the 5% for (5% + 45% * Ua)\n (MathError err3, Exp memoryannualBorrowRate) = addExp(utilizationRateScaled, Exp({mantissa: baseRate}));\n // `addExp` only fails when the addition of mantissasoverflow.\n // As per above, utilizationRateMuled is capped at 45e18,\n // and utilizationRateScaled is capped at 4.5e17.mantissaFivePercent = 0.5e17, and thus the addition\n // is capped at 5e17, which is less than 2^256. This only applies to the standardrates\n if (err3 != MathError.NO_ERROR) {\n return (IRError.FAILED_TO_ADD_BASE_RATE, Exp({mantissa: 0}), Exp({mantissa: 0}));\n}\n\n return (IRError.NO_ERROR, utilizationRate, annualBorrowRate);\n }\n\n /**\n * @notice Gets the current borrowinterest rate based on the given asset, total cash, total borrows\n * and total reserves.\n * @dev The return value should bescaled by 1e18, thus a return value of\n * `(true, 1000000000000)` implies an interest rate of 0.000001 or 0.0001% *per block*.\n *@param cash The total cash of the underlying asset in the CToken\n * @param borrows The total borrows of the underlying asset in the CToken\n* @param _reserves The total reserves of the underlying asset in the CToken\n * @return Success or failure and the borrow interest rateper block scaled by 10e18\n */\n function getBorrowRate(uint cash, uint borrows, uint _reserves) public view returns (uint, uint) {\n_reserves; // pragma ignore unused argument\n\n (IRError err0, Exp memory _utilizationRate, Exp memory annualBorrowRate) =getUtilizationAndAnnualBorrowRate(cash, borrows);\n if (err0 != IRError.NO_ERROR) {\n return (uint(err0), 0);\n }\n\n// And then divide down by blocks per year.\n (MathError err1, Exp memory borrowRate) = divScalar(annualBorrowRate, blocksPerYear); //basis points * blocks per year\n // divScalar only fails when divisor is zero. This is clearly not the case.\n assert(err1 ==MathError.NO_ERROR);\n\n _utilizationRate; // pragma ignore unused variable\n\n // Note: mantissa is the rate scaled 1e18, whichmatches the expected result\n return (uint(IRError.NO_ERROR), borrowRate.mantissa);\n }\n}\n"}}