Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
This contract has been partially verified via Sourcify.
View contract in Sourcify repository
- Contract name:
- BaseV1Router01
- Optimization enabled
- true
- Compiler version
- v0.8.11+commit.d7f03943
- Optimization runs
- 200
- EVM Version
- london
- Verified at
- 2023-07-07T23:49:35.598890Z
contracts/BaseV1-periphery.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.11; import "./CToken.sol"; import "./PriceOracle.sol"; import "./BaseV1-libs.sol"; interface IBaseV1Factory { function allPairsLength() external view returns (uint); function isPair(address pair) external view returns (bool); function pairCodeHash() external pure returns (bytes32); function getPair(address tokenA, address token, bool stable) external view returns (address); function createPair(address tokenA, address tokenB, bool stable) external returns (address); } interface IBaseV1Pair { function transferFrom(address src, address dst, uint amount) external returns (bool); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function burn(address to) external returns (uint amount0, uint amount1); function mint(address to) external returns (uint liquidity); function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast); function getAmountOut(uint, address) external view returns (uint); function current(address tokenIn, uint amountIn) external view returns(uint); function token0() external view returns(address); function token1() external view returns(address); function stable() external view returns(bool); function _k(uint x, uint y) external view returns(uint); //LP token pricing function sampleReserves(uint points, uint window) external view returns(uint[] memory, uint[] memory); function sampleSupply(uint points, uint window) external view returns(uint[] memory); function sample(address tokenIn, uint amountIn, uint points, uint window) external view returns(uint[] memory); function quote(address tokenIn, uint amountIn, uint granularity) external view returns(uint); } interface IWCANTO { function deposit() external payable ; function transfer(address to, uint value) external returns (bool); function withdraw(uint) external ; } interface ICErc20 { function underlying() external view returns(address); } contract BaseV1Router01 is PriceOracle { //address of Unitroller to obtain prices with respect to USDC address public immutable note; //address of Comptroller, so that price of note may be set to 1 in Account Liquidity calculations address public immutable Comptroller; address public admin; struct route { address from; address to; bool stable; } address public immutable factory; IWCANTO public immutable wcanto; uint internal constant MINIMUM_LIQUIDITY = 10**3; bytes32 immutable pairCodeHash; mapping(address => bool) public isStable; error SenderNotAdmin(address sender, address admin); modifier ensure(uint deadline) { require(deadline >= block.timestamp, "BaseV1Router: EXPIRED"); _; } constructor(address _factory, address _wcanto, address note_, address Comptroller_) { factory = _factory; pairCodeHash = IBaseV1Factory(_factory).pairCodeHash(); wcanto = IWCANTO(_wcanto); note = note_; Comptroller = Comptroller_; admin = msg.sender; } receive() external payable { assert(msg.sender == address(wcanto)); // only accept ETH via fallback from the WETH contract } // admin for setting the stable pairs function setAdmin(address admin_) external { require(msg.sender == admin); admin = admin_; } function sortTokens(address tokenA, address tokenB) public pure returns (address token0, address token1) { require(tokenA != tokenB, "BaseV1Router: IDENTICAL_ADDRESSES"); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), "BaseV1Router: ZERO_ADDRESS"); } // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB, bool stable) public view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = address(uint160(uint256(keccak256(abi.encodePacked( hex"ff", factory, keccak256(abi.encodePacked(token0, token1, stable)), pairCodeHash // init code hash ))))); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quoteLiquidity(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, "BaseV1Router: INSUFFICIENT_AMOUNT"); require(reserveA > 0 && reserveB > 0, "BaseV1Router: INSUFFICIENT_LIQUIDITY"); amountB = amountA * reserveB / reserveA; } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB, bool stable) public view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IBaseV1Pair(pairFor(tokenA, tokenB, stable)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // performs chained getAmountOut calculations on any number of pairs function getAmountOut(uint amountIn, address tokenIn, address tokenOut) external view returns (uint amount, bool stable) { address pair = pairFor(tokenIn, tokenOut, true); uint amountStable; uint amountVolatile; if (IBaseV1Factory(factory).isPair(pair)) { amountStable = IBaseV1Pair(pair).getAmountOut(amountIn, tokenIn); } pair = pairFor(tokenIn, tokenOut, false); if (IBaseV1Factory(factory).isPair(pair)) { amountVolatile = IBaseV1Pair(pair).getAmountOut(amountIn, tokenIn); } return amountStable > amountVolatile ? (amountStable, true) : (amountVolatile, false); } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, route[] memory routes) public view returns (uint[] memory amounts) { require(routes.length >= 1, "BaseV1Router: INVALID_PATH"); amounts = new uint[](routes.length+1); amounts[0] = amountIn; for (uint i = 0; i < routes.length; i++) { address pair = pairFor(routes[i].from, routes[i].to, routes[i].stable); if (IBaseV1Factory(factory).isPair(pair)) { amounts[i+1] = IBaseV1Pair(pair).getAmountOut(amounts[i], routes[i].from); } } } function isPair(address pair) public view returns (bool) { return IBaseV1Factory(factory).isPair(pair); } function quoteAddLiquidity( address tokenA, address tokenB, bool stable, uint amountADesired, uint amountBDesired ) external view returns (uint amountA, uint amountB, uint liquidity) { // create the pair if it doesn"t exist yet address _pair = IBaseV1Factory(factory).getPair(tokenA, tokenB, stable); (uint reserveA, uint reserveB) = (0,0); uint _totalSupply = 0; if (_pair != address(0)) { _totalSupply = erc20(_pair).totalSupply(); (reserveA, reserveB) = getReserves(tokenA, tokenB, stable); } if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); liquidity = Math.sqrt(amountA * amountB) - MINIMUM_LIQUIDITY; } else { uint amountBOptimal = quoteLiquidity(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { (amountA, amountB) = (amountADesired, amountBOptimal); liquidity = Math.min(amountA * _totalSupply / reserveA, amountB * _totalSupply / reserveB); } else { uint amountAOptimal = quoteLiquidity(amountBDesired, reserveB, reserveA); (amountA, amountB) = (amountAOptimal, amountBDesired); liquidity = Math.min(amountA * _totalSupply / reserveA, amountB * _totalSupply / reserveB); } } } function quoteRemoveLiquidity( address tokenA, address tokenB, bool stable, uint liquidity ) public view returns (uint amountA, uint amountB) { // create the pair if it doesn"t exist yet address _pair = IBaseV1Factory(factory).getPair(tokenA, tokenB, stable); if (_pair == address(0)) { return (0,0); } (uint reserveA, uint reserveB) = getReserves(tokenA, tokenB, stable); uint _totalSupply = erc20(_pair).totalSupply(); amountA = liquidity * reserveA / _totalSupply; // using balances ensures pro-rata distribution amountB = liquidity * reserveB / _totalSupply; // using balances ensures pro-rata distribution } function _addLiquidity( address tokenA, address tokenB, bool stable, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin ) internal returns (uint amountA, uint amountB) { require(amountADesired >= amountAMin); require(amountBDesired >= amountBMin); // create the pair if it doesn"t exist yet address _pair = IBaseV1Factory(factory).getPair(tokenA, tokenB, stable); if (_pair == address(0)) { _pair = IBaseV1Factory(factory).createPair(tokenA, tokenB, stable); } (uint reserveA, uint reserveB) = getReserves(tokenA, tokenB, stable); if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); } else { uint amountBOptimal = quoteLiquidity(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { require(amountBOptimal >= amountBMin, "BaseV1Router: INSUFFICIENT_B_AMOUNT"); (amountA, amountB) = (amountADesired, amountBOptimal); } else { uint amountAOptimal = quoteLiquidity(amountBDesired, reserveB, reserveA); assert(amountAOptimal <= amountADesired); require(amountAOptimal >= amountAMin, "BaseV1Router: INSUFFICIENT_A_AMOUNT"); (amountA, amountB) = (amountAOptimal, amountBDesired); } } } function addLiquidity( address tokenA, address tokenB, bool stable, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) { (amountA, amountB) = _addLiquidity(tokenA, tokenB, stable, amountADesired, amountBDesired, amountAMin, amountBMin); address pair = pairFor(tokenA, tokenB, stable); _safeTransferFrom(tokenA, msg.sender, pair, amountA); _safeTransferFrom(tokenB, msg.sender, pair, amountB); liquidity = IBaseV1Pair(pair).mint(to); } function addLiquidityCANTO( address token, bool stable, uint amountTokenDesired, uint amountTokenMin, uint amountCANTOMin, address to, uint deadline ) external payable ensure(deadline) returns (uint amountToken, uint amountCANTO, uint liquidity) { (amountToken, amountCANTO) = _addLiquidity( token, address(wcanto), stable, amountTokenDesired, msg.value, amountTokenMin, amountCANTOMin ); address pair = pairFor(token, address(wcanto), stable); _safeTransferFrom(token, msg.sender, pair, amountToken); wcanto.deposit{value: amountCANTO}(); assert(wcanto.transfer(pair, amountCANTO)); liquidity = IBaseV1Pair(pair).mint(to); // refund dust eth, if any if (msg.value > amountCANTO) _safeTransferCANTO(msg.sender, msg.value - amountCANTO); } // **** REMOVE LIQUIDITY **** function removeLiquidity( address tokenA, address tokenB, bool stable, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public ensure(deadline) returns (uint amountA, uint amountB) { address pair = pairFor(tokenA, tokenB, stable); require(IBaseV1Pair(pair).transferFrom(msg.sender, pair, liquidity)); // send liquidity to pair (uint amount0, uint amount1) = IBaseV1Pair(pair).burn(to); (address token0,) = sortTokens(tokenA, tokenB); (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); require(amountA >= amountAMin, "BaseV1Router: INSUFFICIENT_A_AMOUNT"); require(amountB >= amountBMin, "BaseV1Router: INSUFFICIENT_B_AMOUNT"); } function removeLiquidityCANTO( address token, bool stable, uint liquidity, uint amountTokenMin, uint amountCANTOMin, address to, uint deadline ) public ensure(deadline) returns (uint amountToken, uint amountCANTO) { (amountToken, amountCANTO) = removeLiquidity( token, address(wcanto), stable, liquidity, amountTokenMin, amountCANTOMin, address(this), deadline ); _safeTransfer(token, to, amountToken); wcanto.withdraw(amountCANTO); _safeTransferCANTO(to, amountCANTO); } function removeLiquidityWithPermit( address tokenA, address tokenB, bool stable, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB) { address pair = pairFor(tokenA, tokenB, stable); { uint value = approveMax ? type(uint).max : liquidity; IBaseV1Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); } (amountA, amountB) = removeLiquidity(tokenA, tokenB, stable, liquidity, amountAMin, amountBMin, to, deadline); } function removeLiquidityCANTOWithPermit( address token, bool stable, uint liquidity, uint amountTokenMin, uint amountCANTOMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountCANTO) { address pair = pairFor(token, address(wcanto), stable); uint value = approveMax ? type(uint).max : liquidity; IBaseV1Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountToken, amountCANTO) = removeLiquidityCANTO(token, stable, liquidity, amountTokenMin, amountCANTOMin, to, deadline); } // **** SWAP **** // requires the initial amount to have already been sent to the first pair function _swap(uint[] memory amounts, route[] memory routes, address _to) internal virtual { for (uint i = 0; i < routes.length; i++) { (address token0,) = sortTokens(routes[i].from, routes[i].to); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = routes[i].from == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < routes.length - 1 ? pairFor(routes[i+1].from, routes[i+1].to, routes[i+1].stable) : _to; IBaseV1Pair(pairFor(routes[i].from, routes[i].to, routes[i].stable)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } function swapExactTokensForTokensSimple( uint amountIn, uint amountOutMin, address tokenFrom, address tokenTo, bool stable, address to, uint deadline ) external ensure(deadline) returns (uint[] memory amounts) { route[] memory routes = new route[](1); routes[0].from = tokenFrom; routes[0].to = tokenTo; routes[0].stable = stable; amounts = getAmountsOut(amountIn, routes); require(amounts[amounts.length - 1] >= amountOutMin, "BaseV1Router: INSUFFICIENT_OUTPUT_AMOUNT"); _safeTransferFrom( routes[0].from, msg.sender, pairFor(routes[0].from, routes[0].to, routes[0].stable), amounts[0] ); _swap(amounts, routes, to); } function swapExactTokensForTokens( uint amountIn, uint amountOutMin, route[] calldata routes, address to, uint deadline ) external ensure(deadline) returns (uint[] memory amounts) { amounts = getAmountsOut(amountIn, routes); require(amounts[amounts.length - 1] >= amountOutMin, "BaseV1Router: INSUFFICIENT_OUTPUT_AMOUNT"); _safeTransferFrom( routes[0].from, msg.sender, pairFor(routes[0].from, routes[0].to, routes[0].stable), amounts[0] ); _swap(amounts, routes, to); } function swapExactCANTOForTokens(uint amountOutMin, route[] calldata routes, address to, uint deadline) external payable ensure(deadline) returns (uint[] memory amounts) { require(routes[0].from == address(wcanto), "BaseV1Router: INVALID_PATH"); amounts = getAmountsOut(msg.value, routes); require(amounts[amounts.length - 1] >= amountOutMin, "BaseV1Router: INSUFFICIENT_OUTPUT_AMOUNT"); wcanto.deposit{value: amounts[0]}(); assert(wcanto.transfer(pairFor(routes[0].from, routes[0].to, routes[0].stable), amounts[0])); _swap(amounts, routes, to); } function swapExactTokensForCANTO(uint amountIn, uint amountOutMin, route[] calldata routes, address to, uint deadline) external ensure(deadline) returns (uint[] memory amounts) { require(routes[routes.length - 1].to == address(wcanto), "BaseV1Router: INVALID_PATH"); amounts = getAmountsOut(amountIn, routes); require(amounts[amounts.length - 1] >= amountOutMin, "BaseV1Router: INSUFFICIENT_OUTPUT_AMOUNT"); _safeTransferFrom( routes[0].from, msg.sender, pairFor(routes[0].from, routes[0].to, routes[0].stable), amounts[0] ); _swap(amounts, routes, address(this)); wcanto.withdraw(amounts[amounts.length - 1]); _safeTransferCANTO(to, amounts[amounts.length - 1]); } function UNSAFE_swapExactTokensForTokens( uint[] memory amounts, route[] calldata routes, address to, uint deadline ) external ensure(deadline) returns (uint[] memory) { _safeTransferFrom(routes[0].from, msg.sender, pairFor(routes[0].from, routes[0].to, routes[0].stable), amounts[0]); _swap(amounts, routes, to); return amounts; } function _safeTransferCANTO(address to, uint value) internal { (bool success,) = to.call{value:value}(new bytes(0)); require(success, "TransferHelper: ETH_TRANSFER_FAILED"); } function _safeTransfer(address token, address to, uint256 value) internal { require(token.code.length > 0); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(erc20.transfer.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool)))); } function _safeTransferFrom(address token, address from, address to, uint256 value) internal { require(token.code.length > 0, "token code length failure"); erc20 tokenCon = erc20(token); tokenCon.transferFrom(from, to, value); } function setStable(address underlying) external returns (uint) { if (msg.sender != admin) { revert SenderNotAdmin(msg.sender, admin); } isStable[underlying] = true; } //returns the underlying price of the assets as a mantissa (scaled by 1e18) function getUnderlyingPrice(CToken ctoken) external override view returns(uint) { address underlying; { //manual scope to pop symbol off of stack string memory symbol = ctoken.symbol(); if (compareStrings(symbol, "cCANTO")) { underlying = address(wcanto); return getPriceNote(address(wcanto), false); } else { underlying = address(ICErc20(address(ctoken)).underlying()); // We are getting the price for a CErc20 lending market } //set price statically to 1 when the Comptroller is retrieving Price if (compareStrings(symbol, "cNOTE")) { // note in terms of note will always be 1 return 1e18; // Stable coins supported by the lending market are instantiated by governance and their price will always be 1 note } else if (compareStrings(symbol, "cUSDT") && (msg.sender == Comptroller )) { uint decimals = erc20(underlying).decimals(); return 1e18 * 1e18 / (10 ** decimals); //Scale Price as a mantissa to maintain precision in comptroller } else if (compareStrings(symbol, "cUSDC") && (msg.sender == Comptroller)) { uint decimals = erc20(underlying).decimals(); return 1e18 * 1e18 / (10 ** decimals); //Scale Price as a mantissa to maintain precision in comptroller } } if (isPair(underlying)) { // this is an LP Token return getPriceLP(IBaseV1Pair(underlying)); } // this is not an LP Token else { if (isStable[underlying]) { return getPriceNote(underlying, true); // value has already been scaled } return getPriceCanto(underlying) * getPriceNote(address(wcanto), false) / 1e18; } } //return the price of this asset in terms of Canto function getPriceCanto(address token_) internal view returns(uint) { erc20 token = erc20(token_); address pair = pairFor(address(wcanto), address(token), false); if (!isPair(pair)) { return 0; // this pair does not exist with Canto } uint decimals = 10 ** token.decimals(); // get decimals of token uint price = IBaseV1Pair(pair).quote(address(token), decimals, 8); // how much Canto is this asset worth? return price * 1e18 / decimals; //return the scaled price } // returns the price of token in terms of note, scaled by 18 decimals, Notice this will most likely be used with pairs that are stable with note function getPriceNote(address token_, bool stable) internal view returns(uint) { erc20 token = erc20(token_); address pair = pairFor(note, address(token), stable); // pairs with Note may be volatile or stable if (!isPair(pair)) { return 0; // this pair has not yet been deployed } uint decimals = 10 ** token.decimals(); uint price = IBaseV1Pair(pair).quote(address(token), decimals, 8); return price * 1e18 / decimals; // divide by decimals now to maintain precision } // this function returns the TWAP of the LP tokens from pair function getPriceLP(IBaseV1Pair pair) internal view returns(uint) { uint[] memory supply = pair.sampleSupply(8, 1); uint[] memory prices; uint[] memory unitReserves; uint[] memory assetReserves; address token0 = pair.token0(); address token1 = pair.token1(); uint decimals; if (pair.stable()) { // stable pairs will be priced in terms of Note if (token0 == note) { //token0 is the unit, token1 will be priced with respect to this asset initially decimals = 10 ** (erc20(token1).decimals()); // we must normalize the price of token1 to 18 decimals prices = pair.sample(token1, decimals, 8, 1); (unitReserves, assetReserves) = pair.sampleReserves(8, 1); } else { decimals = 10 ** (erc20(token0).decimals()); prices = pair.sample(token0, decimals, 8, 1); (assetReserves, unitReserves) = pair.sampleReserves(8, 1); } } else { // non-stable pairs will be priced in terms of Canto if (token0 == address(wcanto)) { // token0 is Canto, and the unit asset of this pair is Canto decimals = 10 ** (erc20(token1).decimals()); prices = pair.sample(token1, decimals, 8, 1); (unitReserves, assetReserves) = pair.sampleReserves(8, 1); } else { decimals = 10 ** (erc20(token0)).decimals(); prices = pair.sample(token0, decimals, 8, 1); (assetReserves, unitReserves) = pair.sampleReserves(8, 1); } } uint LpPricesCumulative; for(uint i; i < 8; ++i) { uint token0TVL = assetReserves[i] * (prices[i] / decimals); uint token1TVL = unitReserves[i]; // price of the unit asset is always 1 LpPricesCumulative += (token0TVL + token1TVL) * 1e18 / supply[i]; } uint LpPrice = LpPricesCumulative / 8; // take the average of the cumulative prices if (pair.stable()) { // this asset has been priced in terms of Note return LpPrice; } // this asset has been priced in terms of Canto return LpPrice * getPriceNote(address(wcanto), false) / 1e18; // return the price in terms of Note } function compareStrings(string memory str1, string memory str2) internal pure returns(bool) { return (keccak256(abi.encodePacked(str1)) == keccak256(abi.encodePacked(str2))); } function _returnStableBooleans(uint8 stable) internal pure returns (bool, bool){ if (stable == 2) { return (true, false); } else if (stable == 3) { return (false, true); } else if (stable == 4) { return (false, false); } else { return (true, true); } } }
/contracts/CTokenInterfaces.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; import "./ComptrollerInterface.sol"; import "./InterestRateModel.sol"; import "./EIP20NonStandardInterface.sol"; import "./ErrorReporter.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; // Maximum borrow rate that can ever be applied (.0005% / block) uint internal constant borrowRateMaxMantissa = 0.0005e16; // Maximum fraction of interest that can be set aside for reserves uint internal constant reserveFactorMaxMantissa = 1e18; /** * @notice Administrator for this contract */ address payable public admin; /** * @notice Pending administrator for this contract */ address payable public pendingAdmin; /** * @notice Contract which oversees inter-cToken operations */ ComptrollerInterface public comptroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; // Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) uint internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint public reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint public accrualBlockNumber; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint public totalReserves; /** * @notice Total number of tokens in circulation */ uint public totalSupply; // Official record of token balances for each account mapping (address => uint) internal accountTokens; // Approved token transfer amounts on behalf of others mapping (address => mapping (address => uint)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint principal; uint interestIndex; } // Mapping of account addresses to outstanding borrow balances mapping(address => BorrowSnapshot) internal accountBorrows; /** * @notice Share of seized collateral that is added to reserves */ uint public constant protocolSeizeShareMantissa = 2.8e16; //2.8% } abstract contract CTokenInterface is CTokenStorage { /** * @notice Indicator that this is a CToken contract (for inspection) */ bool public constant isCToken = true; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint mintAmount, uint mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint redeemAmount, uint redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address cTokenCollateral, uint seizeTokens); /*** Admin Events ***/ /** * @notice Event emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Event emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /** * @notice Event emitted when comptroller is changed */ event NewComptroller(ComptrollerInterface oldComptroller, ComptrollerInterface newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint amount); /*** User Interface ***/ function transfer(address dst, uint amount) virtual external returns (bool); function transferFrom(address src, address dst, uint amount) virtual external returns (bool); function approve(address spender, uint amount) virtual external returns (bool); function allowance(address owner, address spender) virtual external view returns (uint); function balanceOf(address owner) virtual external view returns (uint); function balanceOfUnderlying(address owner) virtual external returns (uint); function getAccountSnapshot(address account) virtual external view returns (uint, uint, uint, uint); function borrowRatePerBlock() virtual view external returns (uint); function supplyRatePerBlock() virtual view external returns (uint); function totalBorrowsCurrent() virtual external returns (uint); function borrowBalanceCurrent(address account) virtual external returns (uint); function borrowBalanceStored(address account) virtual external view returns (uint); function exchangeRateCurrent() virtual external returns (uint); function exchangeRateStored() virtual external view returns (uint); function getCash() virtual external view returns (uint); function accrueInterest() virtual external returns (uint); function seize(address liquidator, address borrower, uint seizeTokens) virtual external returns (uint); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) virtual external returns (uint); function _acceptAdmin() virtual external returns (uint); function _setComptroller(ComptrollerInterface newComptroller) virtual external returns (uint); function _setReserveFactor(uint newReserveFactorMantissa) virtual external returns (uint); function _reduceReserves(uint reduceAmount) virtual external returns (uint); function _setInterestRateModel(InterestRateModel newInterestRateModel) virtual external returns (uint); } contract CErc20Storage { /** * @notice Underlying asset for this CToken */ address public underlying; } abstract contract CErc20Interface is CErc20Storage { /*** User Interface ***/ function mint(uint mintAmount) virtual external returns (uint); function redeem(uint redeemTokens) virtual external returns (uint); function redeemUnderlying(uint redeemAmount) virtual external returns (uint); function borrow(uint borrowAmount) virtual external returns (uint); function repayBorrow(uint repayAmount) virtual external returns (uint); function repayBorrowBehalf(address borrower, uint repayAmount) virtual external returns (uint); function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) virtual external returns (uint); function sweepToken(EIP20NonStandardInterface token) virtual external; /*** Admin Functions ***/ function _addReserves(uint addAmount) virtual external returns (uint); } contract CDelegationStorage { /** * @notice Implementation address for this contract */ address public implementation; } abstract contract CDelegatorInterface is CDelegationStorage { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) virtual external; } abstract contract CDelegateInterface is CDelegationStorage { /** * @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) virtual external; /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() virtual external; }
/contracts/CToken.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; import "./ComptrollerInterface.sol"; import "./CTokenInterfaces.sol"; import "./ErrorReporter.sol"; import "./EIP20Interface.sol"; import "./InterestRateModel.sol"; import "./ExponentialNoError.sol"; /** * @title Compound's CToken Contract * @notice Abstract base for CTokens * @author Compound */ abstract contract CToken is CTokenInterface, ExponentialNoError, TokenErrorReporter { /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize(ComptrollerInterface comptroller_, InterestRateModel interestRateModel_, uint initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { require(msg.sender == admin, "only admin may initialize the market"); require(accrualBlockNumber == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the comptroller uint err = _setComptroller(comptroller_); require(err == 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 == NO_ERROR, "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally * @param spender The address of the account performing the transfer * @param src The address of the source account * @param dst The address of the destination account * @param tokens The number of tokens to transfer * @return 0 if the transfer succeeded, else revert */ function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) { /* Fail if transfer not allowed */ uint allowed = comptroller.transferAllowed(address(this), src, dst, tokens); if (allowed != 0) { revert TransferComptrollerRejection(allowed); } /* Do not allow self-transfers */ if (src == dst) { revert TransferNotAllowed(); } /* Get the allowance, infinite for the account owner */ uint startingAllowance = 0; if (spender == src) { startingAllowance = type(uint).max; } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ uint allowanceNew = startingAllowance - tokens; uint srcTokensNew = accountTokens[src] - tokens; uint dstTokensNew = accountTokens[dst] + tokens; ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) accountTokens[src] = srcTokensNew; accountTokens[dst] = dstTokensNew; /* Eat some of the allowance (if necessary) */ if (startingAllowance != type(uint).max) { transferAllowances[src][spender] = allowanceNew; } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); // unused function // comptroller.transferVerify(address(this), src, dst, tokens); return NO_ERROR; } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) override external nonReentrant returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == 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) override external nonReentrant returns (bool) { return transferTokens(msg.sender, src, dst, amount) == 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 (uint256.max means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) override 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) override 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) override 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) override external returns (uint) { 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) override external view returns (uint, uint, uint, uint) { return ( NO_ERROR, accountTokens[account], borrowBalanceStoredInternal(account), exchangeRateStoredInternal() ); } /** * @dev Function to simply retrieve block number * This exists mainly for inheriting test contracts to stub this result. */ function getBlockNumber() virtual internal view returns (uint) { return block.number; } /** * @notice Returns the current per-block borrow interest rate for this cToken * @return The borrow interest rate per block, scaled by 1e18 */ function borrowRatePerBlock() override view external returns (uint) { 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() override view external returns (uint) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() override external nonReentrant returns (uint) { accrueInterest(); 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) override external nonReentrant returns (uint) { accrueInterest(); 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) override public view returns (uint) { return borrowBalanceStoredInternal(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return (error code, the calculated balance or 0 if error code is non-zero) */ function borrowBalanceStoredInternal(address account) internal view returns (uint) { /* 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 */ uint principalTimesIndex = borrowSnapshot.principal * borrowIndex; return principalTimesIndex / borrowSnapshot.interestIndex; } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() override public nonReentrant returns (uint) { accrueInterest(); 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() override public view returns (uint) { return exchangeRateStoredInternal(); } /** * @notice Calculates the exchange rate from the underlying to the CToken * @dev This function does not accrue efore calculating the exchange rate * @return calculated exchange rate scaled by 1e18 */ function exchangeRateStoredInternal() virtual internal view returns (uint) { uint _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return initialExchangeRateMantissa; } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint totalCash = getCashPrior(); uint cashPlusBorrowsMinusReserves = totalCash + totalBorrows - totalReserves; uint exchangeRate = cashPlusBorrowsMinusReserves * expScale / _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() override external view returns (uint) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() virtual override public returns (uint) { /* Remember the initial block number */ uint currentBlockNumber = getBlockNumber(); uint accrualBlockNumberPrior = accrualBlockNumber; /* Short-circuit accumulating 0 interest */ if (accrualBlockNumberPrior == currentBlockNumber) { return NO_ERROR; } /* Read the previous values out of storage */ uint cashPrior = getCashPrior(); uint borrowsPrior = totalBorrows; uint reservesPrior = totalReserves; uint borrowIndexPrior = borrowIndex; /* Calculate the current borrow interest rate */ uint borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of blocks elapsed since the last accrual */ uint blockDelta = 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); uint interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, borrowsPrior); uint totalBorrowsNew = interestAccumulated + borrowsPrior; uint totalReservesNew = mul_ScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior); uint 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 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 */ function mintInternal(uint mintAmount) internal nonReentrant { accrueInterest(); // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to mintFresh(msg.sender, mintAmount); } /** * @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 */ function mintFresh(address minter, uint mintAmount) internal virtual { /* Fail if mint not allowed */ uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount); if (allowed != 0) { revert MintComptrollerRejection(allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { revert MintFreshnessCheck(); } Exp memory exchangeRate = Exp({mantissa: 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 ac tually transferred, * in case of a fee. On success, the cToken holds an additional `actualMintAmount` * of cash. */ uint actualMintAmount = doTransferIn(minter, mintAmount); /* * We get the current exchange rate and calculate the number of cTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ uint mintTokens = div_(actualMintAmount, exchangeRate); /* * We calculate the new total supply of cTokens and minter token balance, checking for overflow: * totalSupplyNew = totalSupply + mintTokens * accountTokensNew = accountTokens[minter] + mintTokens * And write them into storage */ totalSupply = totalSupply + mintTokens; accountTokens[minter] = accountTokens[minter] + mintTokens; /* We emit a Mint event, and a Transfer event */ emit Mint(minter, actualMintAmount, mintTokens); emit Transfer(address(this), minter, mintTokens); /* We call the defense hook */ // unused function // comptroller.mintVerify(address(this), minter, actualMintAmount, mintTokens); } /** * @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 */ function redeemInternal(uint redeemTokens) internal nonReentrant { accrueInterest(); // redeemFresh emits redeem-specific logs on errors, so we don't need to redeemFresh(payable(msg.sender), redeemTokens, 0); } /** * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming cTokens */ function redeemUnderlyingInternal(uint redeemAmount) internal nonReentrant { accrueInterest(); // redeemFresh emits redeem-specific logs on errors, so we don't need to redeemFresh(payable(msg.sender), 0, redeemAmount); } /** * @notice User redeems cTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of cTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @param redeemAmountIn The number of underlying tokens to receive from redeeming cTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero) */ function redeemFresh(address payable redeemer, uint redeemTokensIn, uint redeemAmountIn) internal virtual { require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero"); /* exchangeRate = invoke Exchange Rate Stored() */ Exp memory exchangeRate = Exp({mantissa: exchangeRateStoredInternal() }); uint redeemTokens; uint redeemAmount; /* 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 */ redeemTokens = redeemTokensIn; redeemAmount = mul_ScalarTruncate(exchangeRate, redeemTokensIn); } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ redeemTokens = div_(redeemAmountIn, exchangeRate); redeemAmount = redeemAmountIn; } /* Fail if redeem not allowed */ uint allowed = comptroller.redeemAllowed(address(this), redeemer, redeemTokens); if (allowed != 0) { revert RedeemComptrollerRejection(allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { revert RedeemFreshnessCheck(); } /* Fail gracefully if protocol has insufficient cash */ if (getCashPrior() < redeemAmount) { revert RedeemTransferOutNotPossible(); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We write the previously calculated values into storage. * Note: Avoid token reentrancy attacks by writing reduced supply before external transfer. */ totalSupply = totalSupply - redeemTokens; accountTokens[redeemer] = accountTokens[redeemer] - redeemTokens; /* * 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. * accountant supplies market and receives cTokens at current exchange Rate */ doTransferOut(redeemer, redeemAmount); /* We emit a Transfer event, and a Redeem event */ emit Transfer(redeemer, address(this), redeemTokens); emit Redeem(redeemer, redeemAmount, redeemTokens); /* We call the defense hook */ comptroller.redeemVerify(address(this), redeemer, redeemAmount, redeemTokens); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow */ function borrowInternal(uint borrowAmount) internal nonReentrant { accrueInterest(); // borrowFresh emits borrow-specific logs on errors, so we don't need to borrowFresh(payable(msg.sender), borrowAmount); } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow */ function borrowFresh(address payable borrower, uint borrowAmount) internal virtual { /* Fail if borrow not allowed */ uint allowed = comptroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { revert BorrowComptrollerRejection(allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { revert BorrowFreshnessCheck(); } /* Fail gracefully if protocol has insufficient underlying cash */ if (getCashPrior() < borrowAmount) { revert BorrowCashNotAvailable(); } /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowNew = accountBorrow + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ uint accountBorrowsPrev = borrowBalanceStoredInternal(borrower); uint accountBorrowsNew = accountBorrowsPrev + borrowAmount; uint totalBorrowsNew = totalBorrows + borrowAmount; ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We write the previously calculated values into storage. * Note: Avoid token reentrancy attacks by writing increased borrow before external transfer. `*/ accountBorrows[borrower].principal = accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = totalBorrowsNew; /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The cToken must handle variations between ERC-20 and ETH underlying. * On success, the cToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount); /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, accountBorrowsNew, totalBorrowsNew); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay, or -1 for the full outstanding amount */ function repayBorrowInternal(uint repayAmount) internal nonReentrant { accrueInterest(); // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to repayBorrowFresh(msg.sender, msg.sender, repayAmount); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay, or -1 for the full outstanding amount */ function repayBorrowBehalfInternal(address borrower, uint repayAmount) internal nonReentrant { accrueInterest(); // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to repayBorrowFresh(msg.sender, borrower, repayAmount); } /** * @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 underlying tokens being returned, or -1 for the full outstanding amount * @return (uint) the actual repayment amount. */ function repayBorrowFresh(address payer, address borrower, uint repayAmount) internal virtual returns (uint) { /* Fail if repayBorrow not allowed */ uint allowed = comptroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { revert RepayBorrowComptrollerRejection(allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { revert RepayBorrowFreshnessCheck(); } /* We fetch the amount the borrower owes, with accumulated interest */ uint accountBorrowsPrev = borrowBalanceStoredInternal(borrower); /* If repayAmount == -1, repayAmount = accountBorrows */ uint repayAmountFinal = repayAmount == type(uint).max ? accountBorrowsPrev : 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. */ uint actualRepayAmount = doTransferIn(payer, repayAmountFinal); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ uint accountBorrowsNew = accountBorrowsPrev - actualRepayAmount; uint totalBorrowsNew = totalBorrows - actualRepayAmount; /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, actualRepayAmount, accountBorrowsNew, totalBorrowsNew); return actualRepayAmount; } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay */ function liquidateBorrowInternal(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal nonReentrant { accrueInterest(); uint error = cTokenCollateral.accrueInterest(); if (error != NO_ERROR) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed revert LiquidateAccrueCollateralInterestFailed(error); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to liquidateBorrowFresh(msg.sender, borrower, repayAmount, cTokenCollateral); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this cToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param cTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay */ function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, CTokenInterface cTokenCollateral) internal { /* Fail if liquidate not allowed */ uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(cTokenCollateral), liquidator, borrower, repayAmount); if (allowed != 0) { revert LiquidateComptrollerRejection(allowed); } /* Verify market's block number equals current block number */ if (accrualBlockNumber != getBlockNumber()) { revert LiquidateFreshnessCheck(); } /* Verify cTokenCollateral market's block number equals current block number */ if (cTokenCollateral.accrualBlockNumber() != getBlockNumber()) { revert LiquidateCollateralFreshnessCheck(); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { revert LiquidateLiquidatorIsBorrower(); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { revert LiquidateCloseAmountIsZero(); } /* Fail if repayAmount = -1 */ if (repayAmount == type(uint).max) { revert LiquidateCloseAmountIsUintMax(); } /* Fail if repayBorrow fails */ uint actualRepayAmount = repayBorrowFresh(liquidator, borrower, repayAmount); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(cTokenCollateral), actualRepayAmount); require(amountSeizeError == 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 if (address(cTokenCollateral) == address(this)) { seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { require(cTokenCollateral.seize(liquidator, borrower, seizeTokens) == NO_ERROR, "token seizure failed"); } /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(cTokenCollateral), seizeTokens); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another cToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed cToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of cTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize(address liquidator, address borrower, uint seizeTokens) override external nonReentrant returns (uint) { seizeInternal(msg.sender, liquidator, borrower, seizeTokens); return 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 */ function seizeInternal(address seizerToken, address liquidator, address borrower, uint seizeTokens) internal { /* Fail if seize not allowed */ uint allowed = comptroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens); if (allowed != 0) { revert LiquidateSeizeComptrollerRejection(allowed); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { revert LiquidateSeizeLiquidatorIsBorrower(); } /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ uint protocolSeizeTokens = mul_(seizeTokens, Exp({mantissa: protocolSeizeShareMantissa})); uint liquidatorSeizeTokens = seizeTokens - protocolSeizeTokens; Exp memory exchangeRate = Exp({mantissa: exchangeRateStoredInternal()}); uint protocolSeizeAmount = mul_ScalarTruncate(exchangeRate, protocolSeizeTokens); uint totalReservesNew = totalReserves + protocolSeizeAmount; ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the calculated values into storage */ totalReserves = totalReservesNew; totalSupply = totalSupply - protocolSeizeTokens; accountTokens[borrower] = accountTokens[borrower] - seizeTokens; accountTokens[liquidator] = accountTokens[liquidator] + liquidatorSeizeTokens; /* Emit a Transfer event */ emit Transfer(borrower, liquidator, liquidatorSeizeTokens); emit Transfer(borrower, address(this), protocolSeizeTokens); emit ReservesAdded(address(this), protocolSeizeAmount, totalReservesNew); } /*** 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) override external returns (uint) { // Check caller = admin if (msg.sender != admin) { revert SetPendingAdminOwnerCheck(); } // 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 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() override external returns (uint) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { revert AcceptAdminPendingAdminCheck(); } // 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 = payable(address(0)); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return 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) override public returns (uint) { // Check caller is admin if (msg.sender != admin) { revert SetComptrollerOwnerCheck(); } 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 NO_ERROR; } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint newReserveFactorMantissa) override external nonReentrant returns (uint) { accrueInterest(); // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint newReserveFactorMantissa) internal returns (uint) { // Check caller is admin if (msg.sender != admin) { revert SetReserveFactorAdminCheck(); } // Verify market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { revert SetReserveFactorFreshCheck(); } // Check newReserveFactor ≤ maxReserveFactor if (newReserveFactorMantissa > reserveFactorMaxMantissa) { revert SetReserveFactorBoundsCheck(); } uint oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return NO_ERROR; } /** * @notice Accrues interest and reduces reserves by transferring from msg.sender * @param addAmount Amount of addition to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReservesInternal(uint addAmount) internal nonReentrant returns (uint) { accrueInterest(); // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to. _addReservesFresh(addAmount); return NO_ERROR; } /** * @notice Add reserves by transferring from caller * @dev Requires fresh interest accrual * @param addAmount Amount of addition to reserves * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees */ function _addReservesFresh(uint addAmount) internal returns (uint, uint) { // totalReserves + actualAddAmount uint totalReservesNew; uint actualAddAmount; // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { revert AddReservesFactorFreshCheck(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); totalReservesNew = 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 (NO_ERROR, actualAddAmount); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint reduceAmount) override external nonReentrant returns (uint) { accrueInterest(); // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint reduceAmount) internal returns (uint) { // totalReserves - reduceAmount uint totalReservesNew; // Check caller is admin if (msg.sender != admin) { revert ReduceReservesAdminCheck(); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { revert ReduceReservesFreshCheck(); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { revert ReduceReservesCashNotAvailable(); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { revert ReduceReservesCashValidation(); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) totalReservesNew = totalReserves - reduceAmount; // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. doTransferOut(admin, reduceAmount); emit ReservesReduced(admin, reduceAmount, totalReservesNew); return 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) override public returns (uint) { accrueInterest(); // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (msg.sender != admin) { revert SetInterestRateModelOwnerCheck(); } // We fail gracefully unless market's block number equals current block number if (accrualBlockNumber != getBlockNumber()) { revert SetInterestRateModelFreshCheck(); } // 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 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() virtual internal view returns (uint); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn(address from, uint amount) virtual internal returns (uint); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure rather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut(address payable to, uint amount) virtual internal; /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() virtual { require(_notEntered, "re-entered"); _notEntered = false; _; _notEntered = true; // get a gas-refund post-Istanbul } }
/contracts/PriceOracle.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; import "./CToken.sol"; abstract 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) virtual external view returns (uint); }
/contracts/InterestRateModel.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; /** * @title Compound's InterestRateModel Interface * @author Compound */ abstract contract InterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) bool public constant isInterestRateModel = true; /** * @notice Calculates the current borrow interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @return The borrow rate per block (as a percentage, and scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) virtual view external returns (uint); /** * @notice Calculates the current supply interest rate per block * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per block (as a percentage, and scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) virtual view external returns (uint); }
/contracts/ExponentialNoError.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; /** * @title Exponential module for storing fixed-precision decimals * @author Compound * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places. * Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is: * `Exp({mantissa: 5100000000000000000})`. */ contract ExponentialNoError { uint constant expScale = 1e18; uint constant doubleScale = 1e36; uint constant halfExpScale = expScale/2; uint constant mantissaOne = expScale; struct Exp { uint mantissa; } struct Double { uint mantissa; } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) pure internal returns (uint) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint scalar) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (uint) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev Checks if left Exp > right Exp. */ function greaterThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa > right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) pure internal returns (bool) { return value.mantissa == 0; } function safe224(uint n, string memory errorMessage) pure internal returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint n, string memory errorMessage) pure internal returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint a, uint b) pure internal returns (uint) { return a + b; } function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint a, uint b) pure internal returns (uint) { return a - b; } function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Exp memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint a, Double memory b) pure internal returns (uint) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint a, uint b) pure internal returns (uint) { return a * b; } function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Exp memory b) pure internal returns (uint) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint a, Double memory b) pure internal returns (uint) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint a, uint b) pure internal returns (uint) { return a / b; } function fraction(uint a, uint b) pure internal returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } }
/contracts/ErrorReporter.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; 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(uint error, uint info, uint detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } } contract TokenErrorReporter { uint public constant NO_ERROR = 0; // support legacy return codes error TransferComptrollerRejection(uint256 errorCode); error TransferNotAllowed(); error TransferNotEnough(); error TransferTooMuch(); error MintComptrollerRejection(uint256 errorCode); error MintFreshnessCheck(); error RedeemComptrollerRejection(uint256 errorCode); error RedeemFreshnessCheck(); error RedeemTransferOutNotPossible(); error BorrowComptrollerRejection(uint256 errorCode); error BorrowFreshnessCheck(); error BorrowCashNotAvailable(); error RepayBorrowComptrollerRejection(uint256 errorCode); error RepayBorrowFreshnessCheck(); error LiquidateComptrollerRejection(uint256 errorCode); error LiquidateFreshnessCheck(); error LiquidateCollateralFreshnessCheck(); error LiquidateAccrueBorrowInterestFailed(uint256 errorCode); error LiquidateAccrueCollateralInterestFailed(uint256 errorCode); error LiquidateLiquidatorIsBorrower(); error LiquidateCloseAmountIsZero(); error LiquidateCloseAmountIsUintMax(); error LiquidateRepayBorrowFreshFailed(uint256 errorCode); error LiquidateSeizeComptrollerRejection(uint256 errorCode); error LiquidateSeizeLiquidatorIsBorrower(); error AcceptAdminPendingAdminCheck(); error SetComptrollerOwnerCheck(); error SetPendingAdminOwnerCheck(); error SetReserveFactorAdminCheck(); error SetReserveFactorFreshCheck(); error SetReserveFactorBoundsCheck(); error AddReservesFactorFreshCheck(uint256 actualAddAmount); error ReduceReservesAdminCheck(); error ReduceReservesFreshCheck(); error ReduceReservesCashNotAvailable(); error ReduceReservesCashValidation(); error SetInterestRateModelOwnerCheck(); error SetInterestRateModelFreshCheck(); //Accountant Error Codes error AccountantSupplyError(uint256 borrowAmount); error AccountantRedeemError(uint256 redeemAmount); }
/contracts/EIP20NonStandardInterface.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; /** * @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 balance 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 success 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 remaining The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
/contracts/EIP20Interface.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; /** * @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 balance 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 success 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 success 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 success 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 remaining The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); }
/contracts/ComptrollerInterface.sol
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; abstract 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) virtual external returns (uint[] memory); function exitMarket(address cToken) virtual external returns (uint); /*** Policy Hooks ***/ function mintAllowed(address cToken, address minter, uint mintAmount) virtual external returns (uint); function mintVerify(address cToken, address minter, uint mintAmount, uint mintTokens) virtual external; function redeemAllowed(address cToken, address redeemer, uint redeemTokens) virtual external returns (uint); function redeemVerify(address cToken, address redeemer, uint redeemAmount, uint redeemTokens) virtual external; function borrowAllowed(address cToken, address borrower, uint borrowAmount) virtual external returns (uint); function borrowVerify(address cToken, address borrower, uint borrowAmount) virtual external; function repayBorrowAllowed( address cToken, address payer, address borrower, uint repayAmount) virtual external returns (uint); function repayBorrowVerify( address cToken, address payer, address borrower, uint repayAmount, uint borrowerIndex) virtual external; function liquidateBorrowAllowed( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount) virtual external returns (uint); function liquidateBorrowVerify( address cTokenBorrowed, address cTokenCollateral, address liquidator, address borrower, uint repayAmount, uint seizeTokens) virtual external; function seizeAllowed( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) virtual external returns (uint); function seizeVerify( address cTokenCollateral, address cTokenBorrowed, address liquidator, address borrower, uint seizeTokens) virtual external; function transferAllowed(address cToken, address src, address dst, uint transferTokens) virtual external returns (uint); function transferVerify(address cToken, address src, address dst, uint transferTokens) virtual external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address cTokenBorrowed, address cTokenCollateral, uint repayAmount) virtual external view returns (uint, uint); }
/contracts/BaseV1-libs.sol
pragma solidity 0.8.11; interface erc20 { function totalSupply() external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function decimals() external view returns (uint8); function symbol() external view returns (string memory); function balanceOf(address) external view returns (uint); function transferFrom(address sender, address recipient, uint amount) external returns (bool); function approve(address spender, uint value) external returns (bool); } library Math { function min(uint a, uint b) internal pure returns (uint) { return a < b ? a : b; } function sqrt(uint y) internal pure returns (uint z) { if (y > 3) { z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } }
Compiler Settings
{"remappings":[],"optimizer":{"runs":200,"enabled":true},"metadata":{"bytecodeHash":"ipfs"},"libraries":{},"evmVersion":"london","compilationTarget":{"contracts/BaseV1-periphery.sol":"BaseV1Router01"}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_factory","internalType":"address"},{"type":"address","name":"_wcanto","internalType":"address"},{"type":"address","name":"note_","internalType":"address"},{"type":"address","name":"Comptroller_","internalType":"address"}]},{"type":"error","name":"SenderNotAdmin","inputs":[{"type":"address","name":"sender","internalType":"address"},{"type":"address","name":"admin","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"Comptroller","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"UNSAFE_swapExactTokensForTokens","inputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"},{"type":"tuple[]","name":"routes","internalType":"struct BaseV1Router01.route[]","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"amountADesired","internalType":"uint256"},{"type":"uint256","name":"amountBDesired","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountCANTO","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidityCANTO","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"amountTokenDesired","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountCANTOMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"admin","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"factory","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"bool","name":"stable","internalType":"bool"}],"name":"getAmountOut","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address","name":"tokenIn","internalType":"address"},{"type":"address","name":"tokenOut","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"getAmountsOut","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"tuple[]","name":"routes","internalType":"struct BaseV1Router01.route[]","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"reserveA","internalType":"uint256"},{"type":"uint256","name":"reserveB","internalType":"uint256"}],"name":"getReserves","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUnderlyingPrice","inputs":[{"type":"address","name":"ctoken","internalType":"contract CToken"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPair","inputs":[{"type":"address","name":"pair","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPriceOracle","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isStable","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"note","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"pair","internalType":"address"}],"name":"pairFor","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"quoteAddLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"amountADesired","internalType":"uint256"},{"type":"uint256","name":"amountBDesired","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"quoteRemoveLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"liquidity","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountCANTO","internalType":"uint256"}],"name":"removeLiquidityCANTO","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountCANTOMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountCANTO","internalType":"uint256"}],"name":"removeLiquidityCANTOWithPermit","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountCANTOMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidityWithPermit","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAdmin","inputs":[{"type":"address","name":"admin_","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"setStable","inputs":[{"type":"address","name":"underlying","internalType":"address"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"address","name":"token0","internalType":"address"},{"type":"address","name":"token1","internalType":"address"}],"name":"sortTokens","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactCANTOForTokens","inputs":[{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"tuple[]","name":"routes","internalType":"struct BaseV1Router01.route[]","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForCANTO","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"tuple[]","name":"routes","internalType":"struct BaseV1Router01.route[]","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"tuple[]","name":"routes","internalType":"struct BaseV1Router01.route[]","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"}]},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForTokensSimple","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address","name":"tokenFrom","internalType":"address"},{"type":"address","name":"tokenTo","internalType":"address"},{"type":"bool","name":"stable","internalType":"bool"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IWCANTO"}],"name":"wcanto","inputs":[]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x6101206040523480156200001257600080fd5b5060405162004efa38038062004efa8339810160408190526200003591620000f8565b6001600160a01b03841660c081905260408051631355724960e31b81529051639aab9248916004808201926020929091908290030181865afa15801562000080573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000a6919062000155565b610100526001600160a01b0392831660e0529082166080521660a05250600080546001600160a01b031916331790556200016f565b80516001600160a01b0381168114620000f357600080fd5b919050565b600080600080608085870312156200010f57600080fd5b6200011a85620000db565b93506200012a60208601620000db565b92506200013a60408601620000db565b91506200014a60608601620000db565b905092959194509250565b6000602082840312156200016857600080fd5b5051919050565b60805160a05160c05160e05161010051614c666200029460003960006115370152600081816101d6015281816104c2015281816106cc0152818161091801528181610a1c01528181610b2f01528181610bbd01528181610f3301528181610f6901528181610f9e015281816110330152818161212501528181612175015281816122660152818161258a015281816125b00152818161286e0152818161379c01528181613ae30152613b3501526000818161058601528181611355015281816114fc015281816117c9015281816118dd01528181611cd401528181611e480152818161235601528181612ceb0152612d8c015260008181610354015281816126b801526127ae0152600081816102e801528181613181015261348f0152614c666000f3fe6080604052600436106101c65760003560e01c8063704b6c02116100f7578063c45a015511610095578063e5e31b1311610064578063e5e31b1314610616578063f41766d814610636578063f851a44014610656578063fc57d4df1461067657600080fd5b8063c45a015514610574578063c79db9d7146105a8578063dba71376146105c8578063dd54e2a4146105f657600080fd5b80639185f6ec116100d15780639185f6ec146104e45780639881fcb41461051457806398a0fb3c14610534578063a32b1fcd1461055457600080fd5b8063704b6c02146104705780637301e3c8146104905780637aa497d9146104b057600080fd5b80634ae36e8e116101645780635a47ddc31161013e5780635a47ddc3146103d65780635e1e6325146103f65780635e60dab51461042b57806366331bba1461044b57600080fd5b80634ae36e8e146103425780634c1ee03e14610376578063544caa561461039657600080fd5b8063116e4ea3116101a0578063116e4ea31461028857806313dcfc59146102b657806326d111f5146102d65780634386e63c1461032257600080fd5b80630483e3cc1461020a578063058e200a146102405780630dede6c41461025357600080fd5b3661020557336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461020357610203613c8a565b005b600080fd5b34801561021657600080fd5b5061022a610225366004613d08565b610696565b6040516102379190613d7b565b60405180910390f35b61022a61024e366004613dbf565b6109f7565b34801561025f57600080fd5b5061027361026e366004613e34565b610d56565b60408051928352602083019190915201610237565b61029b610296366004613eb9565b610f07565b60408051938452602084019290925290820152606001610237565b3480156102c257600080fd5b5061022a6102d1366004613f2b565b611148565b3480156102e257600080fd5b5061030a7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610237565b34801561032e57600080fd5b5061027361033d366004613f8f565b61134e565b34801561034e57600080fd5b5061030a7f000000000000000000000000000000000000000000000000000000000000000081565b34801561038257600080fd5b5061030a610391366004613fe0565b6114b5565b3480156103a257600080fd5b506103b66103b136600461402b565b6115bd565b604080516001600160a01b03938416815292909116602083015201610237565b3480156103e257600080fd5b5061029b6103f1366004614064565b6116b1565b34801561040257600080fd5b506104166104113660046140f3565b611791565b60408051928352901515602083015201610237565b34801561043757600080fd5b50610273610446366004613fe0565b6119e5565b34801561045757600080fd5b50610460600181565b6040519015158152602001610237565b34801561047c57600080fd5b5061020361048b36600461412a565b611aaf565b34801561049c57600080fd5b5061022a6104ab3660046141b2565b611ae8565b3480156104bc57600080fd5b5061030a7f000000000000000000000000000000000000000000000000000000000000000081565b3480156104f057600080fd5b506104606104ff36600461412a565b60016020526000908152604090205460ff1681565b34801561052057600080fd5b5061022a61052f3660046142f4565b611bbe565b34801561054057600080fd5b5061029b61054f36600461439a565b611e40565b34801561056057600080fd5b5061027361056f366004614404565b612040565b34801561058057600080fd5b5061030a7f000000000000000000000000000000000000000000000000000000000000000081565b3480156105b457600080fd5b506102736105c3366004613eb9565b6120fb565b3480156105d457600080fd5b506105e86105e336600461412a565b6121f0565b604051908152602001610237565b34801561060257600080fd5b506102736106113660046144c4565b61225b565b34801561062257600080fd5b5061046061063136600461412a565b612334565b34801561064257600080fd5b5061022a610651366004613d08565b6123c9565b34801561066257600080fd5b5060005461030a906001600160a01b031681565b34801561068257600080fd5b506105e861069136600461412a565b6124ee565b606081428110156106c25760405162461bcd60e51b81526004016106b990614572565b60405180910390fd5b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001686866106f96001826145b7565b818110610708576107086145ce565b9050606002016020016020810190610720919061412a565b6001600160a01b0316146107465760405162461bcd60e51b81526004016106b9906145e4565b6107a2888787808060200260200160405190810160405280939291908181526020016000905b82821015610798576107896060830286013681900381019061461b565b8152602001906001019061076c565b5050505050611bbe565b91508682600184516107b491906145b7565b815181106107c4576107c46145ce565b602002602001015110156107ea5760405162461bcd60e51b81526004016106b990614637565b6108b986866000818110610800576108006145ce565b610816926020606090920201908101915061412a565b336108998989600081811061082d5761082d6145ce565b610843926020606090920201908101915061412a565b8a8a6000818110610856576108566145ce565b905060600201602001602081019061086e919061412a565b8b8b6000818110610881576108816145ce565b9050606002016040016020810190610391919061467f565b856000815181106108ac576108ac6145ce565b60200260200101516128b1565b610916828787808060200260200160405190810160405280939291908181526020016000905b8282101561090b576108fc6060830286013681900381019061461b565b815260200190600101906108df565b505050505030612991565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632e1a7d4d836001855161095491906145b7565b81518110610964576109646145ce565b60200260200101516040518263ffffffff1660e01b815260040161098a91815260200190565b600060405180830381600087803b1580156109a457600080fd5b505af11580156109b8573d6000803e3d6000fd5b505050506109ec8483600185516109cf91906145b7565b815181106109df576109df6145ce565b6020026020010151612be6565b509695505050505050565b60608142811015610a1a5760405162461bcd60e51b81526004016106b990614572565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031686866000818110610a5757610a576145ce565b610a6d926020606090920201908101915061412a565b6001600160a01b031614610a935760405162461bcd60e51b81526004016106b9906145e4565b610ae5348787808060200260200160405190810160405280939291908181526020016000905b8282101561079857610ad66060830286013681900381019061461b565b81526020019060010190610ab9565b9150868260018451610af791906145b7565b81518110610b0757610b076145ce565b60200260200101511015610b2d5760405162461bcd60e51b81526004016106b990614637565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db083600081518110610b6f57610b6f6145ce565b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b158015610ba257600080fd5b505af1158015610bb6573d6000803e3d6000fd5b50505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a9059cbb610c5488886000818110610c0057610c006145ce565b610c16926020606090920201908101915061412a565b89896000818110610c2957610c296145ce565b9050606002016020016020810190610c41919061412a565b8a8a6000818110610881576108816145ce565b84600081518110610c6757610c676145ce565b60200260200101516040518363ffffffff1660e01b8152600401610ca09291906001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015610cbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce3919061469c565b610cef57610cef613c8a565b610d4c828787808060200260200160405190810160405280939291908181526020016000905b82821015610d4157610d326060830286013681900381019061461b565b81526020019060010190610d15565b505050505086612991565b5095945050505050565b6000808242811015610d7a5760405162461bcd60e51b81526004016106b990614572565b6000610d878c8c8c6114b5565b6040516323b872dd60e01b81523360048201526001600160a01b03821660248201819052604482018c90529192506323b872dd906064016020604051808303816000875af1158015610ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e01919061469c565b610e0a57600080fd5b60405163226bf2d160e21b81526001600160a01b03878116600483015260009182918416906389afcb449060240160408051808303816000875af1158015610e56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7a91906146b9565b915091506000610e8a8f8f6115bd565b509050806001600160a01b03168f6001600160a01b031614610ead578183610eb0565b82825b90975095508a871015610ed55760405162461bcd60e51b81526004016106b9906146dd565b89861015610ef55760405162461bcd60e51b81526004016106b990614720565b50505050509850989650505050505050565b60008060008342811015610f2d5760405162461bcd60e51b81526004016106b990614572565b610f5c8b7f00000000000000000000000000000000000000000000000000000000000000008c8c348d8d612cb4565b90945092506000610f8e8c7f00000000000000000000000000000000000000000000000000000000000000008d6114b5565b9050610f9c8c3383886128b1565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004016000604051808303818588803b158015610ff757600080fd5b505af115801561100b573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038581166004830152602482018990527f000000000000000000000000000000000000000000000000000000000000000016935063a9059cbb925060440190506020604051808303816000875af1158015611080573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a4919061469c565b6110b0576110b0613c8a565b6040516335313c2160e11b81526001600160a01b038881166004830152821690636a627842906024016020604051808303816000875af11580156110f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111c9190614763565b925083341115611139576111393361113486346145b7565b612be6565b50509750975097945050505050565b6060814281101561116b5760405162461bcd60e51b81526004016106b990614572565b604080516001808252818301909252600091816020015b604080516060810182526000808252602080830182905292820152825260001990920191018161118257905050905087816000815181106111c5576111c56145ce565b6020026020010151600001906001600160a01b031690816001600160a01b03168152505086816000815181106111fd576111fd6145ce565b6020026020010151602001906001600160a01b031690816001600160a01b0316815250508581600081518110611235576112356145ce565b60209081029190910101519015156040909101526112538a82611bbe565b925088836001855161126591906145b7565b81518110611275576112756145ce565b6020026020010151101561129b5760405162461bcd60e51b81526004016106b990614637565b611336816000815181106112b1576112b16145ce565b60200260200101516000015133611323846000815181106112d4576112d46145ce565b602002602001015160000151856000815181106112f3576112f36145ce565b60200260200101516020015186600081518110611312576113126145ce565b6020026020010151604001516114b5565b866000815181106108ac576108ac6145ce565b611341838287612991565b5050979650505050505050565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636801cc308888886040518463ffffffff1660e01b81526004016113a39392919061477c565b602060405180830381865afa1580156113c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113e491906147a0565b90506001600160a01b0381166114015760008092509250506114ac565b60008061140f8989896119e5565b915091506000836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611453573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114779190614763565b90508061148484896147bd565b61148e91906147dc565b95508061149b83896147bd565b6114a591906147dc565b9450505050505b94509492505050565b60008060006114c486866115bd565b6040516bffffffffffffffffffffffff19606084811b8216602084015283901b16603482015286151560f81b604882015291935091507f000000000000000000000000000000000000000000000000000000000000000090604901604051602081830303815290604052805190602001207f000000000000000000000000000000000000000000000000000000000000000060405160200161159b939291906001600160f81b0319815260609390931b6bffffffffffffffffffffffff191660018401526015830191909152603582015260550190565b60408051601f1981840301815291905280516020909101209695505050505050565b600080826001600160a01b0316846001600160a01b0316141561162c5760405162461bcd60e51b815260206004820152602160248201527f426173655631526f757465723a204944454e544943414c5f41444452455353456044820152605360f81b60648201526084016106b9565b826001600160a01b0316846001600160a01b03161061164c57828461164f565b83835b90925090506001600160a01b0382166116aa5760405162461bcd60e51b815260206004820152601a60248201527f426173655631526f757465723a205a45524f5f4144445245535300000000000060448201526064016106b9565b9250929050565b600080600083428110156116d75760405162461bcd60e51b81526004016106b990614572565b6116e68d8d8d8d8d8d8d612cb4565b909450925060006116f88e8e8e6114b5565b90506117068e3383886128b1565b6117128d3383876128b1565b6040516335313c2160e11b81526001600160a01b038881166004830152821690636a627842906024016020604051808303816000875af115801561175a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177e9190614763565b9250505099509950999650505050505050565b60008060006117a2858560016114b5565b60405163e5e31b1360e01b81526001600160a01b03828116600483015291925060009182917f00000000000000000000000000000000000000000000000000000000000000009091169063e5e31b1390602401602060405180830381865afa158015611812573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611836919061469c565b156118af576040516378a051ad60e11b8152600481018990526001600160a01b03888116602483015284169063f140a35a90604401602060405180830381865afa158015611888573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ac9190614763565b91505b6118bb878760006114b5565b60405163e5e31b1360e01b81526001600160a01b0380831660048301529194507f00000000000000000000000000000000000000000000000000000000000000009091169063e5e31b1390602401602060405180830381865afa158015611926573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194a919061469c565b156119c3576040516378a051ad60e11b8152600481018990526001600160a01b03888116602483015284169063f140a35a90604401602060405180830381865afa15801561199c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c09190614763565b90505b8082116119d2578060006119d6565b8160015b94509450505050935093915050565b60008060006119f486866115bd565b509050600080611a058888886114b5565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611a42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a669190614815565b506001600160701b031691506001600160701b03169150826001600160a01b0316886001600160a01b031614611a9d578082611aa0565b81815b90999098509650505050505050565b6000546001600160a01b03163314611ac657600080fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b60608142811015611b0b5760405162461bcd60e51b81526004016106b990614572565b611b6186866000818110611b2157611b216145ce565b611b37926020606090920201908101915061412a565b33611b4e8989600081811061082d5761082d6145ce565b8a6000815181106108ac576108ac6145ce565b611bb3878787808060200260200160405190810160405280939291908181526020016000905b82821015610d4157611ba46060830286013681900381019061461b565b81526020019060010190611b87565b509495945050505050565b6060600182511015611be25760405162461bcd60e51b81526004016106b9906145e4565b8151611bef90600161485a565b67ffffffffffffffff811115611c0757611c07614147565b604051908082528060200260200182016040528015611c30578160200160208202803683370190505b5090508281600081518110611c4757611c476145ce565b60200260200101818152505060005b8251811015611e39576000611cb2848381518110611c7657611c766145ce565b602002602001015160000151858481518110611c9457611c946145ce565b602002602001015160200151868581518110611312576113126145ce565b60405163e5e31b1360e01b81526001600160a01b0380831660048301529192507f00000000000000000000000000000000000000000000000000000000000000009091169063e5e31b1390602401602060405180830381865afa158015611d1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d41919061469c565b15611e2657806001600160a01b031663f140a35a848481518110611d6757611d676145ce565b6020026020010151868581518110611d8157611d816145ce565b6020026020010151600001516040518363ffffffff1660e01b8152600401611dbc9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa158015611dd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dfd9190614763565b83611e0984600161485a565b81518110611e1957611e196145ce565b6020026020010181815250505b5080611e3181614872565b915050611c56565b5092915050565b6000806000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636801cc308a8a8a6040518463ffffffff1660e01b8152600401611e969392919061477c565b602060405180830381865afa158015611eb3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed791906147a0565b9050600080806001600160a01b03841615611f6157836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4e9190614763565b9050611f5b8c8c8c6119e5565b90935091505b82158015611f6d575081155b15611f9e578896508795506103e8611f8d611f88888a6147bd565b612ed2565b611f9791906145b7565b9450612031565b6000611fab8a8585612f42565b9050888111611ff357899750955085611fec84611fc8848b6147bd565b611fd291906147dc565b84611fdd858b6147bd565b611fe791906147dc565b61301a565b955061202f565b60006120008a8587612f42565b985089975088905061202b8561201685846147bd565b61202091906147dc565b85611fdd868c6147bd565b9650505b505b50505050955095509592505050565b60008060006120508f8f8f6114b5565b905060008761205f578c612063565b6000195b60405163d505accf60e01b81529091506001600160a01b0383169063d505accf9061209e903390309086908f908e908e908e9060040161488d565b600060405180830381600087803b1580156120b857600080fd5b505af11580156120cc573d6000803e3d6000fd5b50505050506120e18f8f8f8f8f8f8f8f610d56565b8093508194505050509c509c9a5050505050505050505050565b600080824281101561211f5760405162461bcd60e51b81526004016106b990614572565b61214f8a7f00000000000000000000000000000000000000000000000000000000000000008b8b8b8b308b610d56565b909350915061215f8a8685613030565b604051632e1a7d4d60e01b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b1580156121c157600080fd5b505af11580156121d5573d6000803e3d6000fd5b505050506121e38583612be6565b5097509795505050505050565b600080546001600160a01b03163314612231576000546040516374e0514b60e11b81523360048201526001600160a01b0390911660248201526044016106b9565b6001600160a01b039091166000908152600160208190526040909120805460ff1916909117905590565b600080600061228b8e7f00000000000000000000000000000000000000000000000000000000000000008f6114b5565b905060008761229a578c61229e565b6000195b60405163d505accf60e01b81529091506001600160a01b0383169063d505accf906122d9903390309086908f908e908e908e9060040161488d565b600060405180830381600087803b1580156122f357600080fd5b505af1158015612307573d6000803e3d6000fd5b5050505061231a8f8f8f8f8f8f8f6120fb565b809450819550505050509b509b9950505050505050505050565b60405163e5e31b1360e01b81526001600160a01b0382811660048301526000917f00000000000000000000000000000000000000000000000000000000000000009091169063e5e31b1390602401602060405180830381865afa15801561239f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c3919061469c565b92915050565b606081428110156123ec5760405162461bcd60e51b81526004016106b990614572565b61243e888787808060200260200160405190810160405280939291908181526020016000905b828210156107985761242f6060830286013681900381019061461b565b81526020019060010190612412565b915086826001845161245091906145b7565b81518110612460576124606145ce565b602002602001015110156124865760405162461bcd60e51b81526004016106b990614637565b61249c86866000818110610800576108006145ce565b6109ec828787808060200260200160405190810160405280939291908181526020016000905b82821015610d41576124df6060830286013681900381019061461b565b815260200190600101906124c2565b6000806000836001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa158015612531573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261255991908101906148fa565b905061258381604051806040016040528060068152602001656343414e544f60d01b81525061311f565b156125de577f000000000000000000000000000000000000000000000000000000000000000091506125d67f00000000000000000000000000000000000000000000000000000000000000006000613178565b949350505050565b836001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561261c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264091906147a0565b91506126698160405180604001604052806005815260200164634e4f544560d81b81525061311f565b1561267f5750670de0b6b3a76400009392505050565b6126a6816040518060400160405280600581526020016418d554d11560da1b81525061311f565b80156126da5750336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145b15612775576000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561271f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612743919061498e565b60ff16905061275381600a614a8f565b61276c906ec097ce7bc90715b34b9f10000000006147dc565b95945050505050565b61279c8160405180604001604052806005815260200164635553444360d81b81525061311f565b80156127d05750336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145b15612815576000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561271f573d6000803e3d6000fd5b5061281f81612334565b156128345761282d816132d8565b9392505050565b6001600160a01b03811660009081526001602052604090205460ff16156128605761282d816001613178565b670de0b6b3a76400006128947f00000000000000000000000000000000000000000000000000000000000000006000613178565b61289d83613b2c565b6128a791906147bd565b61282d91906147dc565b6000846001600160a01b03163b1161290b5760405162461bcd60e51b815260206004820152601960248201527f746f6b656e20636f6465206c656e677468206661696c7572650000000000000060448201526064016106b9565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390528591908216906323b872dd906064016020604051808303816000875af1158015612965573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612989919061469c565b505050505050565b60005b8251811015612be05760006129e38483815181106129b4576129b46145ce565b6020026020010151600001518584815181106129d2576129d26145ce565b6020026020010151602001516115bd565b5090506000856129f484600161485a565b81518110612a0457612a046145ce565b60200260200101519050600080836001600160a01b0316878681518110612a2d57612a2d6145ce565b6020026020010151600001516001600160a01b031614612a4f57826000612a53565b6000835b91509150600060018851612a6791906145b7565b8610612a735786612ae6565b612ae688612a8288600161485a565b81518110612a9257612a926145ce565b60200260200101516000015189886001612aac919061485a565b81518110612abc57612abc6145ce565b6020026020010151602001518a896001612ad6919061485a565b81518110611312576113126145ce565b9050612b39888781518110612afd57612afd6145ce565b602002602001015160000151898881518110612b1b57612b1b6145ce565b6020026020010151602001518a8981518110611312576113126145ce565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f191660200182016040528015612b76576020820181803683370190505b506040518563ffffffff1660e01b8152600401612b969493929190614a9b565b600060405180830381600087803b158015612bb057600080fd5b505af1158015612bc4573d6000803e3d6000fd5b5050505050505050508080612bd890614872565b915050612994565b50505050565b604080516000808252602082019092526001600160a01b038416908390604051612c109190614aeb565b60006040518083038185875af1925050503d8060008114612c4d576040519150601f19603f3d011682016040523d82523d6000602084013e612c52565b606091505b5050905080612caf5760405162461bcd60e51b815260206004820152602360248201527f5472616e7366657248656c7065723a204554485f5452414e534645525f46414960448201526213115160ea1b60648201526084016106b9565b505050565b60008083861015612cc457600080fd5b82851015612cd157600080fd5b6040516306801cc360e41b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636801cc3090612d24908d908d908d9060040161477c565b602060405180830381865afa158015612d41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d6591906147a0565b90506001600160a01b038116612e0b576040516320b7f73960e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906382dfdce490612dc5908d908d908d9060040161477c565b6020604051808303816000875af1158015612de4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0891906147a0565b90505b600080612e198c8c8c6119e5565b91509150816000148015612e2b575080155b15612e3b57889450879350612ec3565b6000612e488a8484612f42565b9050888111612e7c5786811015612e715760405162461bcd60e51b81526004016106b990614720565b899550935083612ec1565b6000612e898a8486612f42565b90508a811115612e9b57612e9b613c8a565b88811015612ebb5760405162461bcd60e51b81526004016106b9906146dd565b95508894505b505b50505097509795505050505050565b60006003821115612f335750806000612eec6002836147dc565b612ef790600161485a565b90505b81811015612f2d57905080600281612f1281866147dc565b612f1c919061485a565b612f2691906147dc565b9050612efa565b50919050565b8115612f3d575060015b919050565b6000808411612f9d5760405162461bcd60e51b815260206004820152602160248201527f426173655631526f757465723a20494e53554646494349454e545f414d4f554e6044820152601560fa1b60648201526084016106b9565b600083118015612fad5750600082115b6130055760405162461bcd60e51b8152602060048201526024808201527f426173655631526f757465723a20494e53554646494349454e545f4c495155496044820152634449545960e01b60648201526084016106b9565b8261301083866147bd565b6125d691906147dc565b6000818310613029578161282d565b5090919050565b6000836001600160a01b03163b1161304757600080fd5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916130a39190614aeb565b6000604051808303816000865af19150503d80600081146130e0576040519150601f19603f3d011682016040523d82523d6000602084013e6130e5565b606091505b509150915081801561310f57508051158061310f57508080602001905181019061310f919061469c565b61311857600080fd5b5050505050565b6000816040516020016131329190614aeb565b60405160208183030381529060405280519060200120836040516020016131599190614aeb565b6040516020818303038152906040528051906020012014905092915050565b600082816131a77f000000000000000000000000000000000000000000000000000000000000000083866114b5565b90506131b281612334565b6131c1576000925050506123c3565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613201573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613225919061498e565b61323090600a614b07565b604051639e8cc04b60e01b81526001600160a01b0385811660048301526024820183905260086044830152919250600091841690639e8cc04b90606401602060405180830381865afa15801561328a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ae9190614763565b9050816132c382670de0b6b3a76400006147bd565b6132cd91906147dc565b979650505050505050565b60405163eba6aef960e01b8152600860048201526001602482015260009081906001600160a01b0384169063eba6aef990604401600060405180830381865afa158015613329573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526133519190810190614b71565b905060608060606000866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613398573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133bc91906147a0565b90506000876001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061342291906147a0565b90506000886001600160a01b03166322be3de16040518163ffffffff1660e01b8152600401602060405180830381865afa158015613464573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613488919061469c565b1561379a577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316141561363157816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613505573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613529919061498e565b61353490600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe19061356b9085908590600890600190600401614ba6565b600060405180830381865afa158015613588573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526135b09190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa1580156135ff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136279190810190614bcc565b9095509350613977565b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561366f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613693919061498e565b61369e90600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe1906136d59086908590600890600190600401614ba6565b600060405180830381865afa1580156136f2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371a9190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa158015613769573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526137919190810190614bcc565b95509350613977565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316141561381257816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613505573d6000803e3d6000fd5b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613850573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613874919061498e565b61387f90600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe1906138b69086908590600890600190600401614ba6565b600060405180830381865afa1580156138d3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526138fb9190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa15801561394a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526139729190810190614bcc565b955093505b6000805b6008811015613a5057600083898381518110613999576139996145ce565b60200260200101516139ab91906147dc565b8783815181106139bd576139bd6145ce565b60200260200101516139cf91906147bd565b905060008883815181106139e5576139e56145ce565b602002602001015190508a8381518110613a0157613a016145ce565b60200260200101518183613a15919061485a565b613a2790670de0b6b3a76400006147bd565b613a3191906147dc565b613a3b908561485a565b9350505080613a4990614872565b905061397b565b506000613a5e6008836147dc565b90508a6001600160a01b03166322be3de16040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ac2919061469c565b15613ad5579a9950505050505050505050565b670de0b6b3a7640000613b097f00000000000000000000000000000000000000000000000000000000000000006000613178565b613b1390836147bd565b613b1d91906147dc565b9b9a5050505050505050505050565b60008181613b5b7f000000000000000000000000000000000000000000000000000000000000000083836114b5565b9050613b6681612334565b613b74575060009392505050565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613bb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bd8919061498e565b613be390600a614b07565b604051639e8cc04b60e01b81526001600160a01b0385811660048301526024820183905260086044830152919250600091841690639e8cc04b90606401602060405180830381865afa158015613c3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c619190614763565b905081613c7682670de0b6b3a76400006147bd565b613c8091906147dc565b9695505050505050565b634e487b7160e01b600052600160045260246000fd5b60008083601f840112613cb257600080fd5b50813567ffffffffffffffff811115613cca57600080fd5b6020830191508360206060830285010111156116aa57600080fd5b6001600160a01b0381168114613cfa57600080fd5b50565b8035612f3d81613ce5565b60008060008060008060a08789031215613d2157600080fd5b8635955060208701359450604087013567ffffffffffffffff811115613d4657600080fd5b613d5289828a01613ca0565b9095509350506060870135613d6681613ce5565b80925050608087013590509295509295509295565b6020808252825182820181905260009190848201906040850190845b81811015613db357835183529284019291840191600101613d97565b50909695505050505050565b600080600080600060808688031215613dd757600080fd5b85359450602086013567ffffffffffffffff811115613df557600080fd5b613e0188828901613ca0565b9095509350506040860135613e1581613ce5565b949793965091946060013592915050565b8015158114613cfa57600080fd5b600080600080600080600080610100898b031215613e5157600080fd5b8835613e5c81613ce5565b97506020890135613e6c81613ce5565b96506040890135613e7c81613e26565b9550606089013594506080890135935060a0890135925060c0890135613ea181613ce5565b8092505060e089013590509295985092959890939650565b600080600080600080600060e0888a031215613ed457600080fd5b8735613edf81613ce5565b96506020880135613eef81613e26565b955060408801359450606088013593506080880135925060a0880135613f1481613ce5565b8092505060c0880135905092959891949750929550565b600080600080600080600060e0888a031215613f4657600080fd5b87359650602088013595506040880135613f5f81613ce5565b94506060880135613f6f81613ce5565b93506080880135613f7f81613e26565b925060a0880135613f1481613ce5565b60008060008060808587031215613fa557600080fd5b8435613fb081613ce5565b93506020850135613fc081613ce5565b92506040850135613fd081613e26565b9396929550929360600135925050565b600080600060608486031215613ff557600080fd5b833561400081613ce5565b9250602084013561401081613ce5565b9150604084013561402081613e26565b809150509250925092565b6000806040838503121561403e57600080fd5b823561404981613ce5565b9150602083013561405981613ce5565b809150509250929050565b60008060008060008060008060006101208a8c03121561408357600080fd5b893561408e81613ce5565b985060208a013561409e81613ce5565b975060408a01356140ae81613e26565b965060608a0135955060808a0135945060a08a0135935060c08a0135925060e08a01356140da81613ce5565b809250506101008a013590509295985092959850929598565b60008060006060848603121561410857600080fd5b83359250602084013561411a81613ce5565b9150604084013561402081613ce5565b60006020828403121561413c57600080fd5b813561282d81613ce5565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561418657614186614147565b604052919050565b600067ffffffffffffffff8211156141a8576141a8614147565b5060051b60200190565b6000806000806000608086880312156141ca57600080fd5b853567ffffffffffffffff808211156141e257600080fd5b818801915088601f8301126141f657600080fd5b8135602061420b6142068361418e565b61415d565b82815260059290921b8401810191818101908c84111561422a57600080fd5b948201945b838610156142485785358252948201949082019061422f565b9950508901359250508082111561425e57600080fd5b5061426b88828901613ca0565b9095509350613e15905060408701613cfd565b60006060828403121561429057600080fd5b6040516060810181811067ffffffffffffffff821117156142b3576142b3614147565b60405290508082356142c481613ce5565b815260208301356142d481613ce5565b602082015260408301356142e781613e26565b6040919091015292915050565b6000806040838503121561430757600080fd5b8235915060208084013567ffffffffffffffff81111561432657600080fd5b8401601f8101861361433757600080fd5b80356143456142068261418e565b8181526060918202830184019184820191908984111561436457600080fd5b938501935b8385101561438a5761437b8a8661427e565b83529384019391850191614369565b5080955050505050509250929050565b600080600080600060a086880312156143b257600080fd5b85356143bd81613ce5565b945060208601356143cd81613ce5565b935060408601356143dd81613e26565b94979396509394606081013594506080013592915050565b60ff81168114613cfa57600080fd5b6000806000806000806000806000806000806101808d8f03121561442757600080fd5b8c3561443281613ce5565b9b5060208d013561444281613ce5565b9a5060408d013561445281613e26565b995060608d0135985060808d0135975060a08d0135965060c08d013561447781613ce5565b955060e08d013594506101008d013561448f81613e26565b93506101208d01356144a0816143f5565b809350506101408d013591506101608d013590509295989b509295989b509295989b565b60008060008060008060008060008060006101608c8e0312156144e657600080fd5b8b356144f181613ce5565b9a5060208c013561450181613e26565b995060408c0135985060608c0135975060808c0135965060a08c013561452681613ce5565b955060c08c0135945060e08c013561453d81613e26565b93506101008c013561454e816143f5565b809350506101208c013591506101408c013590509295989b509295989b9093969950565b60208082526015908201527410985cd9558c549bdd5d195c8e8811561412549151605a1b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b6000828210156145c9576145c96145a1565b500390565b634e487b7160e01b600052603260045260246000fd5b6020808252601a908201527f426173655631526f757465723a20494e56414c49445f50415448000000000000604082015260600190565b60006060828403121561462d57600080fd5b61282d838361427e565b60208082526028908201527f426173655631526f757465723a20494e53554646494349454e545f4f555450556040820152671517d05353d5539560c21b606082015260800190565b60006020828403121561469157600080fd5b813561282d81613e26565b6000602082840312156146ae57600080fd5b815161282d81613e26565b600080604083850312156146cc57600080fd5b505080516020909101519092909150565b60208082526023908201527f426173655631526f757465723a20494e53554646494349454e545f415f414d4f60408201526215539560ea1b606082015260800190565b60208082526023908201527f426173655631526f757465723a20494e53554646494349454e545f425f414d4f60408201526215539560ea1b606082015260800190565b60006020828403121561477557600080fd5b5051919050565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6000602082840312156147b257600080fd5b815161282d81613ce5565b60008160001904831182151516156147d7576147d76145a1565b500290565b6000826147f957634e487b7160e01b600052601260045260246000fd5b500490565b80516001600160701b0381168114612f3d57600080fd5b60008060006060848603121561482a57600080fd5b614833846147fe565b9250614841602085016147fe565b9150604084015163ffffffff8116811461402057600080fd5b6000821982111561486d5761486d6145a1565b500190565b6000600019821415614886576148866145a1565b5060010190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b60005b838110156148e95781810151838201526020016148d1565b83811115612be05750506000910152565b60006020828403121561490c57600080fd5b815167ffffffffffffffff8082111561492457600080fd5b818401915084601f83011261493857600080fd5b81518181111561494a5761494a614147565b61495d601f8201601f191660200161415d565b915080825285602082850101111561497457600080fd5b6149858160208401602086016148ce565b50949350505050565b6000602082840312156149a057600080fd5b815161282d816143f5565b600181815b808511156149e65781600019048211156149cc576149cc6145a1565b808516156149d957918102915b93841c93908002906149b0565b509250929050565b6000826149fd575060016123c3565b81614a0a575060006123c3565b8160018114614a205760028114614a2a57614a46565b60019150506123c3565b60ff841115614a3b57614a3b6145a1565b50506001821b6123c3565b5060208310610133831016604e8410600b8410161715614a69575081810a6123c3565b614a7383836149ab565b8060001904821115614a8757614a876145a1565b029392505050565b600061282d83836149ee565b84815283602082015260018060a01b03831660408201526080606082015260008251806080840152614ad48160a08501602087016148ce565b601f01601f19169190910160a00195945050505050565b60008251614afd8184602087016148ce565b9190910192915050565b600061282d60ff8416836149ee565b600082601f830112614b2757600080fd5b81516020614b376142068361418e565b82815260059290921b84018101918181019086841115614b5657600080fd5b8286015b848110156109ec5780518352918301918301614b5a565b600060208284031215614b8357600080fd5b815167ffffffffffffffff811115614b9a57600080fd5b6125d684828501614b16565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b60008060408385031215614bdf57600080fd5b825167ffffffffffffffff80821115614bf757600080fd5b614c0386838701614b16565b93506020850151915080821115614c1957600080fd5b50614c2685828601614b16565b915050925092905056fea264697066735822122062b3297058a69e7aca6dd201a40cc1f104537c2c0c273f0017df4ff58eeb862064736f6c634300080b0033000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b0000000000000000000000004e71a2e537b7f9d9413d3991d37958c0b5e1e5030000000000000000000000005e23dc409fc2f832f83cec191e245a191a4bcc5c
Deployed ByteCode
0x6080604052600436106101c65760003560e01c8063704b6c02116100f7578063c45a015511610095578063e5e31b1311610064578063e5e31b1314610616578063f41766d814610636578063f851a44014610656578063fc57d4df1461067657600080fd5b8063c45a015514610574578063c79db9d7146105a8578063dba71376146105c8578063dd54e2a4146105f657600080fd5b80639185f6ec116100d15780639185f6ec146104e45780639881fcb41461051457806398a0fb3c14610534578063a32b1fcd1461055457600080fd5b8063704b6c02146104705780637301e3c8146104905780637aa497d9146104b057600080fd5b80634ae36e8e116101645780635a47ddc31161013e5780635a47ddc3146103d65780635e1e6325146103f65780635e60dab51461042b57806366331bba1461044b57600080fd5b80634ae36e8e146103425780634c1ee03e14610376578063544caa561461039657600080fd5b8063116e4ea3116101a0578063116e4ea31461028857806313dcfc59146102b657806326d111f5146102d65780634386e63c1461032257600080fd5b80630483e3cc1461020a578063058e200a146102405780630dede6c41461025357600080fd5b3661020557336001600160a01b037f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b161461020357610203613c8a565b005b600080fd5b34801561021657600080fd5b5061022a610225366004613d08565b610696565b6040516102379190613d7b565b60405180910390f35b61022a61024e366004613dbf565b6109f7565b34801561025f57600080fd5b5061027361026e366004613e34565b610d56565b60408051928352602083019190915201610237565b61029b610296366004613eb9565b610f07565b60408051938452602084019290925290820152606001610237565b3480156102c257600080fd5b5061022a6102d1366004613f2b565b611148565b3480156102e257600080fd5b5061030a7f0000000000000000000000004e71a2e537b7f9d9413d3991d37958c0b5e1e50381565b6040516001600160a01b039091168152602001610237565b34801561032e57600080fd5b5061027361033d366004613f8f565b61134e565b34801561034e57600080fd5b5061030a7f0000000000000000000000005e23dc409fc2f832f83cec191e245a191a4bcc5c81565b34801561038257600080fd5b5061030a610391366004613fe0565b6114b5565b3480156103a257600080fd5b506103b66103b136600461402b565b6115bd565b604080516001600160a01b03938416815292909116602083015201610237565b3480156103e257600080fd5b5061029b6103f1366004614064565b6116b1565b34801561040257600080fd5b506104166104113660046140f3565b611791565b60408051928352901515602083015201610237565b34801561043757600080fd5b50610273610446366004613fe0565b6119e5565b34801561045757600080fd5b50610460600181565b6040519015158152602001610237565b34801561047c57600080fd5b5061020361048b36600461412a565b611aaf565b34801561049c57600080fd5b5061022a6104ab3660046141b2565b611ae8565b3480156104bc57600080fd5b5061030a7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b81565b3480156104f057600080fd5b506104606104ff36600461412a565b60016020526000908152604090205460ff1681565b34801561052057600080fd5b5061022a61052f3660046142f4565b611bbe565b34801561054057600080fd5b5061029b61054f36600461439a565b611e40565b34801561056057600080fd5b5061027361056f366004614404565b612040565b34801561058057600080fd5b5061030a7f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba81565b3480156105b457600080fd5b506102736105c3366004613eb9565b6120fb565b3480156105d457600080fd5b506105e86105e336600461412a565b6121f0565b604051908152602001610237565b34801561060257600080fd5b506102736106113660046144c4565b61225b565b34801561062257600080fd5b5061046061063136600461412a565b612334565b34801561064257600080fd5b5061022a610651366004613d08565b6123c9565b34801561066257600080fd5b5060005461030a906001600160a01b031681565b34801561068257600080fd5b506105e861069136600461412a565b6124ee565b606081428110156106c25760405162461bcd60e51b81526004016106b990614572565b60405180910390fd5b6001600160a01b037f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b1686866106f96001826145b7565b818110610708576107086145ce565b9050606002016020016020810190610720919061412a565b6001600160a01b0316146107465760405162461bcd60e51b81526004016106b9906145e4565b6107a2888787808060200260200160405190810160405280939291908181526020016000905b82821015610798576107896060830286013681900381019061461b565b8152602001906001019061076c565b5050505050611bbe565b91508682600184516107b491906145b7565b815181106107c4576107c46145ce565b602002602001015110156107ea5760405162461bcd60e51b81526004016106b990614637565b6108b986866000818110610800576108006145ce565b610816926020606090920201908101915061412a565b336108998989600081811061082d5761082d6145ce565b610843926020606090920201908101915061412a565b8a8a6000818110610856576108566145ce565b905060600201602001602081019061086e919061412a565b8b8b6000818110610881576108816145ce565b9050606002016040016020810190610391919061467f565b856000815181106108ac576108ac6145ce565b60200260200101516128b1565b610916828787808060200260200160405190810160405280939291908181526020016000905b8282101561090b576108fc6060830286013681900381019061461b565b815260200190600101906108df565b505050505030612991565b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b0316632e1a7d4d836001855161095491906145b7565b81518110610964576109646145ce565b60200260200101516040518263ffffffff1660e01b815260040161098a91815260200190565b600060405180830381600087803b1580156109a457600080fd5b505af11580156109b8573d6000803e3d6000fd5b505050506109ec8483600185516109cf91906145b7565b815181106109df576109df6145ce565b6020026020010151612be6565b509695505050505050565b60608142811015610a1a5760405162461bcd60e51b81526004016106b990614572565b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b031686866000818110610a5757610a576145ce565b610a6d926020606090920201908101915061412a565b6001600160a01b031614610a935760405162461bcd60e51b81526004016106b9906145e4565b610ae5348787808060200260200160405190810160405280939291908181526020016000905b8282101561079857610ad66060830286013681900381019061461b565b81526020019060010190610ab9565b9150868260018451610af791906145b7565b81518110610b0757610b076145ce565b60200260200101511015610b2d5760405162461bcd60e51b81526004016106b990614637565b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b031663d0e30db083600081518110610b6f57610b6f6145ce565b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b158015610ba257600080fd5b505af1158015610bb6573d6000803e3d6000fd5b50505050507f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b031663a9059cbb610c5488886000818110610c0057610c006145ce565b610c16926020606090920201908101915061412a565b89896000818110610c2957610c296145ce565b9050606002016020016020810190610c41919061412a565b8a8a6000818110610881576108816145ce565b84600081518110610c6757610c676145ce565b60200260200101516040518363ffffffff1660e01b8152600401610ca09291906001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015610cbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce3919061469c565b610cef57610cef613c8a565b610d4c828787808060200260200160405190810160405280939291908181526020016000905b82821015610d4157610d326060830286013681900381019061461b565b81526020019060010190610d15565b505050505086612991565b5095945050505050565b6000808242811015610d7a5760405162461bcd60e51b81526004016106b990614572565b6000610d878c8c8c6114b5565b6040516323b872dd60e01b81523360048201526001600160a01b03821660248201819052604482018c90529192506323b872dd906064016020604051808303816000875af1158015610ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e01919061469c565b610e0a57600080fd5b60405163226bf2d160e21b81526001600160a01b03878116600483015260009182918416906389afcb449060240160408051808303816000875af1158015610e56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7a91906146b9565b915091506000610e8a8f8f6115bd565b509050806001600160a01b03168f6001600160a01b031614610ead578183610eb0565b82825b90975095508a871015610ed55760405162461bcd60e51b81526004016106b9906146dd565b89861015610ef55760405162461bcd60e51b81526004016106b990614720565b50505050509850989650505050505050565b60008060008342811015610f2d5760405162461bcd60e51b81526004016106b990614572565b610f5c8b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b8c8c348d8d612cb4565b90945092506000610f8e8c7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b8d6114b5565b9050610f9c8c3383886128b1565b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b031663d0e30db0856040518263ffffffff1660e01b81526004016000604051808303818588803b158015610ff757600080fd5b505af115801561100b573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038581166004830152602482018990527f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b16935063a9059cbb925060440190506020604051808303816000875af1158015611080573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a4919061469c565b6110b0576110b0613c8a565b6040516335313c2160e11b81526001600160a01b038881166004830152821690636a627842906024016020604051808303816000875af11580156110f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111c9190614763565b925083341115611139576111393361113486346145b7565b612be6565b50509750975097945050505050565b6060814281101561116b5760405162461bcd60e51b81526004016106b990614572565b604080516001808252818301909252600091816020015b604080516060810182526000808252602080830182905292820152825260001990920191018161118257905050905087816000815181106111c5576111c56145ce565b6020026020010151600001906001600160a01b031690816001600160a01b03168152505086816000815181106111fd576111fd6145ce565b6020026020010151602001906001600160a01b031690816001600160a01b0316815250508581600081518110611235576112356145ce565b60209081029190910101519015156040909101526112538a82611bbe565b925088836001855161126591906145b7565b81518110611275576112756145ce565b6020026020010151101561129b5760405162461bcd60e51b81526004016106b990614637565b611336816000815181106112b1576112b16145ce565b60200260200101516000015133611323846000815181106112d4576112d46145ce565b602002602001015160000151856000815181106112f3576112f36145ce565b60200260200101516020015186600081518110611312576113126145ce565b6020026020010151604001516114b5565b866000815181106108ac576108ac6145ce565b611341838287612991565b5050979650505050505050565b60008060007f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba6001600160a01b0316636801cc308888886040518463ffffffff1660e01b81526004016113a39392919061477c565b602060405180830381865afa1580156113c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113e491906147a0565b90506001600160a01b0381166114015760008092509250506114ac565b60008061140f8989896119e5565b915091506000836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611453573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114779190614763565b90508061148484896147bd565b61148e91906147dc565b95508061149b83896147bd565b6114a591906147dc565b9450505050505b94509492505050565b60008060006114c486866115bd565b6040516bffffffffffffffffffffffff19606084811b8216602084015283901b16603482015286151560f81b604882015291935091507f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba90604901604051602081830303815290604052805190602001207f97653931c50be3c0550346c96798d2d21ba0ebddcbc1a6debaa0669b70bb573560405160200161159b939291906001600160f81b0319815260609390931b6bffffffffffffffffffffffff191660018401526015830191909152603582015260550190565b60408051601f1981840301815291905280516020909101209695505050505050565b600080826001600160a01b0316846001600160a01b0316141561162c5760405162461bcd60e51b815260206004820152602160248201527f426173655631526f757465723a204944454e544943414c5f41444452455353456044820152605360f81b60648201526084016106b9565b826001600160a01b0316846001600160a01b03161061164c57828461164f565b83835b90925090506001600160a01b0382166116aa5760405162461bcd60e51b815260206004820152601a60248201527f426173655631526f757465723a205a45524f5f4144445245535300000000000060448201526064016106b9565b9250929050565b600080600083428110156116d75760405162461bcd60e51b81526004016106b990614572565b6116e68d8d8d8d8d8d8d612cb4565b909450925060006116f88e8e8e6114b5565b90506117068e3383886128b1565b6117128d3383876128b1565b6040516335313c2160e11b81526001600160a01b038881166004830152821690636a627842906024016020604051808303816000875af115801561175a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061177e9190614763565b9250505099509950999650505050505050565b60008060006117a2858560016114b5565b60405163e5e31b1360e01b81526001600160a01b03828116600483015291925060009182917f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba9091169063e5e31b1390602401602060405180830381865afa158015611812573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611836919061469c565b156118af576040516378a051ad60e11b8152600481018990526001600160a01b03888116602483015284169063f140a35a90604401602060405180830381865afa158015611888573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ac9190614763565b91505b6118bb878760006114b5565b60405163e5e31b1360e01b81526001600160a01b0380831660048301529194507f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba9091169063e5e31b1390602401602060405180830381865afa158015611926573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194a919061469c565b156119c3576040516378a051ad60e11b8152600481018990526001600160a01b03888116602483015284169063f140a35a90604401602060405180830381865afa15801561199c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c09190614763565b90505b8082116119d2578060006119d6565b8160015b94509450505050935093915050565b60008060006119f486866115bd565b509050600080611a058888886114b5565b6001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611a42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a669190614815565b506001600160701b031691506001600160701b03169150826001600160a01b0316886001600160a01b031614611a9d578082611aa0565b81815b90999098509650505050505050565b6000546001600160a01b03163314611ac657600080fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b60608142811015611b0b5760405162461bcd60e51b81526004016106b990614572565b611b6186866000818110611b2157611b216145ce565b611b37926020606090920201908101915061412a565b33611b4e8989600081811061082d5761082d6145ce565b8a6000815181106108ac576108ac6145ce565b611bb3878787808060200260200160405190810160405280939291908181526020016000905b82821015610d4157611ba46060830286013681900381019061461b565b81526020019060010190611b87565b509495945050505050565b6060600182511015611be25760405162461bcd60e51b81526004016106b9906145e4565b8151611bef90600161485a565b67ffffffffffffffff811115611c0757611c07614147565b604051908082528060200260200182016040528015611c30578160200160208202803683370190505b5090508281600081518110611c4757611c476145ce565b60200260200101818152505060005b8251811015611e39576000611cb2848381518110611c7657611c766145ce565b602002602001015160000151858481518110611c9457611c946145ce565b602002602001015160200151868581518110611312576113126145ce565b60405163e5e31b1360e01b81526001600160a01b0380831660048301529192507f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba9091169063e5e31b1390602401602060405180830381865afa158015611d1d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d41919061469c565b15611e2657806001600160a01b031663f140a35a848481518110611d6757611d676145ce565b6020026020010151868581518110611d8157611d816145ce565b6020026020010151600001516040518363ffffffff1660e01b8152600401611dbc9291909182526001600160a01b0316602082015260400190565b602060405180830381865afa158015611dd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dfd9190614763565b83611e0984600161485a565b81518110611e1957611e196145ce565b6020026020010181815250505b5080611e3181614872565b915050611c56565b5092915050565b6000806000807f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba6001600160a01b0316636801cc308a8a8a6040518463ffffffff1660e01b8152600401611e969392919061477c565b602060405180830381865afa158015611eb3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed791906147a0565b9050600080806001600160a01b03841615611f6157836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4e9190614763565b9050611f5b8c8c8c6119e5565b90935091505b82158015611f6d575081155b15611f9e578896508795506103e8611f8d611f88888a6147bd565b612ed2565b611f9791906145b7565b9450612031565b6000611fab8a8585612f42565b9050888111611ff357899750955085611fec84611fc8848b6147bd565b611fd291906147dc565b84611fdd858b6147bd565b611fe791906147dc565b61301a565b955061202f565b60006120008a8587612f42565b985089975088905061202b8561201685846147bd565b61202091906147dc565b85611fdd868c6147bd565b9650505b505b50505050955095509592505050565b60008060006120508f8f8f6114b5565b905060008761205f578c612063565b6000195b60405163d505accf60e01b81529091506001600160a01b0383169063d505accf9061209e903390309086908f908e908e908e9060040161488d565b600060405180830381600087803b1580156120b857600080fd5b505af11580156120cc573d6000803e3d6000fd5b50505050506120e18f8f8f8f8f8f8f8f610d56565b8093508194505050509c509c9a5050505050505050505050565b600080824281101561211f5760405162461bcd60e51b81526004016106b990614572565b61214f8a7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b8b8b8b8b308b610d56565b909350915061215f8a8685613030565b604051632e1a7d4d60e01b8152600481018390527f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b031690632e1a7d4d90602401600060405180830381600087803b1580156121c157600080fd5b505af11580156121d5573d6000803e3d6000fd5b505050506121e38583612be6565b5097509795505050505050565b600080546001600160a01b03163314612231576000546040516374e0514b60e11b81523360048201526001600160a01b0390911660248201526044016106b9565b6001600160a01b039091166000908152600160208190526040909120805460ff1916909117905590565b600080600061228b8e7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b8f6114b5565b905060008761229a578c61229e565b6000195b60405163d505accf60e01b81529091506001600160a01b0383169063d505accf906122d9903390309086908f908e908e908e9060040161488d565b600060405180830381600087803b1580156122f357600080fd5b505af1158015612307573d6000803e3d6000fd5b5050505061231a8f8f8f8f8f8f8f6120fb565b809450819550505050509b509b9950505050505050505050565b60405163e5e31b1360e01b81526001600160a01b0382811660048301526000917f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba9091169063e5e31b1390602401602060405180830381865afa15801561239f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123c3919061469c565b92915050565b606081428110156123ec5760405162461bcd60e51b81526004016106b990614572565b61243e888787808060200260200160405190810160405280939291908181526020016000905b828210156107985761242f6060830286013681900381019061461b565b81526020019060010190612412565b915086826001845161245091906145b7565b81518110612460576124606145ce565b602002602001015110156124865760405162461bcd60e51b81526004016106b990614637565b61249c86866000818110610800576108006145ce565b6109ec828787808060200260200160405190810160405280939291908181526020016000905b82821015610d41576124df6060830286013681900381019061461b565b815260200190600101906124c2565b6000806000836001600160a01b03166395d89b416040518163ffffffff1660e01b8152600401600060405180830381865afa158015612531573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261255991908101906148fa565b905061258381604051806040016040528060068152602001656343414e544f60d01b81525061311f565b156125de577f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b91506125d67f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6000613178565b949350505050565b836001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561261c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061264091906147a0565b91506126698160405180604001604052806005815260200164634e4f544560d81b81525061311f565b1561267f5750670de0b6b3a76400009392505050565b6126a6816040518060400160405280600581526020016418d554d11560da1b81525061311f565b80156126da5750336001600160a01b037f0000000000000000000000005e23dc409fc2f832f83cec191e245a191a4bcc5c16145b15612775576000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561271f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612743919061498e565b60ff16905061275381600a614a8f565b61276c906ec097ce7bc90715b34b9f10000000006147dc565b95945050505050565b61279c8160405180604001604052806005815260200164635553444360d81b81525061311f565b80156127d05750336001600160a01b037f0000000000000000000000005e23dc409fc2f832f83cec191e245a191a4bcc5c16145b15612815576000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561271f573d6000803e3d6000fd5b5061281f81612334565b156128345761282d816132d8565b9392505050565b6001600160a01b03811660009081526001602052604090205460ff16156128605761282d816001613178565b670de0b6b3a76400006128947f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6000613178565b61289d83613b2c565b6128a791906147bd565b61282d91906147dc565b6000846001600160a01b03163b1161290b5760405162461bcd60e51b815260206004820152601960248201527f746f6b656e20636f6465206c656e677468206661696c7572650000000000000060448201526064016106b9565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390528591908216906323b872dd906064016020604051808303816000875af1158015612965573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612989919061469c565b505050505050565b60005b8251811015612be05760006129e38483815181106129b4576129b46145ce565b6020026020010151600001518584815181106129d2576129d26145ce565b6020026020010151602001516115bd565b5090506000856129f484600161485a565b81518110612a0457612a046145ce565b60200260200101519050600080836001600160a01b0316878681518110612a2d57612a2d6145ce565b6020026020010151600001516001600160a01b031614612a4f57826000612a53565b6000835b91509150600060018851612a6791906145b7565b8610612a735786612ae6565b612ae688612a8288600161485a565b81518110612a9257612a926145ce565b60200260200101516000015189886001612aac919061485a565b81518110612abc57612abc6145ce565b6020026020010151602001518a896001612ad6919061485a565b81518110611312576113126145ce565b9050612b39888781518110612afd57612afd6145ce565b602002602001015160000151898881518110612b1b57612b1b6145ce565b6020026020010151602001518a8981518110611312576113126145ce565b6001600160a01b031663022c0d9f84848460006040519080825280601f01601f191660200182016040528015612b76576020820181803683370190505b506040518563ffffffff1660e01b8152600401612b969493929190614a9b565b600060405180830381600087803b158015612bb057600080fd5b505af1158015612bc4573d6000803e3d6000fd5b5050505050505050508080612bd890614872565b915050612994565b50505050565b604080516000808252602082019092526001600160a01b038416908390604051612c109190614aeb565b60006040518083038185875af1925050503d8060008114612c4d576040519150601f19603f3d011682016040523d82523d6000602084013e612c52565b606091505b5050905080612caf5760405162461bcd60e51b815260206004820152602360248201527f5472616e7366657248656c7065723a204554485f5452414e534645525f46414960448201526213115160ea1b60648201526084016106b9565b505050565b60008083861015612cc457600080fd5b82851015612cd157600080fd5b6040516306801cc360e41b81526000906001600160a01b037f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba1690636801cc3090612d24908d908d908d9060040161477c565b602060405180830381865afa158015612d41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d6591906147a0565b90506001600160a01b038116612e0b576040516320b7f73960e21b81526001600160a01b037f000000000000000000000000e387067f12561e579c5f7d4294f51867e0c1cfba16906382dfdce490612dc5908d908d908d9060040161477c565b6020604051808303816000875af1158015612de4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0891906147a0565b90505b600080612e198c8c8c6119e5565b91509150816000148015612e2b575080155b15612e3b57889450879350612ec3565b6000612e488a8484612f42565b9050888111612e7c5786811015612e715760405162461bcd60e51b81526004016106b990614720565b899550935083612ec1565b6000612e898a8486612f42565b90508a811115612e9b57612e9b613c8a565b88811015612ebb5760405162461bcd60e51b81526004016106b9906146dd565b95508894505b505b50505097509795505050505050565b60006003821115612f335750806000612eec6002836147dc565b612ef790600161485a565b90505b81811015612f2d57905080600281612f1281866147dc565b612f1c919061485a565b612f2691906147dc565b9050612efa565b50919050565b8115612f3d575060015b919050565b6000808411612f9d5760405162461bcd60e51b815260206004820152602160248201527f426173655631526f757465723a20494e53554646494349454e545f414d4f554e6044820152601560fa1b60648201526084016106b9565b600083118015612fad5750600082115b6130055760405162461bcd60e51b8152602060048201526024808201527f426173655631526f757465723a20494e53554646494349454e545f4c495155496044820152634449545960e01b60648201526084016106b9565b8261301083866147bd565b6125d691906147dc565b6000818310613029578161282d565b5090919050565b6000836001600160a01b03163b1161304757600080fd5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916130a39190614aeb565b6000604051808303816000865af19150503d80600081146130e0576040519150601f19603f3d011682016040523d82523d6000602084013e6130e5565b606091505b509150915081801561310f57508051158061310f57508080602001905181019061310f919061469c565b61311857600080fd5b5050505050565b6000816040516020016131329190614aeb565b60405160208183030381529060405280519060200120836040516020016131599190614aeb565b6040516020818303038152906040528051906020012014905092915050565b600082816131a77f0000000000000000000000004e71a2e537b7f9d9413d3991d37958c0b5e1e50383866114b5565b90506131b281612334565b6131c1576000925050506123c3565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613201573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613225919061498e565b61323090600a614b07565b604051639e8cc04b60e01b81526001600160a01b0385811660048301526024820183905260086044830152919250600091841690639e8cc04b90606401602060405180830381865afa15801561328a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ae9190614763565b9050816132c382670de0b6b3a76400006147bd565b6132cd91906147dc565b979650505050505050565b60405163eba6aef960e01b8152600860048201526001602482015260009081906001600160a01b0384169063eba6aef990604401600060405180830381865afa158015613329573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526133519190810190614b71565b905060608060606000866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613398573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133bc91906147a0565b90506000876001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061342291906147a0565b90506000886001600160a01b03166322be3de16040518163ffffffff1660e01b8152600401602060405180830381865afa158015613464573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613488919061469c565b1561379a577f0000000000000000000000004e71a2e537b7f9d9413d3991d37958c0b5e1e5036001600160a01b0316836001600160a01b0316141561363157816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613505573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613529919061498e565b61353490600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe19061356b9085908590600890600190600401614ba6565b600060405180830381865afa158015613588573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526135b09190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa1580156135ff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136279190810190614bcc565b9095509350613977565b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561366f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613693919061498e565b61369e90600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe1906136d59086908590600890600190600401614ba6565b600060405180830381865afa1580156136f2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371a9190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa158015613769573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526137919190810190614bcc565b95509350613977565b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6001600160a01b0316836001600160a01b0316141561381257816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613505573d6000803e3d6000fd5b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613850573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613874919061498e565b61387f90600a614b07565b6040516313345fe160e01b81529091506001600160a01b038a16906313345fe1906138b69086908590600890600190600401614ba6565b600060405180830381865afa1580156138d3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526138fb9190810190614b71565b604051637ccfa8d360e11b815260086004820152600160248201529096506001600160a01b038a169063f99f51a690604401600060405180830381865afa15801561394a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526139729190810190614bcc565b955093505b6000805b6008811015613a5057600083898381518110613999576139996145ce565b60200260200101516139ab91906147dc565b8783815181106139bd576139bd6145ce565b60200260200101516139cf91906147bd565b905060008883815181106139e5576139e56145ce565b602002602001015190508a8381518110613a0157613a016145ce565b60200260200101518183613a15919061485a565b613a2790670de0b6b3a76400006147bd565b613a3191906147dc565b613a3b908561485a565b9350505080613a4990614872565b905061397b565b506000613a5e6008836147dc565b90508a6001600160a01b03166322be3de16040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ac2919061469c565b15613ad5579a9950505050505050505050565b670de0b6b3a7640000613b097f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b6000613178565b613b1390836147bd565b613b1d91906147dc565b9b9a5050505050505050505050565b60008181613b5b7f000000000000000000000000826551890dc65655a0aceca109ab11abdbd7a07b83836114b5565b9050613b6681612334565b613b74575060009392505050565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613bb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bd8919061498e565b613be390600a614b07565b604051639e8cc04b60e01b81526001600160a01b0385811660048301526024820183905260086044830152919250600091841690639e8cc04b90606401602060405180830381865afa158015613c3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c619190614763565b905081613c7682670de0b6b3a76400006147bd565b613c8091906147dc565b9695505050505050565b634e487b7160e01b600052600160045260246000fd5b60008083601f840112613cb257600080fd5b50813567ffffffffffffffff811115613cca57600080fd5b6020830191508360206060830285010111156116aa57600080fd5b6001600160a01b0381168114613cfa57600080fd5b50565b8035612f3d81613ce5565b60008060008060008060a08789031215613d2157600080fd5b8635955060208701359450604087013567ffffffffffffffff811115613d4657600080fd5b613d5289828a01613ca0565b9095509350506060870135613d6681613ce5565b80925050608087013590509295509295509295565b6020808252825182820181905260009190848201906040850190845b81811015613db357835183529284019291840191600101613d97565b50909695505050505050565b600080600080600060808688031215613dd757600080fd5b85359450602086013567ffffffffffffffff811115613df557600080fd5b613e0188828901613ca0565b9095509350506040860135613e1581613ce5565b949793965091946060013592915050565b8015158114613cfa57600080fd5b600080600080600080600080610100898b031215613e5157600080fd5b8835613e5c81613ce5565b97506020890135613e6c81613ce5565b96506040890135613e7c81613e26565b9550606089013594506080890135935060a0890135925060c0890135613ea181613ce5565b8092505060e089013590509295985092959890939650565b600080600080600080600060e0888a031215613ed457600080fd5b8735613edf81613ce5565b96506020880135613eef81613e26565b955060408801359450606088013593506080880135925060a0880135613f1481613ce5565b8092505060c0880135905092959891949750929550565b600080600080600080600060e0888a031215613f4657600080fd5b87359650602088013595506040880135613f5f81613ce5565b94506060880135613f6f81613ce5565b93506080880135613f7f81613e26565b925060a0880135613f1481613ce5565b60008060008060808587031215613fa557600080fd5b8435613fb081613ce5565b93506020850135613fc081613ce5565b92506040850135613fd081613e26565b9396929550929360600135925050565b600080600060608486031215613ff557600080fd5b833561400081613ce5565b9250602084013561401081613ce5565b9150604084013561402081613e26565b809150509250925092565b6000806040838503121561403e57600080fd5b823561404981613ce5565b9150602083013561405981613ce5565b809150509250929050565b60008060008060008060008060006101208a8c03121561408357600080fd5b893561408e81613ce5565b985060208a013561409e81613ce5565b975060408a01356140ae81613e26565b965060608a0135955060808a0135945060a08a0135935060c08a0135925060e08a01356140da81613ce5565b809250506101008a013590509295985092959850929598565b60008060006060848603121561410857600080fd5b83359250602084013561411a81613ce5565b9150604084013561402081613ce5565b60006020828403121561413c57600080fd5b813561282d81613ce5565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561418657614186614147565b604052919050565b600067ffffffffffffffff8211156141a8576141a8614147565b5060051b60200190565b6000806000806000608086880312156141ca57600080fd5b853567ffffffffffffffff808211156141e257600080fd5b818801915088601f8301126141f657600080fd5b8135602061420b6142068361418e565b61415d565b82815260059290921b8401810191818101908c84111561422a57600080fd5b948201945b838610156142485785358252948201949082019061422f565b9950508901359250508082111561425e57600080fd5b5061426b88828901613ca0565b9095509350613e15905060408701613cfd565b60006060828403121561429057600080fd5b6040516060810181811067ffffffffffffffff821117156142b3576142b3614147565b60405290508082356142c481613ce5565b815260208301356142d481613ce5565b602082015260408301356142e781613e26565b6040919091015292915050565b6000806040838503121561430757600080fd5b8235915060208084013567ffffffffffffffff81111561432657600080fd5b8401601f8101861361433757600080fd5b80356143456142068261418e565b8181526060918202830184019184820191908984111561436457600080fd5b938501935b8385101561438a5761437b8a8661427e565b83529384019391850191614369565b5080955050505050509250929050565b600080600080600060a086880312156143b257600080fd5b85356143bd81613ce5565b945060208601356143cd81613ce5565b935060408601356143dd81613e26565b94979396509394606081013594506080013592915050565b60ff81168114613cfa57600080fd5b6000806000806000806000806000806000806101808d8f03121561442757600080fd5b8c3561443281613ce5565b9b5060208d013561444281613ce5565b9a5060408d013561445281613e26565b995060608d0135985060808d0135975060a08d0135965060c08d013561447781613ce5565b955060e08d013594506101008d013561448f81613e26565b93506101208d01356144a0816143f5565b809350506101408d013591506101608d013590509295989b509295989b509295989b565b60008060008060008060008060008060006101608c8e0312156144e657600080fd5b8b356144f181613ce5565b9a5060208c013561450181613e26565b995060408c0135985060608c0135975060808c0135965060a08c013561452681613ce5565b955060c08c0135945060e08c013561453d81613e26565b93506101008c013561454e816143f5565b809350506101208c013591506101408c013590509295989b509295989b9093969950565b60208082526015908201527410985cd9558c549bdd5d195c8e8811561412549151605a1b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b6000828210156145c9576145c96145a1565b500390565b634e487b7160e01b600052603260045260246000fd5b6020808252601a908201527f426173655631526f757465723a20494e56414c49445f50415448000000000000604082015260600190565b60006060828403121561462d57600080fd5b61282d838361427e565b60208082526028908201527f426173655631526f757465723a20494e53554646494349454e545f4f555450556040820152671517d05353d5539560c21b606082015260800190565b60006020828403121561469157600080fd5b813561282d81613e26565b6000602082840312156146ae57600080fd5b815161282d81613e26565b600080604083850312156146cc57600080fd5b505080516020909101519092909150565b60208082526023908201527f426173655631526f757465723a20494e53554646494349454e545f415f414d4f60408201526215539560ea1b606082015260800190565b60208082526023908201527f426173655631526f757465723a20494e53554646494349454e545f425f414d4f60408201526215539560ea1b606082015260800190565b60006020828403121561477557600080fd5b5051919050565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6000602082840312156147b257600080fd5b815161282d81613ce5565b60008160001904831182151516156147d7576147d76145a1565b500290565b6000826147f957634e487b7160e01b600052601260045260246000fd5b500490565b80516001600160701b0381168114612f3d57600080fd5b60008060006060848603121561482a57600080fd5b614833846147fe565b9250614841602085016147fe565b9150604084015163ffffffff8116811461402057600080fd5b6000821982111561486d5761486d6145a1565b500190565b6000600019821415614886576148866145a1565b5060010190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b60005b838110156148e95781810151838201526020016148d1565b83811115612be05750506000910152565b60006020828403121561490c57600080fd5b815167ffffffffffffffff8082111561492457600080fd5b818401915084601f83011261493857600080fd5b81518181111561494a5761494a614147565b61495d601f8201601f191660200161415d565b915080825285602082850101111561497457600080fd5b6149858160208401602086016148ce565b50949350505050565b6000602082840312156149a057600080fd5b815161282d816143f5565b600181815b808511156149e65781600019048211156149cc576149cc6145a1565b808516156149d957918102915b93841c93908002906149b0565b509250929050565b6000826149fd575060016123c3565b81614a0a575060006123c3565b8160018114614a205760028114614a2a57614a46565b60019150506123c3565b60ff841115614a3b57614a3b6145a1565b50506001821b6123c3565b5060208310610133831016604e8410600b8410161715614a69575081810a6123c3565b614a7383836149ab565b8060001904821115614a8757614a876145a1565b029392505050565b600061282d83836149ee565b84815283602082015260018060a01b03831660408201526080606082015260008251806080840152614ad48160a08501602087016148ce565b601f01601f19169190910160a00195945050505050565b60008251614afd8184602087016148ce565b9190910192915050565b600061282d60ff8416836149ee565b600082601f830112614b2757600080fd5b81516020614b376142068361418e565b82815260059290921b84018101918181019086841115614b5657600080fd5b8286015b848110156109ec5780518352918301918301614b5a565b600060208284031215614b8357600080fd5b815167ffffffffffffffff811115614b9a57600080fd5b6125d684828501614b16565b6001600160a01b0394909416845260208401929092526040830152606082015260800190565b60008060408385031215614bdf57600080fd5b825167ffffffffffffffff80821115614bf757600080fd5b614c0386838701614b16565b93506020850151915080821115614c1957600080fd5b50614c2685828601614b16565b915050925092905056fea264697066735822122062b3297058a69e7aca6dd201a40cc1f104537c2c0c273f0017df4ff58eeb862064736f6c634300080b0033