Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Multi Chain
Multichain Addresses
13 addresses found via
Latest 12 from a total of 12 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
_set Aggregators | 13330722 | 730 days 6 hrs ago | IN | 0 ETH | 0.00278944 | ||||
_set Admin | 13041886 | 774 days 23 hrs ago | IN | 0 ETH | 0.00086264 | ||||
_set Guardian | 13041883 | 774 days 23 hrs ago | IN | 0 ETH | 0.00160662 | ||||
_set Aggregators | 13041828 | 774 days 23 hrs ago | IN | 0 ETH | 0.00558308 | ||||
_set Y Vault Tok... | 13041821 | 774 days 23 hrs ago | IN | 0 ETH | 0.00316505 | ||||
_set Y Vault Tok... | 13041814 | 774 days 23 hrs ago | IN | 0 ETH | 0.00271987 | ||||
_set Aggregators | 13041794 | 774 days 23 hrs ago | IN | 0 ETH | 0.00302775 | ||||
_set Y Vault Tok... | 13041567 | 775 days 43 mins ago | IN | 0 ETH | 0.01085391 | ||||
_set Curve Token... | 13041559 | 775 days 44 mins ago | IN | 0 ETH | 0.00582356 | ||||
_set L Ps | 13041483 | 775 days 1 hr ago | IN | 0 ETH | 0.0105551 | ||||
_set Aggregators | 13041446 | 775 days 1 hr ago | IN | 0 ETH | 0.11914898 | ||||
0x61014060 | 13041315 | 775 days 1 hr ago | IN | Create: PriceOracleProxy | 0 ETH | 0.11300432 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
PriceOracleProxy
Compiler Version
v0.5.17+commit.d19bba13
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; import "./Denominations.sol"; import "./PriceOracle.sol"; import "./interfaces/CurveTokenInterface.sol"; import "./interfaces/FeedRegistryInterface.sol"; import "./interfaces/UniswapV2Interface.sol"; import "./interfaces/V1PriceOracleInterface.sol"; import "./interfaces/XSushiExchangeRateInterface.sol"; import "./interfaces/YVaultTokenInterface.sol"; import "../CErc20.sol"; import "../CToken.sol"; import "../Exponential.sol"; import "../EIP20Interface.sol"; contract PriceOracleProxy is PriceOracle, Exponential, Denominations { /// @notice Yvault token version, currently support v1 and v2 enum YvTokenVersion { V1, V2 } /// @notice Curve token version, currently support v1, v2 and v3 enum CurveTokenVersion { V1, V2, V3 } /// @notice Curve pool type, currently support ETH and USD base enum CurvePoolType { ETH, USD } struct YvTokenInfo { /// @notice Check if this token is a Yvault token bool isYvToken; /// @notice The version of Yvault YvTokenVersion version; } struct CrvTokenInfo { /// @notice Check if this token is a curve pool token bool isCrvToken; /// @notice The curve pool type CurvePoolType poolType; /// @notice The curve swap contract address address curveSwap; } struct AggregatorInfo { /// @notice The base address base; /// @notice The quote denomination address quote; /// @notice It's being used or not bool isUsed; } /// @notice Admin address address public admin; /// @notice Guardian address address public guardian; /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /// @notice The v1 price oracle, which will continue to serve prices for v1 assets V1PriceOracleInterface public v1PriceOracle; /// @notice The ChainLink registry address FeedRegistryInterface public registry; /// @notice ChainLink quotes mapping(address => AggregatorInfo) public aggregators; /// @notice Check if the underlying address is Uniswap or SushiSwap LP mapping(address => bool) public isUnderlyingLP; /// @notice Yvault token data mapping(address => YvTokenInfo) public yvTokens; /// @notice Curve pool token data mapping(address => CrvTokenInfo) public crvTokens; /// @notice BTC related addresses. All these underlying we use `Denominations.BTC` as the aggregator base. address[6] public btcAddresses = [ 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599, // WBTC 0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D, // renBTC 0x9BE89D2a4cd102D8Fecc6BF9dA793be995C22541, // BBTC 0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa, // tBTC 0x0316EB71485b0Ab14103307bf65a021042c6d380, // HBTC 0xc4E15973E6fF2A35cC804c2CF9D2a1b817a8b40F // ibBTC ]; address public cEthAddress; address public constant usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address public constant wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; address public constant sushiAddress = 0x6B3595068778DD592e39A122f4f5a5cF09C90fE2; address public constant xSushiExRateAddress = 0x851a040fC0Dcbb13a272EBC272F2bC2Ce1e11C4d; address public constant crXSushiAddress = 0x228619CCa194Fbe3Ebeb2f835eC1eA5080DaFbb2; /** * @param admin_ The address of admin to set aggregators, LPs, curve tokens, or Yvault tokens * @param v1PriceOracle_ The address of the v1 price oracle, which will continue to operate and hold prices for collateral assets * @param cEthAddress_ The address of cETH, which will return a constant 1e18, since all prices relative to ether * @param registry_ The address of ChainLink registry */ constructor( address admin_, address v1PriceOracle_, address cEthAddress_, address registry_ ) public { admin = admin_; v1PriceOracle = V1PriceOracleInterface(v1PriceOracle_); cEthAddress = cEthAddress_; registry = FeedRegistryInterface(registry_); } /** * @notice Get the underlying price of a listed cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18) */ function getUnderlyingPrice(CToken cToken) public view returns (uint256) { address cTokenAddress = address(cToken); if (cTokenAddress == cEthAddress) { // ether always worth 1 return 1e18; } else if (cTokenAddress == crXSushiAddress) { // Handle xSUSHI. uint256 exchangeRate = XSushiExchangeRateInterface(xSushiExRateAddress).getExchangeRate(); return mul_(getTokenPrice(sushiAddress), Exp({mantissa: exchangeRate})); } address underlying = CErc20(cTokenAddress).underlying(); // Handle LP tokens. if (isUnderlyingLP[underlying]) { return getLPFairPrice(underlying); } // Handle Yvault tokens. if (yvTokens[underlying].isYvToken) { return getYvTokenPrice(underlying); } // Handle curve pool tokens. if (crvTokens[underlying].isCrvToken) { return getCrvTokenPrice(underlying); } return getTokenPrice(underlying); } /*** Internal fucntions ***/ /** * @notice Get the price of a specific token. Return 1e18 is it's WETH. * @param token The token to get the price of * @return The price */ function getTokenPrice(address token) internal view returns (uint256) { if (token == wethAddress) { // weth always worth 1 return 1e18; } AggregatorInfo memory aggregatorInfo = aggregators[token]; if (aggregatorInfo.isUsed) { uint256 price = getPriceFromChainlink(aggregatorInfo.base, aggregatorInfo.quote); if (aggregatorInfo.quote == Denominations.USD) { // Convert the price to ETH based if it's USD based. price = mul_(price, Exp({mantissa: getUsdcEthPrice()})); } uint256 underlyingDecimals = EIP20Interface(token).decimals(); return mul_(price, 10**(18 - underlyingDecimals)); } return getPriceFromV1(token); } /** * @notice Get price from ChainLink * @param base The base token that ChainLink aggregator gets the price of * @param quote The quote token, currenlty support ETH and USD * @return The price, scaled by 1e18 */ function getPriceFromChainlink(address base, address quote) internal view returns (uint256) { (, int256 price, , , ) = registry.latestRoundData(base, quote); require(price > 0, "invalid price"); // Extend the decimals to 1e18. return mul_(uint256(price), 10**(18 - uint256(registry.decimals(base, quote)))); } /** * @notice Get the fair price of a LP. We use the mechanism from Alpha Finance. * Ref: https://blog.alphafinance.io/fair-lp-token-pricing/ * @param pair The pair of AMM (Uniswap or SushiSwap) * @return The price */ function getLPFairPrice(address pair) internal view returns (uint256) { address token0 = IUniswapV2Pair(pair).token0(); address token1 = IUniswapV2Pair(pair).token1(); uint256 totalSupply = IUniswapV2Pair(pair).totalSupply(); (uint256 r0, uint256 r1, ) = IUniswapV2Pair(pair).getReserves(); uint256 sqrtR = sqrt(mul_(r0, r1)); uint256 p0 = getTokenPrice(token0); uint256 p1 = getTokenPrice(token1); uint256 sqrtP = sqrt(mul_(p0, p1)); return div_(mul_(2, mul_(sqrtR, sqrtP)), totalSupply); } /** * @notice Get price for Yvault tokens * @param token The Yvault token * @return The price */ function getYvTokenPrice(address token) internal view returns (uint256) { YvTokenInfo memory yvTokenInfo = yvTokens[token]; require(yvTokenInfo.isYvToken, "not a Yvault token"); uint256 pricePerShare; address underlying; if (yvTokenInfo.version == YvTokenVersion.V1) { pricePerShare = YVaultV1Interface(token).getPricePerFullShare(); underlying = YVaultV1Interface(token).token(); } else { pricePerShare = YVaultV2Interface(token).pricePerShare(); underlying = YVaultV2Interface(token).token(); } uint256 underlyingPrice; if (crvTokens[underlying].isCrvToken) { underlyingPrice = getCrvTokenPrice(underlying); } else { underlyingPrice = getTokenPrice(underlying); } return mul_(underlyingPrice, Exp({mantissa: pricePerShare})); } /** * @notice Get price for curve pool tokens * @param token The curve pool token * @return The price */ function getCrvTokenPrice(address token) internal view returns (uint256) { CrvTokenInfo memory crvTokenInfo = crvTokens[token]; require(crvTokenInfo.isCrvToken, "not a curve pool token"); uint256 virtualPrice = CurveSwapInterface(crvTokenInfo.curveSwap).get_virtual_price(); if (crvTokenInfo.poolType == CurvePoolType.ETH) { return virtualPrice; } // We treat USDC as USD and convert the price to ETH base. return mul_(getUsdcEthPrice(), Exp({mantissa: virtualPrice})); } /** * @notice Get USDC price * @dev We treat USDC as USD for convenience * @return The USDC price */ function getUsdcEthPrice() internal view returns (uint256) { return getTokenPrice(usdcAddress) / 1e12; } /** * @notice Get price from v1 price oracle * @param token The token to get the price of * @return The price */ function getPriceFromV1(address token) internal view returns (uint256) { return v1PriceOracle.assetPrices(token); } /** * @notice Compare two strings are the same or not * @param a The first string * @param b The second string * @return The same or not */ function compareStrings(string memory a, string memory b) internal pure returns (bool) { return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b)))); } /** * @notice Check if the token is one of BTC relared address * @param token The token address * @return It's BTC or not */ function isBtcAddress(address token) internal returns (bool) { for (uint256 i = 0; i < btcAddresses.length; i++) { if (btcAddresses[i] == token) { return true; } } return false; } /*** Admin or guardian functions ***/ event AggregatorUpdated(address tokenAddress, address base, address quote, bool isUsed); event IsLPUpdated(address tokenAddress, bool isLP); event SetYVaultToken(address token, YvTokenVersion version); event SetCurveToken(address token, CurvePoolType poolType, address swap); event SetGuardian(address guardian); event SetAdmin(address admin); /** * @notice Set ChainLink aggregators for multiple tokens * @param tokenAddresses The list of underlying tokens * @param quotes The list of ChainLink aggregator quotes, currently support 'ETH' and 'USD' */ function _setAggregators(address[] calldata tokenAddresses, string[] calldata quotes) external { require(msg.sender == admin || msg.sender == guardian, "only the admin or guardian may set the aggregators"); require(tokenAddresses.length == quotes.length, "mismatched data"); for (uint256 i = 0; i < tokenAddresses.length; i++) { address base; address quote; bool isUsed; if (bytes(quotes[i]).length != 0) { require(msg.sender == admin, "guardian may only clear the aggregator"); isUsed = true; base = tokenAddresses[i]; if (isBtcAddress(tokenAddresses[i])) { base = Denominations.BTC; } if (compareStrings(quotes[i], "ETH")) { quote = Denominations.ETH; } else if (compareStrings(quotes[i], "USD")) { quote = Denominations.USD; } else { revert("unsupported denomination"); } // Make sure the aggregator exists. address aggregator = registry.getFeed(base, quote); require(registry.isFeedEnabled(aggregator), "aggregator not enabled"); } aggregators[tokenAddresses[i]] = AggregatorInfo({base: base, quote: quote, isUsed: isUsed}); emit AggregatorUpdated(tokenAddresses[i], base, quote, isUsed); } } /** * @notice See assets as LP tokens for multiple tokens * @param tokenAddresses The list of tokens * @param isLP The list of cToken properties (it's LP or not) */ function _setLPs(address[] calldata tokenAddresses, bool[] calldata isLP) external { require(msg.sender == admin, "only the admin may set LPs"); require(tokenAddresses.length == isLP.length, "mismatched data"); for (uint256 i = 0; i < tokenAddresses.length; i++) { isUnderlyingLP[tokenAddresses[i]] = isLP[i]; if (isLP[i]) { // Sanity check to make sure the token is LP. IUniswapV2Pair(tokenAddresses[i]).token0(); IUniswapV2Pair(tokenAddresses[i]).token1(); } emit IsLPUpdated(tokenAddresses[i], isLP[i]); } } /** * @notice See assets as Yvault tokens for multiple tokens * @param tokenAddresses The list of tokens * @param version The list of vault version */ function _setYVaultTokens(address[] calldata tokenAddresses, YvTokenVersion[] calldata version) external { require(msg.sender == admin, "only the admin may set Yvault tokens"); require(tokenAddresses.length == version.length, "mismatched data"); for (uint256 i = 0; i < tokenAddresses.length; i++) { // Sanity check to make sure version is right. if (version[i] == YvTokenVersion.V1) { YVaultV1Interface(tokenAddresses[i]).getPricePerFullShare(); } else { YVaultV2Interface(tokenAddresses[i]).pricePerShare(); } yvTokens[tokenAddresses[i]] = YvTokenInfo({isYvToken: true, version: version[i]}); emit SetYVaultToken(tokenAddresses[i], version[i]); } } /** * @notice See assets as curve pool tokens for multiple tokens * @param tokenAddresses The list of tokens * @param poolType The list of curve pool type (ETH or USD base only) * @param swap The list of curve swap address */ function _setCurveTokens( address[] calldata tokenAddresses, CurveTokenVersion[] calldata version, CurvePoolType[] calldata poolType, address[] calldata swap ) external { require(msg.sender == admin, "only the admin may set curve pool tokens"); require( tokenAddresses.length == version.length && tokenAddresses.length == poolType.length && tokenAddresses.length == swap.length, "mismatched data" ); for (uint256 i = 0; i < tokenAddresses.length; i++) { if (version[i] == CurveTokenVersion.V3) { // Sanity check to make sure the token minter is right. require(CurveTokenV3Interface(tokenAddresses[i]).minter() == swap[i], "incorrect pool"); } crvTokens[tokenAddresses[i]] = CrvTokenInfo({isCrvToken: true, poolType: poolType[i], curveSwap: swap[i]}); emit SetCurveToken(tokenAddresses[i], poolType[i], swap[i]); } } /** * @notice Set guardian for price oracle proxy * @param _guardian The new guardian */ function _setGuardian(address _guardian) external { require(msg.sender == admin, "only the admin may set new guardian"); guardian = _guardian; emit SetGuardian(guardian); } /** * @notice Set admin for price oracle proxy * @param _admin The new admin */ function _setAdmin(address _admin) external { require(msg.sender == admin, "only the admin may set new admin"); admin = _admin; emit SetAdmin(admin); } }
pragma solidity ^0.5.16; import "./CToken.sol"; /** * @title Compound's CErc20 Contract * @notice CTokens which wrap an EIP-20 underlying * @author Compound */ contract CErc20 is CToken, CErc20Interface { /** * @notice Initialize the new money market * @param underlying_ The address of the underlying asset * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token * @param decimals_ ERC-20 decimal precision of this token */ function initialize( address underlying_, ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { // CToken initialize does the bulk of the work super.initialize(comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_); // Set underlying and sanity check it underlying = underlying_; EIP20Interface(underlying).totalSupply(); } /*** User Interface ***/ /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function mint(uint256 mintAmount) external returns (uint256) { (uint256 err, ) = mintInternal(mintAmount, false); return err; } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeem(uint256 redeemTokens) external returns (uint256) { return redeemInternal(redeemTokens, false); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to redeem * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlying(uint256 redeemAmount) external returns (uint256) { return redeemUnderlyingInternal(redeemAmount, false); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrow(uint256 borrowAmount) external returns (uint256) { return borrowInternal(borrowAmount, false); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrow(uint256 repayAmount) external returns (uint256) { (uint256 err, ) = repayBorrowInternal(repayAmount, false); return err; } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256) { (uint256 err, ) = repayBorrowBehalfInternal(borrower, repayAmount, false); return err; } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param cTokenCollateral The market in which to seize collateral from the borrower * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function liquidateBorrow( address borrower, uint256 repayAmount, CTokenInterface cTokenCollateral ) external returns (uint256) { (uint256 err, ) = liquidateBorrowInternal(borrower, repayAmount, cTokenCollateral, false); return err; } /** * @notice The sender adds to reserves. * @param addAmount The amount fo underlying token to add as reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReserves(uint256 addAmount) external returns (uint256) { return _addReservesInternal(addAmount, false); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying tokens owned by this contract */ function getCashPrior() internal view returns (uint256) { EIP20Interface token = EIP20Interface(underlying); return token.balanceOf(address(this)); } /** * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case. * This will revert due to insufficient balance or insufficient allowance. * This function returns the actual amount received, * which may be less than `amount` if there is a fee attached to the transfer. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferIn( address from, uint256 amount, bool isNative ) internal returns (uint256) { isNative; // unused EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying); uint256 balanceBefore = EIP20Interface(underlying).balanceOf(address(this)); token.transferFrom(from, address(this), amount); bool success; assembly { switch returndatasize() case 0 { // This is a non-standard ERC-20 success := not(0) // set success to true } case 32 { // This is a compliant ERC-20 returndatacopy(0, 0, 32) success := mload(0) // Set `success = returndata` of external call } default { // This is an excessively non-compliant ERC-20, revert. revert(0, 0) } } require(success, "TOKEN_TRANSFER_IN_FAILED"); // Calculate the amount that was *actually* transferred uint256 balanceAfter = EIP20Interface(underlying).balanceOf(address(this)); return sub_(balanceAfter, balanceBefore); } /** * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory * error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to * insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified * it is >= amount, this should not revert in normal conditions. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferOut( address payable to, uint256 amount, bool isNative ) internal { isNative; // unused EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying); token.transfer(to, amount); bool success; assembly { switch returndatasize() case 0 { // This is a non-standard ERC-20 success := not(0) // set success to true } case 32 { // This is a complaint ERC-20 returndatacopy(0, 0, 32) success := mload(0) // Set `success = returndata` of external call } default { // This is an excessively non-compliant ERC-20, revert. revert(0, 0) } } require(success, "TOKEN_TRANSFER_OUT_FAILED"); } /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally * @param spender The address of the account performing the transfer * @param src The address of the source account * @param dst The address of the destination account * @param tokens The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferTokens( address spender, address src, address dst, uint256 tokens ) internal returns (uint256) { /* Fail if transfer not allowed */ uint256 allowed = comptroller.transferAllowed(address(this), src, dst, tokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.TRANSFER_COMPTROLLER_REJECTION, allowed); } /* Do not allow self-transfers */ if (src == dst) { return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED); } /* Get the allowance, infinite for the account owner */ uint256 startingAllowance = 0; if (spender == src) { startingAllowance = uint256(-1); } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ accountTokens[src] = sub_(accountTokens[src], tokens); accountTokens[dst] = add_(accountTokens[dst], tokens); /* Eat some of the allowance (if necessary) */ if (startingAllowance != uint256(-1)) { transferAllowances[src][spender] = sub_(startingAllowance, tokens); } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); // unused function // comptroller.transferVerify(address(this), src, dst, tokens); return uint256(Error.NO_ERROR); } /** * @notice Get the account's cToken balances * @param account The address of the account */ function getCTokenBalanceInternal(address account) internal view returns (uint256) { return accountTokens[account]; } struct MintLocalVars { uint256 exchangeRateMantissa; uint256 mintTokens; uint256 actualMintAmount; } /** * @notice User supplies assets into the market and receives cTokens in exchange * @dev Assumes interest has already been accrued up to the current block * @param minter The address of the account which is supplying the assets * @param mintAmount The amount of the underlying asset to supply * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintFresh( address minter, uint256 mintAmount, bool isNative ) internal returns (uint256, uint256) { /* Fail if mint not allowed */ uint256 allowed = comptroller.mintAllowed(address(this), minter, mintAmount); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed), 0); } /* * Return if mintAmount is zero. * Put behind `mintAllowed` for accuring potential COMP rewards. */ if (mintAmount == 0) { return (uint256(Error.NO_ERROR), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK), 0); } MintLocalVars memory vars; vars.exchangeRateMantissa = exchangeRateStoredInternal(); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call `doTransferIn` for the minter and the mintAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * `doTransferIn` reverts if anything goes wrong, since we can't be sure if * side-effects occurred. The function returns the amount actually transferred, * in case of a fee. On success, the cToken holds an additional `actualMintAmount` * of cash. */ vars.actualMintAmount = doTransferIn(minter, mintAmount, isNative); /* * We get the current exchange rate and calculate the number of cTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ vars.mintTokens = div_ScalarByExpTruncate(vars.actualMintAmount, Exp({mantissa: vars.exchangeRateMantissa})); /* * We calculate the new total supply of cTokens and minter token balance, checking for overflow: * totalSupply = totalSupply + mintTokens * accountTokens[minter] = accountTokens[minter] + mintTokens */ totalSupply = add_(totalSupply, vars.mintTokens); accountTokens[minter] = add_(accountTokens[minter], vars.mintTokens); /* We emit a Mint event, and a Transfer event */ emit Mint(minter, vars.actualMintAmount, vars.mintTokens); emit Transfer(address(this), minter, vars.mintTokens); /* We call the defense hook */ // unused function // comptroller.mintVerify(address(this), minter, vars.actualMintAmount, vars.mintTokens); return (uint256(Error.NO_ERROR), vars.actualMintAmount); } struct RedeemLocalVars { uint256 exchangeRateMantissa; uint256 redeemTokens; uint256 redeemAmount; uint256 totalSupplyNew; uint256 accountTokensNew; } /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block. Only one of redeemTokensIn or redeemAmountIn may be non-zero and it would do nothing if both are zero. * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of cTokens to redeem into underlying * @param redeemAmountIn The number of underlying tokens to receive from redeeming cTokens * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemFresh( address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn, bool isNative ) internal returns (uint256) { require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero"); RedeemLocalVars memory vars; /* exchangeRate = invoke Exchange Rate Stored() */ vars.exchangeRateMantissa = exchangeRateStoredInternal(); /* If redeemTokensIn > 0: */ if (redeemTokensIn > 0) { /* * We calculate the exchange rate and the amount of underlying to be redeemed: * redeemTokens = redeemTokensIn * redeemAmount = redeemTokensIn x exchangeRateCurrent */ vars.redeemTokens = redeemTokensIn; vars.redeemAmount = mul_ScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), redeemTokensIn); } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ vars.redeemTokens = div_ScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa})); vars.redeemAmount = redeemAmountIn; } /* Fail if redeem not allowed */ uint256 allowed = comptroller.redeemAllowed(address(this), redeemer, vars.redeemTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REDEEM_COMPTROLLER_REJECTION, allowed); } /* * Return if redeemTokensIn and redeemAmountIn are zero. * Put behind `redeemAllowed` for accuring potential COMP rewards. */ if (redeemTokensIn == 0 && redeemAmountIn == 0) { return uint256(Error.NO_ERROR); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK); } /* * We calculate the new total supply and redeemer balance, checking for underflow: * totalSupplyNew = totalSupply - redeemTokens * accountTokensNew = accountTokens[redeemer] - redeemTokens */ vars.totalSupplyNew = sub_(totalSupply, vars.redeemTokens); vars.accountTokensNew = sub_(accountTokens[redeemer], vars.redeemTokens); /* Fail gracefully if protocol has insufficient cash */ if (getCashPrior() < vars.redeemAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the redeemer and the redeemAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken has redeemAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(redeemer, vars.redeemAmount, isNative); /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[redeemer] = vars.accountTokensNew; /* We emit a Transfer event, and a Redeem event */ emit Transfer(redeemer, address(this), vars.redeemTokens); emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens); /* We call the defense hook */ comptroller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens); return uint256(Error.NO_ERROR); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken. * Its absolutely critical to use msg.sender as the seizer cToken and not a parameter. * @param seizerToken The contract seizing the collateral (i.e. borrowed cToken) * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seizeInternal( address seizerToken, address liquidator, address borrower, uint256 seizeTokens ) internal returns (uint256) { /* Fail if seize not allowed */ uint256 allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed); } /* * Return if seizeTokens is zero. * Put behind `seizeAllowed` for accuring potential COMP rewards. */ if (seizeTokens == 0) { return uint256(Error.NO_ERROR); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER); } /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ accountTokens[borrower] = sub_(accountTokens[borrower], seizeTokens); accountTokens[liquidator] = add_(accountTokens[liquidator], seizeTokens); /* Emit a Transfer event */ emit Transfer(borrower, liquidator, seizeTokens); /* We call the defense hook */ // unused function // comptroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens); return uint256(Error.NO_ERROR); } }
pragma solidity ^0.5.16; import "./ComptrollerInterface.sol"; import "./CTokenInterfaces.sol"; import "./ErrorReporter.sol"; import "./Exponential.sol"; import "./EIP20Interface.sol"; import "./EIP20NonStandardInterface.sol"; import "./InterestRateModel.sol"; /** * @title Compound's CToken Contract * @notice Abstract base for CTokens * @author Compound */ contract CToken is CTokenInterface, Exponential, TokenErrorReporter { /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize( ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { require(msg.sender == admin, "only admin may initialize the market"); require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the comptroller uint256 err = _setComptroller(comptroller_); require(err == uint256(Error.NO_ERROR), "setting comptroller failed"); // Initialize block number and borrow index (block number mocks depend on comptroller being set) accrualBlockNumber = getBlockNumber(); borrowIndex = mantissaOne; // Set the interest rate model (depends on block number / borrow index) err = _setInterestRateModelFresh(interestRateModel_); require(err == uint256(Error.NO_ERROR), "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == uint256(Error.NO_ERROR); } /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom( address src, address dst, uint256 amount ) external nonReentrant returns (bool) { return transferTokens(msg.sender, src, dst, amount) == uint256(Error.NO_ERROR); } /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool) { address src = msg.sender; transferAllowances[src][spender] = amount; emit Approval(src, spender, amount); return true; } /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256) { return transferAllowances[owner][spender]; } /** * @notice Get the token balance of the `owner` * @param owner The address of the account to query * @return The number of tokens owned by `owner` */ function balanceOf(address owner) external view returns (uint256) { return accountTokens[owner]; } /** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */ function balanceOfUnderlying(address owner) external returns (uint256) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); return mul_ScalarTruncate(exchangeRate, accountTokens[owner]); } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by comptroller to more efficiently perform liquidity checks. * @param account Address of the account to snapshot * @return (possible error, token balance, borrow balance, exchange rate mantissa) */ function getAccountSnapshot(address account) external view returns ( uint256, uint256, uint256, uint256 ) { uint256 cTokenBalance = getCTokenBalanceInternal(account); uint256 borrowBalance = borrowBalanceStoredInternal(account); uint256 exchangeRateMantissa = exchangeRateStoredInternal(); return (uint256(Error.NO_ERROR), cTokenBalance, borrowBalance, exchangeRateMantissa); } /** * @dev Function to simply retrieve block number * This exists mainly for inheriting test contracts to stub this result. */ function getBlockNumber() internal view returns (uint256) { return block.number; } /** * @notice Returns the current per-block borrow interest rate for this cToken * @return The borrow interest rate per block, scaled by 1e18 */ function borrowRatePerBlock() external view returns (uint256) { return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves); } /** * @notice Returns the current per-block supply interest rate for this cToken * @return The supply interest rate per block, scaled by 1e18 */ function supplyRatePerBlock() external view returns (uint256) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa); } /** * @notice Returns the estimated per-block borrow interest rate for this cToken after some change * @return The borrow interest rate per block, scaled by 1e18 */ function estimateBorrowRatePerBlockAfterChange(uint256 change, bool repay) external view returns (uint256) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getBorrowRate(cashPriorNew, totalBorrowsNew, totalReserves); } /** * @notice Returns the estimated per-block supply interest rate for this cToken after some change * @return The supply interest rate per block, scaled by 1e18 */ function estimateSupplyRatePerBlockAfterChange(uint256 change, bool repay) external view returns (uint256) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getSupplyRate(cashPriorNew, totalBorrowsNew, totalReserves, reserveFactorMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return totalBorrows; } /** * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex * @param account The address whose balance should be calculated after updating borrowIndex * @return The calculated balance */ function borrowBalanceCurrent(address account) external nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return borrowBalanceStored(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return The calculated balance */ function borrowBalanceStored(address account) public view returns (uint256) { return borrowBalanceStoredInternal(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return the calculated balance or 0 if error code is non-zero */ function borrowBalanceStoredInternal(address account) internal view returns (uint256) { /* Get borrowBalance and borrowIndex */ BorrowSnapshot storage borrowSnapshot = accountBorrows[account]; /* If borrowBalance = 0 then borrowIndex is likely also 0. * Rather than failing the calculation with a division by 0, we immediately return 0 in this case. */ if (borrowSnapshot.principal == 0) { return 0; } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ uint256 principalTimesIndex = mul_(borrowSnapshot.principal, borrowIndex); uint256 result = div_(principalTimesIndex, borrowSnapshot.interestIndex); return result; } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view returns (uint256) { return exchangeRateStoredInternal(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue interest before calculating the exchange rate * @return calculated exchange rate scaled by 1e18 */ function exchangeRateStoredInternal() internal view returns (uint256) { uint256 _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return initialExchangeRateMantissa; } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint256 totalCash = getCashPrior(); uint256 cashPlusBorrowsMinusReserves = sub_(add_(totalCash, totalBorrows), totalReserves); uint256 exchangeRate = div_(cashPlusBorrowsMinusReserves, Exp({mantissa: _totalSupply})); return exchangeRate; } } /** * @notice Get cash balance of this cToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view returns (uint256) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public returns (uint256) { /* Remember the initial block number */ uint256 currentBlockNumber = getBlockNumber(); uint256 accrualBlockNumberPrior = accrualBlockNumber; /* Short-circuit accumulating 0 interest */ if (accrualBlockNumberPrior == currentBlockNumber) { return uint256(Error.NO_ERROR); } /* Read the previous values out of storage */ uint256 cashPrior = getCashPrior(); uint256 borrowsPrior = totalBorrows; uint256 reservesPrior = totalReserves; uint256 borrowIndexPrior = borrowIndex; /* Calculate the current borrow interest rate */ uint256 borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of blocks elapsed since the last accrual */ uint256 blockDelta = sub_(currentBlockNumber, accrualBlockNumberPrior); /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * blockDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor = mul_(Exp({mantissa: borrowRateMantissa}), blockDelta); uint256 interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, borrowsPrior); uint256 totalBorrowsNew = add_(interestAccumulated, borrowsPrior); uint256 totalReservesNew = mul_ScalarTruncateAddUInt( Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior ); uint256 borrowIndexNew = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accrualBlockNumber = currentBlockNumber; borrowIndex = borrowIndexNew; totalBorrows = totalBorrowsNew; totalReserves = totalReservesNew; /* We emit an AccrueInterest event */ emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew); return uint256(Error.NO_ERROR); } /** * @notice Sender supplies assets into the market and receives cTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint256 mintAmount, bool isNative) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0); } // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to return mintFresh(msg.sender, mintAmount, isNative); } /** * @notice Sender redeems cTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of cTokens to redeem into underlying * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint256 redeemTokens, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, redeemTokens, 0, isNative); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming cTokens * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint256 redeemAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, 0, redeemAmount, isNative); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowInternal(uint256 borrowAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED); } // borrowFresh emits borrow-specific logs on errors, so we don't need to return borrowFresh(msg.sender, borrowAmount, isNative); } struct BorrowLocalVars { MathError mathErr; uint256 accountBorrows; uint256 accountBorrowsNew; uint256 totalBorrowsNew; } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowFresh( address payable borrower, uint256 borrowAmount, bool isNative ) internal returns (uint256) { /* Fail if borrow not allowed */ uint256 allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { return failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed); } /* * Return if borrowAmount is zero. * Put behind `borrowAllowed` for accuring potential COMP rewards. */ if (borrowAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return uint256(Error.NO_ERROR); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK); } /* Fail gracefully if protocol has insufficient underlying cash */ if (getCashPrior() < borrowAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE); } BorrowLocalVars memory vars; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); vars.accountBorrowsNew = add_(vars.accountBorrows, borrowAmount); vars.totalBorrowsNew = add_(totalBorrows, borrowAmount); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount, isNative); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.borrowVerify(address(this), borrower, borrowAmount); return uint256(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint256 repayAmount, bool isNative) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, msg.sender, repayAmount, isNative); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal( address borrower, uint256 repayAmount, bool isNative ) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, borrower, repayAmount, isNative); } struct RepayBorrowLocalVars { Error err; MathError mathErr; uint256 repayAmount; uint256 borrowerIndex; uint256 accountBorrows; uint256 accountBorrowsNew; uint256 totalBorrowsNew; uint256 actualRepayAmount; } /** * @notice Borrows are repaid by another user (possibly the borrower). * @param payer the account paying off the borrow * @param borrower the account with the debt being payed off * @param repayAmount the amount of undelrying tokens being returned * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowFresh( address payer, address borrower, uint256 repayAmount, bool isNative ) internal returns (uint256, uint256) { /* Fail if repayBorrow not allowed */ uint256 allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { return ( failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed), 0 ); } /* * Return if repayAmount is zero. * Put behind `repayBorrowAllowed` for accuring potential COMP rewards. */ if (repayAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return (uint256(Error.NO_ERROR), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0); } RepayBorrowLocalVars memory vars; /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); /* If repayAmount == -1, repayAmount = accountBorrows */ if (repayAmount == uint256(-1)) { vars.repayAmount = vars.accountBorrows; } else { vars.repayAmount = repayAmount; } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the payer and the repayAmount * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken holds an additional repayAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount, isNative); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ vars.accountBorrowsNew = sub_(vars.accountBorrows, vars.actualRepayAmount); vars.totalBorrowsNew = sub_(totalBorrows, vars.actualRepayAmount); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // comptroller.repayBorrowVerify(address(this), payer, borrower, vars.actualRepayAmount, vars.borrowerIndex); return (uint256(Error.NO_ERROR), vars.actualRepayAmount); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param cTokenCollateral The market in which to seize collateral from the borrower * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowInternal( address borrower, uint256 repayAmount, CTokenInterface cTokenCollateral, bool isNative ) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0); } error = cTokenCollateral.accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to return liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral, isNative); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowFresh( address liquidator, address borrower, uint256 repayAmount, CTokenInterface cTokenCollateral, bool isNative ) internal returns (uint256, uint256) { /* Fail if liquidate not allowed */ uint256 allowed = comptroller.liquidateBorrowAllowed( address(this), address(cTokenCollateral), liquidator, borrower, repayAmount ); if (allowed != 0) { return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0); } /* Verify cTokenCollateral market's block number equals current block number */ if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0); } /* Fail if repayAmount = -1 */ if (repayAmount == uint256(-1)) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0); } /* Fail if repayBorrow fails */ (uint256 repayBorrowError, uint256 actualRepayAmount) = repayBorrowFresh( liquidator, borrower, repayAmount, isNative ); if (repayBorrowError != uint256(Error.NO_ERROR)) { return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint256 amountSeizeError, uint256 seizeTokens) = comptroller.liquidateCalculateSeizeTokens( address(this), address(cTokenCollateral), actualRepayAmount ); require(amountSeizeError == uint256(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED"); /* Revert if borrower collateral token balance < seizeTokens */ require(cTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH"); // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call uint256 seizeError; if (address(cTokenCollateral) == address(this)) { seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { seizeError = cTokenCollateral.seize(liquidator, borrower, seizeTokens); } /* Revert if seize tokens fails (since we cannot be sure of side effects) */ require(seizeError == uint256(Error.NO_ERROR), "token seizure failed"); /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens); /* We call the defense hook */ // unused function // comptroller.liquidateBorrowVerify(address(this), address(cTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens); return (uint256(Error.NO_ERROR), actualRepayAmount); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another cToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize( address liquidator, address borrower, uint256 seizeTokens ) external nonReentrant returns (uint256) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } /*** Admin Functions ***/ /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint256) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() external returns (uint256) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Sets a new comptroller for the market * @dev Admin function to set a new comptroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setComptroller(ComptrollerInterface newComptroller) public returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COMPTROLLER_OWNER_CHECK); } ComptrollerInterface oldComptroller = comptroller; // Ensure invoke comptroller.isComptroller() returns true require(newComptroller.isComptroller(), "marker method returned false"); // Set market's comptroller to newComptroller comptroller = newComptroller; // Emit NewComptroller(oldComptroller, newComptroller) emit NewComptroller(oldComptroller, newComptroller); return uint256(Error.NO_ERROR); } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint256 newReserveFactorMantissa) external nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed. return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED); } // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint256 newReserveFactorMantissa) internal returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK); } // Verify market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK); } // Check newReserveFactor ≤ maxReserveFactor if (newReserveFactorMantissa > reserveFactorMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK); } uint256 oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return uint256(Error.NO_ERROR); } /** * @notice Accrues interest and reduces reserves by transferring from msg.sender * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReservesInternal(uint256 addAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED); } // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to. (error, ) = _addReservesFresh(addAmount, isNative); return error; } /** * @notice Add reserves by transferring from caller * @dev Requires fresh interest accrual * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees */ function _addReservesFresh(uint256 addAmount, bool isNative) internal returns (uint256, uint256) { // totalReserves + actualAddAmount uint256 totalReservesNew; uint256 actualAddAmount; // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.ADD_RESERVES_FRESH_CHECK), actualAddAmount); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the caller and the addAmount * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken holds an additional addAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ actualAddAmount = doTransferIn(msg.sender, addAmount, isNative); totalReservesNew = add_(totalReserves, actualAddAmount); // Store reserves[n+1] = reserves[n] + actualAddAmount totalReserves = totalReservesNew; /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */ emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew); /* Return (NO_ERROR, actualAddAmount) */ return (uint256(Error.NO_ERROR), actualAddAmount); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint256 reduceAmount) external nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED); } // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint256 reduceAmount) internal returns (uint256) { // totalReserves - reduceAmount uint256 totalReservesNew; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) totalReservesNew = sub_(totalReserves, reduceAmount); // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. // Restrict reducing reserves in native token. Implementations except `CWrappedNative` won't use parameter `isNative`. doTransferOut(admin, reduceAmount, true); emit ReservesReduced(admin, reduceAmount, totalReservesNew); return uint256(Error.NO_ERROR); } /** * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh * @dev Admin function to accrue interest and update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED); } // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint256) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK); } // Track the market's current interest rate model oldInterestRateModel = interestRateModel; // Ensure invoke newInterestRateModel.isInterestRateModel() returns true require(newInterestRateModel.isInterestRateModel(), "marker method returned false"); // Set the interest rate model to newInterestRateModel interestRateModel = newInterestRateModel; // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel) emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel); return uint256(Error.NO_ERROR); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying owned by this contract */ function getCashPrior() internal view returns (uint256); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn( address from, uint256 amount, bool isNative ) internal returns (uint256); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut( address payable to, uint256 amount, bool isNative ) internal; /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally */ function transferTokens( address spender, address src, address dst, uint256 tokens ) internal returns (uint256); /** * @notice Get the account's cToken balances */ function getCTokenBalanceInternal(address account) internal view returns (uint256); /** * @notice User supplies assets into the market and receives cTokens in exchange * @dev Assumes interest has already been accrued up to the current block */ function mintFresh( address minter, uint256 mintAmount, bool isNative ) internal returns (uint256, uint256); /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block */ function redeemFresh( address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn, bool isNative ) internal returns (uint256); /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another CToken. * Its absolutely critical to use msg.sender as the seizer cToken and not a parameter. */ function seizeInternal( address seizerToken, address liquidator, address borrower, uint256 seizeTokens ) internal returns (uint256); /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() { require(_notEntered, "re-entered"); _notEntered = false; _; _notEntered = true; // get a gas-refund post-Istanbul } }
pragma solidity ^0.5.16; import "./ComptrollerInterface.sol"; import "./InterestRateModel.sol"; contract CTokenStorage { /** * @dev Guard variable for re-entrancy checks */ bool internal _notEntered; /** * @notice EIP-20 token name for this token */ string public name; /** * @notice EIP-20 token symbol for this token */ string public symbol; /** * @notice EIP-20 token decimals for this token */ uint8 public decimals; /** * @notice Maximum borrow rate that can ever be applied (.0005% / block) */ uint256 internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves */ uint256 internal constant reserveFactorMaxMantissa = 1e18; /** * @notice Administrator for this contract */ address payable public admin; /** * @notice Pending administrator for this contract */ address payable public pendingAdmin; /** * @notice Contract which oversees inter-cToken operations */ ComptrollerInterface public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) */ uint256 internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint256 public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint256 public accrualBlockNumber; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint256 public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint256 public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint256 public totalReserves; /** * @notice Total number of tokens in circulation */ uint256 public totalSupply; /** * @notice Official record of token balances for each account */ mapping(address => uint256) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping(address => mapping(address => uint256)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint256 principal; uint256 interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; } contract CErc20Storage { /** * @notice Underlying asset for this CToken */ address public underlying; /** * @notice Implementation address for this contract */ address public implementation; } contract CSupplyCapStorage { /** * @notice Internal cash counter for this CToken. Should equal underlying.balanceOf(address(this)) for CERC20. */ uint256 public internalCash; } contract CCollateralCapStorage { /** * @notice Total number of tokens used as collateral in circulation. */ uint256 public totalCollateralTokens; /** * @notice Record of token balances which could be treated as collateral for each account. * If collateral cap is not set, the value should be equal to accountTokens. */ mapping(address => uint256) public accountCollateralTokens; /** * @notice Check if accountCollateralTokens have been initialized. */ mapping(address => bool) public isCollateralTokenInit; /** * @notice Collateral cap for this CToken, zero for no cap. */ uint256 public collateralCap; } /*** Interface ***/ contract CTokenInterface is CTokenStorage { /** * @notice Indicator that this is a CToken contract (for inspection) */ bool public constant isCToken = true; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint256 cashPrior, uint256 interestAccumulated, uint256 borrowIndex, uint256 totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint256 mintAmount, uint256 mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint256 borrowAmount, uint256 accountBorrows, uint256 totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow( address payer, address borrower, uint256 repayAmount, uint256 accountBorrows, uint256 totalBorrows ); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow( address liquidator, address borrower, uint256 repayAmount, address cTokenCollateral, uint256 seizeTokens ); /*** Admin Events ***/ /** * @notice Event emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Event emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /** * @notice Event emitted when comptroller is changed */ event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint256 oldReserveFactorMantissa, uint256 newReserveFactorMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint256 addAmount, uint256 newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint256 reduceAmount, uint256 newTotalReserves); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint256 amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint256 amount); /** * @notice Failure event */ event Failure(uint256 error, uint256 info, uint256 detail); /*** User Interface ***/ function transfer(address dst, uint256 amount) external returns (bool); function transferFrom( address src, address dst, uint256 amount ) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function balanceOfUnderlying(address owner) external returns (uint256); function getAccountSnapshot(address account) external view returns ( uint256, uint256, uint256, uint256 ); function borrowRatePerBlock() external view returns (uint256); function supplyRatePerBlock() external view returns (uint256); function totalBorrowsCurrent() external returns (uint256); function borrowBalanceCurrent(address account) external returns (uint256); function borrowBalanceStored(address account) public view returns (uint256); function exchangeRateCurrent() public returns (uint256); function exchangeRateStored() public view returns (uint256); function getCash() external view returns (uint256); function accrueInterest() public returns (uint256); function seize( address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint256); function _acceptAdmin() external returns (uint256); function _setComptroller(ComptrollerInterface newComptroller) public returns (uint256); function _setReserveFactor(uint256 newReserveFactorMantissa) external returns (uint256); function _reduceReserves(uint256 reduceAmount) external returns (uint256); function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint256); } contract CErc20Interface is CErc20Storage { /*** User Interface ***/ function mint(uint256 mintAmount) external returns (uint256); function redeem(uint256 redeemTokens) external returns (uint256); function redeemUnderlying(uint256 redeemAmount) external returns (uint256); function borrow(uint256 borrowAmount) external returns (uint256); function repayBorrow(uint256 repayAmount) external returns (uint256); function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256); function liquidateBorrow( address borrower, uint256 repayAmount, CTokenInterface cTokenCollateral ) external returns (uint256); function _addReserves(uint256 addAmount) external returns (uint256); } contract CWrappedNativeInterface is CErc20Interface { /** * @notice Flash loan fee ratio */ uint256 public constant flashFeeBips = 3; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint256 amount, uint256 totalFee, uint256 reservesFee); /*** User Interface ***/ function mintNative() external payable returns (uint256); function redeemNative(uint256 redeemTokens) external returns (uint256); function redeemUnderlyingNative(uint256 redeemAmount) external returns (uint256); function borrowNative(uint256 borrowAmount) external returns (uint256); function repayBorrowNative() external payable returns (uint256); function repayBorrowBehalfNative(address borrower) external payable returns (uint256); function liquidateBorrowNative(address borrower, CTokenInterface cTokenCollateral) external payable returns (uint256); function flashLoan( address payable receiver, uint256 amount, bytes calldata params ) external; function _addReservesNative() external payable returns (uint256); } contract CCapableErc20Interface is CErc20Interface, CSupplyCapStorage { /** * @notice Flash loan fee ratio */ uint256 public constant flashFeeBips = 3; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint256 amount, uint256 totalFee, uint256 reservesFee); /*** User Interface ***/ function gulp() external; function flashLoan( address receiver, uint256 amount, bytes calldata params ) external; } contract CCollateralCapErc20Interface is CCapableErc20Interface, CCollateralCapStorage { /*** Admin Events ***/ /** * @notice Event emitted when collateral cap is set */ event NewCollateralCap(address token, uint256 newCap); /** * @notice Event emitted when user collateral is changed */ event UserCollateralChanged(address account, uint256 newCollateralTokens); /*** User Interface ***/ function registerCollateral(address account) external returns (uint256); function unregisterCollateral(address account) external; /*** Admin Functions ***/ function _setCollateralCap(uint256 newCollateralCap) external; } contract CDelegatorInterface { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementation( address implementation_, bool allowResign, bytes memory becomeImplementationData ) public; } contract CDelegateInterface { /** * @notice Called by the delegator on a delegate to initialize it for duty * @dev Should revert if any issues arise which make it unfit for delegation * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes memory data) public; /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() public; } /*** External interface ***/ /** * @title Flash loan receiver interface */ interface IFlashloanReceiver { function executeOperation( address sender, address underlying, uint256 amount, uint256 fee, bytes calldata params ) external; }
pragma solidity ^0.5.16; /** * @title Careful Math * @author Compound * @notice Derived from OpenZeppelin's SafeMath library * https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol */ contract CarefulMath { /** * @dev Possible error codes that we can return */ enum MathError { NO_ERROR, DIVISION_BY_ZERO, INTEGER_OVERFLOW, INTEGER_UNDERFLOW } /** * @dev Multiplies two numbers, returns an error on overflow. */ function mulUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint256 c = a * b; if (c / a != b) { return (MathError.INTEGER_OVERFLOW, 0); } else { return (MathError.NO_ERROR, c); } } /** * @dev Integer division of two numbers, truncating the quotient. */ function divUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (b == 0) { return (MathError.DIVISION_BY_ZERO, 0); } return (MathError.NO_ERROR, a / b); } /** * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend). */ function subUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (b <= a) { return (MathError.NO_ERROR, a - b); } else { return (MathError.INTEGER_UNDERFLOW, 0); } } /** * @dev Adds two numbers, returns an error on overflow. */ function addUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { uint256 c = a + b; if (c >= a) { return (MathError.NO_ERROR, c); } else { return (MathError.INTEGER_OVERFLOW, 0); } } /** * @dev add a and b and then subtract c */ function addThenSubUInt( uint256 a, uint256 b, uint256 c ) internal pure returns (MathError, uint256) { (MathError err0, uint256 sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } }
pragma solidity ^0.5.16; import "./CToken.sol"; import "./ComptrollerStorage.sol"; contract ComptrollerInterface { /// @notice Indicator that this is a Comptroller contract (for inspection) bool public constant isComptroller = true; /*** Assets You Are In ***/ function enterMarkets(address[] calldata cTokens) external returns (uint256[] memory); function exitMarket(address cToken) external returns (uint256); /*** Policy Hooks ***/ function mintAllowed( address cToken, address minter, uint256 mintAmount ) external returns (uint256); function mintVerify( address cToken, address minter, uint256 mintAmount, uint256 mintTokens ) external; function redeemAllowed( address cToken, address redeemer, uint256 redeemTokens ) external returns (uint256); function redeemVerify( address cToken, address redeemer, uint256 redeemAmount, uint256 redeemTokens ) external; function borrowAllowed( address cToken, address borrower, uint256 borrowAmount ) external returns (uint256); function borrowVerify( address cToken, address borrower, uint256 borrowAmount ) external; function repayBorrowAllowed( address cToken, address payer, address borrower, uint256 repayAmount ) external returns (uint256); function repayBorrowVerify( address cToken, address payer, address borrower, uint256 repayAmount, uint256 borrowerIndex ) external; function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint256 repayAmount ) external returns (uint256); function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint256 repayAmount, uint256 seizeTokens ) external; function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); function seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external; function transferAllowed( address cToken, address src, address dst, uint256 transferTokens ) external returns (uint256); function transferVerify( address cToken, address src, address dst, uint256 transferTokens ) external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint256 repayAmount ) external view returns (uint256, uint256); } interface ComptrollerInterfaceExtension { function checkMembership(address account, CToken cToken) external view returns (bool); function updateCTokenVersion(address cToken, ComptrollerV2Storage.Version version) external; function flashloanAllowed( address cToken, address receiver, uint256 amount, bytes calldata params ) external; }
pragma solidity ^0.5.16; import "./CToken.sol"; import "./PriceOracle/PriceOracle.sol"; contract UnitrollerAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Active brains of Unitroller */ address public comptrollerImplementation; /** * @notice Pending brains of Unitroller */ address public pendingComptrollerImplementation; } contract ComptrollerV1Storage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ PriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint256 public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint256 public liquidationIncentiveMantissa; /** * @notice Max number of assets a single account can participate in (borrow or use as collateral) */ uint256 public maxAssets; /** * @notice Per-account mapping of "assets you are in", capped by maxAssets */ mapping(address => CToken[]) public accountAssets; } contract ComptrollerV2Storage is ComptrollerV1Storage { enum Version { VANILLA, COLLATERALCAP, WRAPPEDNATIVE } struct Market { /// @notice Whether or not this market is listed bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint256 collateralFactorMantissa; /// @notice Per-market mapping of "accounts in this asset" mapping(address => bool) accountMembership; /// @notice Whether or not this market receives COMP bool isComped; /// @notice CToken version Version version; } /** * @notice Official mapping of cTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /** * @notice The Pause Guardian can pause certain actions as a safety mechanism. * Actions which allow users to remove their own assets cannot be paused. * Liquidation / seizing / transfer can only be paused globally, not by market. */ address public pauseGuardian; bool public _mintGuardianPaused; bool public _borrowGuardianPaused; bool public transferGuardianPaused; bool public seizeGuardianPaused; mapping(address => bool) public mintGuardianPaused; mapping(address => bool) public borrowGuardianPaused; } contract ComptrollerV3Storage is ComptrollerV2Storage { struct CompMarketState { /// @notice The market's last updated compBorrowIndex or compSupplyIndex uint224 index; /// @notice The block number the index was last updated at uint32 block; } /// @notice A list of all markets CToken[] public allMarkets; /// @notice The rate at which the flywheel distributes COMP, per block uint256 public compRate; /// @notice The portion of compRate that each market currently receives mapping(address => uint256) public compSpeeds; /// @notice The COMP market supply state for each market mapping(address => CompMarketState) public compSupplyState; /// @notice The COMP market borrow state for each market mapping(address => CompMarketState) public compBorrowState; /// @notice The COMP borrow index for each market for each supplier as of the last time they accrued COMP mapping(address => mapping(address => uint256)) public compSupplierIndex; /// @notice The COMP borrow index for each market for each borrower as of the last time they accrued COMP mapping(address => mapping(address => uint256)) public compBorrowerIndex; /// @notice The COMP accrued but not yet transferred to each user mapping(address => uint256) public compAccrued; } contract ComptrollerV4Storage is ComptrollerV3Storage { // @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market. address public borrowCapGuardian; // @notice Borrow caps enforced by borrowAllowed for each cToken address. Defaults to zero which corresponds to unlimited borrowing. mapping(address => uint256) public borrowCaps; } contract ComptrollerV5Storage is ComptrollerV4Storage { // @notice The supplyCapGuardian can set supplyCaps to any number for any market. Lowering the supply cap could disable supplying to the given market. address public supplyCapGuardian; // @notice Supply caps enforced by mintAllowed for each cToken address. Defaults to zero which corresponds to unlimited supplying. mapping(address => uint256) public supplyCaps; } contract ComptrollerV6Storage is ComptrollerV5Storage { // @notice flashloanGuardianPaused can pause flash loan as a safety mechanism. mapping(address => bool) public flashloanGuardianPaused; } contract ComptrollerV7Storage is ComptrollerV6Storage { /// @notice liquidityMining the liquidity mining module that handles the LM rewards distribution. address public liquidityMining; }
pragma solidity ^0.5.16; /** * @title ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface EIP20Interface { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external returns (bool success); /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom( address src, address dst, uint256 amount ) external returns (bool success); /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
pragma solidity ^0.5.16; /** * @title EIP20NonStandardInterface * @dev Version of ERC20 with no return values for `transfer` and `transferFrom` * See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ interface EIP20NonStandardInterface { /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transfer(address dst, uint256 amount) external; /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `src` to `dst` * @param src The address of the source account * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transferFrom( address src, address dst, uint256 amount ) external; /** * @notice Approve `spender` to transfer up to `amount` from `src` * @dev This will overwrite the approval amount for `spender` * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) * @param spender The address of the account which may transfer tokens * @param amount The number of tokens that are approved * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
pragma solidity ^0.5.16; contract ComptrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, COMPTROLLER_MISMATCH, INSUFFICIENT_SHORTFALL, INSUFFICIENT_LIQUIDITY, INVALID_CLOSE_FACTOR, INVALID_COLLATERAL_FACTOR, INVALID_LIQUIDATION_INCENTIVE, MARKET_NOT_ENTERED, // no longer possible MARKET_NOT_LISTED, MARKET_ALREADY_LISTED, MATH_ERROR, NONZERO_BORROW_BALANCE, PRICE_ERROR, REJECTION, SNAPSHOT_ERROR, TOO_MANY_ASSETS, TOO_MUCH_REPAY } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, EXIT_MARKET_BALANCE_OWED, EXIT_MARKET_REJECTION, SET_CLOSE_FACTOR_OWNER_CHECK, SET_CLOSE_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_NO_EXISTS, SET_COLLATERAL_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_WITHOUT_PRICE, SET_IMPLEMENTATION_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_VALIDATION, SET_MAX_ASSETS_OWNER_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK, SET_PRICE_ORACLE_OWNER_CHECK, SUPPORT_MARKET_EXISTS, SUPPORT_MARKET_OWNER_CHECK, SET_PAUSE_GUARDIAN_OWNER_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint256 error, uint256 info, uint256 detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return uint256(err); } } contract TokenErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, BAD_INPUT, COMPTROLLER_REJECTION, COMPTROLLER_CALCULATION_ERROR, INTEREST_RATE_MODEL_ERROR, INVALID_ACCOUNT_PAIR, INVALID_CLOSE_AMOUNT_REQUESTED, INVALID_COLLATERAL_FACTOR, MATH_ERROR, MARKET_NOT_FRESH, MARKET_NOT_LISTED, TOKEN_INSUFFICIENT_ALLOWANCE, TOKEN_INSUFFICIENT_BALANCE, TOKEN_INSUFFICIENT_CASH, TOKEN_TRANSFER_IN_FAILED, TOKEN_TRANSFER_OUT_FAILED } /* * Note: FailureInfo (but not Error) is kept in alphabetical order * This is because FailureInfo grows significantly faster, and * the order of Error has some meaning, while the order of FailureInfo * is entirely arbitrary. */ enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, BORROW_ACCRUE_INTEREST_FAILED, BORROW_CASH_NOT_AVAILABLE, BORROW_FRESHNESS_CHECK, BORROW_MARKET_NOT_LISTED, BORROW_COMPTROLLER_REJECTION, LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED, LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED, LIQUIDATE_COLLATERAL_FRESHNESS_CHECK, LIQUIDATE_COMPTROLLER_REJECTION, LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED, LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX, LIQUIDATE_CLOSE_AMOUNT_IS_ZERO, LIQUIDATE_FRESHNESS_CHECK, LIQUIDATE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_REPAY_BORROW_FRESH_FAILED, LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_SEIZE_TOO_MUCH, MINT_ACCRUE_INTEREST_FAILED, MINT_COMPTROLLER_REJECTION, MINT_FRESHNESS_CHECK, MINT_TRANSFER_IN_FAILED, MINT_TRANSFER_IN_NOT_POSSIBLE, REDEEM_ACCRUE_INTEREST_FAILED, REDEEM_COMPTROLLER_REJECTION, REDEEM_FRESHNESS_CHECK, REDEEM_TRANSFER_OUT_NOT_POSSIBLE, REDUCE_RESERVES_ACCRUE_INTEREST_FAILED, REDUCE_RESERVES_ADMIN_CHECK, REDUCE_RESERVES_CASH_NOT_AVAILABLE, REDUCE_RESERVES_FRESH_CHECK, REDUCE_RESERVES_VALIDATION, REPAY_BEHALF_ACCRUE_INTEREST_FAILED, REPAY_BORROW_ACCRUE_INTEREST_FAILED, REPAY_BORROW_COMPTROLLER_REJECTION, REPAY_BORROW_FRESHNESS_CHECK, REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_VALIDATION, SET_COMPTROLLER_OWNER_CHECK, SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED, SET_INTEREST_RATE_MODEL_FRESH_CHECK, SET_INTEREST_RATE_MODEL_OWNER_CHECK, SET_MAX_ASSETS_OWNER_CHECK, SET_ORACLE_MARKET_NOT_LISTED, SET_PENDING_ADMIN_OWNER_CHECK, SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED, SET_RESERVE_FACTOR_ADMIN_CHECK, SET_RESERVE_FACTOR_FRESH_CHECK, SET_RESERVE_FACTOR_BOUNDS_CHECK, TRANSFER_COMPTROLLER_REJECTION, TRANSFER_NOT_ALLOWED, ADD_RESERVES_ACCRUE_INTEREST_FAILED, ADD_RESERVES_FRESH_CHECK, ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint256 error, uint256 info, uint256 detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return uint256(err); } }
pragma solidity ^0.5.16; import "./CarefulMath.sol"; /** * @title Exponential module for storing fixed-precision decimals * @author Compound * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places. * Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is: * `Exp({mantissa: 5100000000000000000})`. */ contract Exponential is CarefulMath { uint256 constant expScale = 1e18; uint256 constant doubleScale = 1e36; uint256 constant halfExpScale = expScale / 2; uint256 constant mantissaOne = expScale; struct Exp { uint256 mantissa; } struct Double { uint256 mantissa; } /** * @dev Creates an exponential from numerator and denominator values. * Note: Returns an error if (`num` * 10e18) > MAX_INT, * or if `denom` is zero. */ function getExp(uint256 num, uint256 denom) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint256 rational) = divUInt(scaledNumerator, denom); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: rational})); } /** * @dev Adds two exponentials, returning a new exponential. */ function addExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError error, uint256 result) = addUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Subtracts two exponentials, returning a new exponential. */ function subExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError error, uint256 result) = subUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Multiply an Exp by a scalar, returning a new Exp. */ function mulScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 scaledMantissa) = mulUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa})); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mulScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (MathError, uint256) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mulScalarTruncateAddUInt( Exp memory a, uint256 scalar, uint256 addend ) internal pure returns (MathError, uint256) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (uint256) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt( Exp memory a, uint256 scalar, uint256 addend ) internal pure returns (uint256) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 descaledMantissa) = divUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa})); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function divScalarByExp(uint256 scalar, Exp memory divisor) internal pure returns (MathError, Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ (MathError err0, uint256 numerator) = mulUInt(expScale, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return getExp(numerator, divisor.mantissa); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function divScalarByExpTruncate(uint256 scalar, Exp memory divisor) internal pure returns (MathError, uint256) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function div_ScalarByExp(uint256 scalar, Exp memory divisor) internal pure returns (Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ uint256 numerator = mul_(expScale, scalar); return Exp({mantissa: div_(numerator, divisor)}); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function div_ScalarByExpTruncate(uint256 scalar, Exp memory divisor) internal pure returns (uint256) { Exp memory fraction = div_ScalarByExp(scalar, divisor); return truncate(fraction); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } // We add half the scale before dividing so that we get rounding instead of truncation. // See "Listing 6" and text above it at https://accu.org/index.php/journals/1717 // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18. (MathError err1, uint256 doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint256 product) = divUInt(doubleScaledProductWithHalfScale, expScale); // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero. assert(err2 == MathError.NO_ERROR); return (MathError.NO_ERROR, Exp({mantissa: product})); } /** * @dev Multiplies two exponentials given their mantissas, returning a new exponential. */ function mulExp(uint256 a, uint256 b) internal pure returns (MathError, Exp memory) { return mulExp(Exp({mantissa: a}), Exp({mantissa: b})); } /** * @dev Multiplies three exponentials, returning a new exponential. */ function mulExp3( Exp memory a, Exp memory b, Exp memory c ) internal pure returns (MathError, Exp memory) { (MathError err, Exp memory ab) = mulExp(a, b); if (err != MathError.NO_ERROR) { return (err, ab); } return mulExp(ab, c); } /** * @dev Divides two exponentials, returning a new exponential. * (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, * which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa) */ function divExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) internal pure returns (uint256) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) internal pure returns (bool) { return value.mantissa == 0; } function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint256 a, uint256 b) internal pure returns (uint256) { return add_(a, b, "addition overflow"); } function add_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint256 a, uint256 b) internal pure returns (uint256) { return sub_(a, b, "subtraction underflow"); } function sub_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint256 a, Exp memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint256 a, Double memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint256 a, uint256 b) internal pure returns (uint256) { return mul_(a, b, "multiplication overflow"); } function mul_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint256 a, Exp memory b) internal pure returns (uint256) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint256 a, Double memory b) internal pure returns (uint256) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint256 a, uint256 b) internal pure returns (uint256) { return div_(a, b, "divide by zero"); } function div_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } function fraction(uint256 a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0 // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint256 x) internal pure returns (uint256) { if (x == 0) return 0; uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return (r < r1 ? r : r1); } }
pragma solidity ^0.5.16; /** * @title Compound's InterestRateModel Interface * @author Compound */ contract InterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) bool public constant isInterestRateModel = true; /** * @notice Calculates the current borrow interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @return The borrow rate per block (as a percentage, and scaled by 1e18) */ function getBorrowRate( uint256 cash, uint256 borrows, uint256 reserves ) external view returns (uint256); /** * @notice Calculates the current supply interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per block (as a percentage, and scaled by 1e18) */ function getSupplyRate( uint256 cash, uint256 borrows, uint256 reserves, uint256 reserveFactorMantissa ) external view returns (uint256); }
pragma solidity ^0.5.16; contract Denominations { address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; address public constant BTC = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217 address public constant USD = address(840); address public constant GBP = address(826); address public constant EUR = address(978); address public constant JPY = address(392); address public constant KRW = address(410); address public constant CNY = address(156); address public constant AUD = address(36); address public constant CAD = address(124); address public constant CHF = address(756); address public constant ARS = address(32); address public constant PHP = address(608); address public constant NZD = address(554); address public constant SGD = address(702); address public constant NGN = address(566); address public constant ZAR = address(710); address public constant RUB = address(643); address public constant INR = address(356); address public constant BRL = address(986); }
pragma solidity ^0.5.16; import "../CToken.sol"; contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /** * @notice Get the underlying price of a cToken asset * @param cToken The cToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(CToken cToken) external view returns (uint256); }
pragma solidity ^0.5.16; interface CurveTokenV3Interface { function minter() external view returns (address); } interface CurveSwapInterface { function get_virtual_price() external view returns (uint256); }
pragma solidity ^0.5.16; interface FeedRegistryInterface { function decimals(address base, address quote) external view returns (uint8); function description(address base, address quote) external view returns (string memory); function version(address base, address quote) external view returns (uint256); function getRoundData( address base, address quote, uint80 _roundId ) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData(address base, address quote) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function getFeed(address base, address quote) external view returns (address aggregator); function isFeedEnabled(address aggregator) external view returns (bool); }
pragma solidity ^0.5.16; // Ref: https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Pair.sol interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom( address from, address to, uint256 value ) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns ( uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast ); function price0CumulativeLast() external view returns (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; function skim(address to) external; function sync() external; function initialize(address, address) external; }
pragma solidity ^0.5.16; interface V1PriceOracleInterface { function assetPrices(address asset) external view returns (uint256); }
pragma solidity ^0.5.16; interface XSushiExchangeRateInterface { function getExchangeRate() external view returns (uint256); }
pragma solidity ^0.5.16; interface YVaultV1Interface { function token() external view returns (address); function getPricePerFullShare() external view returns (uint256); } interface YVaultV2Interface { function token() external view returns (address); function pricePerShare() external view returns (uint256); }
{ "evmVersion": "istanbul", "libraries": {}, "metadata": { "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"admin_","type":"address"},{"internalType":"address","name":"v1PriceOracle_","type":"address"},{"internalType":"address","name":"cEthAddress_","type":"address"},{"internalType":"address","name":"registry_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"base","type":"address"},{"indexed":false,"internalType":"address","name":"quote","type":"address"},{"indexed":false,"internalType":"bool","name":"isUsed","type":"bool"}],"name":"AggregatorUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"bool","name":"isLP","type":"bool"}],"name":"IsLPUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"admin","type":"address"}],"name":"SetAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"enum PriceOracleProxy.CurvePoolType","name":"poolType","type":"uint8"},{"indexed":false,"internalType":"address","name":"swap","type":"address"}],"name":"SetCurveToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"guardian","type":"address"}],"name":"SetGuardian","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"enum PriceOracleProxy.YvTokenVersion","name":"version","type":"uint8"}],"name":"SetYVaultToken","type":"event"},{"constant":true,"inputs":[],"name":"ARS","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"AUD","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"BRL","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"BTC","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CAD","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CHF","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CNY","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"EUR","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"GBP","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"INR","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"JPY","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"KRW","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"NGN","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"NZD","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"PHP","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"RUB","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"SGD","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"USD","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ZAR","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"name":"_setAdmin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"},{"internalType":"string[]","name":"quotes","type":"string[]"}],"name":"_setAggregators","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"},{"internalType":"enum PriceOracleProxy.CurveTokenVersion[]","name":"version","type":"uint8[]"},{"internalType":"enum PriceOracleProxy.CurvePoolType[]","name":"poolType","type":"uint8[]"},{"internalType":"address[]","name":"swap","type":"address[]"}],"name":"_setCurveTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_guardian","type":"address"}],"name":"_setGuardian","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"},{"internalType":"bool[]","name":"isLP","type":"bool[]"}],"name":"_setLPs","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"},{"internalType":"enum PriceOracleProxy.YvTokenVersion[]","name":"version","type":"uint8[]"}],"name":"_setYVaultTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"aggregators","outputs":[{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"},{"internalType":"bool","name":"isUsed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"btcAddresses","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cEthAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"crXSushiAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"crvTokens","outputs":[{"internalType":"bool","name":"isCrvToken","type":"bool"},{"internalType":"enum PriceOracleProxy.CurvePoolType","name":"poolType","type":"uint8"},{"internalType":"address","name":"curveSwap","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract CToken","name":"cToken","type":"address"}],"name":"getUnderlyingPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"guardian","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPriceOracle","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isUnderlyingLP","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"internalType":"contract FeedRegistryInterface","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"sushiAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"usdcAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"v1PriceOracle","outputs":[{"internalType":"contract V1PriceOracleInterface","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"wethAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"xSushiExRateAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"yvTokens","outputs":[{"internalType":"bool","name":"isYvToken","type":"bool"},{"internalType":"enum PriceOracleProxy.YvTokenVersion","name":"version","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"}]
Contract Creation Code
610140604052732260fac5e5542a773aa44fbcfedf7c193bc2c599608090815273eb4c2781e4eba804ce9a9803c67d0893436bb27d60a052739be89d2a4cd102d8fecc6bf9da793be995c2254160c052738daebade922df735c38c80c7ebd708af50815faa60e052730316eb71485b0ab14103307bf65a021042c6d3806101005273c4e15973e6ff2a35cc804c2cf9d2a1b817a8b40f61012052620000a99060089060066200012e565b50348015620000b757600080fd5b506040516200330a3803806200330a833981016040819052620000da91620001c8565b600080546001600160a01b039586166001600160a01b0319918216179091556002805494861694821694909417909355600e805492851692841692909217909155600380549190931691161790556200025e565b826006810192821562000179579160200282015b828111156200017957825182546001600160a01b0319166001600160a01b0390911617825560209092019160019091019062000142565b50620001879291506200018b565b5090565b620001b291905b80821115620001875780546001600160a01b031916815560010162000192565b90565b8051620001c28162000244565b92915050565b60008060008060808587031215620001df57600080fd5b6000620001ed8787620001b5565b94505060206200020087828801620001b5565b93505060406200021387828801620001b5565b92505060606200022687828801620001b5565b91505092959194509250565b60006001600160a01b038216620001c2565b6200024f8162000232565b81146200025b57600080fd5b50565b61309c806200026e6000396000f3fe608060405234801561001057600080fd5b50600436106102695760003560e01c80637582bf5211610151578063ca9d1a72116100c3578063f249653811610087578063f249653814610462578063f37fcc4214610475578063f851a4401461047d578063fc57d4df14610485578063fd760c49146104a5578063fe10c98d146104ad57610269565b8063ca9d1a721461042f578063d9355bb814610437578063e38e8c0f1461043f578063e774928e14610452578063efaa41341461045a57610269565b8063976d5e7711610115578063976d5e77146103cf5780639db2a472146103d75780639e09f0c2146103df578063a0d0c0d814610401578063a364136014610414578063a4a235951461042757610269565b80637582bf521461036b5780637b1039991461037e5780638322fff2146103935780638e2dd6591461039b5780638e919267146103bc57610269565b8063294a2bf2116101ea578063465bd0a3116101ae578063465bd0a31461032e5780634f0e0ef31461033657806353f7c3671461033e57806356ef45141461034657806366331bba1461034e5780636b09583c1461036357610269565b8063294a2bf2146102fb5780632e79477f146103035780632ed58e151461030b5780633a74a76714610313578063452a93201461032657610269565b806315b102e31161023157806315b102e3146102c657806316daaff4146102ce57806319342a64146102e35780631bf6c21b146102eb5780632792949d146102f357610269565b806301b8b3391461026e57806302d454571461028c57806303d698f2146102945780630c0128341461029c578063112cdab9146102a4575b600080fd5b6102766104b5565b6040516102839190612d14565b60405180910390f35b6102766104bb565b6102766104d3565b6102766104d9565b6102b76102b2366004612612565b6104de565b60405161028393929190612d72565b610276610510565b6102e16102dc3660046126be565b610528565b005b610276610868565b61027661086d565b610276610873565b61027661088b565b610276610891565b610276610897565b6102e1610321366004612612565b6108a6565b61027661092c565b61027661093b565b610276610941565b610276610959565b61027661095f565b610356610965565b6040516102839190612df8565b61027661096a565b610356610379366004612612565b610970565b610386610985565b6040516102839190612e22565b610276610994565b6103ae6103a9366004612612565b6109ac565b604051610283929190612e14565b6102e16103ca36600461264e565b6109ca565b610276610cb8565b610276610cbe565b6103f26103ed366004612612565b610cc4565b60405161028393929190612e06565b6102e161040f36600461264e565b610cf4565b610276610422366004612873565b610f82565b610276610f9f565b610276610fa4565b610276610faa565b6102e161044d366004612612565b610fc2565b61027661103d565b610276611043565b6102e161047036600461264e565b61105b565b6102766115a9565b6102766115af565b6104986104933660046127cc565b6115be565b6040516102839190612f21565b6102766117dc565b6103866117e1565b61033a81565b73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b61023681565b602081565b600460205260009081526040902080546001909101546001600160a01b0391821691811690600160a01b900460ff1683565b73851a040fc0dcbb13a272ebc272f2bc2ce1e11c4d81565b6000546001600160a01b0316331461055b5760405162461bcd60e51b815260040161055290612ef1565b60405180910390fd5b868514801561056957508683145b801561057457508681145b6105905760405162461bcd60e51b815260040161055290612e61565b60005b8781101561085d5760028787838181106105a957fe5b90506020020160206105be9190810190612808565b60028111156105c957fe5b14156106b0578282828181106105db57fe5b90506020020160206105f09190810190612612565b6001600160a01b031689898381811061060557fe5b905060200201602061061a9190810190612612565b6001600160a01b031663075461726040518163ffffffff1660e01b815260040160206040518083038186803b15801561065257600080fd5b505afa158015610666573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061068a9190810190612630565b6001600160a01b0316146106b05760405162461bcd60e51b815260040161055290612e91565b60405180606001604052806001151581526020018686848181106106d057fe5b90506020020160206106e591908101906127ea565b60018111156106f057fe5b815260200184848481811061070157fe5b90506020020160206107169190810190612612565b6001600160a01b03169052600760008b8b8581811061073157fe5b90506020020160206107469190810190612612565b6001600160a01b031681526020808201929092526040016000208251815460ff191690151517808255918301519091829061ff00191661010083600181111561078b57fe5b02179055506040919091015181546001600160a01b03909116620100000262010000600160b01b03199091161790557fe589de78805ec500bf23a096c2f92013247fd931aeb72be9bdeaa04ed4863ceb8989838181106107e757fe5b90506020020160206107fc9190810190612612565b86868481811061080857fe5b905060200201602061081d91908101906127ea565b85858581811061082957fe5b905060200201602061083e9190810190612612565b60405161084d93929190612db5565b60405180910390a1600101610593565b505050505050505050565b607c81565b61034881565b73bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb81565b6103d281565b6102be81565b600e546001600160a01b031681565b6000546001600160a01b031633146108d05760405162461bcd60e51b815260040161055290612e51565b600080546001600160a01b0319166001600160a01b0383811691909117918290556040517f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a192610921921690612d14565b60405180910390a150565b6001546001600160a01b031681565b61018881565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b61026081565b61019a81565b600181565b6103da81565b60056020526000908152604090205460ff1681565b6003546001600160a01b031681565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b60066020526000908152604090205460ff8082169161010090041682565b6000546001600160a01b031633146109f45760405162461bcd60e51b815260040161055290612f01565b828114610a135760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb1576000838383818110610a2c57fe5b9050602002016020610a4191908101906127ea565b6001811115610a4c57fe5b1415610ae957848482818110610a5e57fe5b9050602002016020610a739190810190612612565b6001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b158015610aab57600080fd5b505afa158015610abf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610ae39190810190612891565b50610b7c565b848482818110610af557fe5b9050602002016020610b0a9190810190612612565b6001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015610b4257600080fd5b505afa158015610b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b7a9190810190612891565b505b6040518060400160405280600115158152602001848484818110610b9c57fe5b9050602002016020610bb191908101906127ea565b6001811115610bbc57fe5b905260066000878785818110610bce57fe5b9050602002016020610be39190810190612612565b6001600160a01b031681526020808201929092526040016000208251815460ff191690151517808255918301519091829061ff001916610100836001811115610c2857fe5b02179055509050507f40b251634471b85d185d32f7f33380d815ce735c0bae07cdeb8657a38402ddaa858583818110610c5d57fe5b9050602002016020610c729190810190612612565b848484818110610c7e57fe5b9050602002016020610c9391908101906127ea565b604051610ca1929190612ddd565b60405180910390a1600101610a16565b5050505050565b61028381565b6102c681565b60076020526000908152604090205460ff808216916101008104909116906201000090046001600160a01b031683565b6000546001600160a01b03163314610d1e5760405162461bcd60e51b815260040161055290612ec1565b828114610d3d5760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb157828282818110610d5457fe5b9050602002016020610d699190810190612790565b60056000878785818110610d7957fe5b9050602002016020610d8e9190810190612612565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055828282818110610dc257fe5b9050602002016020610dd79190810190612790565b15610f0157848482818110610de857fe5b9050602002016020610dfd9190810190612612565b6001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015610e3557600080fd5b505afa158015610e49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610e6d9190810190612630565b50848482818110610e7a57fe5b9050602002016020610e8f9190810190612612565b6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610ec757600080fd5b505afa158015610edb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610eff9190810190612630565b505b7f0cdeca791f00903a9a063565b4d2d5295eaef5ba38390319391986dca98cd7cf858583818110610f2e57fe5b9050602002016020610f439190810190612612565b848484818110610f4f57fe5b9050602002016020610f649190810190612790565b604051610f72929190612d9a565b60405180910390a1600101610d40565b60088160068110610f8f57fe5b01546001600160a01b0316905081565b609c81565b61022a81565b73228619cca194fbe3ebeb2f835ec1ea5080dafbb281565b6000546001600160a01b03163314610fec5760405162461bcd60e51b815260040161055290612eb1565b600180546001600160a01b0319166001600160a01b0383811691909117918290556040517f31845eceb9cde510c7e8b37f76301c688feb70bc9653aa4c28a3734999840fd892610921921690612d14565b61016481565b736b3595068778dd592e39a122f4f5a5cf09c90fe281565b6000546001600160a01b031633148061107e57506001546001600160a01b031633145b61109a5760405162461bcd60e51b815260040161055290612ea1565b8281146110b95760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb15760008060008585858181106110d557fe5b602002820190508035601e19368490030181126110f157600080fd5b9091016020810191503567ffffffffffffffff81111561111057600080fd5b3681900382131561112057600080fd5b159050611485576000546001600160a01b031633146111515760405162461bcd60e51b815260040161055290612f11565b50600187878581811061116057fe5b90506020020160206111759190810190612612565b92506111a088888681811061118657fe5b905060200201602061119b9190810190612612565b6117f0565b156111bd5773bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb92505b61126c8686868181106111cc57fe5b602002820190508035601e19368490030181126111e857600080fd5b9091016020810191503567ffffffffffffffff81111561120757600080fd5b3681900382131561121757600080fd5b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051808201909152600381526208aa8960eb1b602082015291506118409050565b1561128d5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee9150611363565b61133c86868681811061129c57fe5b602002820190508035601e19368490030181126112b857600080fd5b9091016020810191503567ffffffffffffffff8111156112d757600080fd5b368190038213156112e757600080fd5b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250506040805180820190915260038152621554d160ea1b602082015291506118409050565b1561134b576103489150611363565b60405162461bcd60e51b815260040161055290612ee1565b60035460405163d2edb6dd60e01b81526000916001600160a01b03169063d2edb6dd906113969087908790600401612d22565b60206040518083038186803b1580156113ae57600080fd5b505afa1580156113c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113e69190810190612630565b60035460405163b099d43b60e01b81529192506001600160a01b03169063b099d43b90611417908490600401612d14565b60206040518083038186803b15801561142f57600080fd5b505afa158015611443573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061146791908101906127ae565b6114835760405162461bcd60e51b815260040161055290612e41565b505b6040518060600160405280846001600160a01b03168152602001836001600160a01b03168152602001821515815250600460008a8a888181106114c457fe5b90506020020160206114d99190810190612612565b6001600160a01b0390811682526020808301939093526040918201600020845181549083166001600160a01b0319918216178255938501516001909101805495909301511515600160a01b0260ff60a01b19919092169490931693909317919091169190911790557f1ce411df4a158aa72e588cc62a13841fd7f7e644f81b10b60b90cb97b9017fa788888681811061156e57fe5b90506020020160206115839190810190612612565b8484846040516115969493929190612d3d565b60405180910390a15050506001016110bc565b6102f481565b6000546001600160a01b031681565b600e5460009082906001600160a01b03808316911614156115ea57670de0b6b3a76400009150506117d7565b6001600160a01b03811673228619cca194fbe3ebeb2f835ec1ea5080dafbb214156116d557600073851a040fc0dcbb13a272ebc272f2bc2ce1e11c4d6001600160a01b031663e6aa216c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561165e57600080fd5b505afa158015611672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506116969190810190612891565b90506116cc6116b8736b3595068778dd592e39a122f4f5a5cf09c90fe261189a565b604051806020016040528084815250611a1e565b925050506117d7565b6000816001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561171057600080fd5b505afa158015611724573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506117489190810190612630565b6001600160a01b03811660009081526005602052604090205490915060ff1615611775576116cc81611a46565b6001600160a01b03811660009081526006602052604090205460ff161561179f576116cc81611c9e565b6001600160a01b03811660009081526007602052604090205460ff16156117c9576116cc81611f68565b6117d28161189a565b925050505b919050565b602481565b6002546001600160a01b031681565b6000805b600681101561183757826001600160a01b03166008826006811061181457fe5b01546001600160a01b0316141561182f5760019150506117d7565b6001016117f4565b50600092915050565b6000816040516020016118539190612d08565b604051602081830303815290604052805190602001208360405160200161187a9190612d08565b604051602081830303815290604052805190602001201490505b92915050565b60006001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214156118d05750670de0b6b3a76400006117d7565b6118d86124e1565b506001600160a01b03828116600090815260046020908152604091829020825160608101845281548516815260019091015493841691810191909152600160a01b90920460ff1615801591830191909152611a0e576000611941826000015183602001516120a3565b60208301519091506001600160a01b0316610348141561197c576119798160405180602001604052806119726121ee565b9052611a1e565b90505b6000846001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156119b757600080fd5b505afa1580156119cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506119ef9190810190612924565b60ff169050611a048282601203600a0a612220565b93505050506117d7565b611a1783612262565b9392505050565b6000670de0b6b3a7640000611a37848460000151612220565b81611a3e57fe5b049392505050565b600080826001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611a8257600080fd5b505afa158015611a96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611aba9190810190612630565b90506000836001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611af757600080fd5b505afa158015611b0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611b2f9190810190612630565b90506000846001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b6c57600080fd5b505afa158015611b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611ba49190810190612891565b9050600080866001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611be257600080fd5b505afa158015611bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c1a9190810190612826565b506001600160701b031691506001600160701b031691506000611c45611c408484612220565b6122e3565b90506000611c528761189a565b90506000611c5f8761189a565b90506000611c70611c408484612220565b9050611c8f611c896002611c848785612220565b612220565b88612429565b9b9a5050505050505050505050565b6000611ca8612501565b6001600160a01b0383166000908152600660209081526040918290208251808401909352805460ff808216151585529192840191610100909104166001811115611cee57fe5b6001811115611cf957fe5b9052508051909150611d1d5760405162461bcd60e51b815260040161055290612e71565b6000808083602001516001811115611d3157fe5b1415611e2257846001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d7057600080fd5b505afa158015611d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611da89190810190612891565b9150846001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611de357600080fd5b505afa158015611df7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611e1b9190810190612630565b9050611f09565b846001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015611e5b57600080fd5b505afa158015611e6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611e939190810190612891565b9150846001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611ece57600080fd5b505afa158015611ee2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611f069190810190612630565b90505b6001600160a01b03811660009081526007602052604081205460ff1615611f3a57611f3382611f68565b9050611f46565b611f438261189a565b90505b611f5e81604051806020016040528086815250611a1e565b9695505050505050565b6000611f72612518565b6001600160a01b038316600090815260076020908152604091829020825160608101909352805460ff808216151585529192840191610100909104166001811115611fb957fe5b6001811115611fc457fe5b815290546201000090046001600160a01b03166020909101528051909150611ffe5760405162461bcd60e51b815260040161055290612ed1565b600081604001516001600160a01b031663bb7b8b806040518163ffffffff1660e01b815260040160206040518083038186803b15801561203d57600080fd5b505afa158015612051573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506120759190810190612891565b905060008260200151600181111561208957fe5b14156120985791506117d79050565b6117d26116b86121ee565b60035460405163bcfd032d60e01b815260009182916001600160a01b039091169063bcfd032d906120da9087908790600401612d22565b60a06040518083038186803b1580156120f257600080fd5b505afa158015612106573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061212a91908101906128af565b505050915050600081136121505760405162461bcd60e51b815260040161055290612e81565b600354604051630b1c5a7560e31b81526121e69183916001600160a01b03909116906358e2d3a8906121889089908990600401612d22565b60206040518083038186803b1580156121a057600080fd5b505afa1580156121b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506121d89190810190612924565b60ff16601203600a0a612220565b949350505050565b600064e8d4a5100061221373a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4861189a565b8161221a57fe5b04905090565b6000611a1783836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f7700000000000000000081525061245c565b6002546040516317a6948f60e21b81526000916001600160a01b031690635e9a523c90612293908590600401612d14565b60206040518083038186803b1580156122ab57600080fd5b505afa1580156122bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506118949190810190612891565b6000816122f2575060006117d7565b816001600160801b821061230b5760809190911c9060401b5b6801000000000000000082106123265760409190911c9060201b5b640100000000821061233d5760209190911c9060101b5b6201000082106123525760109190911c9060081b5b61010082106123665760089190911c9060041b5b601082106123795760049190911c9060021b5b600882106123855760011b5b600181858161239057fe5b048201901c905060018185816123a257fe5b048201901c905060018185816123b457fe5b048201901c905060018185816123c657fe5b048201901c905060018185816123d857fe5b048201901c905060018185816123ea57fe5b048201901c905060018185816123fc57fe5b048201901c9050600081858161240e57fe5b04905080821061241e5780612420565b815b95945050505050565b6000611a1783836040518060400160405280600e81526020016d646976696465206279207a65726f60901b8152506124ad565b6000831580612469575082155b1561247657506000611a17565b8383028385828161248357fe5b041483906124a45760405162461bcd60e51b81526004016105529190612e30565b50949350505050565b600081836124ce5760405162461bcd60e51b81526004016105529190612e30565b508284816124d857fe5b04949350505050565b604080516060810182526000808252602082018190529181019190915290565b604080518082019091526000808252602082015290565b6040805160608101909152600080825260208201908152600060209091015290565b803561189481612fec565b805161189481612fec565b60008083601f84011261256257600080fd5b50813567ffffffffffffffff81111561257a57600080fd5b60208301915083602082028301111561259257600080fd5b9250929050565b803561189481613000565b805161189481613000565b803561189481613009565b803561189481613012565b80356118948161301f565b80516118948161302c565b805161189481613035565b80356118948161302c565b80516118948161303e565b805161189481613050565b805161189481613047565b60006020828403121561262457600080fd5b60006121e6848461253a565b60006020828403121561264257600080fd5b60006121e68484612545565b6000806000806040858703121561266457600080fd5b843567ffffffffffffffff81111561267b57600080fd5b61268787828801612550565b9450945050602085013567ffffffffffffffff8111156126a657600080fd5b6126b287828801612550565b95989497509550505050565b6000806000806000806000806080898b0312156126da57600080fd5b883567ffffffffffffffff8111156126f157600080fd5b6126fd8b828c01612550565b9850985050602089013567ffffffffffffffff81111561271c57600080fd5b6127288b828c01612550565b9650965050604089013567ffffffffffffffff81111561274757600080fd5b6127538b828c01612550565b9450945050606089013567ffffffffffffffff81111561277257600080fd5b61277e8b828c01612550565b92509250509295985092959890939650565b6000602082840312156127a257600080fd5b60006121e68484612599565b6000602082840312156127c057600080fd5b60006121e684846125a4565b6000602082840312156127de57600080fd5b60006121e684846125af565b6000602082840312156127fc57600080fd5b60006121e684846125ba565b60006020828403121561281a57600080fd5b60006121e684846125c5565b60008060006060848603121561283b57600080fd5b600061284786866125db565b9350506020612858868287016125db565b9250506040612869868287016125f1565b9150509250925092565b60006020828403121561288557600080fd5b60006121e684846125e6565b6000602082840312156128a357600080fd5b60006121e684846125d0565b600080600080600060a086880312156128c757600080fd5b60006128d388886125fc565b95505060206128e4888289016125d0565b94505060406128f5888289016125d0565b9350506060612906888289016125d0565b9250506080612917888289016125fc565b9150509295509295909350565b60006020828403121561293657600080fd5b60006121e68484612607565b61294b81612f3c565b82525050565b61294b81612f47565b61294b81612f4c565b61294b81612f9a565b600061297782612f2f565b6129818185612f33565b9350612991818560208601612fa5565b61299a81612fd5565b9093019392505050565b60006129af82612f2f565b6129b981856117d7565b93506129c9818560208601612fa5565b9290920192915050565b60006129e0601683612f33565b751859d9dc9959d85d1bdc881b9bdd08195b98589b195960521b815260200192915050565b6000612a12602083612f33565b7f6f6e6c79207468652061646d696e206d617920736574206e65772061646d696e815260200192915050565b6000612a4b600f83612f33565b6e6d69736d617463686564206461746160881b815260200192915050565b6000612a76601283612f33565b713737ba1030902cbb30bab63a103a37b5b2b760711b815260200192915050565b6000612aa4600d83612f33565b6c696e76616c696420707269636560981b815260200192915050565b6000612acd600e83612f33565b6d1a5b98dbdc9c9958dd081c1bdbdb60921b815260200192915050565b6000612af7603283612f33565b7f6f6e6c79207468652061646d696e206f7220677561726469616e206d617920738152716574207468652061676772656761746f727360701b602082015260400192915050565b6000612b4b602383612f33565b7f6f6e6c79207468652061646d696e206d617920736574206e657720677561726481526234b0b760e91b602082015260400192915050565b6000612b90601a83612f33565b7f6f6e6c79207468652061646d696e206d617920736574204c5073000000000000815260200192915050565b6000612bc9601683612f33565b753737ba10309031bab93b32903837b7b6103a37b5b2b760511b815260200192915050565b6000612bfb601883612f33565b7f756e737570706f727465642064656e6f6d696e6174696f6e0000000000000000815260200192915050565b6000612c34602883612f33565b7f6f6e6c79207468652061646d696e206d61792073657420637572766520706f6f8152676c20746f6b656e7360c01b602082015260400192915050565b6000612c7e602483612f33565b7f6f6e6c79207468652061646d696e206d61792073657420597661756c7420746f8152636b656e7360e01b602082015260400192915050565b6000612cc4602683612f33565b7f677561726469616e206d6179206f6e6c7920636c65617220746865206167677281526532b3b0ba37b960d11b602082015260400192915050565b61294b81612f61565b6000611a1782846129a4565b602081016118948284612942565b60408101612d308285612942565b611a176020830184612942565b60808101612d4b8287612942565b612d586020830186612942565b612d656040830185612942565b6124206060830184612951565b60608101612d808286612942565b612d8d6020830185612942565b6121e66040830184612951565b60408101612da88285612942565b611a176020830184612951565b60608101612dc38286612942565b612dd06020830185612963565b6121e66040830184612942565b60408101612deb8285612942565b611a176020830184612963565b602081016118948284612951565b60608101612dc38286612951565b60408101612deb8285612951565b60208101611894828461295a565b60208082528101611a17818461296c565b60208082528101611894816129d3565b6020808252810161189481612a05565b6020808252810161189481612a3e565b6020808252810161189481612a69565b6020808252810161189481612a97565b6020808252810161189481612ac0565b6020808252810161189481612aea565b6020808252810161189481612b3e565b6020808252810161189481612b83565b6020808252810161189481612bbc565b6020808252810161189481612bee565b6020808252810161189481612c27565b6020808252810161189481612c71565b6020808252810161189481612cb7565b602081016118948284612cff565b5190565b90815260200190565b600061189482612f70565b151590565b600061189482612f3c565b806117d781612fdf565b90565b6001600160701b031690565b6001600160a01b031690565b63ffffffff1690565b60ff1690565b69ffffffffffffffffffff1690565b600061189482612f57565b60005b83811015612fc0578181015183820152602001612fa8565b83811115612fcf576000848401525b50505050565b601f01601f191690565b60028110612fe957fe5b50565b612ff581612f3c565b8114612fe957600080fd5b612ff581612f47565b612ff581612f4c565b60028110612fe957600080fd5b60038110612fe957600080fd5b612ff581612f61565b612ff581612f64565b612ff581612f7c565b612ff581612f85565b612ff581612f8b56fea365627a7a72315820cf7040c3ffe9f39fc36a9139a5103bf7f4c151463a9d3e37356d0af5f45012516c6578706572696d656e74616cf564736f6c6343000511004000000000000000000000000011690b00fef3091f37dd0f88e36c838cd344547f0000000000000000000000009a975fe93cff8b0387b958adb9082b0ed0659ad2000000000000000000000000d06527d5e56a3495252a528c4987003b712860ee00000000000000000000000047fb2585d2c56fe188d0e6ec628a38b74fceeedf
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102695760003560e01c80637582bf5211610151578063ca9d1a72116100c3578063f249653811610087578063f249653814610462578063f37fcc4214610475578063f851a4401461047d578063fc57d4df14610485578063fd760c49146104a5578063fe10c98d146104ad57610269565b8063ca9d1a721461042f578063d9355bb814610437578063e38e8c0f1461043f578063e774928e14610452578063efaa41341461045a57610269565b8063976d5e7711610115578063976d5e77146103cf5780639db2a472146103d75780639e09f0c2146103df578063a0d0c0d814610401578063a364136014610414578063a4a235951461042757610269565b80637582bf521461036b5780637b1039991461037e5780638322fff2146103935780638e2dd6591461039b5780638e919267146103bc57610269565b8063294a2bf2116101ea578063465bd0a3116101ae578063465bd0a31461032e5780634f0e0ef31461033657806353f7c3671461033e57806356ef45141461034657806366331bba1461034e5780636b09583c1461036357610269565b8063294a2bf2146102fb5780632e79477f146103035780632ed58e151461030b5780633a74a76714610313578063452a93201461032657610269565b806315b102e31161023157806315b102e3146102c657806316daaff4146102ce57806319342a64146102e35780631bf6c21b146102eb5780632792949d146102f357610269565b806301b8b3391461026e57806302d454571461028c57806303d698f2146102945780630c0128341461029c578063112cdab9146102a4575b600080fd5b6102766104b5565b6040516102839190612d14565b60405180910390f35b6102766104bb565b6102766104d3565b6102766104d9565b6102b76102b2366004612612565b6104de565b60405161028393929190612d72565b610276610510565b6102e16102dc3660046126be565b610528565b005b610276610868565b61027661086d565b610276610873565b61027661088b565b610276610891565b610276610897565b6102e1610321366004612612565b6108a6565b61027661092c565b61027661093b565b610276610941565b610276610959565b61027661095f565b610356610965565b6040516102839190612df8565b61027661096a565b610356610379366004612612565b610970565b610386610985565b6040516102839190612e22565b610276610994565b6103ae6103a9366004612612565b6109ac565b604051610283929190612e14565b6102e16103ca36600461264e565b6109ca565b610276610cb8565b610276610cbe565b6103f26103ed366004612612565b610cc4565b60405161028393929190612e06565b6102e161040f36600461264e565b610cf4565b610276610422366004612873565b610f82565b610276610f9f565b610276610fa4565b610276610faa565b6102e161044d366004612612565b610fc2565b61027661103d565b610276611043565b6102e161047036600461264e565b61105b565b6102766115a9565b6102766115af565b6104986104933660046127cc565b6115be565b6040516102839190612f21565b6102766117dc565b6103866117e1565b61033a81565b73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b61023681565b602081565b600460205260009081526040902080546001909101546001600160a01b0391821691811690600160a01b900460ff1683565b73851a040fc0dcbb13a272ebc272f2bc2ce1e11c4d81565b6000546001600160a01b0316331461055b5760405162461bcd60e51b815260040161055290612ef1565b60405180910390fd5b868514801561056957508683145b801561057457508681145b6105905760405162461bcd60e51b815260040161055290612e61565b60005b8781101561085d5760028787838181106105a957fe5b90506020020160206105be9190810190612808565b60028111156105c957fe5b14156106b0578282828181106105db57fe5b90506020020160206105f09190810190612612565b6001600160a01b031689898381811061060557fe5b905060200201602061061a9190810190612612565b6001600160a01b031663075461726040518163ffffffff1660e01b815260040160206040518083038186803b15801561065257600080fd5b505afa158015610666573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061068a9190810190612630565b6001600160a01b0316146106b05760405162461bcd60e51b815260040161055290612e91565b60405180606001604052806001151581526020018686848181106106d057fe5b90506020020160206106e591908101906127ea565b60018111156106f057fe5b815260200184848481811061070157fe5b90506020020160206107169190810190612612565b6001600160a01b03169052600760008b8b8581811061073157fe5b90506020020160206107469190810190612612565b6001600160a01b031681526020808201929092526040016000208251815460ff191690151517808255918301519091829061ff00191661010083600181111561078b57fe5b02179055506040919091015181546001600160a01b03909116620100000262010000600160b01b03199091161790557fe589de78805ec500bf23a096c2f92013247fd931aeb72be9bdeaa04ed4863ceb8989838181106107e757fe5b90506020020160206107fc9190810190612612565b86868481811061080857fe5b905060200201602061081d91908101906127ea565b85858581811061082957fe5b905060200201602061083e9190810190612612565b60405161084d93929190612db5565b60405180910390a1600101610593565b505050505050505050565b607c81565b61034881565b73bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb81565b6103d281565b6102be81565b600e546001600160a01b031681565b6000546001600160a01b031633146108d05760405162461bcd60e51b815260040161055290612e51565b600080546001600160a01b0319166001600160a01b0383811691909117918290556040517f5a272403b402d892977df56625f4164ccaf70ca3863991c43ecfe76a6905b0a192610921921690612d14565b60405180910390a150565b6001546001600160a01b031681565b61018881565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b61026081565b61019a81565b600181565b6103da81565b60056020526000908152604090205460ff1681565b6003546001600160a01b031681565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b60066020526000908152604090205460ff8082169161010090041682565b6000546001600160a01b031633146109f45760405162461bcd60e51b815260040161055290612f01565b828114610a135760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb1576000838383818110610a2c57fe5b9050602002016020610a4191908101906127ea565b6001811115610a4c57fe5b1415610ae957848482818110610a5e57fe5b9050602002016020610a739190810190612612565b6001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b158015610aab57600080fd5b505afa158015610abf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610ae39190810190612891565b50610b7c565b848482818110610af557fe5b9050602002016020610b0a9190810190612612565b6001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015610b4257600080fd5b505afa158015610b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b7a9190810190612891565b505b6040518060400160405280600115158152602001848484818110610b9c57fe5b9050602002016020610bb191908101906127ea565b6001811115610bbc57fe5b905260066000878785818110610bce57fe5b9050602002016020610be39190810190612612565b6001600160a01b031681526020808201929092526040016000208251815460ff191690151517808255918301519091829061ff001916610100836001811115610c2857fe5b02179055509050507f40b251634471b85d185d32f7f33380d815ce735c0bae07cdeb8657a38402ddaa858583818110610c5d57fe5b9050602002016020610c729190810190612612565b848484818110610c7e57fe5b9050602002016020610c9391908101906127ea565b604051610ca1929190612ddd565b60405180910390a1600101610a16565b5050505050565b61028381565b6102c681565b60076020526000908152604090205460ff808216916101008104909116906201000090046001600160a01b031683565b6000546001600160a01b03163314610d1e5760405162461bcd60e51b815260040161055290612ec1565b828114610d3d5760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb157828282818110610d5457fe5b9050602002016020610d699190810190612790565b60056000878785818110610d7957fe5b9050602002016020610d8e9190810190612612565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055828282818110610dc257fe5b9050602002016020610dd79190810190612790565b15610f0157848482818110610de857fe5b9050602002016020610dfd9190810190612612565b6001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015610e3557600080fd5b505afa158015610e49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610e6d9190810190612630565b50848482818110610e7a57fe5b9050602002016020610e8f9190810190612612565b6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610ec757600080fd5b505afa158015610edb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610eff9190810190612630565b505b7f0cdeca791f00903a9a063565b4d2d5295eaef5ba38390319391986dca98cd7cf858583818110610f2e57fe5b9050602002016020610f439190810190612612565b848484818110610f4f57fe5b9050602002016020610f649190810190612790565b604051610f72929190612d9a565b60405180910390a1600101610d40565b60088160068110610f8f57fe5b01546001600160a01b0316905081565b609c81565b61022a81565b73228619cca194fbe3ebeb2f835ec1ea5080dafbb281565b6000546001600160a01b03163314610fec5760405162461bcd60e51b815260040161055290612eb1565b600180546001600160a01b0319166001600160a01b0383811691909117918290556040517f31845eceb9cde510c7e8b37f76301c688feb70bc9653aa4c28a3734999840fd892610921921690612d14565b61016481565b736b3595068778dd592e39a122f4f5a5cf09c90fe281565b6000546001600160a01b031633148061107e57506001546001600160a01b031633145b61109a5760405162461bcd60e51b815260040161055290612ea1565b8281146110b95760405162461bcd60e51b815260040161055290612e61565b60005b83811015610cb15760008060008585858181106110d557fe5b602002820190508035601e19368490030181126110f157600080fd5b9091016020810191503567ffffffffffffffff81111561111057600080fd5b3681900382131561112057600080fd5b159050611485576000546001600160a01b031633146111515760405162461bcd60e51b815260040161055290612f11565b50600187878581811061116057fe5b90506020020160206111759190810190612612565b92506111a088888681811061118657fe5b905060200201602061119b9190810190612612565b6117f0565b156111bd5773bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb92505b61126c8686868181106111cc57fe5b602002820190508035601e19368490030181126111e857600080fd5b9091016020810191503567ffffffffffffffff81111561120757600080fd5b3681900382131561121757600080fd5b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051808201909152600381526208aa8960eb1b602082015291506118409050565b1561128d5773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee9150611363565b61133c86868681811061129c57fe5b602002820190508035601e19368490030181126112b857600080fd5b9091016020810191503567ffffffffffffffff8111156112d757600080fd5b368190038213156112e757600080fd5b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250506040805180820190915260038152621554d160ea1b602082015291506118409050565b1561134b576103489150611363565b60405162461bcd60e51b815260040161055290612ee1565b60035460405163d2edb6dd60e01b81526000916001600160a01b03169063d2edb6dd906113969087908790600401612d22565b60206040518083038186803b1580156113ae57600080fd5b505afa1580156113c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113e69190810190612630565b60035460405163b099d43b60e01b81529192506001600160a01b03169063b099d43b90611417908490600401612d14565b60206040518083038186803b15801561142f57600080fd5b505afa158015611443573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061146791908101906127ae565b6114835760405162461bcd60e51b815260040161055290612e41565b505b6040518060600160405280846001600160a01b03168152602001836001600160a01b03168152602001821515815250600460008a8a888181106114c457fe5b90506020020160206114d99190810190612612565b6001600160a01b0390811682526020808301939093526040918201600020845181549083166001600160a01b0319918216178255938501516001909101805495909301511515600160a01b0260ff60a01b19919092169490931693909317919091169190911790557f1ce411df4a158aa72e588cc62a13841fd7f7e644f81b10b60b90cb97b9017fa788888681811061156e57fe5b90506020020160206115839190810190612612565b8484846040516115969493929190612d3d565b60405180910390a15050506001016110bc565b6102f481565b6000546001600160a01b031681565b600e5460009082906001600160a01b03808316911614156115ea57670de0b6b3a76400009150506117d7565b6001600160a01b03811673228619cca194fbe3ebeb2f835ec1ea5080dafbb214156116d557600073851a040fc0dcbb13a272ebc272f2bc2ce1e11c4d6001600160a01b031663e6aa216c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561165e57600080fd5b505afa158015611672573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506116969190810190612891565b90506116cc6116b8736b3595068778dd592e39a122f4f5a5cf09c90fe261189a565b604051806020016040528084815250611a1e565b925050506117d7565b6000816001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561171057600080fd5b505afa158015611724573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506117489190810190612630565b6001600160a01b03811660009081526005602052604090205490915060ff1615611775576116cc81611a46565b6001600160a01b03811660009081526006602052604090205460ff161561179f576116cc81611c9e565b6001600160a01b03811660009081526007602052604090205460ff16156117c9576116cc81611f68565b6117d28161189a565b925050505b919050565b602481565b6002546001600160a01b031681565b6000805b600681101561183757826001600160a01b03166008826006811061181457fe5b01546001600160a01b0316141561182f5760019150506117d7565b6001016117f4565b50600092915050565b6000816040516020016118539190612d08565b604051602081830303815290604052805190602001208360405160200161187a9190612d08565b604051602081830303815290604052805190602001201490505b92915050565b60006001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214156118d05750670de0b6b3a76400006117d7565b6118d86124e1565b506001600160a01b03828116600090815260046020908152604091829020825160608101845281548516815260019091015493841691810191909152600160a01b90920460ff1615801591830191909152611a0e576000611941826000015183602001516120a3565b60208301519091506001600160a01b0316610348141561197c576119798160405180602001604052806119726121ee565b9052611a1e565b90505b6000846001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156119b757600080fd5b505afa1580156119cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506119ef9190810190612924565b60ff169050611a048282601203600a0a612220565b93505050506117d7565b611a1783612262565b9392505050565b6000670de0b6b3a7640000611a37848460000151612220565b81611a3e57fe5b049392505050565b600080826001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611a8257600080fd5b505afa158015611a96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611aba9190810190612630565b90506000836001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611af757600080fd5b505afa158015611b0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611b2f9190810190612630565b90506000846001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015611b6c57600080fd5b505afa158015611b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611ba49190810190612891565b9050600080866001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611be257600080fd5b505afa158015611bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c1a9190810190612826565b506001600160701b031691506001600160701b031691506000611c45611c408484612220565b6122e3565b90506000611c528761189a565b90506000611c5f8761189a565b90506000611c70611c408484612220565b9050611c8f611c896002611c848785612220565b612220565b88612429565b9b9a5050505050505050505050565b6000611ca8612501565b6001600160a01b0383166000908152600660209081526040918290208251808401909352805460ff808216151585529192840191610100909104166001811115611cee57fe5b6001811115611cf957fe5b9052508051909150611d1d5760405162461bcd60e51b815260040161055290612e71565b6000808083602001516001811115611d3157fe5b1415611e2257846001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b158015611d7057600080fd5b505afa158015611d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611da89190810190612891565b9150846001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611de357600080fd5b505afa158015611df7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611e1b9190810190612630565b9050611f09565b846001600160a01b03166399530b066040518163ffffffff1660e01b815260040160206040518083038186803b158015611e5b57600080fd5b505afa158015611e6f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611e939190810190612891565b9150846001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015611ece57600080fd5b505afa158015611ee2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611f069190810190612630565b90505b6001600160a01b03811660009081526007602052604081205460ff1615611f3a57611f3382611f68565b9050611f46565b611f438261189a565b90505b611f5e81604051806020016040528086815250611a1e565b9695505050505050565b6000611f72612518565b6001600160a01b038316600090815260076020908152604091829020825160608101909352805460ff808216151585529192840191610100909104166001811115611fb957fe5b6001811115611fc457fe5b815290546201000090046001600160a01b03166020909101528051909150611ffe5760405162461bcd60e51b815260040161055290612ed1565b600081604001516001600160a01b031663bb7b8b806040518163ffffffff1660e01b815260040160206040518083038186803b15801561203d57600080fd5b505afa158015612051573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506120759190810190612891565b905060008260200151600181111561208957fe5b14156120985791506117d79050565b6117d26116b86121ee565b60035460405163bcfd032d60e01b815260009182916001600160a01b039091169063bcfd032d906120da9087908790600401612d22565b60a06040518083038186803b1580156120f257600080fd5b505afa158015612106573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061212a91908101906128af565b505050915050600081136121505760405162461bcd60e51b815260040161055290612e81565b600354604051630b1c5a7560e31b81526121e69183916001600160a01b03909116906358e2d3a8906121889089908990600401612d22565b60206040518083038186803b1580156121a057600080fd5b505afa1580156121b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506121d89190810190612924565b60ff16601203600a0a612220565b949350505050565b600064e8d4a5100061221373a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4861189a565b8161221a57fe5b04905090565b6000611a1783836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f7700000000000000000081525061245c565b6002546040516317a6948f60e21b81526000916001600160a01b031690635e9a523c90612293908590600401612d14565b60206040518083038186803b1580156122ab57600080fd5b505afa1580156122bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506118949190810190612891565b6000816122f2575060006117d7565b816001600160801b821061230b5760809190911c9060401b5b6801000000000000000082106123265760409190911c9060201b5b640100000000821061233d5760209190911c9060101b5b6201000082106123525760109190911c9060081b5b61010082106123665760089190911c9060041b5b601082106123795760049190911c9060021b5b600882106123855760011b5b600181858161239057fe5b048201901c905060018185816123a257fe5b048201901c905060018185816123b457fe5b048201901c905060018185816123c657fe5b048201901c905060018185816123d857fe5b048201901c905060018185816123ea57fe5b048201901c905060018185816123fc57fe5b048201901c9050600081858161240e57fe5b04905080821061241e5780612420565b815b95945050505050565b6000611a1783836040518060400160405280600e81526020016d646976696465206279207a65726f60901b8152506124ad565b6000831580612469575082155b1561247657506000611a17565b8383028385828161248357fe5b041483906124a45760405162461bcd60e51b81526004016105529190612e30565b50949350505050565b600081836124ce5760405162461bcd60e51b81526004016105529190612e30565b508284816124d857fe5b04949350505050565b604080516060810182526000808252602082018190529181019190915290565b604080518082019091526000808252602082015290565b6040805160608101909152600080825260208201908152600060209091015290565b803561189481612fec565b805161189481612fec565b60008083601f84011261256257600080fd5b50813567ffffffffffffffff81111561257a57600080fd5b60208301915083602082028301111561259257600080fd5b9250929050565b803561189481613000565b805161189481613000565b803561189481613009565b803561189481613012565b80356118948161301f565b80516118948161302c565b805161189481613035565b80356118948161302c565b80516118948161303e565b805161189481613050565b805161189481613047565b60006020828403121561262457600080fd5b60006121e6848461253a565b60006020828403121561264257600080fd5b60006121e68484612545565b6000806000806040858703121561266457600080fd5b843567ffffffffffffffff81111561267b57600080fd5b61268787828801612550565b9450945050602085013567ffffffffffffffff8111156126a657600080fd5b6126b287828801612550565b95989497509550505050565b6000806000806000806000806080898b0312156126da57600080fd5b883567ffffffffffffffff8111156126f157600080fd5b6126fd8b828c01612550565b9850985050602089013567ffffffffffffffff81111561271c57600080fd5b6127288b828c01612550565b9650965050604089013567ffffffffffffffff81111561274757600080fd5b6127538b828c01612550565b9450945050606089013567ffffffffffffffff81111561277257600080fd5b61277e8b828c01612550565b92509250509295985092959890939650565b6000602082840312156127a257600080fd5b60006121e68484612599565b6000602082840312156127c057600080fd5b60006121e684846125a4565b6000602082840312156127de57600080fd5b60006121e684846125af565b6000602082840312156127fc57600080fd5b60006121e684846125ba565b60006020828403121561281a57600080fd5b60006121e684846125c5565b60008060006060848603121561283b57600080fd5b600061284786866125db565b9350506020612858868287016125db565b9250506040612869868287016125f1565b9150509250925092565b60006020828403121561288557600080fd5b60006121e684846125e6565b6000602082840312156128a357600080fd5b60006121e684846125d0565b600080600080600060a086880312156128c757600080fd5b60006128d388886125fc565b95505060206128e4888289016125d0565b94505060406128f5888289016125d0565b9350506060612906888289016125d0565b9250506080612917888289016125fc565b9150509295509295909350565b60006020828403121561293657600080fd5b60006121e68484612607565b61294b81612f3c565b82525050565b61294b81612f47565b61294b81612f4c565b61294b81612f9a565b600061297782612f2f565b6129818185612f33565b9350612991818560208601612fa5565b61299a81612fd5565b9093019392505050565b60006129af82612f2f565b6129b981856117d7565b93506129c9818560208601612fa5565b9290920192915050565b60006129e0601683612f33565b751859d9dc9959d85d1bdc881b9bdd08195b98589b195960521b815260200192915050565b6000612a12602083612f33565b7f6f6e6c79207468652061646d696e206d617920736574206e65772061646d696e815260200192915050565b6000612a4b600f83612f33565b6e6d69736d617463686564206461746160881b815260200192915050565b6000612a76601283612f33565b713737ba1030902cbb30bab63a103a37b5b2b760711b815260200192915050565b6000612aa4600d83612f33565b6c696e76616c696420707269636560981b815260200192915050565b6000612acd600e83612f33565b6d1a5b98dbdc9c9958dd081c1bdbdb60921b815260200192915050565b6000612af7603283612f33565b7f6f6e6c79207468652061646d696e206f7220677561726469616e206d617920738152716574207468652061676772656761746f727360701b602082015260400192915050565b6000612b4b602383612f33565b7f6f6e6c79207468652061646d696e206d617920736574206e657720677561726481526234b0b760e91b602082015260400192915050565b6000612b90601a83612f33565b7f6f6e6c79207468652061646d696e206d617920736574204c5073000000000000815260200192915050565b6000612bc9601683612f33565b753737ba10309031bab93b32903837b7b6103a37b5b2b760511b815260200192915050565b6000612bfb601883612f33565b7f756e737570706f727465642064656e6f6d696e6174696f6e0000000000000000815260200192915050565b6000612c34602883612f33565b7f6f6e6c79207468652061646d696e206d61792073657420637572766520706f6f8152676c20746f6b656e7360c01b602082015260400192915050565b6000612c7e602483612f33565b7f6f6e6c79207468652061646d696e206d61792073657420597661756c7420746f8152636b656e7360e01b602082015260400192915050565b6000612cc4602683612f33565b7f677561726469616e206d6179206f6e6c7920636c65617220746865206167677281526532b3b0ba37b960d11b602082015260400192915050565b61294b81612f61565b6000611a1782846129a4565b602081016118948284612942565b60408101612d308285612942565b611a176020830184612942565b60808101612d4b8287612942565b612d586020830186612942565b612d656040830185612942565b6124206060830184612951565b60608101612d808286612942565b612d8d6020830185612942565b6121e66040830184612951565b60408101612da88285612942565b611a176020830184612951565b60608101612dc38286612942565b612dd06020830185612963565b6121e66040830184612942565b60408101612deb8285612942565b611a176020830184612963565b602081016118948284612951565b60608101612dc38286612951565b60408101612deb8285612951565b60208101611894828461295a565b60208082528101611a17818461296c565b60208082528101611894816129d3565b6020808252810161189481612a05565b6020808252810161189481612a3e565b6020808252810161189481612a69565b6020808252810161189481612a97565b6020808252810161189481612ac0565b6020808252810161189481612aea565b6020808252810161189481612b3e565b6020808252810161189481612b83565b6020808252810161189481612bbc565b6020808252810161189481612bee565b6020808252810161189481612c27565b6020808252810161189481612c71565b6020808252810161189481612cb7565b602081016118948284612cff565b5190565b90815260200190565b600061189482612f70565b151590565b600061189482612f3c565b806117d781612fdf565b90565b6001600160701b031690565b6001600160a01b031690565b63ffffffff1690565b60ff1690565b69ffffffffffffffffffff1690565b600061189482612f57565b60005b83811015612fc0578181015183820152602001612fa8565b83811115612fcf576000848401525b50505050565b601f01601f191690565b60028110612fe957fe5b50565b612ff581612f3c565b8114612fe957600080fd5b612ff581612f47565b612ff581612f4c565b60028110612fe957600080fd5b60038110612fe957600080fd5b612ff581612f61565b612ff581612f64565b612ff581612f7c565b612ff581612f85565b612ff581612f8b56fea365627a7a72315820cf7040c3ffe9f39fc36a9139a5103bf7f4c151463a9d3e37356d0af5f45012516c6578706572696d656e74616cf564736f6c63430005110040
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000011690b00fef3091f37dd0f88e36c838cd344547f0000000000000000000000009a975fe93cff8b0387b958adb9082b0ed0659ad2000000000000000000000000d06527d5e56a3495252a528c4987003b712860ee00000000000000000000000047fb2585d2c56fe188d0e6ec628a38b74fceeedf
-----Decoded View---------------
Arg [0] : admin_ (address): 0x11690B00Fef3091f37Dd0F88e36c838Cd344547f
Arg [1] : v1PriceOracle_ (address): 0x9A975fe93CFf8b0387b958adB9082B0ed0659AD2
Arg [2] : cEthAddress_ (address): 0xD06527D5e56A3495252A528C4987003b712860eE
Arg [3] : registry_ (address): 0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 00000000000000000000000011690b00fef3091f37dd0f88e36c838cd344547f
Arg [1] : 0000000000000000000000009a975fe93cff8b0387b958adb9082b0ed0659ad2
Arg [2] : 000000000000000000000000d06527d5e56a3495252a528c4987003b712860ee
Arg [3] : 00000000000000000000000047fb2585d2c56fe188d0e6ec628a38b74fceeedf
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.